Armor.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //-----------------------------------------------------------------------------
  2. // Armor.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using System;
  8. using Microsoft.Xna.Framework.Content;
  9. using Microsoft.Xna.Framework.Graphics;
  10. namespace RolePlaying.Data
  11. {
  12. /// <summary>
  13. /// Equipment that can be equipped on a FightingCharacter
  14. /// to improve their defense.
  15. /// </summary>
  16. public class Armor : Equipment
  17. {
  18. /// <summary>
  19. /// Slots that a piece of armor may fill on a character.
  20. /// </summary>
  21. /// <remarks>Only one piece may fill a slot at the same time.</remarks>
  22. public enum ArmorSlot
  23. {
  24. Helmet,
  25. Shield,
  26. Torso,
  27. Boots,
  28. };
  29. /// <summary>
  30. /// The slot that this armor fills.
  31. /// </summary>
  32. private ArmorSlot slot;
  33. /// <summary>
  34. /// The slot that this armor fills.
  35. /// </summary>
  36. public ArmorSlot Slot
  37. {
  38. get { return slot; }
  39. set { slot = value; }
  40. }
  41. /// <summary>
  42. /// Builds and returns a string describing the power of this armor.
  43. /// </summary>
  44. public override string GetPowerText()
  45. {
  46. return "Weapon Defense: " + OwnerHealthDefenseRange.ToString() +
  47. "\nMagic Defense: " + OwnerMagicDefenseRange.ToString();
  48. }
  49. /// <summary>
  50. /// The range of health defense provided by this armor to its owner.
  51. /// </summary>
  52. private Int32Range ownerHealthDefenseRange;
  53. /// <summary>
  54. /// The range of health defense provided by this armor to its owner.
  55. /// </summary>
  56. public Int32Range OwnerHealthDefenseRange
  57. {
  58. get { return ownerHealthDefenseRange; }
  59. set { ownerHealthDefenseRange = value; }
  60. }
  61. /// <summary>
  62. /// The range of magic defense provided by this armor to its owner.
  63. /// </summary>
  64. private Int32Range ownerMagicDefenseRange;
  65. /// <summary>
  66. /// The range of magic defense provided by this armor to its owner.
  67. /// </summary>
  68. public Int32Range OwnerMagicDefenseRange
  69. {
  70. get { return ownerMagicDefenseRange; }
  71. set { ownerMagicDefenseRange = value; }
  72. }
  73. /// <summary>
  74. /// Read the Weapon type from the content pipeline.
  75. /// </summary>
  76. public class ArmorReader : ContentTypeReader<Armor>
  77. {
  78. protected override Armor Read(ContentReader input, Armor existingInstance)
  79. {
  80. Armor armor = existingInstance;
  81. if (armor == null)
  82. {
  83. armor = new Armor();
  84. }
  85. // read the gear settings
  86. input.ReadRawObject<Equipment>(armor as Equipment);
  87. // read armor settings
  88. armor.Slot = (ArmorSlot)input.ReadInt32();
  89. armor.OwnerHealthDefenseRange = input.ReadObject<Int32Range>();
  90. armor.OwnerMagicDefenseRange = input.ReadObject<Int32Range>();
  91. return armor;
  92. }
  93. }
  94. }
  95. }