Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / item / weapon / gun / Gun.cs
@小李xl 小李xl on 14 Feb 2023 4 KB ai射击频率修改
  1. using Godot;
  2.  
  3. /// <summary>
  4. /// 普通的枪
  5. /// </summary>
  6. [RegisterWeapon("1001", typeof(Gun.RifleAttribute))]
  7. [RegisterWeapon("1003", typeof(Gun.PistolAttribute))]
  8. public partial class Gun : Weapon
  9. {
  10. //步枪属性数据
  11. private class RifleAttribute : WeaponAttribute
  12. {
  13. public RifleAttribute()
  14. {
  15. Name = "步枪";
  16. Sprite2D = ResourcePath.resource_sprite_gun_gun4_png;
  17. Weight = 40;
  18. CenterPosition = new Vector2(0.4f, -2.6f);
  19. StartFiringSpeed = 480;
  20. StartScatteringRange = 30;
  21. FinalScatteringRange = 90;
  22. ScatteringRangeAddValue = 2f;
  23. ScatteringRangeBackSpeed = 40;
  24. //连发
  25. ContinuousShoot = true;
  26. AmmoCapacity = 30;
  27. StandbyAmmoCapacity = 30 * 3;
  28. MaxAmmoCapacity = 30 * 3;
  29. //扳机检测间隔
  30. TriggerInterval = 0f;
  31.  
  32. //开火前延时
  33. DelayedTime = 0f;
  34. //攻击距离
  35. MinDistance = 300;
  36. MaxDistance = 400;
  37. //发射子弹数量
  38. MinFireBulletCount = 1;
  39. MaxFireBulletCount = 1;
  40. //抬起角度
  41. UpliftAngle = 10;
  42. //开火位置
  43. FirePosition = new Vector2(16, 2);
  44. AiUseAttribute = Clone();
  45. AiUseAttribute.DelayedTime = 1f;
  46. AiUseAttribute.TriggerInterval = 4f;
  47. AiUseAttribute.ContinuousShoot = true;
  48. //连发数量
  49. AiUseAttribute.MinContinuousCount = 3;
  50. AiUseAttribute.MaxContinuousCount = 3;
  51. }
  52. }
  53.  
  54. //手枪属性数据
  55. private class PistolAttribute : WeaponAttribute
  56. {
  57. public PistolAttribute()
  58. {
  59. Name = "手枪";
  60. Sprite2D = ResourcePath.resource_sprite_gun_gun3_png;
  61. Weight = 20;
  62. CenterPosition = new Vector2(0.4f, -2.6f);
  63. WeightType = WeaponWeightType.DeputyWeapon;
  64. StartFiringSpeed = 300;
  65. FinalFiringSpeed = 300;
  66. StartScatteringRange = 5;
  67. FinalScatteringRange = 60;
  68. ScatteringRangeAddValue = 8f;
  69. ScatteringRangeBackSpeed = 40;
  70. //连发
  71. ContinuousShoot = false;
  72. AmmoCapacity = 12;
  73. StandbyAmmoCapacity = 72;
  74. MaxAmmoCapacity = 72;
  75. //扳机检测间隔
  76. TriggerInterval = 0.1f;
  77. //连发数量
  78. MinContinuousCount = 1;
  79. MaxContinuousCount = 1;
  80. //开火前延时
  81. DelayedTime = 0f;
  82. //攻击距离
  83. MinDistance = 250;
  84. MaxDistance = 300;
  85. //发射子弹数量
  86. MinFireBulletCount = 1;
  87. MaxFireBulletCount = 1;
  88. //抬起角度
  89. UpliftAngle = 30;
  90. //开火位置
  91. FirePosition = new Vector2(10, 2);
  92.  
  93. AiUseAttribute = Clone();
  94. AiUseAttribute.TriggerInterval = 2f;
  95. }
  96. }
  97.  
  98. public Gun(string typeId, WeaponAttribute attribute): base(typeId, attribute)
  99. {
  100. }
  101.  
  102. protected override void OnFire()
  103. {
  104. //创建一个弹壳
  105. var startHeight = 6;
  106. var direction = GlobalRotationDegrees + Utils.RandRangeInt(-30, 30) + 180;
  107. var xf = Utils.RandRangeInt(20, 60);
  108. var yf = Utils.RandRangeInt(60, 120);
  109. var rotate = Utils.RandRangeInt(-720, 720);
  110. var shell = new ShellCase();
  111. shell.Throw(new Vector2(10, 5), Master.GlobalPosition, startHeight, direction, xf, yf, rotate, true);
  112. if (Master == GameApplication.Instance.RoomManager.Player)
  113. {
  114. //创建抖动
  115. GameCamera.Main.ProcessDirectionalShake(Vector2.Right.Rotated(GlobalRotation) * 2f);
  116. }
  117.  
  118. //创建开火特效
  119. var packedScene = ResourceManager.Load<PackedScene>(ResourcePath.prefab_effect_ShotFire_tscn);
  120. var sprite = packedScene.Instantiate<Sprite2D>();
  121. sprite.GlobalPosition = FirePoint.GlobalPosition;
  122. sprite.GlobalRotation = FirePoint.GlobalRotation;
  123. sprite.AddToActivityRoot(RoomLayerEnum.YSortLayer);
  124.  
  125. //播放射击音效
  126. SoundManager.PlaySoundEffectPosition(ResourcePath.resource_sound_sfx_ordinaryBullet2_mp3, GameApplication.Instance.ViewToGlobalPosition(GlobalPosition), -8);
  127. }
  128.  
  129. protected override void OnShoot(float fireRotation)
  130. {
  131. //创建子弹
  132. //CreateBullet(BulletPack, FirePoint.GlobalPosition, fireRotation);
  133. var bullet = new Bullet(
  134. ResourcePath.prefab_weapon_bullet_Bullet_tscn,
  135. 350,
  136. Utils.RandfRange(Attribute.MinDistance, Attribute.MaxDistance),
  137. FirePoint.GlobalPosition,
  138. fireRotation,
  139. GetAttackLayer()
  140. );
  141. bullet.PutDown(RoomLayerEnum.YSortLayer);
  142. }
  143. }