public override CombatStep CalcBattle(Combat combat, CombatVariable atkVal, CombatVariable defVal) { CombatUnit atker = combat.GetCombatUnit(0); CombatUnit defer = combat.GetCombatUnit(1); // 防守者是否可反击 bool canDeferAtk = false; if (defer.role.equipedWeapon != null) { Vector3Int offset = defer.mapClass.cellPosition - atker.mapClass.cellPosition; int dist = Mathf.Abs(offset.x) + Mathf.Abs(offset.y); WeaponUniqueInfo defInfo = defer.role.equipedWeapon.uniqueInfo; //if (defInfo.weaponType != WeaponType.Staff) { // 如果在反击范围内 if (dist >= defInfo.minRange && dist <= defInfo.maxRange) { canDeferAtk = true; } } } // 根据速度初始化攻击者与防守者 if (canDeferAtk) { if (atker.speed < defer.speed) { CombatUnit tmp = atker; atker = defer; defer = tmp; } } // 更新信息 this.message = "战斗开始"; atkVal = new CombatVariable(atker.position, atker.hp, atker.mp, true, atker.durability, CombatAnimaType.Prepare); defVal = new CombatVariable(defer.position, defer.hp, defer.mp, canDeferAtk, defer.durability, CombatAnimaType.Prepare); // 准备阶段 CombatStep firstStep = new CombatStep(atkVal, defVal); return(firstStep); }
public override CombatStep CalcBattle(Combat combat, CombatVariable atkVal, CombatVariable defVal) { CombatUnit atker = combat.GetCombatUnit(atkVal.position); CombatUnit defer = combat.GetCombatUnit(defVal.position); atkVal.animaType = CombatAnimaType.Attack; // 真实命中率 = 攻击者命中 - 防守者回避 int realHit = atker.hit - defer.avoidance; // 概率是否击中 int hitRate = UnityEngine.Random.Range(0, 100); bool isHit = hitRate <= realHit; if (isHit) { bool crit = false; // TODO 是否爆击 int realAtk = atker.atk; /////////////////// // TODO 触发伤害技能 // 这里写触发技能后伤害变化(比如武器特效等), // 或者触发某些状态(比如中毒等) ////////////////// if (crit) { realAtk *= 2; // 假定爆击造成双倍伤害 } // 掉血 = 攻击者攻击力 - 防守者防御力 // 最少掉一滴血 int damageHp = Mathf.Max(1, realAtk - defer.def); if (damageHp > defVal.hp) { damageHp = defVal.hp; } defVal.hp = defVal.hp - damageHp; atkVal.crit = crit; defVal.animaType = CombatAnimaType.Damage; // 更新此次攻击信息 this.message = string.Format( "{0} 对 {1} 的攻击造成了 {2} 点伤害{3}。", atker.role.character.info.name, defer.role.character.info.name, damageHp, crit ? "(爆击)" : string.Empty); if (defVal.isDead) { this.message += string.Format(" {0}被击败了。", defer.role.character.info.name); } } else { defVal.animaType = CombatAnimaType.Evade; // 更新此次躲闪信息 this.message = string.Format( "{1} 躲闪了 {0} 的攻击。", atker.role.character.info.name, defer.role.character.info.name); } // 只有玩家才会减低耐久度 if (atker.role.attitudeTowards == AttitudeTowards.Player) { // 攻击者武器耐久度-1 atkVal.durability = Mathf.Max(0, atkVal.durability - 1); } // 攻击者行动过了 atkVal.action = true; CombatStep step = new CombatStep(atkVal, defVal); return(step); }