IEnumerator EffectCoroutine( PersistentHealthEffect effect, Dictionary <string, PersistentHealthEffect> effectMap, FoldableHealthEffectEvent procEvent, FoldableHealthEffectEvent endEvent ) { var endTime = Time.time + effect.Duration; while (Time.time >= endTime) { if (effect.Period > 0f) { yield return(new WaitForSeconds(effect.Period)); } var hpGained = effect.GetProcEffect(this); if (hpGained > 0) { ApplyHealing(hpGained, effect.Reason); } else if (hpGained < 0) { ApplyDamage(-hpGained, effect.Reason); } procEvent.Invoke(this, effect, hpGained); } RemoveEffect(effect.Key, effectMap, endEvent); }
void ApplyEffect( PersistentHealthEffect effect, Dictionary <string, PersistentHealthEffect> effectMap, FoldableHealthEffectEvent beginEvent, FoldableHealthEffectEvent procEvent, FoldableHealthEffectEvent endEvent ) { if (effectMap.ContainsKey(effect.Key)) { RemoveEffect(effect.Key, effectMap, endEvent); } effectMap.Add(effect.Key, effect); beginEvent.Invoke(this, effect, effect.EffectBeginFunc(this)); effect.EffectCoroutineHandle = EffectCoroutine(effect, effectMap, procEvent, endEvent); StartCoroutine(effect.EffectCoroutineHandle); }
bool RemoveEffect( string key, Dictionary <string, PersistentHealthEffect> effectMap, FoldableHealthEffectEvent endEvent ) { if (!effectMap.ContainsKey(key)) { return(false); } var effect = effectMap[key]; if (effect.EffectCoroutineHandle != null) { StopCoroutine(effect.EffectCoroutineHandle); effect.EffectCoroutineHandle = null; } endEvent.Invoke(this, effect, effect.GetEndEffect(this)); effectMap.Remove(key); return(true); }