1
This commit is contained in:
@@ -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<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})");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d99eda4d1308724c8374c9e305743bc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,38 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 角色 - 数据
|
||||
/// </summary>
|
||||
public class DataCharacter {
|
||||
/// <summary> 角色名字 </summary>
|
||||
public string name;
|
||||
/// <summary> 基础属性 </summary>
|
||||
public DataAttribute basic;
|
||||
/// <summary> 角色职业 </summary>
|
||||
public DataProfession profession;
|
||||
}
|
||||
/// <summary>
|
||||
/// 属性 - 数据
|
||||
/// </summary>
|
||||
public class DataAttribute {
|
||||
/// <summary> 力量(strength) </summary>
|
||||
public int Str;
|
||||
/// <summary> 敏捷(dexterity) </summary>
|
||||
public int Dex;
|
||||
/// <summary> 体质(constitution) </summary>
|
||||
public int Con;
|
||||
/// <summary> 智力(intelligence) </summary>
|
||||
public int Int;
|
||||
/// <summary> 感知(wisdom) </summary>
|
||||
public int Wis;
|
||||
/// <summary> 魅力(charisma) </summary>
|
||||
public int Cha;
|
||||
}
|
||||
/// <summary>
|
||||
/// 职业 - 数据
|
||||
/// </summary>
|
||||
public class DataProfession : DataAttribute {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ae234ab6cd19bf46983ee5f38afd957
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4885347d6f83a5543953f76064ca0fa4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
/// <summary>
|
||||
/// 骰子
|
||||
/// </summary>
|
||||
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]; // 弃最低值
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41f6344596d5e944fb15a16127158213
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user