using System; using MyCollections.Timer; namespace MyCollections.Stats { public abstract class StatModifier : IDisposable { public bool MarkedForRemoval { get; private set; } public event Action<StatModifier> OnDispose = delegate { }; private CountdownTimer timer; protected StatModifier(float duration) { if (duration <= 0) return; //Sets the timer timer = new CountdownTimer(duration); timer.OnTimerStop += () => MarkedForRemoval = true; //Subscribe to the action timer.Start(); //Starts the timer } //Updates the timer public void Update(float deltaTime) => timer?.Tick(deltaTime); public abstract void Handle(object sender, Query query); public void Dispose() { MarkedForRemoval = true; OnDispose.Invoke(this); } } }