Inn.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //-----------------------------------------------------------------------------
  2. // Inn.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using System;
  8. using System.IO;
  9. using Microsoft.Xna.Framework.Content;
  10. using Microsoft.Xna.Framework.Graphics;
  11. namespace RolePlaying.Data
  12. {
  13. /// <summary>
  14. /// An inn in the game world, where the party can rest and restore themselves.
  15. /// </summary>
  16. public class Inn : WorldObject
  17. {
  18. /// <summary>
  19. /// The amount that the party has to pay for each member to stay.
  20. /// </summary>
  21. private int chargePerPlayer;
  22. /// <summary>
  23. /// The amount that the party has to pay for each member to stay.
  24. /// </summary>
  25. public int ChargePerPlayer
  26. {
  27. get { return chargePerPlayer; }
  28. set { chargePerPlayer = value; }
  29. }
  30. /// <summary>
  31. /// The message shown when the player enters the inn.
  32. /// </summary>
  33. private string welcomeMessage;
  34. /// <summary>
  35. /// The message shown when the player enters the inn.
  36. /// </summary>
  37. public string WelcomeMessage
  38. {
  39. get { return welcomeMessage; }
  40. set { welcomeMessage = value; }
  41. }
  42. /// <summary>
  43. /// The message shown when the party successfully pays to stay the night.
  44. /// </summary>
  45. private string paidMessage;
  46. /// <summary>
  47. /// The message shown when the party successfully pays to stay the night.
  48. /// </summary>
  49. public string PaidMessage
  50. {
  51. get { return paidMessage; }
  52. set { paidMessage = value; }
  53. }
  54. /// <summary>
  55. /// The message shown when the party tries to stay but lacks the funds.
  56. /// </summary>
  57. private string notEnoughGoldMessage;
  58. /// <summary>
  59. /// The message shown when the party tries to stay but lacks the funds.
  60. /// </summary>
  61. public string NotEnoughGoldMessage
  62. {
  63. get { return notEnoughGoldMessage; }
  64. set { notEnoughGoldMessage = value; }
  65. }
  66. /// <summary>
  67. /// The content name of the texture for the shopkeeper.
  68. /// </summary>
  69. private string shopkeeperTextureName;
  70. /// <summary>
  71. /// The content name of the texture for the shopkeeper.
  72. /// </summary>
  73. public string ShopkeeperTextureName
  74. {
  75. get { return shopkeeperTextureName; }
  76. set { shopkeeperTextureName = value; }
  77. }
  78. /// <summary>
  79. /// The texture for the shopkeeper.
  80. /// </summary>
  81. private Texture2D shopkeeperTexture;
  82. /// <summary>
  83. /// The texture for the shopkeeper.
  84. /// </summary>
  85. [ContentSerializerIgnore]
  86. public Texture2D ShopkeeperTexture
  87. {
  88. get { return shopkeeperTexture; }
  89. set { shopkeeperTexture = value; }
  90. }
  91. /// <summary>
  92. /// Reads an Inn object from the content pipeline.
  93. /// </summary>
  94. public class InnReader : ContentTypeReader<Inn>
  95. {
  96. protected override Inn Read(ContentReader input, Inn existingInstance)
  97. {
  98. Inn inn = existingInstance;
  99. if (inn == null)
  100. {
  101. inn = new Inn();
  102. }
  103. input.ReadRawObject<WorldObject>(inn as WorldObject);
  104. inn.ChargePerPlayer = input.ReadInt32();
  105. inn.WelcomeMessage = input.ReadString();
  106. inn.PaidMessage = input.ReadString();
  107. inn.NotEnoughGoldMessage = input.ReadString();
  108. inn.ShopkeeperTextureName = input.ReadString();
  109. inn.shopkeeperTexture = input.ContentManager.Load<Texture2D>(Path.Combine("Textures", "Characters", "Portraits", inn.ShopkeeperTextureName));
  110. return inn;
  111. }
  112. }
  113. internal static Inn Load(string contentName, ContentManager contentManager)
  114. {
  115. var asset = XmlHelper.GetAssetElementFromXML(contentName);
  116. var inn = new Inn
  117. {
  118. AssetName = contentName,
  119. Name = asset.Element("Name").Value,
  120. ChargePerPlayer = int.Parse(asset.Element("ChargePerPlayer").Value),
  121. WelcomeMessage = asset.Element("WelcomeMessage").Value,
  122. PaidMessage = asset.Element("PaidMessage").Value,
  123. NotEnoughGoldMessage = asset.Element("NotEnoughGoldMessage").Value,
  124. ShopkeeperTextureName = asset.Element("ShopkeeperTextureName").Value,
  125. ShopkeeperTexture = contentManager.Load<Texture2D>(
  126. System.IO.Path.Combine("Textures", "Characters", "Portraits",
  127. asset.Element("ShopkeeperTextureName").Value)),
  128. };
  129. return inn;
  130. }
  131. }
  132. }