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

Add preliminary StatsManager

parent 7de70203
No related branches found
No related tags found
No related merge requests found
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &5959683136170450115
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6628969328331147427}
- component: {fileID: 3799051240971953}
m_Layer: 0
m_Name: GlobalScripts
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &6628969328331147427
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5959683136170450115}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &3799051240971953
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5959683136170450115}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1f757c0257b830f4db4003340aceb7c3, type: 3}
m_Name:
m_EditorClassIdentifier:
fileFormatVersion: 2
guid: afeb708bd829d8a4aa0310ed2cd87a74
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum UpgradeTypes
{
ENEMY_HEALTH,
ENEMY_DAMAGE,
ENEMY_ARMOR,
MANA_COST,
}
class UpgradeData
{
public Upgrade upgrade;
public int count;
public int GetUnadjustedNextUpgradeCost()
{
return (int)(upgrade.baseCost * (1 + count * upgrade.costMultiplier));
}
public float GetTotalEffectMultiplier()
{
return 1 + count * upgrade.effectMultiplier;
}
}
public class StatsManager : MonoBehaviour
{
public static StatsManager instance { get; private set; }
EnemyStats currentEnemyStats;
PlayerStats currentPlayerStats;
[SerializeField] int currentMana;
[SerializeField] List<Upgrade> availableUpgrades;
Dictionary<UpgradeTypes, UpgradeData> upgrades = new Dictionary<UpgradeTypes, UpgradeData>();
public EnemyStats GetEnemyStats()
{
return currentEnemyStats;
}
public PlayerStats GetPlayerStats(int stage)
{
// TODO use `stage`
return currentPlayerStats;
}
public int GetMana()
{
return currentMana;
}
// Adjusts the given Mana cost based on the amount of Mana cost upgrades currently bought.
public int GetAdjustedManaCost(int cost)
{
return (int)(cost * upgrades[UpgradeTypes.MANA_COST].GetTotalEffectMultiplier());
}
public int GetNextUpgradeCost(UpgradeTypes type)
{
return GetAdjustedManaCost(upgrades[type].GetUnadjustedNextUpgradeCost());
}
// 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)))
{
return false;
}
upgrades[type].count++;
RecalculateStatMultipliers();
return true;
}
// Add (positive value) or spend (negative value) Mana.
public bool ModifyMana(int delta)
{
if (currentMana + delta < 0)
{
return false;
}
currentMana += delta;
return true;
}
void RecalculateStatMultipliers()
{
currentEnemyStats.healthMultiplier = upgrades[UpgradeTypes.ENEMY_HEALTH].GetTotalEffectMultiplier();
currentEnemyStats.damageMultiplier = upgrades[UpgradeTypes.ENEMY_DAMAGE].GetTotalEffectMultiplier();
currentEnemyStats.armorMultiplier = upgrades[UpgradeTypes.ENEMY_ARMOR].GetTotalEffectMultiplier();
}
void Awake()
{
if (instance == null)
{
instance = this;
}
else if (instance != this)
{
Destroy(gameObject);
}
DontDestroyOnLoad(gameObject);
foreach (Upgrade upgrade in availableUpgrades)
{
UpgradeData upgradeData = new UpgradeData();
upgrades.Add(upgrade.type, upgradeData);
}
currentEnemyStats.healthMultiplier = 1f;
currentEnemyStats.damageMultiplier = 1f;
currentEnemyStats.armorMultiplier = 1f;
currentPlayerStats.healthMultiplier = 1f;
currentPlayerStats.damageMultiplier = 1f;
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;
}
fileFormatVersion: 2
guid: 1f757c0257b830f4db4003340aceb7c3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 95ff68de1ef63ea4e960cad9ce01717d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
[CreateAssetMenu(menuName = "Upgrade")]
public class Upgrade : ScriptableObject
{
public UpgradeTypes type;
public string upgradeName;
public int baseCost;
public float costMultiplier;
public Sprite shopSprite;
[Tooltip("Multiplier of the stat that this Upgrade controls")] public float effectMultiplier;
}
fileFormatVersion: 2
guid: fcdf785d9cc66854b866905ab5edbb2e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment