using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 属性 - 工具 /// public static class AttributeTool { #region 创建 /// 随机初始属性 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); } /// 添加属性 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; } /// 减少属性 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; } /// 覆盖属性 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 }