You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Bullet.cs 4.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using Preparation.Interface;
  2. using Preparation.Utility;
  3. using System.Threading;
  4. namespace GameClass.GameObj
  5. {
  6. public abstract class Bullet : ObjOfCharacter
  7. {
  8. /// <summary>
  9. /// //攻击力
  10. /// </summary>
  11. public abstract double BulletBombRange { get; }
  12. public abstract double AttackDistance { get; }
  13. protected int ap;
  14. public int AP
  15. {
  16. get => Interlocked.CompareExchange(ref ap, 0, 0);
  17. }
  18. public void AddAP(int addAp)
  19. {
  20. Interlocked.Add(ref ap, addAp);
  21. }
  22. public abstract int Speed { get; }
  23. public abstract bool IsRemoteAttack { get; }
  24. public abstract int CastTime { get; }
  25. public abstract int Backswing { get; }
  26. public abstract int RecoveryFromHit { get; }
  27. public abstract int CD { get; }
  28. public abstract int MaxBulletNum { get; }
  29. private readonly bool hasSpear;
  30. /// <summary>
  31. /// 是否有矛
  32. /// </summary>
  33. public bool HasSpear => hasSpear;
  34. /// <summary>
  35. /// </summary>
  36. /// <param name="target">被尝试攻击者</param>
  37. /// <returns>是否可以攻击到</returns>
  38. public abstract bool CanAttack(GameObj target);
  39. public abstract bool CanBeBombed(GameObjType gameObjType);
  40. public override bool IgnoreCollideExecutor(IGameObj targetObj)
  41. {
  42. if (targetObj == Parent) return true;
  43. if (targetObj.Type == GameObjType.Gadget || targetObj.Type == GameObjType.Bullet)
  44. return true;
  45. return false;
  46. }
  47. public Bullet(Character player, int radius, XY Position) :
  48. base(Position, radius, GameObjType.Bullet)
  49. {
  50. this.ReSetCanMove(true);
  51. this.MoveSpeed = this.Speed;
  52. this.hasSpear = player.TryUseSpear();
  53. this.Parent = player;
  54. }
  55. public override bool IsRigid => true; // 默认为true
  56. public override ShapeType Shape => ShapeType.Circle; // 默认为圆形
  57. public abstract BulletType TypeOfBullet { get; }
  58. }
  59. public static class BulletFactory
  60. {
  61. public static Bullet? GetBullet(Character character, XY pos, BulletType bulletType)
  62. {
  63. switch (bulletType)
  64. {
  65. case BulletType.FlyingKnife:
  66. return new FlyingKnife(character, pos);
  67. case BulletType.CommonAttackOfGhost:
  68. return new CommonAttackOfGhost(character, pos);
  69. case BulletType.JumpyDumpty:
  70. return new JumpyDumpty(character, pos);
  71. case BulletType.BombBomb:
  72. return new BombBomb(character, pos);
  73. default:
  74. return null;
  75. }
  76. }
  77. public static int BulletRadius(BulletType bulletType)
  78. {
  79. switch (bulletType)
  80. {
  81. case BulletType.FlyingKnife:
  82. default:
  83. return GameData.bulletRadius;
  84. }
  85. }
  86. public static int BulletCD(BulletType bulletType)
  87. {
  88. switch (bulletType)
  89. {
  90. case BulletType.CommonAttackOfGhost:
  91. return CommonAttackOfGhost.cd;
  92. case BulletType.FlyingKnife:
  93. return FlyingKnife.cd;
  94. case BulletType.BombBomb:
  95. return BombBomb.cd;
  96. case BulletType.JumpyDumpty:
  97. return JumpyDumpty.cd;
  98. default:
  99. return GameData.basicCD;
  100. }
  101. }
  102. public static int BulletNum(BulletType bulletType)
  103. {
  104. switch (bulletType)
  105. {
  106. case BulletType.CommonAttackOfGhost:
  107. return CommonAttackOfGhost.maxBulletNum;
  108. case BulletType.FlyingKnife:
  109. return FlyingKnife.maxBulletNum;
  110. case BulletType.BombBomb:
  111. return BombBomb.maxBulletNum;
  112. case BulletType.JumpyDumpty:
  113. return JumpyDumpty.maxBulletNum;
  114. default:
  115. return 0;
  116. }
  117. }
  118. }
  119. }