#region File Description
//-----------------------------------------------------------------------------
// Item.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;
using System.Collections.Generic;
#endregion
namespace RolePlayingGameData
{
///
/// A usable piece of gear that has a spell-like effect.
///
public class Item : Gear
{
#region Usage
///
/// Flags that specify when an item may be used.
///
public enum ItemUsage
{
Combat = 1,
NonCombat = 2,
};
///
/// Description of when the item may be used.
///
/// Defaults to "either", with both values.
private ItemUsage usage = ItemUsage.Combat | ItemUsage.NonCombat;
///
/// Description of when the item may be used.
///
/// Defaults to "either", with both values.
[ContentSerializer(Optional = true)]
public ItemUsage Usage
{
get { return usage; }
set { usage = value; }
}
#endregion
#region Description Data
///
/// Builds and returns a string describing the power of this item.
///
public override 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 item 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 item 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 item 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 item on its target.
///
///
/// This is a debuff if IsOffensive is true, otherwise it's a buff.
///
public StatisticsRange TargetEffectRange
{
get { return targetEffectRange; }
set { targetEffectRange = value; }
}
///
/// The number of simultaneous, adjacent targets affected by this item.
///
private int adjacentTargets;
///
/// The number of simultaneous, adjacent targets affected by this item.
///
public int AdjacentTargets
{
get { return adjacentTargets; }
set { adjacentTargets = value; }
}
#endregion
#region Sound Effects Data
///
/// The name of the sound effect cue played when the item is used.
///
private string usingCueName;
///
/// The name of the sound effect cue played when the item is used.
///
public string UsingCueName
{
get { return usingCueName; }
set { usingCueName = value; }
}
///
/// The name of the sound effect cue played when the item effect is traveling.
///
private string travelingCueName;
///
/// The name of the sound effect cue played when the item effect is traveling.
///
public string TravelingCueName
{
get { return travelingCueName; }
set { travelingCueName = value; }
}
///
/// The name of the sound effect cue played when the item affects its target.
///
private string impactCueName;
///
/// The name of the sound effect cue played when the item affects its target.
///
public string ImpactCueName
{
get { return impactCueName; }
set { impactCueName = value; }
}
///
/// The name of the sound effect cue played when the item effect is blocked.
///
private string blockCueName;
///
/// The name of the sound effect cue played when the item effect is blocked.
///
public string BlockCueName
{
get { return blockCueName; }
set { blockCueName = value; }
}
#endregion
#region Graphics Data
///
/// An animating sprite used when this item is used.
///
///
/// This is optional. If it is null, then a Using or Creating animation
/// in SpellSprite is used.
///
private AnimatingSprite creationSprite;
///
/// An animating sprite used when this item is used.
///
///
/// This is optional. If it is null, then a Using or Creating animation
/// in SpellSprite is used.
///
[ContentSerializer(Optional=true)]
public AnimatingSprite CreationSprite
{
get { return creationSprite; }
set { creationSprite = value; }
}
///
/// The animating sprite used when this item is in action.
///
private AnimatingSprite spellSprite;
///
/// The animating sprite used when this item is in action.
///
public AnimatingSprite SpellSprite
{
get { return spellSprite; }
set { spellSprite = value; }
}
///
/// The overlay sprite for this item.
///
private AnimatingSprite overlay;
///
/// The overlay sprite for this item.
///
public AnimatingSprite Overlay
{
get { return overlay; }
set { overlay = value; }
}
#endregion
#region Content Type Reader
///
/// Read an Item object from the content pipeline
///
public class ItemReader : ContentTypeReader-
{
protected override Item Read(ContentReader input, Item existingInstance)
{
Item item = existingInstance;
if (item == null)
{
item = new Item();
}
// read gear settings
input.ReadRawObject(item as Gear);
// read item settings
item.Usage = (ItemUsage)input.ReadInt32();
item.IsOffensive = input.ReadBoolean();
item.TargetDuration = input.ReadInt32();
item.TargetEffectRange = input.ReadObject();
item.AdjacentTargets = input.ReadInt32();
item.UsingCueName = input.ReadString();
item.TravelingCueName = input.ReadString();
item.ImpactCueName = input.ReadString();
item.BlockCueName = input.ReadString();
item.CreationSprite = input.ReadObject();
item.CreationSprite.SourceOffset = new Vector2(
item.CreationSprite.FrameDimensions.X / 2,
item.CreationSprite.FrameDimensions.Y);
item.SpellSprite = input.ReadObject();
item.SpellSprite.SourceOffset = new Vector2(
item.SpellSprite.FrameDimensions.X / 2,
item.SpellSprite.FrameDimensions.Y);
item.Overlay = input.ReadObject();
item.Overlay.SourceOffset = new Vector2(
item.Overlay.FrameDimensions.X / 2,
item.Overlay.FrameDimensions.Y);
return item;
}
}
#endregion
}
}