Skip to content

Commit

Permalink
fix: Cleans up HonorGump and Honor checks (#1853)
Browse files Browse the repository at this point in the history
### 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.
  • Loading branch information
kamronbatman authored Jul 4, 2024
1 parent ac3e4fc commit 8b1014f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 48 deletions.
31 changes: 11 additions & 20 deletions Projects/UOContent/Engines/Virtues/Honor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
30 changes: 30 additions & 0 deletions Projects/UOContent/Engines/Virtues/HonorSelfGump.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Server.Engines.Virtues;
using Server.Mobiles;
using Server.Network;

namespace Server.Gumps;

public class HonorSelfGump : StaticGump<HonorSelfGump>
{
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);
}
}
}
28 changes: 0 additions & 28 deletions Projects/UOContent/Gumps/HonorSelf.cs

This file was deleted.

0 comments on commit 8b1014f

Please sign in to comment.