Spell.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // Spell.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. #endregion
  15. namespace RolePlayingGameData
  16. {
  17. public class Spell : ContentObject
  18. #if WINDOWS
  19. , ICloneable
  20. #endif
  21. {
  22. #region Description Data
  23. /// <summary>
  24. /// The name of this spell.
  25. /// </summary>
  26. private string name;
  27. /// <summary>
  28. /// The name of this spell.
  29. /// </summary>
  30. public string Name
  31. {
  32. get { return name; }
  33. set { name = value; }
  34. }
  35. /// <summary>
  36. /// The long description of this spell.
  37. /// </summary>
  38. private string description;
  39. /// <summary>
  40. /// The long description of this spell.
  41. /// </summary>
  42. public string Description
  43. {
  44. get { return description; }
  45. set { description = value; }
  46. }
  47. /// <summary>
  48. /// The cost, in magic points, to cast this spell.
  49. /// </summary>
  50. private int magicPointCost;
  51. /// <summary>
  52. /// The cost, in magic points, to cast this spell.
  53. /// </summary>
  54. public int MagicPointCost
  55. {
  56. get { return magicPointCost; }
  57. set { magicPointCost = value; }
  58. }
  59. /// <summary>
  60. /// Builds and returns a string describing the power of this spell.
  61. /// </summary>
  62. public virtual string GetPowerText()
  63. {
  64. return TargetEffectRange.GetModifierString();
  65. }
  66. #endregion
  67. #region Target Buff/Debuff Data
  68. /// <summary>
  69. /// If true, the statistics change are used as a debuff (subtracted).
  70. /// Otherwise, the statistics change is used as a buff (added).
  71. /// </summary>
  72. private bool isOffensive;
  73. /// <summary>
  74. /// If true, the statistics change are used as a debuff (subtracted).
  75. /// Otherwise, the statistics change is used as a buff (added).
  76. /// </summary>
  77. public bool IsOffensive
  78. {
  79. get { return isOffensive; }
  80. set { isOffensive = value; }
  81. }
  82. /// <summary>
  83. /// The duration of the effect of this spell on its target, in rounds.
  84. /// </summary>
  85. /// <remarks>
  86. /// If the duration is zero, then the effects last for the rest of the battle.
  87. /// </remarks>
  88. private int targetDuration;
  89. /// <summary>
  90. /// The duration of the effect of this spell on its target, in rounds.
  91. /// </summary>
  92. /// <remarks>
  93. /// If the duration is zero, then the effects last for the rest of the battle.
  94. /// </remarks>
  95. public int TargetDuration
  96. {
  97. get { return targetDuration; }
  98. set { targetDuration = value; }
  99. }
  100. /// <summary>
  101. /// The range of statistics effects of this spell on its target.
  102. /// </summary>
  103. /// <remarks>
  104. /// This is a debuff if IsOffensive is true, otherwise it's a buff.
  105. /// </remarks>
  106. private StatisticsRange targetEffectRange = new StatisticsRange();
  107. /// <summary>
  108. /// The range of statistics effects of this spell on its target.
  109. /// </summary>
  110. /// <remarks>
  111. /// This is a debuff if IsOffensive is true, otherwise it's a buff.
  112. /// </remarks>
  113. [ContentSerializerIgnore]
  114. public StatisticsRange TargetEffectRange
  115. {
  116. get { return targetEffectRange; }
  117. }
  118. /// <summary>
  119. /// The initial range of statistics effects of this spell on its target.
  120. /// </summary>
  121. /// <remarks>
  122. /// This is a debuff if IsOffensive is true, otherwise it's a buff.
  123. /// </remarks>
  124. private StatisticsRange initialTargetEffectRange = new StatisticsRange();
  125. /// <summary>
  126. /// The initial range of statistics effects of this spell on its target.
  127. /// </summary>
  128. /// <remarks>
  129. /// This is a debuff if IsOffensive is true, otherwise it's a buff.
  130. /// </remarks>
  131. public StatisticsRange InitialTargetEffectRange
  132. {
  133. get { return initialTargetEffectRange; }
  134. set { initialTargetEffectRange = value; }
  135. }
  136. /// <summary>
  137. /// The number of simultaneous, adjacent targets affected by this spell.
  138. /// </summary>
  139. private int adjacentTargets;
  140. /// <summary>
  141. /// The number of simultaneous, adjacent targets affected by this spell.
  142. /// </summary>
  143. public int AdjacentTargets
  144. {
  145. get { return adjacentTargets; }
  146. set { adjacentTargets = value; }
  147. }
  148. #endregion
  149. #region Spell Leveling
  150. /// <summary>
  151. /// The level of the spell.
  152. /// </summary>
  153. private int level = 1;
  154. /// <summary>
  155. /// The level of the spell.
  156. /// </summary>
  157. [ContentSerializerIgnore]
  158. public int Level
  159. {
  160. get { return level; }
  161. set
  162. {
  163. level = value;
  164. targetEffectRange = initialTargetEffectRange;
  165. for (int i = 1; i < level; i++)
  166. {
  167. targetEffectRange += LevelingProgression;
  168. }
  169. }
  170. }
  171. /// <summary>
  172. /// Defines how the spell improves as it levels up.
  173. /// </summary>
  174. private StatisticsValue levelingProgression = new StatisticsValue();
  175. /// <summary>
  176. /// Defines how the spell improves as it levels up.
  177. /// </summary>
  178. public StatisticsValue LevelingProgression
  179. {
  180. get { return levelingProgression; }
  181. set { levelingProgression = value; }
  182. }
  183. #endregion
  184. #region Sound Effects Data
  185. /// <summary>
  186. /// The name of the sound effect cue played when the spell is cast.
  187. /// </summary>
  188. private string creatingCueName;
  189. /// <summary>
  190. /// The name of the sound effect cue played when the spell is cast.
  191. /// </summary>
  192. public string CreatingCueName
  193. {
  194. get { return creatingCueName; }
  195. set { creatingCueName = value; }
  196. }
  197. /// <summary>
  198. /// The name of the sound effect cue played when the spell effect is traveling.
  199. /// </summary>
  200. private string travelingCueName;
  201. /// <summary>
  202. /// The name of the sound effect cue played when the spell effect is traveling.
  203. /// </summary>
  204. public string TravelingCueName
  205. {
  206. get { return travelingCueName; }
  207. set { travelingCueName = value; }
  208. }
  209. /// <summary>
  210. /// The name of the sound effect cue played when the spell affects its target.
  211. /// </summary>
  212. private string impactCueName;
  213. /// <summary>
  214. /// The name of the sound effect cue played when the spell affects its target.
  215. /// </summary>
  216. public string ImpactCueName
  217. {
  218. get { return impactCueName; }
  219. set { impactCueName = value; }
  220. }
  221. /// <summary>
  222. /// The name of the sound effect cue played when the spell effect is blocked.
  223. /// </summary>
  224. private string blockCueName;
  225. /// <summary>
  226. /// The name of the sound effect cue played when the spell effect is blocked.
  227. /// </summary>
  228. public string BlockCueName
  229. {
  230. get { return blockCueName; }
  231. set { blockCueName = value; }
  232. }
  233. #endregion
  234. #region Graphics Data
  235. /// <summary>
  236. /// The content path and name of the icon for this spell.
  237. /// </summary>
  238. private string iconTextureName;
  239. /// <summary>
  240. /// The content path and name of the icon for this spell.
  241. /// </summary>
  242. public string IconTextureName
  243. {
  244. get { return iconTextureName; }
  245. set { iconTextureName = value; }
  246. }
  247. /// <summary>
  248. /// The icon texture for this spell.
  249. /// </summary>
  250. private Texture2D iconTexture;
  251. /// <summary>
  252. /// The icon texture for this spell.
  253. /// </summary>
  254. [ContentSerializerIgnore]
  255. public Texture2D IconTexture
  256. {
  257. get { return iconTexture; }
  258. }
  259. /// <summary>
  260. /// The animating sprite used when this spell is in action.
  261. /// </summary>
  262. private AnimatingSprite spellSprite;
  263. /// <summary>
  264. /// The animating sprite used when this spell is in action.
  265. /// </summary>
  266. public AnimatingSprite SpellSprite
  267. {
  268. get { return spellSprite; }
  269. set { spellSprite = value; }
  270. }
  271. /// <summary>
  272. /// The overlay sprite for this spell.
  273. /// </summary>
  274. private AnimatingSprite overlay;
  275. /// <summary>
  276. /// The overlay sprite for this spell.
  277. /// </summary>
  278. public AnimatingSprite Overlay
  279. {
  280. get { return overlay; }
  281. set { overlay = value; }
  282. }
  283. #endregion
  284. #region Content Type Reader
  285. /// <summary>
  286. /// Read an Spell object from the content pipeline.
  287. /// </summary>
  288. public class SpellReader : ContentTypeReader<Spell>
  289. {
  290. /// <summary>
  291. /// Read an Spell object from the content pipeline.
  292. /// </summary>
  293. protected override Spell Read(ContentReader input, Spell existingInstance)
  294. {
  295. Spell spell = existingInstance;
  296. if (spell == null)
  297. {
  298. spell = new Spell();
  299. }
  300. spell.AssetName = input.AssetName;
  301. spell.Name = input.ReadString();
  302. spell.Description = input.ReadString();
  303. spell.MagicPointCost = input.ReadInt32();
  304. spell.IconTextureName = input.ReadString();
  305. spell.iconTexture = input.ContentManager.Load<Texture2D>(
  306. System.IO.Path.Combine(@"Textures\Spells", spell.IconTextureName));
  307. spell.IsOffensive = input.ReadBoolean();
  308. spell.TargetDuration = input.ReadInt32();
  309. spell.targetEffectRange = spell.InitialTargetEffectRange =
  310. input.ReadObject<StatisticsRange>();
  311. spell.AdjacentTargets = input.ReadInt32();
  312. spell.LevelingProgression = input.ReadObject<StatisticsValue>();
  313. spell.CreatingCueName = input.ReadString();
  314. spell.TravelingCueName = input.ReadString();
  315. spell.ImpactCueName = input.ReadString();
  316. spell.BlockCueName = input.ReadString();
  317. spell.SpellSprite = input.ReadObject<AnimatingSprite>();
  318. spell.SpellSprite.SourceOffset = new Vector2(
  319. spell.SpellSprite.FrameDimensions.X / 2,
  320. spell.SpellSprite.FrameDimensions.Y);
  321. spell.Overlay = input.ReadObject<AnimatingSprite>();
  322. spell.Overlay.SourceOffset = new Vector2(
  323. spell.Overlay.FrameDimensions.X / 2,
  324. spell.Overlay.FrameDimensions.Y);
  325. spell.Level = 1;
  326. return spell;
  327. }
  328. }
  329. #endregion
  330. #region ICloneable Members
  331. public object Clone()
  332. {
  333. Spell spell = new Spell();
  334. spell.adjacentTargets = adjacentTargets;
  335. spell.AssetName = AssetName;
  336. spell.blockCueName = blockCueName;
  337. spell.creatingCueName = creatingCueName;
  338. spell.description = description;
  339. spell.iconTexture = iconTexture;
  340. spell.iconTextureName = iconTextureName;
  341. spell.impactCueName = impactCueName;
  342. spell.initialTargetEffectRange = initialTargetEffectRange;
  343. spell.isOffensive = isOffensive;
  344. spell.levelingProgression = levelingProgression;
  345. spell.magicPointCost = magicPointCost;
  346. spell.name = name;
  347. spell.overlay = overlay.Clone() as AnimatingSprite;
  348. spell.spellSprite = spellSprite.Clone() as AnimatingSprite;
  349. spell.targetDuration = targetDuration;
  350. spell.travelingCueName = travelingCueName;
  351. spell.Level = Level;
  352. return spell;
  353. }
  354. #endregion
  355. }
  356. }