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