add stat effects, and rework attributes again
This commit is contained in:
parent
2bffefc0cb
commit
8170727c59
@ -5,25 +5,16 @@
|
||||
public class Attribute : ScriptableObject
|
||||
{
|
||||
public long Base { get; set; }
|
||||
public long BaseBonus { get; set; }
|
||||
public long PermyriadBonus { get; set; }
|
||||
public long FlatBonus { get; set; }
|
||||
|
||||
public long Value => Calc(Base, BaseBonus, PermyriadBonus, FlatBonus);
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the stat value with accumulated buff and debuff modifiers.
|
||||
/// </summary>
|
||||
/// <param name="baseValue">Base value.</param>
|
||||
/// <param name="baseBonus">Additive bonus applied before multiplicative scaling.</param>
|
||||
/// <param name="permyriadBonus">Multiplicative scaling in hundredths of a percent. E.g., 625 permyriad corresponds to 6.25%.</param>
|
||||
/// <param name="flatBonus">Additive bonus applied after multiplicative scaling.</param>
|
||||
/// <returns>(base + baseBonus) * (100% + permyriadBonus) + flatBonus, bounded below by 0.</returns>
|
||||
public static long Calc(long baseValue, long baseBonus, long permyriadBonus, long flatBonus)
|
||||
public long Calc(EffectSO effect)
|
||||
{
|
||||
var r = baseValue + baseBonus;
|
||||
var m = permyriadBonus + 10000;
|
||||
r = r * (m / 10000) + (r / 10000) * (m % 10000) + flatBonus;
|
||||
var r = Base + effect.Base;
|
||||
var m = effect.Permyriad + 10000;
|
||||
r = r * (m / 10000) + (r / 10000) * (m % 10000) + effect.Flat;
|
||||
if (r <= 0)
|
||||
{
|
||||
return 0;
|
||||
|
45
Assets/Scripts/EffectSO.cs
Normal file
45
Assets/Scripts/EffectSO.cs
Normal file
@ -0,0 +1,45 @@
|
||||
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));
|
||||
}
|
||||
}
|
11
Assets/Scripts/EffectSO.cs.meta
generated
Normal file
11
Assets/Scripts/EffectSO.cs.meta
generated
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 494a21c06960ec442a7a6806f8aefedb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -19,9 +19,7 @@ public long Value(long startStat, long baseBonus, long permyriadBonus, long flat
|
||||
{
|
||||
var attr = ScriptableObject.CreateInstance<Attribute>();
|
||||
attr.Base = startStat;
|
||||
attr.BaseBonus = baseBonus;
|
||||
attr.PermyriadBonus = permyriadBonus;
|
||||
attr.FlatBonus = flatBonus;
|
||||
return attr.Value;
|
||||
var effect = EffectSO.New(baseBonus, permyriadBonus, flatBonus);
|
||||
return attr.Calc(effect);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user