Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / activity / bullet / special / SpecialBullet0001.cs
  1.  
  2. using System;
  3. using Config;
  4. using Godot;
  5.  
  6. /// <summary>
  7. /// 垂直往填上飞, 落在地上爆炸产生一个子弹圈
  8. /// </summary>
  9. [Tool]
  10. public partial class SpecialBullet0001 : ActivityObject, IPoolItem
  11. {
  12. /// <summary>
  13. /// 创建子分裂子弹时的回调
  14. /// </summary>
  15. public event Action<IBullet> OnCreateSplitBulletEvent;
  16. public bool IsRecycled { get; set; }
  17. public string Logotype { get; set; }
  18. private string _bulletId;
  19. private int _bulletCount;
  20. private Role _role;
  21. private Vector2 _targetPosition;
  22. public void InitBullet(string bulletId, int bulletCount, Role role, Vector2 targetPosition)
  23. {
  24. _bulletId = bulletId;
  25. _bulletCount = bulletCount;
  26. _role = role;
  27. _targetPosition = targetPosition;
  28. }
  29.  
  30. protected override void OnThrowMaxHeight(float height)
  31. {
  32. Position = _targetPosition;
  33. VerticalSpeed = -50;
  34. ShowShadowSprite();
  35. }
  36.  
  37. protected override void OnFallToGround()
  38. {
  39. if (!string.IsNullOrEmpty(_bulletId) && (_role != null && !_role.IsDestroyed))
  40. {
  41. var bulletBase = ExcelConfig.BulletBase_Map[_bulletId];
  42. var bulletData = FireManager.GetBulletData(_role, 0, bulletBase);
  43. //创建分裂子弹
  44. var a = Mathf.Pi * 2 / _bulletCount;
  45. for (var i = 0; i < _bulletCount; i++)
  46. {
  47. var clone = bulletData.Clone();
  48. clone.Rotation = a * i;
  49. clone.Position = Position + new Vector2(5, 0).Rotated(clone.Rotation);
  50. var shootBullet = FireManager.ShootBullet(clone, clone.TriggerRole.Camp);
  51. if (OnCreateSplitBulletEvent != null)
  52. {
  53. OnCreateSplitBulletEvent(shootBullet);
  54. }
  55. }
  56. }
  57. //执行回收
  58. ObjectPool.Reclaim(this);
  59. }
  60. public void OnReclaim()
  61. {
  62. Visible = false;
  63. GetParent().CallDeferred(Node.MethodName.RemoveChild, this);
  64. }
  65.  
  66. public void OnLeavePool()
  67. {
  68. OnCreateSplitBulletEvent = null;
  69. Visible = true;
  70. _role = null;
  71. Altitude = 0;
  72. VerticalSpeed = 0;
  73. MoveController.ClearForce();
  74. MoveController.BasisVelocity = Vector2.Zero;
  75. Velocity = Vector2.Zero;
  76. _bulletId = null;
  77. }
  78. }