1
This commit is contained in:
@@ -26,7 +26,7 @@ public class BattleCharacter : DataAttribute {
|
||||
|
||||
public BattleCharacter(DataCharacter character, int team) {
|
||||
this.character = character;
|
||||
Cover(character);
|
||||
AttributeTool.Cover(this, character);
|
||||
this.team = team;
|
||||
name = character.name;
|
||||
level = character.Level;
|
||||
@@ -35,8 +35,12 @@ public class BattleCharacter : DataAttribute {
|
||||
armorClass = character.ArmorClass;
|
||||
}
|
||||
|
||||
/// <summary> 攻击目标 </summary>
|
||||
public bool AttackTarget(BattleCharacter target) {
|
||||
/// <summary> 是否允许行动 </summary>
|
||||
public bool IsAction() {
|
||||
return hitPoint.x > 0;
|
||||
}
|
||||
/// <summary> 是否敌对目标 </summary>
|
||||
public bool IsHostility(BattleCharacter target) {
|
||||
return team != target.team && target.hitPoint.x > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,10 @@ using UnityEngine;
|
||||
/// 行动阶段
|
||||
/// </summary>
|
||||
public class PhaseAction : BattlePhase {
|
||||
/// <summary> 当前行动 </summary>
|
||||
private BattleCharacter currentAction;
|
||||
/// <summary> 当前目标 </summary>
|
||||
private BattleCharacter currentTarget;
|
||||
|
||||
public PhaseAction(BattleSimulator simulator) : base(simulator) { }
|
||||
|
||||
@@ -13,14 +17,23 @@ public class PhaseAction : BattlePhase {
|
||||
// throw new System.NotImplementedException();
|
||||
}
|
||||
public override void UpdatePhase() {
|
||||
// 选择行动目标,没有行动目标则进入结算阶段
|
||||
if (!BattleQueue.Dequeue(out BattleCharacter character)) { simulator.Transition(PhaseType.结算阶段); return; }
|
||||
// 判断是否可以行动
|
||||
if (ActionPredicate(character)) { return; }
|
||||
// 选择一个可以攻击的目标
|
||||
BattleCharacter target = BattleQueue.FirstOrDefault(obj => character.AttackTarget(obj));
|
||||
// 对目标进行攻击
|
||||
|
||||
// 选择行动的角色,如果没有则进入下一轮
|
||||
if (!SelectAction()) { return; }
|
||||
// 选择攻击的目标,如果没有目标则结算战斗
|
||||
if (!SelectTarget()) { return; }
|
||||
// 命中检定
|
||||
int hit = Dice.Roll20(currentAction.DexModifier);
|
||||
int ac = currentTarget.armorClass;
|
||||
bool isHit = hit > ac;
|
||||
// 伤害计算
|
||||
if (isHit) {
|
||||
int damage = Dice.Roll8(currentAction.StrModifier);
|
||||
currentTarget.hitPoint.x -= damage;
|
||||
Debug.Log($"{currentAction.name}使用 普通攻击({hit}) 对 {currentTarget.name}({ac}) 造成 {damage} 点伤害!");
|
||||
}
|
||||
else {
|
||||
Debug.Log($"{currentAction.name}使用 普通攻击({hit}) 对 {currentTarget.name}({ac}) 未命中!");
|
||||
}
|
||||
// TODO:记录器
|
||||
// Debug.Log($"正式回合:{roundCount}");
|
||||
}
|
||||
@@ -28,9 +41,20 @@ public class PhaseAction : BattlePhase {
|
||||
// throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary> 行动判断 </summary>
|
||||
private bool ActionPredicate(BattleCharacter character) {
|
||||
return character.hitPoint.x > 0;
|
||||
/// <summary> 选择当前行动角色 </summary>
|
||||
private bool SelectAction() {
|
||||
// 选择行动的角色,如果没有则进入下一回合
|
||||
if (!BattleQueue.Dequeue(out currentAction)) { simulator.Transition(PhaseType.回合阶段); return false; }
|
||||
// 判断是否可以行动
|
||||
if (!currentAction.IsAction()) { return false; }
|
||||
return true;
|
||||
}
|
||||
/// <summary> 选择当前目标角色 </summary>
|
||||
private bool SelectTarget() {
|
||||
// 选择一个可以攻击的目标
|
||||
currentTarget = BattleQueue.FirstOrDefault(obj => currentAction.IsHostility(obj));
|
||||
// 如果没有可以攻击的目标则结算战斗
|
||||
if (currentTarget == null) { simulator.Transition(PhaseType.结算阶段); }
|
||||
return currentTarget != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,12 +10,12 @@ public class PhaseAssault : BattlePhase {
|
||||
public PhaseAssault(BattleSimulator simulator) : base(simulator) { }
|
||||
|
||||
public override void StartPhase() {
|
||||
throw new System.NotImplementedException();
|
||||
// throw new System.NotImplementedException();
|
||||
}
|
||||
public override void UpdatePhase() {
|
||||
throw new System.NotImplementedException();
|
||||
// throw new System.NotImplementedException();
|
||||
}
|
||||
public override void QuitPhase() {
|
||||
throw new System.NotImplementedException();
|
||||
// throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,16 @@ public class PhaseFinish : BattlePhase {
|
||||
public PhaseFinish(BattleSimulator simulator) : base(simulator) { }
|
||||
|
||||
public override void StartPhase() {
|
||||
throw new System.NotImplementedException();
|
||||
// TODO:记录器
|
||||
Debug.Log("结束战斗!");
|
||||
}
|
||||
public override void UpdatePhase() {
|
||||
throw new System.NotImplementedException();
|
||||
// TODO:需要添加结算判断
|
||||
// simulator.Transition(PhaseType.回合阶段);
|
||||
// TODO:记录器
|
||||
|
||||
}
|
||||
public override void QuitPhase() {
|
||||
throw new System.NotImplementedException();
|
||||
// throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,9 @@ public class PhaseFormal : BattlePhase {
|
||||
simulator.Transition(PhaseType.行动阶段);
|
||||
// TODO:记录器
|
||||
Debug.Log($"正式回合:{roundCount}");
|
||||
string message = "存活";
|
||||
BattleQueue.ForEach(obj => message += $" {obj.name}({obj.hitPoint.x})");
|
||||
Debug.Log(message);
|
||||
}
|
||||
public override void QuitPhase() {
|
||||
// throw new System.NotImplementedException();
|
||||
|
||||
@@ -18,7 +18,9 @@ public class PhaseInitiative : BattlePhase {
|
||||
// TODO:需要添加突袭阶段
|
||||
simulator.Transition(PhaseType.回合阶段);
|
||||
// TODO:记录器
|
||||
Debug.Log("先攻");
|
||||
string message = "先攻";
|
||||
BattleQueue.ForEach(obj => message += $" {obj.name}({obj.sequence})");
|
||||
Debug.Log(message);
|
||||
}
|
||||
public override void QuitPhase() {
|
||||
// throw new System.NotImplementedException();
|
||||
|
||||
@@ -9,7 +9,6 @@ using UnityEngine;
|
||||
/// 战斗 - 模拟器
|
||||
/// </summary>
|
||||
public class BattleSimulator {
|
||||
|
||||
/// <summary> 战斗队列 </summary>
|
||||
public BattleQueue battleQueue = new BattleQueue();
|
||||
|
||||
@@ -19,6 +18,9 @@ public class BattleSimulator {
|
||||
public Dictionary<PhaseType, IPhase> dictionary = new Dictionary<PhaseType, IPhase>();
|
||||
|
||||
public BattleSimulator(BattleTeam team1, BattleTeam team2) {
|
||||
team1.Initial(1);
|
||||
team2.Initial(2);
|
||||
|
||||
battleQueue.Add(team1.battles);
|
||||
battleQueue.Add(team2.battles);
|
||||
|
||||
@@ -27,6 +29,8 @@ public class BattleSimulator {
|
||||
dictionary.Add(PhaseType.回合阶段, new PhaseFormal(this));
|
||||
dictionary.Add(PhaseType.行动阶段, new PhaseAction(this));
|
||||
dictionary.Add(PhaseType.结算阶段, new PhaseFinish(this));
|
||||
|
||||
Transition(PhaseType.先攻阶段);
|
||||
}
|
||||
public void Update() {
|
||||
currentPhase?.UpdatePhase();
|
||||
@@ -40,7 +44,7 @@ public class BattleSimulator {
|
||||
currentPhase?.QuitPhase();
|
||||
currentPhase = newPhase;
|
||||
currentPhase?.StartPhase();
|
||||
Debug.Log($"战斗阶段已转换为: {phaseType}");
|
||||
// Debug.Log($"战斗阶段已转换为: {phaseType}");
|
||||
}
|
||||
else {
|
||||
// 不存在时输出警告信息
|
||||
|
||||
Reference in New Issue
Block a user