Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / buff / fragment / Buff_Damage.cs
@小李xl 小李xl on 14 Mar 2024 1 KB buff系统重构中
  1.  
  2. using Godot;
  3.  
  4. /// <summary>
  5. /// 提升伤害buff
  6. /// </summary>
  7. [Buff("Damage", "提升伤害buff, 参数‘1’为伤害增加类型: 1:具体伤害, 2:百分比伤害(小数), 参数‘2’为增益伤害值")]
  8. public class Buff_Damage : 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.CalcDamageEvent += CalcDamage1;
  23. }
  24. else
  25. {
  26. Role.RoleState.CalcDamageEvent += CalcDamage2;
  27. }
  28. }
  29.  
  30. public override void OnRemoveItem()
  31. {
  32. if (_type == 1)
  33. {
  34. Role.RoleState.CalcDamageEvent -= CalcDamage1;
  35. }
  36. else
  37. {
  38. Role.RoleState.CalcDamageEvent -= CalcDamage2;
  39. }
  40. }
  41.  
  42. private void CalcDamage1(int originDamage, RefValue<int> refValue)
  43. {
  44. refValue.Value += Mathf.CeilToInt(_value);
  45. }
  46. private void CalcDamage2(int originDamage, RefValue<int> refValue)
  47. {
  48. refValue.Value += Mathf.CeilToInt(originDamage * _value);
  49. }
  50. }