ModernUO/Projects/UOContent/Items/Skill Items/Magical/Misc/Moongate.cs
Kamron Batman 83f771c99a
perf: Migrate Travel/Moongate gumps to DynamicGump (#2412)
## Summary

Migrates the three player-facing travel/moongate gumps from legacy `Gump` to the modern `DynamicGump` system.

- `GoGump` (Gumps/Go/GoGump.cs) → `DynamicGump`. The category-tree layout's row count varies with the current `GoCategory`'s child count and pagination. Refreshes via `SendGump(this)` after mutating `_node`/`_page` instead of allocating a new instance per nav/page click.
- `MoongateGump` (Items/Misc/PublicMoongate.cs) → `DynamicGump`. The destination tab strip and per-map pages are gated by ruleset (sigil bearer, murderer, faction facet) and expansion/young flag, plus the configured map selection. The set of pages and the active-map swap make the layout shape per-instance.
- `MoongateConfirmGump` (Items/Skill Items/Magical/Misc/Moongate.cs) → `DynamicGump`. Per the **dynamic-cliloc rule**, the gump bakes one of two different cliloc numbers (1062050 Felucca-warning vs 1062049 generic confirm) and selects between an AOS and pre-AOS layout shape — both characteristics force `DynamicGump` rather than `StaticGump<T>` because cached layout bytes would otherwise lock in the wrong cliloc/shape.

All three now use a `private` constructor with a `public static DisplayTo(...)` entry point that validates prerequisites before any gump is allocated (empty-gump rule, CLAUDE.md §13). All are `Singleton` and use `SendGump(this)` self-refresh on internal navigation. Updated callers: `PublicMoongate.UseGate` and `Moongate.BeginConfirmation` now call `DisplayTo(...)`.
2026-04-25 17:03:24 -07:00

388 lines
10 KiB
C#

using System;
using ModernUO.Serialization;
using Server.Factions;
using Server.Gumps;
using Server.Misc;
using Server.Mobiles;
using Server.Network;
using Server.Regions;
namespace Server.Items;
[DispellableField]
[SerializationGenerator(0, false)]
public partial class Moongate : Item
{
[SerializableField(0)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private Point3D _target;
[SerializableField(1)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private Map _targetMap;
[SerializableField(2)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private bool _dispellable;
[Constructible]
public Moongate(bool dispellable = true) : this(Point3D.Zero, null, dispellable)
{
}
[Constructible]
public Moongate(Point3D target, Map targetMap = null, bool dispellable = true) : base(0xF6C)
{
Movable = false;
Light = LightType.Circle300;
Target = target;
TargetMap = targetMap;
Dispellable = dispellable;
}
public virtual bool ShowFeluccaWarning => false;
public override void OnDoubleClick(Mobile from)
{
if (!from.Player)
{
return;
}
if (from.InRange(GetWorldLocation(), 1))
{
CheckGate(from, 1);
}
else
{
from.SendLocalizedMessage(500446); // That is too far away.
}
}
public override bool OnMoveOver(Mobile m)
{
if (m.Player)
{
CheckGate(m, 0);
}
return true;
}
public virtual void CheckGate(Mobile m, int range)
{
if (m.Hidden && m.AccessLevel == AccessLevel.Player && Core.ML)
{
m.RevealingAction();
}
new DelayTimer(m, this, range).Start();
}
public virtual void OnGateUsed(Mobile m)
{
}
public virtual void UseGate(Mobile m)
{
var flags = m.NetState?.Flags ?? ClientFlags.None;
if (Sigil.ExistsOn(m))
{
m.SendLocalizedMessage(1061632); // You can't do that while carrying the sigil.
}
else if (TargetMap == Map.Felucca && m is PlayerMobile mobile && mobile.Young)
{
mobile.SendLocalizedMessage(1049543); // You decide against traveling to Felucca while you are still young.
}
else if (m.Murderer && TargetMap != Map.Felucca ||
TargetMap == Map.Tokuno && (flags & ClientFlags.Tokuno) == 0 ||
TargetMap == Map.Malas && (flags & ClientFlags.Malas) == 0 ||
TargetMap == Map.Ilshenar && (flags & ClientFlags.Ilshenar) == 0 ||
TargetMap == Map.TerMur && (flags & ClientFlags.TerMur) == 0)
{
m.SendLocalizedMessage(1019004); // You are not allowed to travel there.
}
else if (m.Spell != null)
{
m.SendLocalizedMessage(1049616); // You are too busy to do that at the moment.
}
else if (TargetMap != null && TargetMap != Map.Internal)
{
BaseCreature.TeleportPets(m, Target, TargetMap);
m.MoveToWorld(Target, TargetMap);
if (m.AccessLevel == AccessLevel.Player || !m.Hidden)
{
m.PlaySound(0x1FE);
}
OnGateUsed(m);
}
else
{
m.SendMessage("This moongate does not seem to go anywhere.");
}
}
public virtual bool ValidateUse(Mobile from, bool message)
{
if (from.Deleted || Deleted)
{
return false;
}
if (from.Map != Map || !from.InRange(this, 1))
{
if (message)
{
from.SendLocalizedMessage(500446); // That is too far away.
}
return false;
}
return true;
}
public virtual void BeginConfirmation(Mobile from)
{
if (IsInTown(from.Location, from.Map) && !IsInTown(Target, TargetMap) ||
from.Map != Map.Felucca && TargetMap == Map.Felucca && ShowFeluccaWarning)
{
if (from.AccessLevel == AccessLevel.Player || !from.Hidden)
{
from.SendSound(0x20E, from);
}
MoongateConfirmGump.DisplayTo(from, this);
}
else
{
EndConfirmation(from);
}
}
public virtual void EndConfirmation(Mobile from)
{
if (!ValidateUse(from, true))
{
return;
}
UseGate(from);
}
public virtual void DelayCallback(Mobile from, int range)
{
if (!ValidateUse(from, false) || !from.InRange(this, range))
{
return;
}
if (TargetMap != null)
{
BeginConfirmation(from);
}
else
{
from.SendMessage("This moongate does not seem to go anywhere.");
}
}
public static bool IsInTown(Point3D p, Map map) =>
map != null && Region.Find(p, map).GetRegion<GuardedRegion>()?.IsDisabled() == false;
private class DelayTimer : Timer
{
private Mobile _from;
private Moongate _gate;
private int _range;
public DelayTimer(Mobile from, Moongate gate, int range) : base(TimeSpan.FromSeconds(1.0))
{
_from = from;
_gate = gate;
_range = range;
}
protected override void OnTick()
{
_gate.DelayCallback(_from, _range);
}
}
}
[SerializationGenerator(1, false)]
public partial class ConfirmationMoongate : Moongate
{
[SerializableField(0)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private TextDefinition _message;
[SerializableField(1)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private int _gumpWidth;
[SerializableField(2)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private int _gumpHeight;
[SerializableField(3)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private int _titleColor;
[SerializableField(4)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private int _messageColor;
[SerializableField(5)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private int _titleNumber;
[Constructible]
public ConfirmationMoongate() : this(Point3D.Zero)
{
}
[Constructible]
public ConfirmationMoongate(Point3D target, Map targetMap = null) : base(target, targetMap)
{
}
public virtual void Warning_Callback(Mobile from, bool okay)
{
if (okay)
{
EndConfirmation(from);
}
}
public override void BeginConfirmation(Mobile from)
{
if (GumpWidth > 0 && GumpHeight > 0 && TitleNumber > 0 && Message?.IsEmpty == false)
{
from.SendGump(
new WarningGump(
TitleNumber,
TitleColor,
Message,
MessageColor,
GumpWidth,
GumpHeight,
okay => Warning_Callback(from, okay)
),
true
);
}
else
{
base.BeginConfirmation(from);
}
}
private void Deserialize(IGenericReader reader, int version)
{
base.Deserialize(reader);
GumpWidth = reader.ReadEncodedInt();
GumpHeight = reader.ReadEncodedInt();
TitleColor = reader.ReadEncodedInt();
MessageColor = reader.ReadEncodedInt();
TitleNumber = reader.ReadEncodedInt();
var number = reader.ReadEncodedInt();
var message = reader.ReadString();
Message = number > 0 ? number : message;
}
}
public class MoongateConfirmGump : DynamicGump
{
private readonly Mobile _from;
private readonly Moongate _gate;
public override bool Singleton => true;
private MoongateConfirmGump(Mobile from, Moongate gate) : base(Core.AOS ? 110 : 20, Core.AOS ? 100 : 30)
{
_from = from;
_gate = gate;
}
public static void DisplayTo(Mobile from, Moongate gate)
{
if (from?.NetState == null || gate == null || gate.Deleted)
{
return;
}
from.SendGump(new MoongateConfirmGump(from, gate));
}
protected override void BuildLayout(ref DynamicGumpBuilder builder)
{
builder.AddPage();
if (Core.AOS)
{
builder.SetNoClose();
builder.AddBackground(0, 0, 420, 280, 5054);
builder.AddImageTiled(10, 10, 400, 20, 2624);
builder.AddAlphaRegion(10, 10, 400, 20);
builder.AddHtmlLocalized(10, 10, 400, 20, 1062051, 30720); // Gate Warning
builder.AddImageTiled(10, 40, 400, 200, 2624);
builder.AddAlphaRegion(10, 40, 400, 200);
if (_from.Map != Map.Felucca && _gate.TargetMap == Map.Felucca && _gate.ShowFeluccaWarning)
{
// This Gate goes to Felucca... Continue to enter the gate, Cancel to stay here
builder.AddHtmlLocalized(10, 40, 400, 200, 1062050, 32512, false, true);
}
else
{
// Dost thou wish to step into the moongate? Continue to enter the gate, Cancel to stay here
builder.AddHtmlLocalized(10, 40, 400, 200, 1062049, 32512, false, true);
}
builder.AddImageTiled(10, 250, 400, 20, 2624);
builder.AddAlphaRegion(10, 250, 400, 20);
builder.AddButton(10, 250, 4005, 4007, 1);
builder.AddHtmlLocalized(40, 250, 170, 20, 1011036, 32767); // OKAY
builder.AddButton(210, 250, 4005, 4007, 0);
builder.AddHtmlLocalized(240, 250, 170, 20, 1011012, 32767); // CANCEL
}
else
{
builder.AddBackground(0, 0, 420, 400, 5054);
builder.AddBackground(10, 10, 400, 380, 3000);
// Dost thou wish to step into the moongate? Continue to enter the gate, Cancel to stay here
builder.AddHtmlLocalized(20, 40, 380, 60, 1062049);
builder.AddHtmlLocalized(55, 110, 290, 20, 1011012); // CANCEL
builder.AddButton(20, 110, 4005, 4007, 0);
builder.AddHtmlLocalized(55, 140, 290, 40, 1011011); // CONTINUE
builder.AddButton(20, 140, 4005, 4007, 1);
}
}
public override void OnResponse(NetState state, in RelayInfo info)
{
if (info.ButtonID == 1)
{
_gate.EndConfirmation(_from);
}
}
}