[#14] rozbudowa stats + dodanie modyfikatorów

This commit is contained in:
2026-06-30 20:28:51 +02:00
parent 86b4a8a93f
commit 8326c4b279
33 changed files with 444 additions and 129 deletions
@@ -0,0 +1,64 @@
using RPGCore.Stats.ObjectModules.StatsObjectModule.Events;
using UnityEngine;
namespace RPGCore.Stats.ObjectModules.StatsObjectModule
{
/// <summary>
/// <b>You should never instantiate this by yourself!</b>
/// Instantiated automatically by <see cref="StatsModule"/> for every available <see cref="StatResourceDefinitionSO"/>.
/// </summary>
public sealed class StatResource
{
public StatResourceDefinitionSO definition { get; internal set; }
public StatValue statValue { get; internal set; }
/// <summary>
/// This value represent current resource of this stat. Always between <see cref="StatValue.baseValue"/> and <see cref="StatValue.value"/>
/// </summary>
public int resource { get; private set; }
internal StatResource(StatResourceDefinitionSO definition, int defaultValue, StatValue statValue)
{
this.definition = definition;
resource = defaultValue;
this.statValue = statValue;
}
/// <summary>
/// Changes (or simpler - uses) <see cref="resource"/> of this stat value by given amount.
/// It just calls <see cref="SetResource(int)"/> with: <see cref="resource"/> + <see cref="amount"/>
/// </summary>
/// <param name="amount">Amount that will be added or subtracted from <see cref="resource"/></param>
public void ChangeResource(int amount)
{
SetResource(resource + amount);
}
/// <summary>
/// Sets <see cref="resource"/> to given amount. Amount will be clamped between ZERO and <see cref="StatValue.value"/>.
/// </summary>
/// <param name="amount">New amount</param>
public void SetResource(int amount)
{
var old = resource;
resource = Mathf.Clamp(amount, 0, statValue.value);
statValue.obj.events.Invoke(new StatResourceChangeEvent
{
delta = resource - old,
after = resource,
before = old,
resourceDefinition = definition,
target = statValue.obj
});
}
/// <summary>
/// Sets <see cref="resource"/> to given percentage. Percentage will be clamped between ZERO and ONE.
/// </summary>
/// <param name="percentage">New percentage</param>
public void SetResource(float percentage)
{
SetResource(Mathf.CeilToInt(Mathf.Clamp01(percentage) * statValue.value));
}
}
}