mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-27 23:43:45 -04:00
Modularise core zombie code some more, poll player positions every 50ms instead of every 500ms, also rounds start after 30 seconds not two minutes.
This commit is contained in:
parent
2752a9e018
commit
6b04139c5b
@ -45,7 +45,7 @@ namespace MCGalaxy.Commands
|
|||||||
Player.SendMessage(p, "There is a one-time Zombie Survival game currently in progress.");
|
Player.SendMessage(p, "There is a one-time Zombie Survival game currently in progress.");
|
||||||
return;
|
return;
|
||||||
case 3:
|
case 3:
|
||||||
Player.SendMessage(p, "There is a Zombie Survival game currently in progress with a " + Server.zombie.limitRounds + " amount of rounds.");
|
Player.SendMessage(p, "There is a Zombie Survival game currently in progress with a " + Server.zombie.MaxRounds + " amount of rounds.");
|
||||||
return;
|
return;
|
||||||
case 4:
|
case 4:
|
||||||
Player.SendMessage(p, "There is a Zombie Survival game currently in progress, scheduled to stop after this round.");
|
Player.SendMessage(p, "There is a Zombie Survival game currently in progress, scheduled to stop after this round.");
|
||||||
|
@ -37,14 +37,14 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
zombieRound = false;
|
zombieRound = false;
|
||||||
amountOfRounds++;
|
RoundsDone++;
|
||||||
|
|
||||||
if (gameStatus == 0) { return; }
|
if (gameStatus == 0) { return; }
|
||||||
else if (gameStatus == 1) { DoRound(); if (ChangeLevels) ChangeLevel();}
|
else if (gameStatus == 1) { DoRound(); if (ChangeLevels) ChangeLevel();}
|
||||||
else if (gameStatus == 2) { DoRound(); if (ChangeLevels) ChangeLevel(); gameStatus = 0; return; }
|
else if (gameStatus == 2) { DoRound(); if (ChangeLevels) ChangeLevel(); gameStatus = 0; return; }
|
||||||
else if (gameStatus == 3)
|
else if (gameStatus == 3)
|
||||||
{
|
{
|
||||||
if (limitRounds == amountOfRounds) { ResetState(); return; }
|
if (RoundsDone == MaxRounds) { ResetState(); return; }
|
||||||
else { DoRound(); if (ChangeLevels) ChangeLevel(); }
|
else { DoRound(); if (ChangeLevels) ChangeLevel(); }
|
||||||
}
|
}
|
||||||
else if (gameStatus == 4) { ResetState(); return; }
|
else if (gameStatus == 4) { ResetState(); return; }
|
||||||
@ -54,79 +54,91 @@ namespace MCGalaxy {
|
|||||||
void DoRound()
|
void DoRound()
|
||||||
{
|
{
|
||||||
if (gameStatus == 0) return;
|
if (gameStatus == 0) return;
|
||||||
GoBack: Player.GlobalMessage("%4Round Start:%f 2:00");
|
List<Player> players = DoRoundCountdown();
|
||||||
Thread.Sleep(60000); if (!Server.ZombieModeOn) return;
|
|
||||||
Player.GlobalMessage("%4Round Start:%f 1:00");
|
|
||||||
Thread.Sleep(55000); if (!Server.ZombieModeOn) return;
|
|
||||||
Server.s.Log(Convert.ToString(ChangeLevels) + " " + Convert.ToString(Server.ZombieOnlyServer) + " " + Convert.ToString(UseLevelList) + " " + string.Join(",", LevelList.ToArray()));
|
|
||||||
Player.GlobalMessage("%4Round Start:%f 5...");
|
|
||||||
Thread.Sleep(1000); if (!Server.ZombieModeOn) return;
|
|
||||||
Player.GlobalMessage("%4Round Start:%f 4...");
|
|
||||||
Thread.Sleep(1000); if (!Server.ZombieModeOn) return;
|
|
||||||
Player.GlobalMessage("%4Round Start:%f 3...");
|
|
||||||
Thread.Sleep(1000); if (!Server.ZombieModeOn) return;
|
|
||||||
Player.GlobalMessage("%4Round Start:%f 2...");
|
|
||||||
Thread.Sleep(1000); if (!Server.ZombieModeOn) return;
|
|
||||||
Player.GlobalMessage("%4Round Start:%f 1...");
|
|
||||||
Thread.Sleep(1000); if (!Server.ZombieModeOn) return;
|
|
||||||
zombieRound = true;
|
|
||||||
int playerscountminusref = 0; List<Player> players = new List<Player>();
|
|
||||||
|
|
||||||
Player[] online = PlayerInfo.Online;
|
|
||||||
foreach (Player p in online) {
|
|
||||||
if (p.referee) {
|
|
||||||
p.color = p.group.color;
|
|
||||||
} else if (p.level.name == currentLevelName) {
|
|
||||||
p.color = p.group.color;
|
|
||||||
players.Add(p);
|
|
||||||
playerscountminusref++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (playerscountminusref < 2) {
|
|
||||||
Player.GlobalMessage(Colors.red + "ERROR: Need more than 2 players to play");
|
|
||||||
goto GoBack;
|
|
||||||
}
|
|
||||||
|
|
||||||
theEnd:
|
theEnd:
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
int firstinfect = random.Next(players.Count());
|
int firstinfect = random.Next(players.Count());
|
||||||
Player player = null;
|
Player player = null;
|
||||||
if (queZombie)
|
if (queZombie) player = PlayerInfo.Find(nextZombie);
|
||||||
player = PlayerInfo.Find(nextZombie);
|
else player = players[firstinfect];
|
||||||
else
|
|
||||||
player = players[firstinfect];
|
|
||||||
|
|
||||||
if (player.level.name != currentLevelName) goto theEnd;
|
if (player.level.name != currentLevelName) goto theEnd;
|
||||||
|
|
||||||
Player.GlobalMessage(player.color + player.name + Server.DefaultColor + " started the infection!");
|
Player.GlobalMessage(player.color + player.name + " %Sstarted the infection!");
|
||||||
player.infected = true;
|
player.infected = true;
|
||||||
player.color = Colors.red;
|
player.color = Colors.red;
|
||||||
Player.GlobalDespawn(player, false);
|
Player.GlobalDespawn(player, false);
|
||||||
Player.GlobalSpawn(player, player.pos[0], player.pos[1], player.pos[2], player.rot[0], player.rot[1], false);
|
Player.GlobalSpawn(player, player.pos[0], player.pos[1], player.pos[2], player.rot[0], player.rot[1], false);
|
||||||
|
|
||||||
zombieRound = true;
|
zombieRound = true;
|
||||||
int roundMins = random.Next(5, 12);
|
int roundMins = random.Next(5, 8);
|
||||||
Player.GlobalMessage("The round will last for " + roundMins + " minutes!");
|
Player.GlobalMessage("The round will last for " + roundMins + " minutes!");
|
||||||
timer = new System.Timers.Timer(roundMins * 60 * 1000);
|
timer = new System.Timers.Timer(roundMins * 60 * 1000);
|
||||||
timer.Elapsed += new ElapsedEventHandler(EndRound);
|
timer.Elapsed += new ElapsedEventHandler(EndRound);
|
||||||
timer.Enabled = true;
|
timer.Enabled = true;
|
||||||
|
|
||||||
online = PlayerInfo.Online;
|
Player[] online = PlayerInfo.Online;
|
||||||
foreach (Player p in online)
|
foreach (Player p in online) {
|
||||||
{
|
if (p != player)
|
||||||
if(p != player)
|
|
||||||
alive.Add(p);
|
alive.Add(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
infectd.Clear();
|
infectd.Clear();
|
||||||
if (queZombie)
|
if (queZombie) infectd.Add(PlayerInfo.Find(nextZombie));
|
||||||
infectd.Add(PlayerInfo.Find(nextZombie));
|
else infectd.Add(player);
|
||||||
else
|
|
||||||
infectd.Add(player);
|
|
||||||
aliveCount = alive.Count;
|
aliveCount = alive.Count;
|
||||||
|
DoCoreGame(players, random);
|
||||||
|
|
||||||
while (aliveCount > 0)
|
if (gameStatus == 0) {
|
||||||
{
|
gameStatus = 4; return;
|
||||||
|
} else {
|
||||||
|
HandOutRewards();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Player> DoRoundCountdown() {
|
||||||
|
while (true) {
|
||||||
|
string logMessage = Convert.ToString(ChangeLevels) + " " + Convert.ToString(Server.ZombieOnlyServer) +
|
||||||
|
" " + Convert.ToString(UseLevelList) + " " + string.Join(",", LevelList.ToArray());
|
||||||
|
Server.s.Log(logMessage);
|
||||||
|
|
||||||
|
Player.GlobalMessage("%4Round Start:%f 30...");
|
||||||
|
Thread.Sleep(45000); if (!Server.ZombieModeOn) return null;
|
||||||
|
Player.GlobalMessage("%4Round Start:%f 10...");
|
||||||
|
Thread.Sleep(10000); if (!Server.ZombieModeOn) return null;
|
||||||
|
Player.GlobalMessage("%4Round Start:%f 5...");
|
||||||
|
Thread.Sleep(1000); if (!Server.ZombieModeOn) return null;
|
||||||
|
Player.GlobalMessage("%4Round Start:%f 4...");
|
||||||
|
Thread.Sleep(1000); if (!Server.ZombieModeOn) return null;
|
||||||
|
Player.GlobalMessage("%4Round Start:%f 3...");
|
||||||
|
Thread.Sleep(1000); if (!Server.ZombieModeOn) return null;
|
||||||
|
Player.GlobalMessage("%4Round Start:%f 2...");
|
||||||
|
Thread.Sleep(1000); if (!Server.ZombieModeOn) return null;
|
||||||
|
Player.GlobalMessage("%4Round Start:%f 1...");
|
||||||
|
Thread.Sleep(1000); if (!Server.ZombieModeOn) return null;
|
||||||
|
zombieRound = true;
|
||||||
|
int nonRefPlayers = 0;
|
||||||
|
List<Player> players = new List<Player>();
|
||||||
|
|
||||||
|
Player[] online = PlayerInfo.Online;
|
||||||
|
foreach (Player p in online) {
|
||||||
|
if (p.referee) {
|
||||||
|
p.color = p.group.color;
|
||||||
|
} else if (p.level.name == currentLevelName) {
|
||||||
|
p.color = p.group.color;
|
||||||
|
players.Add(p);
|
||||||
|
nonRefPlayers++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nonRefPlayers >= 2) return players;
|
||||||
|
Player.GlobalMessage(Colors.red + "ERROR: Need 2 or more players to play");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DoCoreGame(List<Player> players, Random random) {
|
||||||
|
while (aliveCount > 0) {
|
||||||
aliveCount = alive.Count;
|
aliveCount = alive.Count;
|
||||||
infectd.ForEach(delegate(Player pKiller)
|
infectd.ForEach(delegate(Player pKiller)
|
||||||
{
|
{
|
||||||
@ -186,26 +198,16 @@ namespace MCGalaxy {
|
|||||||
pKiller.playersInfected = pKiller.playersInfected++;
|
pKiller.playersInfected = pKiller.playersInfected++;
|
||||||
Player.GlobalDespawn(pAlive, false);
|
Player.GlobalDespawn(pAlive, false);
|
||||||
Player.GlobalSpawn(pAlive, pAlive.pos[0], pAlive.pos[1], pAlive.pos[2], pAlive.rot[0], pAlive.rot[1], false);
|
Player.GlobalSpawn(pAlive, pAlive.pos[0], pAlive.pos[1], pAlive.pos[2], pAlive.rot[0], pAlive.rot[1], false);
|
||||||
Thread.Sleep(500);
|
Thread.Sleep(50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Thread.Sleep(500);
|
Thread.Sleep(50);
|
||||||
}
|
|
||||||
if (gameStatus == 0)
|
|
||||||
{
|
|
||||||
gameStatus = 4;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
HandOutRewards();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EndRound(object sender, ElapsedEventArgs e)
|
public void EndRound(object sender, ElapsedEventArgs e) {
|
||||||
{
|
|
||||||
if (gameStatus == 0) return;
|
if (gameStatus == 0) return;
|
||||||
Player.GlobalMessage("%4Round End:%f 5"); Thread.Sleep(1000);
|
Player.GlobalMessage("%4Round End:%f 5"); Thread.Sleep(1000);
|
||||||
Player.GlobalMessage("%4Round End:%f 4"); Thread.Sleep(1000);
|
Player.GlobalMessage("%4Round End:%f 4"); Thread.Sleep(1000);
|
||||||
@ -215,8 +217,7 @@ namespace MCGalaxy {
|
|||||||
HandOutRewards();
|
HandOutRewards();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandOutRewards()
|
public void HandOutRewards() {
|
||||||
{
|
|
||||||
zombieRound = false;
|
zombieRound = false;
|
||||||
if (gameStatus == 0) return;
|
if (gameStatus == 0) return;
|
||||||
Player.GlobalMessage(Colors.lime + "The game has ended!");
|
Player.GlobalMessage(Colors.lime + "The game has ended!");
|
||||||
|
@ -35,10 +35,13 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed partial class ZombieGame
|
public sealed partial class ZombieGame {
|
||||||
{
|
/// <summary> The number of rounds that have been played in this game so far. </summary>
|
||||||
public int amountOfRounds = 0;
|
public int RoundsDone = 0;
|
||||||
public int limitRounds = 0;
|
|
||||||
|
/// <summary> The maximum number of rounds that can be played before the game ends. </summary>
|
||||||
|
public int MaxRounds = 0;
|
||||||
|
|
||||||
public int aliveCount = 0;
|
public int aliveCount = 0;
|
||||||
public string currentZombieLevel = "";
|
public string currentZombieLevel = "";
|
||||||
public static System.Timers.Timer timer;
|
public static System.Timers.Timer timer;
|
||||||
@ -79,8 +82,8 @@ namespace MCGalaxy {
|
|||||||
gameStatus = status;
|
gameStatus = status;
|
||||||
zombieRound = false;
|
zombieRound = false;
|
||||||
initialChangeLevel = false;
|
initialChangeLevel = false;
|
||||||
limitRounds = amount + 1;
|
MaxRounds = amount + 1;
|
||||||
amountOfRounds = 0;
|
RoundsDone = 0;
|
||||||
//SET ALL THE VARIABLES?!?
|
//SET ALL THE VARIABLES?!?
|
||||||
|
|
||||||
//Start the main Zombie thread
|
//Start the main Zombie thread
|
||||||
@ -204,7 +207,7 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
public void ResetState() {
|
public void ResetState() {
|
||||||
gameStatus = 0;
|
gameStatus = 0;
|
||||||
limitRounds = 0;
|
MaxRounds = 0;
|
||||||
initialChangeLevel = false;
|
initialChangeLevel = false;
|
||||||
Server.ZombieModeOn = false;
|
Server.ZombieModeOn = false;
|
||||||
zombieRound = false;
|
zombieRound = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user