Beispiel #1
0
    public static void UniqueSkillDamage(FightUnit attacker, FightUnit target, UniqueSkill skill)
    {
        if (target == null || attacker == null || target.isInvincible)
        {
            return;
        }
        //判断命中
        if (IsMiss(attacker, target))
        {
            HealthUIManager.instance.DisplayHurtNum(target, "Miss", true, false);
            //当闪避攻击时
            if (target.OnDodge != null)
            {
                target.OnDodge();
            }
            return;
        }
        //判断无敌
        if (target.isInvincible)
        {
            HealthUIManager.instance.DisplayHurtNum(target, "Invincible", true, false);
            return;
        }
        //判断暴击
        bool  isCrit    = false;
        float critScale = 1f;

        if (IsCritical(attacker, target))
        {
            isCrit    = true;
            critScale = Const.CONST_BASIC_CRIT_DMG + attacker.fightAttribute.criticalImprove;
            //当被暴击时
            if (target.OnGotCritil != null)
            {
                target.OnGotCritil();
            }
        }
        float defense = (float)1 / (1 + Const.CONST_DEF_FACTOR * target.fightAttribute.Defence);//防御效果

        defense = Mathf.Clamp(defense, Const.CONST_MIN_DEF_EFFECT, Const.CONST_MAX_DEF_EFFECT);
        int      hurtNum  = 1;
        HurtType hurtType = (HurtType)skill.specialSkill.attackAttribute;

        if (hurtType != HurtType.True)
        {
            float elementFactor        = ElementFactorDic[skill.specialSkill.attackAttribute * 10 + (int)target.fightAttribute.elementType].factor;//属性伤害系数
            float elementDefenseFactor = 0;
            switch (hurtType)
            {
            case HurtType.Fire:
                elementDefenseFactor = target.fightAttribute.fireDefenseRate;
                break;

            case HurtType.Water:
                elementDefenseFactor = target.fightAttribute.waterDefenseRate;
                break;

            case HurtType.Earth:
                elementDefenseFactor = target.fightAttribute.eathDefenseRate;
                break;

            case HurtType.Light:
                elementDefenseFactor = target.fightAttribute.lightDefeneseRate;
                break;

            case HurtType.Dark:
                elementDefenseFactor = target.fightAttribute.darkDefenseRate;
                break;
            }
            hurtNum = Mathf.RoundToInt((float)(attacker.fightAttribute.attack * skill.specialSkillLvUp.percent + skill.specialSkillLvUp.additional) * defense
                                       * (1 + attacker.fightAttribute.allDamageRate) * (1 - elementDefenseFactor) * (1 - target.fightAttribute.allDefenseRate) * elementFactor * critScale * Random.Range(0.95f, 1.05f));
        }
        else
        {
            hurtNum = Mathf.RoundToInt((float)(attacker.fightAttribute.attack * skill.specialSkillLvUp.percent + skill.specialSkillLvUp.additional)
                                       * (1 + attacker.fightAttribute.allDamageRate) * (1 - target.fightAttribute.allDefenseRate) * critScale * Random.Range(0.95f, 1.05f));
        }
        hurtNum = Mathf.Max(0, hurtNum);

        //受击特效
        skill.StartCoroutine(skill.DisplayHitEffect(target));
        //触发技能命中事件
        if (attacker.OnSkillHit != null)
        {
            attacker.OnSkillHit(hurtNum);
        }
        //触发反弹事件
        if (target.OnFantan != null)
        {
            target.OnFantan(hurtNum, skill, hurtType);
        }
        //护盾计算
        hurtNum = CaculateHudun(hurtNum, target, hurtType);
        //附加buff
        SkillAttachBuff(attacker, target, skill.buffConfigList, (HurtType)skill.specialSkill.attackAttribute);
        //附加效果
        AttachExtension(attacker, target, hurtNum, skill.attachExtension, skill.attachExtensionParam);
        //伤血
        if (hurtNum == 0)
        {
            return;
        }
        HealthUIManager.instance.DisplayHurtNum(target, hurtNum.ToString(), true, isCrit);
        target.health -= hurtNum;
        if (target.health == 0)
        {
            FightManager.GetInstance().UnitDead(attacker, target);
        }
    }