46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
|
using UnityEngine;
|
||
|
|
||
|
[CreateAssetMenu(fileName = "StatEffect", menuName = "Stat Effect")]
|
||
|
public class EffectSO : ScriptableObject
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// Additive change applied before multiplicative scaling.
|
||
|
/// </summary>
|
||
|
public long Base { get; private set; }
|
||
|
/// <summary>
|
||
|
/// Multiplicative scaling in units of hundredth of a percent.
|
||
|
/// E.g., 625 permyriad is 6.25%.
|
||
|
/// </summary>
|
||
|
public long Permyriad { get; private set; }
|
||
|
/// <summary>
|
||
|
/// Additive change applied after multiplicative scaling.
|
||
|
/// </summary>
|
||
|
public long Flat { get; private set; }
|
||
|
|
||
|
/// <summary>
|
||
|
/// Create a new attribute effect instance.
|
||
|
/// </summary>
|
||
|
/// <param name="baseBonus"></param>
|
||
|
/// <param name="permyriad"></param>
|
||
|
/// <param name="flat"></param>
|
||
|
/// <returns></returns>
|
||
|
public static EffectSO New(long baseBonus = 0, long permyriad = 0, long flat = 0)
|
||
|
{
|
||
|
var effect = ScriptableObject.CreateInstance<EffectSO>();
|
||
|
effect.Base = baseBonus;
|
||
|
effect.Permyriad = permyriad;
|
||
|
effect.Flat = flat;
|
||
|
return effect;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Create a new EffectSO from a percentage.
|
||
|
/// </summary>
|
||
|
/// <param name="p">Percentage. E.g., 6.25f results in a Permyriad of 625.</param>
|
||
|
/// <returns>Effect with the given percentage.</returns>
|
||
|
public static EffectSO FromPercent(float p)
|
||
|
{
|
||
|
return New(permyriad: (long)(p * 100));
|
||
|
}
|
||
|
}
|