using System.Collections.Generic; using NaughtyAttributes; using SLSFramework.General; using Unity.VisualScripting; using UnityEngine; namespace Continentis.MainGame { public partial class AttributeGroup { /// /// 基础属性,不会改变,通常情况下不会直接使用 /// public Dictionary original; /// /// 当前属性,会受到buff和其他效果的影响 /// public Dictionary current; public AttributeGroup(Dictionary original) { this.original = new Dictionary(); this.current = new Dictionary(); this.original.AddRange(original); this.current.AddRange(original); } public AttributeGroup(Dictionary original, Dictionary endowing) { this.original = new Dictionary(); this.current = new Dictionary(); this.original.AddRange(original); this.current.AddRange(original); SetUpEndowments(endowing); } public void SetUpEndowments(Dictionary endowing) { if (endowing == null || endowing.Count == 0) { return; } foreach (KeyValuePair endowment in endowing) { if (string.IsNullOrEmpty(endowment.Value)) { current.Add(endowment.Key, 0); } else if (float.TryParse(endowment.Value, out float value)) { current.Add(endowment.Key, value); } else { current[endowment.Key] = original.GetValueOrDefault(endowment.Value, 0); } } } } public partial class AttributeGroup { public void ResetAttribute(string attributeName) { if (original.TryGetValue(attributeName, out float originalAttribute)) { current[attributeName] = originalAttribute; } } public void SetAttribute(string attributeName, float value) { if (!current.ContainsKey(attributeName)) { Debug.Log($"{attributeName} is not found in current attributes, use default value"); } current[attributeName] = value; } public void ModifyAttribute(string attributeName, float numericChange, float percentageChangeOfAccumulation, float percentChangeOfMultiplication) { if (!current.ContainsKey(attributeName)) { Debug.Log($"{attributeName} is not found in current attributes, use default value"); if (attributeName.Contains("Multiplier")) { current[attributeName] = 1f; } else { current[attributeName] = 0f; } } current[attributeName] += numericChange; current[attributeName] = (1 + percentageChangeOfAccumulation) * current[attributeName]; current[attributeName] = percentChangeOfMultiplication * current[attributeName]; } } public partial class AttributeGroup { public void ApplyAllAttributes() { foreach (KeyValuePair attribute in original) { current[attribute.Key] = attribute.Value; } } } }