Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using StatsSystem;
- using UnityEngine;
- //I would normally name this script "StatsKeeper" or "ActorStats" so I can use it on players and enemies
- //Player stats is less abstract and easier to learn from
- public class PlayerStats : MonoBehaviour
- {
- //We will only have two stats for this example
- public StatisticPoint HealthPoints = new StatisticPoint(100);
- public StatisticPoint Strength = new StatisticPoint(12);// 12 STR
- ////Special note: if you want these stats private you will have to make functions to change them
- //We use an list of status effects to allow effect stacking as an mechanic
- private List<StatusEffect> StatusEffectList = new List<StatusEffect>();
- void Start()
- {
- //Now lets add some effects on start
- StatusEffectList.Add(new Bleed());
- StatusEffectList.Add(new Bleed());
- //StatusEffectList.Add(new Weaken()); //Weaken will drastically reduce strength
- //StatusEffectList.Add(new Poison());
- StatusEffectList.Add(new Poison());
- //This will start the turn based simulation
- StartCoroutine(EverySecondIsATurn());
- }
- //Use a Coroutine to simulate a turn based game
- IEnumerator EverySecondIsATurn()
- {
- ////This is where the magic happens! we run DoEffect here but in your game it would be at the start or end of turn
- for (; ; )
- {
- //Run list backwards so we can remove effects without the need of a cleanup pass
- for (int i = StatusEffectList.Count - 1; i >= 0; i--)
- {
- //Do the thing
- StatusEffectList.ElementAt(i).DoEffect(this);
- //Remove condition, an item will just remove this without checking
- if (StatusEffectList.ElementAt(i).RemoveEffect() == true)
- {
- Debug.Log( string.Format("Effect expired:{0}", StatusEffectList.ElementAt(i)) );
- StatusEffectList.RemoveAt(i);
- }
- }
- //Now of course you would update the HUD:
- print(string.Format("Player Health is:{0}, and strength is:{1}", HealthPoints.GetValue(), Strength.GetValue()));
- yield return new WaitForSeconds(1f);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement