Exemple #1
0
        public void Damage(Unit target, DamageType type)
        {
            DamageInfo damageInfo = new DamageInfo(this, target);

            damageInfo.PrePassive  = Modification.PrePassive;
            damageInfo.Critical    = Modification.Critical;
            damageInfo.Evasion     = target.Modification.Evasion;
            damageInfo.Reduction   = target.Modification.Reduction;
            damageInfo.PostPassive = Modification.PostPassive;

            damageInfo.DamageAmount = AttackDamage;
            damageInfo.Type         = type;
            damageInfo.CalculateDamage();

            /* Damage pipeline:
             * calculate raw damage target will receive
             * apply effect, buff, modification, etc to raw damage
             * apply damage to target
             * checking shield
             * steal life
             */
            if (damageInfo.TriggerAttack)
            {
            }

            if (Shield > 0 || PhysicalShield > 0 || MagicShield > 0)
            {
                if (damageInfo.Type == DamageType.Physical)
                {
                    float min = Mathf.Min(PhysicalShield, damageInfo.DamageAmount);
                    PhysicalShield          -= min;
                    damageInfo.DamageAmount -= min;

                    Debug.Log("Physical shield prevent: " + min);
                }

                if (damageInfo.Type == DamageType.Magical)
                {
                    float min = Mathf.Min(MagicShield, damageInfo.DamageAmount);
                    MagicShield             -= min;
                    damageInfo.DamageAmount -= min;
                }

                if (damageInfo.DamageAmount > 0)
                {
                    float min = Mathf.Min(Shield, damageInfo.DamageAmount);
                    Shield -= min;
                    damageInfo.DamageAmount -= min;

                    Debug.Log("Shield prevent: " + min);
                }
            }

            target.CurrentHp = target.CurrentHp - damageInfo.DamageAmount;
        }