Item.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // Item.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using Microsoft.Xna.Framework;
  12. using Microsoft.Xna.Framework.Content;
  13. using Microsoft.Xna.Framework.Graphics;
  14. using System.Collections.Generic;
  15. #endregion
  16. namespace RolePlayingGameData
  17. {
  18. /// <summary>
  19. /// A usable piece of gear that has a spell-like effect.
  20. /// </summary>
  21. public class Item : Gear
  22. {
  23. #region Usage
  24. /// <summary>
  25. /// Flags that specify when an item may be used.
  26. /// </summary>
  27. public enum ItemUsage
  28. {
  29. Combat = 1,
  30. NonCombat = 2,
  31. };
  32. /// <summary>
  33. /// Description of when the item may be used.
  34. /// </summary>
  35. /// <remarks>Defaults to "either", with both values.</remarks>
  36. private ItemUsage usage = ItemUsage.Combat | ItemUsage.NonCombat;
  37. /// <summary>
  38. /// Description of when the item may be used.
  39. /// </summary>
  40. /// <remarks>Defaults to "either", with both values.</remarks>
  41. [ContentSerializer(Optional = true)]
  42. public ItemUsage Usage
  43. {
  44. get { return usage; }
  45. set { usage = value; }
  46. }
  47. #endregion
  48. #region Description Data
  49. /// <summary>
  50. /// Builds and returns a string describing the power of this item.
  51. /// </summary>
  52. public override string GetPowerText()
  53. {
  54. return TargetEffectRange.GetModifierString();
  55. }
  56. #endregion
  57. #region Target Buff/Debuff Data
  58. /// <summary>
  59. /// If true, the statistics change are used as a debuff (subtracted).
  60. /// Otherwise, the statistics change is used as a buff (added).
  61. /// </summary>
  62. private bool isOffensive;
  63. /// <summary>
  64. /// If true, the statistics change are used as a debuff (subtracted).
  65. /// Otherwise, the statistics change is used as a buff (added).
  66. /// </summary>
  67. public bool IsOffensive
  68. {
  69. get { return isOffensive; }
  70. set { isOffensive = value; }
  71. }
  72. /// <summary>
  73. /// The duration of the effect of this item on its target, in rounds.
  74. /// </summary>
  75. /// <remarks>
  76. /// If the duration is zero, then the effects last for the rest of the battle.
  77. /// </remarks>
  78. private int targetDuration;
  79. /// <summary>
  80. /// The duration of the effect of this item on its target, in rounds.
  81. /// </summary>
  82. /// <remarks>
  83. /// If the duration is zero, then the effects last for the rest of the battle.
  84. /// </remarks>
  85. public int TargetDuration
  86. {
  87. get { return targetDuration; }
  88. set { targetDuration = value; }
  89. }
  90. /// <summary>
  91. /// The range of statistics effects of this item on its target.
  92. /// </summary>
  93. /// <remarks>
  94. /// This is a debuff if IsOffensive is true, otherwise it's a buff.
  95. /// </remarks>
  96. private StatisticsRange targetEffectRange = new StatisticsRange();
  97. /// <summary>
  98. /// The range of statistics effects of this item on its target.
  99. /// </summary>
  100. /// <remarks>
  101. /// This is a debuff if IsOffensive is true, otherwise it's a buff.
  102. /// </remarks>
  103. public StatisticsRange TargetEffectRange
  104. {
  105. get { return targetEffectRange; }
  106. set { targetEffectRange = value; }
  107. }
  108. /// <summary>
  109. /// The number of simultaneous, adjacent targets affected by this item.
  110. /// </summary>
  111. private int adjacentTargets;
  112. /// <summary>
  113. /// The number of simultaneous, adjacent targets affected by this item.
  114. /// </summary>
  115. public int AdjacentTargets
  116. {
  117. get { return adjacentTargets; }
  118. set { adjacentTargets = value; }
  119. }
  120. #endregion
  121. #region Sound Effects Data
  122. /// <summary>
  123. /// The name of the sound effect cue played when the item is used.
  124. /// </summary>
  125. private string usingCueName;
  126. /// <summary>
  127. /// The name of the sound effect cue played when the item is used.
  128. /// </summary>
  129. public string UsingCueName
  130. {
  131. get { return usingCueName; }
  132. set { usingCueName = value; }
  133. }
  134. /// <summary>
  135. /// The name of the sound effect cue played when the item effect is traveling.
  136. /// </summary>
  137. private string travelingCueName;
  138. /// <summary>
  139. /// The name of the sound effect cue played when the item effect is traveling.
  140. /// </summary>
  141. public string TravelingCueName
  142. {
  143. get { return travelingCueName; }
  144. set { travelingCueName = value; }
  145. }
  146. /// <summary>
  147. /// The name of the sound effect cue played when the item affects its target.
  148. /// </summary>
  149. private string impactCueName;
  150. /// <summary>
  151. /// The name of the sound effect cue played when the item affects its target.
  152. /// </summary>
  153. public string ImpactCueName
  154. {
  155. get { return impactCueName; }
  156. set { impactCueName = value; }
  157. }
  158. /// <summary>
  159. /// The name of the sound effect cue played when the item effect is blocked.
  160. /// </summary>
  161. private string blockCueName;
  162. /// <summary>
  163. /// The name of the sound effect cue played when the item effect is blocked.
  164. /// </summary>
  165. public string BlockCueName
  166. {
  167. get { return blockCueName; }
  168. set { blockCueName = value; }
  169. }
  170. #endregion
  171. #region Graphics Data
  172. /// <summary>
  173. /// An animating sprite used when this item is used.
  174. /// </summary>
  175. /// <remarks>
  176. /// This is optional. If it is null, then a Using or Creating animation
  177. /// in SpellSprite is used.
  178. /// </remarks>
  179. private AnimatingSprite creationSprite;
  180. /// <summary>
  181. /// An animating sprite used when this item is used.
  182. /// </summary>
  183. /// <remarks>
  184. /// This is optional. If it is null, then a Using or Creating animation
  185. /// in SpellSprite is used.
  186. /// </remarks>
  187. [ContentSerializer(Optional=true)]
  188. public AnimatingSprite CreationSprite
  189. {
  190. get { return creationSprite; }
  191. set { creationSprite = value; }
  192. }
  193. /// <summary>
  194. /// The animating sprite used when this item is in action.
  195. /// </summary>
  196. private AnimatingSprite spellSprite;
  197. /// <summary>
  198. /// The animating sprite used when this item is in action.
  199. /// </summary>
  200. public AnimatingSprite SpellSprite
  201. {
  202. get { return spellSprite; }
  203. set { spellSprite = value; }
  204. }
  205. /// <summary>
  206. /// The overlay sprite for this item.
  207. /// </summary>
  208. private AnimatingSprite overlay;
  209. /// <summary>
  210. /// The overlay sprite for this item.
  211. /// </summary>
  212. public AnimatingSprite Overlay
  213. {
  214. get { return overlay; }
  215. set { overlay = value; }
  216. }
  217. #endregion
  218. #region Content Type Reader
  219. /// <summary>
  220. /// Read an Item object from the content pipeline
  221. /// </summary>
  222. public class ItemReader : ContentTypeReader<Item>
  223. {
  224. protected override Item Read(ContentReader input, Item existingInstance)
  225. {
  226. Item item = existingInstance;
  227. if (item == null)
  228. {
  229. item = new Item();
  230. }
  231. // read gear settings
  232. input.ReadRawObject<Gear>(item as Gear);
  233. // read item settings
  234. item.Usage = (ItemUsage)input.ReadInt32();
  235. item.IsOffensive = input.ReadBoolean();
  236. item.TargetDuration = input.ReadInt32();
  237. item.TargetEffectRange = input.ReadObject<StatisticsRange>();
  238. item.AdjacentTargets = input.ReadInt32();
  239. item.UsingCueName = input.ReadString();
  240. item.TravelingCueName = input.ReadString();
  241. item.ImpactCueName = input.ReadString();
  242. item.BlockCueName = input.ReadString();
  243. item.CreationSprite = input.ReadObject<AnimatingSprite>();
  244. item.CreationSprite.SourceOffset = new Vector2(
  245. item.CreationSprite.FrameDimensions.X / 2,
  246. item.CreationSprite.FrameDimensions.Y);
  247. item.SpellSprite = input.ReadObject<AnimatingSprite>();
  248. item.SpellSprite.SourceOffset = new Vector2(
  249. item.SpellSprite.FrameDimensions.X / 2,
  250. item.SpellSprite.FrameDimensions.Y);
  251. item.Overlay = input.ReadObject<AnimatingSprite>();
  252. item.Overlay.SourceOffset = new Vector2(
  253. item.Overlay.FrameDimensions.X / 2,
  254. item.Overlay.FrameDimensions.Y);
  255. return item;
  256. }
  257. }
  258. #endregion
  259. }
  260. }