public override void OnResponse(NetState sender, RelayInfo info) { if (info.ButtonID == 1 && info.IsSwitched(1)) { Tournament tourny = this.m_Tournament; Mobile from = this.m_From; switch ( tourny.Stage ) { case TournamentStage.Fighting: { if (this.m_Registrar != null) { if (this.m_Tournament.HasParticipant(from)) { this.m_Registrar.PrivateOverheadMessage(MessageType.Regular, 0x35, false, "Excuse me? You are already signed up.", from.NetState); } else { this.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: { if (this.m_Registrar != null) this.m_Registrar.PrivateOverheadMessage(MessageType.Regular, 0x35, false, "The tournament is closed.", from.NetState); break; } case TournamentStage.Signup: { if (this.m_Players.Count != tourny.PlayersPerParticipant) { if (this.m_Registrar != null) { this.m_Registrar.PrivateOverheadMessage(MessageType.Regular, 0x35, false, "You have not yet chosen your team.", from.NetState); } this.m_From.SendGump(new ConfirmSignupGump(this.m_From, this.m_Registrar, this.m_Tournament, this.m_Players)); break; } Ladder ladder = Ladder.Instance; for (int i = 0; i < this.m_Players.Count; ++i) { Mobile mob = (Mobile)this.m_Players[i]; LadderEntry entry = (ladder == null ? null : ladder.Find(mob)); if (entry != null && Ladder.GetLevel(entry.Experience) < tourny.LevelRequirement) { if (this.m_Registrar != null) { if (mob == from) { this.m_Registrar.PrivateOverheadMessage(MessageType.Regular, 0x35, false, "You have not yet proven yourself a worthy dueler.", from.NetState); } else { this.m_Registrar.PrivateOverheadMessage(MessageType.Regular, 0x35, false, String.Format("{0} has not yet proven themselves a worthy dueler.", mob.Name), from.NetState); } } this.m_From.SendGump(new ConfirmSignupGump(this.m_From, this.m_Registrar, this.m_Tournament, this.m_Players)); return; } else if (tourny.HasParticipant(mob)) { if (this.m_Registrar != null) { if (mob == from) { this.m_Registrar.PrivateOverheadMessage(MessageType.Regular, 0x35, false, "You have already entered this tournament.", from.NetState); } else { this.m_Registrar.PrivateOverheadMessage(MessageType.Regular, 0x35, false, String.Format("{0} has already entered this tournament.", mob.Name), from.NetState); } } this.m_From.SendGump(new ConfirmSignupGump(this.m_From, this.m_Registrar, this.m_Tournament, this.m_Players)); return; } else if (mob is PlayerMobile && ((PlayerMobile)mob).DuelContext != null) { if (this.m_Registrar != null) { if (mob == from) { this.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 { this.m_Registrar.PrivateOverheadMessage(MessageType.Regular, 0x35, false, String.Format("{0} is already assigned to a duel. They must yield it before joining this tournament.", mob.Name), from.NetState); } } this.m_From.SendGump(new ConfirmSignupGump(this.m_From, this.m_Registrar, this.m_Tournament, this.m_Players)); return; } } if (this.m_Registrar != null) { string fmt; if (tourny.PlayersPerParticipant == 1) fmt = "As you say m'{0}. I've written your name to the bracket. The tournament will begin {1}."; else if (tourny.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; int minutesUntil = (int)Math.Round(((tourny.SignupStart + tourny.SignupPeriod) - DateTime.Now).TotalMinutes); if (minutesUntil == 0) timeUntil = "momentarily"; else timeUntil = String.Format("in {0} minute{1}", minutesUntil, minutesUntil == 1 ? "" : "s"); this.m_Registrar.PrivateOverheadMessage(MessageType.Regular, 0x35, false, String.Format(fmt, from.Female ? "Lady" : "Lord", timeUntil), from.NetState); } TournyParticipant part = new TournyParticipant(from); part.Players.Clear(); part.Players.AddRange(this.m_Players); tourny.Participants.Add(part); break; } } } else if (info.ButtonID > 1) { int index = info.ButtonID - 1; if (index > 0 && index < this.m_Players.Count) { this.m_Players.RemoveAt(index); this.m_From.SendGump(new ConfirmSignupGump(this.m_From, this.m_Registrar, this.m_Tournament, this.m_Players)); } else if (this.m_Players.Count < this.m_Tournament.PlayersPerParticipant) { this.m_From.BeginTarget(12, false, TargetFlags.None, new TargetCallback(AddPlayer_OnTarget)); this.m_From.SendGump(new ConfirmSignupGump(this.m_From, this.m_Registrar, this.m_Tournament, this.m_Players)); } } }
public void HandleWon(Arena arena, TournyMatch match, TournyParticipant winner) { StringBuilder sb = new StringBuilder(); sb.Append("The match is complete. "); sb.Append(winner.NameList); if (winner.Players.Count > 1) sb.Append(" have bested "); else sb.Append(" has bested "); if (match.Participants.Count > 2) sb.AppendFormat("{0} other {1}: ", match.Participants.Count - 1, winner.Players.Count == 1 ? "players" : "teams"); bool hasAppended = false; for (int j = 0; j < match.Participants.Count; ++j) { TournyParticipant part = (TournyParticipant)match.Participants[j]; if (part == winner) continue; this.m_Undefeated.Remove(part); if (hasAppended) sb.Append(", "); sb.Append(part.NameList); hasAppended = true; } sb.Append("."); if (this.m_TournyType == TournyType.Standard) this.Alert(arena, sb.ToString()); }
public void AddLevel(int partsPerMatch, ArrayList participants, GroupingType groupType, TournyType tournyType) { ArrayList copy = new ArrayList(participants); if (groupType == GroupingType.Nearest || groupType == GroupingType.HighVsLow) copy.Sort(); PyramidLevel level = new PyramidLevel(); switch ( tournyType ) { case TournyType.RedVsBlue: { TournyParticipant[] parts = new TournyParticipant[2]; for (int i = 0; i < parts.Length; ++i) parts[i] = new TournyParticipant(new ArrayList()); for (int i = 0; i < copy.Count; ++i) { ArrayList players = ((TournyParticipant)copy[i]).Players; for (int j = 0; j < players.Count; ++j) { Mobile mob = (Mobile)players[j]; if (mob.Kills >= 5) parts[0].Players.Add(mob); else parts[1].Players.Add(mob); } } level.Matches.Add(new TournyMatch(new ArrayList(parts))); break; } case TournyType.RandomTeam: { TournyParticipant[] parts = new TournyParticipant[partsPerMatch]; for (int i = 0; i < partsPerMatch; ++i) parts[i] = new TournyParticipant(new ArrayList()); for (int i = 0; i < copy.Count; ++i) parts[i % parts.Length].Players.AddRange(((TournyParticipant)copy[i]).Players); level.Matches.Add(new TournyMatch(new ArrayList(parts))); break; } case TournyType.FreeForAll: { level.Matches.Add(new TournyMatch(copy)); break; } case TournyType.Standard: { if (partsPerMatch == 2 && (participants.Count % 2) == 1) { int lowAdvances = int.MaxValue; for (int i = 0; i < participants.Count; ++i) { TournyParticipant p = (TournyParticipant)participants[i]; if (p.FreeAdvances < lowAdvances) lowAdvances = p.FreeAdvances; } ArrayList toAdvance = new ArrayList(); for (int i = 0; i < participants.Count; ++i) { TournyParticipant p = (TournyParticipant)participants[i]; if (p.FreeAdvances == lowAdvances) toAdvance.Add(p); } if (toAdvance.Count == 0) toAdvance = copy; // sanity int idx = Utility.Random(toAdvance.Count); ((TournyParticipant)toAdvance[idx]).AddLog("Advanced automatically due to an odd number of challengers."); level.FreeAdvance = (TournyParticipant)toAdvance[idx]; ++level.FreeAdvance.FreeAdvances; copy.Remove(toAdvance[idx]); } while (copy.Count >= partsPerMatch) { ArrayList thisMatch = new ArrayList(); for (int i = 0; i < partsPerMatch; ++i) { int idx = 0; switch ( groupType ) { case GroupingType.HighVsLow: idx = (i * (copy.Count - 1)) / (partsPerMatch - 1); break; case GroupingType.Nearest: idx = 0; break; case GroupingType.Random: idx = Utility.Random(copy.Count); break; } thisMatch.Add(copy[idx]); copy.RemoveAt(idx); } level.Matches.Add(new TournyMatch(thisMatch)); } if (copy.Count > 1) level.Matches.Add(new TournyMatch(copy)); break; } } this.m_Levels.Add(level); }
public void AddLevel(int partsPerMatch, List<TournyParticipant> participants, GroupingType groupType, TournyType tournyType) { var copy = new List<TournyParticipant>(participants); if (groupType == GroupingType.Nearest || groupType == GroupingType.HighVsLow) { copy.Sort(); } var level = new PyramidLevel(); switch (tournyType) { case TournyType.RedVsBlue: { var parts = new TournyParticipant[2]; for (int i = 0; i < parts.Length; ++i) { parts[i] = new TournyParticipant(new List<Mobile>()); } for (int i = 0; i < copy.Count; ++i) { List<Mobile> players = copy[i].Players; for (int j = 0; j < players.Count; ++j) { Mobile mob = players[j]; if (mob.Kills >= 5) { parts[0].Players.Add(mob); } else { parts[1].Players.Add(mob); } } } level.Matches.Add(new TournyMatch(new List<TournyParticipant>(parts))); break; } case TournyType.RandomTeam: { var parts = new TournyParticipant[partsPerMatch]; for (int i = 0; i < partsPerMatch; ++i) { parts[i] = new TournyParticipant(new List<Mobile>()); } for (int i = 0; i < copy.Count; ++i) { parts[i % parts.Length].Players.AddRange(copy[i].Players); } level.Matches.Add(new TournyMatch(new List<TournyParticipant>(parts))); break; } case TournyType.FreeForAll: { level.Matches.Add(new TournyMatch(copy)); break; } case TournyType.Standard: { if (partsPerMatch >= 2 && participants.Count % partsPerMatch == 1) { int lowAdvances = int.MaxValue; for (int i = 0; i < participants.Count; ++i) { TournyParticipant p = participants[i]; if (p.FreeAdvances < lowAdvances) { lowAdvances = p.FreeAdvances; } } var toAdvance = new List<TournyParticipant>(); for (int i = 0; i < participants.Count; ++i) { TournyParticipant p = participants[i]; if (p.FreeAdvances == lowAdvances) { toAdvance.Add(p); } } if (toAdvance.Count == 0) { toAdvance = copy; // sanity } int idx = Utility.Random(toAdvance.Count); toAdvance[idx].AddLog("Advanced automatically due to an odd number of challengers."); level.FreeAdvance = toAdvance[idx]; ++level.FreeAdvance.FreeAdvances; copy.Remove(toAdvance[idx]); } while (copy.Count >= partsPerMatch) { var thisMatch = new List<TournyParticipant>(); for (int i = 0; i < partsPerMatch; ++i) { int idx = 0; switch (groupType) { case GroupingType.HighVsLow: idx = (i * (copy.Count - 1)) / (partsPerMatch - 1); break; case GroupingType.Nearest: idx = 0; break; case GroupingType.Random: idx = Utility.Random(copy.Count); break; } thisMatch.Add(copy[idx]); copy.RemoveAt(idx); } level.Matches.Add(new TournyMatch(thisMatch)); } if (copy.Count > 1) { level.Matches.Add(new TournyMatch(copy)); } break; } } m_Levels.Add(level); }