Armor.cs 3.7 KB

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