Skip to content

Instantly share code, notes, and snippets.

@SenpaiRar
Last active May 2, 2019 04:13
Show Gist options
  • Save SenpaiRar/0c34462bc948fa81875c6ab61a72e958 to your computer and use it in GitHub Desktop.
Save SenpaiRar/0c34462bc948fa81875c6ab61a72e958 to your computer and use it in GitHub Desktop.
The Modifer Manager is the script that takes every modifier and runs the four components inside each modifier.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Modifier_Manager : MonoBehaviour
{
public Player_Manager Player; //Every modifier needs a Player_Mangager, so we create one here instead of getting it for each modifier
public List<Modifier_Template> Debuffs = new List<Modifier_Template>(); //We create a list of modifiers
//Which holds the list of modifier we can go through
//and execute their code.
public float Tickrate; //The modifiers are run every number of seconds, so we create this variable to allow greater control
void Start()
{
///We add every modifier that will be run to the previously created list. They're created with the new keyword, making sure to put in a float variable in the constrcutor
Debuffs.Add(new Sluggishness(0.5f));
Debuffs.Add(new ShortSightedness(2.5f));
Debuffs.Add(new Starvation(5));
Debuffs.Add(new Richness(5.0f));
Player = GetComponent<Player_Manager>();
StartCoroutine(UpdateModifiers());
}
//Using a coroutine, we run through every modifier every Tickrate number of seconds, running the code inside each component.
IEnumerator UpdateModifiers() //TODO:Get the system to restore regular stats after a certain amount of time
{
for (; ;) //This loops infinitely
{
foreach (Modifier_Template x in Debuffs) //We go through every Modifier_Template object in the list, naming it x in the loop
{ //This lets us go through a list, executing code
if (x.ConditionMet(Player)) //We check if the condition for the modifier is met
{
x.AttributeChange(Player); //If it, we execute the code to affect the Player_Manager.
}
if(!x.ConditionMet(Player)) //If the condition for the modifier isn't met
{
x.EndChange(Player); //We end the change
}
}
yield return new WaitForSeconds(Tickrate); //We then wait Tickrate seconds
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment