清理项目
This commit is contained in:
@@ -1,108 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Random = System.Random;
|
||||
|
||||
public class DNDWarrior : MonoBehaviour {
|
||||
// 战士基础属性
|
||||
public int Strength { get; private set; }
|
||||
public int Dexterity { get; private set; }
|
||||
public int Constitution { get; private set; }
|
||||
public int Intelligence { get; private set; }
|
||||
public int Wisdom { get; private set; }
|
||||
public int Charisma { get; private set; }
|
||||
|
||||
public int Level { get; private set; } = 1;
|
||||
public int HitPoints { get; private set; }
|
||||
public int ArmorClass { get; private set; }
|
||||
public string ArmorType { get; private set; } = "Chain Mail"; // 默认中甲
|
||||
|
||||
private Random _random = new Random();
|
||||
|
||||
private void Awake() {
|
||||
Strength = Roll4d6();
|
||||
Dexterity = Roll4d6();
|
||||
Constitution = Roll4d6();
|
||||
Intelligence = Roll4d6();
|
||||
Wisdom = Roll4d6();
|
||||
Charisma = Roll4d6();
|
||||
|
||||
// 计算初始生命值(1d10+体质修正)
|
||||
HitPoints = 10 + GetAbilityModifier(Constitution);
|
||||
CalculateAC();
|
||||
PrintCharacterSheet();
|
||||
|
||||
Console.WriteLine("\n=== 升级到12级 ===");
|
||||
LevelUpTo(12);
|
||||
PrintCharacterSheet();
|
||||
}
|
||||
|
||||
// 4d6规则:投4次d6,去掉最低值
|
||||
private int Roll4d6() {
|
||||
List<int> rolls = new List<int>();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
rolls.Add(_random.Next(1, 7));
|
||||
}
|
||||
rolls.Sort();
|
||||
return rolls[1] + rolls[2] + rolls[3]; // 取最高3个值
|
||||
}
|
||||
|
||||
// 计算属性调整值(属性值-10)/2 向下取整
|
||||
private int GetAbilityModifier(int abilityScore) {
|
||||
return (int)Math.Floor((abilityScore - 10) / 2.0);
|
||||
}
|
||||
|
||||
// 计算护甲等级(AC)
|
||||
private void CalculateAC() {
|
||||
int dexModifier = GetAbilityModifier(Dexterity);
|
||||
|
||||
switch (ArmorType) {
|
||||
case "Plate Armor": // 重甲(敏捷修正上限+1)
|
||||
ArmorClass = 18 + Math.Min(dexModifier, 1);
|
||||
break;
|
||||
case "Chain Mail": // 中甲(敏捷修正上限+2)
|
||||
ArmorClass = 16 + Math.Min(dexModifier, 2);
|
||||
break;
|
||||
default: // 无甲(全敏捷修正)
|
||||
ArmorClass = 10 + dexModifier;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 升级到指定等级(模拟到12级)
|
||||
public void LevelUpTo(int targetLevel) {
|
||||
while (Level < targetLevel) {
|
||||
Level++;
|
||||
|
||||
// 每级生命值增加:1d10+体质修正
|
||||
HitPoints += _random.Next(1, 11) + GetAbilityModifier(Constitution);
|
||||
|
||||
// 每4级获得属性点(4/8/12级)
|
||||
if (Level % 4 == 0) {
|
||||
// 战士优先提升力量或体质
|
||||
if (Strength < 20) Strength += 2;
|
||||
else if (Constitution < 20) Constitution += 2;
|
||||
}
|
||||
|
||||
// 6级更换板甲
|
||||
if (Level == 6) ArmorType = "Plate Armor";
|
||||
|
||||
CalculateAC(); // 更新AC
|
||||
}
|
||||
}
|
||||
|
||||
// 打印角色卡
|
||||
public void PrintCharacterSheet() {
|
||||
Debug.Log($"=== 战士 LV{Level} ===");
|
||||
Debug.Log($"力量: {Strength} (+{GetAbilityModifier(Strength)})");
|
||||
Debug.Log($"敏捷: {Dexterity} (+{GetAbilityModifier(Dexterity)})");
|
||||
Debug.Log($"体质: {Constitution} (+{GetAbilityModifier(Constitution)})");
|
||||
Debug.Log($"智力: {Intelligence} (+{GetAbilityModifier(Intelligence)})");
|
||||
Debug.Log($"感知: {Wisdom} (+{GetAbilityModifier(Wisdom)})");
|
||||
Debug.Log($"魅力: {Charisma} (+{GetAbilityModifier(Charisma)})");
|
||||
Debug.Log($"生命值: {HitPoints}");
|
||||
Debug.Log($"护甲: {ArmorType} (AC: {ArmorClass})");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d99eda4d1308724c8374c9e305743bc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,123 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 属性 - 数据
|
||||
/// </summary>
|
||||
public class DataAttribute {
|
||||
/// <summary> 力量(strength) </summary>
|
||||
public virtual int Str { get; set; }
|
||||
/// <summary> 敏捷(dexterity) </summary>
|
||||
public virtual int Dex { get; set; }
|
||||
/// <summary> 体质(constitution) </summary>
|
||||
public virtual int Con { get; set; }
|
||||
/// <summary> 智力(intelligence) </summary>
|
||||
public virtual int Int { get; set; }
|
||||
/// <summary> 感知(wisdom) </summary>
|
||||
public virtual int Wis { get; set; }
|
||||
/// <summary> 魅力(charisma) </summary>
|
||||
public virtual int Cha { get; set; }
|
||||
|
||||
/// <summary> 力量调整值(strength) </summary>
|
||||
public int StrModifier => AttributeTool.Modifier(Str);
|
||||
/// <summary> 敏捷调整值(dexterity) </summary>
|
||||
public int DexModifier => AttributeTool.Modifier(Dex);
|
||||
/// <summary> 体质调整值(constitution) </summary>
|
||||
public int ConModifier => AttributeTool.Modifier(Con);
|
||||
/// <summary> 智力调整值(intelligence) </summary>
|
||||
public int IntModifier => AttributeTool.Modifier(Int);
|
||||
/// <summary> 感知调整值(wisdom) </summary>
|
||||
public int WisModifier => AttributeTool.Modifier(Wis);
|
||||
/// <summary> 魅力调整值(charisma) </summary>
|
||||
public int ChaModifier => AttributeTool.Modifier(Cha);
|
||||
}
|
||||
/// <summary>
|
||||
/// 角色 - 数据
|
||||
/// TODO: 补充角色的专长(Feats)、技能(Skills)、法术(Spells)等
|
||||
/// </summary>
|
||||
public class DataCharacter : DataAttribute {
|
||||
/// <summary> 名字 </summary>
|
||||
public string name;
|
||||
/// <summary> 经验 </summary>
|
||||
public int expPoint;
|
||||
/// <summary> 种族 </summary>
|
||||
public DataRace race;
|
||||
/// <summary> 属性 </summary>
|
||||
public DataAttribute basis;
|
||||
/// <summary> 职业 </summary>
|
||||
public DataProfession profession;
|
||||
/// <summary> 装备 </summary>
|
||||
public DataEquipment equipment;
|
||||
|
||||
/// <summary> 战斗等级 </summary>
|
||||
public int Level => CharacterTool.GetLevel(this);
|
||||
/// <summary> 生命点 </summary>
|
||||
public int HitPoint => CharacterTool.GetHitPoint(this);
|
||||
/// <summary> 护甲等级 </summary>
|
||||
public int ArmorClass => CharacterTool.GetArmorClass(this);
|
||||
|
||||
/// <summary> 力量(strength) 基础值 + 种族加值 </summary>
|
||||
public override int Str { get => basis.Str + race.Str; }
|
||||
/// <summary> 敏捷(dexterity) 基础值 + 种族加值 </summary>
|
||||
public override int Dex { get => basis.Dex + race.Dex; }
|
||||
/// <summary> 体质(constitution) 基础值 + 种族加值 </summary>
|
||||
public override int Con { get => basis.Con + race.Con; }
|
||||
/// <summary> 智力(intelligence) 基础值 + 种族加值 </summary>
|
||||
public override int Int { get => basis.Int + race.Int; }
|
||||
/// <summary> 感知(wisdom) 基础值 + 种族加值 </summary>
|
||||
public override int Wis { get => basis.Wis + race.Wis; }
|
||||
/// <summary> 魅力(charisma) 基础值 + 种族加值 </summary>
|
||||
public override int Cha { get => basis.Cha + race.Cha; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 种族 - 数据
|
||||
/// TODO: 补充种族特殊能力
|
||||
/// </summary>
|
||||
public class DataRace : DataAttribute {
|
||||
/// <summary> 种族名称 </summary>
|
||||
public string name;
|
||||
}
|
||||
/// <summary>
|
||||
/// 职业 - 数据
|
||||
/// </summary>
|
||||
public class DataProfession {
|
||||
/// <summary> 职业名称 </summary>
|
||||
public string name;
|
||||
/// <summary> 生命骰子 </summary>
|
||||
public int hitDice = 0;
|
||||
/// <summary> 角色 </summary>
|
||||
public DataCharacter character;
|
||||
/// <summary> 职业等级 </summary>
|
||||
public int level = 0;
|
||||
/// <summary> 累计生命点 </summary>
|
||||
public List<int> hitPoints = new List<int>();
|
||||
}
|
||||
/// <summary>
|
||||
/// 战斗角色 - 数据
|
||||
/// </summary>
|
||||
public class DataCombatRole : DataAttribute {
|
||||
/// <summary> 角色数据 </summary>
|
||||
public readonly DataCharacter character;
|
||||
/// <summary> 战斗角色 </summary>
|
||||
public DataCombatRole(DataCharacter character) => this.character = character;
|
||||
|
||||
/// <summary> 归属队伍 </summary>
|
||||
public int team;
|
||||
/// <summary> 角色名字 </summary>
|
||||
public string name;
|
||||
/// <summary> 战斗等级 </summary>
|
||||
public int level;
|
||||
/// <summary> 战场位置 </summary>
|
||||
public int position;
|
||||
/// <summary> 先攻顺序 </summary>
|
||||
public int sequence;
|
||||
/// <summary> 护甲等级 </summary>
|
||||
public int armorClass;
|
||||
/// <summary> 生命点 </summary>
|
||||
public Vector2Int hitPoint;
|
||||
/// <summary> 武器1 </summary>
|
||||
public DataWeapon weapon1;
|
||||
/// <summary> 武器2 </summary>
|
||||
public DataWeapon weapon2;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ae234ab6cd19bf46983ee5f38afd957
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,31 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 装备栏 - 库存
|
||||
/// </summary>
|
||||
public class DataEquipment {
|
||||
/// <summary> 武器1 </summary>
|
||||
public DataWeapon weapon1;
|
||||
/// <summary> 武器2 </summary>
|
||||
public DataWeapon weapon2;
|
||||
/// <summary> 护甲 </summary>
|
||||
public DataArmor armor;
|
||||
/// <summary> 头盔 </summary>
|
||||
public DataWear helmets;
|
||||
/// <summary> 手套 </summary>
|
||||
public DataWear gloves;
|
||||
/// <summary> 鞋子 </summary>
|
||||
public DataWear shoes;
|
||||
|
||||
/// <summary> 附加效果 </summary>
|
||||
public DataAddition addition = new DataAddition();
|
||||
}
|
||||
/// <summary>
|
||||
/// 附加 - 数据
|
||||
/// </summary>
|
||||
public class DataAddition {
|
||||
/// <summary> 护甲等级 </summary>
|
||||
public int armorClass = 0;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62fae57d4dbef374ba92424caa7b6885
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,27 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 库存类型枚举,区分背包、仓库等不同库存。
|
||||
/// </summary>
|
||||
public enum InventoryType { EquipmentSlot, Backpack, Storage }
|
||||
/// <summary>
|
||||
/// 物品库存 - 数据
|
||||
/// </summary>
|
||||
public abstract class DataInventory {
|
||||
/// <summary> 库存类型 </summary>
|
||||
public InventoryType inventoryType;
|
||||
}
|
||||
/// <summary>
|
||||
/// 仓库 - 库存
|
||||
/// </summary>
|
||||
public class DataStorage : DataInventory {
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 背包 - 库存
|
||||
/// </summary>
|
||||
public class DataBackpack : DataInventory {
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 278351779c3c1514bbcce18723dd500c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,83 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 物品类型
|
||||
/// </summary>
|
||||
public enum ItemType { 材料, 装备 }
|
||||
/// <summary>
|
||||
/// 物品 - 数据
|
||||
/// </summary>
|
||||
public class DataItem {
|
||||
/// <summary> 物品名称 </summary>
|
||||
public string name;
|
||||
/// <summary> 物品类型 </summary>
|
||||
public ItemType itemType;
|
||||
}
|
||||
/// <summary>
|
||||
/// 材料 - 数据
|
||||
/// </summary>
|
||||
public class DataMaterial : DataItem {
|
||||
/// <summary> 物品数量 </summary>
|
||||
public int quantity;
|
||||
/// <summary> 堆叠上限 </summary>
|
||||
public int maxStack;
|
||||
}
|
||||
/// <summary>
|
||||
/// 穿戴类型
|
||||
/// </summary>
|
||||
public enum WearType { 武器, 护甲, 头盔, 手套, 鞋子, }
|
||||
/// <summary>
|
||||
/// 穿戴 - 数据
|
||||
/// </summary>
|
||||
public class DataWear : DataItem {
|
||||
/// <summary> 装备类型 </summary>
|
||||
public WearType wearType;
|
||||
/// <summary> 附加列表 </summary>
|
||||
public List<DataAddition> additions = new List<DataAddition>();
|
||||
/// <summary> 附加效果 </summary>
|
||||
public virtual DataAddition Addition => EquipmentTool.Merge(additions);
|
||||
}
|
||||
/// <summary>
|
||||
/// 武器类型。
|
||||
/// </summary>
|
||||
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>
|
||||
/// 护甲类型。
|
||||
/// </summary>
|
||||
public enum ArmorType { 布甲, 轻甲, 中甲, 重甲, }
|
||||
/// <summary>
|
||||
/// 护甲 - 数据
|
||||
/// </summary>
|
||||
public class DataArmor : DataWear {
|
||||
/// <summary> 护甲类型 </summary>
|
||||
public ArmorType armorType;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 557ad290ccf27454baad3a04e41aec95
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,46 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 用户
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class DataUser {
|
||||
public string id;
|
||||
public string username;
|
||||
public string passwordhash;
|
||||
}
|
||||
/// <summary>
|
||||
/// 注册请求
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class DataRegisterRequest {
|
||||
public string username;
|
||||
public string password;
|
||||
}
|
||||
/// <summary>
|
||||
/// 登录请求
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class DataLoginRequest {
|
||||
public string username;
|
||||
public string password;
|
||||
}
|
||||
/// <summary>
|
||||
/// 登录响应,返回JWT。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class DataLoginResponse {
|
||||
public string token;
|
||||
}
|
||||
/// <summary>
|
||||
/// 修改密码请求。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class DataChangePasswordRequest {
|
||||
public string username;
|
||||
public string oldpassword;
|
||||
public string newpassword;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: febe432c83103fd4fbbc833bc7dd08cd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7cb6057f1015c34e83bfc292a519030
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 59e1aa3dad18b83438571f22a94d78af
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,36 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 阶段类型
|
||||
/// </summary>
|
||||
public enum PhaseType {
|
||||
先攻阶段, 突袭阶段, 回合阶段, 行动阶段, 结算阶段,
|
||||
选择角色, 角色攻击
|
||||
}
|
||||
/// <summary>
|
||||
/// 阶段
|
||||
/// </summary>
|
||||
public interface IPhase {
|
||||
/// <summary> 执行阶段 </summary>
|
||||
public void Execute();
|
||||
}
|
||||
/// <summary>
|
||||
/// 战斗阶段
|
||||
/// </summary>
|
||||
public abstract class BattlePhase : IPhase {
|
||||
/// <summary> 模拟器 </summary>
|
||||
public readonly BattleSimulator simulator;
|
||||
|
||||
/// <summary> 行动角色 </summary>
|
||||
public DataCombatRole ActionRole => simulator.actionRole;
|
||||
/// <summary> 战斗队列 </summary>
|
||||
public BattleQueue BattleQueue => simulator.battleQueue;
|
||||
|
||||
public BattlePhase(BattleSimulator simulator) => this.simulator = simulator;
|
||||
|
||||
public abstract void Execute();
|
||||
/// <summary> 阶段过渡 </summary>
|
||||
public void Transition(PhaseType phaseType) => simulator.Transition(phaseType);
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee046dc0d64f6184c966baba17876ec9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,89 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 行动阶段
|
||||
/// </summary>
|
||||
public class PhaseAction : BattlePhase {
|
||||
|
||||
public PhaseAction(BattleSimulator simulator) : base(simulator) { }
|
||||
|
||||
public override void Execute() {
|
||||
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 行动角色选择
|
||||
/// </summary>
|
||||
public class PhaseActionRoleSelect : BattlePhase {
|
||||
|
||||
public PhaseActionRoleSelect(BattleSimulator simulator) : base(simulator) { }
|
||||
|
||||
public override void Execute() {
|
||||
// 选择行动的角色,如果没有则进入下一回合
|
||||
if (!BattleQueue.Dequeue(out simulator.actionRole)) { Transition(PhaseType.回合阶段); return; }
|
||||
// 判断是否可以行动
|
||||
if (ActionRole.hitPoint.x <= 0) { Transition(PhaseType.选择角色); return; }
|
||||
// 进行ai判断
|
||||
// TODO: 进行武器攻击,使用技能,使用法术,使用物品的判断
|
||||
Transition(PhaseType.角色攻击);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 武器攻击
|
||||
/// </summary>
|
||||
public class PhaseActionRoleAttack : BattlePhase {
|
||||
|
||||
public PhaseActionRoleAttack(BattleSimulator simulator) : base(simulator) { }
|
||||
|
||||
public override void Execute() {
|
||||
// 如果没有可以攻击的目标则结算战斗
|
||||
if (!AttackTarget(out DataCombatRole target)) { 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;
|
||||
// 如果命中小于等于目标护甲等级,则不造成伤害
|
||||
if (hit > armorClass) {
|
||||
// 获取所有武器伤害骰
|
||||
DataDamageDice damageDice = ActionRole.weapon1.damageDice;
|
||||
// 伤害计算: 武器伤害骰 + 属性修正
|
||||
int damage = Dice.Roll(damageDice.value) + modifier;
|
||||
target.hitPoint.x -= damage;
|
||||
// 生成战斗消息
|
||||
MessageHit(hit, weaponName, target.name, armorClass, damage, damageDice.type);
|
||||
}
|
||||
else {
|
||||
// 生成战斗消息
|
||||
MessageMiss(hit, weaponName, target.name, armorClass);
|
||||
}
|
||||
// 结束行动
|
||||
Transition(PhaseType.选择角色);
|
||||
}
|
||||
/// <summary> 攻击目标 </summary>
|
||||
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>
|
||||
private bool Hostility(DataCombatRole role) {
|
||||
return role.team != ActionRole.team && role.hitPoint.x > 0;
|
||||
}
|
||||
/// <summary> 战斗消息:没有命中 </summary>
|
||||
private void MessageMiss(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 MessageHit(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);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad6c0033db83a3c4fa9d92f3f1912d5f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,15 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 突袭阶段
|
||||
/// </summary>
|
||||
public class PhaseAssault : BattlePhase {
|
||||
|
||||
public PhaseAssault(BattleSimulator simulator) : base(simulator) { }
|
||||
|
||||
public override void Execute() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 620e71ced51f8e94997a198ac8b1e6c6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,18 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 结束阶段
|
||||
/// </summary>
|
||||
public class PhaseFinish : BattlePhase {
|
||||
|
||||
public PhaseFinish(BattleSimulator simulator) : base(simulator) { }
|
||||
|
||||
public override void Execute() {
|
||||
// TODO:需要添加结算判断
|
||||
// simulator.Transition(PhaseType.回合阶段);
|
||||
// TODO:记录器
|
||||
Debug.Log("结束战斗!");
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 357207f5d09ca394e84210d51916507b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,24 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 正式阶段
|
||||
/// </summary>
|
||||
public class PhaseFormal : BattlePhase {
|
||||
/// <summary> 回合计数 </summary>
|
||||
public int roundCount;
|
||||
|
||||
public PhaseFormal(BattleSimulator simulator) : base(simulator) { }
|
||||
|
||||
public override void Execute() {
|
||||
roundCount++;
|
||||
BattleQueue.UpdateQueue();
|
||||
// TODO:记录器
|
||||
Debug.Log($"正式回合:{roundCount}");
|
||||
string message = "存活";
|
||||
BattleQueue.ForEach(obj => message += $" {obj.name}({obj.hitPoint.x})");
|
||||
Debug.Log(message);
|
||||
simulator.Transition(PhaseType.选择角色);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 066680fafb7f9cf4dbac4f7291e682cc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,22 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 先攻阶段
|
||||
/// </summary>
|
||||
public class PhaseInitiative : BattlePhase {
|
||||
|
||||
public PhaseInitiative(BattleSimulator simulator) : base(simulator) { }
|
||||
|
||||
public override void Execute() {
|
||||
BattleQueue.ForEach(obj => obj.sequence = Dice.Roll20(obj.DexModifier));
|
||||
BattleQueue.OrderByDescending(c => c.sequence);
|
||||
// TODO:需要添加突袭阶段
|
||||
// TODO:记录器
|
||||
string message = "先攻";
|
||||
BattleQueue.ForEach(obj => message += $" {obj.name}({obj.sequence})");
|
||||
Debug.Log(message);
|
||||
simulator.Transition(PhaseType.回合阶段);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4fc0f8aced9d5f04f879b8300fd02e47
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,49 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 战斗队列
|
||||
/// </summary>
|
||||
public class BattleQueue {
|
||||
/// <summary> 执行队列 </summary>
|
||||
public Queue<DataCombatRole> queue = new Queue<DataCombatRole>();
|
||||
/// <summary> 战斗合集 </summary>
|
||||
public List<DataCombatRole> characters = new List<DataCombatRole>();
|
||||
|
||||
/// <summary> 添加角色 </summary>
|
||||
public void Add(List<DataCombatRole> list) {
|
||||
characters.AddRange(list);
|
||||
}
|
||||
/// <summary> 添加角色 </summary>
|
||||
public void Add(DataCombatRole character) {
|
||||
characters.Add(character);
|
||||
}
|
||||
/// <summary> 遍历角色 </summary>
|
||||
public void ForEach(Action<DataCombatRole> action) {
|
||||
characters.ForEach(action);
|
||||
}
|
||||
// /// <summary> 排序:大到小 </summary>
|
||||
public void OrderByDescending(Func<DataCombatRole, int> func) {
|
||||
characters = characters.OrderByDescending(func).ToList();
|
||||
}
|
||||
/// <summary> 根据条件查询元素 </summary>
|
||||
public List<DataCombatRole> Where(Func<DataCombatRole, bool> predicate) {
|
||||
return characters.Where(predicate).ToList();
|
||||
}
|
||||
/// <summary> 根据条件查询第一个匹配的元素 </summary>
|
||||
public DataCombatRole FirstOrDefault(Func<DataCombatRole, bool> predicate) {
|
||||
return characters.FirstOrDefault(predicate);
|
||||
}
|
||||
/// <summary> 更新队列 </summary>
|
||||
public void UpdateQueue() {
|
||||
queue = new Queue<DataCombatRole>(characters);
|
||||
}
|
||||
/// <summary> 取出一个 </summary>
|
||||
public bool Dequeue(out DataCombatRole battle) {
|
||||
battle = queue.Count > 0 ? queue.Dequeue() : null;
|
||||
return battle != null;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed7fc5b50e619ea4a8eaf9d71dc0ec9d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,105 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 战斗报告
|
||||
/// </summary>
|
||||
public class BattleReport {
|
||||
/// <summary> 战斗消息 </summary>
|
||||
public List<BattleMessage> messages;
|
||||
}
|
||||
/// <summary>
|
||||
/// 战斗消息
|
||||
/// </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>
|
||||
/// 普通攻击 - 战斗消息
|
||||
/// </summary>
|
||||
public class MessageNormalAttack : BattleMessage {
|
||||
/// <summary> 攻击者 </summary>
|
||||
public DataCombatRole attacker;
|
||||
/// <summary> 命中值 </summary>
|
||||
public int hit;
|
||||
/// <summary> 伤害值 </summary>
|
||||
public int damage;
|
||||
|
||||
/// <summary> 被攻击者 </summary>
|
||||
public DataCombatRole attacked;
|
||||
/// <summary> 护甲等级 </summary>
|
||||
public int armorClass;
|
||||
|
||||
/// <summary> 设置攻击者 </summary>
|
||||
public void Settings(DataCombatRole attacker, int hit, int damage) {
|
||||
this.attacker = attacker;
|
||||
this.hit = hit;
|
||||
this.damage = damage;
|
||||
}
|
||||
/// <summary> 设置被攻击者 </summary>
|
||||
public void Settings(DataCombatRole attacked, int armorClass) {
|
||||
this.attacked = attacked;
|
||||
this.armorClass = armorClass;
|
||||
}
|
||||
public override string ToString() {
|
||||
return $"{attacker.name}{Dynamics()}{attacked.name}({armorClass}),{attacked.name}{Result()}";
|
||||
}
|
||||
|
||||
/// <summary> 动态修饰词 </summary>
|
||||
private string Dynamics() {
|
||||
return $"使用长剑劈向({hit})";
|
||||
}
|
||||
/// <summary> 结果修饰词 </summary>
|
||||
private string Result() {
|
||||
return hit <= armorClass ? Miss() : Hit();
|
||||
}
|
||||
// 未命中的多种情况
|
||||
private string Miss() {
|
||||
string[] missText = new string[] {
|
||||
"轻松避开了这一击!",
|
||||
"巧妙地闪开了!",
|
||||
"险之又险地躲过了!",
|
||||
"成功格挡住了!"
|
||||
};
|
||||
return RandomChoice(missText);
|
||||
}
|
||||
// 命中的情况,可根据伤害量或是否暴击细分
|
||||
private string Hit() {
|
||||
string[] hitText = new string[] {
|
||||
$"躲避不及遭受到了{damage}点伤害!",
|
||||
$"被狠狠击中,承受了{damage}点伤害!",
|
||||
$"格挡失败受到了{damage}点伤害!",
|
||||
};
|
||||
return RandomChoice(hitText);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26a3fb20ae1a54143ab478049f4acd8e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,46 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 战斗 - 模拟器
|
||||
/// </summary>
|
||||
public class BattleSimulator {
|
||||
/// <summary> 当前行动 </summary>
|
||||
public DataCombatRole actionRole;
|
||||
/// <summary> 战斗队列 </summary>
|
||||
public BattleQueue battleQueue = new BattleQueue();
|
||||
|
||||
/// <summary> 当前阶段 </summary>
|
||||
public IPhase currentPhase;
|
||||
/// <summary> 阶段字典 </summary>
|
||||
public Dictionary<PhaseType, IPhase> dictionary = new Dictionary<PhaseType, IPhase>();
|
||||
|
||||
public BattleSimulator(BattleTeam team1, BattleTeam team2) {
|
||||
team1.Initial();
|
||||
team2.Initial();
|
||||
|
||||
team1.Settings(1, 1);
|
||||
team2.Settings(2, 1);
|
||||
|
||||
battleQueue.Add(team1.battles);
|
||||
battleQueue.Add(team2.battles);
|
||||
|
||||
dictionary.Add(PhaseType.先攻阶段, new PhaseInitiative(this));
|
||||
dictionary.Add(PhaseType.突袭阶段, new PhaseAssault(this));
|
||||
dictionary.Add(PhaseType.回合阶段, new PhaseFormal(this));
|
||||
dictionary.Add(PhaseType.行动阶段, new PhaseAction(this));
|
||||
dictionary.Add(PhaseType.选择角色, new PhaseActionRoleSelect(this));
|
||||
dictionary.Add(PhaseType.角色攻击, new PhaseActionRoleAttack(this));
|
||||
dictionary.Add(PhaseType.结算阶段, new PhaseFinish(this));
|
||||
}
|
||||
|
||||
/// <summary> 阶段过渡 </summary>
|
||||
public void Transition(PhaseType phaseType) {
|
||||
// 检查阶段字典中是否存在指定的阶段类型
|
||||
if (!dictionary.TryGetValue(phaseType, out IPhase newPhase)) { return; }
|
||||
currentPhase = newPhase;
|
||||
currentPhase?.Execute();
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ade6b45b3d808449b5ed0cf0810fffd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,10 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 战斗技能
|
||||
/// </summary>
|
||||
public class BattleSkill {
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4f5e0db8e96cfd4d8d9243f4057f99a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,43 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 战斗队伍
|
||||
/// </summary>
|
||||
public class BattleTeam {
|
||||
/// <summary> 队伍名字 </summary>
|
||||
public string name;
|
||||
/// <summary> 原始数据 </summary>
|
||||
public List<DataCharacter> characters = new List<DataCharacter>();
|
||||
/// <summary> 战斗数据 </summary>
|
||||
public List<DataCombatRole> battles = new List<DataCombatRole>();
|
||||
|
||||
/// <summary> 添加角色 </summary>
|
||||
public void Add(List<DataCharacter> list) {
|
||||
characters.AddRange(list);
|
||||
}
|
||||
/// <summary> 添加角色 </summary>
|
||||
public void Add(DataCharacter obj) {
|
||||
characters.Add(obj);
|
||||
}
|
||||
/// <summary> 删除角色 </summary>
|
||||
public void Remove(DataCharacter character) {
|
||||
characters.Remove(character);
|
||||
}
|
||||
|
||||
/// <summary> 初始化 </summary>
|
||||
public void Initial() {
|
||||
characters.ForEach(Initial);
|
||||
}
|
||||
/// <summary> 初始化 </summary>
|
||||
public void Initial(DataCharacter character) {
|
||||
DataCombatRole role = new DataCombatRole(character);
|
||||
role.Initial();
|
||||
battles.Add(role);
|
||||
}
|
||||
/// <summary> 战斗编队 </summary>
|
||||
public void Settings(int team, int position) {
|
||||
battles.ForEach(obj => obj.Settings(team, position));
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 60ddd9f20d0d1bd49a6b68d86ccc904a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,26 +0,0 @@
|
||||
### 战斗流程示例
|
||||
|
||||
#### 先攻判断
|
||||
- 艾薇拉(18) → 哥布林射手(15) → 托尔吉(7) → 哥布林战士(5)
|
||||
|
||||
#### 突袭轮
|
||||
- 哥布林射手 使用短弓射击(23)对艾薇拉(AC12)造成了 5穿刺伤害
|
||||
|
||||
#### 正式回合1
|
||||
- 艾薇拉 施放纠缠术(法术豁免DC14),哥布林射手(敏捷豁免6)被束缚
|
||||
- 艾薇拉 躲至矿石掩体后(AC提升至14)
|
||||
|
||||
- 哥布林射手 试图挣脱藤蔓(力量豁免3)失败了
|
||||
- 哥布林射手 使用多重射击,第一箭(劣势2)对托尔吉(AC14)未命中,第二箭(劣势9)对托尔吉(AC14)未命中
|
||||
|
||||
- 托尔吉 使用狂暴(附赠动作开启)→ 获得力量加成与抗性
|
||||
- 托尔吉 移动至哥布林战士前面
|
||||
- 托尔吉 使用巨斧猛击(19)对哥布林战士(AC12) 造成了 14钝击伤害
|
||||
- 托尔吉 使用巨斧猛击(19)没有命中哥布林战士(AC12)
|
||||
|
||||
- 哥布林战士死亡
|
||||
|
||||
#### 正式回合2
|
||||
- 艾薇拉 施放奥术飞弹(法术豁免DC14),哥布林射手(敏捷豁免6)受到了 10奥术伤害
|
||||
|
||||
- 哥布林射手死亡
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dc4066f5b83586a47bc6bc8ce0115d1d
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f85c0d8dce903b4eb5fb0aca37d2040
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,48 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 属性 - 工具
|
||||
/// </summary>
|
||||
public static class AttributeTool {
|
||||
|
||||
#region 创建
|
||||
/// <summary> 随机初始属性 </summary>
|
||||
public static DataAttribute Random() {
|
||||
DataAttribute attribute = new DataAttribute();
|
||||
attribute.Str = Dice.RollAttribute();
|
||||
attribute.Dex = Dice.RollAttribute();
|
||||
attribute.Con = Dice.RollAttribute();
|
||||
attribute.Int = Dice.RollAttribute();
|
||||
attribute.Wis = Dice.RollAttribute();
|
||||
attribute.Cha = Dice.RollAttribute();
|
||||
return attribute;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 扩展
|
||||
// 计算属性调整值(属性值-10)/2 向下取整
|
||||
public static int Modifier(int value) {
|
||||
return (int)System.Math.Floor((value - 10) / 2.0);
|
||||
}
|
||||
/// <summary> 添加属性 </summary>
|
||||
public static void Add(this DataAttribute a, DataAttribute b) {
|
||||
a.Str += b.Str; a.Dex += b.Dex;
|
||||
a.Con += b.Con; a.Int += b.Int;
|
||||
a.Wis += b.Wis; a.Cha += b.Cha;
|
||||
}
|
||||
/// <summary> 减少属性 </summary>
|
||||
public static void Sub(this DataAttribute a, DataAttribute b) {
|
||||
a.Str -= b.Str; a.Dex -= b.Dex;
|
||||
a.Con -= b.Con; a.Int -= b.Int;
|
||||
a.Wis -= b.Wis; a.Cha -= b.Cha;
|
||||
}
|
||||
/// <summary> 覆盖属性 </summary>
|
||||
public static void Cover(this DataAttribute a, DataAttribute b) {
|
||||
a.Str = b.Str; a.Dex = b.Dex;
|
||||
a.Con = b.Con; a.Int = b.Int;
|
||||
a.Wis = b.Wis; a.Cha = b.Cha;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f6a814b3a3b754241ae35753e6d7c7f8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,56 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 角色 - 字典
|
||||
/// </summary>
|
||||
public static class CharacterDictionary {
|
||||
/// <summary> 艾薇拉 精灵 法师 </summary>
|
||||
public static DataCharacter Character001() {
|
||||
DataCharacter character = new DataCharacter();
|
||||
character.name = "艾薇拉";
|
||||
character.race = RaceTool.Elven();
|
||||
character.basis = new DataAttribute { Str = 8, Dex = 12, Con = 10, Int = 16, Wis = 14, Cha = 11 };
|
||||
character.profession = ProfessionTool.Wizard();
|
||||
character.profession.Initial(character);
|
||||
character.equipment = new DataEquipment();
|
||||
// 装备法杖
|
||||
character.equipment.Wear(WeaponDictionary.Weapon302(), out DataWear old1);
|
||||
// 装备法袍
|
||||
character.equipment.Wear(ArmorDictionary.Armor101(), out DataWear old2);
|
||||
return character;
|
||||
}
|
||||
/// <summary> 托尔吉 兽人 战士 </summary>
|
||||
public static DataCharacter Character002() {
|
||||
DataCharacter character = new DataCharacter();
|
||||
character.name = "托尔吉";
|
||||
character.race = RaceTool.Orc();
|
||||
character.basis = new DataAttribute { Str = 16, Dex = 10, Con = 14, Int = 8, Wis = 10, Cha = 9 };
|
||||
character.profession = ProfessionTool.Warrior();
|
||||
character.profession.Initial(character);
|
||||
character.equipment = new DataEquipment();
|
||||
// 装备木棒和木盾
|
||||
character.equipment.Wear(WeaponDictionary.Weapon201(), out DataWear old1);
|
||||
character.equipment.Wear(WeaponDictionary.Weapon401(), out DataWear old2);
|
||||
// 装备板甲
|
||||
character.equipment.Wear(ArmorDictionary.Armor401(), out DataWear old3);
|
||||
return character;
|
||||
}
|
||||
/// <summary> 格伦布林 矮人 牧师 </summary>
|
||||
public static DataCharacter Character003() {
|
||||
DataCharacter character = new DataCharacter();
|
||||
character.name = "格伦布林";
|
||||
character.race = RaceTool.Dwarf();
|
||||
character.basis = new DataAttribute { Str = 14, Dex = 10, Con = 16, Int = 9, Wis = 15, Cha = 12 };
|
||||
character.profession = ProfessionTool.Cleric();
|
||||
character.profession.Initial(character);
|
||||
character.equipment = new DataEquipment();
|
||||
// 装备木棒和木盾
|
||||
character.equipment.Wear(WeaponDictionary.Weapon201(), out DataWear old1);
|
||||
character.equipment.Wear(WeaponDictionary.Weapon401(), out DataWear old2);
|
||||
// 装备链甲
|
||||
character.equipment.Wear(ArmorDictionary.Armor301(), out DataWear old3);
|
||||
return character;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c6813cdd5afeb949843c657358613db
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,81 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 角色工具
|
||||
/// </summary>
|
||||
public static class CharacterTool {
|
||||
|
||||
#region 设置参数
|
||||
/// <summary> 设置职业 </summary>
|
||||
public static void Settings(this DataCharacter character, DataRace race) {
|
||||
character.race = race;
|
||||
}
|
||||
/// <summary> 设置职业 </summary>
|
||||
public static void Settings(this DataCharacter character, DataProfession profession) {
|
||||
character.profession = profession;
|
||||
profession.character = character;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 属性扩展
|
||||
/// <summary> 战斗等级 </summary>
|
||||
public static int GetLevel(this DataCharacter character) {
|
||||
// TODO:需要补充多职业的等级总和
|
||||
return character.profession.level;
|
||||
}
|
||||
/// <summary> 生命点 </summary>
|
||||
public static int GetHitPoint(this DataCharacter character) {
|
||||
// TODO:需要补充多职业的生命值加成
|
||||
return character.profession.HitPoint();
|
||||
}
|
||||
/// <summary> 计算护甲等级(AC) </summary>
|
||||
public static int GetArmorClass(this DataCharacter character) {
|
||||
// TODO:需要补充专长,技能,熟练之类的加值
|
||||
int modifier = character.DexModifier;
|
||||
return character.equipment.ArmorClass(modifier);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 创建角色
|
||||
/// <summary> 创建默认角色 </summary>
|
||||
public static DataCharacter Create(string name) {
|
||||
DataCharacter character = new DataCharacter();
|
||||
character.name = name;
|
||||
character.race = RaceTool.None();
|
||||
character.basis = AttributeTool.Random();
|
||||
character.profession = ProfessionTool.None();
|
||||
character.profession.Initial(character);
|
||||
character.equipment = new DataEquipment();
|
||||
return character;
|
||||
}
|
||||
/// <summary> 创建默认角色 </summary>
|
||||
public static DataCharacter Create(string name, DataRace race, DataProfession profession) {
|
||||
DataCharacter character = new DataCharacter();
|
||||
character.name = name;
|
||||
character.race = race;
|
||||
character.basis = AttributeTool.Random();
|
||||
character.profession = profession;
|
||||
character.profession.Initial(character);
|
||||
character.equipment = new DataEquipment();
|
||||
return character;
|
||||
}
|
||||
#endregion
|
||||
|
||||
// 打印角色卡
|
||||
public static void PrintCharacterSheet(this DataCharacter character) {
|
||||
Debug.Log($"=== {character.name} LV{character.Level} ===");
|
||||
Debug.Log($"种族: {character.race.name}");
|
||||
Debug.Log($"职业: {character.profession.name}");
|
||||
Debug.Log($"力量: {character.Str} ({character.StrModifier.ToString("+#;-#;+0")})");
|
||||
Debug.Log($"敏捷: {character.Dex} ({character.DexModifier.ToString("+#;-#;+0")})");
|
||||
Debug.Log($"体质: {character.Con} ({character.ConModifier.ToString("+#;-#;+0")})");
|
||||
Debug.Log($"智力: {character.Int} ({character.IntModifier.ToString("+#;-#;+0")})");
|
||||
Debug.Log($"感知: {character.Wis} ({character.WisModifier.ToString("+#;-#;+0")})");
|
||||
Debug.Log($"魅力: {character.Cha} ({character.ChaModifier.ToString("+#;-#;+0")})");
|
||||
Debug.Log($"经验值: {character.expPoint}");
|
||||
Debug.Log($"生命值: {character.HitPoint}");
|
||||
Debug.Log($"护甲等级: {character.ArmorClass})");
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a6bdd4c70e0068d4dbe460c7a6961901
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,30 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 战斗角色 - 工具
|
||||
/// </summary>
|
||||
public static class CombatRoleTool {
|
||||
|
||||
#region 设置参数
|
||||
/// <summary> 初始角色 </summary>
|
||||
public static void Initial(this DataCombatRole role) {
|
||||
AttributeTool.Cover(role, role.character);
|
||||
role.name = role.character.name;
|
||||
role.level = role.character.Level;
|
||||
role.hitPoint = new Vector2Int(role.character.HitPoint, role.character.HitPoint);
|
||||
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) {
|
||||
role.team = team;
|
||||
role.position = position;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2eb2cecc8838b1445a24dce7aa669bd3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,31 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 怪物 - 字典
|
||||
/// </summary>
|
||||
public static class MonsterDictionary {
|
||||
/// <summary> 哥布林战士 怪物 </summary>
|
||||
public static DataCharacter Monster001() {
|
||||
DataCharacter character = new DataCharacter();
|
||||
character.name = "哥布林战士";
|
||||
character.race = RaceTool.None();
|
||||
character.basis = AttributeTool.Random();
|
||||
character.profession = ProfessionTool.None();
|
||||
character.profession.Initial(character);
|
||||
character.equipment = new DataEquipment();
|
||||
return character;
|
||||
}
|
||||
/// <summary> 哥布林射手 怪物 </summary>
|
||||
public static DataCharacter Monster002() {
|
||||
DataCharacter character = new DataCharacter();
|
||||
character.name = "哥布林射手";
|
||||
character.race = RaceTool.None();
|
||||
character.basis = AttributeTool.Random();
|
||||
character.profession = ProfessionTool.None();
|
||||
character.profession.Initial(character);
|
||||
character.equipment = new DataEquipment();
|
||||
return character;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b03641f0b64dd44894d3b5f3cb10d5d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,75 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 种族 - 工具
|
||||
/// </summary>
|
||||
public static class ProfessionTool {
|
||||
|
||||
#region 扩展
|
||||
/// <summary> 初始:满生命骰子 + 体质调整值 </summary>
|
||||
public static void Initial(this DataProfession profession, DataCharacter character) {
|
||||
profession.character = character;
|
||||
int hitPoint = profession.hitDice + character.ConModifier;
|
||||
profession.level = 1;
|
||||
profession.hitPoints = new List<int> { hitPoint };
|
||||
}
|
||||
/// <summary> 升级:骰生命骰子 + 体质调整值 </summary>
|
||||
public static void Upgrade(this DataProfession profession) {
|
||||
profession.level++;
|
||||
int hitPoint = Dice.Roll(profession.hitDice);
|
||||
int modifier = profession.character.ConModifier;
|
||||
profession.hitPoints.Add(hitPoint + modifier);
|
||||
}
|
||||
/// <summary> 生命点:每级生命点总和 </summary>
|
||||
public static int HitPoint(this DataProfession profession) {
|
||||
return profession.hitPoints.Sum();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 创建
|
||||
/// <summary> 创建 </summary>
|
||||
public static DataProfession Create(string name, int hitDice) {
|
||||
DataProfession profession = new DataProfession { name = name, hitDice = hitDice };
|
||||
profession.name = name;
|
||||
profession.hitDice = hitDice;
|
||||
return profession;
|
||||
}
|
||||
/// <summary> 无职业 1d4 </summary>
|
||||
public static DataProfession None() {
|
||||
return Create("无", 4);
|
||||
}
|
||||
/// <summary> 随机职业 </summary>
|
||||
public static DataProfession Random() {
|
||||
int index = Dice.Roll(5);
|
||||
if (index == 1) { return Warrior(); }
|
||||
if (index == 2) { return Wizard(); }
|
||||
if (index == 3) { return Cleric(); }
|
||||
if (index == 4) { return Ranger(); }
|
||||
if (index == 5) { return Chanter(); }
|
||||
return None();
|
||||
}
|
||||
/// <summary> 战士 1d10 </summary>
|
||||
public static DataProfession Warrior() {
|
||||
return Create("战士", 10);
|
||||
}
|
||||
/// <summary> 法师 1d6 </summary>
|
||||
public static DataProfession Wizard() {
|
||||
return Create("法师", 6);
|
||||
}
|
||||
/// <summary> 牧师 1d8 </summary>
|
||||
public static DataProfession Cleric() {
|
||||
return Create("牧师", 8);
|
||||
}
|
||||
/// <summary> 游侠 1d8 </summary>
|
||||
public static DataProfession Ranger() {
|
||||
return Create("游侠", 8);
|
||||
}
|
||||
/// <summary> 歌者 1d6 </summary>
|
||||
public static DataProfession Chanter() {
|
||||
return Create("歌者", 6);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd48318dcbe216449a81d70622f8ba35
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,47 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 种族 - 工具
|
||||
/// </summary>
|
||||
public static class RaceTool {
|
||||
|
||||
#region 创建
|
||||
// 混血人类,木精灵,丘陵矮人(Hill Dwarf),龙裔,半精灵
|
||||
/// <summary> 无种族 </summary>
|
||||
public static DataRace None() {
|
||||
return new DataRace { name = "未知" };
|
||||
}
|
||||
/// <summary> 随机职业 </summary>
|
||||
public static DataRace Random() {
|
||||
int index = Dice.Roll(5);
|
||||
if (index == 1) { return Human(); }
|
||||
if (index == 2) { return Elven(); }
|
||||
if (index == 3) { return Dwarf(); }
|
||||
if (index == 4) { return Orc(); }
|
||||
if (index == 5) { return Halfling(); }
|
||||
return None();
|
||||
}
|
||||
/// <summary> 人类(Human) 全属性+1 </summary>
|
||||
public static DataRace Human() {
|
||||
return new DataRace { name = "人类", Str = 1, Dex = 1, Con = 1, Int = 1, Wis = 1, Cha = 1 };
|
||||
}
|
||||
/// <summary> 精灵(Elven) 敏捷+2 智力+2 感知+1 </summary>
|
||||
public static DataRace Elven() {
|
||||
return new DataRace { name = "精灵", Dex = 2, Int = 2, Wis = 1 };
|
||||
}
|
||||
/// <summary> 矮人(Dwarf) 力量+2 体质+2 感知+1 </summary>
|
||||
public static DataRace Dwarf() {
|
||||
return new DataRace { name = "矮人", Str = 2, Con = 2, Wis = 1 };
|
||||
}
|
||||
/// <summary> 半兽人(Orc) 力量+3 体质+2 </summary>
|
||||
public static DataRace Orc() {
|
||||
return new DataRace { name = "半兽人", Str = 3, Con = 2 };
|
||||
}
|
||||
/// <summary> 半身人(Halfling) 敏捷+2 魅力+2 体质+1 </summary>
|
||||
public static DataRace Halfling() {
|
||||
return new DataRace { name = "半身人", Dex = 2, Cha = 2, Con = 1 };
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9694db834fdbe8744882901e02003034
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c29e0b5bff9f654439aa3e867ac20484
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,42 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 装备 - 字典
|
||||
/// </summary>
|
||||
public static class ArmorDictionary {
|
||||
/// <summary> 护甲 </summary>
|
||||
public static DataArmor Armor(string name, ArmorType armorType) {
|
||||
DataArmor armor = new DataArmor();
|
||||
armor.name = name;
|
||||
armor.itemType = ItemType.装备;
|
||||
armor.wearType = WearType.护甲;
|
||||
armor.armorType = armorType;
|
||||
return armor;
|
||||
}
|
||||
/// <summary> 法师袍 ac10 </summary>
|
||||
public static DataArmor Armor101() {
|
||||
DataArmor armor = Armor("法师袍", ArmorType.布甲);
|
||||
armor.additions.Add(new DataAddition { armorClass = 10 });
|
||||
return armor;
|
||||
}
|
||||
/// <summary> 皮甲 ac11 </summary>
|
||||
public static DataArmor Armor201() {
|
||||
DataArmor armor = Armor("皮甲", ArmorType.轻甲);
|
||||
armor.additions.Add(new DataAddition { armorClass = 11 });
|
||||
return armor;
|
||||
}
|
||||
/// <summary> 链甲 ac15 </summary>
|
||||
public static DataArmor Armor301() {
|
||||
DataArmor armor = Armor("链甲", ArmorType.中甲);
|
||||
armor.additions.Add(new DataAddition { armorClass = 15 });
|
||||
return armor;
|
||||
}
|
||||
/// <summary> 板甲 ac18 </summary>
|
||||
public static DataArmor Armor401() {
|
||||
DataArmor armor = Armor("板甲", ArmorType.重甲);
|
||||
armor.additions.Add(new DataAddition { armorClass = 18 });
|
||||
return armor;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f13627182bd77434991f32751b8c15f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,105 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 装备栏 - 工具
|
||||
/// </summary>
|
||||
public static class EquipmentTool {
|
||||
|
||||
#region 附加
|
||||
/// <summary> 添加属性 </summary>
|
||||
public static void Add(this DataAddition a, DataAddition b) {
|
||||
a.armorClass += b.armorClass;
|
||||
}
|
||||
/// <summary> 合并属性 </summary>
|
||||
public static DataAddition Merge(List<DataAddition> additions) {
|
||||
DataAddition addition = new DataAddition();
|
||||
additions.ForEach(obj => addition.Add(obj));
|
||||
return addition;
|
||||
}
|
||||
/// <summary> 更新附加值 </summary>
|
||||
public static void UpdateAddition(this DataEquipment equipment) {
|
||||
DataAddition addition = new DataAddition();
|
||||
if (equipment.weapon1 != null) { addition.Add(equipment.weapon1.Addition); }
|
||||
if (equipment.weapon2 != null) { addition.Add(equipment.weapon2.Addition); }
|
||||
if (equipment.armor != null) { addition.Add(equipment.armor.Addition); }
|
||||
if (equipment.helmets != null) { addition.Add(equipment.helmets.Addition); }
|
||||
if (equipment.gloves != null) { addition.Add(equipment.gloves.Addition); }
|
||||
if (equipment.shoes != null) { addition.Add(equipment.shoes.Addition); }
|
||||
equipment.addition = addition;
|
||||
}
|
||||
/// <summary> 获取护甲等级 </summary>
|
||||
public static int ArmorClass(this DataEquipment equipment, int modifier) {
|
||||
int addValue = equipment.addition.armorClass;
|
||||
// 无甲 基础AC = 10 + 调整值 + 附加值
|
||||
if (equipment.armor == null) { return 10 + modifier + addValue; }
|
||||
// 布甲/轻甲 调整值全额生效
|
||||
if (equipment.armor.armorType == ArmorType.布甲) { }
|
||||
// 调整值全额生效
|
||||
if (equipment.armor.armorType == ArmorType.轻甲) { }
|
||||
// 中甲 调整值上限=2
|
||||
if (equipment.armor.armorType == ArmorType.中甲) { modifier = Mathf.Min(modifier, 2); }
|
||||
// 重甲 调整值无效
|
||||
if (equipment.armor.armorType == ArmorType.重甲) { modifier = 0; }
|
||||
// 调整值 + 附加值
|
||||
return modifier + addValue;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 穿戴
|
||||
/// <summary> 穿戴装备 </summary>
|
||||
public static bool Wear(this DataEquipment equipment, DataWear wear, out DataWear old) {
|
||||
old = wear; bool isWear = false;
|
||||
if (wear.wearType == WearType.武器) { isWear = WearWeapon(equipment, wear, out old); }
|
||||
if (wear.wearType == WearType.护甲) { isWear = WearArmor(equipment, wear, out old); }
|
||||
if (wear.wearType == WearType.头盔) { isWear = WearHelmets(equipment, wear, out old); }
|
||||
if (wear.wearType == WearType.手套) { isWear = WearGloves(equipment, wear, out old); }
|
||||
if (wear.wearType == WearType.鞋子) { isWear = WearShoes(equipment, wear, out old); }
|
||||
equipment.UpdateAddition();
|
||||
return isWear;
|
||||
}
|
||||
/// <summary> 穿戴武器 </summary>
|
||||
public static bool WearWeapon(this DataEquipment equipment, DataWear wear, out DataWear old) {
|
||||
old = null;
|
||||
// 校验是否为武器类型
|
||||
if (!(wear is DataWeapon newWeapon)) { return false; }
|
||||
// 情况1:主手为空,直接装备主手
|
||||
if (equipment.weapon1 == null) { equipment.weapon1 = newWeapon; return true; }
|
||||
// 情况2:副手为空,直接装备副手
|
||||
if (equipment.weapon2 == null) { equipment.weapon2 = newWeapon; return true; }
|
||||
// 情况3:主手副手都不为空,默认替换主手
|
||||
old = equipment.weapon1;
|
||||
equipment.weapon1 = newWeapon;
|
||||
equipment.UpdateAddition();
|
||||
return true;
|
||||
}
|
||||
/// <summary> 穿戴护甲 </summary>
|
||||
public static bool WearArmor(this DataEquipment equipment, DataWear wear, out DataWear old) {
|
||||
old = null;
|
||||
// 校验是否为护甲类型
|
||||
if (!(wear is DataArmor newArmor)) { return false; }
|
||||
old = equipment.armor;
|
||||
equipment.armor = newArmor;
|
||||
return true;
|
||||
}
|
||||
/// <summary> 穿戴头盔 </summary>
|
||||
public static bool WearHelmets(this DataEquipment equipment, DataWear wear, out DataWear old) {
|
||||
old = equipment.helmets;
|
||||
equipment.helmets = wear;
|
||||
return true;
|
||||
}
|
||||
/// <summary> 穿戴手套 </summary>
|
||||
public static bool WearGloves(this DataEquipment equipment, DataWear wear, out DataWear old) {
|
||||
old = equipment.gloves;
|
||||
equipment.gloves = wear;
|
||||
return true;
|
||||
}
|
||||
/// <summary> 穿戴鞋子 </summary>
|
||||
public static bool WearShoes(this DataEquipment equipment, DataWear wear, out DataWear old) {
|
||||
old = equipment.shoes;
|
||||
equipment.shoes = wear;
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1fd627b70f23dd44493bf8fb1e577370
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,71 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 武器 - 字典
|
||||
/// </summary>
|
||||
public static class WeaponDictionary {
|
||||
/// <summary> 武器 </summary>
|
||||
public static DataWeapon Weapon(string name, WeaponType weaponType) {
|
||||
DataWeapon weapon = new DataWeapon();
|
||||
weapon.name = name;
|
||||
weapon.itemType = ItemType.装备;
|
||||
weapon.wearType = WearType.武器;
|
||||
weapon.weaponType = weaponType;
|
||||
return weapon;
|
||||
}
|
||||
|
||||
/// <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.damageDice = new DataDamageDice(4, DamageType.穿刺);
|
||||
return weapon;
|
||||
}
|
||||
/// <summary> 短弓 1d6 </summary>
|
||||
public static DataWeapon Weapon102() {
|
||||
DataWeapon weapon = Weapon("短弓", WeaponType.轻型武器);
|
||||
weapon.damageDice = new DataDamageDice(6, DamageType.穿刺);
|
||||
return weapon;
|
||||
}
|
||||
|
||||
/// <summary> 木棒 1d6 </summary>
|
||||
public static DataWeapon Weapon201() {
|
||||
DataWeapon weapon = Weapon("木棒", WeaponType.中型武器);
|
||||
weapon.damageDice = new DataDamageDice(6, DamageType.钝击);
|
||||
return weapon;
|
||||
}
|
||||
|
||||
/// <summary> 巨棒 1d8 </summary>
|
||||
public static DataWeapon Weapon301() {
|
||||
DataWeapon weapon = Weapon("巨棒", WeaponType.重型武器);
|
||||
weapon.damageDice = new DataDamageDice(8, DamageType.钝击);
|
||||
return weapon;
|
||||
}
|
||||
/// <summary> 法杖 1d6 </summary>
|
||||
public static DataWeapon Weapon302() {
|
||||
DataWeapon weapon = Weapon("法杖", WeaponType.重型武器);
|
||||
weapon.damageDice = new DataDamageDice(6, DamageType.钝击);
|
||||
return weapon;
|
||||
}
|
||||
|
||||
/// <summary> 木盾 ac1 </summary>
|
||||
public static DataWeapon Weapon401() {
|
||||
DataWeapon weapon = Weapon("木盾", WeaponType.盾牌);
|
||||
weapon.additions.Add(new DataAddition { armorClass = 1 });
|
||||
return weapon;
|
||||
}
|
||||
/// <summary> 箭袋 +20 </summary>
|
||||
public static DataWeapon Weapon402() {
|
||||
DataWeapon weapon = Weapon("箭袋", WeaponType.盾牌);
|
||||
weapon.additions.Add(new DataAddition { armorClass = 1 });
|
||||
return weapon;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32522aef438403f4d9ed01fe6650243b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,43 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MuHua;
|
||||
|
||||
/// <summary>
|
||||
/// 请求 - 管理器
|
||||
/// </summary>
|
||||
public class ManagerRequest : ModuleSingle<ManagerRequest> {
|
||||
|
||||
/// <summary> 域名 </summary>
|
||||
public static string Address => "http://localhost:5086";
|
||||
|
||||
protected override void Awake() => NoReplace(false);
|
||||
|
||||
#region 用户
|
||||
/// <summary> 登录 </summary>
|
||||
public void Login(string username, string password, Action<string> callback) {
|
||||
string url = Address + "/api/user/login";
|
||||
DataLoginRequest login = new DataLoginRequest { username = username, password = password };
|
||||
PostForm(url, login, callback);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 请求类型
|
||||
public void PostForm<T>(string url, T data, Action<string> callback) {
|
||||
string json = JsonTool.ToJson(data);
|
||||
Debug.Log(json);
|
||||
DataRequestPost request = new DataRequestPost(url, json);
|
||||
request.OnError = (json) => { ErrorHandle(url, json); };
|
||||
request.OnCallback = callback;
|
||||
NetworkRequestAsync.Execute(request);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 结果处理
|
||||
/// <summary> 错误处理 </summary>
|
||||
private void ErrorHandle(string url, string json) {
|
||||
Debug.LogError($"{url} \n {json}");
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b4112fa4a2bfe84984b0472be3af46c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,34 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MuHua;
|
||||
|
||||
/// <summary>
|
||||
/// 模拟器 - 管理
|
||||
/// </summary>
|
||||
public class ManagerSimulator : ModuleSingle<ManagerSimulator> {
|
||||
|
||||
/// <summary> 队伍1 </summary>
|
||||
public BattleTeam team1;
|
||||
/// <summary> 队伍2 </summary>
|
||||
public BattleTeam team2;
|
||||
|
||||
public BattleSimulator battleSimulator;
|
||||
|
||||
protected override void Awake() => NoReplace(false);
|
||||
|
||||
private void Start() {
|
||||
team1 = new BattleTeam();
|
||||
team1.Add(CharacterDictionary.Character001());
|
||||
team1.Add(CharacterDictionary.Character002());
|
||||
team1.Add(CharacterDictionary.Character003());
|
||||
|
||||
team2 = new BattleTeam();
|
||||
team2.Add(MonsterDictionary.Monster001());
|
||||
team2.Add(MonsterDictionary.Monster002());
|
||||
team2.Add(MonsterDictionary.Monster002());
|
||||
|
||||
battleSimulator = new BattleSimulator(team1, team2);
|
||||
battleSimulator.Transition(PhaseType.先攻阶段);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ce4cafcd40fff3428928289fa060de4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,13 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MuHua;
|
||||
|
||||
/// <summary>
|
||||
/// 测试管理器
|
||||
/// </summary>
|
||||
public class TestManager : ModuleSingle<TestManager> {
|
||||
|
||||
protected override void Awake() => NoReplace();
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48413b9054701704499e7cb2c698ac97
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,96 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using MuHua;
|
||||
|
||||
/// <summary>
|
||||
/// 登录页面
|
||||
/// </summary>
|
||||
public class UILoginPage : ModuleUIPage {
|
||||
|
||||
private UILoginPanel loginPanel;
|
||||
private UIRegisterPanel registerPanel;
|
||||
|
||||
public override VisualElement Element => root.Q<VisualElement>("LoginPage");
|
||||
|
||||
public VisualElement LoginPanel => Q<VisualElement>("LoginPanel");
|
||||
public VisualElement RegisterPanel => Q<VisualElement>("RegisterPanel");
|
||||
|
||||
private void Awake() {
|
||||
loginPanel = new UILoginPanel(LoginPanel, this);
|
||||
registerPanel = new UIRegisterPanel(RegisterPanel, this);
|
||||
|
||||
ModuleUI.OnJumpPage += ModuleUI_OnJumpPage;
|
||||
}
|
||||
|
||||
private void ModuleUI_OnJumpPage(Page page) {
|
||||
Element.EnableInClassList("document-page-hide", page != Page.Login);
|
||||
if (page != Page.Login) { return; }
|
||||
OpenLoginPanel();
|
||||
}
|
||||
public void OpenLoginPanel() {
|
||||
loginPanel.Resetting(false);
|
||||
registerPanel.Resetting(true);
|
||||
}
|
||||
public void OpenRegisterPanel() {
|
||||
loginPanel.Resetting(true);
|
||||
registerPanel.Resetting(false);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 登录面板
|
||||
/// </summary>
|
||||
public class UILoginPanel : ModuleUIPanel {
|
||||
|
||||
private string username;
|
||||
private string password;
|
||||
|
||||
public Label Title => Q<Label>("Title");
|
||||
public UITextField InputField1 => Q<UITextField>("InputField1");
|
||||
public UITextField InputField2 => Q<UITextField>("InputField2");
|
||||
public Button Button1 => Q<Button>("Button1");
|
||||
public Button Button2 => Q<Button>("Button2");
|
||||
|
||||
public UILoginPanel(VisualElement element, UILoginPage parent) : base(element) {
|
||||
InputField1.RegisterCallback<ChangeEvent<string>>(evt => { username = evt.newValue; });
|
||||
InputField2.RegisterCallback<ChangeEvent<string>>(evt => { password = evt.newValue; });
|
||||
Button1.clicked += () => parent.OpenRegisterPanel();
|
||||
Button2.clicked += () => ManagerRequest.I.Login(username, password, (s) => {
|
||||
ModuleUI.Settings(Page.None);
|
||||
Debug.Log(s);
|
||||
});
|
||||
}
|
||||
public void Resetting(bool isHide) {
|
||||
InputField1.value = username = "";
|
||||
InputField2.value = password = "";
|
||||
element.EnableInClassList("login-hide", isHide);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 注册面板
|
||||
/// </summary>
|
||||
public class UIRegisterPanel : ModuleUIPanel {
|
||||
|
||||
private string username;
|
||||
private string password;
|
||||
|
||||
public Label Title => Q<Label>("Title");
|
||||
public UITextField InputField1 => Q<UITextField>("InputField1");
|
||||
public UITextField InputField2 => Q<UITextField>("InputField2");
|
||||
public Button Button1 => Q<Button>("Button1");
|
||||
public Button Button2 => Q<Button>("Button2");
|
||||
|
||||
public UIRegisterPanel(VisualElement element, UILoginPage parent) : base(element) {
|
||||
InputField1.RegisterCallback<ChangeEvent<string>>(evt => { username = evt.newValue; });
|
||||
InputField2.RegisterCallback<ChangeEvent<string>>(evt => { password = evt.newValue; });
|
||||
Button1.clicked += () => parent.OpenLoginPanel();
|
||||
Button2.clicked += () => { };
|
||||
}
|
||||
public void Resetting(bool isHide) {
|
||||
InputField1.value = "";
|
||||
InputField2.value = "";
|
||||
element.EnableInClassList("login-hide", isHide);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71f4d873d8595a04b9f0e23ece70c12f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,56 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using MuHua;
|
||||
|
||||
/// <summary>
|
||||
/// 测试页面
|
||||
/// </summary>
|
||||
public class UITestPage : ModuleUIPage {
|
||||
|
||||
public VisualTreeAsset SlideButtonTemplate;
|
||||
|
||||
public UISlideButton<UIOption, Option> slideButton;
|
||||
|
||||
public override VisualElement Element => root;
|
||||
public VisualElement SlideButton => Q<VisualElement>("SlideButton");
|
||||
|
||||
public void Awake() {
|
||||
slideButton = new UISlideButton<UIOption, Option>(SlideButton, root, SlideButtonTemplate, (data, element) => new UIOption(data, element));
|
||||
|
||||
List<Option> options = new List<Option>();
|
||||
options.Add(new Option());
|
||||
options.Add(new Option());
|
||||
options.Add(new Option());
|
||||
options.Add(new Option());
|
||||
slideButton.Create(options);
|
||||
|
||||
slideButton.Items[1].Select();
|
||||
}
|
||||
public void Update() {
|
||||
slideButton.Update();
|
||||
}
|
||||
|
||||
public class Option : DataSlideButton {
|
||||
|
||||
}
|
||||
|
||||
public class UIOption : ModuleUIItem<Option> {
|
||||
|
||||
public Button Button => Q<Button>("Button");
|
||||
|
||||
public UIOption(Option value, VisualElement element) : base(value, element) {
|
||||
value.element = element;
|
||||
Button.clicked += Select;
|
||||
}
|
||||
public override void SelectState() {
|
||||
Button.EnableInClassList("slidebutton-button-s", true);
|
||||
}
|
||||
public override void DefaultState() {
|
||||
Button.EnableInClassList("slidebutton-button-s", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be9d3ba84a127e14abd0d56796e7d7e0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,36 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using MuHua;
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
public class Test : ModuleUIPage {
|
||||
|
||||
private string skill;
|
||||
|
||||
public override VisualElement Element => root;
|
||||
public Label label => Q<Label>();
|
||||
|
||||
private void Awake() {
|
||||
string goblin = Settings("哥布林射手", Color.red);
|
||||
string skill = Settings("短弓射击(23)", Color.yellow);
|
||||
string elvira = Settings("艾薇拉(12)", Color.green);
|
||||
string damage = Settings("5穿刺伤害", Color.red);
|
||||
label.text = $"{goblin}使用{skill}对{elvira}造成了{damage}";
|
||||
label.RegisterCallback<MouseMoveEvent>(OnMouseMove);
|
||||
|
||||
this.skill = Regex.Replace(goblin, "<.*?>", "");
|
||||
}
|
||||
|
||||
private void OnMouseMove(MouseMoveEvent evt) {
|
||||
Vector2 localPosition = evt.localMousePosition;
|
||||
if (label.EnterString(skill, localPosition)) { Debug.Log($"鼠标位 {skill} 上"); }
|
||||
}
|
||||
|
||||
private string Settings(string value, Color color) {
|
||||
value = UITool.RichTextUnderline(value);
|
||||
return UITool.RichTextColor(value, color);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13b55fb0978ba0740b207fa9fc1c91bf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user