Example #1
0
        public virtual List <int> TakeDamage(int damage)
        {
            double perc         = 0.0;
            int    stat         = 0;
            var    temp         = Int32.MaxValue;
            var    heavyBroken  = 0;
            var    mediumBroken = 0;
            var    lightBroken  = 0;

            foreach (BuffDebuff eff in Effects)
            {
                perc += eff.DefensePercentBuff;
                perc -= eff.DefensePercentDebuff;
                stat += eff.DefenseStaticBuff;
                //Find the Minimum of DefenseSetBuff in Effects
                if (eff.DefenseSetBuff >= 0 && eff.DefenseSetBuff < temp)
                {
                    temp = eff.DefenseSetBuff;
                }
                eff.StrikeTick();
            }

            if (HasPassive)
            {
                perc = Passive.PassiveDefensePercentCalculation(perc);
                stat = Passive.PassiveDefenseStaticCalculation(stat);
                temp = Passive.PassiveDefenseSetBuffCalculation(temp);
            }

            //Buffs are applied
            damage = damage - (int)((double)damage * perc) + stat;
            if (damage > temp)
            {
                damage = temp;
            }

            var totalDamage = damage;

            //Calculate shield cascading
            foreach (BuffDebuff eff in Effects)
            {
                if (eff.LightShield > 0 && damage > 0)
                {
                    while (eff.LightShield > 0 && damage > 0)
                    {
                        damage -= 5;
                        if (damage < 0)
                        {
                            damage = 0;
                        }
                        else
                        {
                            eff.LightShield--;
                            lightBroken++;
                        }
                    }
                }
                if (eff.MediumShield > 0 && TotalLightShield() <= 0 && damage > 0)
                {
                    while (eff.MediumShield > 0 && damage > 0)
                    {
                        damage -= 15;
                        if (damage < 0)
                        {
                            damage = 0;
                        }
                        else
                        {
                            eff.MediumShield--;
                            mediumBroken++;
                        }
                    }
                }
                if (eff.HeavyShield > 0 && TotalLightShield() <= 0 && TotalMediumShield() <= 0 && damage > 0)
                {
                    while (eff.HeavyShield > 0 && damage > 0)
                    {
                        damage -= 30;
                        if (damage < 0)
                        {
                            damage = 0;
                        }
                        else
                        {
                            eff.HeavyShield--;
                            heavyBroken++;
                        }
                    }
                }
            }

            var healthDamage = damage;

            foreach (BuffDebuff eff in Effects)
            {
                if (damage > 0 && eff.Growth > 0)
                {
                    temp        = eff.Growth;
                    eff.Growth -= damage;

                    if (eff.Growth < 0)
                    {
                        eff.Growth = 0;
                    }

                    damage -= temp;

                    if (damage < 0)
                    {
                        damage = 0;
                    }
                }
            }

            CurrentHP -= healthDamage;


            if (CurrentHP < 0)
            {
                CurrentHP = 0;
            }

            EffectCleanup();

            List <int> output = new List <int>();

            output.Add(totalDamage);
            output.Add(healthDamage);
            output.Add(heavyBroken);
            output.Add(mediumBroken);
            output.Add(lightBroken);
            return(output);
        }