From 44bd129734d67c6bb820ba1557ef392b766c1121 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Thu, 10 Mar 2022 12:18:22 -0800 Subject: [PATCH] fix: Fixes mana insufficient message for newer clients. (#957) Publish 100 introduced the cliloc change for insufficient mana. This was rolled out starting with v7.0.65.4 on 6/22/2018. --- Projects/UOContent/Spells/Base/Spell.cs | 166 +++++++++++++----------- 1 file changed, 91 insertions(+), 75 deletions(-) diff --git a/Projects/UOContent/Spells/Base/Spell.cs b/Projects/UOContent/Spells/Base/Spell.cs index 78eea7bdc..c7631a7ee 100644 --- a/Projects/UOContent/Spells/Base/Spell.cs +++ b/Projects/UOContent/Spells/Base/Spell.cs @@ -459,6 +459,8 @@ namespace Server.Spells } } + private static ClientVersion _insufficientManaClientChange = new ClientVersion("7.0.65.4"); + public bool Cast() { StartCastTime = Core.TickCount; @@ -473,13 +475,19 @@ namespace Server.Spells return false; } - if (Scroll is BaseWand && Caster.Spell?.IsCasting == true) + var isCasting = Caster.Spell?.IsCasting == true; + var isWand = Scroll is BaseWand; + + if (isCasting) { - Caster.SendLocalizedMessage(502643); // You can not cast a spell while frozen. - } - else if (Caster.Spell?.IsCasting == true) - { - Caster.SendLocalizedMessage(502642); // You are already casting a spell. + if (isWand) + { + Caster.SendLocalizedMessage(502643); // You can not cast a spell while frozen. + } + else + { + Caster.SendLocalizedMessage(502642); // You are already casting a spell. + } } else if (BlockedByHorrificBeast && TransformationSpellHelper.UnderTransformation(Caster, typeof(HorrificBeastSpell)) || @@ -487,7 +495,7 @@ namespace Server.Spells { Caster.SendLocalizedMessage(1061091); // You cannot cast that spell in this form. } - else if (Scroll is not BaseWand && (Caster.Paralyzed || Caster.Frozen)) + else if (!isWand && (Caster.Paralyzed || Caster.Frozen)) { Caster.SendLocalizedMessage(502643); // You can not cast a spell while frozen. } @@ -502,76 +510,84 @@ namespace Server.Spells else if ((Caster as PlayerMobile)?.DuelContext?.AllowSpellCast(Caster, this) == false) { } - else if (Caster.Mana >= ScaleMana(GetMana())) - { - if (Caster.Spell == null && Caster.CheckSpellCast(this) && CheckCast() && - Caster.Region.OnBeginSpellCast(Caster, this)) - { - State = SpellState.Casting; - Caster.Spell = this; - - if (Scroll is not BaseWand && RevealOnCast) - { - Caster.RevealingAction(); - } - - SayMantra(); - - var castDelay = GetCastDelay(); - - if (ShowHandMovement && (Caster.Body.IsHuman || Caster.Player && Caster.Body.IsMonster)) - { - var count = (int)Math.Ceiling(castDelay.TotalSeconds / AnimateDelay.TotalSeconds); - - if (count != 0) - { - _animTimer = new AnimTimer(this, count); - _animTimer.Start(); - } - - if (Info.LeftHandEffect > 0) - { - Caster.FixedParticles(0, 10, 5, Info.LeftHandEffect, EffectLayer.LeftHand); - } - - if (Info.RightHandEffect > 0) - { - Caster.FixedParticles(0, 10, 5, Info.RightHandEffect, EffectLayer.RightHand); - } - } - - if (ClearHandsOnCast) - { - Caster.ClearHands(); - } - - if (Core.ML) - { - WeaponAbility.ClearCurrentAbility(Caster); - } - - _castTimer = new CastTimer(this, castDelay); - // m_CastTimer.Start(); - - OnBeginCast(); - - if (castDelay > TimeSpan.Zero) - { - _castTimer.Start(); - } - else - { - _castTimer.Tick(); - } - - return true; - } - - return false; - } else { - Caster.LocalOverheadMessage(MessageType.Regular, 0x22, 502625); // Insufficient mana + var requiredMana = ScaleMana(GetMana()); + + if (Caster.Mana >= requiredMana) + { + if (Caster.Spell == null && Caster.CheckSpellCast(this) && CheckCast() && + Caster.Region.OnBeginSpellCast(Caster, this)) + { + State = SpellState.Casting; + Caster.Spell = this; + + if (!isWand && RevealOnCast) + { + Caster.RevealingAction(); + } + + SayMantra(); + + var castDelay = GetCastDelay(); + + if (ShowHandMovement && (Caster.Body.IsHuman || Caster.Player && Caster.Body.IsMonster)) + { + var count = (int)Math.Ceiling(castDelay.TotalSeconds / AnimateDelay.TotalSeconds); + + if (count != 0) + { + _animTimer = new AnimTimer(this, count); + _animTimer.Start(); + } + + if (Info.LeftHandEffect > 0) + { + Caster.FixedParticles(0, 10, 5, Info.LeftHandEffect, EffectLayer.LeftHand); + } + + if (Info.RightHandEffect > 0) + { + Caster.FixedParticles(0, 10, 5, Info.RightHandEffect, EffectLayer.RightHand); + } + } + + if (ClearHandsOnCast) + { + Caster.ClearHands(); + } + + if (Core.ML) + { + WeaponAbility.ClearCurrentAbility(Caster); + } + + _castTimer = new CastTimer(this, castDelay); + // m_CastTimer.Start(); + + OnBeginCast(); + + if (castDelay > TimeSpan.Zero) + { + _castTimer.Start(); + } + else + { + _castTimer.Tick(); + } + + return true; + } + } + else if (Caster.NetState?.Version >= _insufficientManaClientChange) + { + // Insufficient mana. You must have at least ~1_MANA_REQUIREMENT~ Mana to use this spell. + Caster.LocalOverheadMessage(MessageType.Regular, 0x22, 502625, requiredMana.ToString()); + } + else + { + Caster.LocalOverheadMessage(MessageType.Regular, 0x22, 502625); // Insufficient mana + } } return false;