/// <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); } }