Weapon.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // Weapon.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;
  12. using Microsoft.Xna.Framework.Content;
  13. using Microsoft.Xna.Framework.Graphics;
  14. #endregion
  15. namespace RolePlayingGameData
  16. {
  17. /// <summary>
  18. /// Equipment that can be equipped on a FightingCharacter
  19. /// to improve their physical damage.
  20. /// </summary>
  21. public class Weapon : Equipment
  22. {
  23. #region Description Data
  24. /// <summary>
  25. /// Builds and returns a string describing the power of this weapon.
  26. /// </summary>
  27. public override string GetPowerText()
  28. {
  29. return "Weapon Attack: " + TargetDamageRange.ToString();
  30. }
  31. #endregion
  32. #region Target Damage Data
  33. /// <summary>
  34. /// The range of health damage applied by this weapon to its target.
  35. /// </summary>
  36. /// <remarks>Damage range values are positive, and will be subtracted.</remarks>
  37. private Int32Range targetDamageRange;
  38. /// <summary>
  39. /// The range of health damage applied by this weapon to its target.
  40. /// </summary>
  41. /// <remarks>Damage range values are positive, and will be subtracted.</remarks>
  42. public Int32Range TargetDamageRange
  43. {
  44. get { return targetDamageRange; }
  45. set { targetDamageRange = value; }
  46. }
  47. #endregion
  48. #region Sound Effects Data
  49. /// <summary>
  50. /// The name of the sound effect cue played when the weapon is swung.
  51. /// </summary>
  52. private string swingCueName;
  53. /// <summary>
  54. /// The name of the sound effect cue played when the weapon is swung.
  55. /// </summary>
  56. public string SwingCueName
  57. {
  58. get { return swingCueName; }
  59. set { swingCueName = value; }
  60. }
  61. /// <summary>
  62. /// The name of the sound effect cue played when the weapon hits its target.
  63. /// </summary>
  64. private string hitCueName;
  65. /// <summary>
  66. /// The name of the sound effect cue played when the weapon hits its target.
  67. /// </summary>
  68. public string HitCueName
  69. {
  70. get { return hitCueName; }
  71. set { hitCueName = value; }
  72. }
  73. /// <summary>
  74. /// The name of the sound effect cue played when the weapon is blocked.
  75. /// </summary>
  76. private string blockCueName;
  77. /// <summary>
  78. /// The name of the sound effect cue played when the weapon is blocked.
  79. /// </summary>
  80. public string BlockCueName
  81. {
  82. get { return blockCueName; }
  83. set { blockCueName = value; }
  84. }
  85. #endregion
  86. #region Graphics Data
  87. /// <summary>
  88. /// The overlay sprite for this weapon.
  89. /// </summary>
  90. private AnimatingSprite overlay;
  91. /// <summary>
  92. /// The overlay sprite for this weapon.
  93. /// </summary>
  94. public AnimatingSprite Overlay
  95. {
  96. get { return overlay; }
  97. set { overlay = value; }
  98. }
  99. #endregion
  100. #region Content Type Reader
  101. /// <summary>
  102. /// Read the Weapon type from the content pipeline.
  103. /// </summary>
  104. public class WeaponReader : ContentTypeReader<Weapon>
  105. {
  106. /// <summary>
  107. /// Read the Weapon type from the content pipeline.
  108. /// </summary>
  109. protected override Weapon Read(ContentReader input, Weapon existingInstance)
  110. {
  111. Weapon weapon = existingInstance;
  112. if (weapon == null)
  113. {
  114. weapon = new Weapon();
  115. }
  116. // read the gear settings
  117. input.ReadRawObject<Equipment>(weapon as Equipment);
  118. // read the weapon settings
  119. weapon.TargetDamageRange = input.ReadObject<Int32Range>();
  120. weapon.SwingCueName = input.ReadString();
  121. weapon.HitCueName = input.ReadString();
  122. weapon.BlockCueName = input.ReadString();
  123. weapon.Overlay = input.ReadObject<AnimatingSprite>();
  124. weapon.Overlay.SourceOffset = new Vector2(
  125. weapon.Overlay.FrameDimensions.X / 2,
  126. weapon.Overlay.FrameDimensions.Y);
  127. return weapon;
  128. }
  129. }
  130. #endregion
  131. }
  132. }