Beispiel #1
0
    /// <summary>
    /// 普通攻击的入口函数
    /// </summary>
    public static void NormalAttackWork(FightUnit attacker, FightUnit target, NormalAttack skill)
    {
        if (target == null || target.health == 0 || attacker == null || attacker.health == 0)
        {
            return;
        }
        switch ((SkillCurve)skill.attack.curve)
        {
        case SkillCurve.None:
        case SkillCurve.Melee:
            NormalAttackDamage(attacker, target, skill, skill.curHitEffect);
            break;

        case SkillCurve.Directional:
            GameObject obj = ProjectileMove.CreateProjectile(skill.name + "_" + attacker.mTrans.name, attacker.mTrans.parent, skill.flyEffectFromPos, skill.curFlyEffect.speed, target.Body, delegate(SpecialEffect fx)
            {
                if (attacker != null && target != null)
                {
                    NormalAttackDamage(attacker, target, skill, fx);
                }
            });
            obj.GetComponent <ProjectileMove>().hitEffect = skill.curHitEffect;
            skill.StartCoroutine(skill.DisplayFlyEffect(obj.transform));
            break;

        case SkillCurve.Parabola:
            Vector3 targetPos;
            bool    isHeroSkill = attacker.parentGroup.group == FightGroup.GroupType.Mine;
            if (skill.flyEffect.distance > 0)
            {
                targetPos = attacker.mTrans.localPosition + (isHeroSkill? -1 : 1) * Vector3.right * skill.flyEffect.distance;
            }
            else
            {
                targetPos = target.mTrans.localPosition + target.Body.localPosition;
            }
            GameObject obj_1 = ProjectileMove.CreateProjectile(skill.name, attacker.mTrans.parent, skill.flyEffectFromPos, skill.curFlyEffect.speed, skill.curFlyEffect.height, targetPos, delegate(SpecialEffect fx)
            {
                if (attacker != null && target != null)
                {
                    NormalAttackDamage(attacker, target, skill, fx);
                }
            });
            obj_1.GetComponent <ProjectileMove>().hitEffect = skill.curHitEffect;
            if (!isHeroSkill)
            {
                obj_1.AddComponent <DragRecord>();
            }
            break;
        }
    }
Beispiel #2
0
    /// <summary>
    /// 普通攻击伤害
    /// 普通攻击伤害=攻击方最终攻击*防御效果*攻击方伤害加成效果系数*防御方对应属性免伤系数*防御方全免伤系数*属性相克系数*暴击伤害系数*random(0.95,1.05)
    /// 防御效果=1/(1+防御系数*防御方最终防御)
    /// 防御效果必须介于20%和100%之间,这两个参数由策划配置
    /// 防御常数为常量,由策划配置,下同
    /// 普通攻击的属性和单位自身的属性相同
    /// </summary>
    public static void NormalAttackDamage(FightUnit attacker, FightUnit target, NormalAttack skill, SpecialEffect hitEffect)
    {
        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 (attacker.OnNormalAttackCritil != null)
            {
                attacker.OnNormalAttackCritil(target);
            }
            //当被暴击时
            if (target.OnGotCritil != null)
            {
                attacker.OnGotCritil();
            }
        }

        //受击特效
        skill.StartCoroutine(skill.DisplayHitEffect(target, hitEffect));

        //计算数值
        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);
        float    elementDefenseFactor = 0;
        HurtType hurtType             = (HurtType)attacker.fightAttribute.elementType;

        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;
        }
        float elementFactor = ElementFactorDic[(int)attacker.fightAttribute.elementType * 10 + (int)target.fightAttribute.elementType].factor;
        int   hurtNum       = Mathf.RoundToInt(attacker.fightAttribute.attack * defense
                                               * (1 + attacker.fightAttribute.allDamageRate) * (1 - elementDefenseFactor) * (1 - target.fightAttribute.allDefenseRate) * elementFactor * critScale * Random.Range(0.95f, 1.05f));

        hurtNum = Mathf.Max(0, hurtNum);

        //触发普通攻击命中事件
        if (attacker.OnNoramlAttackHit != null)
        {
            attacker.OnNoramlAttackHit(hurtNum);
        }
        //触发反弹事件
        if (target.OnFantan != null)
        {
            target.OnFantan(hurtNum, skill, hurtType);
        }
        //护盾计算
        hurtNum = CaculateHudun(hurtNum, target, hurtType);

        //伤血
        if (hurtNum == 0)
        {
            return;
        }
        HealthUIManager.instance.DisplayHurtNum(target, hurtNum.ToString(), true, isCrit);
        target.health -= hurtNum;
        if (target.health == 0)
        {
            FightManager.GetInstance().UnitDead(attacker, target);
        }
    }