Spell.cs 12 KB

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