Do test for round end on main zombie thread instead of separate timer, avoids issues when using /zg force then /zg start again. (Thanks goodlyay)

This commit is contained in:
UnknownShadow200 2016-04-23 17:08:43 +10:00
parent 4ef88d5867
commit ec137eb52a
5 changed files with 16 additions and 22 deletions

View File

@ -39,7 +39,7 @@ namespace MCGalaxy.Commands {
WhoInfo info = new WhoInfo();
string prefix = who.title == "" ? "" : "[" + who.titlecolor + who.title + who.color + "] ";
info.FullName = prefix + who.DisplayName;
info.FullName = prefix + who.ColoredName;
info.Name = who.name;
info.Group = who.group;
info.Money = who.money; info.Deaths = who.overallDeath;

View File

@ -51,7 +51,7 @@ namespace MCGalaxy.Commands {
string prefix = target.title == "" ? "" : "[" + target.titleColor + target.title + color + "] ";
WhoInfo info = new WhoInfo();
info.FullName = prefix + target.name.TrimEnd('+');
info.FullName = prefix + color + target.name.TrimEnd('+');
info.Name = target.name;
info.Group = group;
info.Money = int.Parse(target.money); info.Deaths = int.Parse(target.deaths);

View File

@ -40,7 +40,7 @@ namespace MCGalaxy.Commands {
Player.SendMessage(p, ">> &a" + who.Deaths + " &cdeaths%s, " + Awards.AwardAmount(who.Name) + " awards");
if (who.LoginBlocks >= 0)
Player.SendMessage(p, ">> &bModified &a" + who.TotalBlocks + " &eblocks, &a" + who.LoginBlocks + " &e since login.");
Player.SendMessage(p, ">> &bModified &a" + who.TotalBlocks + " &eblocks, &a" + who.LoginBlocks + " &esince login");
else
Player.SendMessage(p, ">> &bModified &a" + who.TotalBlocks + " &eblocks");
@ -56,7 +56,7 @@ namespace MCGalaxy.Commands {
Player.SendMessage(p, ">> First login on &a" + who.First.ToString("yyyy-MM-dd")
+ "%S, and is currently &aonline");
Player.SendMessage(p, ">> Logged in &a" + who.Logins + " %Stimes, &c" + who.Kicks + " %Sof which ended in a kick.");
Player.SendMessage(p, ">> Logged in &a" + who.Logins + " %Stimes, &c" + who.Kicks + " %Sof which ended in a kick");
string[] data = Ban.GetBanData(who.Name);
if (data != null)
Player.SendMessage(p, ">> is banned for " + data[1] + " by " + data[0]);

View File

@ -91,10 +91,7 @@ namespace MCGalaxy.Games {
string suffix = roundMins == 1 ? " %Sminute!" : " %Sminutes!";
CurLevel.ChatLevel("The round will last for &a" + roundMins + suffix);
RoundEnd = DateTime.UtcNow.AddMinutes(roundMins);
timer = new System.Timers.Timer(roundMins * 60 * 1000);
timer.Elapsed += new ElapsedEventHandler(EndRound);
timer.Enabled = true;
Player[] online = PlayerInfo.Online.Items;
foreach (Player p in online) {
if (p.level == null || p.level != CurLevel || p.Game.Referee) continue;
@ -161,10 +158,19 @@ namespace MCGalaxy.Games {
void DoCoreGame(Random random) {
Player[] alive = null;
string lastTimespan = null;
while ((alive = Alive.Items).Length > 0) {
int lastTime = -1;
while ((alive = Alive.Items).Length > 0 && Running) {
Player[] infected = Infected.Items;
// Update the round time left shown in the top right
// Do round end.
int seconds = (int)(RoundEnd - DateTime.UtcNow).TotalSeconds;
if (seconds <= 0) { HandOutRewards(); return; }
if (seconds <= 5 && seconds != lastTime) {
CurLevel.ChatLevel("%4Round End:%f " + seconds);
lastTime = seconds;
}
// Update the round time left shown in the top right
string timespan = GetTimespan(seconds);
if (lastTimespan != timespan) {
UpdateAllPlayerStatus(timespan);
@ -289,16 +295,6 @@ namespace MCGalaxy.Games {
Entities.GlobalDespawn(p, true);
Entities.GlobalSpawn(p, true);
}
void EndRound(object sender, ElapsedEventArgs e) {
if (!Running) return;
CurLevel.ChatLevel("%4Round End:%f 5"); Thread.Sleep(1000);
CurLevel.ChatLevel("%4Round End:%f 4"); Thread.Sleep(1000);
CurLevel.ChatLevel("%4Round End:%f 3"); Thread.Sleep(1000);
CurLevel.ChatLevel("%4Round End:%f 2"); Thread.Sleep(1000);
CurLevel.ChatLevel("%4Round End:%f 1"); Thread.Sleep(1000);
HandOutRewards();
}
public void HandOutRewards() {
if (!RoundInProgress) return;
@ -314,7 +310,6 @@ namespace MCGalaxy.Games {
else if (alive.Length == 1) CurLevel.ChatLevel(Colors.green + "Congratulations to the sole survivor:");
else CurLevel.ChatLevel(Colors.green + "Congratulations to the survivors:");
timer.Enabled = false;
string playersString = "";
Player[] online = null;
CurLevel.RoundsPlayed++;

View File

@ -67,7 +67,6 @@ namespace MCGalaxy.Games {
/// <summary> Time at which the next round is scheduled to end. </summary>
public DateTime RoundEnd;
public static System.Timers.Timer timer;
public bool initialChangeLevel = false;
/// <summary> The name of the level that the last round of zombie survival was played on. </summary>