fix: Renames WeightOverloading to StaminaSystem (#1495)

This commit is contained in:
Kamron Batman 2023-09-06 18:58:45 -07:00 committed by GitHub
parent 6820efe0ca
commit 319d82fec9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 143 additions and 144 deletions

View file

@ -247,7 +247,7 @@ public partial class BraceletOfBinding : BaseBracelet, TranslocationItem
return false;
}
if (WeightOverloading.IsOverloaded(from))
if (StaminaSystem.IsOverloaded(from))
{
from.SendLocalizedMessage(502359, "", 0x22); // Thou art too encumbered to move.
return false;

View file

@ -0,0 +1,125 @@
using System;
using Server.Mobiles;
using Server.Spells.Ninjitsu;
namespace Server.Misc;
public enum DFAlgorithm
{
Standard,
PainSpike
}
public static class StaminaSystem
{
public const int OverloadAllowance = 4; // We can be four stones overweight without getting fatigued
public static DFAlgorithm DFA { get; set; }
public static void Initialize()
{
EventSink.Movement += EventSink_Movement;
}
public static void FatigueOnDamage(Mobile m, int damage)
{
var fatigue = DFA switch
{
DFAlgorithm.Standard => damage * (100.0 / m.Hits) * ((double)m.Stam / 100) - 5.0,
DFAlgorithm.PainSpike => damage * (100.0 / m.Hits + (50.0 + m.Stam) / 100 - 1.0) - 5.0,
_ => 0.0
};
if (fatigue > 0)
{
m.Stam -= (int)fatigue;
}
}
public static int GetMaxWeight(Mobile m) => m.MaxWeight;
public static void EventSink_Movement(MovementEventArgs e)
{
var from = e.Mobile;
if (!from.Alive || from.AccessLevel > AccessLevel.Player)
{
return;
}
if (!from.Player)
{
// Else it won't work on monsters.
DeathStrike.AddStep(from);
return;
}
var maxWeight = GetMaxWeight(from) + OverloadAllowance;
var overWeight = Mobile.BodyWeight + from.TotalWeight - maxWeight;
if (overWeight > 0)
{
from.Stam -= GetStamLoss(from, overWeight, (e.Direction & Direction.Running) != 0);
if (from.Stam == 0)
{
from.SendLocalizedMessage(
500109
); // You are too fatigued to move, because you are carrying too much weight!
e.Blocked = true;
return;
}
}
if (from.Stam * 100 / Math.Max(from.StamMax, 1) < 10)
{
--from.Stam;
}
if (!Core.AOS && from.Stam == 0)
{
from.SendLocalizedMessage(500110); // You are too fatigued to move.
e.Blocked = true;
return;
}
if (from is PlayerMobile pm)
{
var amt = pm.Mounted ? 48 : 16;
if (++pm.StepsTaken % amt == 0)
{
--pm.Stam;
}
}
DeathStrike.AddStep(from);
}
public static int GetStamLoss(Mobile from, int overWeight, bool running)
{
var loss = 5 + overWeight / 25;
if (from.Mounted)
{
loss /= 3;
}
if (running)
{
loss *= 2;
}
return loss;
}
public static bool IsOverloaded(Mobile m)
{
if (!m.Player || !m.Alive || m.AccessLevel > AccessLevel.Player)
{
return false;
}
return Mobile.BodyWeight + m.TotalWeight > GetMaxWeight(m) + OverloadAllowance;
}
}

View file

@ -1,126 +0,0 @@
using System;
using Server.Mobiles;
using Server.Spells.Ninjitsu;
namespace Server.Misc
{
public enum DFAlgorithm
{
Standard,
PainSpike
}
public static class WeightOverloading
{
public const int OverloadAllowance = 4; // We can be four stones overweight without getting fatigued
public static DFAlgorithm DFA { get; set; }
public static void Initialize()
{
EventSink.Movement += EventSink_Movement;
}
public static void FatigueOnDamage(Mobile m, int damage)
{
var fatigue = DFA switch
{
DFAlgorithm.Standard => damage * (100.0 / m.Hits) * ((double)m.Stam / 100) - 5.0,
DFAlgorithm.PainSpike => damage * (100.0 / m.Hits + (50.0 + m.Stam) / 100 - 1.0) - 5.0,
_ => 0.0
};
if (fatigue > 0)
{
m.Stam -= (int)fatigue;
}
}
public static int GetMaxWeight(Mobile m) => m.MaxWeight;
public static void EventSink_Movement(MovementEventArgs e)
{
var from = e.Mobile;
if (!from.Alive || from.AccessLevel > AccessLevel.Player)
{
return;
}
if (!from.Player)
{
// Else it won't work on monsters.
DeathStrike.AddStep(from);
return;
}
var maxWeight = GetMaxWeight(from) + OverloadAllowance;
var overWeight = Mobile.BodyWeight + from.TotalWeight - maxWeight;
if (overWeight > 0)
{
from.Stam -= GetStamLoss(from, overWeight, (e.Direction & Direction.Running) != 0);
if (from.Stam == 0)
{
from.SendLocalizedMessage(
500109
); // You are too fatigued to move, because you are carrying too much weight!
e.Blocked = true;
return;
}
}
if (from.Stam * 100 / Math.Max(from.StamMax, 1) < 10)
{
--from.Stam;
}
if (!Core.AOS && from.Stam == 0)
{
from.SendLocalizedMessage(500110); // You are too fatigued to move.
e.Blocked = true;
return;
}
if (from is PlayerMobile pm)
{
var amt = pm.Mounted ? 48 : 16;
if (++pm.StepsTaken % amt == 0)
{
--pm.Stam;
}
}
DeathStrike.AddStep(from);
}
public static int GetStamLoss(Mobile from, int overWeight, bool running)
{
var loss = 5 + overWeight / 25;
if (from.Mounted)
{
loss /= 3;
}
if (running)
{
loss *= 2;
}
return loss;
}
public static bool IsOverloaded(Mobile m)
{
if (!m.Player || !m.Alive || m.AccessLevel > AccessLevel.Player)
{
return false;
}
return Mobile.BodyWeight + m.TotalWeight > GetMaxWeight(m) + OverloadAllowance;
}
}
}

View file

@ -1569,7 +1569,7 @@ namespace Server.Mobiles
Confidence.StopRegenerating(this);
WeightOverloading.FatigueOnDamage(this, amount);
StaminaSystem.FatigueOnDamage(this, amount);
var speechType = SpeechType;

View file

@ -1613,7 +1613,7 @@ namespace Server.Mobiles
{
if (AccessLevel < AccessLevel.GameMaster && item.IsChildOf(Backpack))
{
var maxWeight = WeightOverloading.GetMaxWeight(this);
var maxWeight = StaminaSystem.GetMaxWeight(this);
var curWeight = BodyWeight + TotalWeight;
if (curWeight > maxWeight)
@ -2339,7 +2339,7 @@ namespace Server.Mobiles
Confidence.StopRegenerating(this);
WeightOverloading.FatigueOnDamage(this, amount);
StaminaSystem.FatigueOnDamage(this, amount);
ReceivedHonorContext?.OnTargetDamaged(from, amount);
SentHonorContext?.OnSourceDamaged(from, amount);

View file

@ -74,7 +74,7 @@ namespace Server.Misc
public virtual GiftResult GiveGift(Mobile mob, Item item)
{
if (mob.PlaceInBackpack(item) && !WeightOverloading.IsOverloaded(mob))
if (mob.PlaceInBackpack(item) && !StaminaSystem.IsOverloaded(mob))
{
return GiftResult.Backpack;
}

View file

@ -1009,11 +1009,11 @@ namespace Server.Spells
bcTarget?.AlterSpellDamageFrom(from, ref dmg);
WeightOverloading.DFA = dfa;
StaminaSystem.DFA = dfa;
var damageGiven = AOS.Damage(target, from, dmg, phys, fire, cold, pois, nrgy, chaos);
WeightOverloading.DFA = DFAlgorithm.Standard;
StaminaSystem.DFA = DFAlgorithm.Standard;
bcFrom?.OnDamageSpell(target, damageGiven);
@ -1143,11 +1143,11 @@ namespace Server.Spells
bcTarg?.AlterSpellDamageFrom(m_From, ref m_Damage);
}
WeightOverloading.DFA = m_DFA;
StaminaSystem.DFA = m_DFA;
var damageGiven = AOS.Damage(m_Target, m_From, m_Damage, m_Phys, m_Fire, m_Cold, m_Pois, m_Nrgy, m_Chaos);
WeightOverloading.DFA = DFAlgorithm.Standard;
StaminaSystem.DFA = DFAlgorithm.Standard;
bcFrom?.OnDamageSpell(m_Target, damageGiven);

View file

@ -72,7 +72,7 @@ namespace Server.Spells.Chivalry
{
Caster.SendLocalizedMessage(1061282); // You cannot use the Sacred Journey ability to flee from combat.
}
else if (WeightOverloading.IsOverloaded(Caster))
else if (StaminaSystem.IsOverloaded(Caster))
{
Caster.SendLocalizedMessage(502359, "", 0x22); // Thou art too encumbered to move.
}
@ -150,7 +150,7 @@ namespace Server.Spells.Chivalry
return false;
}
if (WeightOverloading.IsOverloaded(Caster))
if (StaminaSystem.IsOverloaded(Caster))
{
Caster.SendLocalizedMessage(502359, "", 0x22); // Thou art too encumbered to move.
return false;

View file

@ -72,7 +72,7 @@ namespace Server.Spells.Fourth
{
Caster.SendLocalizedMessage(1005564, "", 0x22); // Wouldst thou flee during the heat of battle??
}
else if (WeightOverloading.IsOverloaded(Caster))
else if (StaminaSystem.IsOverloaded(Caster))
{
Caster.SendLocalizedMessage(502359, "", 0x22); // Thou art too encumbered to move.
}
@ -153,7 +153,7 @@ namespace Server.Spells.Fourth
return false;
}
if (WeightOverloading.IsOverloaded(Caster))
if (StaminaSystem.IsOverloaded(Caster))
{
Caster.SendLocalizedMessage(502359, "", 0x22); // Thou art too encumbered to move.
return false;

View file

@ -73,10 +73,10 @@ namespace Server.Spells.Necromancy
BuffInfo.AddBuff(m, new BuffInfo(BuffIcon.PainSpike, 1075667, buffTime, m, Convert.ToString((int)damage)));
// TODO: Find a better way to do this
WeightOverloading.DFA = DFAlgorithm.PainSpike;
StaminaSystem.DFA = DFAlgorithm.PainSpike;
m.Damage((int)damage, Caster);
SpellHelper.DoLeech((int)damage, Caster, m);
WeightOverloading.DFA = DFAlgorithm.Standard;
StaminaSystem.DFA = DFAlgorithm.Standard;
// SpellHelper.Damage( this, m, damage, 100, 0, 0, 0, 0, Misc.DFAlgorithm.PainSpike );
HarmfulSpell(m);

View file

@ -47,7 +47,7 @@ namespace Server.Spells.Ninjitsu
{
Caster.SendLocalizedMessage(1061632); // You can't do that while carrying the sigil.
}
else if (WeightOverloading.IsOverloaded(Caster))
else if (StaminaSystem.IsOverloaded(Caster))
{
Caster.SendLocalizedMessage(502359, "", 0x22); // Thou art too encumbered to move.
}

View file

@ -39,7 +39,7 @@ namespace Server.Spells.Third
{
Caster.SendLocalizedMessage(1061632); // You can't do that while carrying the sigil.
}
else if (WeightOverloading.IsOverloaded(Caster))
else if (StaminaSystem.IsOverloaded(Caster))
{
Caster.SendLocalizedMessage(502359, "", 0x22); // Thou art too encumbered to move.
}
@ -121,7 +121,7 @@ namespace Server.Spells.Third
return false;
}
if (WeightOverloading.IsOverloaded(Caster))
if (StaminaSystem.IsOverloaded(Caster))
{
Caster.SendLocalizedMessage(502359, "", 0x22); // Thou art too encumbered to move.
return false;