1
This commit is contained in:
@@ -22,54 +22,68 @@ public class PhaseActionRoleSelect : BattlePhase {
|
||||
|
||||
public override void Execute() {
|
||||
// 选择行动的角色,如果没有则进入下一回合
|
||||
PhaseType phase = BattleQueue.Dequeue(out simulator.actionRole) ? PhaseType.角色攻击 : PhaseType.回合阶段;
|
||||
simulator.Transition(phase);
|
||||
if (!BattleQueue.Dequeue(out simulator.actionRole)) { simulator.Transition(PhaseType.回合阶段); return; }
|
||||
// 判断是否可以行动
|
||||
if (ActionRole.hitPoint.x <= 0) { simulator.Transition(PhaseType.选择角色); return; }
|
||||
// 进行ai判断
|
||||
// TODO: 进行武器攻击,使用技能,使用法术,使用物品的判断
|
||||
simulator.Transition(PhaseType.角色攻击);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 行动角色攻击
|
||||
/// 武器攻击
|
||||
/// </summary>
|
||||
public class PhaseActionRoleAttack : BattlePhase {
|
||||
|
||||
public PhaseActionRoleAttack(BattleSimulator simulator) : base(simulator) { }
|
||||
|
||||
public override void Execute() {
|
||||
// 判断是否可以行动
|
||||
if (ActionRole.hitPoint.x <= 0) { simulator.Transition(PhaseType.选择角色); return; }
|
||||
// 选择可以攻击的目标
|
||||
List<DataCombatRole> 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);
|
||||
if (!AttackTarget(out DataCombatRole target)) { simulator.Transition(PhaseType.结算阶段); return; }
|
||||
// 武器判断:轻型武器使用敏捷,其他都使用力量
|
||||
string weaponName = ActionRole.weapon1.name;
|
||||
WeaponType weaponType = ActionRole.weapon1.weaponType;
|
||||
int modifier = weaponType == WeaponType.轻型武器 ? ActionRole.DexModifier : ActionRole.StrModifier;
|
||||
// 命中检定: d20 + 属性修正
|
||||
int hit = Dice.Roll20(modifier);
|
||||
int armorClass = target.armorClass;
|
||||
// 伤害计算
|
||||
int damage = Dice.Roll8(ActionRole.StrModifier);
|
||||
if (hit > armorClass) { target.hitPoint.x -= damage; }
|
||||
// 如果命中小于等于目标护甲等级,则不造成伤害
|
||||
if (hit <= armorClass) {
|
||||
// 生成战斗消息
|
||||
Miss(hit, weaponName, target.name, armorClass);
|
||||
// 结束行动
|
||||
simulator.Transition(PhaseType.选择角色);
|
||||
return;
|
||||
}
|
||||
// 获取所有武器伤害骰
|
||||
DataDamageDice damageDice = ActionRole.weapon1.damageDice;
|
||||
// 伤害计算: 武器伤害骰 + 属性修正
|
||||
int damage = Dice.Roll(damageDice.value) + modifier;
|
||||
target.hitPoint.x -= damage;
|
||||
// 生成战斗消息
|
||||
MessageNormalAttack message = new MessageNormalAttack();
|
||||
message.Settings(ActionRole, hit, damage);
|
||||
message.Settings(target, armorClass);
|
||||
Debug.Log(message);
|
||||
Hit(hit, weaponName, target.name, armorClass, damage, damageDice.type);
|
||||
// 结束行动
|
||||
simulator.Transition(PhaseType.选择角色);
|
||||
}
|
||||
/// <summary> 攻击目标 </summary>
|
||||
private List<DataCombatRole> AttackTarget() {
|
||||
return BattleQueue.Where(Hostility);
|
||||
private bool AttackTarget(out DataCombatRole target) {
|
||||
List<DataCombatRole> roles = BattleQueue.Where(Hostility);
|
||||
if (roles.Count == 0) { target = null; return false; }
|
||||
int randomIndex = Random.Range(0, roles.Count);
|
||||
target = roles[randomIndex];
|
||||
return true;
|
||||
}
|
||||
/// <summary> 敌对目标 </summary>
|
||||
public bool Hostility(DataCombatRole role) {
|
||||
private bool Hostility(DataCombatRole role) {
|
||||
return role.team != ActionRole.team && role.hitPoint.x > 0;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 战斗行动
|
||||
/// </summary>
|
||||
public class BattleAction {
|
||||
|
||||
private void Miss(int hit, string weapon, string attacked, int armorClass) {
|
||||
MissAttack message = new MissAttack(ActionRole.name, hit, weapon, attacked, armorClass);
|
||||
Debug.Log(message);
|
||||
}
|
||||
/// <summary> 战斗消息 </summary>
|
||||
private void Hit(int hit, string weapon, string attacked, int armorClass, int damage, DamageType damageType) {
|
||||
HitAttack message = new HitAttack(ActionRole.name, hit, weapon, attacked, armorClass, damage, damageType);
|
||||
Debug.Log(message);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,36 @@ public class BattleReport {
|
||||
/// 战斗消息
|
||||
/// </summary>
|
||||
public class BattleMessage {
|
||||
|
||||
/// <summary> 战斗消息内容 </summary>
|
||||
public string content;
|
||||
/// <summary> 战斗消息内容 </summary>
|
||||
public override string ToString() {
|
||||
return content;
|
||||
}
|
||||
// 辅助方法:随机选择一个字符串,增加多样性
|
||||
public string RandomChoice(params string[] options) {
|
||||
if (options.Length == 0) return "";
|
||||
return options[Random.Range(0, options.Length)];
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 未命中攻击 - 战斗消息
|
||||
/// </summary>
|
||||
public class MissAttack : BattleMessage {
|
||||
public MissAttack(string attacker, int hit, string weapon, string attacked, int armorClass) {
|
||||
// 托尔吉使用巨斧猛击(19)没有命中哥布林战士(AC12)
|
||||
content = $"{attacker}使用{weapon}({hit})没有命中{attacked}({armorClass})";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 命中攻击 - 战斗消息
|
||||
/// </summary>
|
||||
public class HitAttack : BattleMessage {
|
||||
public HitAttack(string attacker, int hit, string weapon, string attacked, int armorClass, int damage, DamageType damageType) {
|
||||
string damageTypeString = damageType == DamageType.无 ? "" : damageType.ToString();
|
||||
// 托尔吉使用巨斧猛击(19)对哥布林战士(AC12)造成了 14钝击伤害
|
||||
content = $"{attacker}使用{weapon}({hit})对{attacked}({armorClass})造成了{damage}{damageTypeString}伤害";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 普通攻击 - 战斗消息
|
||||
@@ -73,9 +102,4 @@ public class MessageNormalAttack : BattleMessage {
|
||||
};
|
||||
return RandomChoice(hitText);
|
||||
}
|
||||
// 辅助方法:随机选择一个字符串,增加多样性
|
||||
private string RandomChoice(params string[] options) {
|
||||
if (options.Length == 0) return "";
|
||||
return options[Random.Range(0, options.Length)];
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
- 托尔吉 使用狂暴(附赠动作开启)→ 获得力量加成与抗性
|
||||
- 托尔吉 移动至哥布林战士前面
|
||||
- 托尔吉 使用巨斧猛击(19)对哥布林战士(AC12) 造成了 14钝击伤害
|
||||
- 托尔吉 使用巨斧猛击(19)没有命中哥布林战士(AC12)
|
||||
|
||||
- 哥布林战士死亡
|
||||
|
||||
|
||||
Reference in New Issue
Block a user