diff --git a/Projects/UOContent/Items/Special/Solen Items/BraceletOfBinding.cs b/Projects/UOContent/Items/Special/Solen Items/BraceletOfBinding.cs index 5b820f404..78a8a791a 100644 --- a/Projects/UOContent/Items/Special/Solen Items/BraceletOfBinding.cs +++ b/Projects/UOContent/Items/Special/Solen Items/BraceletOfBinding.cs @@ -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; diff --git a/Projects/UOContent/Misc/StaminaSystem.cs b/Projects/UOContent/Misc/StaminaSystem.cs new file mode 100644 index 000000000..e033c6a7d --- /dev/null +++ b/Projects/UOContent/Misc/StaminaSystem.cs @@ -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; + } +} diff --git a/Projects/UOContent/Misc/WeightOverloading.cs b/Projects/UOContent/Misc/WeightOverloading.cs deleted file mode 100644 index 41c997920..000000000 --- a/Projects/UOContent/Misc/WeightOverloading.cs +++ /dev/null @@ -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; - } - } -} diff --git a/Projects/UOContent/Mobiles/BaseCreature.cs b/Projects/UOContent/Mobiles/BaseCreature.cs index ffc515223..ea2ed659f 100644 --- a/Projects/UOContent/Mobiles/BaseCreature.cs +++ b/Projects/UOContent/Mobiles/BaseCreature.cs @@ -1569,7 +1569,7 @@ namespace Server.Mobiles Confidence.StopRegenerating(this); - WeightOverloading.FatigueOnDamage(this, amount); + StaminaSystem.FatigueOnDamage(this, amount); var speechType = SpeechType; diff --git a/Projects/UOContent/Mobiles/PlayerMobile.cs b/Projects/UOContent/Mobiles/PlayerMobile.cs index 636e8d34b..972949c89 100644 --- a/Projects/UOContent/Mobiles/PlayerMobile.cs +++ b/Projects/UOContent/Mobiles/PlayerMobile.cs @@ -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); diff --git a/Projects/UOContent/Special Systems/Engines/GiftGiving.cs b/Projects/UOContent/Special Systems/Engines/GiftGiving.cs index 5cfc1a06a..7bbeef3f2 100644 --- a/Projects/UOContent/Special Systems/Engines/GiftGiving.cs +++ b/Projects/UOContent/Special Systems/Engines/GiftGiving.cs @@ -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; } diff --git a/Projects/UOContent/Spells/Base/SpellHelper.cs b/Projects/UOContent/Spells/Base/SpellHelper.cs index dd63413cc..90299d3f8 100644 --- a/Projects/UOContent/Spells/Base/SpellHelper.cs +++ b/Projects/UOContent/Spells/Base/SpellHelper.cs @@ -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); diff --git a/Projects/UOContent/Spells/Chivalry/SacredJourney.cs b/Projects/UOContent/Spells/Chivalry/SacredJourney.cs index bd5b1e4fd..ef3d71bc5 100644 --- a/Projects/UOContent/Spells/Chivalry/SacredJourney.cs +++ b/Projects/UOContent/Spells/Chivalry/SacredJourney.cs @@ -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; diff --git a/Projects/UOContent/Spells/Fourth/Recall.cs b/Projects/UOContent/Spells/Fourth/Recall.cs index 11cf61ad0..37887a64e 100644 --- a/Projects/UOContent/Spells/Fourth/Recall.cs +++ b/Projects/UOContent/Spells/Fourth/Recall.cs @@ -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; diff --git a/Projects/UOContent/Spells/Necromancy/PainSpike.cs b/Projects/UOContent/Spells/Necromancy/PainSpike.cs index 9a73e91c3..ea1f87fc7 100644 --- a/Projects/UOContent/Spells/Necromancy/PainSpike.cs +++ b/Projects/UOContent/Spells/Necromancy/PainSpike.cs @@ -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); diff --git a/Projects/UOContent/Spells/Ninjitsu/ShadowJump.cs b/Projects/UOContent/Spells/Ninjitsu/ShadowJump.cs index f28d9cd87..ccb6c50b0 100644 --- a/Projects/UOContent/Spells/Ninjitsu/ShadowJump.cs +++ b/Projects/UOContent/Spells/Ninjitsu/ShadowJump.cs @@ -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. } diff --git a/Projects/UOContent/Spells/Third/Teleport.cs b/Projects/UOContent/Spells/Third/Teleport.cs index 8f2546893..642f5040c 100644 --- a/Projects/UOContent/Spells/Third/Teleport.cs +++ b/Projects/UOContent/Spells/Third/Teleport.cs @@ -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;