ModernUO/Projects/UOContent/Engines/ConPVP/TournamentSignupItem.cs
Kamron Batman a74c7f9d4e
perf: Migrates ConPVP lobby gumps from legacy Gump. (#2423)
## Summary

Migrates 14 ConPVP lobby/tournament gumps from legacy `Gump` to modern `DynamicGump`/`StaticGump<T>`. Layouts move into `BuildLayout(ref DynamicGumpBuilder)`, constructors become private, and validation moves into static `DisplayTo` entry points (empty-gump rule).

**Per-gump base type decisions:**

- `BeginGump` → `StaticGump<BeginGump>`: layout is fully fixed (no dynamic content). All other gumps below are `DynamicGump` because they bake dynamic player names, guild abbreviations, ruleset titles, arena names, tournament participant names, ladder rankings, or per-instance rule modifications. Per the cliloc/dynamic-text rule, dynamic content forces `DynamicGump`.
- `ReadyGump`, `ReadyUpGump` → `DynamicGump` (per-instance participant rosters).
- `AcceptDuelGump`, `AcceptTeamGump`, `ConfirmSignupGump` → `DynamicGump` (challenger/registrar/team names, dynamic rule modifications).
- `PickRulesetGump`, `RulesetGump` → `DynamicGump` (ruleset titles and option labels per instance).
- `ParticipantGump`, `DuelContextGump` → `DynamicGump` (player rosters/team labels).
- `LadderGump` → `DynamicGump` (ladder entries: ranks, levels, guild abbrs, names, wins/losses).
- `ArenaGump` → `DynamicGump` (arena names with active player names).
- `PreferencesGump` → `DynamicGump` (arena name list).
- `TournamentBracketGump` (~1k LOC) → `DynamicGump`. The whole gump is one type-switched view that re-renders on every button press across `Index`, `Rules_Info`, `Participant_List`, `Participant_Info`, `Round_List`, `Round_Info`, `Match_Info`, `Player_Info`. All branches bake per-instance content.

**Refresh-via-this conversions (the big perf wins):**

- `LadderGump`: page +/- now mutates `_page` and calls `from.SendGump(this)` instead of allocating a new `LadderGump`.
- `PickRulesetGump`: ruleset apply / flavor toggle now refreshes via `this`.
- `ParticipantGump`: increase/decrease team size, remove player, target failure all refresh via `this`.
- `DuelContextGump`: failed-start and add-participant refresh via `this`.
- `ConfirmSignupGump`: every signup-validation rejection branch in `OnResponse` and every `AddPlayer_OnTarget` rejection branch refreshes via `this` (was allocating a new gump per branch).
- `TournamentBracketGump`: every navigation button (back/forward, type change, page change, drill-down) mutates `_type`/`_object`/`_list`/`_page` and refreshes via `this`. Previously each click allocated a new 1k LOC gump.

All gumps are `Singleton`, use private constructors with static `DisplayTo` entry points that null-check `NetState` before allocation. External callers in `DuelContext`, `TournamentBracketItem`, `TournamentController`, `TournamentSignupItem`, and the cross-references between `AcceptDuelGump`/`ParticipantGump`/`AcceptTeamGump`/`ConfirmSignupGump` are all updated to use `DisplayTo`. Legacy `m_X` fields renamed to `_x` per coding standards.
2026-05-03 01:06:04 -07:00

165 lines
6.1 KiB
C#

using System.Collections.Generic;
using ModernUO.Serialization;
using Server.Factions;
using Server.Gumps;
using Server.Mobiles;
namespace Server.Engines.ConPVP;
[SerializationGenerator(0, false)]
public partial class TournamentSignupItem : Item
{
[SerializedCommandProperty(AccessLevel.GameMaster)]
[SerializableField(0)]
private TournamentController _tournament;
[SerializedCommandProperty(AccessLevel.GameMaster)]
[SerializableField(1)]
private Mobile _registrar;
[Constructible]
public TournamentSignupItem() : base(4029) => Movable = false;
public override string DefaultName => "tournament signup book";
public override void OnDoubleClick(Mobile from)
{
if (!from.InRange(GetWorldLocation(), 2))
{
from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 1019045); // I can't reach that
}
else
{
var tourney = Tournament?.Tournament;
if (tourney == null)
{
return;
}
Registrar?.Direction = Registrar.GetDirectionTo(this);
switch (tourney.Stage)
{
case TournamentStage.Fighting:
{
if (Registrar != null)
{
if (tourney.HasParticipant(from))
{
Registrar.PrivateOverheadMessage(
MessageType.Regular,
0x35,
false,
"Excuse me? You are already signed up.",
from.NetState
);
}
else
{
Registrar.PrivateOverheadMessage(
MessageType.Regular,
0x22,
false,
"The tournament has already begun. You are too late to signup now.",
from.NetState
);
}
}
break;
}
case TournamentStage.Inactive:
{
Registrar?.PrivateOverheadMessage(
MessageType.Regular,
0x35,
false,
"The tournament is closed.",
from.NetState
);
break;
}
case TournamentStage.Signup:
{
var ladder = Ladder.Instance;
var entry = ladder?.Find(from);
if (entry != null && Ladder.GetLevel(entry.Experience) < tourney.LevelRequirement)
{
Registrar?.PrivateOverheadMessage(
MessageType.Regular,
0x35,
false,
"You have not yet proven yourself a worthy dueler.",
from.NetState
);
break;
}
if (tourney.IsFactionRestricted && Faction.Find(from) == null)
{
Registrar?.PrivateOverheadMessage(
MessageType.Regular,
0x35,
false,
"Only those who have declared their faction allegiance may participate.",
from.NetState
);
break;
}
if (from.HasGump<AcceptTeamGump>())
{
Registrar?.PrivateOverheadMessage(
MessageType.Regular,
0x22,
false,
"You must first respond to the offer I've given you.",
from.NetState
);
}
else if (from.HasGump<AcceptDuelGump>())
{
Registrar?.PrivateOverheadMessage(
MessageType.Regular,
0x22,
false,
"You must first cancel your duel offer.",
from.NetState
);
}
else if (from is PlayerMobile mobile && mobile.DuelContext != null)
{
Registrar?.PrivateOverheadMessage(
MessageType.Regular,
0x22,
false,
"You are already participating in a duel.",
mobile.NetState
);
}
else if (!tourney.HasParticipant(from))
{
ConfirmSignupGump.DisplayTo(from, Registrar, tourney, new List<Mobile> { from });
}
else
{
Registrar?.PrivateOverheadMessage(
MessageType.Regular,
0x35,
false,
"You have already entered this tournament.",
from.NetState
);
}
break;
}
}
}
}
}