1
This commit is contained in:
@@ -34,6 +34,7 @@ public class DataAttribute {
|
||||
}
|
||||
/// <summary>
|
||||
/// 角色 - 数据
|
||||
/// TODO: 补充角色的专长(Feats)、技能(Skills)、法术(Spells)等
|
||||
/// </summary>
|
||||
public class DataCharacter : DataAttribute {
|
||||
/// <summary> 名字 </summary>
|
||||
@@ -71,6 +72,7 @@ public class DataCharacter : DataAttribute {
|
||||
}
|
||||
/// <summary>
|
||||
/// 种族 - 数据
|
||||
/// TODO: 补充种族特殊能力
|
||||
/// </summary>
|
||||
public class DataRace : DataAttribute {
|
||||
/// <summary> 种族名称 </summary>
|
||||
|
||||
@@ -28,24 +28,4 @@ public class DataEquipment {
|
||||
public class DataAddition {
|
||||
/// <summary> 护甲等级 </summary>
|
||||
public int armorClass = 0;
|
||||
/// <summary> 伤害骰子 </summary>
|
||||
public List<DataDamageDice> damageDices = new List<DataDamageDice>();
|
||||
}
|
||||
/// <summary>
|
||||
/// 伤害类型
|
||||
/// </summary>
|
||||
public enum DamageType { 穿刺, 挥砍, 钝击 }
|
||||
/// <summary>
|
||||
/// 伤害 - 数据
|
||||
/// </summary>
|
||||
public class DataDamageDice {
|
||||
/// <summary> 伤害骰子 </summary>
|
||||
public readonly int dice;
|
||||
/// <summary> 伤害类型 </summary>
|
||||
public readonly DamageType damageType;
|
||||
|
||||
public DataDamageDice(int dice, DamageType damageType) {
|
||||
this.dice = dice;
|
||||
this.damageType = damageType;
|
||||
}
|
||||
}
|
||||
@@ -43,13 +43,33 @@ public class DataWear : DataItem {
|
||||
/// <summary>
|
||||
/// 武器类型。
|
||||
/// </summary>
|
||||
public enum WeaponType { 轻型武器, 中型武器, 重型武器, 盾牌, }
|
||||
public enum WeaponType { 无, 轻型武器, 中型武器, 重型武器, 盾牌, }
|
||||
/// <summary>
|
||||
/// 武器 - 数据
|
||||
/// </summary>
|
||||
public class DataWeapon : DataWear {
|
||||
/// <summary> 武器类型 </summary>
|
||||
public WeaponType weaponType;
|
||||
/// <summary> 伤害骰子 </summary>
|
||||
public DataDamageDice damageDice;
|
||||
}
|
||||
/// <summary>
|
||||
/// 伤害类型
|
||||
/// </summary>
|
||||
public enum DamageType { 无, 穿刺, 挥砍, 钝击 }
|
||||
/// <summary>
|
||||
/// 伤害骰子 - 数据
|
||||
/// </summary>
|
||||
public class DataDamageDice {
|
||||
/// <summary> 伤害骰子 </summary>
|
||||
public readonly int value;
|
||||
/// <summary> 伤害类型 </summary>
|
||||
public readonly DamageType type;
|
||||
|
||||
public DataDamageDice(int value, DamageType type) {
|
||||
this.value = value;
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 护甲类型。
|
||||
|
||||
@@ -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) {
|
||||
// 生成战斗消息
|
||||
MessageNormalAttack message = new MessageNormalAttack();
|
||||
message.Settings(ActionRole, hit, damage);
|
||||
message.Settings(target, armorClass);
|
||||
Debug.Log(message);
|
||||
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;
|
||||
// 生成战斗消息
|
||||
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)
|
||||
|
||||
- 哥布林战士死亡
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ public static class CombatRoleTool {
|
||||
role.armorClass = role.character.ArmorClass;
|
||||
role.weapon1 = role.character.equipment.weapon1;
|
||||
role.weapon2 = role.character.equipment.weapon2;
|
||||
if (role.weapon1 == null) { role.weapon1 = WeaponDictionary.Weapon000(); }
|
||||
if (role.weapon2 == null) { role.weapon2 = WeaponDictionary.Weapon000(); }
|
||||
}
|
||||
/// <summary> 设置队伍 </summary>
|
||||
public static void Settings(this DataCombatRole role, int team, int position) {
|
||||
|
||||
@@ -11,7 +11,6 @@ public static class EquipmentTool {
|
||||
/// <summary> 添加属性 </summary>
|
||||
public static void Add(this DataAddition a, DataAddition b) {
|
||||
a.armorClass += b.armorClass;
|
||||
a.damageDices.AddRange(b.damageDices);
|
||||
}
|
||||
/// <summary> 合并属性 </summary>
|
||||
public static DataAddition Merge(List<DataAddition> additions) {
|
||||
|
||||
@@ -15,44 +15,44 @@ public static class WeaponDictionary {
|
||||
weapon.weaponType = weaponType;
|
||||
return weapon;
|
||||
}
|
||||
/// <summary> 伤害骰子 </summary>
|
||||
public static DataAddition DamageDice(int value, DamageType type) {
|
||||
DataDamageDice dice = new DataDamageDice(value, type);
|
||||
DataAddition addition = new DataAddition();
|
||||
addition.damageDices.Add(dice);
|
||||
return addition;
|
||||
|
||||
/// <summary> 空手 1d2 </summary>
|
||||
public static DataWeapon Weapon000() {
|
||||
DataWeapon weapon = Weapon("空手", WeaponType.无);
|
||||
weapon.damageDice = new DataDamageDice(2, DamageType.无);
|
||||
return weapon;
|
||||
}
|
||||
|
||||
/// <summary> 匕首 1d4 </summary>
|
||||
public static DataWeapon Weapon101() {
|
||||
DataWeapon weapon = Weapon("匕首", WeaponType.轻型武器);
|
||||
weapon.additions.Add(DamageDice(4, DamageType.穿刺));
|
||||
weapon.damageDice = new DataDamageDice(4, DamageType.穿刺);
|
||||
return weapon;
|
||||
}
|
||||
/// <summary> 短弓 1d6 </summary>
|
||||
public static DataWeapon Weapon102() {
|
||||
DataWeapon weapon = Weapon("短弓", WeaponType.轻型武器);
|
||||
weapon.additions.Add(DamageDice(6, DamageType.穿刺));
|
||||
weapon.damageDice = new DataDamageDice(6, DamageType.穿刺);
|
||||
return weapon;
|
||||
}
|
||||
|
||||
/// <summary> 木棒 1d6 </summary>
|
||||
public static DataWeapon Weapon201() {
|
||||
DataWeapon weapon = Weapon("木棒", WeaponType.中型武器);
|
||||
weapon.additions.Add(DamageDice(6, DamageType.挥砍));
|
||||
weapon.damageDice = new DataDamageDice(6, DamageType.钝击);
|
||||
return weapon;
|
||||
}
|
||||
|
||||
/// <summary> 巨棒 1d8 </summary>
|
||||
public static DataWeapon Weapon301() {
|
||||
DataWeapon weapon = Weapon("巨棒", WeaponType.重型武器);
|
||||
weapon.additions.Add(DamageDice(8, DamageType.钝击));
|
||||
weapon.damageDice = new DataDamageDice(8, DamageType.钝击);
|
||||
return weapon;
|
||||
}
|
||||
/// <summary> 法杖 1d6 </summary>
|
||||
public static DataWeapon Weapon302() {
|
||||
DataWeapon weapon = Weapon("法杖", WeaponType.重型武器);
|
||||
weapon.additions.Add(DamageDice(6, DamageType.钝击));
|
||||
weapon.damageDice = new DataDamageDice(6, DamageType.钝击);
|
||||
return weapon;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user