Fix several bugs in zombie survival.

This commit is contained in:
UnknownShadow200 2016-03-26 12:00:11 +11:00
parent be4a50e0be
commit 5babc4332f
7 changed files with 53 additions and 77 deletions

View File

@ -32,17 +32,9 @@ namespace MCGalaxy.Commands {
Player[] players = PlayerInfo.Online.Items; Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) { foreach (Player pl in players) {
if (pl.level != p.level || p == pl || !Player.CanSee(p, pl) || pl.referee) continue; if (pl.level != p.level || p == pl || !Player.CanSee(p, pl) || pl.referee) continue;
p.SendDespawn(pl.id); p.SendDespawn(pl.id);
string name = null; Player.SpawnEntity(pl, p, pl.id, pl.pos[0], pl.pos[1], pl.pos[2], pl.rot[0], pl.rot[1], "");
if (pl.infected) {
name = (Server.zombie.ZombieName != "" && showInfected) ?
Colors.red + Server.zombie.ZombieName : Colors.red + pl.name;
} else {
name = pl.color + pl.name;
}
p.SendSpawn(pl.id, name, pl.pos[0], pl.pos[1], pl.pos[2], pl.rot[0], pl.rot[1]);
} }
} }

View File

@ -75,24 +75,9 @@ namespace MCGalaxy.Commands {
PlayerBot[] bots = PlayerBot.Bots.Items; PlayerBot[] bots = PlayerBot.Bots.Items;
foreach (PlayerBot b in bots) if (who.level == b.level) who.SendDespawn(b.id); foreach (PlayerBot b in bots) if (who.level == b.level) who.SendDespawn(b.id);
ushort x = who.pos[0], y = who.pos[1], z = who.pos[2];
Player.GlobalDespawn(who, true); Player.GlobalDespawn(who, true);
who.SendUserMOTD(); who.SendMap(who.level); who.SendUserMOTD(); who.SendMap(who.level);
CmdGoto.SpawnEntities(who, who.pos[0], who.pos[1], who.pos[2], who.rot[0], who.rot[1]);
if (!who.hidden)
Player.GlobalSpawn(who, x, y, z, who.level.rotx, who.level.roty, true);
else
who.SendPos(0xFF, x, y, z, who.level.rotx, who.level.roty);
players = PlayerInfo.Online.Items;
foreach (Player pl in players)
if (pl.level == who.level && who != pl && !pl.hidden)
who.SendSpawn(pl.id, pl.color + pl.name, pl.pos[0], pl.pos[1], pl.pos[2], pl.rot[0], pl.rot[1]);
bots = PlayerBot.Bots.Items;
foreach (PlayerBot b in bots)
if (b.level == who.level)
who.SendSpawn(b.id, b.color + b.name, b.pos[0], b.pos[1], b.pos[2], b.rot[0], b.rot[1]);
who.Loading = false; who.Loading = false;
if (!showMessage) return; if (!showMessage) return;

View File

@ -49,7 +49,7 @@ namespace MCGalaxy.Commands {
if (!didJoin) return; if (!didJoin) return;
bool unloadOld = true; bool unloadOld = true;
if (oldLevel.unload && !oldLevel.name.Contains("&cMuseum ")) { if (oldLevel.unload && !oldLevel.name.Contains("&cMuseum ")) {
Player[] players = PlayerInfo.Online.Items; Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) foreach (Player pl in players)
if (pl.level == oldLevel) { unloadOld = false; break; } if (pl.level == oldLevel) { unloadOld = false; break; }
if (unloadOld && Server.AutoLoad) oldLevel.Unload(true); if (unloadOld && Server.AutoLoad) oldLevel.Unload(true);
@ -127,21 +127,7 @@ namespace MCGalaxy.Commands {
ushort x = (ushort)((0.5 + lvl.spawnx) * 32); ushort x = (ushort)((0.5 + lvl.spawnx) * 32);
ushort y = (ushort)((1 + lvl.spawny) * 32); ushort y = (ushort)((1 + lvl.spawny) * 32);
ushort z = (ushort)((0.5 + lvl.spawnz) * 32); ushort z = (ushort)((0.5 + lvl.spawnz) * 32);
SpawnEntities(p, x, y, z, lvl.rotx, lvl.roty);
if (!p.hidden)
Player.GlobalSpawn(p, x, y, z, lvl.rotx, lvl.roty, true, "");
else
p.SendPos(0xFF, x, y, z, lvl.rotx, lvl.roty);
players = PlayerInfo.Online.Items;
foreach (Player pl in players)
if (pl.level == p.level && p != pl && !pl.hidden)
p.SendSpawn(pl.id, pl.color + pl.name, pl.pos[0], pl.pos[1], pl.pos[2], pl.rot[0], pl.rot[1]);
bots = PlayerBot.Bots.Items;
foreach (PlayerBot b in bots)
if (b.level == p.level)
p.SendSpawn(b.id, b.color + b.name, b.pos[0], b.pos[1], b.pos[2], b.rot[0], b.rot[1]);
p.Loading = false; p.Loading = false;
CheckGamesJoin(p, oldLevel); CheckGamesJoin(p, oldLevel);
@ -152,9 +138,25 @@ namespace MCGalaxy.Commands {
return true; return true;
} }
internal static void SpawnEntities(Player p, ushort x, ushort y, ushort z, byte rotX, byte rotY) {
Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) {
if (pl.level != p.level || pl.hidden || p == pl) continue;
Player.SpawnEntity(pl, p, pl.id, pl.pos[0], pl.pos[1], pl.pos[2], pl.rot[0], pl.rot[1], "");
}
if (!p.hidden) Player.GlobalSpawn(p, x, y, z, rotX, rotY, true, "");
else p.SendPos(0xFF, x, y, z, rotX, rotY);
PlayerBot[] bots = PlayerBot.Bots.Items;
foreach (PlayerBot b in bots)
if (b.level == p.level)
p.SendSpawn(b.id, b.color + b.name, b.pos[0], b.pos[1], b.pos[2], b.rot[0], b.rot[1]);
}
internal static 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);
if (p.inTNTwarsMap) p.canBuild = true; if (p.inTNTwarsMap) p.canBuild = true;
TntWarsGame game = TntWarsGame.Find(p.level); TntWarsGame game = TntWarsGame.Find(p.level);

View File

@ -69,7 +69,7 @@ namespace MCGalaxy.Games {
CurrentLevel.ChatLevel(first.color + first.name + " %Sstarted the infection!"); CurrentLevel.ChatLevel(first.color + first.name + " %Sstarted the infection!");
first.infected = true; first.infected = true;
UpdatePlayerColor(first, Colors.red); UpdatePlayerColor(first, InfectCol);
RoundInProgress = true; RoundInProgress = true;
int roundMins = random.Next(4, 7); int roundMins = random.Next(4, 7);
@ -101,6 +101,7 @@ namespace MCGalaxy.Games {
do { do {
first = QueuedZombie != null ? first = QueuedZombie != null ?
PlayerInfo.Find(QueuedZombie) : players[random.Next(players.Count)]; PlayerInfo.Find(QueuedZombie) : players[random.Next(players.Count)];
QueuedZombie = null;
} while (first == null || !first.level.name.CaselessEq(CurrentLevelName)); } while (first == null || !first.level.name.CaselessEq(CurrentLevelName));
return first; return first;
} }
@ -153,7 +154,7 @@ namespace MCGalaxy.Games {
foreach (Player pKiller in infected) { foreach (Player pKiller in infected) {
pKiller.infected = true; pKiller.infected = true;
UpdatePlayerColor(pKiller, Colors.red); UpdatePlayerColor(pKiller, InfectCol);
bool aliveChanged = false; bool aliveChanged = false;
foreach (Player pAlive in alive) { foreach (Player pAlive in alive) {
UpdatePlayerColor(pAlive, pAlive.color); UpdatePlayerColor(pAlive, pAlive.color);
@ -190,7 +191,7 @@ namespace MCGalaxy.Games {
CheckHumanPledge(pAlive); CheckHumanPledge(pAlive);
CheckBounty(pAlive, pKiller); CheckBounty(pAlive, pKiller);
UpdatePlayerColor(pAlive, Colors.red); UpdatePlayerColor(pAlive, InfectCol);
} }
} }
if (aliveChanged) alive = Alive.Items; if (aliveChanged) alive = Alive.Items;

View File

@ -38,6 +38,8 @@ namespace MCGalaxy.Games {
public enum ZombieGameStatus { NotStarted, InfiniteRounds, SingleRound, VariableRounds, LastRound } public enum ZombieGameStatus { NotStarted, InfiniteRounds, SingleRound, VariableRounds, LastRound }
public sealed partial class ZombieGame { public sealed partial class ZombieGame {
public const string InfectCol = "&infect";
/// <summary> The number of rounds that have been played in this game so far. </summary> /// <summary> The number of rounds that have been played in this game so far. </summary>
public int RoundsDone = 0; public int RoundsDone = 0;

View File

@ -538,18 +538,7 @@ namespace MCGalaxy {
ushort y = (ushort)((1 + level.spawny) * 32); ushort y = (ushort)((1 + level.spawny) * 32);
ushort z = (ushort)((0.5 + level.spawnz) * 32); ushort z = (ushort)((0.5 + level.spawnz) * 32);
pos = new ushort[3] { x, y, z }; rot = new byte[2] { level.rotx, level.roty }; pos = new ushort[3] { x, y, z }; rot = new byte[2] { level.rotx, level.roty };
CmdGoto.SpawnEntities(this, x, y, z, rot[0], rot[1]);
GlobalSpawn(this, x, y, z, rot[0], rot[1], true);
Player[] players = PlayerInfo.Online.Items;
foreach (Player p in players) {
if (p.level == level && p != this && !p.hidden)
SendSpawn(p.id, p.color + p.name, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1]);
}
PlayerBot[] bots = PlayerBot.Bots.Items;
foreach (PlayerBot pB in bots) {
if (pB.level == level)
SendSpawn(pB.id, pB.color + pB.name, pB.pos[0], pB.pos[1], pB.pos[2], pB.rot[0], pB.rot[1]);
}
} catch (Exception e) { } catch (Exception e) {
Server.ErrorLog(e); Server.ErrorLog(e);
Server.s.Log("Error spawning player \"" + name + "\""); Server.s.Log("Error spawning player \"" + name + "\"");

View File

@ -487,34 +487,39 @@ namespace MCGalaxy {
public static void GlobalSpawn(Player p, ushort x, ushort y, ushort z, public static void GlobalSpawn(Player p, ushort x, ushort y, ushort z,
byte rotx, byte roty, bool self, string possession = "") { byte rotx, byte roty, bool self, string possession = "") {
Player[] players = PlayerInfo.Online.Items; Player[] players = PlayerInfo.Online.Items;
p.lastSpawnColor = p.infected ? Colors.red : p.color; p.lastSpawnColor = p.infected ? ZombieGame.InfectCol : p.color;
foreach (Player other in players) { foreach (Player other in players) {
if (other.Loading && p != other) continue; if (other.Loading && p != other) continue;
if (p.level != other.level || (p.hidden && !self)) continue; if (p.level != other.level || (p.hidden && !self)) continue;
if (p != other) { if (p != other) {
if (Server.ZombieModeOn) { SpawnEntity(p, other, p.id, x, y, z, rotx, roty, possession);
if (p.infected) {
if (Server.zombie.ZombieName != "" && !other.aka)
other.SendSpawn(p.id, Colors.red + Server.zombie.ZombieName + possession, x, y, z, rotx, roty);
else
other.SendSpawn(p.id, Colors.red + p.name + possession, x, y, z, rotx, roty);
if (other.HasCpeExt(CpeExt.ChangeModel))
other.SendChangeModel(p.id, "zombie");
} else if (!p.referee) {
other.SendSpawn(p.id, p.color + p.name + possession, x, y, z, rotx, roty);
}
} else {
other.SendSpawn(p.id, p.color + p.name + possession, x, y, z, rotx, roty);
}
} else if (self) { } else if (self) {
other.pos = new ushort[3] { x, y, z }; other.rot = new byte[2] { rotx, roty }; other.pos = new ushort[3] { x, y, z }; other.rot = new byte[2] { rotx, roty };
other.oldpos = other.pos; other.basepos = other.pos; other.oldrot = other.rot; other.oldpos = other.pos; other.basepos = other.pos; other.oldrot = other.rot;
other.SendSpawn(0xFF, p.color + p.name + possession, x, y, z, rotx, roty); SpawnEntity(p, other, 0xFF, x, y, z, rotx, roty, possession);
} }
} }
} }
internal static void SpawnEntity(Player p, Player dst, byte id, ushort x, ushort y, ushort z,
byte rotx, byte roty, string possession = "") {
if (!Server.ZombieModeOn) {
dst.SendSpawn(id, p.color + p.name + possession, x, y, z, rotx, roty); return;
}
if (p.infected) {
if (Server.zombie.ZombieName != "" && !dst.aka)
dst.SendSpawn(id, Colors.red + Server.zombie.ZombieName + possession, x, y, z, rotx, roty);
else
dst.SendSpawn(id, Colors.red + p.name + possession, x, y, z, rotx, roty);
if (dst.HasCpeExt(CpeExt.ChangeModel))
dst.SendChangeModel(id, "zombie");
} else if (!p.referee) {
dst.SendSpawn(id, p.color + p.name + possession, x, y, z, rotx, roty);
}
}
public static void GlobalDespawn(Player p, bool self) { public static void GlobalDespawn(Player p, bool self) {
Player[] players = PlayerInfo.Online.Items; Player[] players = PlayerInfo.Online.Items;
foreach (Player other in players) { foreach (Player other in players) {