public TourneyMatch(List <TourneyParticipant> participants) { Participants = participants; for (int i = 0; i < participants.Count; ++i) { TourneyParticipant part = participants[i]; StringBuilder sb = new StringBuilder(); sb.Append("Matched in a duel against "); if (participants.Count > 2) { sb.AppendFormat("{0} other {1}: ", participants.Count - 1, part.Players.Count == 1 ? "players" : "teams"); } bool hasAppended = false; for (int j = 0; j < participants.Count; ++j) { if (i == j) { continue; } if (hasAppended) { sb.Append(", "); } sb.Append(participants[j].NameList); hasAppended = true; } sb.Append("."); part.AddLog(sb.ToString()); } }
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 void Start(Arena arena, Tournament tourney) { TourneyParticipant first = Participants[0]; DuelContext dc = new DuelContext(first.Players[0], tourney.Ruleset.Layout, false); dc.Ruleset.Options.SetAll(false); dc.Ruleset.Options.Or(tourney.Ruleset.Options); for (int i = 0; i < Participants.Count; ++i) { TourneyParticipant tourneyPart = Participants[i]; Participant duelPart = new Participant(dc, tourneyPart.Players.Count) { TourneyPart = tourneyPart }; for (int j = 0; j < tourneyPart.Players.Count; ++j) { duelPart.Add(tourneyPart.Players[j]); } for (int j = 0; j < duelPart.Players.Length; ++j) { if (duelPart.Players[j] != null) { duelPart.Players[j].Ready = true; } } dc.Participants.Add(duelPart); } if (tourney.EventController != null) { dc.m_EventGame = tourney.EventController.Construct(dc); } dc.m_Tournament = tourney; dc.m_Match = this; dc.m_OverrideArena = arena; if (tourney.SuddenDeath > TimeSpan.Zero && (tourney.SuddenDeathRounds == 0 || tourney.Pyramid.Levels.Count <= tourney.SuddenDeathRounds)) { dc.StartSuddenDeath(tourney.SuddenDeath); } dc.SendReadyGump(0); if (dc.StartedBeginCountdown) { Context = dc; for (int i = 0; i < Participants.Count; ++i) { TourneyParticipant p = Participants[i]; for (int j = 0; j < p.Players.Count; ++j) { Mobile mob = p.Players[j]; foreach (Mobile view in mob.GetMobilesInRange(18)) { if (!mob.CanSee(view)) { mob.Send(view.RemovePacket); } } mob.LocalOverheadMessage(MessageType.Emote, 0x3B2, false, "* Your mind focuses intently on the fight and all other distractions fade away *"); } } } else { dc.Unregister(); dc.StopCountdown(); } }
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); StringBuilder 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 (int 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) { TimeSpan until = m_Tournament.SignupStart + m_Tournament.SignupPeriod - DateTime.UtcNow; string text; int secs = (int)until.TotalSeconds; if (secs > 0) { int 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: { Ruleset ruleset = tourney.Ruleset; Ruleset basedef = ruleset.Base; BitArray defs; if (ruleset.Flavors.Count > 0) { defs = new BitArray(basedef.Options); for (int i = 0; i < ruleset.Flavors.Count; ++i) { defs.Or(ruleset.Flavors[i].Options); } } else { defs = basedef.Options; } int changes = 0; BitArray opts = ruleset.Options; for (int 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")); int 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; string 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 (int 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 (int i = 0; i < opts.Length; ++i) { if (defs[i] != opts[i]) { string 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); List <TourneyParticipant> 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 int index, out int count, out int y, 12); for (int i = 0; i < count; ++i, y += 18) { TourneyParticipant part = pList[index + i]; string 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")); int y = 53; AddHtml(25, y, 200, 20, part.Players.Count == 1 ? "Players" : "Team"); y += 20; for (int i = 0; i < part.Players.Count; ++i) { Mobile mob = part.Players[i]; string 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; StringBuilder sb = new StringBuilder(); for (int 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; } Ladder ladder = Ladder.Instance; LadderEntry 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; }