private bool ResolveLongTimeDamagerConflicts(ITimedDamageInfo dmgInf)
        {
            for (int i = 0; i < dmgBuffer.Count; i++)
            {
                switch (dmgInf.DamageTypEliminates(dmgBuffer[i].DmgTyp))
                {
                case ITimedDamageInfo.ConflictResolve.EliminateOther:
                    RemoveLongTimeDamager(i);
                    i--;
                    break;

                case ITimedDamageInfo.ConflictResolve.Substract:
                    float newDmg = dmgBuffer[i].Damage - dmgInf.Damage;
                    if (newDmg <= 0)
                    {
                        dmgInf.Damage -= dmgBuffer[i].Damage;
                        RemoveLongTimeDamager(i);
                        i--;
                    }
                    else
                    {
                        dmgBuffer[i].Damage = newDmg;
                        return(false);
                    }
                    break;
                }
            }
            return(true);
        }
        private IEnumerator HandleLongTimeDamager(ITimedDamageInfo timedDmgInf, HealthChangeTyp healthChangeTyp)
        {
            IDamageInfo timeLessDmg = (IDamageInfo)timedDmgInf;

            while (timedDmgInf.RunTime > 0)
            {
                ChangeHealth(timeLessDmg);
                float secondsToWait = timedDmgInf.Frequency;
                yield return(new WaitForSeconds(secondsToWait));

                timedDmgInf.RunTime -= secondsToWait;
            }
        }
        public override void AddLongTimeDamager(ITimedDamageInfo timedDmgInf, HealthChangeTyp healthChangeTyp)
        {
            if (!ResolveLongTimeDamagerConflicts(timedDmgInf))
            {
                return;
            }
            if (timedDmgInf.AddBehaivior == ITimedDamageInfo.AddingBehaivior.Replace)
            {
                int index = TryGetLongTimeDangerIndex(timedDmgInf.DmgTyp);
                if (index != -1)
                {
                    RemoveLongTimeDamager(index);
                }
                dmgBuffer.Add(timedDmgInf);
                longTimeDamageHandler.Add(StartCoroutine(HandleLongTimeDamager(timedDmgInf, healthChangeTyp)));
            }
            else if (timedDmgInf.AddBehaivior == ITimedDamageInfo.AddingBehaivior.AddMostDangerous)
            {
                ITimedDamageInfo output;
                int index = TryGetNextLongTimeDanger(timedDmgInf.DmgTyp, 0, out output);

                if (index == -1)
                {
                    dmgBuffer.Add(timedDmgInf);
                    longTimeDamageHandler.Add(StartCoroutine(HandleLongTimeDamager(timedDmgInf, healthChangeTyp)));
                    return;
                }
                do
                {
                    if (output.Damage < timedDmgInf.Damage)
                    {
                        output.Damage = timedDmgInf.Damage;
                        return;
                    }
                    if (output.Frequency < timedDmgInf.Frequency)
                    {
                        output.Frequency = timedDmgInf.Frequency;
                        return;
                    }
                    index++;
                } while ((index = TryGetNextLongTimeDanger(timedDmgInf.DmgTyp, index, out output)) != -1);
            }
            else
            {
                dmgBuffer.Add(timedDmgInf);
                longTimeDamageHandler.Add(StartCoroutine(HandleLongTimeDamager(timedDmgInf, healthChangeTyp)));
            }
        }
Beispiel #4
0
 public abstract int TryGetNextLongTimeDanger(IDamageInfo.DamageTyp typ, int index, out ITimedDamageInfo timedDmgInf);
Beispiel #5
0
 public abstract void AddLongTimeDamager(ITimedDamageInfo timedDmgInf, HealthChangeTyp changeTyp);
 public override int TryGetNextLongTimeDanger(IDamageInfo.DamageTyp typ, int index, out ITimedDamageInfo timedDmgInf)
 {
     for (int i = index; i < dmgBuffer.Count; i++)
     {
         if (dmgBuffer[i].DmgTyp == typ)
         {
             timedDmgInf = dmgBuffer[i];
             return(i);
         }
     }
     timedDmgInf = null;
     return(-1);
 }