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", "子弹击退 buff, 参数‘1’为击退增加类型: 1:具体击退值, 2:百分比击退值(小数), 参数‘2’为子弹增加的击退值")]
  5. public class Buff_BulletRepel : BuffFragment
  6. {
  7. private int _type;
  8. private float _value;
  9. public override void InitParam(float arg1, float arg2)
  10. {
  11. _type = (int)arg1;
  12. _value = arg2;
  13. }
  14.  
  15. public override void OnPickUpItem()
  16. {
  17. if (_type == 1)
  18. {
  19. Role.RoleState.CalcBulletRepelEvent += CalcBulletRepelEvent1;
  20. }
  21. else
  22. {
  23. Role.RoleState.CalcBulletRepelEvent += CalcBulletRepelEvent2;
  24. }
  25. }
  26. public override void OnRemoveItem()
  27. {
  28. if (_type == 1)
  29. {
  30. Role.RoleState.CalcBulletRepelEvent -= CalcBulletRepelEvent1;
  31. }
  32. else
  33. {
  34. Role.RoleState.CalcBulletRepelEvent -= CalcBulletRepelEvent2;
  35. }
  36. }
  37. private void CalcBulletRepelEvent1(float originRepel, RefValue<float> repel)
  38. {
  39. if (Role.WeaponPack.ActiveItem != null && Role.WeaponPack.ActiveItem.Attribute.IsMelee)
  40. {
  41. return;
  42. }
  43. repel.Value += _value;
  44. }
  45. private void CalcBulletRepelEvent2(float originRepel, RefValue<float> repel)
  46. {
  47. if (Role.WeaponPack.ActiveItem != null && Role.WeaponPack.ActiveItem.Attribute.IsMelee)
  48. {
  49. return;
  50. }
  51.  
  52. if (_value > 0)
  53. {
  54. repel.Value += originRepel * _value;
  55. }
  56. else
  57. {
  58. repel.Value = Mathf.Max(0, repel.Value - Mathf.FloorToInt(repel.Value * _value));
  59. }
  60. }
  61. }