using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 行动阶段 /// public class PhaseAction : BattlePhase { public PhaseAction(BattleSimulator simulator) : base(simulator) { } public override void Execute() { } } /// /// 行动角色选择 /// public class PhaseActionRoleSelect : BattlePhase { public PhaseActionRoleSelect(BattleSimulator simulator) : base(simulator) { } public override void Execute() { // 选择行动的角色,如果没有则进入下一回合 PhaseType phase = BattleQueue.Dequeue(out simulator.actionRole) ? PhaseType.角色攻击 : PhaseType.回合阶段; simulator.Transition(phase); } } /// /// 行动角色攻击 /// public class PhaseActionRoleAttack : BattlePhase { public PhaseActionRoleAttack(BattleSimulator simulator) : base(simulator) { } public override void Execute() { // 判断是否可以行动 if (ActionRole.hitPoint.x <= 0) { simulator.Transition(PhaseType.选择角色); return; } // 选择可以攻击的目标 List roles = AttackTarget(); // 如果没有可以攻击的目标则结算战斗 if (roles.Count == 0) { simulator.Transition(PhaseType.结算阶段); return; } // 攻击单体目标 int randomIndex = Random.Range(0, roles.Count); DataCombatRole target = roles[randomIndex]; // 武器判断 // ActionRole.weapon1 // 命中检定 int hit = Dice.Roll20(ActionRole.StrModifier); int armorClass = target.armorClass; // 伤害计算 int damage = Dice.Roll8(ActionRole.StrModifier); if (hit > armorClass) { target.hitPoint.x -= damage; } // 生成战斗消息 MessageNormalAttack message = new MessageNormalAttack(); message.Settings(ActionRole, hit, damage); message.Settings(target, armorClass); Debug.Log(message); simulator.Transition(PhaseType.选择角色); } /// 攻击目标 private List AttackTarget() { return BattleQueue.Where(Hostility); } /// 敌对目标 public bool Hostility(DataCombatRole role) { return role.team != ActionRole.team && role.hitPoint.x > 0; } } /// /// 战斗行动 /// public class BattleAction { }