71 lines
4.0 KiB
C#
71 lines
4.0 KiB
C#
namespace Harmony.StatRebirth
|
|
{
|
|
public class StatPatches
|
|
{
|
|
|
|
[HarmonyPatch(typeof(Stat))]
|
|
[HarmonyPatch("Tick")]
|
|
public class Tick
|
|
{
|
|
public static MethodInfo SetChangedFlag = AccessTools.Method(typeof(Stat), "SetChangedFlag", new Type[] { typeof(float), typeof(float) });
|
|
|
|
private static bool Prefix(Stat __instance, float dt, ulong worldTime, bool godMode,
|
|
ref float ___m_originalBaseMax,
|
|
ref float ___m_lastValue,
|
|
ref float ___m_value,
|
|
ref bool ___m_isEntityAlive,
|
|
ref bool ___m_isEntityPlayer,
|
|
ref float ___m_baseMax,
|
|
ref bool ___m_changed
|
|
)
|
|
{
|
|
if (__instance.Entity is EntitySupplyCrate)
|
|
{
|
|
float healthMax = __instance.Entity.Buffs.GetCustomVar("$healthMax");
|
|
|
|
if (healthMax > 0)
|
|
{
|
|
__instance.Entity.Stats.Health.BaseMax = healthMax;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (__instance.MaxPassive != PassiveEffects.None)
|
|
{
|
|
__instance.BaseMax = EffectManager.GetValue(__instance.MaxPassive, null, ___m_originalBaseMax, __instance.Entity, null, new FastTags<TagGroup.Global>(), true, true, true, true, true, 1);
|
|
}
|
|
___m_isEntityAlive = (__instance.Entity != null);
|
|
___m_isEntityPlayer = (__instance.Entity as global::EntityPlayer != null);
|
|
if ((__instance.StatType == Stat.StatTypes.Stamina || __instance.StatType == Stat.StatTypes.Health) && Mathf.Abs(___m_lastValue - ___m_value) >= 1f)
|
|
{
|
|
if (___m_value > ___m_lastValue && __instance.GainPassive != PassiveEffects.None)
|
|
{
|
|
___m_value = Mathf.Clamp(___m_lastValue + EffectManager.GetValue(__instance.GainPassive, null, ___m_value - ___m_lastValue, __instance.Entity, null, new FastTags<TagGroup.Global>(), true, true, true, true, true, 1), 0f, ___m_baseMax);
|
|
}
|
|
else if (___m_value < ___m_lastValue && __instance.LossPassive != PassiveEffects.None)
|
|
{
|
|
___m_value = Mathf.Clamp(___m_lastValue - EffectManager.GetValue(__instance.LossPassive, null, ___m_lastValue - ___m_value, __instance.Entity, null, new FastTags<TagGroup.Global>(), true, true, true, true, true, 1), 0f, ___m_baseMax);
|
|
}
|
|
}
|
|
if (___m_value + __instance.RegenerationAmount > __instance.ModifiedMax)
|
|
{
|
|
__instance.RegenerationAmount = __instance.ModifiedMax - ___m_value;
|
|
}
|
|
___m_value += __instance.RegenerationAmount;
|
|
if (__instance.RegenerationAmount > 0f)
|
|
{
|
|
if (__instance.StatType == Stat.StatTypes.Stamina)
|
|
{
|
|
__instance.Entity.Stats.Water.RegenerationAmount -= __instance.RegenerationAmount * EffectManager.GetValue(PassiveEffects.WaterLossPerStaminaPointGained, null, 1f, __instance.Entity, null, new FastTags<TagGroup.Global>(), true, true, true, true, true, 1);
|
|
__instance.Entity.Stats.Food.RegenerationAmount -= __instance.RegenerationAmount * EffectManager.GetValue(PassiveEffects.FoodLossPerStaminaPointGained, null, 1f, __instance.Entity, null, new FastTags<TagGroup.Global>(), true, true, true, true, true, 1);
|
|
}
|
|
}
|
|
__instance.RegenerationAmount = ___m_value - ___m_lastValue;
|
|
SetChangedFlag.Invoke(__instance, new object[] { ___m_value, ___m_lastValue });
|
|
___m_lastValue = ___m_value;
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
} |