public override void OnMovement(Mobile m, Point3D oldLocation) { base.OnMovement(m, oldLocation); Tournament tourney = Tournament?.Tournament; if (InRange(m, 4) && !InRange(oldLocation, 4) && tourney != null && tourney.Stage == TournamentStage.Signup && m.CanBeginAction(this)) { Ladder ladder = Ladder.Instance; LadderEntry entry = ladder?.Find(m); if (entry != null && Ladder.GetLevel(entry.Experience) < tourney.LevelRequirement) { return; } if (tourney.IsFactionRestricted && Faction.Find(m) == null) { return; } if (tourney.HasParticipant(m)) { return; } PrivateOverheadMessage(MessageType.Regular, 0x35, false, $"Hello m'{(m.Female ? "Lady" : "Lord")}. Dost thou wish to enter this tournament? You need only to write your name in this book.", m.NetState); m.BeginAction(this); Timer.DelayCall(TimeSpan.FromSeconds(10.0), ReleaseLock_Callback, m); } }
public LadderGump(Ladder ladder, int page) : base(50, 50) { m_Ladder = ladder; m_Page = page; AddPage(0); List <LadderEntry> list = ladder.Entries; m_List = list; int lc = Math.Min(list.Count, 150); int start = page * 15; int end = start + 15; if (end > lc) { end = lc; } int ct = end - start; int height = 12 + 20 + (ct * 20) + 23 + 12; AddBackground(0, 0, 499, height, 0x2436); for (int i = start + 1; i < end; i += 2) { AddImageTiled(12, 32 + ((i - start) * 20), 475, 20, 0x2430); } AddAlphaRegion(10, 10, 479, height - 20); if (page > 0) { AddButton(446, height - 12 - 2 - 16, 0x15E3, 0x15E7, 1, GumpButtonType.Reply, 0); } else { AddImage(446, height - 12 - 2 - 16, 0x2626); } if (((page + 1) * 15) < lc) { AddButton(466, height - 12 - 2 - 16, 0x15E1, 0x15E5, 2, GumpButtonType.Reply, 0); } else { AddImage(466, height - 12 - 2 - 16, 0x2622); } AddHtml(16, height - 12 - 2 - 18, 400, 20, Color(String.Format("Top {3} of {0:N0} duelists, page {1} of {2}", list.Count, page + 1, (lc + 14) / 15, lc), 0xFFC000), false, false); AddColumnHeader(75, "Rank"); AddColumnHeader(115, "Level"); AddColumnHeader(50, "Guild"); AddColumnHeader(115, "Name"); AddColumnHeader(60, "Wins"); AddColumnHeader(60, "Losses"); for (int i = start; i < end && i < lc; ++i) { LadderEntry entry = list[i]; int y = 32 + ((i - start) * 20); int x = 12; AddBorderedText(x, y, 75, Center(Rank(i + 1)), 0xFFFFFF, 0); x += 75; /*AddImage( 20, y + 5, 0x2616, 0x96C ); * 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); int xp = entry.Experience; int level = Ladder.GetLevel(xp); int xpBase, xpAdvance; Ladder.GetLevelInfo(level, out xpBase, out xpAdvance); int width; int xpOffset = xp - xpBase; if (xpOffset >= xpAdvance) { width = 109; // level 50 } else { width = ((109 * xpOffset) + (xpAdvance / 2)) / (xpAdvance - 1); } //AddImageTiled( 21, y + 6, width, 8, 0x2617 ); AddImageTiled(x + 3, y + 4, width, 11, 0x806); AddBorderedText(x, y, 115, Center(level.ToString()), 0xFFFFFF, 0); x += 115; Mobile mob = entry.Mobile; if (mob.Guild != null) { AddBorderedText(x, y, 50, Center(mob.Guild.Abbreviation), 0xFFFFFF, 0); } x += 50; AddBorderedText(x + 5, y, 115 - 5, (mob.Name), 0xFFFFFF, 0); x += 115; AddBorderedText(x, y, 60, Center(entry.Wins.ToString()), 0xFFFFFF, 0); x += 60; AddBorderedText(x, y, 60, Center(entry.Losses.ToString()), 0xFFFFFF, 0); 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 ); } }
public override void OnResponse(NetState sender, RelayInfo info) { if (info.ButtonID == 1 && info.IsSwitched(1)) { var tourney = m_Tournament; var from = m_From; switch (tourney.Stage) { case TournamentStage.Fighting: { if (m_Registrar != null) { if (m_Tournament.HasParticipant(from)) { m_Registrar.PrivateOverheadMessage( MessageType.Regular, 0x35, false, "Excuse me? You are already signed up.", from.NetState ); } else { m_Registrar.PrivateOverheadMessage( MessageType.Regular, 0x22, false, "The tournament has already begun. You are too late to signup now.", from.NetState ); } } break; } case TournamentStage.Inactive: { m_Registrar?.PrivateOverheadMessage( MessageType.Regular, 0x35, false, "The tournament is closed.", from.NetState ); break; } case TournamentStage.Signup: { if (m_Players.Count != tourney.PlayersPerParticipant) { m_Registrar?.PrivateOverheadMessage( MessageType.Regular, 0x35, false, "You have not yet chosen your team.", from.NetState ); m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); break; } var ladder = Ladder.Instance; for (var i = 0; i < m_Players.Count; ++i) { var mob = m_Players[i]; var entry = ladder?.Find(mob); if (entry != null && Ladder.GetLevel(entry.Experience) < tourney.LevelRequirement) { if (m_Registrar != null) { if (mob == from) { m_Registrar.PrivateOverheadMessage( MessageType.Regular, 0x35, false, "You have not yet proven yourself a worthy dueler.", from.NetState ); } else { m_Registrar.PrivateOverheadMessage( MessageType.Regular, 0x35, false, $"{mob.Name} has not yet proven themselves a worthy dueler.", from.NetState ); } } m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); return; } if (tourney.IsFactionRestricted && Faction.Find(mob) == null) { m_Registrar?.PrivateOverheadMessage( MessageType.Regular, 0x35, false, "Only those who have declared their faction allegiance may participate.", from.NetState ); m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); return; } if (tourney.HasParticipant(mob)) { if (m_Registrar != null) { if (mob == from) { m_Registrar.PrivateOverheadMessage( MessageType.Regular, 0x35, false, "You have already entered this tournament.", from.NetState ); } else { m_Registrar.PrivateOverheadMessage( MessageType.Regular, 0x35, false, $"{mob.Name} has already entered this tournament.", from.NetState ); } } m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players)); return; } if (mob is PlayerMobile mobile && mobile.DuelContext != null) { if (mob == from) { m_Registrar?.PrivateOverheadMessage( MessageType.Regular, 0x35, false, "You are already assigned to a duel. You must yield it before joining this tournament.", from.NetState ); } else { m_Registrar?.PrivateOverheadMessage( MessageType.Regular, 0x35, false, $"{mobile.Name} is already assigned to a duel. They must yield it before joining this tournament.", 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 { fmt = "As you wish m'{0}. The tournament will begin {1}, but first you must name your team."; } string timeUntil; var minutesUntil = (int)Math.Round( (tourney.SignupStart + tourney.SignupPeriod - DateTime.UtcNow) .TotalMinutes ); if (minutesUntil == 0) { timeUntil = "momentarily"; } else { timeUntil = $"in {minutesUntil} minute{(minutesUntil == 1 ? "" : "s")}"; } m_Registrar.PrivateOverheadMessage( MessageType.Regular, 0x35, false, string.Format(fmt, from.Female ? "Lady" : "Lord", timeUntil), from.NetState ); } var part = new TourneyParticipant(from); part.Players.Clear(); part.Players.AddRange(m_Players); tourney.Participants.Add(part); 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)); } } }
public TournamentBracketGump( Mobile from, Tournament tourney, TourneyBracketGumpType type, List <object> list = null, int page = 0, object obj = null ) : base(50, 50) { m_From = from; m_Tournament = tourney; m_Type = type; m_List = list; m_Page = page; m_Object = obj; m_PerPage = 12; switch (type) { case TourneyBracketGumpType.Index: { AddPage(0); AddBackground(0, 0, 300, 300, 9380); var sb = new StringBuilder(); if (tourney.TourneyType == TourneyType.FreeForAll) { sb.Append("FFA"); } else if (tourney.TourneyType == TourneyType.RandomTeam) { sb.Append(tourney.ParticipantsPerMatch); sb.Append("-Team"); } else if (tourney.TourneyType == TourneyType.RedVsBlue) { sb.Append("Red v Blue"); } else if (tourney.TourneyType == TourneyType.Faction) { sb.Append(tourney.ParticipantsPerMatch); sb.Append("-Team Faction"); } else { for (var i = 0; i < tourney.ParticipantsPerMatch; ++i) { if (sb.Length > 0) { sb.Append('v'); } sb.Append(tourney.PlayersPerParticipant); } } if (tourney.EventController != null) { sb.Append(' ').Append(tourney.EventController.Title); } sb.Append(" Tournament Bracket"); AddHtml(25, 35, 250, 20, Center(sb.ToString())); AddRightArrow(25, 53, ToButtonID(0, 4), "Rules"); AddRightArrow(25, 71, ToButtonID(0, 1), "Participants"); if (m_Tournament.Stage == TournamentStage.Signup) { var until = m_Tournament.SignupStart + m_Tournament.SignupPeriod - DateTime.UtcNow; string text; var secs = (int)until.TotalSeconds; if (secs > 0) { var mins = secs / 60; secs %= 60; if (mins > 0 && secs > 0) { text = $"The tournament will begin in {mins} minute{(mins == 1 ? "" : "s")} and {secs} second{(secs == 1 ? "" : "s")}."; } else if (mins > 0) { text = $"The tournament will begin in {mins} minute{(mins == 1 ? "" : "s")}."; } else if (secs > 0) { text = $"The tournament will begin in {secs} second{(secs == 1 ? "" : "s")}."; } else { text = "The tournament will begin shortly."; } } else { text = "The tournament will begin shortly."; } AddHtml(25, 92, 250, 40, text); } else { AddRightArrow(25, 89, ToButtonID(0, 2), "Rounds"); } break; } case TourneyBracketGumpType.Rules_Info: { var ruleset = tourney.Ruleset; var basedef = ruleset.Base; BitArray defs; if (ruleset.Flavors.Count > 0) { defs = new BitArray(basedef.Options); for (var i = 0; i < ruleset.Flavors.Count; ++i) { defs.Or(ruleset.Flavors[i].Options); } } else { defs = basedef.Options; } var changes = 0; var opts = ruleset.Options; for (var i = 0; i < opts.Length; ++i) { if (defs[i] != opts[i]) { ++changes; } } AddPage(0); AddBackground( 0, 0, 300, 60 + 18 + 20 + 20 + 20 + 8 + 20 + ruleset.Flavors.Count * 18 + 4 + 20 + changes * 22 + 6, 9380 ); AddLeftArrow(25, 11, ToButtonID(0, 0)); AddHtml(25, 35, 250, 20, Center("Rules")); var y = 53; var groupText = tourney.GroupType switch { GroupingType.HighVsLow => "High vs Low", GroupingType.Nearest => "Closest opponent", GroupingType.Random => "Random", _ => null }; AddHtml(35, y, 190, 20, $"Grouping: {groupText}"); y += 20; var tieText = tourney.TieType switch { TieType.Random => "Random", TieType.Highest => "Highest advances", TieType.Lowest => "Lowest advances", TieType.FullAdvancement => tourney.ParticipantsPerMatch == 2 ? "Both advance" : "Everyone advances", TieType.FullElimination => tourney.ParticipantsPerMatch == 2 ? "Both eliminated" : "Everyone eliminated", _ => null }; AddHtml(35, y, 190, 20, $"Tiebreaker: {tieText}"); y += 20; var sdText = "Off"; if (tourney.SuddenDeath > TimeSpan.Zero) { sdText = $"{(int)tourney.SuddenDeath.TotalMinutes}:{tourney.SuddenDeath.Seconds:D2}"; if (tourney.SuddenDeathRounds > 0) { sdText = $"{sdText} (first {tourney.SuddenDeathRounds} rounds)"; } else { sdText = $"{sdText} (all rounds)"; } } AddHtml(35, y, 240, 20, $"Sudden Death: {sdText}"); y += 20; y += 8; AddHtml(35, y, 190, 20, $"Ruleset: {basedef.Title}"); y += 20; for (var i = 0; i < ruleset.Flavors.Count; ++i, y += 18) { AddHtml(35, y, 190, 20, $" + {ruleset.Flavors[i].Title}"); } y += 4; if (changes > 0) { AddHtml(35, y, 190, 20, "Modifications:"); y += 20; for (var i = 0; i < opts.Length; ++i) { if (defs[i] != opts[i]) { var name = ruleset.Layout.FindByIndex(i); if (name != null) // sanity { AddImage(35, y, opts[i] ? 0xD3 : 0xD2); AddHtml(60, y, 165, 22, name); } y += 22; } } } else { AddHtml(35, y, 190, 20, "Modifications: None"); } break; } case TourneyBracketGumpType.Participant_List: { AddPage(0); AddBackground(0, 0, 300, 300, 9380); var pList = m_List != null ? Utility.CastListCovariant <object, TourneyParticipant>(m_List) : new List <TourneyParticipant>(tourney.Participants); AddLeftArrow(25, 11, ToButtonID(0, 0)); AddHtml(25, 35, 250, 20, Center($"{pList.Count} Participant{(pList.Count == 1 ? "" : "s")}")); StartPage(out var index, out var count, out var y, 12); for (var i = 0; i < count; ++i, y += 18) { var part = pList[index + i]; var name = part.NameList; if (m_Tournament.TourneyType != TourneyType.Standard && part.Players.Count == 1) { if (part.Players[0] is PlayerMobile pm && pm.DuelPlayer != null) { name = Color(name, pm.DuelPlayer.Eliminated ? 0x6633333 : 0x336666); } } AddRightArrow(25, y, ToButtonID(2, index + i), name); } break; } case TourneyBracketGumpType.Participant_Info: { if (!(obj is TourneyParticipant part)) { break; } AddPage(0); AddBackground(0, 0, 300, 60 + 18 + 20 + part.Players.Count * 18 + 20 + 20 + 160, 9380); AddLeftArrow(25, 11, ToButtonID(0, 1)); AddHtml(25, 35, 250, 20, Center("Participants")); var y = 53; AddHtml(25, y, 200, 20, part.Players.Count == 1 ? "Players" : "Team"); y += 20; for (var i = 0; i < part.Players.Count; ++i) { var mob = part.Players[i]; var name = mob.Name; if (m_Tournament.TourneyType != TourneyType.Standard) { if (mob is PlayerMobile pm && pm.DuelPlayer != null) { name = Color(name, pm.DuelPlayer.Eliminated ? 0x6633333 : 0x336666); } } AddRightArrow(35, y, ToButtonID(4, i), name); y += 18; } AddHtml( 25, y, 200, 20, $"Free Advances: {(part.FreeAdvances == 0 ? "None" : part.FreeAdvances.ToString())}" ); y += 20; AddHtml(25, y, 200, 20, "Log:"); y += 20; var sb = new StringBuilder(); for (var i = 0; i < part.Log.Count; ++i) { if (sb.Length > 0) { sb.Append("<br>"); } sb.Append(part.Log[i]); } if (sb.Length == 0) { sb.Append("Nothing logged yet."); } AddHtml(25, y, 250, 150, Color(sb.ToString(), BlackColor32), false, true); break; } case TourneyBracketGumpType.Player_Info: { AddPage(0); AddBackground(0, 0, 300, 300, 9380); AddLeftArrow(25, 11, ToButtonID(0, 3)); AddHtml(25, 35, 250, 20, Center("Participants")); if (!(obj is Mobile mob)) { break; } var ladder = Ladder.Instance; var entry = ladder?.Find(mob); AddHtml(25, 53, 250, 20, $"Name: {mob.Name}"); AddHtml( 25, 73, 250, 20, $"Guild: {(mob.Guild == null ? "None" : $"{mob.Guild.Name} [{mob.Guild.Abbreviation}]")}" ); AddHtml(25, 93, 250, 20, $"Rank: {(entry == null ? "N/A" : LadderGump.Rank(entry.Index + 1))}"); AddHtml(25, 113, 250, 20, $"Level: {(entry == null ? 0 : Ladder.GetLevel(entry.Experience))}"); AddHtml(25, 133, 250, 20, $"Wins: {entry?.Wins ?? 0:N0}"); AddHtml(25, 153, 250, 20, $"Losses: {entry?.Losses ?? 0:N0}"); break; }