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

@ -21,7 +21,6 @@ using MCGalaxy.Games;
namespace MCGalaxy.Commands { namespace MCGalaxy.Commands {
public sealed class CmdTeam : Command { public sealed class CmdTeam : Command {
public override string name { get { return "team"; } } public override string name { get { return "team"; } }
public override string shortcut { get { return ""; } } public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Games; } } 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 LevelPermission defaultRank { get { return LevelPermission.Guest; } }
public override void Use(Player p, string message) { public override void Use(Player p, string message) {
if (p == null) { MessageInGameOnly(p); return; }
if (message == "") { Help(p); return; } if (message == "") { Help(p); return; }
string[] args = message.Split(' '); string[] args = message.Split(' ');
@ -49,6 +49,12 @@ namespace MCGalaxy.Commands {
HandleLeave(p, args); break; HandleLeave(p, args); break;
case "members": case "members":
HandleMembers(p, args); break; 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) { 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 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 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."); 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 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 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, "%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 Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at obtain a copy of the Licenses at
http://www.osedu.org/licenses/ECL-2.0 http://www.osedu.org/licenses/ECL-2.0
http://www.gnu.org/licenses/gpl-3.0.html http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing, Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS" software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
using MCGalaxy.Games; using MCGalaxy.Games;
namespace MCGalaxy.Commands namespace MCGalaxy.Commands {
{
public sealed class CmdAlive : Command public sealed class CmdAlive : Command {
{
public override string name { get { return "alive"; } } public override string name { get { return "alive"; } }
public override string shortcut { get { return "alive"; } } public override string shortcut { get { return "alive"; } }
public override string type { get { return CommandTypes.Games; } } public override string type { get { return CommandTypes.Games; } }
@ -29,25 +28,20 @@ namespace MCGalaxy.Commands
public override bool Enabled { get { return Server.ZombieModeOn; } } public override bool Enabled { get { return Server.ZombieModeOn; } }
public CmdAlive() { } public CmdAlive() { }
public override void Use(Player p, string message) public override void Use(Player p, string message) {
{ Player[] alive = Server.zombie.Alive.Items;
if (ZombieGame.alive.Count == 0) if (alive.Length == 0) {
{ Player.SendMessage(p, "No one is alive."); return;
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);
} }
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"); Player.SendMessage(p, "/alive - shows who is alive");
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -60,12 +60,24 @@ namespace MCGalaxy.Games {
/// <summary> Time at which the next round is scheduled to end. </summary> /// <summary> Time at which the next round is scheduled to end. </summary>
public DateTime RoundEnd; public DateTime RoundEnd;
public int aliveCount = 0;
public static System.Timers.Timer timer; public static System.Timers.Timer timer;
public bool initialChangeLevel = false; public bool initialChangeLevel = false;
public string lastLevelName = "", currentLevelName = "";
public static List<Player> alive = new List<Player>(); /// <summary> The name of the level that the last round of zombie survival was played on. </summary>
public static List<Player> infectd = new List<Player>(); 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}", 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} 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}", "{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(); t.Start();
} }
public void InfectedPlayerDC() { /// <summary> If there are no infected players left, randomly selected one of the alive players to continue the infection. </summary>
if (Status == ZombieGameStatus.NotStarted) return; public void AssignFirstZombie() {
//This is for when the first zombie disconnects if (Status == ZombieGameStatus.NotStarted || !RoundInProgress || Infected.Count > 0) return;
Random random = new Random(); Random random = new Random();
if ((Status != ZombieGameStatus.NotStarted && RoundInProgress) && infectd.Count <= 0) { Player[] alive = Alive.Items;
if (alive.Count == 0) return; if (alive.Length == 0) return;
int index = random.Next(alive.Count); int index = random.Next(alive.Length);
while (alive[index].referee || alive[index].level.name == Server.zombie.currentLevelName) { while (alive[index].referee || !alive[index].level.name.CaselessEq(CurrentLevelName)) {
if (index >= alive.Count - 1) index = 0; if (index >= alive.Length - 1) {
else index++; 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) { public void InfectPlayer(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)
{
if (!RoundInProgress || p == null) return; if (!RoundInProgress || p == null) return;
infectd.Add(p); Infected.Add(p);
alive.Remove(p); Alive.Remove(p);
p.infected = true; p.infected = true;
UpdatePlayerColor(p, Colors.red); UpdatePlayerColor(p, Colors.red);
aliveCount = alive.Count;
} }
public void DisinfectPlayer(Player p) public void DisinfectPlayer(Player p) {
{
if (!RoundInProgress || p == null) return; if (!RoundInProgress || p == null) return;
infectd.Remove(p); Infected.Remove(p);
alive.Add(p); Alive.Add(p);
p.infected = false; p.infected = false;
UpdatePlayerColor(p, p.group.color); UpdatePlayerColor(p, p.group.color);
aliveCount = alive.Count;
} }
void ChangeLevel(string next) { void ChangeLevel(string next) {
currentLevelName = next; CurrentLevelName = next;
queLevel = false; queLevel = false;
nextLevel = ""; nextLevel = "";
Command.all.Find("load").Use(null, next.ToLower() + " 0"); 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("The next map has been chosen - " + Colors.red + next.ToLower());
Player.GlobalMessage("Please wait while you are transfered."); Player.GlobalMessage("Please wait while you are transfered.");
string oldLevel = Server.mainLevel.name; string oldLevel = Server.mainLevel.name;
if (Server.ZombieOnlyServer) if (Server.ZombieOnlyServer)
Server.mainLevel = LevelInfo.Find(next); Server.mainLevel = CurrentLevel;
Player[] online = PlayerInfo.Online.Items; Player[] online = PlayerInfo.Online.Items;
foreach (Player pl in online) { 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!"); pl.SendMessage("Going to the next map!");
Command.all.Find("goto").Use(pl, next); Command.all.Find("goto").Use(pl, next);
} }
} }
if (lastLevelName != "") if (LastLevelName != "")
Command.all.Find("unload").Use(null, lastLevelName); Command.all.Find("unload").Use(null, LastLevelName);
lastLevelName = next; LastLevelName = next;
}
public bool IsInZombieGameLevel(Player p) {
return p.level.name == currentLevelName;
} }
public void ResetState() { public void ResetState() {
@ -190,6 +186,9 @@ namespace MCGalaxy.Games {
RoundInProgress = false; RoundInProgress = false;
RoundStart = DateTime.MinValue; RoundStart = DateTime.MinValue;
RoundEnd = DateTime.MinValue; RoundEnd = DateTime.MinValue;
LastLevelName = "";
CurrentLevelName = "";
CurrentLevel = null;
} }
} }
} }

View File

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

View File

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

View File

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

View File

@ -613,6 +613,12 @@ namespace MCGalaxy {
Chat.standardTokens.Remove(token); Chat.standardTokens.Remove(token);
Chat.disabledTokens = value; Chat.disabledTokens = value;
} break; } 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("main-name = " + Server.level);
w.WriteLine("default-texture-url = " + Server.defaultTerrainUrl); w.WriteLine("default-texture-url = " + Server.defaultTerrainUrl);
w.WriteLine("default-texture-pack-url = " + Server.defaultTexturePackUrl); 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();
w.WriteLine("# irc bot options"); w.WriteLine("# irc bot options");
w.WriteLine("irc = " + Server.irc.ToString().ToLower()); w.WriteLine("irc = " + Server.irc.ToString().ToLower());

View File

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

View File

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

View File

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