Equipment.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //-----------------------------------------------------------------------------
  2. // Equipment.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using Microsoft.Xna.Framework.Content;
  11. using Microsoft.Xna.Framework.Graphics;
  12. namespace RolePlaying.Data
  13. {
  14. /// <summary>
  15. /// Gear that may be equipped onto a FightingCharacter.
  16. /// </summary>
  17. public class Equipment : Gear
  18. {
  19. /// <summary>
  20. /// The statistics buff applied by this equipment to its owner.
  21. /// </summary>
  22. /// <remarks>Buff values are positive, and will be added.</remarks>
  23. private StatisticsValue ownerBuffStatistics = new StatisticsValue();
  24. /// <summary>
  25. /// The statistics buff applied by this equipment to its owner.
  26. /// </summary>
  27. /// <remarks>Buff values are positive, and will be added.</remarks>
  28. [ContentSerializer(Optional = true)]
  29. public StatisticsValue OwnerBuffStatistics
  30. {
  31. get { return ownerBuffStatistics; }
  32. set { ownerBuffStatistics = value; }
  33. }
  34. public static Equipment Load(string equipmentAssetName, ContentManager contentManager)
  35. {
  36. var equipmentAsset = XmlHelper.GetAssetElementFromXML(equipmentAssetName);
  37. var equipment = new Equipment()
  38. {
  39. AssetName = equipmentAssetName,
  40. Name = (string)equipmentAsset.Element("Name"),
  41. Description = (string)equipmentAsset.Element("Description"),
  42. GoldValue = (int)equipmentAsset.Element("GoldValue"),
  43. IconTextureName = (string)equipmentAsset.Element("IconTextureName"),
  44. IconTexture = contentManager.Load<Texture2D>(Path.Combine("Textures", "Gear", (string)equipmentAsset.Element("IconTextureName"))),
  45. MinimumCharacterLevel = int.Parse(equipmentAsset.Element("MinimumCharacterLevel").Value),
  46. };
  47. return equipment;
  48. }
  49. /// <summary>
  50. /// Read the Equipment type from the content pipeline.
  51. /// </summary>
  52. public class EquipmentReader : ContentTypeReader<Equipment>
  53. {
  54. /// <summary>
  55. /// Read the Equipment type from the content pipeline.
  56. /// </summary>
  57. protected override Equipment Read(ContentReader input,
  58. Equipment existingInstance)
  59. {
  60. Equipment equipment = existingInstance;
  61. if (equipment == null)
  62. {
  63. throw new ArgumentException(
  64. "Unable to create new Equipment objects.");
  65. }
  66. // read the gear settings
  67. input.ReadRawObject<Gear>(equipment as Gear);
  68. // read the equipment settings
  69. equipment.OwnerBuffStatistics = input.ReadObject<StatisticsValue>();
  70. return equipment;
  71. }
  72. }
  73. }
  74. }