diff --git a/Assets/Scripts/StatsManager.cs b/Assets/Scripts/StatsManager.cs index e27103e39b372e5239969bbf578c372f2732b5c0..835fb6472f075a1af5c3d4b87853ca7406364035 100644 --- a/Assets/Scripts/StatsManager.cs +++ b/Assets/Scripts/StatsManager.cs @@ -50,12 +50,13 @@ public interface IManaChangeCallback void OnManaChanged(int oldValue, int newValue); } -public class StatsManager : MonoBehaviour +public class StatsManager : MonoBehaviour, IRoundCallback { public static StatsManager instance { get; private set; } [SerializeField] int currentMana; + int manaAtRoundStart; [SerializeField, Tooltip("When the AntiPlayer receives damage, how much of that damage is converted to Mana")] float antiPlayerDamageManaMultiplier = 100f; [SerializeField, Tooltip("When the AntiPlayer dies, how much mana to give")] @@ -186,4 +187,24 @@ public class StatsManager : MonoBehaviour armorMultiplier = 1f, }); } + + void Start() + { + RoundController.instance.roundCallbacks.Add(this); + } + + public void OnRoundStart() + { + manaAtRoundStart = currentMana; + } + + public void OnRoundEnd(bool won) + { + if (!won) + { + // Reset current Mana back to start value if round was lost + var gainedMana = currentMana - manaAtRoundStart; + ModifyMana(-gainedMana); + } + } } diff --git a/Assets/Scripts/Store/EnemySpawnController.cs b/Assets/Scripts/Store/EnemySpawnController.cs index 9869563a76e5beb938f8d300fbc0948e8efe9874..1166d7eeb91793fa22cc78a58633a959b958e52a 100644 --- a/Assets/Scripts/Store/EnemySpawnController.cs +++ b/Assets/Scripts/Store/EnemySpawnController.cs @@ -69,9 +69,9 @@ public class EnemySpawnController : MonoBehaviour public void OnEnemyMouseDown(string enemyName) { + SetEnemyToSpawnObject(enemyName); if (!RoundController.instance.roundRunning && StatsManager.instance.ModifyMana(-1 * (int)activeSpawn.enemyCost)) { - SetEnemyToSpawnObject(enemyName); dragObject.GetComponent<Image>().sprite = activeSpawn.EnemySprite; enemyImage = Instantiate(dragObject, GetPreviewWorldPosition(), Quaternion.identity, transform); }