From 8b1014f3953e72ac8a35c076218a51c89ad77760 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Thu, 4 Jul 2024 11:23:42 -0700 Subject: [PATCH] fix: Cleans up HonorGump and Honor checks (#1853) ### Summary - Moves `HonorSelf` gump to the Virtues folder. - Renames `HonorSelf` to `HonorSelfGump` - Makes `HonorSelfGump` a static gump. - Changes the text in the gump to a cliloc. - Collapses some of the checks for honoring to simplify the logic. - Moves the player check higher to fix the wrong error message displaying when trying to honor damaged players. --- Projects/UOContent/Engines/Virtues/Honor.cs | 31 +++++++------------ .../Engines/Virtues/HonorSelfGump.cs | 30 ++++++++++++++++++ Projects/UOContent/Gumps/HonorSelf.cs | 28 ----------------- 3 files changed, 41 insertions(+), 48 deletions(-) create mode 100644 Projects/UOContent/Engines/Virtues/HonorSelfGump.cs delete mode 100644 Projects/UOContent/Gumps/HonorSelf.cs diff --git a/Projects/UOContent/Engines/Virtues/Honor.cs b/Projects/UOContent/Engines/Virtues/Honor.cs index 3ce8064a87..51fe093ac1 100644 --- a/Projects/UOContent/Engines/Virtues/Honor.cs +++ b/Projects/UOContent/Engines/Virtues/Honor.cs @@ -67,7 +67,7 @@ private static void EmbraceHonor(PlayerMobile pm) } } - pm.SendGump(new HonorSelf(pm)); + pm.SendGump(new HonorSelfGump(pm)); } public static void ActivateEmbrace(PlayerMobile pm) @@ -89,7 +89,7 @@ public static void ActivateEmbrace(PlayerMobile pm) Timer.DelayCall( TimeSpan.FromSeconds(duration), - (m) => + m => { // We get the virtues again, in case it was deleted/dereferenced var v = VirtueSystem.GetOrCreateVirtues(m); @@ -125,32 +125,23 @@ private static void Honor(PlayerMobile source, Mobile target) } } - if (target.Hits < target.HitsMax) + if (Core.ML && target is PlayerMobile) { - source.SendLocalizedMessage(1063166); // You cannot honor this monster because it is too damaged. + source.SendLocalizedMessage(1075614); // You cannot honor other players. return; } - if (target.Body.IsHuman && (target is not BaseCreature cret || !cret.AlwaysAttackable && !cret.AlwaysMurderer)) + if (target.Hits < target.HitsMax) { - if (reg?.IsDisabled() != true) - { - // Allow honor on blue if not in a guarded region - } - else if ((map?.Rules & MapRules.HarmfulRestrictions) == 0) - { - // Allow honor on blue if in Fel - } - else - { - source.SendLocalizedMessage(1001018); // You cannot perform negative acts - return; // cannot honor in trammel town on blue - } + source.SendLocalizedMessage(1063166); // You cannot honor this monster because it is too damaged. + return; } - if (Core.ML && target is PlayerMobile) + // Allow honor on blue if not in a guarded region or blue in Felucca + if (target.Body.IsHuman && (target is not BaseCreature cret || !cret.AlwaysAttackable && !cret.AlwaysMurderer) && + reg?.IsDisabled() == true && (map?.Rules & MapRules.HarmfulRestrictions) != 0) { - source.SendLocalizedMessage(1075614); // You cannot honor other players. + source.SendLocalizedMessage(1001018); // You cannot perform negative acts return; } diff --git a/Projects/UOContent/Engines/Virtues/HonorSelfGump.cs b/Projects/UOContent/Engines/Virtues/HonorSelfGump.cs new file mode 100644 index 0000000000..203301e6eb --- /dev/null +++ b/Projects/UOContent/Engines/Virtues/HonorSelfGump.cs @@ -0,0 +1,30 @@ +using Server.Engines.Virtues; +using Server.Mobiles; +using Server.Network; + +namespace Server.Gumps; + +public class HonorSelfGump : StaticGump +{ + private readonly PlayerMobile _from; + + public HonorSelfGump(PlayerMobile from) : base(150, 50) => _from = from; + + protected override void BuildLayout(ref StaticGumpBuilder builder) + { + builder.AddBackground(0, 0, 245, 145, 9250); + builder.AddButton(157, 101, 247, 248, 1); + builder.AddButton(81, 100, 241, 248, 0); + + // Are you sure you want to use honor points on yourself? + builder.AddHtmlLocalized(21, 20, 203, 70, 1071218, true); + } + + public override void OnResponse(NetState sender, in RelayInfo info) + { + if (info.ButtonID == 1) + { + HonorVirtue.ActivateEmbrace(_from); + } + } +} diff --git a/Projects/UOContent/Gumps/HonorSelf.cs b/Projects/UOContent/Gumps/HonorSelf.cs deleted file mode 100644 index 641d15eb6b..0000000000 --- a/Projects/UOContent/Gumps/HonorSelf.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Server.Engines.Virtues; -using Server.Mobiles; -using Server.Network; - -namespace Server.Gumps -{ - public class HonorSelf : Gump - { - private readonly PlayerMobile m_from; - - public HonorSelf(PlayerMobile from) : base(150, 50) - { - m_from = from; - AddBackground(0, 0, 245, 145, 9250); - AddButton(157, 101, 247, 248, 1); - AddButton(81, 100, 241, 248, 0); - AddHtml(21, 20, 203, 70, "Are you sure you want to use honor points on yourself?", true); - } - - public override void OnResponse(NetState sender, in RelayInfo info) - { - if (info.ButtonID == 1) - { - HonorVirtue.ActivateEmbrace(m_from); - } - } - } -}