From c0bc7cb05d84ccf44add1ef6e4500bf364759ba9 Mon Sep 17 00:00:00 2001 From: MuHua-123 <136542559+MuHua-123@users.noreply.github.com> Date: Mon, 28 Jul 2025 17:11:36 +0800 Subject: [PATCH] 1 --- Assets/ModuleCore/Module/DataCharacter.cs | 2 + Assets/ModuleCore/Module/DataEquipment.cs | 20 ----- Assets/ModuleCore/Module/DataItem.cs | 22 +++++- .../ModuleBattle/BattlePhase/PhaseAction.cs | 76 +++++++++++-------- .../ModuleCore/ModuleBattle/BattleReport.cs | 36 +++++++-- Assets/ModuleCore/ModuleBattle/Sample.md | 1 + .../ModuleCharacter/CombatRoleTool.cs | 2 + .../ModuleInventory/EquipmentTool.cs | 1 - .../ModuleInventory/WeaponDictionary.cs | 22 +++--- 9 files changed, 112 insertions(+), 70 deletions(-) diff --git a/Assets/ModuleCore/Module/DataCharacter.cs b/Assets/ModuleCore/Module/DataCharacter.cs index 6eda4ff..7948eda 100644 --- a/Assets/ModuleCore/Module/DataCharacter.cs +++ b/Assets/ModuleCore/Module/DataCharacter.cs @@ -34,6 +34,7 @@ public class DataAttribute { } /// /// 角色 - 数据 +/// TODO: 补充角色的专长(Feats)、技能(Skills)、法术(Spells)等 /// public class DataCharacter : DataAttribute { /// 名字 @@ -71,6 +72,7 @@ public class DataCharacter : DataAttribute { } /// /// 种族 - 数据 +/// TODO: 补充种族特殊能力 /// public class DataRace : DataAttribute { /// 种族名称 diff --git a/Assets/ModuleCore/Module/DataEquipment.cs b/Assets/ModuleCore/Module/DataEquipment.cs index 6a2d203..18d29b1 100644 --- a/Assets/ModuleCore/Module/DataEquipment.cs +++ b/Assets/ModuleCore/Module/DataEquipment.cs @@ -28,24 +28,4 @@ public class DataEquipment { public class DataAddition { /// 护甲等级 public int armorClass = 0; - /// 伤害骰子 - public List damageDices = new List(); } -/// -/// 伤害类型 -/// -public enum DamageType { 穿刺, 挥砍, 钝击 } -/// -/// 伤害 - 数据 -/// -public class DataDamageDice { - /// 伤害骰子 - public readonly int dice; - /// 伤害类型 - public readonly DamageType damageType; - - public DataDamageDice(int dice, DamageType damageType) { - this.dice = dice; - this.damageType = damageType; - } -} \ No newline at end of file diff --git a/Assets/ModuleCore/Module/DataItem.cs b/Assets/ModuleCore/Module/DataItem.cs index 34e98c7..4f378cb 100644 --- a/Assets/ModuleCore/Module/DataItem.cs +++ b/Assets/ModuleCore/Module/DataItem.cs @@ -43,13 +43,33 @@ public class DataWear : DataItem { /// /// 武器类型。 /// -public enum WeaponType { 轻型武器, 中型武器, 重型武器, 盾牌, } +public enum WeaponType { 无, 轻型武器, 中型武器, 重型武器, 盾牌, } /// /// 武器 - 数据 /// public class DataWeapon : DataWear { /// 武器类型 public WeaponType weaponType; + /// 伤害骰子 + public DataDamageDice damageDice; +} +/// +/// 伤害类型 +/// +public enum DamageType { 无, 穿刺, 挥砍, 钝击 } +/// +/// 伤害骰子 - 数据 +/// +public class DataDamageDice { + /// 伤害骰子 + public readonly int value; + /// 伤害类型 + public readonly DamageType type; + + public DataDamageDice(int value, DamageType type) { + this.value = value; + this.type = type; + } } /// /// 护甲类型。 diff --git a/Assets/ModuleCore/ModuleBattle/BattlePhase/PhaseAction.cs b/Assets/ModuleCore/ModuleBattle/BattlePhase/PhaseAction.cs index 2fdbcc1..21a9092 100644 --- a/Assets/ModuleCore/ModuleBattle/BattlePhase/PhaseAction.cs +++ b/Assets/ModuleCore/ModuleBattle/BattlePhase/PhaseAction.cs @@ -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.角色攻击); } } /// -/// 行动角色攻击 +/// 武器攻击 /// 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); + 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.选择角色); } /// 攻击目标 - private List AttackTarget() { - return BattleQueue.Where(Hostility); + private bool AttackTarget(out DataCombatRole target) { + List roles = BattleQueue.Where(Hostility); + if (roles.Count == 0) { target = null; return false; } + int randomIndex = Random.Range(0, roles.Count); + target = roles[randomIndex]; + return true; } /// 敌对目标 - public bool Hostility(DataCombatRole role) { + private bool Hostility(DataCombatRole role) { return role.team != ActionRole.team && role.hitPoint.x > 0; } -} -/// -/// 战斗行动 -/// -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); + } + /// 战斗消息 + 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); + } } \ No newline at end of file diff --git a/Assets/ModuleCore/ModuleBattle/BattleReport.cs b/Assets/ModuleCore/ModuleBattle/BattleReport.cs index 447160c..18de40e 100644 --- a/Assets/ModuleCore/ModuleBattle/BattleReport.cs +++ b/Assets/ModuleCore/ModuleBattle/BattleReport.cs @@ -13,7 +13,36 @@ public class BattleReport { /// 战斗消息 /// public class BattleMessage { - + /// 战斗消息内容 + public string content; + /// 战斗消息内容 + public override string ToString() { + return content; + } + // 辅助方法:随机选择一个字符串,增加多样性 + public string RandomChoice(params string[] options) { + if (options.Length == 0) return ""; + return options[Random.Range(0, options.Length)]; + } +} +/// +/// 未命中攻击 - 战斗消息 +/// +public class MissAttack : BattleMessage { + public MissAttack(string attacker, int hit, string weapon, string attacked, int armorClass) { + // 托尔吉使用巨斧猛击(19)没有命中哥布林战士(AC12) + content = $"{attacker}使用{weapon}({hit})没有命中{attacked}({armorClass})"; + } +} +/// +/// 命中攻击 - 战斗消息 +/// +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}伤害"; + } } /// /// 普通攻击 - 战斗消息 @@ -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)]; - } } \ No newline at end of file diff --git a/Assets/ModuleCore/ModuleBattle/Sample.md b/Assets/ModuleCore/ModuleBattle/Sample.md index b0e0943..497912b 100644 --- a/Assets/ModuleCore/ModuleBattle/Sample.md +++ b/Assets/ModuleCore/ModuleBattle/Sample.md @@ -16,6 +16,7 @@ - 托尔吉 使用狂暴(附赠动作开启)→ 获得力量加成与抗性 - 托尔吉 移动至哥布林战士前面 - 托尔吉 使用巨斧猛击(19)对哥布林战士(AC12) 造成了 14钝击伤害 +- 托尔吉 使用巨斧猛击(19)没有命中哥布林战士(AC12) - 哥布林战士死亡 diff --git a/Assets/ModuleCore/ModuleCharacter/CombatRoleTool.cs b/Assets/ModuleCore/ModuleCharacter/CombatRoleTool.cs index 12f2a92..55c9143 100644 --- a/Assets/ModuleCore/ModuleCharacter/CombatRoleTool.cs +++ b/Assets/ModuleCore/ModuleCharacter/CombatRoleTool.cs @@ -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(); } } /// 设置队伍 public static void Settings(this DataCombatRole role, int team, int position) { diff --git a/Assets/ModuleCore/ModuleInventory/EquipmentTool.cs b/Assets/ModuleCore/ModuleInventory/EquipmentTool.cs index c7aa0dd..8077587 100644 --- a/Assets/ModuleCore/ModuleInventory/EquipmentTool.cs +++ b/Assets/ModuleCore/ModuleInventory/EquipmentTool.cs @@ -11,7 +11,6 @@ public static class EquipmentTool { /// 添加属性 public static void Add(this DataAddition a, DataAddition b) { a.armorClass += b.armorClass; - a.damageDices.AddRange(b.damageDices); } /// 合并属性 public static DataAddition Merge(List additions) { diff --git a/Assets/ModuleCore/ModuleInventory/WeaponDictionary.cs b/Assets/ModuleCore/ModuleInventory/WeaponDictionary.cs index d97364e..6084059 100644 --- a/Assets/ModuleCore/ModuleInventory/WeaponDictionary.cs +++ b/Assets/ModuleCore/ModuleInventory/WeaponDictionary.cs @@ -15,44 +15,44 @@ public static class WeaponDictionary { weapon.weaponType = weaponType; return weapon; } - /// 伤害骰子 - public static DataAddition DamageDice(int value, DamageType type) { - DataDamageDice dice = new DataDamageDice(value, type); - DataAddition addition = new DataAddition(); - addition.damageDices.Add(dice); - return addition; + + /// 空手 1d2 + public static DataWeapon Weapon000() { + DataWeapon weapon = Weapon("空手", WeaponType.无); + weapon.damageDice = new DataDamageDice(2, DamageType.无); + return weapon; } /// 匕首 1d4 public static DataWeapon Weapon101() { DataWeapon weapon = Weapon("匕首", WeaponType.轻型武器); - weapon.additions.Add(DamageDice(4, DamageType.穿刺)); + weapon.damageDice = new DataDamageDice(4, DamageType.穿刺); return weapon; } /// 短弓 1d6 public static DataWeapon Weapon102() { DataWeapon weapon = Weapon("短弓", WeaponType.轻型武器); - weapon.additions.Add(DamageDice(6, DamageType.穿刺)); + weapon.damageDice = new DataDamageDice(6, DamageType.穿刺); return weapon; } /// 木棒 1d6 public static DataWeapon Weapon201() { DataWeapon weapon = Weapon("木棒", WeaponType.中型武器); - weapon.additions.Add(DamageDice(6, DamageType.挥砍)); + weapon.damageDice = new DataDamageDice(6, DamageType.钝击); return weapon; } /// 巨棒 1d8 public static DataWeapon Weapon301() { DataWeapon weapon = Weapon("巨棒", WeaponType.重型武器); - weapon.additions.Add(DamageDice(8, DamageType.钝击)); + weapon.damageDice = new DataDamageDice(8, DamageType.钝击); return weapon; } /// 法杖 1d6 public static DataWeapon Weapon302() { DataWeapon weapon = Weapon("法杖", WeaponType.重型武器); - weapon.additions.Add(DamageDice(6, DamageType.钝击)); + weapon.damageDice = new DataDamageDice(6, DamageType.钝击); return weapon; }