Weapon.cs 4.3 KB

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