Skip to content
Snippets Groups Projects
Verified Commit 1aca14bc authored by Adrian Paschkowski's avatar Adrian Paschkowski :thinking:
Browse files

Reset Mana on round loss

parent 594d4e3f
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
}
}
......@@ -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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment