diff --git a/Assets/ModuleCore/DNDWarrior.cs b/Assets/ModuleCore/DNDWarrior.cs new file mode 100644 index 0000000..8425839 --- /dev/null +++ b/Assets/ModuleCore/DNDWarrior.cs @@ -0,0 +1,108 @@ +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 rolls = new List(); + 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})"); + } +} + + diff --git a/Assets/ModuleCore/DNDWarrior.cs.meta b/Assets/ModuleCore/DNDWarrior.cs.meta new file mode 100644 index 0000000..d839da8 --- /dev/null +++ b/Assets/ModuleCore/DNDWarrior.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3d99eda4d1308724c8374c9e305743bc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ModuleCore/Module/DataCharacter.cs b/Assets/ModuleCore/Module/DataCharacter.cs new file mode 100644 index 0000000..6afcde5 --- /dev/null +++ b/Assets/ModuleCore/Module/DataCharacter.cs @@ -0,0 +1,38 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +/// +/// 角色 - 数据 +/// +public class DataCharacter { + /// 角色名字 + public string name; + /// 基础属性 + public DataAttribute basic; + /// 角色职业 + public DataProfession profession; +} +/// +/// 属性 - 数据 +/// +public class DataAttribute { + /// 力量(strength) + public int Str; + /// 敏捷(dexterity) + public int Dex; + /// 体质(constitution) + public int Con; + /// 智力(intelligence) + public int Int; + /// 感知(wisdom) + public int Wis; + /// 魅力(charisma) + public int Cha; +} +/// +/// 职业 - 数据 +/// +public class DataProfession : DataAttribute { + +} \ No newline at end of file diff --git a/Assets/ModuleCore/Module/DataCharacter.cs.meta b/Assets/ModuleCore/Module/DataCharacter.cs.meta new file mode 100644 index 0000000..84317de --- /dev/null +++ b/Assets/ModuleCore/Module/DataCharacter.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3ae234ab6cd19bf46983ee5f38afd957 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ModuleCore/ModuleTools.meta b/Assets/ModuleCore/ModuleTools.meta new file mode 100644 index 0000000..3f0182c --- /dev/null +++ b/Assets/ModuleCore/ModuleTools.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4885347d6f83a5543953f76064ca0fa4 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/ModuleCore/ModuleTools/Dice.cs b/Assets/ModuleCore/ModuleTools/Dice.cs new file mode 100644 index 0000000..b427900 --- /dev/null +++ b/Assets/ModuleCore/ModuleTools/Dice.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using Random = UnityEngine.Random; + +/// +/// 骰子 +/// +public static class Dice { + // 生成4d6弃最低的随机属性值 + public static int RollAttribute() { + int[] rolls = { Random.Range(1, 7), Random.Range(1, 7), Random.Range(1, 7), Random.Range(1, 7) }; + Array.Sort(rolls); + return rolls[1] + rolls[2] + rolls[3]; // 弃最低值 + } +} diff --git a/Assets/ModuleCore/ModuleTools/Dice.cs.meta b/Assets/ModuleCore/ModuleTools/Dice.cs.meta new file mode 100644 index 0000000..987a635 --- /dev/null +++ b/Assets/ModuleCore/ModuleTools/Dice.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 41f6344596d5e944fb15a16127158213 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SceneManager/SampleScene/SampleScene.unity b/Assets/SceneManager/SampleScene/SampleScene.unity index a5506d0..f3fd290 100644 --- a/Assets/SceneManager/SampleScene/SampleScene.unity +++ b/Assets/SceneManager/SampleScene/SampleScene.unity @@ -133,6 +133,7 @@ GameObject: - component: {fileID: 670296964} - component: {fileID: 670296963} - component: {fileID: 670296965} + - component: {fileID: 670296966} m_Layer: 5 m_Name: "----\u754C\u9762\u6587\u6863----" m_TagString: Untagged @@ -185,6 +186,18 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: document: {fileID: 670296963} +--- !u!114 &670296966 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 670296962} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3d99eda4d1308724c8374c9e305743bc, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &705507993 GameObject: m_ObjectHideFlags: 0 @@ -502,7 +515,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!4 &1621578791 Transform: m_ObjectHideFlags: 0