Пример #1
0
    /// <summary>
    /// 被攻击
    /// </summary>
    /// <param name="damage"></param>
    /// <param name="unit">攻击者</param>
    /// <returns></returns>
    public IDamage BeAttack(IDamage damage, Unit unit)
    {
        if (unitProperty.hp.CurrValue <= 0)
        {
            return(null);
        }
        int a = 0;
        int b = 0;
        int c = 0;

        if (!IsInvincible)
        {
            if (damage.DamageStyle == DamageStyle.PHYSICS)
            {
                a = (int)((damage.AttackDamage - this.unitProperty.defensive.CurrValue - this.unitProperty.ignoreDamage.ExtraValue) * (1 - this.unitProperty.ignoreDamage.ExtraPercent));
                b = (int)((damage.CriticalDamage - this.unitProperty.defensive.CurrValue - this.unitProperty.ignoreDamage.ExtraValue) * (1 - this.unitProperty.ignoreDamage.ExtraPercent));
            }
            else if (damage.DamageStyle == DamageStyle.MAGIC)
            {
                a = (int)((damage.AttackDamage - this.unitProperty.magicDefensive.CurrValue - this.unitProperty.ignoreDamage.ExtraValue) * (1 - this.unitProperty.ignoreDamage.ExtraPercent));
                b = (int)((damage.CriticalDamage - this.unitProperty.magicDefensive.CurrValue - this.unitProperty.ignoreDamage.ExtraValue) * (1 - this.unitProperty.ignoreDamage.ExtraPercent));
            }
            b = Mathf.Max(0, b);
            c = damage.AttachDamage;
            this.unitProperty.hp.CurrValue -= a + b + c;
        }
        var id = new DamageValue()
        {
            DamageStyle    = damage.DamageStyle,
            AttackDamage   = a,
            AttachDamage   = c,
            CriticalDamage = b,
        };

        if (unitProperty.hp.CurrValue <= 0)
        {
            ani.Play("Death");
            unitProperty.hp.CurrValue = 0;
        }
        GlobalEvent.showDamageFontEvent(id, transform.position);
        if (isPlayer)
        {
            GlobalEvent.hpChangeEvent(this.unitProperty.hp.CurrValue, this.unitProperty.hp.MaxValue);
        }
        return(id);
    }