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); }
public void ApplyRegen( string key, string description, float duration, float period, int reason, Func <Health, float> effectBeginFunc = null, Func <Health, float> effectProcFunc = null, Func <Health, float> effectEndFunc = null, Func <Health, bool> resistFunc = null ) { var effect = new PersistentHealthEffect( key, description, duration, period, reason, effectBeginFunc, effectProcFunc, effectEndFunc, resistFunc ); ApplyEffect(effect, RegenEffects, RegenBegan, RegenProc, RegenEnded); }