Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / buff / effect / Eff_PiggyBank.cs
@小李xl 小李xl on 18 Mar 2024 1 KB 调整Prop
  1.  
  2. using Godot;
  3.  
  4. [EffectFragment("PiggyBank", "存钱罐, 使用后返还存入的金币, 参数1为返还金币的倍率(小数)")]
  5. public class Eff_PiggyBank : EffectFragment
  6. {
  7. private float _value;
  8. //当前存入的金币数量
  9. private float _currValue;
  10. public override void InitParam(float arg1)
  11. {
  12. _value = arg1;
  13. }
  14.  
  15. public override bool OnCheckUse()
  16. {
  17. return _currValue > 0;
  18. }
  19.  
  20. public override void OnUse()
  21. {
  22. var goldList = Utils.GetGoldList(Mathf.FloorToInt(_currValue * _value));
  23. foreach (var id in goldList)
  24. {
  25. var o = ObjectManager.GetActivityObject<Gold>(id);
  26. o.Position = Role.Position;
  27. o.Throw(0,
  28. Utils.Random.RandomRangeInt(50, 110),
  29. new Vector2(Utils.Random.RandomRangeInt(-20, 20), Utils.Random.RandomRangeInt(-20, 20)),
  30. 0
  31. );
  32. }
  33.  
  34. _currValue = 0;
  35. }
  36.  
  37. public override void OnPickUpItem()
  38. {
  39. Role.RoleState.CalcGetGoldEvent += OnCalcGetGoldEvent;
  40. }
  41.  
  42. public override void OnRemoveItem()
  43. {
  44. Role.RoleState.CalcGetGoldEvent -= OnCalcGetGoldEvent;
  45. }
  46. private void OnCalcGetGoldEvent(int origin, RefValue<int> refValue)
  47. {
  48. _currValue += refValue.Value;
  49. refValue.Value = 0;
  50. }
  51. }