コード例 #1
0
    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);
    }
コード例 #2
0
 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);
 }
コード例 #3
0
    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);
    }