private void End(TournamentBattle b, TournamentTeam t) { DateEnd = DateTime.UtcNow; foreach (var pm in Players.Where(p => IsAlive(p) && b.IsParticipant(p))) { b.RefreshStats(pm, true, true); b.TeleportToHomeBase(t, pm); } }
public static TournamentArchive CreateArchive(TournamentBattle b) { TournamentArchive a = null; foreach (var r in b.Matches.Where(o => !o.IsDisposed && o.IsComplete && o.Records.Count > 0)) { if (a == null) { a = new TournamentArchive(b.Name, DateTime.UtcNow); } a.Matches.Add(r); } if (a != null) { Registry.Add(a); } return(a); }
public void Sync(TournamentBattle b, TournamentTeam t) { if (IsDisposed || IsComplete) { return; } if (b == null || b.Deleted || b.IsInternal || b.IsQueueing || b.IsPreparing) { return; } if (t == null || t.Deleted || t.Serial.ValueHash != Team) { return; } if (b.IsRunning && DateStart == DateTime.MinValue) // Populate & Start { for (var i = 0; i < Capacity; i++) { var pm = Players[i]; if (pm != null && !b.IsAliveParticipant(pm)) { Players[i] = null; Dead[i] = false; Statistics[i].SetAll(0); Broadcast(0x22, "{0} has left the match! [{1} / {2}]", pm.RawName, Count, Capacity); } } if (!IsFull) { var q = b.GetMatchQueue(Capacity - Count); for (var i = 0; i < Capacity && q.Count > 0; i++) { var pm = Players[i]; if (pm == null) { Players[i] = pm = q.Dequeue(); Dead[i] = false; Statistics[i].SetAll(0); Broadcast(0x55, "{0} has joined the match! [{1} / {2}]", pm.RawName, Count, Capacity); } } q.Free(true); } if (IsFull) { Broadcast("The match is now full, prepare to fight!"); Start(b, t); } } else if (b.IsRunning && Expire > TimeSpan.Zero) // Tick { var started = !IsDelayed; if (_MessageBuffer <= Core.TickCount) { var time = started ? Expire : ((DateStart + Delay) - DateTime.UtcNow); if (time.Hours > 0 && time.Hours <= 3) { _MessageBuffer = Core.TickCount + (Math.Min(15, time.Minutes) * 60000); } else if (time.Minutes > 0 && time.Minutes <= 5) { _MessageBuffer = Core.TickCount + (Math.Min(15, time.Seconds) * 1000); } else if (time.Seconds > 0 && time.Seconds <= 10) { _MessageBuffer = Core.TickCount + Math.Min(1000, time.Milliseconds); } else { _MessageBuffer = Int64.MaxValue; } var seconds = (int)Math.Ceiling(time.TotalSeconds); if (seconds > 5) { Broadcast( "The match will {0} in {1} second{2}!", !started ? "begin" : "end", seconds, seconds != 1 ? "s" : String.Empty); } else if (seconds > 0) { Broadcast("{0}...", seconds); } else { Broadcast(!started ? "FIGHT!" : "CEASE!"); } } PlayerMobile o = null; var count = 0; foreach (var pm in Players.Where(p => IsAlive(p) && b.IsAliveParticipant(p)).OrderBy(ComputeScore)) { o = pm; ++count; } if (count <= 1) { if (!started) { Broadcast("Not enough players to start the match."); } Winner = o; if (Winner != null) { if (!started) { Broadcast("{0} has won the match by default!", Winner.RawName); } else { Broadcast("{0} has won the match!", Winner.RawName); } } else { Broadcast("No winner has been declared."); } End(b, t); } } else if ((b.IsRunning || b.IsEnded) && DateEnd == DateTime.MaxValue) // End { var started = !IsDelayed; if (started) { Broadcast("TIME UP!"); } Winner = Players.Where(p => IsAlive(p) && b.IsAliveParticipant(p)).Highest(ComputeScore); if (Winner != null) { if (!started) { Broadcast("{0} has won the match by default!", Winner.RawName); } else { Broadcast("{0} has won the match!", Winner.RawName); } } else { Broadcast("No winner has been declared."); } End(b, t); } }
public TournamentMatch(int index, TournamentBattle battle, TournamentTeam team) : this(index, team.Serial.ValueHash, battle.MatchDelay, battle.MatchDuration) { }
public TournamentArchiveUI(Mobile user, TournamentBattle battle, Gump parent = null) : this(user, (IEnumerable <TournamentMatch>)battle, parent) { }