123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451 |
- #region File Description
- //-----------------------------------------------------------------------------
- // Spell.cs
- //
- // Microsoft XNA Community Game Platform
- // Copyright (C) Microsoft Corporation. All rights reserved.
- //-----------------------------------------------------------------------------
- #endregion
- #region Using Statements
- using System;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.Graphics;
- #endregion
- namespace RolePlayingGameData
- {
- public class Spell : ContentObject
- #if WINDOWS
- , ICloneable
- #endif
- {
- #region Description Data
- /// <summary>
- /// The name of this spell.
- /// </summary>
- private string name;
- /// <summary>
- /// The name of this spell.
- /// </summary>
- public string Name
- {
- get { return name; }
- set { name = value; }
- }
- /// <summary>
- /// The long description of this spell.
- /// </summary>
- private string description;
- /// <summary>
- /// The long description of this spell.
- /// </summary>
- public string Description
- {
- get { return description; }
- set { description = value; }
- }
- /// <summary>
- /// The cost, in magic points, to cast this spell.
- /// </summary>
- private int magicPointCost;
- /// <summary>
- /// The cost, in magic points, to cast this spell.
- /// </summary>
- public int MagicPointCost
- {
- get { return magicPointCost; }
- set { magicPointCost = value; }
- }
- /// <summary>
- /// Builds and returns a string describing the power of this spell.
- /// </summary>
- public virtual string GetPowerText()
- {
- return TargetEffectRange.GetModifierString();
- }
- #endregion
- #region Target Buff/Debuff Data
- /// <summary>
- /// If true, the statistics change are used as a debuff (subtracted).
- /// Otherwise, the statistics change is used as a buff (added).
- /// </summary>
- private bool isOffensive;
- /// <summary>
- /// If true, the statistics change are used as a debuff (subtracted).
- /// Otherwise, the statistics change is used as a buff (added).
- /// </summary>
- public bool IsOffensive
- {
- get { return isOffensive; }
- set { isOffensive = value; }
- }
- /// <summary>
- /// The duration of the effect of this spell on its target, in rounds.
- /// </summary>
- /// <remarks>
- /// If the duration is zero, then the effects last for the rest of the battle.
- /// </remarks>
- private int targetDuration;
- /// <summary>
- /// The duration of the effect of this spell on its target, in rounds.
- /// </summary>
- /// <remarks>
- /// If the duration is zero, then the effects last for the rest of the battle.
- /// </remarks>
- public int TargetDuration
- {
- get { return targetDuration; }
- set { targetDuration = value; }
- }
- /// <summary>
- /// The range of statistics effects of this spell on its target.
- /// </summary>
- /// <remarks>
- /// This is a debuff if IsOffensive is true, otherwise it's a buff.
- /// </remarks>
- private StatisticsRange targetEffectRange = new StatisticsRange();
- /// <summary>
- /// The range of statistics effects of this spell on its target.
- /// </summary>
- /// <remarks>
- /// This is a debuff if IsOffensive is true, otherwise it's a buff.
- /// </remarks>
- [ContentSerializerIgnore]
- public StatisticsRange TargetEffectRange
- {
- get { return targetEffectRange; }
- }
- /// <summary>
- /// The initial range of statistics effects of this spell on its target.
- /// </summary>
- /// <remarks>
- /// This is a debuff if IsOffensive is true, otherwise it's a buff.
- /// </remarks>
- private StatisticsRange initialTargetEffectRange = new StatisticsRange();
- /// <summary>
- /// The initial range of statistics effects of this spell on its target.
- /// </summary>
- /// <remarks>
- /// This is a debuff if IsOffensive is true, otherwise it's a buff.
- /// </remarks>
- public StatisticsRange InitialTargetEffectRange
- {
- get { return initialTargetEffectRange; }
- set { initialTargetEffectRange = value; }
- }
- /// <summary>
- /// The number of simultaneous, adjacent targets affected by this spell.
- /// </summary>
- private int adjacentTargets;
- /// <summary>
- /// The number of simultaneous, adjacent targets affected by this spell.
- /// </summary>
- public int AdjacentTargets
- {
- get { return adjacentTargets; }
- set { adjacentTargets = value; }
- }
- #endregion
- #region Spell Leveling
- /// <summary>
- /// The level of the spell.
- /// </summary>
- private int level = 1;
- /// <summary>
- /// The level of the spell.
- /// </summary>
- [ContentSerializerIgnore]
- public int Level
- {
- get { return level; }
- set
- {
- level = value;
- targetEffectRange = initialTargetEffectRange;
- for (int i = 1; i < level; i++)
- {
- targetEffectRange += LevelingProgression;
- }
- }
- }
- /// <summary>
- /// Defines how the spell improves as it levels up.
- /// </summary>
- private StatisticsValue levelingProgression = new StatisticsValue();
- /// <summary>
- /// Defines how the spell improves as it levels up.
- /// </summary>
- public StatisticsValue LevelingProgression
- {
- get { return levelingProgression; }
- set { levelingProgression = value; }
- }
- #endregion
- #region Sound Effects Data
- /// <summary>
- /// The name of the sound effect cue played when the spell is cast.
- /// </summary>
- private string creatingCueName;
- /// <summary>
- /// The name of the sound effect cue played when the spell is cast.
- /// </summary>
- public string CreatingCueName
- {
- get { return creatingCueName; }
- set { creatingCueName = value; }
- }
- /// <summary>
- /// The name of the sound effect cue played when the spell effect is traveling.
- /// </summary>
- private string travelingCueName;
- /// <summary>
- /// The name of the sound effect cue played when the spell effect is traveling.
- /// </summary>
- public string TravelingCueName
- {
- get { return travelingCueName; }
- set { travelingCueName = value; }
- }
- /// <summary>
- /// The name of the sound effect cue played when the spell affects its target.
- /// </summary>
- private string impactCueName;
- /// <summary>
- /// The name of the sound effect cue played when the spell affects its target.
- /// </summary>
- public string ImpactCueName
- {
- get { return impactCueName; }
- set { impactCueName = value; }
- }
- /// <summary>
- /// The name of the sound effect cue played when the spell effect is blocked.
- /// </summary>
- private string blockCueName;
- /// <summary>
- /// The name of the sound effect cue played when the spell effect is blocked.
- /// </summary>
- public string BlockCueName
- {
- get { return blockCueName; }
- set { blockCueName = value; }
- }
- #endregion
- #region Graphics Data
- /// <summary>
- /// The content path and name of the icon for this spell.
- /// </summary>
- private string iconTextureName;
- /// <summary>
- /// The content path and name of the icon for this spell.
- /// </summary>
- public string IconTextureName
- {
- get { return iconTextureName; }
- set { iconTextureName = value; }
- }
- /// <summary>
- /// The icon texture for this spell.
- /// </summary>
- private Texture2D iconTexture;
- /// <summary>
- /// The icon texture for this spell.
- /// </summary>
- [ContentSerializerIgnore]
- public Texture2D IconTexture
- {
- get { return iconTexture; }
- }
-
-
- /// <summary>
- /// The animating sprite used when this spell is in action.
- /// </summary>
- private AnimatingSprite spellSprite;
- /// <summary>
- /// The animating sprite used when this spell is in action.
- /// </summary>
- public AnimatingSprite SpellSprite
- {
- get { return spellSprite; }
- set { spellSprite = value; }
- }
- /// <summary>
- /// The overlay sprite for this spell.
- /// </summary>
- private AnimatingSprite overlay;
- /// <summary>
- /// The overlay sprite for this spell.
- /// </summary>
- public AnimatingSprite Overlay
- {
- get { return overlay; }
- set { overlay = value; }
- }
- #endregion
- #region Content Type Reader
- /// <summary>
- /// Read an Spell object from the content pipeline.
- /// </summary>
- public class SpellReader : ContentTypeReader<Spell>
- {
- /// <summary>
- /// Read an Spell object from the content pipeline.
- /// </summary>
- protected override Spell Read(ContentReader input, Spell existingInstance)
- {
- Spell spell = existingInstance;
- if (spell == null)
- {
- spell = new Spell();
- }
- spell.AssetName = input.AssetName;
- spell.Name = input.ReadString();
- spell.Description = input.ReadString();
- spell.MagicPointCost = input.ReadInt32();
- spell.IconTextureName = input.ReadString();
- spell.iconTexture = input.ContentManager.Load<Texture2D>(
- System.IO.Path.Combine(@"Textures\Spells", spell.IconTextureName));
- spell.IsOffensive = input.ReadBoolean();
- spell.TargetDuration = input.ReadInt32();
- spell.targetEffectRange = spell.InitialTargetEffectRange =
- input.ReadObject<StatisticsRange>();
- spell.AdjacentTargets = input.ReadInt32();
- spell.LevelingProgression = input.ReadObject<StatisticsValue>();
- spell.CreatingCueName = input.ReadString();
- spell.TravelingCueName = input.ReadString();
- spell.ImpactCueName = input.ReadString();
- spell.BlockCueName = input.ReadString();
- spell.SpellSprite = input.ReadObject<AnimatingSprite>();
- spell.SpellSprite.SourceOffset = new Vector2(
- spell.SpellSprite.FrameDimensions.X / 2,
- spell.SpellSprite.FrameDimensions.Y);
- spell.Overlay = input.ReadObject<AnimatingSprite>();
- spell.Overlay.SourceOffset = new Vector2(
- spell.Overlay.FrameDimensions.X / 2,
- spell.Overlay.FrameDimensions.Y);
- spell.Level = 1;
- return spell;
- }
- }
- #endregion
- #region ICloneable Members
- public object Clone()
- {
- Spell spell = new Spell();
- spell.adjacentTargets = adjacentTargets;
- spell.AssetName = AssetName;
- spell.blockCueName = blockCueName;
- spell.creatingCueName = creatingCueName;
- spell.description = description;
- spell.iconTexture = iconTexture;
- spell.iconTextureName = iconTextureName;
- spell.impactCueName = impactCueName;
- spell.initialTargetEffectRange = initialTargetEffectRange;
- spell.isOffensive = isOffensive;
- spell.levelingProgression = levelingProgression;
- spell.magicPointCost = magicPointCost;
- spell.name = name;
- spell.overlay = overlay.Clone() as AnimatingSprite;
- spell.spellSprite = spellSprite.Clone() as AnimatingSprite;
- spell.targetDuration = targetDuration;
- spell.travelingCueName = travelingCueName;
- spell.Level = Level;
- return spell;
- }
- #endregion
- }
- }
|