| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- //-----------------------------------------------------------------------------
- // Item.cs
- //
- // Microsoft XNA Community Game Platform
- // Copyright (C) Microsoft Corporation. All rights reserved.
- //-----------------------------------------------------------------------------
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.Graphics;
- using System;
- using System.Collections.Generic;
- using System.IO;
- namespace RolePlaying.Data
- {
- /// <summary>
- /// A usable piece of gear that has a spell-like effect.
- /// </summary>
- public class Item : Gear
- {
- /// <summary>
- /// Flags that specify when an item may be used.
- /// </summary>
- public enum ItemUsage
- {
- Combat = 1,
- NonCombat = 2,
- };
- /// <summary>
- /// Description of when the item may be used.
- /// </summary>
- /// <remarks>Defaults to "either", with both values.</remarks>
- private ItemUsage usage = ItemUsage.Combat | ItemUsage.NonCombat;
- /// <summary>
- /// Description of when the item may be used.
- /// </summary>
- /// <remarks>Defaults to "either", with both values.</remarks>
- [ContentSerializer(Optional = true)]
- public ItemUsage Usage
- {
- get { return usage; }
- set { usage = value; }
- }
- /// <summary>
- /// Builds and returns a string describing the power of this item.
- /// </summary>
- public override string GetPowerText()
- {
- return TargetEffectRange.GetModifierString();
- }
- /// <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 item 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 item 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 item 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 item on its target.
- /// </summary>
- /// <remarks>
- /// This is a debuff if IsOffensive is true, otherwise it's a buff.
- /// </remarks>
- public StatisticsRange TargetEffectRange
- {
- get { return targetEffectRange; }
- set { targetEffectRange = value; }
- }
- /// <summary>
- /// The number of simultaneous, adjacent targets affected by this item.
- /// </summary>
- private int adjacentTargets;
- /// <summary>
- /// The number of simultaneous, adjacent targets affected by this item.
- /// </summary>
- public int AdjacentTargets
- {
- get { return adjacentTargets; }
- set { adjacentTargets = value; }
- }
- /// <summary>
- /// The name of the sound effect cue played when the item is used.
- /// </summary>
- private string usingCueName;
- /// <summary>
- /// The name of the sound effect cue played when the item is used.
- /// </summary>
- public string UsingCueName
- {
- get { return usingCueName; }
- set { usingCueName = value; }
- }
- /// <summary>
- /// The name of the sound effect cue played when the item effect is traveling.
- /// </summary>
- private string travelingCueName;
- /// <summary>
- /// The name of the sound effect cue played when the item effect is traveling.
- /// </summary>
- public string TravelingCueName
- {
- get { return travelingCueName; }
- set { travelingCueName = value; }
- }
- /// <summary>
- /// The name of the sound effect cue played when the item affects its target.
- /// </summary>
- private string impactCueName;
- /// <summary>
- /// The name of the sound effect cue played when the item affects its target.
- /// </summary>
- public string ImpactCueName
- {
- get { return impactCueName; }
- set { impactCueName = value; }
- }
- /// <summary>
- /// The name of the sound effect cue played when the item effect is blocked.
- /// </summary>
- private string blockCueName;
- /// <summary>
- /// The name of the sound effect cue played when the item effect is blocked.
- /// </summary>
- public string BlockCueName
- {
- get { return blockCueName; }
- set { blockCueName = value; }
- }
- /// <summary>
- /// An animating sprite used when this item is used.
- /// </summary>
- /// <remarks>
- /// This is optional. If it is null, then a Using or Creating animation
- /// in SpellSprite is used.
- /// </remarks>
- private AnimatingSprite creationSprite;
- /// <summary>
- /// An animating sprite used when this item is used.
- /// </summary>
- /// <remarks>
- /// This is optional. If it is null, then a Using or Creating animation
- /// in SpellSprite is used.
- /// </remarks>
- [ContentSerializer(Optional = true)]
- public AnimatingSprite CreationSprite
- {
- get { return creationSprite; }
- set { creationSprite = value; }
- }
- /// <summary>
- /// The animating sprite used when this item is in action.
- /// </summary>
- private AnimatingSprite spellSprite;
- /// <summary>
- /// The animating sprite used when this item is in action.
- /// </summary>
- public AnimatingSprite SpellSprite
- {
- get { return spellSprite; }
- set { spellSprite = value; }
- }
- /// <summary>
- /// The overlay sprite for this item.
- /// </summary>
- private AnimatingSprite overlay;
- /// <summary>
- /// The overlay sprite for this item.
- /// </summary>
- public AnimatingSprite Overlay
- {
- get { return overlay; }
- set { overlay = value; }
- }
- internal static Item Load(string itemAssetName, ContentManager contentManager)
- {
- var itemAsset = XmlHelper.GetAssetElementFromXML(itemAssetName);
- var item = new Item()
- {
- AssetName = itemAssetName,
- Name = (string)itemAsset.Element("Name"),
- Description = (string)itemAsset.Element("Description"),
- GoldValue = (int)itemAsset.Element("GoldValue"),
- IconTextureName = (string)itemAsset.Element("IconTextureName"),
- IconTexture = contentManager.Load<Texture2D>(Path.Combine("Textures", "Gear", (string)itemAsset.Element("IconTextureName"))),
- MinimumCharacterLevel = int.Parse(itemAsset.Element("MinimumCharacterLevel").Value),
- Usage = itemAsset.Element("Usage") != null ? (ItemUsage)Enum.Parse(typeof(ItemUsage), (string)itemAsset.Element("Usage")) : default,
- IsOffensive = bool.Parse(itemAsset.Element("IsOffensive").Value),
- TargetDuration = int.Parse(itemAsset.Element("TargetDuration").Value),
- AdjacentTargets = int.Parse(itemAsset.Element("AdjacentTargets").Value),
- UsingCueName = (string)itemAsset.Element("UsingCueName"),
- TravelingCueName = (string)itemAsset.Element("TravelingCueName"),
- ImpactCueName = (string)itemAsset.Element("ImpactCueName"),
- BlockCueName = (string)itemAsset.Element("BlockCueName"),
- CreationSprite = itemAsset.Element("CreatingSprite") != null ? AnimatingSprite.Load(itemAsset.Element("CreatingSprite"), contentManager) : null,
- SpellSprite = itemAsset.Element("SpellSprite") != null ? AnimatingSprite.Load(itemAsset.Element("SpellSprite"), contentManager) : null,
- Overlay = itemAsset.Element("Overlay") != null ? AnimatingSprite.Load(itemAsset.Element("Overlay"), contentManager) : null,
- };
- return item;
- }
- /// <summary>
- /// Read an Item object from the content pipeline
- /// </summary>
- public class ItemReader : ContentTypeReader<Item>
- {
- protected override Item Read(ContentReader input, Item existingInstance)
- {
- Item item = existingInstance;
- if (item == null)
- {
- item = new Item();
- }
- // read gear settings
- input.ReadRawObject<Gear>(item as Gear);
- // read item settings
- item.Usage = (ItemUsage)input.ReadInt32();
- item.IsOffensive = input.ReadBoolean();
- item.TargetDuration = input.ReadInt32();
- item.TargetEffectRange = input.ReadObject<StatisticsRange>();
- item.AdjacentTargets = input.ReadInt32();
- item.UsingCueName = input.ReadString();
- item.TravelingCueName = input.ReadString();
- item.ImpactCueName = input.ReadString();
- item.BlockCueName = input.ReadString();
- item.CreationSprite = input.ReadObject<AnimatingSprite>();
- item.CreationSprite.SourceOffset = new Vector2(
- item.CreationSprite.FrameDimensions.X / 2,
- item.CreationSprite.FrameDimensions.Y);
- item.SpellSprite = input.ReadObject<AnimatingSprite>();
- item.SpellSprite.SourceOffset = new Vector2(
- item.SpellSprite.FrameDimensions.X / 2,
- item.SpellSprite.FrameDimensions.Y);
- item.Overlay = input.ReadObject<AnimatingSprite>();
- item.Overlay.SourceOffset = new Vector2(
- item.Overlay.FrameDimensions.X / 2,
- item.Overlay.FrameDimensions.Y);
- return item;
- }
- }
- }
- }
|