Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / buff / fragment / Buff_BulletRepel.cs
@小李xl 小李xl on 15 Mar 2024 1 KB buff系统重构中
  1.  
  2. using Godot;
  3.  
  4. [Buff("BulletRepel",
  5. "子弹击退 buff, " +
  6. "参数‘1’为击退增加类型: 1:具体击退值, 2:百分比击退值(小数), " +
  7. "参数‘2’为子弹增加的击退值")]
  8. public class Buff_BulletRepel : BuffFragment
  9. {
  10. private int _type;
  11. private float _value;
  12. public override void InitParam(float arg1, float arg2)
  13. {
  14. _type = (int)arg1;
  15. _value = arg2;
  16. }
  17.  
  18. public override void OnPickUpItem()
  19. {
  20. if (_type == 1)
  21. {
  22. Role.RoleState.CalcBulletRepelEvent += CalcBulletRepelEvent1;
  23. }
  24. else
  25. {
  26. Role.RoleState.CalcBulletRepelEvent += CalcBulletRepelEvent2;
  27. }
  28. }
  29. public override void OnRemoveItem()
  30. {
  31. if (_type == 1)
  32. {
  33. Role.RoleState.CalcBulletRepelEvent -= CalcBulletRepelEvent1;
  34. }
  35. else
  36. {
  37. Role.RoleState.CalcBulletRepelEvent -= CalcBulletRepelEvent2;
  38. }
  39. }
  40. private void CalcBulletRepelEvent1(float originRepel, RefValue<float> repel)
  41. {
  42. if (Role.WeaponPack.ActiveItem != null && Role.WeaponPack.ActiveItem.Attribute.IsMelee)
  43. {
  44. return;
  45. }
  46. repel.Value += _value;
  47. }
  48. private void CalcBulletRepelEvent2(float originRepel, RefValue<float> repel)
  49. {
  50. if (Role.WeaponPack.ActiveItem != null && Role.WeaponPack.ActiveItem.Attribute.IsMelee)
  51. {
  52. return;
  53. }
  54.  
  55. if (_value > 0)
  56. {
  57. repel.Value += originRepel * _value;
  58. }
  59. else
  60. {
  61. repel.Value = Mathf.Max(0, repel.Value + Mathf.FloorToInt(repel.Value * _value));
  62. }
  63. }
  64. }