using Cal; using System; using System.Collections.Generic; namespace ET { public class CharacterAwakeSystem : AwakeSystem { public override void Awake(Character self) { self.getAttributeFunc = self.GetAttribute; } } public class CharacterLoadSystem : LoadSystem { public override void Load(Character self) { self.getAttributeFunc = self.GetAttribute; } } public class CharacterDeserializeSystem : DeserializeSystem { public override void Deserialize(Character self) { self.getAttributeFunc = self.GetAttribute; } } public class CharacterDestroySystem : DestroySystem { public override void Destroy(Character self) { self.attribute.Clear(); self.pointRecord.Clear(); self.getAttributeFunc = null; } } public static class CharacterSystem { public static float GetAttribute(this Character self, AttributeType type) { self.attribute.TryGetValue((int)type, out float value); return value; } public static void Set(this Character self, AttributeType type, float value) { self.attribute[(int)type] = value; } public static void SetAdd(this Character self, AttributeType type, float value) { int intKey = (int)type; if (!self.attribute.ContainsKey(intKey)) self.attribute[intKey] = 0; self.attribute[intKey] += value; } public static void AddAllPoint(this Character self, int value) { self.SetAdd(AttributeType.力量, value); self.SetAdd(AttributeType.敏捷, value); self.SetAdd(AttributeType.精神, value); self.SetAdd(AttributeType.智慧, value); self.SetAdd(AttributeType.体质, value); self.SetAdd(AttributeType.耐力, value); } public static void AddPoint(this Character self, AttributeType type, int value) { int intType = (int)type; if (!self.pointRecord.TryGetValue(intType, out int oldValue)) { self.pointRecord[intType] = value; } self.pointRecord[intType] = oldValue + value; SetAdd(self, type, value); } public static int RemovePoint(this Character self) { int record = 0; foreach (KeyValuePair kv in self.pointRecord) { SetAdd(self, (AttributeType)kv.Key, -kv.Value); record += kv.Value; } self.pointRecord.Clear(); return record; } public static void ReSet(this Character self) { self.attribute.Clear(); self.pointRecord.Clear(); } } }