Cleanup parts of the core in zombie survival and fix some bugs with it.

This commit is contained in:
UnknownShadow200 2016-03-20 22:15:58 +11:00
parent f702c72e6c
commit 551f66145f
16 changed files with 305 additions and 310 deletions

View File

@ -20,8 +20,7 @@ using MCGalaxy.Games;
namespace MCGalaxy.Commands {
public sealed class CmdTeam : Command {
public sealed class CmdTeam : Command {
public override string name { get { return "team"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Games; } }
@ -29,6 +28,7 @@ namespace MCGalaxy.Commands {
public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
public override void Use(Player p, string message) {
if (p == null) { MessageInGameOnly(p); return; }
if (message == "") { Help(p); return; }
string[] args = message.Split(' ');
@ -49,6 +49,12 @@ namespace MCGalaxy.Commands {
HandleLeave(p, args); break;
case "members":
HandleMembers(p, args); break;
default:
Team team = p.GameTeam;
if (team == null) {
Player.SendMessage(p, "You need to be in a team first to send a team message."); return;
}
team.Chat(p, message); break;
}
}
@ -175,7 +181,6 @@ namespace MCGalaxy.Commands {
}
public override void Help(Player p) {
//.. team message?
Player.SendMessage(p, "%T/team owner <name> %H-Sets the player who has owner priveliges for the team.");
Player.SendMessage(p, "%T/team kick [name] %H-Removes that player from the team you are in.");
Player.SendMessage(p, "%T/team color [color] %H-Sets the color of the team name shown in chat.");
@ -185,6 +190,7 @@ namespace MCGalaxy.Commands {
Player.SendMessage(p, "%T/team invite [name] %H-Invites that player to join your team.");
Player.SendMessage(p, "%T/team leave %H-Removes you from the team you are in.");
Player.SendMessage(p, "%T/team members [name] %H-Lists the players within that team.");
Player.SendMessage(p, "%HAnything else is sent as a message to all members of the team.");
}
}
}

View File

@ -1,26 +1,25 @@
/*
Copyright 2010 MCLawl Team - Written by Valek (Modified for use with MCGalaxy)
Copyright 2010 MCLawl Team - Written by Valek (Modified for use with MCGalaxy)
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.osedu.org/licenses/ECL-2.0
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.osedu.org/licenses/ECL-2.0
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using MCGalaxy.Games;
namespace MCGalaxy.Commands
{
public sealed class CmdAlive : Command
{
namespace MCGalaxy.Commands {
public sealed class CmdAlive : Command {
public override string name { get { return "alive"; } }
public override string shortcut { get { return "alive"; } }
public override string type { get { return CommandTypes.Games; } }
@ -29,25 +28,20 @@ namespace MCGalaxy.Commands
public override bool Enabled { get { return Server.ZombieModeOn; } }
public CmdAlive() { }
public override void Use(Player p, string message)
{
if (ZombieGame.alive.Count == 0)
{
Player.SendMessage(p, "No one is alive.");
}
else
{
Player.SendMessage(p, "Players who are " + Colors.green + "alive " + Server.DefaultColor + "are:");
string playerstring = "";
ZombieGame.alive.ForEach(delegate(Player player)
{
playerstring = playerstring + player.group.color + player.name + Server.DefaultColor + ", ";
});
Player.SendMessage(p, playerstring);
public override void Use(Player p, string message) {
Player[] alive = Server.zombie.Alive.Items;
if (alive.Length == 0) {
Player.SendMessage(p, "No one is alive."); return;
}
Player.SendMessage(p, "Players who are " + Colors.green + "alive %Sare:");
string list = "";
foreach (Player pl in alive)
list = list + pl.group.color + pl.DisplayName + "%S, ";
Player.SendMessage(p, list);
}
public override void Help(Player p)
{
public override void Help(Player p) {
Player.SendMessage(p, "/alive - shows who is alive");
}
}

View File

@ -1,53 +1,47 @@
/*
Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using MCGalaxy.Games;
namespace MCGalaxy.Commands
{
public sealed class CmdInfected : Command
{
namespace MCGalaxy.Commands {
public sealed class CmdInfected : Command {
public override string name { get { return "infected"; } }
public override string shortcut { get { return "dead"; } }
public override string type { get { return CommandTypes.Games; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
public override bool Enabled { get { return Server.ZombieModeOn; } }
public override bool Enabled { get { return Server.ZombieModeOn; } }
public CmdInfected() { }
public override void Use(Player p, string message)
{
if (ZombieGame.infectd.Count == 0)
{
Player.SendMessage(p, "No one is infected");
}
else
{
Player.SendMessage(p, "Players who are " + Colors.red + "infected %Sare:");
string playerstring = "";
ZombieGame.infectd.ForEach(delegate(Player player)
{
playerstring = playerstring + Colors.red + player.DisplayName + "%S, ";
});
Player.SendMessage(p, playerstring);
public override void Use(Player p, string message) {
Player[] infected = Server.zombie.Infected.Items;
if (infected.Length == 0) {
Player.SendMessage(p, "No one is infected"); return;
}
Player.SendMessage(p, "Players who are " + Colors.red + "infected %Sare:");
string list = "";
foreach (Player pl in infected)
list = list + Colors.red + pl.DisplayName + "%S, ";
Player.SendMessage(p, list);
}
public override void Help(Player p)
{
public override void Help(Player p) {
Player.SendMessage(p, "/infected - shows who is infected");
}
}

View File

@ -1,26 +1,25 @@
/*
Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using MCGalaxy.Games;
namespace MCGalaxy.Commands
{
public sealed class CmdReferee : Command
{
namespace MCGalaxy.Commands {
public sealed class CmdReferee : Command {
public override string name { get { return "ref"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Moderation; } }
@ -29,54 +28,36 @@ namespace MCGalaxy.Commands
public override bool Enabled { get { return Server.ZombieModeOn; } }
public CmdReferee() { }
public override void Use(Player p, string message)
{
public override void Use(Player p, string message) {
if (p == null) { MessageInGameOnly(p); return; }
if (p.referee)
{
if (p.referee) {
p.referee = false;
LevelPermission perm = Group.findPlayerGroup(name).Permission;
Player.GlobalDespawn(p, false);
Player.SendChatFrom(p, p.FullName + " %Sis no longer a referee", false);
if (Server.zombie.RoundInProgress)
{
if (Server.zombie.RoundInProgress) {
Server.zombie.InfectPlayer(p);
}
else
{
} else {
Player.GlobalDespawn(p, false);
Player.GlobalSpawn(p, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1], false);
ZombieGame.infectd.Remove(p);
ZombieGame.alive.Add(p);
Server.zombie.Infected.Remove(p);
Server.zombie.Alive.Add(p);
p.color = p.group.color;
}
}
else
{
} else {
p.referee = true;
Player.SendChatFrom(p, p.FullName + " %Sis now a referee", false);
Player.GlobalDespawn(p, false);
Server.zombie.Alive.Remove(p);
Server.zombie.Infected.Remove(p);
p.color = p.group.color;
if (Server.zombie.RoundInProgress)
{
p.color = p.group.color;
try
{
ZombieGame.infectd.Remove(p);
ZombieGame.alive.Remove(p);
}
catch { }
Server.zombie.InfectedPlayerDC();
}
else
{
ZombieGame.infectd.Remove(p);
ZombieGame.alive.Remove(p);
p.color = p.group.color;
}
Server.zombie.AssignFirstZombie();
}
}
public override void Help(Player p)
{
public override void Help(Player p) {
Player.SendMessage(p, "/referee - Turns referee mode on/off.");
}
}

View File

@ -87,7 +87,7 @@ namespace MCGalaxy.Commands
Player.SendMessage(p, "There is no Zombie Survival game currently in progress."); return;
}
Server.s.Log("Zombie Survival ended forcefully by " + p.name);
Server.zombie.aliveCount = 0;
Server.zombie.Alive.Clear();
Server.zombie.ResetState();
}

View File

@ -152,7 +152,7 @@ namespace MCGalaxy.Commands {
return true;
}
void CheckGamesJoin(Player p, Level oldLvl) {
internal static void CheckGamesJoin(Player p, Level oldLvl) {
Server.lava.PlayerJoinedLevel(p, oldLvl);
Server.zombie.PlayerJoinedLevel(p, oldLvl);

View File

@ -64,23 +64,24 @@ namespace MCGalaxy.Games {
if (Status == ZombieGameStatus.NotStarted) return;
List<Player> players = DoRoundCountdown();
RoundInProgress = true;
theEnd:
Random random = new Random();
pickFirst:
int firstinfect = random.Next(players.Count());
Player player = null;
if (queZombie) player = PlayerInfo.Find(nextZombie);
else player = players[firstinfect];
Player first = null;
if (queZombie) first = PlayerInfo.Find(nextZombie);
else first = players[firstinfect];
queZombie = false;
if (player.level.name != currentLevelName) goto theEnd;
if (!first.level.name.CaselessEq(CurrentLevelName)) goto pickFirst;
Player.GlobalMessage(player.color + player.name + " %Sstarted the infection!");
player.infected = true;
UpdatePlayerColor(player, Colors.red);
CurrentLevel.ChatLevel(first.color + first.name + " %Sstarted the infection!");
first.infected = true;
UpdatePlayerColor(first, Colors.red);
RoundInProgress = true;
int roundMins = random.Next(5, 8);
Player.GlobalMessage("The round will last for " + roundMins + " minutes!");
CurrentLevel.ChatLevel("The round will last for " + roundMins + " minutes!");
RoundEnd = DateTime.UtcNow.AddMinutes(roundMins);
timer = new System.Timers.Timer(roundMins * 60 * 1000);
timer.Elapsed += new ElapsedEventHandler(EndRound);
@ -88,14 +89,12 @@ namespace MCGalaxy.Games {
Player[] online = PlayerInfo.Online.Items;
foreach (Player p in online) {
if (p != player) alive.Add(p);
if (p != first) Alive.Add(p);
}
infectd.Clear();
if (queZombie) infectd.Add(PlayerInfo.Find(nextZombie));
else infectd.Add(player);
aliveCount = alive.Count;
DoCoreGame(players, random);
Infected.Clear();
Infected.Add(first);
DoCoreGame(random);
if (Status == ZombieGameStatus.NotStarted) {
Status = ZombieGameStatus.LastRound; return;
@ -111,19 +110,19 @@ namespace MCGalaxy.Games {
Server.s.Log(logMessage);
RoundStart = DateTime.UtcNow.AddSeconds(30);
Player.GlobalMessage("%4Round Start:%f 30...");
CurrentLevel.ChatLevel("%4Round Start:%f 30...");
Thread.Sleep(20000); if (!Server.ZombieModeOn) return null;
Player.GlobalMessage("%4Round Start:%f 10...");
CurrentLevel.ChatLevel("%4Round Start:%f 10...");
Thread.Sleep(10000); if (!Server.ZombieModeOn) return null;
Player.GlobalMessage("%4Round Start:%f 5...");
CurrentLevel.ChatLevel("%4Round Start:%f 5...");
Thread.Sleep(1000); if (!Server.ZombieModeOn) return null;
Player.GlobalMessage("%4Round Start:%f 4...");
CurrentLevel.ChatLevel("%4Round Start:%f 4...");
Thread.Sleep(1000); if (!Server.ZombieModeOn) return null;
Player.GlobalMessage("%4Round Start:%f 3...");
CurrentLevel.ChatLevel("%4Round Start:%f 3...");
Thread.Sleep(1000); if (!Server.ZombieModeOn) return null;
Player.GlobalMessage("%4Round Start:%f 2...");
CurrentLevel.ChatLevel("%4Round Start:%f 2...");
Thread.Sleep(1000); if (!Server.ZombieModeOn) return null;
Player.GlobalMessage("%4Round Start:%f 1...");
CurrentLevel.ChatLevel("%4Round Start:%f 1...");
Thread.Sleep(1000); if (!Server.ZombieModeOn) return null;
int nonRefPlayers = 0;
List<Player> players = new List<Player>();
@ -132,7 +131,7 @@ namespace MCGalaxy.Games {
foreach (Player p in online) {
if (p.referee) {
p.color = p.group.color;
} else if (p.level.name == currentLevelName) {
} else if (p.level.name.CaselessEq(CurrentLevelName)) {
p.color = p.group.color;
players.Add(p);
nonRefPlayers++;
@ -140,64 +139,65 @@ namespace MCGalaxy.Games {
}
if (nonRefPlayers >= 2) return players;
Player.GlobalMessage(Colors.red + "ERROR: Need 2 or more players to play");
CurrentLevel.ChatLevel(Colors.red + "ERROR: Need 2 or more players to play");
}
}
void DoCoreGame(List<Player> players, Random random) {
while (aliveCount > 0) {
aliveCount = alive.Count;
infectd.ForEach(
delegate(Player pKiller)
{
UpdatePlayerColor(pKiller, Colors.red);
alive.ForEach(
delegate(Player pAlive)
{
UpdatePlayerColor(pAlive, pAlive.group.color);
if (Math.Abs(pAlive.pos[0] - pKiller.pos[0]) > HitboxPrecision
|| Math.Abs(pAlive.pos[1] - pKiller.pos[1]) > HitboxPrecision
|| Math.Abs(pAlive.pos[2] - pKiller.pos[2]) > HitboxPrecision)
return;
if (!pAlive.infected && pKiller.infected && !pAlive.referee && !pKiller.referee &&
pKiller != pAlive && pKiller.level.name == currentLevelName && pAlive.level.name == currentLevelName)
{
pAlive.infected = true;
infectd.Add(pAlive);
alive.Remove(pAlive);
players.Remove(pAlive);
pAlive.blockCount = 25;
if (lastPlayerToInfect == pKiller.name) {
infectCombo++;
if (infectCombo >= 2) {
pKiller.SendMessage("You gained " + (4 - infectCombo) + " " + Server.moneys);
pKiller.money += 4 - infectCombo;
Player.GlobalMessage(pKiller.FullName + " is on a rampage! " + (infectCombo + 1) + " infections in a row!");
}
} else {
infectCombo = 0;
}
lastPlayerToInfect = pKiller.name;
pKiller.playersInfected++;
Player.GlobalMessage(String.Format(
messages[random.Next(messages.Length)],
Colors.red + pKiller.DisplayName + Colors.yellow,
Colors.red + pAlive.DisplayName + Colors.yellow));
BountyData bounty;
if (Bounties.TryGetValue(pAlive.name, out bounty))
Bounties.Remove(pAlive.name);
if (bounty != null) {
Player.GlobalMessage(pKiller.FullName + " %Scollected the bounty of &a" +
bounty.Amount + " %S" + Server.moneys + " on " + pAlive.FullName + "%S.");
bounty.Origin.money = Math.Max(0, bounty.Origin.money - bounty.Amount);
pKiller.money += bounty.Amount;
}
UpdatePlayerColor(pAlive, Colors.red);
void DoCoreGame(Random random) {
Player[] alive = null;
while ((alive = Alive.Items).Length > 0) {
Player[] infected = Infected.Items;
foreach (Player pKiller in infected) {
UpdatePlayerColor(pKiller, Colors.red);
bool aliveChanged = false;
foreach (Player pAlive in alive) {
UpdatePlayerColor(pAlive, pAlive.group.color);
if (Math.Abs(pAlive.pos[0] - pKiller.pos[0]) > HitboxPrecision
|| Math.Abs(pAlive.pos[1] - pKiller.pos[1]) > HitboxPrecision
|| Math.Abs(pAlive.pos[2] - pKiller.pos[2]) > HitboxPrecision)
continue;
if (!pAlive.infected && pKiller.infected && !pAlive.referee && !pKiller.referee && pKiller != pAlive
&& pKiller.level.name.CaselessEq(CurrentLevelName) && pAlive.level.name.CaselessEq(CurrentLevelName))
{
pAlive.infected = true;
Infected.Add(pAlive);
Alive.Remove(pAlive);
aliveChanged = true;
pAlive.blockCount = 25;
if (lastPlayerToInfect == pKiller.name) {
infectCombo++;
if (infectCombo >= 2) {
pKiller.SendMessage("You gained " + (4 - infectCombo) + " " + Server.moneys);
pKiller.money += 4 - infectCombo;
CurrentLevel.ChatLevel(pKiller.FullName + " is on a rampage! " + (infectCombo + 1) + " infections in a row!");
}
});
});
} else {
infectCombo = 0;
}
lastPlayerToInfect = pKiller.name;
pKiller.playersInfected++;
CurrentLevel.ChatLevel(String.Format(
messages[random.Next(messages.Length)],
Colors.red + pKiller.DisplayName + Colors.yellow,
Colors.red + pAlive.DisplayName + Colors.yellow));
BountyData bounty;
if (Bounties.TryGetValue(pAlive.name, out bounty))
Bounties.Remove(pAlive.name);
if (bounty != null) {
CurrentLevel.ChatLevel(pKiller.FullName + " %Scollected the bounty of &a" +
bounty.Amount + " %S" + Server.moneys + " on " + pAlive.FullName + "%S.");
bounty.Origin.money = Math.Max(0, bounty.Origin.money - bounty.Amount);
pKiller.money += bounty.Amount;
}
UpdatePlayerColor(pAlive, Colors.red);
}
}
if (aliveChanged) alive = Alive.Items;
}
Thread.Sleep(50);
}
}
@ -211,11 +211,11 @@ namespace MCGalaxy.Games {
public void EndRound(object sender, ElapsedEventArgs e) {
if (Status == ZombieGameStatus.NotStarted) return;
Player.GlobalMessage("%4Round End:%f 5"); Thread.Sleep(1000);
Player.GlobalMessage("%4Round End:%f 4"); Thread.Sleep(1000);
Player.GlobalMessage("%4Round End:%f 3"); Thread.Sleep(1000);
Player.GlobalMessage("%4Round End:%f 2"); Thread.Sleep(1000);
Player.GlobalMessage("%4Round End:%f 1"); Thread.Sleep(1000);
CurrentLevel.ChatLevel("%4Round End:%f 5"); Thread.Sleep(1000);
CurrentLevel.ChatLevel("%4Round End:%f 4"); Thread.Sleep(1000);
CurrentLevel.ChatLevel("%4Round End:%f 3"); Thread.Sleep(1000);
CurrentLevel.ChatLevel("%4Round End:%f 2"); Thread.Sleep(1000);
CurrentLevel.ChatLevel("%4Round End:%f 1"); Thread.Sleep(1000);
HandOutRewards();
}
@ -225,34 +225,37 @@ namespace MCGalaxy.Games {
RoundEnd = DateTime.MinValue;
Bounties.Clear();
if (Status == ZombieGameStatus.NotStarted) return;
Player.GlobalMessage(Colors.lime + "The game has ended!");
if (aliveCount == 0) Player.GlobalMessage(Colors.maroon + "Zombies have won this round.");
else if (aliveCount == 1) Player.GlobalMessage(Colors.green + "Congratulations to the sole survivor:");
else Player.GlobalMessage(Colors.green + "Congratulations to the survivors:");
Player[] alive = Alive.Items;
CurrentLevel.ChatLevel(Colors.lime + "The game has ended!");
if (alive.Length == 0) CurrentLevel.ChatLevel(Colors.maroon + "Zombies have won this round.");
else if (alive.Length == 1) CurrentLevel.ChatLevel(Colors.green + "Congratulations to the sole survivor:");
else CurrentLevel.ChatLevel(Colors.green + "Congratulations to the survivors:");
timer.Enabled = false;
string playersString = "";
Player[] online = null;
if (aliveCount == 0) {
if (alive.Length == 0) {
online = PlayerInfo.Online.Items;
foreach (Player pl in online)
ResetPlayer(pl, ref playersString);
} else {
alive.ForEach(pl => ResetPlayer(pl, ref playersString));
foreach (Player pl in alive)
ResetPlayer(pl, ref playersString);
}
Player.GlobalMessage(playersString);
CurrentLevel.ChatLevel(playersString);
online = PlayerInfo.Online.Items;
Random rand = new Random();
foreach (Player pl in online) {
int money = 0;
if (pl.level.name != currentLevelName) continue;
if (!pl.level.name.CaselessEq(CurrentLevelName)) continue;
bool inBlock = pl.CheckIfInsideBlock();
if (!inBlock && aliveCount == 0) {
if (!inBlock && alive.Length == 0) {
money = rand.Next(1, 5 + pl.playersInfected);
} else if (!inBlock && (aliveCount == 1 && !pl.infected)) {
} else if (!inBlock && (alive.Length == 1 && !pl.infected)) {
money = rand.Next(5, 15);
} else if (inBlock) {
money = -1;
@ -276,7 +279,8 @@ namespace MCGalaxy.Games {
pl.money++;
}
}
try {alive.Clear(); infectd.Clear(); } catch{ }
Alive.Clear();
Infected.Clear();
}
void ResetPlayer(Player p, ref string playersString) {
@ -284,7 +288,7 @@ namespace MCGalaxy.Games {
p.infected = false;
p.playersInfected = 0;
if (p.level.name == currentLevelName) {
if (p.level.name.CaselessEq(CurrentLevelName)) {
p.color = p.group.color;
playersString += p.group.color + p.DisplayName + Colors.white + ", ";
}
@ -309,7 +313,7 @@ namespace MCGalaxy.Games {
string level2 = levels[r.Next(0, levels.Count)];
if (lastLevel1 == level || lastLevel2 == level2 || lastLevel1 == level2 ||
lastLevel2 == level || currentLevelName == level || currentLevelName == level2) {
lastLevel2 == level || CurrentLevelName == level || CurrentLevelName == level2) {
goto LevelChoice;
} else if (selectedLevel1 == "") {
selectedLevel1 = level; goto LevelChoice;
@ -325,7 +329,7 @@ namespace MCGalaxy.Games {
if (initialChangeLevel) {
Server.votingforlevel = true;
Player.GlobalMessage(" " + Colors.black + "Level Vote: %S" + selectedLevel1 + ", " + selectedLevel2 +
CurrentLevel.ChatLevel(" " + Colors.black + "Level Vote: %S" + selectedLevel1 + ", " + selectedLevel2 +
" or random " + "(" + Colors.lime + "1%S/" + Colors.red + "2%S/" + Colors.blue + "3%S)");
System.Threading.Thread.Sleep(15000);
Server.votingforlevel = false;

View File

@ -41,7 +41,7 @@ namespace MCGalaxy.Games {
p.lastXblock = x; p.lastYblock = y; p.lastZblock = z;
if (action == 1 || (action == 0 && p.painting)) {
if (p.level.name != Server.zombie.currentLevelName || p.referee) return false;
if (!p.level.name.CaselessEq(CurrentLevelName) || p.referee) return false;
if (p.blockCount == 0 ) {
p.SendMessage("You have no blocks left.");
@ -84,31 +84,38 @@ namespace MCGalaxy.Games {
}
public override void PlayerLeftServer(Player p) {
InfectedPlayerDC();
Alive.Remove(p);
Infected.Remove(p);
AssignFirstZombie();
}
public override void PlayerJoinedServer(Player p) {
if (Status == ZombieGameStatus.NotStarted) return;
Player.SendMessage(p, "There is a Zombie Survival game currently in-progress! " +
"Join it by typing /g " + Server.zombie.currentLevelName);
"Join it by typing /g " + CurrentLevelName);
}
public override void PlayerJoinedLevel(Player p, Level oldLevl) {
if (Server.zombie.RoundInProgress && p.level.name == currentLevelName)
Server.zombie.InfectedPlayerLogin(p);
if (p.level.name == currentLevelName) {
double startLeft = (RoundStart - DateTime.UtcNow).TotalSeconds;
if (startLeft >= 0)
p.SendMessage("%a" + (int)startLeft + " %Sseconds left until the round starts. %aRun!");
public override void PlayerJoinedLevel(Player p, Level oldLvl) {
Server.s.Log("CHECK " + p.name);
if (RoundInProgress && p.level.name.CaselessEq(CurrentLevelName)) {
if (Status != ZombieGameStatus.NotStarted && p != null) {
p.SendMessage("You joined in the middle of a round. &cYou are now infected!");
p.blockCount = 50;
InfectPlayer(p);
}
}
if (p.level.name.CaselessEq(CurrentLevelName)) {
double startLeft = (RoundStart - DateTime.UtcNow).TotalSeconds;
if (startLeft >= 0)
p.SendMessage("%a" + (int)startLeft + " %Sseconds left until the round starts. %aRun!");
//p.SendMessage(CpeMessageType.BottomRight1, "%SYou have &a" + p.money + " %S" + Server.moneys);
return;
}
p.SendMessage(CpeMessageType.BottomRight1, "");
if(ZombieGame.alive.Contains(p))
ZombieGame.alive.Remove(p);
if (ZombieGame.infectd.Contains(p))
ZombieGame.infectd.Remove(p);
Alive.Remove(p);
Infected.Remove(p);
}
}
}

View File

@ -60,12 +60,24 @@ namespace MCGalaxy.Games {
/// <summary> Time at which the next round is scheduled to end. </summary>
public DateTime RoundEnd;
public int aliveCount = 0;
public static System.Timers.Timer timer;
public bool initialChangeLevel = false;
public string lastLevelName = "", currentLevelName = "";
public static List<Player> alive = new List<Player>();
public static List<Player> infectd = new List<Player>();
/// <summary> The name of the level that the last round of zombie survival was played on. </summary>
public string LastLevelName = "";
/// <summary> The name of the level that the current round of zombie survival is being played on. </summary>
public string CurrentLevelName = "";
/// <summary> The level that the current round of zombie survival is being played on. </summary>
public Level CurrentLevel = null;
/// <summary> List of alive/human players. </summary>
public VolatileArray<Player> Alive = new VolatileArray<Player>(false);
/// <summary> List of dead/infected players. </summary>
public VolatileArray<Player> Infected = new VolatileArray<Player>(false);
static string[] messages = new string[] { "{0} WIKIWOO'D {1}", "{0} stuck their teeth into {1}",
"{0} licked {1}'s brain ", "{0} danubed {1}", "{0} made {1} meet their maker", "{0} tripped {1}",
"{0} made some zombie babies with {1}", "{0} made {1} see the dark side", "{0} tweeted {1}",
@ -102,84 +114,68 @@ namespace MCGalaxy.Games {
t.Start();
}
public void InfectedPlayerDC() {
if (Status == ZombieGameStatus.NotStarted) return;
//This is for when the first zombie disconnects
/// <summary> If there are no infected players left, randomly selected one of the alive players to continue the infection. </summary>
public void AssignFirstZombie() {
if (Status == ZombieGameStatus.NotStarted || !RoundInProgress || Infected.Count > 0) return;
Random random = new Random();
if ((Status != ZombieGameStatus.NotStarted && RoundInProgress) && infectd.Count <= 0) {
if (alive.Count == 0) return;
int index = random.Next(alive.Count);
while (alive[index].referee || alive[index].level.name == Server.zombie.currentLevelName) {
if (index >= alive.Count - 1) index = 0;
else index++;
Player[] alive = Alive.Items;
if (alive.Length == 0) return;
int index = random.Next(alive.Length);
while (alive[index].referee || !alive[index].level.name.CaselessEq(CurrentLevelName)) {
if (index >= alive.Length - 1) {
index = 0;
alive = Alive.Items;
if (alive.Length == 0) return;
} else {
index++;
}
Player zombie = alive[index];
Player.GlobalMessage(zombie.FullName + " %Scontinued the infection!");
InfectPlayer(zombie);
}
Player zombie = alive[index];
Player.GlobalMessage(zombie.FullName + " %Scontinued the infection!");
InfectPlayer(zombie);
}
public bool InfectedPlayerLogin(Player p) {
if (Status == ZombieGameStatus.NotStarted || p == null) return false;
if (p.level.name != Server.zombie.currentLevelName) return false;
p.SendMessage("You have joined in the middle of a round. You are now infected!");
p.blockCount = 50;
try
{
Server.zombie.InfectPlayer(p);
}
catch { }
return true;
}
public void InfectPlayer(Player p)
{
public void InfectPlayer(Player p) {
if (!RoundInProgress || p == null) return;
infectd.Add(p);
alive.Remove(p);
Infected.Add(p);
Alive.Remove(p);
p.infected = true;
UpdatePlayerColor(p, Colors.red);
aliveCount = alive.Count;
}
public void DisinfectPlayer(Player p)
{
public void DisinfectPlayer(Player p) {
if (!RoundInProgress || p == null) return;
infectd.Remove(p);
alive.Add(p);
Infected.Remove(p);
Alive.Add(p);
p.infected = false;
UpdatePlayerColor(p, p.group.color);
aliveCount = alive.Count;
}
void ChangeLevel(string next) {
currentLevelName = next;
CurrentLevelName = next;
queLevel = false;
nextLevel = "";
Command.all.Find("load").Use(null, next.ToLower() + " 0");
CurrentLevel = LevelInfo.Find(next);
Player.GlobalMessage("The next map has been chosen - " + Colors.red + next.ToLower());
Player.GlobalMessage("Please wait while you are transfered.");
string oldLevel = Server.mainLevel.name;
if (Server.ZombieOnlyServer)
Server.mainLevel = LevelInfo.Find(next);
Server.mainLevel = CurrentLevel;
Player[] online = PlayerInfo.Online.Items;
foreach (Player pl in online) {
if (pl.level.name != next && pl.level.name == lastLevelName) {
if (!pl.level.name.CaselessEq(next) && pl.level.name.CaselessEq(LastLevelName)) {
pl.SendMessage("Going to the next map!");
Command.all.Find("goto").Use(pl, next);
}
}
if (lastLevelName != "")
Command.all.Find("unload").Use(null, lastLevelName);
lastLevelName = next;
}
public bool IsInZombieGameLevel(Player p) {
return p.level.name == currentLevelName;
if (LastLevelName != "")
Command.all.Find("unload").Use(null, LastLevelName);
LastLevelName = next;
}
public void ResetState() {
@ -190,6 +186,9 @@ namespace MCGalaxy.Games {
RoundInProgress = false;
RoundStart = DateTime.MinValue;
RoundEnd = DateTime.MinValue;
LastLevelName = "";
CurrentLevelName = "";
CurrentLevel = null;
}
}
}

View File

@ -280,8 +280,9 @@ namespace MCGalaxy
public static event OnLevelLoaded LevelLoaded;
public bool ShouldSaveLevelFile() {
if (Server.ZombieModeOn && (name == Server.zombie.currentLevelName
|| name == Server.zombie.lastLevelName)) return false;
if (Server.ZombieModeOn &&
(name.CaselessEq(Server.zombie.CurrentLevelName)
|| name.CaselessEq(Server.zombie.LastLevelName))) return false;
if (Server.lava.active && Server.lava.HasMap(name)) return false;
return true;
}

View File

@ -20,6 +20,7 @@ using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using MCGalaxy.Commands;
using MCGalaxy.Games;
using MCGalaxy.SQL;
@ -531,7 +532,6 @@ namespace MCGalaxy {
}
Server.s.Log(name + " [" + ip + "] has joined the server.");
Server.zombie.PlayerJoinedServer(this);
try {
ushort x = (ushort)((0.5 + level.spawnx) * 32);
@ -554,6 +554,7 @@ namespace MCGalaxy {
Server.ErrorLog(e);
Server.s.Log("Error spawning player \"" + name + "\"");
}
CmdGoto.CheckGamesJoin(this, null);
Loading = false;
}

View File

@ -101,12 +101,7 @@ namespace MCGalaxy {
string suffix = players.Length == 1 ? " player online" : " players online";
SendMessage("There are currently &a" + players.Length + suffix);
try {
ZombieGame.alive.Remove(this);
ZombieGame.infectd.Remove(this);
} catch {
}
if ( Server.lava.active )
if (Server.lava.active)
SendMessage("There is a &aLava Survival " + Server.DefaultColor + "game active! Join it by typing /ls go");
extraTimer.Dispose();
}

View File

@ -613,6 +613,12 @@ namespace MCGalaxy {
Chat.standardTokens.Remove(token);
Chat.disabledTokens = value;
} break;
case "enable-http-api":
try {
Server.EnableHttpApi = bool.Parse(value);
}
catch { Server.s.Log("Invalid " + key + ". Using default."); }
break;
}
}
@ -745,7 +751,7 @@ namespace MCGalaxy {
w.WriteLine("main-name = " + Server.level);
w.WriteLine("default-texture-url = " + Server.defaultTerrainUrl);
w.WriteLine("default-texture-pack-url = " + Server.defaultTexturePackUrl);
//w.WriteLine("guest-goto = " + Server.guestGoto);
w.WriteLine("enable-http-api = " + Server.EnableHttpApi);
w.WriteLine();
w.WriteLine("# irc bot options");
w.WriteLine("irc = " + Server.irc.ToString().ToLower());

View File

@ -150,10 +150,12 @@ namespace MCGalaxy {
void InitRest() {
try {
APIServer = new WebServer(SendResponse, "http://localhost:8080/api/");
APIServer.Run();
InfoServer = new WebServer(WhoIsResponse, "http://localhost:8080/whois/");
InfoServer.Run();
if (EnableHttpApi) {
APIServer = new WebServer(SendResponse, "http://localhost:8080/api/");
APIServer.Run();
InfoServer = new WebServer(WhoIsResponse, "http://localhost:8080/whois/");
InfoServer.Run();
}
} catch {
Server.s.Log("Failed to start local API server");
}

View File

@ -71,8 +71,7 @@ namespace MCGalaxy
public static WebServer APIServer;
public static WebServer InfoServer;
public static DateTime StartTime, StartTimeLocal;
public static int speedPhysics = 250;
public static bool EnableHttpApi = false;
public static Version Version { get { return System.Reflection.Assembly.GetAssembly(typeof(Server)).GetName().Version; } }
@ -184,7 +183,6 @@ namespace MCGalaxy
public static bool pub = true;
public static bool verify = true;
public static bool worldChat = true;
// public static bool guestGoto = false;
//Spam Prevention
public static bool checkspam = false;
@ -647,8 +645,8 @@ namespace MCGalaxy
p.LeaveServer(msg, msg);
}
}
APIServer.Stop();
InfoServer.Stop();
if (APIServer != null) APIServer.Stop();
if (InfoServer != null) InfoServer.Stop();
//PlayerInfo.players.ForEach(delegate(Player p) { p.Kick("Server shutdown. Rejoin in 10 seconds."); });
Player.connections.ForEach(
delegate(Player p)

View File

@ -65,5 +65,12 @@ namespace MCGalaxy {
Items = newItems;
}
}
public void Clear() {
lock (locker) {
if (useList) list.Clear();
Items = new T[0];
}
}
}
}