Files
Cielonos/Assets/Scripts/MainGame/Base/Attribute/AttributeGroup.cs
SoulliesOfficial 9a9e48f8a5
2026-06-27 12:52:03 -04:00

123 lines
4.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
namespace Cielonos.MainGame
{
public partial class AttributeGroup
{
/// <summary>
/// 基础属性,不会改变,通常情况下不会直接使用
/// </summary>
public Dictionary<string, float> original;
/// <summary>
/// 当前属性会受到buff和其他效果的影响
/// </summary>
public Dictionary<string, float> current;
public AttributeGroup(Dictionary<string, float> original)
{
this.original = new Dictionary<string, float>();
this.current = new Dictionary<string, float>();
this.original.AddRange(original);
this.current.AddRange(original);
}
public AttributeGroup(Dictionary<string, float> original, Dictionary<string, string> endowing)
{
this.original = new Dictionary<string, float>();
this.current = new Dictionary<string, float>();
this.original.AddRange(original);
this.current.AddRange(original);
SetUpEndowments(endowing);
}
public void SetUpEndowments(Dictionary<string, string> endowing)
{
if (endowing == null || endowing.Count == 0)
{
return;
}
foreach (KeyValuePair<string, string> 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.Add(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;
}
else if (current.ContainsKey(attributeName))
{
// 动态属性(由装备等外部来源添加、不存在于 original 中的属性)
// 需要重置到逻辑默认值,否则每次 Refresh 都会在旧值上叠加。
current[attributeName] = attributeName.Contains("Multiplier") ? 1f : 0f;
}
}
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<string, float> attribute in original)
{
current[attribute.Key] = attribute.Value;
}
}
}
}