1
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f6a814b3a3b754241ae35753e6d7c7f8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,81 @@
|
||||
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})");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a6bdd4c70e0068d4dbe460c7a6961901
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,75 @@
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd48318dcbe216449a81d70622f8ba35
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9694db834fdbe8744882901e02003034
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user