Files
Continentis/Assets/Scripts/MainGame/Base/AttributeGroup.cs
2025-11-01 06:13:58 -04:00

119 lines
3.8 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 NaughtyAttributes;
using SLSFramework.General;
using Unity.VisualScripting;
using UnityEngine;
namespace Continentis.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;
}
}
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;
}
}
}
}