Newer
Older
TheVengeance-Project-IADE-Unity2D / Assets / Scripts / Player / Stats / StatModifier.cs
@Rackday Rackday on 29 Oct 919 bytes Major Update
  1. using System;
  2. using MyCollections.Timer;
  3. namespace MyCollections.Stats
  4. {
  5. public abstract class StatModifier : IDisposable
  6. {
  7. public bool MarkedForRemoval { get; private set; }
  8. public event Action<StatModifier> OnDispose = delegate { };
  9. private CountdownTimer timer;
  10. protected StatModifier(float duration)
  11. {
  12. if (duration <= 0) return;
  13. //Sets the timer
  14. timer = new CountdownTimer(duration);
  15. timer.OnTimerStop += () => MarkedForRemoval = true; //Subscribe to the action
  16. timer.Start(); //Starts the timer
  17. }
  18. //Updates the timer
  19. public void Update(float deltaTime) => timer?.Tick(deltaTime);
  20. public abstract void Handle(object sender, Query query);
  21. public void Dispose()
  22. {
  23. MarkedForRemoval = true;
  24. OnDispose.Invoke(this);
  25. }
  26. }
  27. }