idle-survivors/Assets/Scripts/Attribute.cs
zephyr 51fabc12b6
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
feature-attributes (#7)
Updates #2.

Co-authored-by: Branden J Brown <zephyrtronium@gmail.com>
Reviewed-on: #7
2023-07-30 10:58:19 -05:00

29 lines
709 B
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[Serializable]
public struct Attribute
{
public long Base;
public Attribute(long stat) { Base = stat; }
/// <summary>
/// Calculates the stat value with accumulated buff and debuff modifiers.
/// </summary>
/// <returns>(base + baseBonus) * (100% + permyriadBonus) + flatBonus, bounded below by 0.</returns>
public long Calc(EffectSO effect)
{
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;
}
return r;
}
}