Created
April 4, 2014 01:23
-
-
Save MrBluePotato/9966216 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Voting | |
public void TakeVote() | |
{ | |
if (!VoteIsOn) return; | |
//Actual voting | |
if (!_votingRestarting) | |
{ | |
World[] voteWorlds = PropHuntWorlds.OrderBy(x => RandWorld.Next()) | |
.Take(3) | |
.ToArray(); | |
World1 = voteWorlds[0]; | |
World2 = voteWorlds[1]; | |
World3 = voteWorlds[2]; | |
//Stop the game before voting | |
_task.Stop(); | |
_checkIdlesTask.Stop(); | |
Player.Moving -= PlayerMovingHandler; | |
if (PropHuntPlayers != null) | |
{ | |
lock (PropHuntPlayers.ToList()) | |
{ | |
foreach (Player p in PropHuntPlayers.ToList()) | |
{ | |
RevertPlayer(p); | |
} | |
} | |
} | |
} | |
if (_votingRestarting) _votingRestarting = false; | |
Server.Players.Message("&S--------------------------------------------------------------"); | |
Server.Players.Message("&SVote for the next map!"); | |
Server.Players.Message("&S/Vote &c1&S for {0}&S, &c2&S for {1}&S, and &c3&S for {2}", | |
World1.ClassyName, World2.ClassyName, World3.ClassyName); | |
Server.Players.Message("&S--------------------------------------------------------------"); | |
Scheduler.NewTask(task => VoteCheck()) | |
.RunOnce(TimeSpan.FromSeconds(60)); | |
} | |
public void VoteCheck() | |
{ | |
if (!VoteIsOn) return; | |
if (Voted1 > Voted2 || Voted1 > Voted3) | |
{ | |
_winningWorld = World1; | |
} | |
else if (Voted2 > Voted1 || Voted2 > Voted3) | |
{ | |
_winningWorld = World2; | |
} | |
else if (Voted3 > Voted1 || Voted3 > Voted2) | |
{ | |
_winningWorld = World3; | |
} | |
else if (!Voted.Any()) | |
{ | |
Logger.Log(LogType.Warning, "There we no votes. Voting will restart."); | |
Server.Message("&WThere were no votes. Voting will restart."); | |
_votingRestarting = true; | |
TakeVote(); | |
return; | |
} | |
Server.Players.Message("&S--------------------------------------------------------------"); | |
Server.Players.Message("&SThe results are in! &A{0}&S:&C {1}, &A{2}&S:&C {3}, &A{4}&S:&C {5}", | |
World1.ClassyName, | |
Voted1, World2.ClassyName, Voted2, World3.ClassyName, Voted3); | |
Server.Players.Message("&SThe next map is: {0}", _winningWorld.ClassyName); | |
Server.Players.Message("&S--------------------------------------------------------------"); | |
VoteIsOn = false; | |
foreach (Player p in Voted) | |
{ | |
p.HasVoted = false; | |
} | |
foreach (Player p in PropHuntPlayers) | |
{ | |
#if DEBUG | |
p.Message("Joining new world."); | |
#endif | |
p.JoinWorld(_winningWorld); | |
} | |
var game = new PropHunt(_winningWorld); | |
Voted1 = 0; | |
Voted2 = 0; | |
Voted3 = 0; | |
game.Start(); | |
_restartGame = true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment