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

StatsManager: Public upgrade info, add CanModifyMana

parent 45c8e2aa
No related branches found
No related tags found
No related merge requests found
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
......@@ -10,20 +11,41 @@ public enum UpgradeTypes
MANA_COST,
}
class UpgradeData
public struct EnemyStats
{
public float healthMultiplier;
public float damageMultiplier;
public float armorMultiplier;
}
public struct PlayerStats
{
public float healthMultiplier;
public float damageMultiplier;
public float armorMultiplier;
}
public class UpgradeData
{
public Upgrade upgrade;
public int count;
public int GetUnadjustedNextUpgradeCost()
// How much it costs to purchase another one of this upgrade
public int GetNextUpgradeCost()
{
return (int)(upgrade.baseCost * (1 + count * upgrade.costMultiplier));
return StatsManager.instance.AdjustManaCost(GetUnadjustedNextUpgradeCost());
}
public float GetTotalEffectMultiplier()
{
return 1 + count * upgrade.effectMultiplier;
}
// You probably shouldn't call this outside this file.
public int GetUnadjustedNextUpgradeCost()
{
return (int)(upgrade.baseCost * (1 + count * upgrade.costMultiplier));
}
}
public class StatsManager : MonoBehaviour
......@@ -36,7 +58,9 @@ public class StatsManager : MonoBehaviour
[SerializeField] int currentMana;
[SerializeField] List<Upgrade> availableUpgrades;
Dictionary<UpgradeTypes, UpgradeData> upgrades = new Dictionary<UpgradeTypes, UpgradeData>();
// Information about currently available and purchased upgrades. Should only be read, not modified.
public Dictionary<UpgradeTypes, UpgradeData> upgrades = new Dictionary<UpgradeTypes, UpgradeData>();
public EnemyStats GetEnemyStats()
{
......@@ -55,20 +79,20 @@ public class StatsManager : MonoBehaviour
}
// Adjusts the given Mana cost based on the amount of Mana cost upgrades currently bought.
public int GetAdjustedManaCost(int cost)
public int AdjustManaCost(int cost)
{
return (int)(cost * upgrades[UpgradeTypes.MANA_COST].GetTotalEffectMultiplier());
}
public int GetNextUpgradeCost(UpgradeTypes type)
{
return GetAdjustedManaCost(upgrades[type].GetUnadjustedNextUpgradeCost());
return upgrades[type].GetNextUpgradeCost();
}
// Buys an upgrade, spending the required amount of Mana in the process. Returns false if not enough Mana is available.
public bool BuyUpgrade(UpgradeTypes type)
{
if (!ModifyMana(GetNextUpgradeCost(type)))
if (!ModifyMana(-GetNextUpgradeCost(type)))
{
return false;
}
......@@ -77,10 +101,10 @@ public class StatsManager : MonoBehaviour
return true;
}
// Add (positive value) or spend (negative value) Mana.
// Add (positive value) or spend (negative value) Mana. Returns false if not enough Mana is available to spend.
public bool ModifyMana(int delta)
{
if (currentMana + delta < 0)
if (!CanModifyMana(delta))
{
return false;
}
......@@ -88,6 +112,12 @@ public class StatsManager : MonoBehaviour
return true;
}
// If `delta` is negative, returns this amount of Mana can be spent. If `delta` is positive, this will always return `true`.
public bool CanModifyMana(int delta)
{
return currentMana + delta >= 0;
}
void RecalculateStatMultipliers()
{
currentEnemyStats.healthMultiplier = upgrades[UpgradeTypes.ENEMY_HEALTH].GetTotalEffectMultiplier();
......@@ -121,17 +151,3 @@ public class StatsManager : MonoBehaviour
currentPlayerStats.armorMultiplier = 1f;
}
}
public struct EnemyStats
{
public float healthMultiplier;
public float damageMultiplier;
public float armorMultiplier;
}
public struct PlayerStats
{
public float healthMultiplier;
public float damageMultiplier;
public float armorMultiplier;
}
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