Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- //Stats allows us to keep track of player data or any data the game needs
- namespace StatsSystem //Name spaces are just a way of sorting all these classes you will need for a game
- {
- //We want to know that our statistics data is limited to keep order
- public class StatisticPoint
- {
- private int MaxValue;
- private int CurrentValue;
- //Constructors for making the stat
- public StatisticPoint(int SizeOfStat)
- {
- MaxValue = SizeOfStat;
- CurrentValue = SizeOfStat;
- }
- //Add value safely to the stat, we can use this to subtract also
- public void AddToStat(int Amount)
- {
- CurrentValue += Amount;
- CurrentValue = Mathf.Clamp(CurrentValue, 0, MaxValue);
- }
- //Set value safely to the stat, for effects that don't stack, must be positive!
- public void SetToStat(int Amount)
- {
- if (Amount < 0)
- {
- Debug.LogError("Used a negative number to set a stat for the game");
- }
- else
- {
- CurrentValue = Mathf.Clamp(Amount, 0, MaxValue);
- }
- }
- public int GetValue() { return CurrentValue; }
- public int GetMaxValue() { return MaxValue; }
- }
- }
- //For now lets just re-use the name space to split them for readability, again a name space is like a group
- //I would usually use two scripts to keep the status effects separate from the stats them self
- namespace StatsSystem
- {
- //Think as an abstract class as a guide or contract for how classes derived from it should work
- public abstract class StatusEffect //The master class that all status effect are derived from
- {
- //We use the stat class we made before to target the exact stats we need
- public abstract void DoEffect(PlayerStats Target);
- //Every effect must implement the idea of removal (even if a effect that can't be removed must think about it)
- public abstract bool RemoveEffect();
- }
- //Health loss over time
- public class Bleed : StatusEffect
- {
- int TurnCount = 3;
- public override void DoEffect(PlayerStats Target)
- {
- Target.HealthPoints.AddToStat(-1);
- TurnCount -= 1;
- }
- //Will run out
- public override bool RemoveEffect()
- {
- if (TurnCount < 1)
- {
- return true;
- }
- return false;
- }
- }
- //Strength loss over time
- public class Weaken : StatusEffect
- {
- int TurnCount = 1;
- public override void DoEffect(PlayerStats Target)
- {
- //subtracts 10% of the stat value
- float Influence = (Target.Strength.GetMaxValue() / 100f) * 10f;
- Target.Strength.AddToStat((int)-Influence); //Will -1 from 12 because 12/100 = 0,12 * 10 = 1,2 to int -> 1
- }
- //Will run out
- public override bool RemoveEffect()
- {
- if (TurnCount < 1)
- {
- return true;
- }
- return false;
- }
- }
- //Health loss over time and strength set to a low value
- public class Poison : StatusEffect
- {
- public override void DoEffect(PlayerStats Target)
- {
- Target.HealthPoints.AddToStat(-1);
- float TenPercent = (Target.Strength.GetMaxValue() / 100f) * 10f;
- //Only subtract strength when it is 10% or more of max, to allow other effects to stack and reduce it bellow 10%
- if (Target.Strength.GetValue() > TenPercent)
- {
- //sets stength to 10% of max, without subtracting more strength
- Target.Strength.SetToStat((int)TenPercent);
- }
- }
- //Needs to be removed by item or the player will loose health till dead
- public override bool RemoveEffect()
- {
- return false;
- }
- }
- }
Add Comment
Please, Sign In to add comment