Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / item / weapon / gun / Shotgun.cs
@小李xl 小李xl on 7 Nov 2022 3 KB 添加Role攻击目标
  1. using Godot;
  2.  
  3. [RegisterWeapon("1002", typeof(Shotgun.ShotgunAttribute))]
  4. public class Shotgun : Weapon
  5. {
  6.  
  7. private class ShotgunAttribute : WeaponAttribute
  8. {
  9. public ShotgunAttribute()
  10. {
  11. Name = "霰弹枪";
  12. Sprite = ResourcePath.resource_sprite_gun_gun2_png;
  13. Weight = 40;
  14. CenterPosition = new Vector2(0.4f, -2.6f);
  15. StartFiringSpeed = 120;
  16. StartScatteringRange = 30;
  17. FinalScatteringRange = 90;
  18. ScatteringRangeAddValue = 50f;
  19. ScatteringRangeBackSpeed = 50;
  20. //连发
  21. ContinuousShoot = false;
  22. AmmoCapacity = 7;
  23. MaxAmmoCapacity = 42;
  24. AloneReload = true;
  25. AloneReloadCanShoot = true;
  26. ReloadTime = 0.3f;
  27. //连发数量
  28. MinContinuousCount = 1;
  29. MaxContinuousCount = 1;
  30. //开火前延时
  31. DelayedTime = 0f;
  32. //攻击距离
  33. MinDistance = 500;
  34. MaxDistance = 600;
  35. //发射子弹数量
  36. MinFireBulletCount = 1;
  37. MaxFireBulletCount = 1;
  38. //抬起角度
  39. UpliftAngle = 15;
  40. MaxBacklash = 6;
  41. MinBacklash = 5;
  42. //枪身长度
  43. FirePosition = new Vector2(16, 1.5f);
  44. }
  45. }
  46. /// <summary>
  47. /// 弹壳预制体
  48. /// </summary>
  49. public PackedScene ShellPack;
  50.  
  51. public Shotgun(string id, WeaponAttribute attribute) : base(id, attribute)
  52. {
  53. ShellPack = ResourceManager.Load<PackedScene>(ResourcePath.prefab_weapon_shell_ShellCase_tscn);
  54. }
  55.  
  56. protected override void OnFire()
  57. {
  58. //创建一个弹壳
  59. var startPos = GlobalPosition + new Vector2(0, 5);
  60. var startHeight = 6;
  61. var direction = GlobalRotationDegrees + MathUtils.RandRangeInt(-30, 30) + 180;
  62. var xf = MathUtils.RandRangeInt(20, 60);
  63. var yf = MathUtils.RandRangeInt(60, 120);
  64. var rotate = MathUtils.RandRangeInt(-720, 720);
  65. var shell = new ShellCase();
  66. shell.Throw(new Vector2(5, 10), startPos, startHeight, direction, xf, yf, rotate, true);
  67. //创建抖动
  68. GameCamera.Main.ProcessDirectionalShake(Vector2.Right.Rotated(GlobalRotation) * 1.5f);
  69. //播放射击音效
  70. SoundManager.PlaySoundEffect("ordinaryBullet.ogg", this, 6f);
  71. }
  72.  
  73. protected override void OnShoot(float fireRotation)
  74. {
  75. for (int i = 0; i < 5; i++)
  76. {
  77. //创建子弹
  78. //CreateBullet(BulletPack, FirePoint.GlobalPosition, fireRotation + MathUtils.RandRange(-20 / 180f * Mathf.Pi, 20 / 180f * Mathf.Pi));
  79. var bullet = new Bullet(
  80. ResourcePath.prefab_weapon_bullet_Bullet_tscn,
  81. MathUtils.RandRange(Attribute.MinDistance, Attribute.MaxDistance),
  82. FirePoint.GlobalPosition,
  83. fireRotation + MathUtils.RandRange(-20 / 180f * Mathf.Pi, 20 / 180f * Mathf.Pi),
  84. Master != null ? Master.AttackLayer : Role.DefaultAttackLayer
  85. );
  86. bullet.PutDown();
  87. }
  88. }
  89.  
  90. protected override void OnReload()
  91. {
  92.  
  93. }
  94.  
  95. protected override void OnReloadFinish()
  96. {
  97.  
  98. }
  99.  
  100. protected override void OnDownTrigger()
  101. {
  102. }
  103.  
  104. protected override void OnUpTrigger()
  105. {
  106.  
  107. }
  108.  
  109. protected override void OnPickUp(Role master)
  110. {
  111.  
  112. }
  113.  
  114. protected override void OnRemove()
  115. {
  116.  
  117. }
  118.  
  119. protected override void OnActive()
  120. {
  121.  
  122. }
  123.  
  124. protected override void OnConceal()
  125. {
  126.  
  127. }
  128. }