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