using System; using System.Collections; using System.Collections.Generic; using System.Reflection; using UnityEngine; public class StatusEffects : MonoBehaviour, IEffectsHandler, IUpdatable { // Start is called before the first frame update public float speedGround; public float speedAir; public float dragStop; public float jumpForce; public float increasedGravity; public float maxHp; public float shield; public float damage; private List<AppliedEffectsStruct> appliedEffects = new List<AppliedEffectsStruct>(); private IEffectsHandler effectsHandler; private float timer; private void Start() { effectsHandler= GetComponent<IEffectsHandler>(); } void IEffectsHandler.ApplyEffect(EffectBase effect, GameObject source) { effect.ApplyEffect(this); appliedEffects.Add(new AppliedEffectsStruct(effect, source)); } void IEffectsHandler.RemoveEffect(EffectBase effect, GameObject source) { foreach(AppliedEffectsStruct ae in appliedEffects) { if((effect == ae.effect && source == ae.source) || (effect == null && source == ae.source)) { ae.effect.RemoveEffect(this); appliedEffects.Remove(ae); } } } void IEffectsHandler.RemoveEffect(int index) { appliedEffects[index].effect.RemoveEffect(this); appliedEffects.RemoveAt(index); } public void Updating() { timer -= Time.deltaTime; if (timer < 0) { for (int i = 0; i < appliedEffects.Count; i++) { if (appliedEffects[i].effect.duration != -100) { if (appliedEffects[i].currentTimer > 0) { AppliedEffectsStruct temp = appliedEffects[i]; temp.currentTimer -= 1; if (temp.currentTimer <= 0) { effectsHandler.RemoveEffect(i); } else appliedEffects[i] = temp; } } } timer = 1; } } }