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.
This commit is contained in:
Kamron Batman 2026-05-03 01:06:04 -07:00 • committed by GitHub
parent 9c2ac2b8ea
commit a74c7f9d4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 3203 additions and 3226 deletions

View file

@ -4,125 +4,132 @@ using Server.Gumps;
using Server.Mobiles; using Server.Mobiles;
using Server.Network; using Server.Network;
namespace Server.Engines.ConPVP namespace Server.Engines.ConPVP;
{
public class AcceptDuelGump : Gump public class AcceptDuelGump : DynamicGump
{ {
private const int LabelColor32 = 0xFFFFFF; private const int LabelColor32 = 0xFFFFFF;
private const int BlackColor32 = 0x000008; private const int BlackColor32 = 0x000008;
private static readonly Dictionary<Mobile, List<IgnoreEntry>> m_IgnoreLists = private static readonly Dictionary<Mobile, List<IgnoreEntry>> _ignoreLists = new();
new();
private readonly Mobile m_Challenged; private readonly Mobile _challenged;
private readonly Mobile m_Challenger; private readonly Mobile _challenger;
private readonly DuelContext m_Context; private readonly DuelContext _context;
private readonly Participant m_Participant; private readonly Participant _participant;
private readonly int m_Slot; private readonly int _slot;
private bool m_Active = true; private bool _active = true;
public override bool Singleton => true; public override bool Singleton => true;
public AcceptDuelGump(Mobile challenger, Mobile challenged, DuelContext context, Participant p, int slot) : base( private AcceptDuelGump(Mobile challenger, Mobile challenged, DuelContext context, Participant p, int slot)
50, : base(50, 50)
50
)
{ {
m_Challenger = challenger; _challenger = challenger;
m_Challenged = challenged; _challenged = challenged;
m_Context = context; _context = context;
m_Participant = p; _participant = p;
m_Slot = slot; _slot = slot;
Closable = false;
AddPage(0);
// AddBackground( 0, 0, 400, 220, 9150 );
AddBackground(1, 1, 398, 218, 3600);
// AddBackground( 16, 15, 369, 189, 9100 );
AddImageTiled(16, 15, 369, 189, 3604);
AddAlphaRegion(16, 15, 369, 189);
AddImage(215, -43, 0xEE40);
// AddImage( 330, 141, 0x8BA );
var duelChallengeBlack = "Duel Challenge".Center(BlackColor32);
AddHtml(22 - 1, 22, 294, 20, duelChallengeBlack);
AddHtml(22 + 1, 22, 294, 20, duelChallengeBlack);
AddHtml(22, 22 - 1, 294, 20, duelChallengeBlack);
AddHtml(22, 22 + 1, 294, 20, duelChallengeBlack);
AddHtml(22, 22, 294, 20, "Duel Challenge".Center(LabelColor32));
var accept = p.Contains(challenger)
? $"You have been asked to join sides with {challenger.Name} in a duel. Do you accept?"
: $"You have been challenged to a duel from {challenger.Name}. Do you accept?";
var acceptBlack = accept.Color(BlackColor32);
AddHtml(22 - 1, 50, 294, 40, acceptBlack);
AddHtml(22 + 1, 50, 294, 40, acceptBlack);
AddHtml(22, 50 - 1, 294, 40, acceptBlack);
AddHtml(22, 50 + 1, 294, 40, acceptBlack);
AddHtml(22, 50, 294, 40, accept.Color(0xB0C868));
AddImageTiled(32, 88, 264, 1, 9107);
AddImageTiled(42, 90, 264, 1, 9157);
var yesBlack = "Yes, I will fight this duel.".Color(BlackColor32);
AddRadio(24, 100, 9727, 9730, true, 1);
AddHtml(60 - 1, 105, 250, 20, yesBlack);
AddHtml(60 + 1, 105, 250, 20, yesBlack);
AddHtml(60, 105 - 1, 250, 20, yesBlack);
AddHtml(60, 105 + 1, 250, 20, yesBlack);
AddHtml(60, 105, 250, 20, "Yes, I will fight this duel.".Color(LabelColor32));
var noBlack = "No, I do not wish to fight.".Color(BlackColor32);
AddRadio(24, 135, 9727, 9730, false, 2);
AddHtml(60 - 1, 140, 250, 20, noBlack);
AddHtml(60 + 1, 140, 250, 20, noBlack);
AddHtml(60, 140 - 1, 250, 20, noBlack);
AddHtml(60, 140 + 1, 250, 20, noBlack);
AddHtml(60, 140, 250, 20, "No, I do not wish to fight.".Color(LabelColor32));
var noAskBlack = "No, knave. Do not ask again.".Color(BlackColor32);
AddRadio(24, 170, 9727, 9730, false, 3);
AddHtml(60 - 1, 175, 250, 20, noAskBlack);
AddHtml(60 + 1, 175, 250, 20, noAskBlack);
AddHtml(60, 175 - 1, 250, 20, noAskBlack);
AddHtml(60, 175 + 1, 250, 20, noAskBlack);
AddHtml(60, 175, 250, 20, "No, knave. Do not ask again.".Color(LabelColor32));
AddButton(314, 173, 247, 248, 1);
Timer.StartTimer(TimeSpan.FromSeconds(15.0), AutoReject); Timer.StartTimer(TimeSpan.FromSeconds(15.0), AutoReject);
} }
public void AutoReject() public static void DisplayTo(Mobile challenger, Mobile challenged, DuelContext context, Participant p, int slot)
{ {
if (!m_Active) if (challenged?.NetState == null || challenger == null || context == null || p == null)
{ {
return; return;
} }
m_Active = false; challenged.SendGump(new AcceptDuelGump(challenger, challenged, context, p, slot));
}
m_Challenged.CloseGump<AcceptDuelGump>(); protected override void BuildLayout(ref DynamicGumpBuilder builder)
{
builder.SetNoClose();
m_Challenger.SendMessage($"{m_Challenged.Name} seems unresponsive."); builder.AddPage();
m_Challenged.SendMessage("You decline the challenge.");
builder.AddBackground(1, 1, 398, 218, 3600);
builder.AddImageTiled(16, 15, 369, 189, 3604);
builder.AddAlphaRegion(16, 15, 369, 189);
builder.AddImage(215, -43, 0xEE40);
var duelChallengeBlack = "Duel Challenge".Center(BlackColor32);
builder.AddHtml(22 - 1, 22, 294, 20, duelChallengeBlack);
builder.AddHtml(22 + 1, 22, 294, 20, duelChallengeBlack);
builder.AddHtml(22, 22 - 1, 294, 20, duelChallengeBlack);
builder.AddHtml(22, 22 + 1, 294, 20, duelChallengeBlack);
builder.AddHtml(22, 22, 294, 20, "Duel Challenge".Center(LabelColor32));
var accept = _participant.Contains(_challenger)
? $"You have been asked to join sides with {_challenger.Name} in a duel. Do you accept?"
: $"You have been challenged to a duel from {_challenger.Name}. Do you accept?";
var acceptBlack = accept.Color(BlackColor32);
builder.AddHtml(22 - 1, 50, 294, 40, acceptBlack);
builder.AddHtml(22 + 1, 50, 294, 40, acceptBlack);
builder.AddHtml(22, 50 - 1, 294, 40, acceptBlack);
builder.AddHtml(22, 50 + 1, 294, 40, acceptBlack);
builder.AddHtml(22, 50, 294, 40, accept.Color(0xB0C868));
builder.AddImageTiled(32, 88, 264, 1, 9107);
builder.AddImageTiled(42, 90, 264, 1, 9157);
var yesBlack = "Yes, I will fight this duel.".Color(BlackColor32);
builder.AddRadio(24, 100, 9727, 9730, true, 1);
builder.AddHtml(60 - 1, 105, 250, 20, yesBlack);
builder.AddHtml(60 + 1, 105, 250, 20, yesBlack);
builder.AddHtml(60, 105 - 1, 250, 20, yesBlack);
builder.AddHtml(60, 105 + 1, 250, 20, yesBlack);
builder.AddHtml(60, 105, 250, 20, "Yes, I will fight this duel.".Color(LabelColor32));
var noBlack = "No, I do not wish to fight.".Color(BlackColor32);
builder.AddRadio(24, 135, 9727, 9730, false, 2);
builder.AddHtml(60 - 1, 140, 250, 20, noBlack);
builder.AddHtml(60 + 1, 140, 250, 20, noBlack);
builder.AddHtml(60, 140 - 1, 250, 20, noBlack);
builder.AddHtml(60, 140 + 1, 250, 20, noBlack);
builder.AddHtml(60, 140, 250, 20, "No, I do not wish to fight.".Color(LabelColor32));
var noAskBlack = "No, knave. Do not ask again.".Color(BlackColor32);
builder.AddRadio(24, 170, 9727, 9730, false, 3);
builder.AddHtml(60 - 1, 175, 250, 20, noAskBlack);
builder.AddHtml(60 + 1, 175, 250, 20, noAskBlack);
builder.AddHtml(60, 175 - 1, 250, 20, noAskBlack);
builder.AddHtml(60, 175 + 1, 250, 20, noAskBlack);
builder.AddHtml(60, 175, 250, 20, "No, knave. Do not ask again.".Color(LabelColor32));
builder.AddButton(314, 173, 247, 248, 1);
}
public void AutoReject()
{
if (!_active)
{
return;
}
_active = false;
_challenged.CloseGump<AcceptDuelGump>();
_challenger.SendMessage($"{_challenged.Name} seems unresponsive.");
_challenged.SendMessage("You decline the challenge.");
} }
public static void BeginIgnore(Mobile source, Mobile toIgnore) public static void BeginIgnore(Mobile source, Mobile toIgnore)
{ {
if (!m_IgnoreLists.TryGetValue(source, out var list)) if (!_ignoreLists.TryGetValue(source, out var list))
{ {
m_IgnoreLists[source] = list = new List<IgnoreEntry>(); _ignoreLists[source] = list = new List<IgnoreEntry>();
} }
for (var i = 0; i < list.Count; ++i) for (var i = 0; i < list.Count; ++i)
@ -146,7 +153,7 @@ namespace Server.Engines.ConPVP
public static bool IsIgnored(Mobile source, Mobile check) public static bool IsIgnored(Mobile source, Mobile check)
{ {
if (!m_IgnoreLists.TryGetValue(source, out var list)) if (!_ignoreLists.TryGetValue(source, out var list))
{ {
return false; return false;
} }
@ -170,21 +177,21 @@ namespace Server.Engines.ConPVP
public override void OnResponse(NetState sender, in RelayInfo info) public override void OnResponse(NetState sender, in RelayInfo info)
{ {
if (info.ButtonID != 1 || !m_Active || !m_Context.Registered) if (info.ButtonID != 1 || !_active || !_context.Registered)
{ {
return; return;
} }
m_Active = false; _active = false;
if (!m_Context.Participants.Contains(m_Participant)) if (!_context.Participants.Contains(_participant))
{ {
return; return;
} }
if (info.IsSwitched(1)) if (info.IsSwitched(1))
{ {
if (m_Challenged is not PlayerMobile pm) if (_challenged is not PlayerMobile pm)
{ {
return; return;
} }
@ -200,7 +207,7 @@ namespace Server.Engines.ConPVP
pm.SendMessage(0x22, "You have already been challenged in a duel."); pm.SendMessage(0x22, "You have already been challenged in a duel.");
} }
m_Challenger.SendMessage($"{pm.Name} cannot fight because they are already assigned to another duel."); _challenger.SendMessage($"{pm.Name} cannot fight because they are already assigned to another duel.");
} }
else if (DuelContext.CheckCombat(pm)) else if (DuelContext.CheckCombat(pm))
{ {
@ -208,32 +215,32 @@ namespace Server.Engines.ConPVP
0x22, 0x22,
"You have recently been in combat with another player and must wait before starting a duel." "You have recently been in combat with another player and must wait before starting a duel."
); );
m_Challenger.SendMessage( _challenger.SendMessage(
$"{pm.Name} cannot fight because they have recently been in combat with another player." $"{pm.Name} cannot fight because they have recently been in combat with another player."
); );
} }
else if (TournamentController.IsActive) else if (TournamentController.IsActive)
{ {
pm.SendMessage(0x22, "A tournament is currently active and you may not duel."); pm.SendMessage(0x22, "A tournament is currently active and you may not duel.");
m_Challenger.SendMessage(0x22, "A tournament is currently active and you may not duel."); _challenger.SendMessage(0x22, "A tournament is currently active and you may not duel.");
} }
else else
{ {
var added = false; var added = false;
if (m_Slot >= 0 && m_Slot < m_Participant.Players.Length && m_Participant.Players[m_Slot] == null) if (_slot >= 0 && _slot < _participant.Players.Length && _participant.Players[_slot] == null)
{ {
added = true; added = true;
m_Participant.Players[m_Slot] = new DuelPlayer(m_Challenged, m_Participant); _participant.Players[_slot] = new DuelPlayer(_challenged, _participant);
} }
else else
{ {
for (var i = 0; i < m_Participant.Players.Length; ++i) for (var i = 0; i < _participant.Players.Length; ++i)
{ {
if (m_Participant.Players[i] == null) if (_participant.Players[i] == null)
{ {
added = true; added = true;
m_Participant.Players[i] = new DuelPlayer(m_Challenged, m_Participant); _participant.Players[i] = new DuelPlayer(_challenged, _participant);
break; break;
} }
} }
@ -241,37 +248,37 @@ namespace Server.Engines.ConPVP
if (added) if (added)
{ {
m_Challenger.SendMessage($"{m_Challenged.Name} has accepted the request."); _challenger.SendMessage($"{_challenged.Name} has accepted the request.");
m_Challenged.SendMessage($"You have accepted the request from {m_Challenger.Name}."); _challenged.SendMessage($"You have accepted the request from {_challenger.Name}.");
foreach (var g in m_Challenger.GetGumps()) foreach (var g in _challenger.GetGumps())
{ {
if (g is ParticipantGump pg && pg.Participant == m_Participant) if (g is ParticipantGump pg && pg.Participant == _participant)
{ {
m_Challenger.SendGump(new ParticipantGump(m_Challenger, m_Context, m_Participant)); ParticipantGump.DisplayTo(_challenger, _context, _participant);
break; break;
} }
if (g is DuelContextGump dcg && dcg.Context == m_Context) if (g is DuelContextGump dcg && dcg.Context == _context)
{ {
m_Challenger.SendGump(new DuelContextGump(m_Challenger, m_Context)); DuelContextGump.DisplayTo(_challenger, _context);
break; break;
} }
} }
} }
else else
{ {
m_Challenger.SendMessage( _challenger.SendMessage(
$"The participant list was full and so {m_Challenged.Name} could not join." $"The participant list was full and so {_challenged.Name} could not join."
); );
if (m_Participant.Contains(m_Challenger)) if (_participant.Contains(_challenger))
{ {
m_Challenged.SendMessage($"The participant list was full and so you could not join the fight with {m_Challenger.Name}."); _challenged.SendMessage($"The participant list was full and so you could not join the fight with {_challenger.Name}.");
} }
else else
{ {
m_Challenged.SendMessage($"The participant list was full and so you could not join the fight against {m_Challenger.Name}."); _challenged.SendMessage($"The participant list was full and so you could not join the fight against {_challenger.Name}.");
} }
} }
} }
@ -280,18 +287,18 @@ namespace Server.Engines.ConPVP
{ {
if (info.IsSwitched(3)) if (info.IsSwitched(3))
{ {
BeginIgnore(m_Challenged, m_Challenger); BeginIgnore(_challenged, _challenger);
} }
m_Challenger.SendMessage($"{m_Challenged.Name} does not wish to fight."); _challenger.SendMessage($"{_challenged.Name} does not wish to fight.");
if (m_Participant.Contains(m_Challenger)) if (_participant.Contains(_challenger))
{ {
m_Challenged.SendMessage($"You chose not to fight with {m_Challenger.Name}."); _challenged.SendMessage($"You chose not to fight with {_challenger.Name}.");
} }
else else
{ {
m_Challenged.SendMessage($"You chose not to fight against {m_Challenger.Name}."); _challenged.SendMessage($"You chose not to fight against {_challenger.Name}.");
} }
} }
} }
@ -299,19 +306,17 @@ namespace Server.Engines.ConPVP
private class IgnoreEntry private class IgnoreEntry
{ {
private static readonly TimeSpan ExpireDelay = TimeSpan.FromMinutes(15.0); private static readonly TimeSpan ExpireDelay = TimeSpan.FromMinutes(15.0);
public readonly Mobile m_Ignored; private DateTime _expire;
public DateTime m_Expire;
public IgnoreEntry(Mobile ignored) public IgnoreEntry(Mobile ignored)
{ {
m_Ignored = ignored; Ignored = ignored;
Refresh(); Refresh();
} }
public Mobile Ignored => m_Ignored; public Mobile Ignored { get; }
public bool Expired => Core.Now >= m_Expire; public bool Expired => Core.Now >= _expire;
public void Refresh() => m_Expire = Core.Now + ExpireDelay; public void Refresh() => _expire = Core.Now + ExpireDelay;
}
} }
} }

View file

@ -1307,19 +1307,19 @@ public partial class DuelContext
{ {
if (dc.m_Tournament == null) if (dc.m_Tournament == null)
{ {
pm.SendGump(new ReadyGump(pm, dc, dc.ReadyCount)); ReadyGump.DisplayTo(pm, dc, dc.ReadyCount);
} }
} }
else if (dc.ReadyWait && !dc.StartedBeginCountdown && !dc.Started && !dc.Finished) else if (dc.ReadyWait && !dc.StartedBeginCountdown && !dc.Started && !dc.Finished)
{ {
if (dc.m_Tournament == null) if (dc.m_Tournament == null)
{ {
pm.SendGump(new ReadyUpGump(pm, dc)); ReadyUpGump.DisplayTo(pm, dc);
} }
} }
else if (dc.Initiator == pm && !dc.ReadyWait && !dc.StartedBeginCountdown && !dc.Started && !dc.Finished) else if (dc.Initiator == pm && !dc.ReadyWait && !dc.StartedBeginCountdown && !dc.Started && !dc.Finished)
{ {
pm.SendGump(new DuelContextGump(pm, dc)); DuelContextGump.DisplayTo(pm, dc);
} }
} }
@ -1418,7 +1418,7 @@ public partial class DuelContext
} }
else else
{ {
pm.SendGump(new DuelContextGump(pm, new DuelContext(pm, RulesetLayout.Root))); DuelContextGump.DisplayTo(pm, new DuelContext(pm, RulesetLayout.Root));
e.Handled = true; e.Handled = true;
} }
} }
@ -1433,7 +1433,7 @@ public partial class DuelContext
if (prefs != null) if (prefs != null)
{ {
e.Mobile.SendGump(new PreferencesGump(e.Mobile, prefs)); PreferencesGump.DisplayTo(e.Mobile, prefs);
} }
} }
} }
@ -1547,13 +1547,13 @@ public partial class DuelContext
{ {
if (g is ParticipantGump pg && pg.Participant == p) if (g is ParticipantGump pg && pg.Participant == p)
{ {
init.SendGump(new ParticipantGump(init, dc, p)); ParticipantGump.DisplayTo(init, dc, p);
break; break;
} }
if (g is DuelContextGump dcg && dcg.Context == dc) if (g is DuelContextGump dcg && dcg.Context == dc)
{ {
init.SendGump(new DuelContextGump(init, dc)); DuelContextGump.DisplayTo(init, dc);
break; break;
} }
} }
@ -1582,14 +1582,14 @@ public partial class DuelContext
{ {
if (g is ParticipantGump pg && pg.Participant == p) if (g is ParticipantGump pg && pg.Participant == p)
{ {
init.SendGump(new ParticipantGump(init, dc, p)); ParticipantGump.DisplayTo(init, dc, p);
send = false; send = false;
break; break;
} }
if (g is DuelContextGump dcg && dcg.Context == dc) if (g is DuelContextGump dcg && dcg.Context == dc)
{ {
init.SendGump(new DuelContextGump(init, dc)); DuelContextGump.DisplayTo(init, dc);
send = false; send = false;
break; break;
} }
@ -1597,7 +1597,7 @@ public partial class DuelContext
if (send) if (send)
{ {
init.SendGump(new DuelContextGump(init, dc)); DuelContextGump.DisplayTo(init, dc);
} }
} }
} }
@ -1626,14 +1626,14 @@ public partial class DuelContext
{ {
if (g is ParticipantGump pg && pg.Participant == p) if (g is ParticipantGump pg && pg.Participant == p)
{ {
init.SendGump(new ParticipantGump(init, dc, p)); ParticipantGump.DisplayTo(init, dc, p);
send = false; send = false;
break; break;
} }
if (g is DuelContextGump dcg && dcg.Context == dc) if (g is DuelContextGump dcg && dcg.Context == dc)
{ {
init.SendGump(new DuelContextGump(init, dc)); DuelContextGump.DisplayTo(init, dc);
send = false; send = false;
break; break;
} }
@ -1641,7 +1641,7 @@ public partial class DuelContext
if (send) if (send)
{ {
init.SendGump(new DuelContextGump(init, dc)); DuelContextGump.DisplayTo(init, dc);
} }
} }
} }
@ -1801,7 +1801,7 @@ public partial class DuelContext
} }
else if (!m_Yielding) else if (!m_Yielding)
{ {
Initiator.SendGump(new DuelContextGump(Initiator, this)); DuelContextGump.DisplayTo(Initiator, this);
} }
ReadyWait = false; ReadyWait = false;
@ -2195,7 +2195,7 @@ public partial class DuelContext
gumps.Close<ReadyGump>(); gumps.Close<ReadyGump>();
gumps.Close<ReadyUpGump>(); gumps.Close<ReadyUpGump>();
gumps.Close<BeginGump>(); gumps.Close<BeginGump>();
gumps.Send(new BeginGump(count)); BeginGump.DisplayTo(mob, count);
} }
mob.Frozen = true; mob.Frozen = true;
@ -2254,7 +2254,7 @@ public partial class DuelContext
if (mob != null && m_Tournament == null) if (mob != null && m_Tournament == null)
{ {
mob.SendGump(new ReadyUpGump(mob, this), true); ReadyUpGump.DisplayTo(mob, this);
} }
} }
} }
@ -2509,7 +2509,7 @@ public partial class DuelContext
{ {
if (m_Tournament == null) if (m_Tournament == null)
{ {
mob.SendGump(new ReadyGump(mob, this, count), true); ReadyGump.DisplayTo(mob, this, count);
} }
} }
else else

View file

@ -6,33 +6,50 @@ using Server.Mobiles;
using Server.Network; using Server.Network;
using Server.Text; using Server.Text;
namespace Server.Engines.ConPVP namespace Server.Engines.ConPVP;
{
public class AcceptTeamGump : Gump public class AcceptTeamGump : DynamicGump
{ {
private const int BlackColor32 = 0x000008; private const int BlackColor32 = 0x000008;
private const int LabelColor32 = 0xFFFFFF; private const int LabelColor32 = 0xFFFFFF;
private readonly Mobile m_From; private readonly Mobile _from;
private readonly List<Mobile> m_Players; private readonly List<Mobile> _players;
private readonly Mobile m_Registrar; private readonly Mobile _registrar;
private readonly Mobile m_Requested; private readonly Mobile _requested;
private readonly Tournament m_Tournament; private readonly Tournament _tournament;
private bool m_Active; private bool _active;
public AcceptTeamGump( public override bool Singleton => true;
private AcceptTeamGump(
Mobile from, Mobile requested, Tournament tourney, Mobile registrar, List<Mobile> players Mobile from, Mobile requested, Tournament tourney, Mobile registrar, List<Mobile> players
) : base(50, 50) ) : base(50, 50)
{ {
m_From = from; _from = from;
m_Requested = requested; _requested = requested;
m_Tournament = tourney; _tournament = tourney;
m_Registrar = registrar; _registrar = registrar;
m_Players = players; _players = players;
m_Active = true; _active = true;
var ruleset = tourney.Ruleset; Timer.StartTimer(TimeSpan.FromSeconds(15.0), AutoReject);
}
public static void DisplayTo(Mobile from, Mobile requested, Tournament tourney, Mobile registrar, List<Mobile> players)
{
if (requested?.NetState != null && from != null && tourney != null && players != null)
{
requested.SendGump(new AcceptTeamGump(from, requested, tourney, registrar, players));
}
}
protected override void BuildLayout(ref DynamicGumpBuilder builder)
{
builder.SetNoClose();
var ruleset = _tournament.Ruleset;
var basedef = ruleset.Base; var basedef = ruleset.Base;
var height = 185 + 35 + 60 + 12; var height = 185 + 35 + 60 + 12;
@ -71,73 +88,72 @@ namespace Server.Engines.ConPVP
height += 10 + 22 + 25 + 25; height += 10 + 22 + 25 + 25;
Closable = false; builder.AddPage();
AddPage(0); builder.AddBackground(1, 1, 398, height, 3600);
AddBackground(1, 1, 398, height, 3600); builder.AddImageTiled(16, 15, 369, height - 29, 3604);
builder.AddAlphaRegion(16, 15, 369, height - 29);
AddImageTiled(16, 15, 369, height - 29, 3604); builder.AddImage(215, -43, 0xEE40);
AddAlphaRegion(16, 15, 369, height - 29);
AddImage(215, -43, 0xEE40);
using var sb = new ValueStringBuilder(stackalloc char[64]); using var sb = new ValueStringBuilder(stackalloc char[64]);
if (tourney.TourneyType == TourneyType.FreeForAll) if (_tournament.TourneyType == TourneyType.FreeForAll)
{ {
sb.Append("FFA"); sb.Append("FFA");
} }
else if (tourney.TourneyType == TourneyType.RandomTeam) else if (_tournament.TourneyType == TourneyType.RandomTeam)
{ {
sb.Append($"{tourney.ParticipantsPerMatch}-Team"); sb.Append($"{_tournament.ParticipantsPerMatch}-Team");
} }
else if (tourney.TourneyType == TourneyType.Faction) else if (_tournament.TourneyType == TourneyType.Faction)
{ {
sb.Append($"{tourney.ParticipantsPerMatch}-Team Faction"); sb.Append($"{_tournament.ParticipantsPerMatch}-Team Faction");
} }
else if (tourney.TourneyType == TourneyType.RedVsBlue) else if (_tournament.TourneyType == TourneyType.RedVsBlue)
{ {
sb.Append("Red v Blue"); sb.Append("Red v Blue");
} }
else else
{ {
for (var i = 0; i < tourney.ParticipantsPerMatch; ++i) for (var i = 0; i < _tournament.ParticipantsPerMatch; ++i)
{ {
if (sb.Length > 0) if (sb.Length > 0)
{ {
sb.Append('v'); sb.Append('v');
} }
sb.Append(tourney.PlayersPerParticipant); sb.Append(_tournament.PlayersPerParticipant);
} }
} }
if (tourney.EventController != null) if (_tournament.EventController != null)
{ {
sb.Append($" {tourney.EventController.Title}"); sb.Append($" {_tournament.EventController.Title}");
} }
sb.Append(" Tournament Invitation"); sb.Append(" Tournament Invitation");
AddBorderedText(22, 22, 294, 20, sb.AsSpan().Center(), LabelColor32, BlackColor32); AddBorderedText(ref builder, 22, 22, 294, 20, sb.AsSpan().Center(), LabelColor32, BlackColor32);
AddBorderedText( AddBorderedText(
ref builder,
22, 22,
50, 50,
294, 294,
40, 40,
$"You have been asked to partner with {from.Name} in a tournament. Do you accept?", $"You have been asked to partner with {_from.Name} in a tournament. Do you accept?",
0xB0C868, 0xB0C868,
BlackColor32 BlackColor32
); );
AddImageTiled(32, 88, 264, 1, 9107); builder.AddImageTiled(32, 88, 264, 1, 9107);
AddImageTiled(42, 90, 264, 1, 9157); builder.AddImageTiled(42, 90, 264, 1, 9157);
var y = 100; var y = 100;
var groupText = tourney.GroupType switch var groupText = _tournament.GroupType switch
{ {
GroupingType.HighVsLow => "High vs Low", GroupingType.HighVsLow => "High vs Low",
GroupingType.Nearest => "Closest opponent", GroupingType.Nearest => "Closest opponent",
@ -145,56 +161,56 @@ namespace Server.Engines.ConPVP
_ => null _ => null
}; };
AddBorderedText(35, y, 190, 20, $"Grouping: {groupText}", LabelColor32, BlackColor32); AddBorderedText(ref builder, 35, y, 190, 20, $"Grouping: {groupText}", LabelColor32, BlackColor32);
y += 20; y += 20;
var tieText = tourney.TieType switch var tieText = _tournament.TieType switch
{ {
TieType.Random => "Random", TieType.Random => "Random",
TieType.Highest => "Highest advances", TieType.Highest => "Highest advances",
TieType.Lowest => "Lowest advances", TieType.Lowest => "Lowest advances",
TieType.FullAdvancement => tourney.ParticipantsPerMatch == 2 ? "Both advance" : "Everyone advances", TieType.FullAdvancement => _tournament.ParticipantsPerMatch == 2 ? "Both advance" : "Everyone advances",
TieType.FullElimination => tourney.ParticipantsPerMatch == 2 ? "Both eliminated" : "Everyone eliminated", TieType.FullElimination => _tournament.ParticipantsPerMatch == 2 ? "Both eliminated" : "Everyone eliminated",
_ => null _ => null
}; };
AddBorderedText(35, y, 190, 20, $"Tiebreaker: {tieText}", LabelColor32, BlackColor32); AddBorderedText(ref builder, 35, y, 190, 20, $"Tiebreaker: {tieText}", LabelColor32, BlackColor32);
y += 20; y += 20;
string sdText; string sdText;
if (tourney.SuddenDeath > TimeSpan.Zero) if (_tournament.SuddenDeath > TimeSpan.Zero)
{ {
sdText = tourney.SuddenDeathRounds > 0 ? sdText = _tournament.SuddenDeathRounds > 0 ?
$"Sudden Death: {(int)tourney.SuddenDeath.TotalMinutes}:{tourney.SuddenDeath.Seconds:D2} (first {tourney.SuddenDeathRounds} rounds)" : $"Sudden Death: {(int)_tournament.SuddenDeath.TotalMinutes}:{_tournament.SuddenDeath.Seconds:D2} (first {_tournament.SuddenDeathRounds} rounds)" :
$"Sudden Death: {(int)tourney.SuddenDeath.TotalMinutes}:{tourney.SuddenDeath.Seconds:D2} (all rounds)"; $"Sudden Death: {(int)_tournament.SuddenDeath.TotalMinutes}:{_tournament.SuddenDeath.Seconds:D2} (all rounds)";
} }
else else
{ {
sdText = "Sudden Death: Off"; sdText = "Sudden Death: Off";
} }
AddBorderedText(35, y, 240, 20, sdText, LabelColor32, BlackColor32); AddBorderedText(ref builder, 35, y, 240, 20, sdText, LabelColor32, BlackColor32);
y += 20; y += 20;
y += 6; y += 6;
AddImageTiled(32, y - 1, 264, 1, 9107); builder.AddImageTiled(32, y - 1, 264, 1, 9107);
AddImageTiled(42, y + 1, 264, 1, 9157); builder.AddImageTiled(42, y + 1, 264, 1, 9157);
y += 6; y += 6;
AddBorderedText(35, y, 190, 20, $"Ruleset: {basedef.Title}", LabelColor32, BlackColor32); AddBorderedText(ref builder, 35, y, 190, 20, $"Ruleset: {basedef.Title}", LabelColor32, BlackColor32);
y += 20; y += 20;
for (var i = 0; i < ruleset.Flavors.Count; ++i, y += 18) for (var i = 0; i < ruleset.Flavors.Count; ++i, y += 18)
{ {
AddBorderedText(35, y, 190, 20, $" + {ruleset.Flavors[i].Title}", LabelColor32, BlackColor32); AddBorderedText(ref builder, 35, y, 190, 20, $" + {ruleset.Flavors[i].Title}", LabelColor32, BlackColor32);
} }
y += 4; y += 4;
if (changes > 0) if (changes > 0)
{ {
AddBorderedText(35, y, 190, 20, "Modifications:", LabelColor32, BlackColor32); AddBorderedText(ref builder, 35, y, 190, 20, "Modifications:", LabelColor32, BlackColor32);
y += 20; y += 20;
for (var i = 0; i < opts.Length; ++i) for (var i = 0; i < opts.Length; ++i)
@ -205,8 +221,8 @@ namespace Server.Engines.ConPVP
if (name != null) // sanity if (name != null) // sanity
{ {
AddImage(35, y, opts[i] ? 0xD3 : 0xD2); builder.AddImage(35, y, opts[i] ? 0xD3 : 0xD2);
AddBorderedText(60, y, 165, 22, name, LabelColor32, BlackColor32); AddBorderedText(ref builder, 60, y, 165, 22, name, LabelColor32, BlackColor32);
} }
y += 22; y += 22;
@ -215,90 +231,88 @@ namespace Server.Engines.ConPVP
} }
else else
{ {
AddBorderedText(35, y, 190, 20, "Modifications: None", LabelColor32, BlackColor32); AddBorderedText(ref builder, 35, y, 190, 20, "Modifications: None", LabelColor32, BlackColor32);
y += 20; y += 20;
} }
y += 8; y += 8;
AddImageTiled(32, y - 1, 264, 1, 9107); builder.AddImageTiled(32, y - 1, 264, 1, 9107);
AddImageTiled(42, y + 1, 264, 1, 9157); builder.AddImageTiled(42, y + 1, 264, 1, 9157);
y += 8; y += 8;
AddRadio(24, y, 9727, 9730, true, 1); builder.AddRadio(24, y, 9727, 9730, true, 1);
AddBorderedText(60, y + 5, 250, 20, "Yes, I will join them.", LabelColor32, BlackColor32); AddBorderedText(ref builder, 60, y + 5, 250, 20, "Yes, I will join them.", LabelColor32, BlackColor32);
y += 35; y += 35;
AddRadio(24, y, 9727, 9730, false, 2); builder.AddRadio(24, y, 9727, 9730, false, 2);
AddBorderedText(60, y + 5, 250, 20, "No, I do not wish to fight.", LabelColor32, BlackColor32); AddBorderedText(ref builder, 60, y + 5, 250, 20, "No, I do not wish to fight.", LabelColor32, BlackColor32);
y += 35; y += 35;
AddRadio(24, y, 9727, 9730, false, 3); builder.AddRadio(24, y, 9727, 9730, false, 3);
AddBorderedText(60, y + 5, 270, 20, "No, most certainly not. Do not ask again.", LabelColor32, BlackColor32); AddBorderedText(ref builder, 60, y + 5, 270, 20, "No, most certainly not. Do not ask again.", LabelColor32, BlackColor32);
y += 35; y += 35;
y -= 3; y -= 3;
AddButton(314, y, 247, 248, 1); builder.AddButton(314, y, 247, 248, 1);
Timer.StartTimer(TimeSpan.FromSeconds(15.0), AutoReject);
} }
private void AddBorderedText(int x, int y, int width, int height, string text, int color, int borderColor) private static void AddBorderedText(ref DynamicGumpBuilder builder, int x, int y, int width, int height, string text, int color, int borderColor)
{ {
AddColoredText(x - 1, y - 1, width, height, text, borderColor); AddColoredText(ref builder, x - 1, y - 1, width, height, text, borderColor);
AddColoredText(x - 1, y + 1, width, height, text, borderColor); AddColoredText(ref builder, x - 1, y + 1, width, height, text, borderColor);
AddColoredText(x + 1, y - 1, width, height, text, borderColor); AddColoredText(ref builder, x + 1, y - 1, width, height, text, borderColor);
AddColoredText(x + 1, y + 1, width, height, text, borderColor); AddColoredText(ref builder, x + 1, y + 1, width, height, text, borderColor);
AddColoredText(x, y, width, height, text, color); AddColoredText(ref builder, x, y, width, height, text, color);
} }
private void AddColoredText(int x, int y, int width, int height, string text, int color) private static void AddColoredText(ref DynamicGumpBuilder builder, int x, int y, int width, int height, string text, int color)
{ {
AddHtml(x, y, width, height, color == 0 ? text : text.Color(color)); builder.AddHtml(x, y, width, height, color == 0 ? text : text.Color(color));
} }
public void AutoReject() public void AutoReject()
{ {
if (!m_Active) if (!_active)
{ {
return; return;
} }
m_Active = false; _active = false;
m_Requested.CloseGump<AcceptTeamGump>(); _requested.CloseGump<AcceptTeamGump>();
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); ConfirmSignupGump.DisplayTo(_from, _registrar, _tournament, _players);
if (m_Registrar != null) if (_registrar != null)
{ {
m_Registrar.PrivateOverheadMessage( _registrar.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x22, 0x22,
false, false,
$"{m_Requested.Name} seems unresponsive.", $"{_requested.Name} seems unresponsive.",
m_From.NetState _from.NetState
); );
m_Registrar.PrivateOverheadMessage( _registrar.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x22, 0x22,
false, false,
$"You have declined the partnership with {m_From.Name}.", $"You have declined the partnership with {_from.Name}.",
m_Requested.NetState _requested.NetState
); );
} }
} }
public override void OnResponse(NetState sender, in RelayInfo info) public override void OnResponse(NetState sender, in RelayInfo info)
{ {
var from = m_From; var from = _from;
var mob = m_Requested; var mob = _requested;
if (info.ButtonID != 1 || !m_Active) if (info.ButtonID != 1 || !_active)
{ {
return; return;
} }
m_Active = false; _active = false;
if (info.IsSwitched(1)) if (info.IsSwitched(1))
{ {
@ -309,9 +323,9 @@ namespace Server.Engines.ConPVP
if (AcceptDuelGump.IsIgnored(mob, from) || mob.Blessed) if (AcceptDuelGump.IsIgnored(mob, from) || mob.Blessed)
{ {
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); ConfirmSignupGump.DisplayTo(_from, _registrar, _tournament, _players);
m_Registrar?.PrivateOverheadMessage( _registrar?.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x22, 0x22,
false, false,
@ -321,9 +335,9 @@ namespace Server.Engines.ConPVP
} }
else if (pm.DuelContext != null) else if (pm.DuelContext != null)
{ {
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); ConfirmSignupGump.DisplayTo(_from, _registrar, _tournament, _players);
m_Registrar?.PrivateOverheadMessage( _registrar?.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x22, 0x22,
false, false,
@ -331,11 +345,11 @@ namespace Server.Engines.ConPVP
from.NetState from.NetState
); );
} }
else if (m_Players.Contains(mob)) else if (_players.Contains(mob))
{ {
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); ConfirmSignupGump.DisplayTo(_from, _registrar, _tournament, _players);
m_Registrar?.PrivateOverheadMessage( _registrar?.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x22, 0x22,
false, false,
@ -343,11 +357,11 @@ namespace Server.Engines.ConPVP
from.NetState from.NetState
); );
} }
else if (m_Tournament.HasParticipant(mob)) else if (_tournament.HasParticipant(mob))
{ {
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); ConfirmSignupGump.DisplayTo(_from, _registrar, _tournament, _players);
m_Registrar?.PrivateOverheadMessage( _registrar?.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x22, 0x22,
false, false,
@ -355,11 +369,11 @@ namespace Server.Engines.ConPVP
from.NetState from.NetState
); );
} }
else if (m_Players.Count >= m_Tournament.PlayersPerParticipant) else if (_players.Count >= _tournament.PlayersPerParticipant)
{ {
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); ConfirmSignupGump.DisplayTo(_from, _registrar, _tournament, _players);
m_Registrar?.PrivateOverheadMessage( _registrar?.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x22, 0x22,
false, false,
@ -369,13 +383,13 @@ namespace Server.Engines.ConPVP
} }
else else
{ {
m_Players.Add(mob); _players.Add(mob);
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); ConfirmSignupGump.DisplayTo(_from, _registrar, _tournament, _players);
if (m_Registrar != null) if (_registrar != null)
{ {
m_Registrar.PrivateOverheadMessage( _registrar.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x59, 0x59,
false, false,
@ -383,7 +397,7 @@ namespace Server.Engines.ConPVP
from.NetState from.NetState
); );
m_Registrar.PrivateOverheadMessage( _registrar.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x59, 0x59,
false, false,
@ -397,14 +411,14 @@ namespace Server.Engines.ConPVP
{ {
if (info.IsSwitched(3)) if (info.IsSwitched(3))
{ {
AcceptDuelGump.BeginIgnore(m_Requested, m_From); AcceptDuelGump.BeginIgnore(_requested, _from);
} }
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); ConfirmSignupGump.DisplayTo(_from, _registrar, _tournament, _players);
if (m_Registrar != null) if (_registrar != null)
{ {
m_Registrar.PrivateOverheadMessage( _registrar.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x22, 0x22,
false, false,
@ -412,7 +426,7 @@ namespace Server.Engines.ConPVP
from.NetState from.NetState
); );
m_Registrar.PrivateOverheadMessage( _registrar.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x22, 0x22,
false, false,
@ -423,4 +437,3 @@ namespace Server.Engines.ConPVP
} }
} }
} }
}

View file

@ -33,7 +33,7 @@ public partial class ArenasMoongate : Item
return false; return false;
} }
from.SendGump(new ArenaGump(from, this)); ArenaGump.DisplayTo(from, this);
if (!from.Hidden || from.AccessLevel == AccessLevel.Player) if (!from.Hidden || from.AccessLevel == AccessLevel.Player)
{ {
@ -58,44 +58,55 @@ public partial class ArenasMoongate : Item
public override bool OnMoveOver(Mobile m) => !m.Player || UseGate(m); public override bool OnMoveOver(Mobile m) => !m.Player || UseGate(m);
} }
public class ArenaGump : Gump public class ArenaGump : DynamicGump
{ {
private readonly List<Arena> m_Arenas; private readonly List<Arena> _arenas;
private readonly Mobile m_From; private readonly ArenasMoongate _gate;
private readonly ArenasMoongate m_Gate;
private int m_ColumnX = 12; private int _columnX;
public override bool Singleton => true; public override bool Singleton => true;
public ArenaGump(Mobile from, ArenasMoongate gate) : base(50, 50) private ArenaGump(ArenasMoongate gate) : base(50, 50)
{ {
m_From = from; _gate = gate;
m_Gate = gate; _arenas = Arena.Arenas;
m_Arenas = Arena.Arenas; }
AddPage(0); public static void DisplayTo(Mobile from, ArenasMoongate gate)
{
if (from?.NetState != null && gate != null)
{
from.SendGump(new ArenaGump(gate));
}
}
var height = 12 + 20 + m_Arenas.Count * 31 + 24 + 12; protected override void BuildLayout(ref DynamicGumpBuilder builder)
{
_columnX = 12;
AddBackground(0, 0, 499 + 40, height, 0x2436); builder.AddPage();
var list = m_Arenas; var height = 12 + 20 + _arenas.Count * 31 + 24 + 12;
builder.AddBackground(0, 0, 499 + 40, height, 0x2436);
var list = _arenas;
for (var i = 1; i < list.Count; i += 2) for (var i = 1; i < list.Count; i += 2)
{ {
AddImageTiled(12, 32 + i * 31, 475 + 40, 30, 0x2430); builder.AddImageTiled(12, 32 + i * 31, 475 + 40, 30, 0x2430);
} }
AddAlphaRegion(10, 10, 479 + 40, height - 20); builder.AddAlphaRegion(10, 10, 479 + 40, height - 20);
AddColumnHeader(35, null); AddColumnHeader(ref builder, 35, null);
AddColumnHeader(115, "Arena"); AddColumnHeader(ref builder, 115, "Arena");
AddColumnHeader(325, "Participants"); AddColumnHeader(ref builder, 325, "Participants");
AddColumnHeader(40, "Obs"); AddColumnHeader(ref builder, 40, "Obs");
AddButton(499 + 40 - 12 - 63 - 4 - 63, height - 12 - 24, 247, 248, 1); builder.AddButton(499 + 40 - 12 - 63 - 4 - 63, height - 12 - 24, 247, 248, 1);
AddButton(499 + 40 - 12 - 63, height - 12 - 24, 241, 242, 2); builder.AddButton(499 + 40 - 12 - 63, height - 12 - 24, 241, 242, 2);
var sb = new ValueStringBuilder(stackalloc char[256]); var sb = new ValueStringBuilder(stackalloc char[256]);
@ -108,10 +119,10 @@ public class ArenaGump : Gump
var color = ar.Players.Count > 0 ? 0xCCFFCC : 0xCCCCCC; var color = ar.Players.Count > 0 ? 0xCCFFCC : 0xCCCCCC;
AddRadio(x + 3, y + 1, 9727, 9730, false, i); builder.AddRadio(x + 3, y + 1, 9727, 9730, false, i);
x += 35; x += 35;
AddBorderedText(x + 5, y + 5, 115 - 5, ar.Name ?? "(no name)", color, 0); AddBorderedText(ref builder, x + 5, y + 5, 115 - 5, ar.Name ?? "(no name)", color);
x += 115; x += 115;
sb.Reset(); sb.Reset();
@ -171,16 +182,16 @@ public class ArenaGump : Gump
sb.Append("Empty"); sb.Append("Empty");
} }
AddBorderedText(x + 5, y + 5, 325 - 5, sb.ToString(), color, 0); AddBorderedText(ref builder, x + 5, y + 5, 325 - 5, sb.ToString(), color);
x += 325; x += 325;
AddBorderedText(x, y + 5, 40, Html.Center($"{ar.Spectators}"), color, 0); AddBorderedText(ref builder, x, y + 5, 40, Html.Center($"{ar.Spectators}"), color);
} }
sb.Dispose(); sb.Dispose();
} }
private void Append(ref ValueStringBuilder sb, LadderEntry le) private static void Append(ref ValueStringBuilder sb, LadderEntry le)
{ {
if (le == null) if (le == null)
{ {
@ -211,72 +222,63 @@ public class ArenaGump : Gump
var opt = switches[0]; var opt = switches[0];
if (opt < 0 || opt >= m_Arenas.Count) if (opt < 0 || opt >= _arenas.Count)
{ {
return; return;
} }
var arena = m_Arenas[opt]; var arena = _arenas[opt];
var from = sender.Mobile;
if (!m_From.InRange(m_Gate.GetWorldLocation(), 1) || m_From.Map != m_Gate.Map) if (!from.InRange(_gate.GetWorldLocation(), 1) || from.Map != _gate.Map)
{ {
m_From.SendLocalizedMessage(1019002); // You are too far away to use the gate. from.SendLocalizedMessage(1019002); // You are too far away to use the gate.
} }
else if (DuelContext.CheckCombat(m_From)) else if (DuelContext.CheckCombat(from))
{ {
m_From.SendMessage( from.SendMessage(
0x22, 0x22,
"You have recently been in combat with another player and cannot use this moongate." "You have recently been in combat with another player and cannot use this moongate."
); );
} }
else if (m_From.Spell != null) else if (from.Spell != null)
{ {
m_From.SendLocalizedMessage(1049616); // You are too busy to do that at the moment. from.SendLocalizedMessage(1049616); // You are too busy to do that at the moment.
} }
else if (m_From.Map == arena.Facet && arena.Zone.Contains(m_From.Location)) else if (from.Map == arena.Facet && arena.Zone.Contains(from.Location))
{ {
m_From.SendLocalizedMessage(1019003); // You are already there. from.SendLocalizedMessage(1019003); // You are already there.
} }
else else
{ {
BaseCreature.TeleportPets(m_From, arena.GateIn, arena.Facet); BaseCreature.TeleportPets(from, arena.GateIn, arena.Facet);
m_From.Combatant = null; from.Combatant = null;
m_From.Warmode = false; from.Warmode = false;
m_From.Hidden = true; from.Hidden = true;
m_From.MoveToWorld(arena.GateIn, arena.Facet); from.MoveToWorld(arena.GateIn, arena.Facet);
Effects.PlaySound(arena.GateIn, arena.Facet, 0x1FE); Effects.PlaySound(arena.GateIn, arena.Facet, 0x1FE);
} }
} }
private void AddBorderedText(int x, int y, int width, string text, int color, int borderColor) private static void AddBorderedText(ref DynamicGumpBuilder builder, int x, int y, int width, string text, int color) =>
{ AddColoredText(ref builder, x, y, width, text, color);
/*AddColoredText( x - 1, y, width, text, borderColor );
AddColoredText( x + 1, y, width, text, borderColor );
AddColoredText( x, y - 1, width, text, borderColor );
AddColoredText( x, y + 1, width, text, borderColor );*/
/*AddColoredText( x - 1, y - 1, width, text, borderColor );
AddColoredText( x + 1, y + 1, width, text, borderColor );*/
AddColoredText(x, y, width, text, color);
}
private void AddColoredText(int x, int y, int width, string text, int color) private static void AddColoredText(ref DynamicGumpBuilder builder, int x, int y, int width, string text, int color) =>
{ builder.AddHtml(x, y, width, 20, color == 0 ? text : text.Color(color));
AddHtml(x, y, width, 20, color == 0 ? text : text.Color(color));
}
private void AddColumnHeader(int width, string name) private void AddColumnHeader(ref DynamicGumpBuilder builder, int width, string name)
{ {
AddBackground(m_ColumnX, 12, width, 20, 0x242C); builder.AddBackground(_columnX, 12, width, 20, 0x242C);
AddImageTiled(m_ColumnX + 2, 14, width - 4, 16, 0x2430); builder.AddImageTiled(_columnX + 2, 14, width - 4, 16, 0x2430);
if (name != null) if (name != null)
{ {
AddBorderedText(m_ColumnX, 13, width, name.Center(), 0xFFFFFF, 0); AddBorderedText(ref builder, _columnX, 13, width, name.Center(), 0xFFFFFF);
} }
m_ColumnX += width; _columnX += width;
} }
} }

View file

@ -1,41 +1,57 @@
using Server.Gumps; using Server.Gumps;
namespace Server.Engines.ConPVP namespace Server.Engines.ConPVP;
{
public class BeginGump : Gump public class BeginGump : StaticGump<BeginGump>
{ {
private const int LabelColor32 = 0xFFFFFF; private const int LabelColor32 = 0xFFFFFF;
private const int BlackColor32 = 0x000008; private const int BlackColor32 = 0x000008;
public BeginGump(int count) : base(50, 50) public override bool Singleton => true;
private BeginGump() : base(50, 50)
{ {
AddPage(0); }
public static void DisplayTo(Mobile from, int count)
{
if (from?.NetState == null)
{
return;
}
from.SendGump(new BeginGump());
}
protected override void BuildLayout(ref StaticGumpBuilder builder)
{
builder.AddPage();
const int offset = 50; const int offset = 50;
AddBackground(1, 1, 398, 202 - offset, 3600); builder.AddBackground(1, 1, 398, 202 - offset, 3600);
AddImageTiled(16, 15, 369, 173 - offset, 3604); builder.AddImageTiled(16, 15, 369, 173 - offset, 3604);
AddAlphaRegion(16, 15, 369, 173 - offset); builder.AddAlphaRegion(16, 15, 369, 173 - offset);
AddImage(215, -43, 0xEE40); builder.AddImage(215, -43, 0xEE40);
var duelCountdownBlack = "Duel Countdown".Center(BlackColor32); var duelCountdownBlack = "Duel Countdown".Center(BlackColor32);
AddHtml(22 - 1, 22, 294, 20, duelCountdownBlack); builder.AddHtml(22 - 1, 22, 294, 20, duelCountdownBlack);
AddHtml(22 + 1, 22, 294, 20, duelCountdownBlack); builder.AddHtml(22 + 1, 22, 294, 20, duelCountdownBlack);
AddHtml(22, 22 - 1, 294, 20, duelCountdownBlack); builder.AddHtml(22, 22 - 1, 294, 20, duelCountdownBlack);
AddHtml(22, 22 + 1, 294, 20, duelCountdownBlack); builder.AddHtml(22, 22 + 1, 294, 20, duelCountdownBlack);
AddHtml(22, 22, 294, 20, "Duel Countdown".Center(LabelColor32)); builder.AddHtml(22, 22, 294, 20, "Duel Countdown".Center(LabelColor32));
var beginMessageBlack = var beginMessageBlack =
"The arranged duel is about to begin. During this countdown period you may not cast spells and you may not move. This message will close automatically when the period ends." "The arranged duel is about to begin. During this countdown period you may not cast spells and you may not move. This message will close automatically when the period ends."
.Color(BlackColor32); .Color(BlackColor32);
AddHtml(22 - 1, 50, 294, 80, beginMessageBlack); builder.AddHtml(22 - 1, 50, 294, 80, beginMessageBlack);
AddHtml(22 + 1, 50, 294, 80, beginMessageBlack); builder.AddHtml(22 + 1, 50, 294, 80, beginMessageBlack);
AddHtml(22, 50 - 1, 294, 80, beginMessageBlack); builder.AddHtml(22, 50 - 1, 294, 80, beginMessageBlack);
AddHtml(22, 50 + 1, 294, 80, beginMessageBlack); builder.AddHtml(22, 50 + 1, 294, 80, beginMessageBlack);
AddHtml( builder.AddHtml(
22, 22,
50, 50,
294, 294,
@ -44,7 +60,6 @@ namespace Server.Engines.ConPVP
.Color(0xFFCC66) .Color(0xFFCC66)
); );
AddButton(314 - 50, 157 - offset, 247, 248, 1); builder.AddButton(314 - 50, 157 - offset, 247, 248, 1);
}
} }
} }

View file

@ -8,33 +8,45 @@ using Server.Network;
using Server.Targeting; using Server.Targeting;
using Server.Text; using Server.Text;
namespace Server.Engines.ConPVP namespace Server.Engines.ConPVP;
{
public class ConfirmSignupGump : Gump public class ConfirmSignupGump : DynamicGump
{ {
private const int BlackColor32 = 0x000008; private const int BlackColor32 = 0x000008;
private const int LabelColor32 = 0xFFFFFF; private const int LabelColor32 = 0xFFFFFF;
private readonly Mobile m_From; private readonly List<Mobile> _players;
private readonly List<Mobile> m_Players; private readonly Mobile _registrar;
private readonly Mobile m_Registrar; private readonly Tournament _tournament;
private readonly Tournament m_Tournament;
public override bool Singleton => true; public override bool Singleton => true;
public ConfirmSignupGump(Mobile from, Mobile registrar, Tournament tourney, List<Mobile> players) : base(50, 50) private ConfirmSignupGump(Mobile registrar, Tournament tourney, List<Mobile> players) : base(50, 50)
{ {
m_From = from; _registrar = registrar;
m_Registrar = registrar; _tournament = tourney;
m_Tournament = tourney; _players = players;
m_Players = players; }
var gumps = m_From.GetGumps(); public static void DisplayTo(Mobile from, Mobile registrar, Tournament tourney, List<Mobile> players)
{
if (from?.NetState == null || tourney == null || players == null)
{
return;
}
var gumps = from.GetGumps();
gumps.Close<AcceptTeamGump>(); gumps.Close<AcceptTeamGump>();
gumps.Close<AcceptDuelGump>(); gumps.Close<AcceptDuelGump>();
gumps.Close<DuelContextGump>(); gumps.Close<DuelContextGump>();
var ruleset = tourney.Ruleset; from.SendGump(new ConfirmSignupGump(registrar, tourney, players));
}
protected override void BuildLayout(ref DynamicGumpBuilder builder)
{
builder.SetNoClose();
var ruleset = _tournament.Ruleset;
var basedef = ruleset.Base; var basedef = ruleset.Base;
var height = 185 + 60 + 12; var height = 185 + 60 + 12;
@ -73,65 +85,61 @@ namespace Server.Engines.ConPVP
height += 10 + 22 + 25 + 25; height += 10 + 22 + 25 + 25;
if (tourney.PlayersPerParticipant > 1) if (_tournament.PlayersPerParticipant > 1)
{ {
height += 36 + tourney.PlayersPerParticipant * 20; height += 36 + _tournament.PlayersPerParticipant * 20;
} }
Closable = false; builder.AddPage();
AddPage(0); builder.AddBackground(1, 1, 398, height, 3600);
// AddBackground( 0, 0, 400, 220, 9150 ); builder.AddImageTiled(16, 15, 369, height - 29, 3604);
AddBackground(1, 1, 398, height, 3600); builder.AddAlphaRegion(16, 15, 369, height - 29);
// AddBackground( 16, 15, 369, 189, 9100 );
AddImageTiled(16, 15, 369, height - 29, 3604); builder.AddImage(215, -43, 0xEE40);
AddAlphaRegion(16, 15, 369, height - 29);
AddImage(215, -43, 0xEE40);
// AddImage( 330, 141, 0x8BA );
using var sb = new ValueStringBuilder(stackalloc char[64]); using var sb = new ValueStringBuilder(stackalloc char[64]);
if (tourney.TourneyType == TourneyType.FreeForAll) if (_tournament.TourneyType == TourneyType.FreeForAll)
{ {
sb.Append("FFA"); sb.Append("FFA");
} }
else if (tourney.TourneyType == TourneyType.RandomTeam) else if (_tournament.TourneyType == TourneyType.RandomTeam)
{ {
sb.Append($"{tourney.ParticipantsPerMatch}-Team"); sb.Append($"{_tournament.ParticipantsPerMatch}-Team");
} }
else if (tourney.TourneyType == TourneyType.Faction) else if (_tournament.TourneyType == TourneyType.Faction)
{ {
sb.Append($"{tourney.ParticipantsPerMatch}-Team Faction"); sb.Append($"{_tournament.ParticipantsPerMatch}-Team Faction");
} }
else if (tourney.TourneyType == TourneyType.RedVsBlue) else if (_tournament.TourneyType == TourneyType.RedVsBlue)
{ {
sb.Append("Red v Blue"); sb.Append("Red v Blue");
} }
else else
{ {
for (var i = 0; i < tourney.ParticipantsPerMatch; ++i) for (var i = 0; i < _tournament.ParticipantsPerMatch; ++i)
{ {
if (sb.Length > 0) if (sb.Length > 0)
{ {
sb.Append('v'); sb.Append('v');
} }
sb.Append(tourney.PlayersPerParticipant); sb.Append(_tournament.PlayersPerParticipant);
} }
} }
if (tourney.EventController != null) if (_tournament.EventController != null)
{ {
sb.Append($" {tourney.EventController.Title}"); sb.Append($" {_tournament.EventController.Title}");
} }
sb.Append(" Tournament Signup"); sb.Append(" Tournament Signup");
AddBorderedText(22, 22, 294, 20, sb.AsSpan().Center(), LabelColor32, BlackColor32); AddBorderedText(ref builder, 22, 22, 294, 20, sb.AsSpan().Center(), LabelColor32, BlackColor32);
AddBorderedText( AddBorderedText(
ref builder,
22, 22,
50, 50,
294, 294,
@ -141,12 +149,12 @@ namespace Server.Engines.ConPVP
BlackColor32 BlackColor32
); );
AddImageTiled(32, 88, 264, 1, 9107); builder.AddImageTiled(32, 88, 264, 1, 9107);
AddImageTiled(42, 90, 264, 1, 9157); builder.AddImageTiled(42, 90, 264, 1, 9157);
var y = 100; var y = 100;
var groupText = tourney.GroupType switch var groupText = _tournament.GroupType switch
{ {
GroupingType.HighVsLow => "High vs Low", GroupingType.HighVsLow => "High vs Low",
GroupingType.Nearest => "Closest opponent", GroupingType.Nearest => "Closest opponent",
@ -154,56 +162,56 @@ namespace Server.Engines.ConPVP
_ => null _ => null
}; };
AddBorderedText(35, y, 190, 20, $"Grouping: {groupText}", LabelColor32, BlackColor32); AddBorderedText(ref builder, 35, y, 190, 20, $"Grouping: {groupText}", LabelColor32, BlackColor32);
y += 20; y += 20;
var tieText = tourney.TieType switch var tieText = _tournament.TieType switch
{ {
TieType.Random => "Random", TieType.Random => "Random",
TieType.Highest => "Highest advances", TieType.Highest => "Highest advances",
TieType.Lowest => "Lowest advances", TieType.Lowest => "Lowest advances",
TieType.FullAdvancement => tourney.ParticipantsPerMatch == 2 ? "Both advance" : "Everyone advances", TieType.FullAdvancement => _tournament.ParticipantsPerMatch == 2 ? "Both advance" : "Everyone advances",
TieType.FullElimination => tourney.ParticipantsPerMatch == 2 ? "Both eliminated" : "Everyone eliminated", TieType.FullElimination => _tournament.ParticipantsPerMatch == 2 ? "Both eliminated" : "Everyone eliminated",
_ => null _ => null
}; };
AddBorderedText(35, y, 190, 20, $"Tiebreaker: {tieText}", LabelColor32, BlackColor32); AddBorderedText(ref builder, 35, y, 190, 20, $"Tiebreaker: {tieText}", LabelColor32, BlackColor32);
y += 20; y += 20;
string sdText; string sdText;
if (tourney.SuddenDeath > TimeSpan.Zero) if (_tournament.SuddenDeath > TimeSpan.Zero)
{ {
sdText = tourney.SuddenDeathRounds > 0 ? sdText = _tournament.SuddenDeathRounds > 0 ?
$"Sudden Death: {(int)tourney.SuddenDeath.TotalMinutes}:{tourney.SuddenDeath.Seconds:D2} (first {tourney.SuddenDeathRounds} rounds)" : $"Sudden Death: {(int)_tournament.SuddenDeath.TotalMinutes}:{_tournament.SuddenDeath.Seconds:D2} (first {_tournament.SuddenDeathRounds} rounds)" :
$"Sudden Death: {(int)tourney.SuddenDeath.TotalMinutes}:{tourney.SuddenDeath.Seconds:D2} (all rounds)"; $"Sudden Death: {(int)_tournament.SuddenDeath.TotalMinutes}:{_tournament.SuddenDeath.Seconds:D2} (all rounds)";
} }
else else
{ {
sdText = "Sudden Death: Off"; sdText = "Sudden Death: Off";
} }
AddBorderedText(35, y, 240, 20, sdText, LabelColor32, BlackColor32); AddBorderedText(ref builder, 35, y, 240, 20, sdText, LabelColor32, BlackColor32);
y += 20; y += 20;
y += 6; y += 6;
AddImageTiled(32, y - 1, 264, 1, 9107); builder.AddImageTiled(32, y - 1, 264, 1, 9107);
AddImageTiled(42, y + 1, 264, 1, 9157); builder.AddImageTiled(42, y + 1, 264, 1, 9157);
y += 6; y += 6;
AddBorderedText(35, y, 190, 20, $"Ruleset: {basedef.Title}", LabelColor32, BlackColor32); AddBorderedText(ref builder, 35, y, 190, 20, $"Ruleset: {basedef.Title}", LabelColor32, BlackColor32);
y += 20; y += 20;
for (var i = 0; i < ruleset.Flavors.Count; ++i, y += 18) for (var i = 0; i < ruleset.Flavors.Count; ++i, y += 18)
{ {
AddBorderedText(35, y, 190, 20, $" + {ruleset.Flavors[i].Title}", LabelColor32, BlackColor32); AddBorderedText(ref builder, 35, y, 190, 20, $" + {ruleset.Flavors[i].Title}", LabelColor32, BlackColor32);
} }
y += 4; y += 4;
if (changes > 0) if (changes > 0)
{ {
AddBorderedText(35, y, 190, 20, "Modifications:", LabelColor32, BlackColor32); AddBorderedText(ref builder, 35, y, 190, 20, "Modifications:", LabelColor32, BlackColor32);
y += 20; y += 20;
for (var i = 0; i < opts.Length; ++i) for (var i = 0; i < opts.Length; ++i)
@ -214,8 +222,8 @@ namespace Server.Engines.ConPVP
if (name != null) // sanity if (name != null) // sanity
{ {
AddImage(35, y, opts[i] ? 0xD3 : 0xD2); builder.AddImage(35, y, opts[i] ? 0xD3 : 0xD2);
AddBorderedText(60, y, 165, 22, name, LabelColor32, BlackColor32); AddBorderedText(ref builder, 60, y, 165, 22, name, LabelColor32, BlackColor32);
} }
y += 22; y += 22;
@ -224,102 +232,120 @@ namespace Server.Engines.ConPVP
} }
else else
{ {
AddBorderedText(35, y, 190, 20, "Modifications: None", LabelColor32, BlackColor32); AddBorderedText(ref builder, 35, y, 190, 20, "Modifications: None", LabelColor32, BlackColor32);
y += 20; y += 20;
} }
if (tourney.PlayersPerParticipant > 1) if (_tournament.PlayersPerParticipant > 1)
{ {
y += 8; y += 8;
AddImageTiled(32, y - 1, 264, 1, 9107); builder.AddImageTiled(32, y - 1, 264, 1, 9107);
AddImageTiled(42, y + 1, 264, 1, 9157); builder.AddImageTiled(42, y + 1, 264, 1, 9157);
y += 8; y += 8;
AddBorderedText(35, y, 190, 20, "Your Team", LabelColor32, BlackColor32); AddBorderedText(ref builder, 35, y, 190, 20, "Your Team", LabelColor32, BlackColor32);
y += 20; y += 20;
for (var i = 0; i < players.Count; ++i, y += 20) for (var i = 0; i < _players.Count; ++i, y += 20)
{ {
if (i == 0) if (i == 0)
{ {
AddImage(35, y, 0xD2); builder.AddImage(35, y, 0xD2);
} }
else else
{ {
AddGoldenButton(35, y, 1 + i); AddGoldenButton(ref builder, 35, y, 1 + i);
} }
AddBorderedText(60, y, 200, 20, players[i].Name, LabelColor32, BlackColor32); AddBorderedText(ref builder, 60, y, 200, 20, _players[i].Name, LabelColor32, BlackColor32);
} }
for (var i = players.Count; i < tourney.PlayersPerParticipant; ++i, y += 20) for (var i = _players.Count; i < _tournament.PlayersPerParticipant; ++i, y += 20)
{ {
if (i == 0) if (i == 0)
{ {
AddImage(35, y, 0xD2); builder.AddImage(35, y, 0xD2);
} }
else else
{ {
AddGoldenButton(35, y, 1 + i); AddGoldenButton(ref builder, 35, y, 1 + i);
} }
AddBorderedText(60, y, 200, 20, "(Empty)", LabelColor32, BlackColor32); AddBorderedText(ref builder, 60, y, 200, 20, "(Empty)", LabelColor32, BlackColor32);
} }
} }
y += 8; y += 8;
AddImageTiled(32, y - 1, 264, 1, 9107); builder.AddImageTiled(32, y - 1, 264, 1, 9107);
AddImageTiled(42, y + 1, 264, 1, 9157); builder.AddImageTiled(42, y + 1, 264, 1, 9157);
y += 8; y += 8;
AddRadio(24, y, 9727, 9730, true, 1); builder.AddRadio(24, y, 9727, 9730, true, 1);
AddBorderedText(60, y + 5, 250, 20, "Yes, I wish to join the tournament.", LabelColor32, BlackColor32); AddBorderedText(ref builder, 60, y + 5, 250, 20, "Yes, I wish to join the tournament.", LabelColor32, BlackColor32);
y += 35; y += 35;
AddRadio(24, y, 9727, 9730, false, 2); builder.AddRadio(24, y, 9727, 9730, false, 2);
AddBorderedText(60, y + 5, 250, 20, "No, I do not wish to join.", LabelColor32, BlackColor32); AddBorderedText(ref builder, 60, y + 5, 250, 20, "No, I do not wish to join.", LabelColor32, BlackColor32);
y += 35; y += 35;
y -= 3; y -= 3;
AddButton(314, y, 247, 248, 1); builder.AddButton(314, y, 247, 248, 1);
} }
private void AddBorderedText(int x, int y, int width, int height, string text, int color, int borderColor) private static void AddBorderedText(ref DynamicGumpBuilder builder, int x, int y, int width, int height, string text, int color, int borderColor)
{ {
AddColoredText(x - 1, y - 1, width, height, text, borderColor); AddColoredText(ref builder, x - 1, y - 1, width, height, text, borderColor);
AddColoredText(x - 1, y + 1, width, height, text, borderColor); AddColoredText(ref builder, x - 1, y + 1, width, height, text, borderColor);
AddColoredText(x + 1, y - 1, width, height, text, borderColor); AddColoredText(ref builder, x + 1, y - 1, width, height, text, borderColor);
AddColoredText(x + 1, y + 1, width, height, text, borderColor); AddColoredText(ref builder, x + 1, y + 1, width, height, text, borderColor);
AddColoredText(x, y, width, height, text, color); AddColoredText(ref builder, x, y, width, height, text, color);
} }
private void AddColoredText(int x, int y, int width, int height, string text, int color) private static void AddColoredText(ref DynamicGumpBuilder builder, int x, int y, int width, int height, string text, int color)
{ {
AddHtml(x, y, width, height, color == 0 ? text : text.Color(color)); builder.AddHtml(x, y, width, height, color == 0 ? text : text.Color(color));
} }
public void AddGoldenButton(int x, int y, int bid) private static void AddGoldenButton(ref DynamicGumpBuilder builder, int x, int y, int bid)
{ {
AddButton(x, y, 0xD2, 0xD2, bid); builder.AddButton(x, y, 0xD2, 0xD2, bid);
AddButton(x + 3, y + 3, 0xD8, 0xD8, bid); builder.AddButton(x + 3, y + 3, 0xD8, 0xD8, bid);
} }
public override void OnResponse(NetState sender, in RelayInfo info) public override void OnResponse(NetState sender, in RelayInfo info)
{ {
if (info.ButtonID == 1 && info.IsSwitched(1)) var from = sender.Mobile;
{
var tourney = m_Tournament;
var from = m_From;
switch (tourney.Stage) if (info.ButtonID != 1 || !info.IsSwitched(1))
{
if (info.ButtonID > 1)
{
var index = info.ButtonID - 1;
if (index > 0 && index < _players.Count)
{
_players.RemoveAt(index);
from.SendGump(this); // refresh-via-this
}
else if (_players.Count < _tournament.PlayersPerParticipant)
{
from.BeginTarget(12, false, TargetFlags.None, AddPlayer_OnTarget);
from.SendGump(this); // refresh-via-this
}
}
return;
}
switch (_tournament.Stage)
{ {
case TournamentStage.Fighting: case TournamentStage.Fighting:
{ {
if (m_Registrar != null) if (_registrar != null)
{ {
if (m_Tournament.HasParticipant(from)) if (_tournament.HasParticipant(from))
{ {
m_Registrar.PrivateOverheadMessage( _registrar.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x35, 0x35,
false, false,
@ -329,7 +355,7 @@ namespace Server.Engines.ConPVP
} }
else else
{ {
m_Registrar.PrivateOverheadMessage( _registrar.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x22, 0x22,
false, false,
@ -343,7 +369,7 @@ namespace Server.Engines.ConPVP
} }
case TournamentStage.Inactive: case TournamentStage.Inactive:
{ {
m_Registrar?.PrivateOverheadMessage( _registrar?.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x35, 0x35,
false, false,
@ -355,9 +381,9 @@ namespace Server.Engines.ConPVP
} }
case TournamentStage.Signup: case TournamentStage.Signup:
{ {
if (m_Players.Count != tourney.PlayersPerParticipant) if (_players.Count != _tournament.PlayersPerParticipant)
{ {
m_Registrar?.PrivateOverheadMessage( _registrar?.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x35, 0x35,
false, false,
@ -365,25 +391,25 @@ namespace Server.Engines.ConPVP
from.NetState from.NetState
); );
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); from.SendGump(this); // refresh-via-this
break; break;
} }
var ladder = Ladder.Instance; var ladder = Ladder.Instance;
for (var i = 0; i < m_Players.Count; ++i) for (var i = 0; i < _players.Count; ++i)
{ {
var mob = m_Players[i]; var mob = _players[i];
var entry = ladder?.Find(mob); var entry = ladder?.Find(mob);
if (entry != null && Ladder.GetLevel(entry.Experience) < tourney.LevelRequirement) if (entry != null && Ladder.GetLevel(entry.Experience) < _tournament.LevelRequirement)
{ {
if (m_Registrar != null) if (_registrar != null)
{ {
if (mob == from) if (mob == from)
{ {
m_Registrar.PrivateOverheadMessage( _registrar.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x35, 0x35,
false, false,
@ -393,7 +419,7 @@ namespace Server.Engines.ConPVP
} }
else else
{ {
m_Registrar.PrivateOverheadMessage( _registrar.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x35, 0x35,
false, false,
@ -402,32 +428,24 @@ namespace Server.Engines.ConPVP
); );
} }
} }
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players));
return;
} }
else if (_tournament.IsFactionRestricted && Faction.Find(mob) == null)
if (tourney.IsFactionRestricted && Faction.Find(mob) == null)
{ {
m_Registrar?.PrivateOverheadMessage( _registrar?.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x35, 0x35,
false, false,
"Only those who have declared their faction allegiance may participate.", "Only those who have declared their faction allegiance may participate.",
from.NetState from.NetState
); );
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players));
return;
} }
else if (_tournament.HasParticipant(mob))
if (tourney.HasParticipant(mob))
{ {
if (m_Registrar != null) if (_registrar != null)
{ {
if (mob == from) if (mob == from)
{ {
m_Registrar.PrivateOverheadMessage( _registrar.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x35, 0x35,
false, false,
@ -437,7 +455,7 @@ namespace Server.Engines.ConPVP
} }
else else
{ {
m_Registrar.PrivateOverheadMessage( _registrar.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x35, 0x35,
false, false,
@ -446,16 +464,12 @@ namespace Server.Engines.ConPVP
); );
} }
} }
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players));
return;
} }
else if (mob is PlayerMobile mobile && mobile.DuelContext != null)
if (mob is PlayerMobile mobile && mobile.DuelContext != null)
{ {
if (mob == from) if (mob == from)
{ {
m_Registrar?.PrivateOverheadMessage( _registrar?.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x35, 0x35,
false, false,
@ -465,7 +479,7 @@ namespace Server.Engines.ConPVP
} }
else else
{ {
m_Registrar?.PrivateOverheadMessage( _registrar?.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x35, 0x35,
false, false,
@ -473,48 +487,35 @@ namespace Server.Engines.ConPVP
from.NetState from.NetState
); );
} }
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players));
return;
}
}
if (m_Registrar != null)
{
string fmt;
if (tourney.PlayersPerParticipant == 1)
{
fmt =
"As you say m'{0}. I've written your name to the bracket. The tournament will begin {1}.";
}
else if (tourney.PlayersPerParticipant == 2)
{
fmt =
"As you wish m'{0}. The tournament will begin {1}, but first you must name your partner.";
} }
else else
{ {
fmt = continue;
"As you wish m'{0}. The tournament will begin {1}, but first you must name your team.";
} }
string timeUntil; from.SendGump(this); // refresh-via-this
return;
}
if (_registrar != null)
{
string fmt = _tournament.PlayersPerParticipant switch
{
1 => "As you say m'{0}. I've written your name to the bracket. The tournament will begin {1}.",
2 => "As you wish m'{0}. The tournament will begin {1}, but first you must name your partner.",
_ => "As you wish m'{0}. The tournament will begin {1}, but first you must name your team."
};
var minutesUntil = (int)Math.Round( var minutesUntil = (int)Math.Round(
(tourney.SignupStart + tourney.SignupPeriod - Core.Now) (_tournament.SignupStart + _tournament.SignupPeriod - Core.Now)
.TotalMinutes .TotalMinutes
); );
if (minutesUntil == 0) var timeUntil = minutesUntil == 0
{ ? "momentarily"
timeUntil = "momentarily"; : $"in {minutesUntil} minute{(minutesUntil == 1 ? "" : "s")}";
}
else
{
timeUntil = $"in {minutesUntil} minute{(minutesUntil == 1 ? "" : "s")}";
}
m_Registrar.PrivateOverheadMessage( _registrar.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x35, 0x35,
false, false,
@ -525,38 +526,20 @@ namespace Server.Engines.ConPVP
var part = new TourneyParticipant(from); var part = new TourneyParticipant(from);
part.Players.Clear(); part.Players.Clear();
part.Players.AddRange(m_Players); part.Players.AddRange(_players);
tourney.Participants.Add(part); _tournament.Participants.Add(part);
break; break;
} }
} }
} }
else if (info.ButtonID > 1)
{
var index = info.ButtonID - 1;
if (index > 0 && index < m_Players.Count)
{
m_Players.RemoveAt(index);
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players));
}
else if (m_Players.Count < m_Tournament.PlayersPerParticipant)
{
m_From.BeginTarget(12, false, TargetFlags.None, AddPlayer_OnTarget);
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players));
}
}
}
private void AddPlayer_OnTarget(Mobile from, object obj) private void AddPlayer_OnTarget(Mobile from, object obj)
{ {
if (obj is not Mobile mob || mob == from) if (obj is not Mobile mob || mob == from)
{ {
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); _registrar?.PrivateOverheadMessage(
m_Registrar?.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x22, 0x22,
false, false,
@ -566,8 +549,6 @@ namespace Server.Engines.ConPVP
} }
else if (!mob.Player) else if (!mob.Player)
{ {
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players));
if (mob.Body.IsHuman) if (mob.Body.IsHuman)
{ {
mob.SayTo(from, 1005443); // Nay, I would rather stay here and watch a nail rust. mob.SayTo(from, 1005443); // Nay, I would rather stay here and watch a nail rust.
@ -579,9 +560,7 @@ namespace Server.Engines.ConPVP
} }
else if (AcceptDuelGump.IsIgnored(mob, from) || mob.Blessed) else if (AcceptDuelGump.IsIgnored(mob, from) || mob.Blessed)
{ {
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); _registrar?.PrivateOverheadMessage(
m_Registrar?.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x22, 0x22,
false, false,
@ -589,18 +568,13 @@ namespace Server.Engines.ConPVP
from.NetState from.NetState
); );
} }
else else if (mob is not PlayerMobile pm)
{
if (mob is not PlayerMobile pm)
{ {
return; return;
} }
else if (pm.DuelContext != null)
if (pm.DuelContext != null)
{ {
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); _registrar?.PrivateOverheadMessage(
m_Registrar?.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x22, 0x22,
false, false,
@ -610,9 +584,7 @@ namespace Server.Engines.ConPVP
} }
else if (mob.HasGump<AcceptTeamGump>()) else if (mob.HasGump<AcceptTeamGump>())
{ {
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); _registrar?.PrivateOverheadMessage(
m_Registrar?.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x22, 0x22,
false, false,
@ -622,9 +594,7 @@ namespace Server.Engines.ConPVP
} }
else if (mob.HasGump<ConfirmSignupGump>()) else if (mob.HasGump<ConfirmSignupGump>())
{ {
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); _registrar?.PrivateOverheadMessage(
m_Registrar?.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x22, 0x22,
false, false,
@ -632,11 +602,9 @@ namespace Server.Engines.ConPVP
from.NetState from.NetState
); );
} }
else if (m_Players.Contains(mob)) else if (_players.Contains(mob))
{ {
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); _registrar?.PrivateOverheadMessage(
m_Registrar?.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x22, 0x22,
false, false,
@ -644,11 +612,9 @@ namespace Server.Engines.ConPVP
from.NetState from.NetState
); );
} }
else if (m_Tournament.HasParticipant(mob)) else if (_tournament.HasParticipant(mob))
{ {
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); _registrar?.PrivateOverheadMessage(
m_Registrar?.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x22, 0x22,
false, false,
@ -656,11 +622,9 @@ namespace Server.Engines.ConPVP
from.NetState from.NetState
); );
} }
else if (m_Players.Count >= m_Tournament.PlayersPerParticipant) else if (_players.Count >= _tournament.PlayersPerParticipant)
{ {
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); _registrar?.PrivateOverheadMessage(
m_Registrar?.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x22, 0x22,
false, false,
@ -670,10 +634,9 @@ namespace Server.Engines.ConPVP
} }
else else
{ {
m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); AcceptTeamGump.DisplayTo(from, mob, _tournament, _registrar, _players);
mob.SendGump(new AcceptTeamGump(from, mob, m_Tournament, m_Registrar, m_Players));
m_Registrar?.PrivateOverheadMessage( _registrar?.PrivateOverheadMessage(
MessageType.Regular, MessageType.Regular,
0x59, 0x59,
false, false,
@ -681,7 +644,7 @@ namespace Server.Engines.ConPVP
from.NetState from.NetState
); );
} }
}
} from.SendGump(this); // refresh-via-this
} }
} }

View file

@ -1,23 +1,33 @@
using Server.Gumps; using Server.Gumps;
using Server.Network; using Server.Network;
namespace Server.Engines.ConPVP namespace Server.Engines.ConPVP;
{
public class DuelContextGump : Gump public class DuelContextGump : DynamicGump
{ {
public override bool Singleton => true; public override bool Singleton => true;
public DuelContextGump(Mobile from, DuelContext context) : base(50, 50) private DuelContextGump(DuelContext context) : base(50, 50) => Context = context;
public static void DisplayTo(Mobile from, DuelContext context)
{ {
From = from; if (from?.NetState == null || context == null)
Context = context; {
return;
}
var gumps = from.GetGumps(); var gumps = from.GetGumps();
gumps.Close<RulesetGump>(); gumps.Close<RulesetGump>();
gumps.Close<ParticipantGump>(); gumps.Close<ParticipantGump>();
var count = context.Participants.Count; from.SendGump(new DuelContextGump(context));
}
public DuelContext Context { get; }
protected override void BuildLayout(ref DynamicGumpBuilder builder)
{
var count = Context.Participants.Count;
if (count < 3) if (count < 3)
{ {
@ -26,31 +36,32 @@ namespace Server.Engines.ConPVP
var height = 35 + 10 + 22 + 30 + 22 + 22 + 2 + count * 22 + 2 + 30; var height = 35 + 10 + 22 + 30 + 22 + 22 + 2 + count * 22 + 2 + 30;
AddPage(0); builder.AddPage();
AddBackground(0, 0, 300, height, 9250); builder.AddBackground(0, 0, 300, height, 9250);
AddBackground(10, 10, 280, height - 20, 0xDAC); builder.AddBackground(10, 10, 280, height - 20, 0xDAC);
AddHtml(35, 25, 230, 20, Center("Duel Setup")); builder.AddHtml(35, 25, 230, 20, Center("Duel Setup"));
var x = 35; var x = 35;
var y = 47; var y = 47;
AddGoldenButtonLabeled(x, y, 1, "Rules"); AddGoldenButtonLabeled(ref builder, x, y, 1, "Rules");
y += 22; y += 22;
AddGoldenButtonLabeled(x, y, 2, "Start"); AddGoldenButtonLabeled(ref builder, x, y, 2, "Start");
y += 22; y += 22;
AddGoldenButtonLabeled(x, y, 3, "Add Participant"); AddGoldenButtonLabeled(ref builder, x, y, 3, "Add Participant");
y += 30; y += 30;
AddHtml(35, y, 230, 20, Center("Participants")); builder.AddHtml(35, y, 230, 20, Center("Participants"));
y += 22; y += 22;
for (var i = 0; i < context.Participants.Count; ++i) for (var i = 0; i < Context.Participants.Count; ++i)
{ {
var p = context.Participants[i]; var p = Context.Participants[i];
AddGoldenButtonLabeled( AddGoldenButtonLabeled(
ref builder,
x, x,
y, y,
4 + i, 4 + i,
@ -66,22 +77,18 @@ namespace Server.Engines.ConPVP
} }
} }
public Mobile From { get; } private static string Center(string text) => $"<CENTER>{text}</CENTER>";
public DuelContext Context { get; } private static void AddGoldenButton(ref DynamicGumpBuilder builder, int x, int y, int bid)
public string Center(string text) => $"<CENTER>{text}</CENTER>";
public void AddGoldenButton(int x, int y, int bid)
{ {
AddButton(x, y, 0xD2, 0xD2, bid); builder.AddButton(x, y, 0xD2, 0xD2, bid);
AddButton(x + 3, y + 3, 0xD8, 0xD8, bid); builder.AddButton(x + 3, y + 3, 0xD8, 0xD8, bid);
} }
public void AddGoldenButtonLabeled(int x, int y, int bid, string text) private static void AddGoldenButtonLabeled(ref DynamicGumpBuilder builder, int x, int y, int bid, string text)
{ {
AddGoldenButton(x, y, bid); AddGoldenButton(ref builder, x, y, bid);
AddHtml(x + 25, y, 200, 20, text); builder.AddHtml(x + 25, y, 200, 20, text);
} }
public override void OnResponse(NetState sender, in RelayInfo info) public override void OnResponse(NetState sender, in RelayInfo info)
@ -91,6 +98,7 @@ namespace Server.Engines.ConPVP
return; return;
} }
var from = sender.Mobile;
var index = info.ButtonID; var index = info.ButtonID;
switch (index) switch (index)
@ -106,8 +114,7 @@ namespace Server.Engines.ConPVP
} }
case 1: // Rules case 1: // Rules
{ {
// m_From.SendGump( new RulesetGump( m_From, m_Context.Ruleset, m_Context.Ruleset.Layout, m_Context ) ); PickRulesetGump.DisplayTo(from, Context, Context.Ruleset);
From.SendGump(new PickRulesetGump(From, Context, Context.Ruleset));
break; break;
} }
case 2: // Start case 2: // Start
@ -116,14 +123,13 @@ namespace Server.Engines.ConPVP
{ {
Context.CloseAllGumps(); Context.CloseAllGumps();
Context.SendReadyUpGump(); Context.SendReadyUpGump();
// m_Context.SendReadyGump();
} }
else else
{ {
From.SendMessage( from.SendMessage(
"You cannot start the duel before all participating players have been assigned." "You cannot start the duel before all participating players have been assigned."
); );
From.SendGump(new DuelContextGump(From, Context)); from.SendGump(this); // refresh-via-this
} }
break; break;
@ -136,10 +142,10 @@ namespace Server.Engines.ConPVP
} }
else else
{ {
From.SendMessage("The number of participating parties may not be increased further."); from.SendMessage("The number of participating parties may not be increased further.");
} }
From.SendGump(new DuelContextGump(From, Context)); from.SendGump(this); // refresh-via-this
break; break;
} }
@ -149,7 +155,7 @@ namespace Server.Engines.ConPVP
if (index >= 0 && index < Context.Participants.Count) if (index >= 0 && index < Context.Participants.Count)
{ {
From.SendGump(new ParticipantGump(From, Context, Context.Participants[index])); ParticipantGump.DisplayTo(from, Context, Context.Participants[index]);
} }
break; break;
@ -157,4 +163,3 @@ namespace Server.Engines.ConPVP
} }
} }
} }
}

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using ModernUO.Serialization; using ModernUO.Serialization;
using Server.Collections;
using Server.Gumps; using Server.Gumps;
using Server.Network; using Server.Network;
@ -26,7 +27,7 @@ public partial class LadderItem : Item
if (ladder != null) if (ladder != null)
{ {
from.SendGump(new LadderGump(ladder), true); LadderGump.DisplayTo(from, ladder);
} }
} }
else else
@ -36,26 +37,42 @@ public partial class LadderItem : Item
} }
} }
public class LadderGump : Gump public class LadderGump : DynamicGump
{ {
private readonly Ladder m_Ladder; private readonly Ladder _ladder;
private readonly List<LadderEntry> m_List; private int _page;
private readonly int m_Page; private int _columnX;
private int m_ColumnX = 12;
public LadderGump(Ladder ladder, int page = 0) : base(50, 50) public override bool Singleton => true;
private LadderGump(Ladder ladder, int page) : base(50, 50)
{ {
m_Ladder = ladder; _ladder = ladder;
m_Page = page; _page = page;
}
AddPage(0); public static void DisplayTo(Mobile from, Ladder ladder, int page = 0)
{
if (from?.NetState == null || ladder == null)
{
return;
}
m_List = new List<LadderEntry>(ladder.Entries); from.SendGump(new LadderGump(ladder, page), true);
}
var lc = Math.Min(m_List.Count, 150); protected override void BuildLayout(ref DynamicGumpBuilder builder)
{
_columnX = 12;
var start = page * 15; builder.AddPage();
var list = _ladder.Entries;
var lc = Math.Min(list.Count, 150);
var start = _page * 15;
var end = start + 15; var end = start + 15;
if (end > lc) if (end > lc)
@ -67,66 +84,59 @@ public class LadderGump : Gump
var height = 12 + 20 + ct * 20 + 23 + 12; var height = 12 + 20 + ct * 20 + 23 + 12;
AddBackground(0, 0, 499, height, 0x2436); builder.AddBackground(0, 0, 499, height, 0x2436);
for (var i = start + 1; i < end; i += 2) for (var i = start + 1; i < end; i += 2)
{ {
AddImageTiled(12, 32 + (i - start) * 20, 475, 20, 0x2430); builder.AddImageTiled(12, 32 + (i - start) * 20, 475, 20, 0x2430);
} }
AddAlphaRegion(10, 10, 479, height - 20); builder.AddAlphaRegion(10, 10, 479, height - 20);
if (page > 0) if (_page > 0)
{ {
AddButton(446, height - 12 - 2 - 16, 0x15E3, 0x15E7, 1); builder.AddButton(446, height - 12 - 2 - 16, 0x15E3, 0x15E7, 1);
} }
else else
{ {
AddImage(446, height - 12 - 2 - 16, 0x2626); builder.AddImage(446, height - 12 - 2 - 16, 0x2626);
} }
if ((page + 1) * 15 < lc) if ((_page + 1) * 15 < lc)
{ {
AddButton(466, height - 12 - 2 - 16, 0x15E1, 0x15E5, 2); builder.AddButton(466, height - 12 - 2 - 16, 0x15E1, 0x15E5, 2);
} }
else else
{ {
AddImage(466, height - 12 - 2 - 16, 0x2622); builder.AddImage(466, height - 12 - 2 - 16, 0x2622);
} }
AddHtml( builder.AddHtml(
16, 16,
height - 12 - 2 - 18, height - 12 - 2 - 18,
400, 400,
20, 20,
Html.Color($"Top {lc} of {m_List.Count:N0} duelists, page {page + 1} of {(lc + 14) / 15}", 0xFFC000) Html.Color($"Top {lc} of {list.Count:N0} duelists, page {_page + 1} of {(lc + 14) / 15}", 0xFFC000)
); );
AddColumnHeader(75, "Rank"); AddColumnHeader(ref builder, 75, "Rank");
AddColumnHeader(115, "Level"); AddColumnHeader(ref builder, 115, "Level");
AddColumnHeader(50, "Guild"); AddColumnHeader(ref builder, 50, "Guild");
AddColumnHeader(115, "Name"); AddColumnHeader(ref builder, 115, "Name");
AddColumnHeader(60, "Wins"); AddColumnHeader(ref builder, 60, "Wins");
AddColumnHeader(60, "Losses"); AddColumnHeader(ref builder, 60, "Losses");
for (var i = start; i < end && i < lc; ++i) for (var i = start; i < end && i < lc; ++i)
{ {
var entry = m_List[i]; var entry = list[i];
var y = 32 + (i - start) * 20; var y = 32 + (i - start) * 20;
var x = 12; var x = 12;
AddBorderedText(x, y, 75, Rank(i + 1).Center(), 0xFFFFFF, 0); AddBorderedText(ref builder, x, y, 75, Rank(i + 1).Center(), 0xFFFFFF);
x += 75; x += 75;
/*AddImage( 20, y + 5, 0x2616, 0x96C ); builder.AddImage(x + 3, y + 4, 0x805);
AddImage( 22, y + 5, 0x2616, 0x96C );
AddImage( 20, y + 7, 0x2616, 0x96C );
AddImage( 22, y + 7, 0x2616, 0x96C );
AddImage( 21, y + 6, 0x2616, 0x454 );*/
AddImage(x + 3, y + 4, 0x805);
var xp = entry.Experience; var xp = entry.Experience;
var level = Ladder.GetLevel(xp); var level = Ladder.GetLevel(xp);
@ -146,30 +156,26 @@ public class LadderGump : Gump
width = (109 * xpOffset + xpAdvance / 2) / (xpAdvance - 1); width = (109 * xpOffset + xpAdvance / 2) / (xpAdvance - 1);
} }
// AddImageTiled( 21, y + 6, width, 8, 0x2617 ); builder.AddImageTiled(x + 3, y + 4, width, 11, 0x806);
AddImageTiled(x + 3, y + 4, width, 11, 0x806); AddBorderedText(ref builder, x, y, 115, Html.Center($"{level}"), 0xFFFFFF);
AddBorderedText(x, y, 115, Html.Center($"{level}"), 0xFFFFFF, 0);
x += 115; x += 115;
var mob = entry.Mobile; var mob = entry.Mobile;
if (mob.Guild != null) if (mob.Guild != null)
{ {
AddBorderedText(x, y, 50, mob.Guild.Abbreviation.Center(), 0xFFFFFF, 0); AddBorderedText(ref builder, x, y, 50, mob.Guild.Abbreviation.Center(), 0xFFFFFF);
} }
x += 50; x += 50;
AddBorderedText(x + 5, y, 115 - 5, mob.Name, 0xFFFFFF, 0); AddBorderedText(ref builder, x + 5, y, 115 - 5, mob.Name, 0xFFFFFF);
x += 115; x += 115;
AddBorderedText(x, y, 60, Html.Center($"{entry.Wins}"), 0xFFFFFF, 0); AddBorderedText(ref builder, x, y, 60, Html.Center($"{entry.Wins}"), 0xFFFFFF);
x += 60; x += 60;
AddBorderedText(x, y, 60, Html.Center($"{entry.Losses}"), 0xFFFFFF, 0); AddBorderedText(ref builder, x, y, 60, Html.Center($"{entry.Losses}"), 0xFFFFFF);
x += 60;
// AddBorderedText( 292 + 15, y, 115 - 30, String.Format( "{0} <DIV ALIGN=CENTER>/</DIV> <DIV ALIGN=RIGHT>{1}</DIV>", entry.Wins, entry.Losses ), 0xFFC000, 0 );
} }
} }
@ -195,38 +201,30 @@ public class LadderGump : Gump
{ {
var from = sender.Mobile; var from = sender.Mobile;
if (info.ButtonID == 1 && m_Page > 0) if (info.ButtonID == 1 && _page > 0)
{ {
from.SendGump(new LadderGump(m_Ladder, m_Page - 1)); _page--;
} }
else if (info.ButtonID == 2 && (m_Page + 1) * 15 < Math.Min(m_List.Count, 150)) else if (info.ButtonID == 2 && (_page + 1) * 15 < Math.Min(_ladder.Entries.Count, 150))
{ {
from.SendGump(new LadderGump(m_Ladder, m_Page + 1)); _page++;
}
} }
private void AddBorderedText(int x, int y, int width, string text, int color, int borderColor) from.SendGump(this); // refresh-via-this
{
/*AddColoredText( x - 1, y, width, text, borderColor );
AddColoredText( x + 1, y, width, text, borderColor );
AddColoredText( x, y - 1, width, text, borderColor );
AddColoredText( x, y + 1, width, text, borderColor );*/
/*AddColoredText( x - 1, y - 1, width, text, borderColor );
AddColoredText( x + 1, y + 1, width, text, borderColor );*/
AddColoredText(x, y, width, text, color);
} }
private void AddColoredText(int x, int y, int width, string text, int color) private static void AddBorderedText(ref DynamicGumpBuilder builder, int x, int y, int width, string text, int color) =>
{ AddColoredText(ref builder, x, y, width, text, color);
AddHtml(x, y, width, 20, color == 0 ? text : text.Color(color));
}
private void AddColumnHeader(int width, string name) private static void AddColoredText(ref DynamicGumpBuilder builder, int x, int y, int width, string text, int color) =>
{ builder.AddHtml(x, y, width, 20, color == 0 ? text : text.Color(color));
AddBackground(m_ColumnX, 12, width, 20, 0x242C);
AddImageTiled(m_ColumnX + 2, 14, width - 4, 16, 0x2430);
AddBorderedText(m_ColumnX, 13, width, name.Center(), 0xFFFFFF, 0);
m_ColumnX += width; private void AddColumnHeader(ref DynamicGumpBuilder builder, int width, string name)
{
builder.AddBackground(_columnX, 12, width, 20, 0x242C);
builder.AddImageTiled(_columnX + 2, 14, width - 4, 16, 0x2430);
AddBorderedText(ref builder, _columnX, 13, width, name.Center(), 0xFFFFFF);
_columnX += width;
} }
} }

View file

@ -3,84 +3,91 @@ using Server.Mobiles;
using Server.Network; using Server.Network;
using Server.Targeting; using Server.Targeting;
namespace Server.Engines.ConPVP namespace Server.Engines.ConPVP;
{
public class ParticipantGump : Gump public class ParticipantGump : DynamicGump
{ {
public override bool Singleton => true; public override bool Singleton => true;
public ParticipantGump(Mobile from, DuelContext context, Participant p) : base(50, 50) private ParticipantGump(DuelContext context, Participant p) : base(50, 50)
{ {
From = from;
Context = context; Context = context;
Participant = p; Participant = p;
}
public static void DisplayTo(Mobile from, DuelContext context, Participant p)
{
if (from?.NetState == null || context == null || p == null)
{
return;
}
var gumps = from.GetGumps(); var gumps = from.GetGumps();
gumps.Close<RulesetGump>(); gumps.Close<RulesetGump>();
gumps.Close<DuelContextGump>(); gumps.Close<DuelContextGump>();
var count = p.Players.Length; from.SendGump(new ParticipantGump(context, p));
}
public DuelContext Context { get; }
public Participant Participant { get; }
protected override void BuildLayout(ref DynamicGumpBuilder builder)
{
var count = Participant.Players.Length;
if (count < 4) if (count < 4)
{ {
count = 4; count = 4;
} }
AddPage(0); builder.AddPage();
var height = 35 + 10 + 22 + 22 + 30 + 22 + 2 + count * 22 + 2 + 30; var height = 35 + 10 + 22 + 22 + 30 + 22 + 2 + count * 22 + 2 + 30;
AddBackground(0, 0, 300, height, 9250); builder.AddBackground(0, 0, 300, height, 9250);
AddBackground(10, 10, 280, height - 20, 0xDAC); builder.AddBackground(10, 10, 280, height - 20, 0xDAC);
AddButton(240, 25, 0xFB1, 0xFB3, 3); builder.AddButton(240, 25, 0xFB1, 0xFB3, 3);
// AddButton( 223, 54, 0x265A, 0x265A, 4, ); builder.AddHtml(35, 25, 230, 20, Center("Participant Setup"));
AddHtml(35, 25, 230, 20, Center("Participant Setup"));
var x = 35; var x = 35;
var y = 47; var y = 47;
AddHtml(x, y, 200, 20, $"Team Size: {p.Players.Length}"); builder.AddHtml(x, y, 200, 20, $"Team Size: {Participant.Players.Length}");
y += 22; y += 22;
AddGoldenButtonLabeled(x + 20, y, 1, "Increase"); AddGoldenButtonLabeled(ref builder, x + 20, y, 1, "Increase");
y += 22; y += 22;
AddGoldenButtonLabeled(x + 20, y, 2, "Decrease"); AddGoldenButtonLabeled(ref builder, x + 20, y, 2, "Decrease");
y += 30; y += 30;
AddHtml(35, y, 230, 20, Center("Players")); builder.AddHtml(35, y, 230, 20, Center("Players"));
y += 22; y += 22;
for (var i = 0; i < p.Players.Length; ++i) for (var i = 0; i < Participant.Players.Length; ++i)
{ {
var pl = p.Players[i]; var pl = Participant.Players[i];
AddGoldenButtonLabeled(x, y, 5 + i, $"{1 + i}: {(pl == null ? "Empty" : pl.Mobile.Name)}"); AddGoldenButtonLabeled(ref builder, x, y, 5 + i, $"{1 + i}: {(pl == null ? "Empty" : pl.Mobile.Name)}");
y += 22; y += 22;
} }
} }
public Mobile From { get; } private static string Center(string text) => $"<CENTER>{text}</CENTER>";
public DuelContext Context { get; } private static void AddGoldenButton(ref DynamicGumpBuilder builder, int x, int y, int bid)
public Participant Participant { get; }
public string Center(string text) => $"<CENTER>{text}</CENTER>";
public void AddGoldenButton(int x, int y, int bid)
{ {
AddButton(x, y, 0xD2, 0xD2, bid); builder.AddButton(x, y, 0xD2, 0xD2, bid);
AddButton(x + 3, y + 3, 0xD8, 0xD8, bid); builder.AddButton(x + 3, y + 3, 0xD8, 0xD8, bid);
} }
public void AddGoldenButtonLabeled(int x, int y, int bid, string text) private static void AddGoldenButtonLabeled(ref DynamicGumpBuilder builder, int x, int y, int bid, string text)
{ {
AddGoldenButton(x, y, bid); AddGoldenButton(ref builder, x, y, bid);
AddHtml(x + 25, y, 200, 20, text); builder.AddHtml(x + 25, y, 200, 20, text);
} }
public override void OnResponse(NetState sender, in RelayInfo info) public override void OnResponse(NetState sender, in RelayInfo info)
@ -90,82 +97,53 @@ namespace Server.Engines.ConPVP
return; return;
} }
var from = sender.Mobile;
var bid = info.ButtonID; var bid = info.ButtonID;
if (bid == 0) switch (bid)
{ {
From.SendGump(new DuelContextGump(From, Context)); case 0:
{
DuelContextGump.DisplayTo(from, Context);
return;
} }
else if (bid == 1) case 1 when Participant.Count < 8:
{
if (Participant.Count < 8)
{ {
Participant.Resize(Participant.Count + 1); Participant.Resize(Participant.Count + 1);
break;
} }
else case 1:
{ {
From.SendMessage("You may not raise the team size any further."); from.SendMessage("You may not raise the team size any further.");
break;
} }
case 2 when Participant.Count > 1 && Participant.Count > Participant.FilledSlots:
From.SendGump(new ParticipantGump(From, Context, Participant));
}
else if (bid == 2)
{
if (Participant.Count > 1 && Participant.Count > Participant.FilledSlots)
{ {
Participant.Resize(Participant.Count - 1); Participant.Resize(Participant.Count - 1);
break;
} }
else case 2:
{ {
From.SendMessage("You may not lower the team size any further."); from.SendMessage("You may not lower the team size any further.");
break;
} }
case 3 when Participant.FilledSlots > 0:
From.SendGump(new ParticipantGump(From, Context, Participant)); {
from.SendMessage("There is at least one currently active player. You must remove them first.");
break;
} }
else if (bid == 3) case 3 when Context.Participants.Count > 2:
{ {
if (Participant.FilledSlots > 0)
{
From.SendMessage("There is at least one currently active player. You must remove them first.");
From.SendGump(new ParticipantGump(From, Context, Participant));
}
else if (Context.Participants.Count > 2)
{
/*Container cont = m_Participant.Stakes;
if (cont != null)
cont.Delete();*/
Context.Participants.Remove(Participant); Context.Participants.Remove(Participant);
From.SendGump(new DuelContextGump(From, Context)); DuelContextGump.DisplayTo(from, Context);
return;
} }
else case 3:
{ {
From.SendMessage("Duels must have at least two participating parties."); from.SendMessage("Duels must have at least two participating parties.");
From.SendGump(new ParticipantGump(From, Context, Participant)); break;
} }
} default:
/*else if (bid == 4)
{
m_From.SendGump( new ParticipantGump( m_From, m_Context, m_Participant ) );
Container cont = m_Participant.Stakes;
if (cont != null && !cont.Deleted)
{
cont.DisplayTo( m_From );
Item[] checks = cont.FindItemsByType( typeof( BankCheck ) );
int gold = cont.TotalGold;
for ( int i = 0; i < checks.Length; ++i )
gold += ((BankCheck)checks[i]).Worth;
m_From.SendMessage( "This container has {0} item{1} and {2} stone{3}. In gold or check form there is a total of {4:D}gp.", cont.TotalItems, cont.TotalItems==1?"":"s", cont.TotalWeight, cont.TotalWeight==1?"":"s", gold );
}
}*/
else
{ {
bid -= 5; bid -= 5;
@ -173,49 +151,54 @@ namespace Server.Engines.ConPVP
{ {
if (Participant.Players[bid] == null) if (Participant.Players[bid] == null)
{ {
From.Target = new ParticipantTarget(Context, Participant, bid); from.Target = new ParticipantTarget(Context, Participant, bid);
From.SendMessage("Target a player."); from.SendMessage("Target a player.");
return;
} }
else
{
Participant.Players[bid].Mobile.SendMessage("You have been removed from the duel."); Participant.Players[bid].Mobile.SendMessage("You have been removed from the duel.");
if (Participant.Players[bid].Mobile is PlayerMobile) if (Participant.Players[bid].Mobile is PlayerMobile playerMobile)
{ {
((PlayerMobile)Participant.Players[bid].Mobile).DuelPlayer = null; playerMobile.DuelPlayer = null;
} }
Participant.Players[bid] = null; Participant.Players[bid] = null;
From.SendMessage("They have been removed from the duel."); from.SendMessage("They have been removed from the duel.");
From.SendGump(new ParticipantGump(From, Context, Participant));
} }
} else
}
}
private class ParticipantTarget : Target
{
private readonly DuelContext m_Context;
private readonly int m_Index;
private readonly Participant m_Participant;
public ParticipantTarget(DuelContext context, Participant p, int index) : base(12, false, TargetFlags.None)
{
m_Context = context;
m_Participant = p;
m_Index = index;
}
protected override void OnTarget(Mobile from, object targeted)
{
if (!m_Context.Registered)
{ {
return; return;
} }
var index = m_Index; break;
}
}
if (index < 0 || index >= m_Participant.Players.Length) from.SendGump(this); // refresh-via-this
}
private class ParticipantTarget : Target
{
private readonly DuelContext _context;
private readonly int _index;
private readonly Participant _participant;
public ParticipantTarget(DuelContext context, Participant p, int index) : base(12, false, TargetFlags.None)
{
_context = context;
_participant = p;
_index = index;
}
protected override void OnTarget(Mobile from, object targeted)
{
if (!_context.Registered)
{
return;
}
if (_index < 0 || _index >= _participant.Players.Length)
{ {
return; return;
} }
@ -239,14 +222,10 @@ namespace Server.Engines.ConPVP
{ {
from.SendMessage("They ignore your offer."); from.SendMessage("They ignore your offer.");
} }
else else if (mob is not PlayerMobile pm)
{ {
if (mob is not PlayerMobile pm)
{
return;
} }
else if (pm.DuelContext != null)
if (pm.DuelContext != null)
{ {
from.SendMessage($"{pm.Name} cannot fight because they are already assigned to another duel."); from.SendMessage($"{pm.Name} cannot fight because they are already assigned to another duel.");
} }
@ -262,7 +241,7 @@ namespace Server.Engines.ConPVP
} }
else else
{ {
if (m_Participant.Find(from) == null) if (_participant.Find(from) == null)
{ {
from.SendMessage($"You send a challenge to {mob.Name}."); from.SendMessage($"You send a challenge to {mob.Name}.");
} }
@ -271,15 +250,10 @@ namespace Server.Engines.ConPVP
from.SendMessage($"You send an invitation to {mob.Name}."); from.SendMessage($"You send an invitation to {mob.Name}.");
} }
mob.SendGump(new AcceptDuelGump(from, mob, m_Context, m_Participant, m_Index)); AcceptDuelGump.DisplayTo(from, mob, _context, _participant, _index);
}
} }
} }
protected override void OnTargetFinish(Mobile from) protected override void OnTargetFinish(Mobile from) => DisplayTo(from, _context, _participant);
{
from.SendGump(new ParticipantGump(from, m_Context, m_Participant));
}
}
} }
} }

View file

@ -1,135 +1,149 @@
using Server.Gumps; using Server.Gumps;
using Server.Network; using Server.Network;
namespace Server.Engines.ConPVP namespace Server.Engines.ConPVP;
public class PickRulesetGump : DynamicGump
{ {
public class PickRulesetGump : Gump private readonly DuelContext _context;
private readonly Ruleset[] _defaults;
private readonly Ruleset[] _flavors;
private readonly Ruleset _ruleset;
public override bool Singleton => true;
private PickRulesetGump(DuelContext context, Ruleset ruleset) : base(50, 50)
{ {
private readonly DuelContext m_Context; _context = context;
private readonly Ruleset[] m_Defaults; _ruleset = ruleset;
private readonly Ruleset[] m_Flavors; _defaults = ruleset.Layout.Defaults;
private readonly Mobile m_From; _flavors = ruleset.Layout.Flavors;
private readonly Ruleset m_Ruleset;
public PickRulesetGump(Mobile from, DuelContext context, Ruleset ruleset) : base(50, 50)
{
m_From = from;
m_Context = context;
m_Ruleset = ruleset;
m_Defaults = ruleset.Layout.Defaults;
m_Flavors = ruleset.Layout.Flavors;
var height = 25 + 20 + (m_Defaults.Length + 1) * 22 + 6 + 20 + m_Flavors.Length * 22 + 25;
AddPage(0);
AddBackground(0, 0, 260, height, 9250);
AddBackground(10, 10, 240, height - 20, 0xDAC);
AddHtml(35, 25, 190, 20, Center("Rules"));
var y = 25 + 20;
for (var i = 0; i < m_Defaults.Length; ++i)
{
var cur = m_Defaults[i];
AddHtml(35 + 14, y, 176, 20, cur.Title);
if (ruleset.Base == cur && !ruleset.Changed)
{
AddImage(35, y + 4, 0x939);
}
else if (ruleset.Base == cur)
{
AddButton(35, y + 4, 0x93A, 0x939, 2 + i);
}
else
{
AddButton(35, y + 4, 0x938, 0x939, 2 + i);
} }
y += 22; public static void DisplayTo(Mobile from, DuelContext context, Ruleset ruleset)
}
AddHtml(35 + 14, y, 176, 20, "Custom");
AddButton(35, y + 4, ruleset.Changed ? 0x939 : 0x938, 0x939, 1);
y += 22;
y += 6;
AddHtml(35, y, 190, 20, Center("Flavors"));
y += 20;
for (var i = 0; i < m_Flavors.Length; ++i)
{ {
var cur = m_Flavors[i]; if (from?.NetState == null || ruleset == null)
AddHtml(35 + 14, y, 176, 20, cur.Title);
if (ruleset.Flavors.Contains(cur))
{
AddButton(35, y + 4, 0x939, 0x938, 2 + m_Defaults.Length + i);
}
else
{
AddButton(35, y + 4, 0x938, 0x939, 2 + m_Defaults.Length + i);
}
y += 22;
}
}
public string Center(string text) => $"<CENTER>{text}</CENTER>";
public override void OnResponse(NetState sender, in RelayInfo info)
{
if (m_Context?.Registered == false)
{ {
return; return;
} }
from.SendGump(new PickRulesetGump(context, ruleset));
}
protected override void BuildLayout(ref DynamicGumpBuilder builder)
{
var height = 25 + 20 + (_defaults.Length + 1) * 22 + 6 + 20 + _flavors.Length * 22 + 25;
builder.AddPage();
builder.AddBackground(0, 0, 260, height, 9250);
builder.AddBackground(10, 10, 240, height - 20, 0xDAC);
builder.AddHtml(35, 25, 190, 20, Center("Rules"));
var y = 25 + 20;
for (var i = 0; i < _defaults.Length; ++i)
{
var cur = _defaults[i];
builder.AddHtml(35 + 14, y, 176, 20, cur.Title);
if (_ruleset.Base == cur && !_ruleset.Changed)
{
builder.AddImage(35, y + 4, 0x939);
}
else if (_ruleset.Base == cur)
{
builder.AddButton(35, y + 4, 0x93A, 0x939, 2 + i);
}
else
{
builder.AddButton(35, y + 4, 0x938, 0x939, 2 + i);
}
y += 22;
}
builder.AddHtml(35 + 14, y, 176, 20, "Custom");
builder.AddButton(35, y + 4, _ruleset.Changed ? 0x939 : 0x938, 0x939, 1);
y += 22;
y += 6;
builder.AddHtml(35, y, 190, 20, Center("Flavors"));
y += 20;
for (var i = 0; i < _flavors.Length; ++i)
{
var cur = _flavors[i];
builder.AddHtml(35 + 14, y, 176, 20, cur.Title);
if (_ruleset.Flavors.Contains(cur))
{
builder.AddButton(35, y + 4, 0x939, 0x938, 2 + _defaults.Length + i);
}
else
{
builder.AddButton(35, y + 4, 0x938, 0x939, 2 + _defaults.Length + i);
}
y += 22;
}
}
private static string Center(string text) => $"<CENTER>{text}</CENTER>";
public override void OnResponse(NetState sender, in RelayInfo info)
{
if (_context?.Registered == false)
{
return;
}
var from = sender.Mobile;
switch (info.ButtonID) switch (info.ButtonID)
{ {
case 0: // closed case 0: // closed
{ {
if (m_Context != null) if (_context != null)
{ {
m_From.SendGump(new DuelContextGump(m_From, m_Context)); DuelContextGump.DisplayTo(from, _context);
} }
break; break;
} }
case 1: // customize case 1: // customize
{ {
m_From.SendGump(new RulesetGump(m_From, m_Ruleset, m_Ruleset.Layout, m_Context)); RulesetGump.DisplayTo(from, _ruleset, _ruleset.Layout, _context);
break; break;
} }
default: default:
{ {
var idx = info.ButtonID - 2; var idx = info.ButtonID - 2;
if (idx >= 0 && idx < m_Defaults.Length) if (idx >= 0 && idx < _defaults.Length)
{ {
m_Ruleset.ApplyDefault(m_Defaults[idx]); _ruleset.ApplyDefault(_defaults[idx]);
m_From.SendGump(new PickRulesetGump(m_From, m_Context, m_Ruleset)); from.SendGump(this); // refresh-via-this
} }
else else
{ {
idx -= m_Defaults.Length; idx -= _defaults.Length;
if (idx >= 0 && idx < m_Flavors.Length) if (idx >= 0 && idx < _flavors.Length)
{ {
if (m_Ruleset.Flavors.Contains(m_Flavors[idx])) if (_ruleset.Flavors.Contains(_flavors[idx]))
{ {
m_Ruleset.RemoveFlavor(m_Flavors[idx]); _ruleset.RemoveFlavor(_flavors[idx]);
} }
else else
{ {
m_Ruleset.AddFlavor(m_Flavors[idx]); _ruleset.AddFlavor(_flavors[idx]);
} }
m_From.SendGump(new PickRulesetGump(m_From, m_Context, m_Ruleset)); from.SendGump(this); // refresh-via-this
} }
} }
@ -138,4 +152,3 @@ namespace Server.Engines.ConPVP
} }
} }
} }
}

View file

@ -1,21 +1,39 @@
using Server.Gumps; using Server.Gumps;
using Server.Network; using Server.Network;
namespace Server.Engines.ConPVP namespace Server.Engines.ConPVP;
{
public class ReadyGump : Gump
{
private DuelContext m_Context;
private int m_Count;
private Mobile m_From;
public ReadyGump(Mobile from, DuelContext context, int count) : base(50, 50) public class ReadyGump : DynamicGump
{ {
m_From = from; private readonly DuelContext _context;
m_Context = context; private readonly int _count;
m_Count = count;
var parts = context.Participants; public override bool Singleton => true;
private ReadyGump(DuelContext context, int count) : base(50, 50)
{
_context = context;
_count = count;
}
public static void DisplayTo(Mobile from, DuelContext context, int count)
{
if (from?.NetState == null || context == null)
{
return;
}
from.SendGump(new ReadyGump(context, count), true);
}
protected override void BuildLayout(ref DynamicGumpBuilder builder)
{
builder.SetNoClose();
builder.SetNoMove();
builder.AddPage();
var parts = _context.Participants;
var height = 25 + 20; var height = 25 + 20;
@ -35,22 +53,17 @@ namespace Server.Engines.ConPVP
height += 25; height += 25;
Closable = false; builder.AddBackground(0, 0, 260, height, 9250);
Draggable = false; builder.AddBackground(10, 10, 240, height - 20, 0xDAC);
AddPage(0); if (_count == -1)
AddBackground(0, 0, 260, height, 9250);
AddBackground(10, 10, 240, height - 20, 0xDAC);
if (count == -1)
{ {
AddHtml(35, 25, 190, 20, Center("Ready")); builder.AddHtml(35, 25, 190, 20, "Ready".Center());
} }
else else
{ {
AddHtml(35, 25, 190, 20, Center("Starting")); builder.AddHtml(35, 25, 190, 20, "Starting".Center());
AddHtml(35, 25, 190, 20, $"<DIV ALIGN=RIGHT>{count}"); builder.AddHtml(35, 25, 190, 20, $"<DIV ALIGN=RIGHT>{_count}");
} }
var y = 25 + 20; var y = 25 + 20;
@ -67,7 +80,7 @@ namespace Server.Engines.ConPVP
if (p.Players.Length > 1) if (p.Players.Length > 1)
{ {
AddHtml(35 + 14, y, 176, 20, $"Participant #{i + 1}"); builder.AddHtml(35 + 14, y, 176, 20, $"Participant #{i + 1}");
y += 22; y += 22;
offset = 10; offset = 10;
} }
@ -78,32 +91,29 @@ namespace Server.Engines.ConPVP
if (pl?.Ready == true) if (pl?.Ready == true)
{ {
AddImage(35 + offset, y + 4, 0x939); builder.AddImage(35 + offset, y + 4, 0x939);
} }
else else
{ {
AddImage(35 + offset, y + 4, 0x938); builder.AddImage(35 + offset, y + 4, 0x938);
isAllReady = false; isAllReady = false;
} }
var name = pl == null ? "(Empty)" : pl.Mobile.Name; var name = pl == null ? "(Empty)" : pl.Mobile.Name;
AddHtml(35 + offset + 14, y, 166, 20, name); builder.AddHtml(35 + offset + 14, y, 166, 20, name);
y += 22; y += 22;
} }
if (p.Players.Length > 1) if (p.Players.Length > 1)
{ {
AddImage(35, yStore + 4, isAllReady ? 0x939 : 0x938); builder.AddImage(35, yStore + 4, isAllReady ? 0x939 : 0x938);
} }
} }
} }
public string Center(string text) => $"<CENTER>{text}</CENTER>";
public override void OnResponse(NetState sender, in RelayInfo info) public override void OnResponse(NetState sender, in RelayInfo info)
{ {
} }
} }
}

View file

@ -3,38 +3,48 @@ using Server.Gumps;
using Server.Mobiles; using Server.Mobiles;
using Server.Network; using Server.Network;
namespace Server.Engines.ConPVP namespace Server.Engines.ConPVP;
{
public class ReadyUpGump : Gump
{
private readonly DuelContext m_Context;
private readonly Mobile m_From;
public ReadyUpGump(Mobile from, DuelContext context) : base(50, 50) public class ReadyUpGump : DynamicGump
{ {
m_From = from; private readonly DuelContext _context;
m_Context = context;
Closable = false; public override bool Singleton => true;
AddPage(0);
if (context.Rematch) private ReadyUpGump(DuelContext context) : base(50, 50) => _context = context;
public static void DisplayTo(Mobile from, DuelContext context)
{
if (from?.NetState == null || context == null)
{
return;
}
from.SendGump(new ReadyUpGump(context), true);
}
protected override void BuildLayout(ref DynamicGumpBuilder builder)
{
builder.SetNoClose();
builder.AddPage();
if (_context.Rematch)
{ {
var height = 25 + 20 + 10 + 22 + 25; var height = 25 + 20 + 10 + 22 + 25;
AddBackground(0, 0, 210, height, 9250); builder.AddBackground(0, 0, 210, height, 9250);
AddBackground(10, 10, 190, height - 20, 0xDAC); builder.AddBackground(10, 10, 190, height - 20, 0xDAC);
AddHtml(35, 25, 140, 20, Center("Rematch?")); builder.AddHtml(35, 25, 140, 20, "Rematch?".Center());
AddButton(35, 55, 247, 248, 1); builder.AddButton(35, 55, 247, 248, 1);
AddButton(115, 55, 242, 241, 2); builder.AddButton(115, 55, 242, 241, 2);
} }
else else
{ {
AddPage(1); builder.AddPage(1);
var parts = context.Participants; var parts = _context.Participants;
var height = 25 + 20; var height = 25 + 20;
@ -54,10 +64,10 @@ namespace Server.Engines.ConPVP
height += 10 + 22 + 25; height += 10 + 22 + 25;
AddBackground(0, 0, 260, height, 9250); builder.AddBackground(0, 0, 260, height, 9250);
AddBackground(10, 10, 240, height - 20, 0xDAC); builder.AddBackground(10, 10, 240, height - 20, 0xDAC);
AddHtml(35, 25, 190, 20, Center("Participants")); builder.AddHtml(35, 25, 190, 20, "Participants".Center());
var y = 20 + 25; var y = 20 + 25;
@ -71,7 +81,7 @@ namespace Server.Engines.ConPVP
if (p.Players.Length > 1) if (p.Players.Length > 1)
{ {
AddHtml(35, y, 176, 20, $"Team #{i + 1}"); builder.AddHtml(35, y, 176, 20, $"Team #{i + 1}");
y += 22; y += 22;
offset = 10; offset = 10;
} }
@ -82,7 +92,7 @@ namespace Server.Engines.ConPVP
var name = pl == null ? "(Empty)" : pl.Mobile.Name; var name = pl == null ? "(Empty)" : pl.Mobile.Name;
AddHtml(35 + offset, y, 166, 20, name); builder.AddHtml(35 + offset, y, 166, 20, name);
y += 22; y += 22;
} }
@ -90,16 +100,16 @@ namespace Server.Engines.ConPVP
y += 8; y += 8;
AddHtml(35, y, 176, 20, "Continue?"); builder.AddHtml(35, y, 176, 20, "Continue?");
y -= 2; y -= 2;
AddButton(102, y, 247, 248, 0, GumpButtonType.Page, 2); builder.AddButton(102, y, 247, 248, 0, GumpButtonType.Page, 2);
AddButton(169, y, 242, 241, 2); builder.AddButton(169, y, 242, 241, 2);
AddPage(2); builder.AddPage(2);
var ruleset = context.Ruleset; var ruleset = _context.Ruleset;
var basedef = ruleset.Base; var basedef = ruleset.Base;
height = 25 + 20 + 5 + 20 + 20 + 4; height = 25 + 20 + 5 + 20 + 20 + 4;
@ -138,25 +148,25 @@ namespace Server.Engines.ConPVP
height += 10 + 22 + 25; height += 10 + 22 + 25;
AddBackground(0, 0, 260, height, 9250); builder.AddBackground(0, 0, 260, height, 9250);
AddBackground(10, 10, 240, height - 20, 0xDAC); builder.AddBackground(10, 10, 240, height - 20, 0xDAC);
AddHtml(35, 25, 190, 20, Center("Rules")); builder.AddHtml(35, 25, 190, 20, "Rules".Center());
AddHtml(35, 50, 190, 20, $"Set: {basedef.Title}"); builder.AddHtml(35, 50, 190, 20, $"Set: {basedef.Title}");
y = 70; y = 70;
for (var i = 0; i < ruleset.Flavors.Count; ++i, y += 18) for (var i = 0; i < ruleset.Flavors.Count; ++i, y += 18)
{ {
AddHtml(35, y, 190, 20, $" + {ruleset.Flavors[i].Title}"); builder.AddHtml(35, y, 190, 20, $" + {ruleset.Flavors[i].Title}");
} }
y += 4; y += 4;
if (changes > 0) if (changes > 0)
{ {
AddHtml(35, y, 190, 20, "Modifications:"); builder.AddHtml(35, y, 190, 20, "Modifications:");
y += 20; y += 20;
for (var i = 0; i < opts.Length; ++i) for (var i = 0; i < opts.Length; ++i)
@ -167,8 +177,8 @@ namespace Server.Engines.ConPVP
if (name != null) // sanity if (name != null) // sanity
{ {
AddImage(35, y, opts[i] ? 0xD3 : 0xD2); builder.AddImage(35, y, opts[i] ? 0xD3 : 0xD2);
AddHtml(60, y, 165, 22, name); builder.AddHtml(60, y, 165, 22, name);
} }
y += 22; y += 22;
@ -177,61 +187,55 @@ namespace Server.Engines.ConPVP
} }
else else
{ {
AddHtml(35, y, 190, 20, "Modifications: None"); builder.AddHtml(35, y, 190, 20, "Modifications: None");
y += 20; y += 20;
} }
y += 8; y += 8;
AddHtml(35, y, 176, 20, "Continue?"); builder.AddHtml(35, y, 176, 20, "Continue?");
y -= 2; y -= 2;
AddButton(102, y, 247, 248, 1); builder.AddButton(102, y, 247, 248, 1);
AddButton(169, y, 242, 241, 3); builder.AddButton(169, y, 242, 241, 3);
} }
} }
public string Center(string text) => $"<CENTER>{text}</CENTER>"; private static string Center(string text) => $"<CENTER>{text}</CENTER>";
public void AddGoldenButton(int x, int y, int bid)
{
AddButton(x, y, 0xD2, 0xD2, bid);
AddButton(x + 3, y + 3, 0xD8, 0xD8, bid);
}
public override void OnResponse(NetState sender, in RelayInfo info) public override void OnResponse(NetState sender, in RelayInfo info)
{ {
if (!m_Context.Registered || !m_Context.ReadyWait) if (!_context.Registered || !_context.ReadyWait)
{ {
return; return;
} }
var from = sender.Mobile;
switch (info.ButtonID) switch (info.ButtonID)
{ {
case 1: // okay case 1: // okay
{ {
if (m_From is not PlayerMobile pm) if (from is not PlayerMobile pm)
{ {
break; break;
} }
pm.DuelPlayer.Ready = true; pm.DuelPlayer.Ready = true;
m_Context.SendReadyGump(); _context.SendReadyGump();
break; break;
} }
case 2: // reject participants case 2: // reject participants
{ {
m_Context.RejectReady(m_From, "participants"); _context.RejectReady(from, "participants");
break; break;
} }
case 3: // reject rules case 3: // reject rules
{ {
m_Context.RejectReady(m_From, "rules"); _context.RejectReady(from, "rules");
break; break;
} }
} }
} }
} }
}

View file

@ -2,106 +2,119 @@ using System.Collections;
using Server.Gumps; using Server.Gumps;
using Server.Network; using Server.Network;
namespace Server.Engines.ConPVP namespace Server.Engines.ConPVP;
public class RulesetGump : DynamicGump
{ {
public class RulesetGump : Gump private readonly DuelContext _duelContext;
{ private readonly RulesetLayout _page;
private readonly DuelContext m_DuelContext; private readonly bool _readOnly;
private readonly Mobile m_From; private readonly Ruleset _ruleset;
private readonly RulesetLayout m_Page;
private readonly bool m_ReadOnly;
private readonly Ruleset m_Ruleset;
public override bool Singleton => true; public override bool Singleton => true;
public RulesetGump(Mobile from, Ruleset ruleset, RulesetLayout page, DuelContext duelContext, bool readOnly = false) private RulesetGump(Ruleset ruleset, RulesetLayout page, DuelContext duelContext, bool readOnly)
: base(readOnly ? 310 : 50, 50) : base(readOnly ? 310 : 50, 50)
{ {
m_From = from; _ruleset = ruleset;
m_Ruleset = ruleset; _page = page;
m_Page = page; _duelContext = duelContext;
m_DuelContext = duelContext; _readOnly = readOnly;
m_ReadOnly = readOnly; }
Draggable = !readOnly; public static void DisplayTo(
Mobile from, Ruleset ruleset, RulesetLayout page, DuelContext duelContext, bool readOnly = false
)
{
if (from?.NetState == null || ruleset == null || page == null)
{
return;
}
var gumps = from.GetGumps(); var gumps = from.GetGumps();
gumps.Close<DuelContextGump>(); gumps.Close<DuelContextGump>();
gumps.Close<ParticipantGump>(); gumps.Close<ParticipantGump>();
var depthCounter = page; from.SendGump(new RulesetGump(ruleset, page, duelContext, readOnly));
}
protected override void BuildLayout(ref DynamicGumpBuilder builder)
{
if (_readOnly)
{
builder.SetNoMove();
}
var depthCounter = _page;
while (depthCounter != null) while (depthCounter != null)
{ {
depthCounter = depthCounter.Parent; depthCounter = depthCounter.Parent;
} }
var count = page.Children.Length + page.Options.Length; var count = _page.Children.Length + _page.Options.Length;
AddPage(0); builder.AddPage();
var height = 35 + 10 + 2 + count * 22 + 2 + 30; var height = 35 + 10 + 2 + count * 22 + 2 + 30;
AddBackground(0, 0, 260, height, 9250); builder.AddBackground(0, 0, 260, height, 9250);
AddBackground(10, 10, 240, height - 20, 0xDAC); builder.AddBackground(10, 10, 240, height - 20, 0xDAC);
AddHtml(35, 25, 190, 20, Center(page.Title)); builder.AddHtml(35, 25, 190, 20, _page.Title.Center());
var x = 35; var x = 35;
var y = 47; var y = 47;
for (var i = 0; i < page.Children.Length; ++i) for (var i = 0; i < _page.Children.Length; ++i)
{ {
AddGoldenButton(x, y, 1 + i); AddGoldenButton(ref builder, x, y, 1 + i);
AddHtml(x + 25, y, 250, 22, page.Children[i].Title); builder.AddHtml(x + 25, y, 250, 22, _page.Children[i].Title);
y += 22; y += 22;
} }
for (var i = 0; i < page.Options.Length; ++i) for (var i = 0; i < _page.Options.Length; ++i)
{ {
var enabled = ruleset.Options[page.Offset + i]; var enabled = _ruleset.Options[_page.Offset + i];
if (readOnly) if (_readOnly)
{ {
AddImage(x, y, enabled ? 0xD3 : 0xD2); builder.AddImage(x, y, enabled ? 0xD3 : 0xD2);
} }
else else
{ {
AddCheck(x, y, 0xD2, 0xD3, enabled, i); builder.AddCheckbox(x, y, 0xD2, 0xD3, enabled, i);
} }
AddHtml(x + 25, y, 250, 22, page.Options[i]); builder.AddHtml(x + 25, y, 250, 22, _page.Options[i]);
y += 22; y += 22;
} }
} }
public string Center(string text) => $"<CENTER>{text}</CENTER>"; private static void AddGoldenButton(ref DynamicGumpBuilder builder, int x, int y, int bid)
public void AddGoldenButton(int x, int y, int bid)
{ {
AddButton(x, y, 0xD2, 0xD2, bid); builder.AddButton(x, y, 0xD2, 0xD2, bid);
AddButton(x + 3, y + 3, 0xD8, 0xD8, bid); builder.AddButton(x + 3, y + 3, 0xD8, 0xD8, bid);
} }
public override void OnResponse(NetState sender, in RelayInfo info) public override void OnResponse(NetState sender, in RelayInfo info)
{ {
if (m_DuelContext?.Registered == false) if (_duelContext?.Registered == false)
{ {
return; return;
} }
if (!m_ReadOnly) if (!_readOnly)
{ {
var opts = new BitArray(m_Page.Options.Length); var opts = new BitArray(_page.Options.Length);
for (var i = 0; i < info.Switches.Length; ++i) for (var i = 0; i < info.Switches.Length; ++i)
{ {
var sid = info.Switches[i]; var sid = info.Switches[i];
if (sid >= 0 && sid < m_Page.Options.Length) if (sid >= 0 && sid < _page.Options.Length)
{ {
opts[sid] = true; opts[sid] = true;
} }
@ -109,35 +122,35 @@ namespace Server.Engines.ConPVP
for (var i = 0; i < opts.Length; ++i) for (var i = 0; i < opts.Length; ++i)
{ {
if (m_Ruleset.Options[m_Page.Offset + i] != opts[i]) if (_ruleset.Options[_page.Offset + i] != opts[i])
{ {
m_Ruleset.Options[m_Page.Offset + i] = opts[i]; _ruleset.Options[_page.Offset + i] = opts[i];
m_Ruleset.Changed = true; _ruleset.Changed = true;
} }
} }
} }
var from = sender.Mobile;
var bid = info.ButtonID; var bid = info.ButtonID;
if (bid == 0) if (bid == 0)
{ {
if (m_Page.Parent != null) if (_page.Parent != null)
{ {
m_From.SendGump(new RulesetGump(m_From, m_Ruleset, m_Page.Parent, m_DuelContext, m_ReadOnly)); DisplayTo(from, _ruleset, _page.Parent, _duelContext, _readOnly);
} }
else if (!m_ReadOnly) else if (!_readOnly)
{ {
m_From.SendGump(new PickRulesetGump(m_From, m_DuelContext, m_Ruleset)); PickRulesetGump.DisplayTo(from, _duelContext, _ruleset);
} }
} }
else else
{ {
bid -= 1; bid -= 1;
if (bid >= 0 && bid < m_Page.Children.Length) if (bid >= 0 && bid < _page.Children.Length)
{ {
m_From.SendGump(new RulesetGump(m_From, m_Ruleset, m_Page.Children[bid], m_DuelContext, m_ReadOnly)); DisplayTo(from, _ruleset, _page.Children[bid], _duelContext, _readOnly);
}
} }
} }
} }

View file

@ -174,42 +174,56 @@ namespace Server.Engines.ConPVP
} }
} }
public class PreferencesGump : Gump public class PreferencesGump : DynamicGump
{ {
private readonly PreferencesEntry m_Entry; private readonly PreferencesEntry _entry;
private int m_ColumnX = 12; private int _columnX;
public override bool Singleton => true; public override bool Singleton => true;
public PreferencesGump(Mobile from, Preferences prefs) : base(50, 50) private PreferencesGump(PreferencesEntry entry) : base(50, 50) => _entry = entry;
{
m_Entry = prefs.Find(from);
if (m_Entry == null) public static void DisplayTo(Mobile from, Preferences prefs)
{
if (from?.NetState == null || prefs == null)
{ {
return; return;
} }
var entry = prefs.Find(from);
if (entry == null)
{
return;
}
from.SendGump(new PreferencesGump(entry));
}
protected override void BuildLayout(ref DynamicGumpBuilder builder)
{
_columnX = 12;
var arenas = Arena.Arenas; var arenas = Arena.Arenas;
AddPage(0); builder.AddPage();
var height = 12 + 20 + arenas.Count * 31 + 24 + 12; var height = 12 + 20 + arenas.Count * 31 + 24 + 12;
AddBackground(0, 0, 499 + 40 - 365, height, 0x2436); builder.AddBackground(0, 0, 499 + 40 - 365, height, 0x2436);
for (var i = 1; i < arenas.Count; i += 2) for (var i = 1; i < arenas.Count; i += 2)
{ {
AddImageTiled(12, 32 + i * 31, 475 + 40 - 365, 30, 0x2430); builder.AddImageTiled(12, 32 + i * 31, 475 + 40 - 365, 30, 0x2430);
} }
AddAlphaRegion(10, 10, 479 + 40 - 365, height - 20); builder.AddAlphaRegion(10, 10, 479 + 40 - 365, height - 20);
AddColumnHeader(35, null); AddColumnHeader(ref builder, 35, null);
AddColumnHeader(115, "Arena"); AddColumnHeader(ref builder, 115, "Arena");
AddButton(499 + 40 - 365 - 12 - 63 - 4 - 63, height - 12 - 24, 247, 248, 1); builder.AddButton(499 + 40 - 365 - 12 - 63 - 4 - 63, height - 12 - 24, 247, 248, 1);
AddButton(499 + 40 - 365 - 12 - 63, height - 12 - 24, 241, 242, 2); builder.AddButton(499 + 40 - 365 - 12 - 63, height - 12 - 24, 241, 242, 2);
for (var i = 0; i < arenas.Count; ++i) for (var i = 0; i < arenas.Count; ++i)
{ {
@ -222,16 +236,16 @@ namespace Server.Engines.ConPVP
var color = 0xCCFFCC; var color = 0xCCFFCC;
AddCheck(x + 3, y + 1, 9730, 9727, m_Entry.Disliked.Contains(name), i); builder.AddCheckbox(x + 3, y + 1, 9730, 9727, _entry.Disliked.Contains(name), i);
x += 35; x += 35;
AddBorderedText(x + 5, y + 5, 115 - 5, name, color, 0); AddBorderedText(ref builder, x + 5, y + 5, 115 - 5, name, color, 0);
} }
} }
public override void OnResponse(NetState sender, in RelayInfo info) public override void OnResponse(NetState sender, in RelayInfo info)
{ {
if (m_Entry == null) if (_entry == null)
{ {
return; return;
} }
@ -241,7 +255,7 @@ namespace Server.Engines.ConPVP
return; return;
} }
m_Entry.Disliked.Clear(); _entry.Disliked.Clear();
var arenas = Arena.Arenas; var arenas = Arena.Arenas;
@ -251,32 +265,32 @@ namespace Server.Engines.ConPVP
if (idx >= 0 && idx < arenas.Count) if (idx >= 0 && idx < arenas.Count)
{ {
m_Entry.Disliked.Add(arenas[idx].Name); _entry.Disliked.Add(arenas[idx].Name);
} }
} }
} }
private void AddBorderedText(int x, int y, int width, string text, int color, int borderColor) private static void AddBorderedText(ref DynamicGumpBuilder builder, int x, int y, int width, string text, int color, int borderColor)
{ {
AddColoredText(x, y, width, text, color); AddColoredText(ref builder, x, y, width, text, color);
} }
private void AddColoredText(int x, int y, int width, string text, int color) private static void AddColoredText(ref DynamicGumpBuilder builder, int x, int y, int width, string text, int color)
{ {
AddHtml(x, y, width, 20, color == 0 ? text : text.Color(color)); builder.AddHtml(x, y, width, 20, color == 0 ? text : text.Color(color));
} }
private void AddColumnHeader(int width, string name) private void AddColumnHeader(ref DynamicGumpBuilder builder, int width, string name)
{ {
AddBackground(m_ColumnX, 12, width, 20, 0x242C); builder.AddBackground(_columnX, 12, width, 20, 0x242C);
AddImageTiled(m_ColumnX + 2, 14, width - 4, 16, 0x2430); builder.AddImageTiled(_columnX + 2, 14, width - 4, 16, 0x2430);
if (name != null) if (name != null)
{ {
AddBorderedText(m_ColumnX, 13, width, name.Center(), 0xFFFFFF, 0); AddBorderedText(ref builder, _columnX, 13, width, name.Center(), 0xFFFFFF, 0);
} }
m_ColumnX += width; _columnX += width;
} }
} }
} }

View file

@ -27,7 +27,7 @@ public partial class TournamentBracketItem : Item
if (tourney != null) if (tourney != null)
{ {
from.SendGump(new TournamentBracketGump(from, tourney, TourneyBracketGumpType.Index), true); TournamentBracketGump.DisplayTo(from, tourney, TourneyBracketGumpType.Index);
} }
} }
} }

View file

@ -70,7 +70,7 @@ namespace Server.Engines.ConPVP
gumps.Close<RulesetGump>(); gumps.Close<RulesetGump>();
gumps.Close<PickRulesetGump>(); gumps.Close<PickRulesetGump>();
gumps.Send(new PickRulesetGump(from, null, Tournament.Ruleset)); PickRulesetGump.DisplayTo(from, null, Tournament.Ruleset);
} }
} }

View file

@ -144,7 +144,7 @@ public partial class TournamentSignupItem : Item
} }
else if (!tourney.HasParticipant(from)) else if (!tourney.HasParticipant(from))
{ {
from.SendGump(new ConfirmSignupGump(from, Registrar, tourney, new List<Mobile> { from })); ConfirmSignupGump.DisplayTo(from, Registrar, tourney, new List<Mobile> { from });
} }
else else
{ {