mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Add a OnPlayerSpawning event, reduce hardcoding of games.
This commit is contained in:
parent
9c37250630
commit
0e3378a22d
@ -33,26 +33,28 @@ namespace MCGalaxy.Commands.Fun {
|
||||
public override void Use(Player p, string message) {
|
||||
if (message == "") { Help(p); return; }
|
||||
string[] args = message.ToLower().SplitSpaces();
|
||||
ZSGame game = Server.zombie;
|
||||
|
||||
switch (args[0]) {
|
||||
case "go": HandleGo(p, args); break;
|
||||
case "status": HandleStatus(p, args); break;
|
||||
case "start": HandleStart(p, args); break;
|
||||
case "end": HandleEnd(p, args); break;
|
||||
case "stop": HandleStop(p, args); break;
|
||||
case "set": HandleSet(p, args); break;
|
||||
case "go": HandleGo(p, game, args); break;
|
||||
case "status": HandleStatus(p, game, args); break;
|
||||
case "start": HandleStart(p, game, args); break;
|
||||
case "end": HandleEnd(p, game, args); break;
|
||||
case "stop": HandleStop(p, game, args); break;
|
||||
case "set": HandleSet(p, game, args); break;
|
||||
default: Help(p); break;
|
||||
}
|
||||
}
|
||||
|
||||
static void HandleGo(Player p, string[] args) {
|
||||
if (Server.zombie.Status == ZombieGameStatus.NotStarted) {
|
||||
static void HandleGo(Player p, ZSGame game, string[] args) {
|
||||
if (game.Status == ZombieGameStatus.NotStarted) {
|
||||
Player.Message(p, "Zombie Survival is not currently running."); return;
|
||||
}
|
||||
PlayerActions.ChangeMap(p, Server.zombie.CurLevel);
|
||||
PlayerActions.ChangeMap(p, game.CurLevel);
|
||||
}
|
||||
|
||||
static void HandleStatus(Player p, string[] args) {
|
||||
switch (Server.zombie.Status) {
|
||||
static void HandleStatus(Player p, ZSGame game, string[] args) {
|
||||
switch (game.Status) {
|
||||
case ZombieGameStatus.NotStarted:
|
||||
Player.Message(p, "Zombie Survival is not currently running."); break;
|
||||
case ZombieGameStatus.InfiniteRounds:
|
||||
@ -60,17 +62,17 @@ namespace MCGalaxy.Commands.Fun {
|
||||
case ZombieGameStatus.SingleRound:
|
||||
Player.Message(p, "Zombie Survival game currently in progress."); break;
|
||||
case ZombieGameStatus.VariableRounds:
|
||||
Player.Message(p, "Zombie Survival game currently in progress with " + Server.zombie.MaxRounds + " rounds."); break;
|
||||
Player.Message(p, "Zombie Survival game currently in progress with " + game.MaxRounds + " rounds."); break;
|
||||
case ZombieGameStatus.LastRound:
|
||||
Player.Message(p, "Zombie Survival game currently in progress, with this round being the final round."); break;
|
||||
}
|
||||
|
||||
if (Server.zombie.Status == ZombieGameStatus.NotStarted || Server.zombie.CurLevelName == "") return;
|
||||
Player.Message(p, "Running on map: " + Server.zombie.CurLevelName);
|
||||
if (game.Status == ZombieGameStatus.NotStarted || game.CurLevelName == "") return;
|
||||
Player.Message(p, "Running on map: " + game.CurLevelName);
|
||||
}
|
||||
|
||||
static void HandleStart(Player p, string[] args) {
|
||||
if (Server.zombie.Running) {
|
||||
static void HandleStart(Player p, ZSGame game, string[] args) {
|
||||
if (game.Running) {
|
||||
Player.Message(p, "There is already a Zombie Survival game currently in progress."); return;
|
||||
}
|
||||
Level lvl = Player.IsSuper(p) ? null : p.level;
|
||||
@ -81,45 +83,45 @@ namespace MCGalaxy.Commands.Fun {
|
||||
|
||||
ZombieGameStatus status = rounds == 0 ?
|
||||
ZombieGameStatus.InfiniteRounds : ZombieGameStatus.VariableRounds;
|
||||
Server.zombie.Start(status, lvl, rounds);
|
||||
game.Start(status, lvl, rounds);
|
||||
} else {
|
||||
Server.zombie.Start(ZombieGameStatus.SingleRound, lvl, 0);
|
||||
game.Start(ZombieGameStatus.SingleRound, lvl, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void HandleEnd(Player p, string[] args) {
|
||||
if (Server.zombie.RoundInProgress) {
|
||||
Server.zombie.EndRound();
|
||||
static void HandleEnd(Player p, ZSGame game, string[] args) {
|
||||
if (game.RoundInProgress) {
|
||||
game.EndRound();
|
||||
} else {
|
||||
Player.Message(p, "No round is currently in progress.");
|
||||
}
|
||||
}
|
||||
|
||||
static void HandleStop(Player p, string[] args) {
|
||||
if (!Server.zombie.Running) {
|
||||
static void HandleStop(Player p, ZSGame game, string[] args) {
|
||||
if (!game.Running) {
|
||||
Player.Message(p, "There is no Zombie Survival game currently in progress."); return;
|
||||
}
|
||||
|
||||
string src = p == null ? "(console)" : p.ColoredName;
|
||||
Level lvl = Server.zombie.CurLevel;
|
||||
Level lvl = game.CurLevel;
|
||||
if (lvl != null) {
|
||||
Chat.MessageLevel(Server.zombie.CurLevel, "Zombie Survival was stopped by " + src);
|
||||
Chat.MessageLevel(game.CurLevel, "Zombie Survival was stopped by " + src);
|
||||
}
|
||||
|
||||
src = p == null ? "(console)" : p.name;
|
||||
Logger.Log(LogType.GameActivity, "Zombie Survival stopped by " + src);
|
||||
Server.zombie.End();
|
||||
game.End();
|
||||
}
|
||||
|
||||
void HandleSet(Player p, string[] args) {
|
||||
void HandleSet(Player p, ZSGame game, string[] args) {
|
||||
if (args.Length == 1) { Help(p, "set"); return; }
|
||||
|
||||
if (args[1].CaselessEq("hitbox")) { HandleHitbox(p, args); return; }
|
||||
if (args[1].CaselessEq("maxmove")) { HandleMaxMove(p, args); return; }
|
||||
if (args[1].CaselessEq("hitbox")) { HandleHitbox(p, game, args); return; }
|
||||
if (args[1].CaselessEq("maxmove")) { HandleMaxMove(p, game, args); return; }
|
||||
Help(p, "set");
|
||||
}
|
||||
|
||||
static void HandleHitbox(Player p, string[] args) {
|
||||
static void HandleHitbox(Player p, ZSGame game, string[] args) {
|
||||
if (args.Length == 2) {
|
||||
Player.Message(p, "Hitbox detection is currently &a" + ZSConfig.HitboxPrecision + " %Sunits apart.");
|
||||
return;
|
||||
@ -133,7 +135,7 @@ namespace MCGalaxy.Commands.Fun {
|
||||
ZSConfig.SaveSettings();
|
||||
}
|
||||
|
||||
static void HandleMaxMove(Player p, string[] args) {
|
||||
static void HandleMaxMove(Player p, ZSGame game, string[] args) {
|
||||
if (args.Length == 2) {
|
||||
Player.Message(p, "Maxmium move distance is currently &a" + ZSConfig.MaxMoveDistance + " %Sunits apart.");
|
||||
return;
|
||||
|
@ -72,7 +72,9 @@ namespace MCGalaxy.Commands.World {
|
||||
byte extBlock = lvl.GetExtTileNoCheck(x, y, z);
|
||||
temp.SetExtTileNoCheck(x, y, z, extBlock);
|
||||
}
|
||||
|
||||
temp.spawnx = lvl.spawnx; temp.spawny = lvl.spawny; temp.spawnz = lvl.spawnz;
|
||||
temp.rotx = lvl.rotx; temp.roty = lvl.roty;
|
||||
|
||||
lock (lvl.saveLock) {
|
||||
lvl.Backup(true);
|
||||
|
@ -15,6 +15,7 @@
|
||||
or implied. See the Licenses for the specific language governing
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using MCGalaxy.Events.PlayerEvents;
|
||||
using MCGalaxy.Games;
|
||||
|
||||
namespace MCGalaxy.Commands.World {
|
||||
@ -28,14 +29,14 @@ namespace MCGalaxy.Commands.World {
|
||||
public override void Use(Player p, string message) {
|
||||
if (message != "") { Help(p); return; }
|
||||
bool cpSpawn = p.useCheckpointSpawn;
|
||||
int x = 16 + (cpSpawn ? p.checkpointX : p.level.spawnx) * 32;
|
||||
int y = 32 + (cpSpawn ? p.checkpointY : p.level.spawny) * 32;
|
||||
int z = 16 + (cpSpawn ? p.checkpointZ : p.level.spawnz) * 32;
|
||||
Position pos;
|
||||
|
||||
pos.X = 16 + (cpSpawn ? p.checkpointX : p.level.spawnx) * 32;
|
||||
pos.Y = 32 + (cpSpawn ? p.checkpointY : p.level.spawny) * 32;
|
||||
pos.Z = 16 + (cpSpawn ? p.checkpointZ : p.level.spawnz) * 32;
|
||||
byte yaw = cpSpawn ? p.checkpointRotX : p.level.rotx;
|
||||
byte pitch = cpSpawn ? p.checkpointRotY : p.level.roty;
|
||||
|
||||
if (!p.Game.Referee && !p.Game.Infected && Server.zombie.RoundInProgress)
|
||||
Server.zombie.InfectPlayer(p, null);
|
||||
OnPlayerSpawningEvent.Call(p, ref pos, ref yaw, ref pitch, true);
|
||||
|
||||
if (p.PlayingTntWars) {
|
||||
TntWarsGame game = TntWarsGame.GetTntWarsGame(p);
|
||||
@ -43,16 +44,15 @@ namespace MCGalaxy.Commands.World {
|
||||
&& game.GameStatus != TntWarsGame.TntWarsGameStatus.Finished && game.RedSpawn != null && game.BlueSpawn != null) {
|
||||
bool blue = game.FindPlayer(p).Blue;
|
||||
|
||||
x = 16 + (blue ? game.BlueSpawn[0] : game.RedSpawn[0]) * 32;
|
||||
y = 32 + (blue ? game.BlueSpawn[1] : game.RedSpawn[1]) * 32;
|
||||
z = 16 + (blue ? game.BlueSpawn[2] : game.RedSpawn[2]) * 32;
|
||||
pos.X = 16 + (blue ? game.BlueSpawn[0] : game.RedSpawn[0]) * 32;
|
||||
pos.Y = 32 + (blue ? game.BlueSpawn[1] : game.RedSpawn[1]) * 32;
|
||||
pos.Z = 16 + (blue ? game.BlueSpawn[2] : game.RedSpawn[2]) * 32;
|
||||
yaw = (byte)(blue ? game.BlueSpawn[3] : game.RedSpawn[3]);
|
||||
pitch = (byte)(blue ? game.BlueSpawn[4] : game.RedSpawn[4]);
|
||||
}
|
||||
}
|
||||
|
||||
p.SendPos(Entities.SelfID, new Position(x, y, z),
|
||||
new Orientation(yaw, pitch));
|
||||
p.SendPos(Entities.SelfID, pos, new Orientation(yaw, pitch));
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
|
@ -42,7 +42,7 @@ namespace MCGalaxy {
|
||||
/// <summary> Spawns this player to all other players that can see the player in the current world. </summary>
|
||||
public static void GlobalSpawn(Player p, Position pos, Orientation rot, bool self, string possession = "") {
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
p.Game.lastSpawnColor = p.Game.Infected ? ZombieGame.InfectCol : p.color;
|
||||
p.Game.lastSpawnColor = p.Game.Infected ? ZSGame.InfectCol : p.color;
|
||||
TabList.Update(p, self);
|
||||
|
||||
foreach (Player other in players) {
|
||||
|
@ -177,5 +177,26 @@ namespace MCGalaxy.Events.PlayerEvents {
|
||||
if (handlers.Count == 0) return;
|
||||
CallCommon(pl => pl(p, packet));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public delegate void OnPlayerSpawning(Player p, ref Position pos, ref byte yaw, ref byte pitch, bool respawning);
|
||||
/// <summary> Called when a player is being initially spawned in a map,
|
||||
/// or is respawning (e.g. died from a killer block). </summary>
|
||||
public sealed class OnPlayerSpawningEvent : IEvent<OnPlayerSpawning> {
|
||||
|
||||
public static void Call(Player p, ref Position pos, ref byte yaw, ref byte pitch, bool respawning) {
|
||||
IEvent<OnPlayerSpawning>[] items = handlers.Items;
|
||||
// Can't use CallCommon because we need to pass arguments by ref
|
||||
for (int i = 0; i < items.Length; i++) {
|
||||
IEvent<OnPlayerSpawning> handler = items[i];
|
||||
|
||||
try {
|
||||
handler.method(p, ref pos, ref yaw, ref pitch, respawning);
|
||||
} catch (Exception ex) {
|
||||
LogHandlerException(ex, handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -269,7 +269,7 @@ namespace MCGalaxy.Games {
|
||||
#endregion
|
||||
|
||||
|
||||
public void Death(Player p) {
|
||||
public void PlayerDied(Player p) {
|
||||
Map.ChatLevel(p.ColoredName + " %Sis out of countdown!");
|
||||
Remaining.Remove(p);
|
||||
UpdatePlayersLeft();
|
||||
|
@ -30,12 +30,14 @@ namespace MCGalaxy.Games {
|
||||
OnPlayerMoveEvent.Register(HandlePlayerMove, Priority.High);
|
||||
OnPlayerDisconnectEvent.Register(HandlePlayerDisconnect, Priority.High);
|
||||
OnLevelUnloadEvent.Register(HandleLevelUnload, Priority.High);
|
||||
OnPlayerSpawningEvent.Register(HandlePlayerSpawning, Priority.High);
|
||||
}
|
||||
|
||||
public override void Unload(bool shutdown) {
|
||||
OnPlayerMoveEvent.Unregister(HandlePlayerMove);
|
||||
OnPlayerDisconnectEvent.Unregister(HandlePlayerDisconnect);
|
||||
OnLevelUnloadEvent.Unregister(HandleLevelUnload);
|
||||
OnPlayerSpawningEvent.Unregister(HandlePlayerSpawning);
|
||||
}
|
||||
|
||||
|
||||
@ -66,6 +68,11 @@ namespace MCGalaxy.Games {
|
||||
void HandleLevelUnload(Level lvl) {
|
||||
if (Game.Status == CountdownGameStatus.Disabled || lvl != Game.Map) return;
|
||||
Game.Disable();
|
||||
}
|
||||
|
||||
void HandlePlayerSpawning(Player p, ref Position pos, ref byte yaw, ref byte pitch, bool respawning) {
|
||||
if (!respawning || !Game.Remaining.Contains(p)) return;
|
||||
Game.PlayerDied(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,24 +20,24 @@ using System;
|
||||
namespace MCGalaxy.Games.ZS {
|
||||
internal static class HUD {
|
||||
|
||||
internal static void UpdateAllPrimary(ZombieGame game) {
|
||||
internal static void UpdateAllPrimary(ZSGame game) {
|
||||
int left = (int)(game.RoundEnd - DateTime.UtcNow).TotalSeconds;
|
||||
string status = FormatPrimary(game, left);
|
||||
MessageAll(game, CpeMessageType.Status1, status);
|
||||
}
|
||||
|
||||
internal static void UpdatePrimary(ZombieGame game, Player p) {
|
||||
internal static void UpdatePrimary(ZSGame game, Player p) {
|
||||
int left = (int)(game.RoundEnd - DateTime.UtcNow).TotalSeconds;
|
||||
string status = FormatPrimary(game, left);
|
||||
p.SendCpeMessage(CpeMessageType.Status1, status);
|
||||
}
|
||||
|
||||
internal static void UpdateAllSecondary(ZombieGame game) {
|
||||
internal static void UpdateAllSecondary(ZSGame game) {
|
||||
string status = FormatSecondary(game);
|
||||
MessageAll(game, CpeMessageType.Status2, status);
|
||||
}
|
||||
|
||||
internal static void UpdateSecondary(ZombieGame game, Player p) {
|
||||
internal static void UpdateSecondary(ZSGame game, Player p) {
|
||||
string status = FormatSecondary(game);
|
||||
p.SendCpeMessage(CpeMessageType.Status2, status);
|
||||
}
|
||||
@ -66,7 +66,7 @@ namespace MCGalaxy.Games.ZS {
|
||||
}
|
||||
|
||||
|
||||
static string FormatPrimary(ZombieGame game, int seconds) {
|
||||
static string FormatPrimary(ZSGame game, int seconds) {
|
||||
string timespan = GetTimeLeft(seconds);
|
||||
if (timespan.Length > 0) {
|
||||
const string format = "&a{0} %Salive %S({2}, map: {1})";
|
||||
@ -77,7 +77,7 @@ namespace MCGalaxy.Games.ZS {
|
||||
}
|
||||
}
|
||||
|
||||
static string FormatSecondary(ZombieGame game) {
|
||||
static string FormatSecondary(ZSGame game) {
|
||||
string pillar = "%SPillaring " + (game.CurLevel.Config.Pillaring ? "&aYes" : "&cNo");
|
||||
string type = "%S, Type is &a" + game.CurLevel.Config.BuildType;
|
||||
return pillar + type;
|
||||
@ -89,7 +89,7 @@ namespace MCGalaxy.Games.ZS {
|
||||
return money + state;
|
||||
}
|
||||
|
||||
static void MessageAll(ZombieGame game, CpeMessageType type, string message) {
|
||||
static void MessageAll(ZSGame game, CpeMessageType type, string message) {
|
||||
if (!game.Running) return;
|
||||
Player[] online = PlayerInfo.Online.Items;
|
||||
foreach (Player p in online) {
|
||||
|
@ -24,7 +24,7 @@ using System.Threading;
|
||||
namespace MCGalaxy.Games.ZS {
|
||||
internal static class LevelPicker {
|
||||
|
||||
internal static void ChooseNextLevel(ZombieGame game) {
|
||||
internal static void ChooseNextLevel(ZSGame game) {
|
||||
if (game.QueuedLevel != null) { game.ChangeLevel(game.QueuedLevel); return; }
|
||||
if (!ZSConfig.ChangeLevels) return;
|
||||
|
||||
@ -49,7 +49,7 @@ namespace MCGalaxy.Games.ZS {
|
||||
}
|
||||
}
|
||||
|
||||
static void RemoveRecentLevels(List<string> maps, ZombieGame game) {
|
||||
static void RemoveRecentLevels(List<string> maps, ZSGame game) {
|
||||
// Try to avoid recently played levels, avoiding most recent
|
||||
List<string> recent = game.RecentMaps;
|
||||
for (int i = recent.Count - 1; i >= 0; i--) {
|
||||
@ -66,7 +66,7 @@ namespace MCGalaxy.Games.ZS {
|
||||
maps.CaselessRemove(game.Candidate3);
|
||||
}
|
||||
|
||||
static void DoLevelVote(ZombieGame game) {
|
||||
static void DoLevelVote(ZSGame game) {
|
||||
Server.votingforlevel = true;
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
foreach (Player pl in players) {
|
||||
@ -78,7 +78,7 @@ namespace MCGalaxy.Games.ZS {
|
||||
Server.votingforlevel = false;
|
||||
}
|
||||
|
||||
static void VoteCountdown(ZombieGame game) {
|
||||
static void VoteCountdown(ZSGame game) {
|
||||
// Show message for non-CPE clients
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
foreach (Player pl in players) {
|
||||
@ -98,7 +98,7 @@ namespace MCGalaxy.Games.ZS {
|
||||
|
||||
|
||||
/// <summary> Moves all players to the level which has the highest number of votes. </summary>
|
||||
static void MoveToNextLevel(Random r, List<string> levels, ZombieGame game) {
|
||||
static void MoveToNextLevel(Random r, List<string> levels, ZSGame game) {
|
||||
int v1 = game.Votes1, v2 = game.Votes2, v3 = game.Votes3;
|
||||
|
||||
if (v1 >= v2) {
|
||||
@ -167,7 +167,7 @@ namespace MCGalaxy.Games.ZS {
|
||||
}
|
||||
|
||||
/// <summary> Sends the formatted vote message to the player (using bottom right if supported) </summary>
|
||||
internal static void SendVoteMessage(Player p, ZombieGame game) {
|
||||
internal static void SendVoteMessage(Player p, ZSGame game) {
|
||||
const string line1 = "&eLevel vote - type &a1&e, &b2&e or &c3";
|
||||
string line2 = "&a" + game.Candidate1 + "&e, &b"
|
||||
+ game.Candidate2 + "&e, &c" + game.Candidate3;
|
||||
|
@ -24,7 +24,7 @@ namespace MCGalaxy.Games.ZS {
|
||||
internal static class Pillaring {
|
||||
|
||||
internal static bool Handles(Player p, ushort x, ushort y, ushort z,
|
||||
byte action, byte block, byte old, ZombieGame game) {
|
||||
byte action, byte block, byte old, ZSGame game) {
|
||||
|
||||
if (action == 1 && !game.CurLevel.Config.Pillaring && !p.Game.Referee) {
|
||||
if (NotPillaring(block, old)) {
|
||||
|
@ -23,7 +23,7 @@ namespace MCGalaxy.Games.ZS {
|
||||
|
||||
internal static class Rewards {
|
||||
|
||||
public static void HandOut(ZombieGame game) {
|
||||
public static void HandOut(ZSGame game) {
|
||||
Player[] alive = game.Alive.Items, dead = game.Infected.Items;
|
||||
game.CurLevel.ChatLevel("&aThe game has ended!");
|
||||
|
||||
@ -43,7 +43,7 @@ namespace MCGalaxy.Games.ZS {
|
||||
DoLottery(game);
|
||||
}
|
||||
|
||||
static void AnnounceWinners(ZombieGame game, Player[] alive, Player[] dead) {
|
||||
static void AnnounceWinners(ZSGame game, Player[] alive, Player[] dead) {
|
||||
if (alive.Length > 0) {
|
||||
string winners = alive.Join(p => p.ColoredName);
|
||||
game.CurLevel.ChatLevel(winners);
|
||||
@ -66,7 +66,7 @@ namespace MCGalaxy.Games.ZS {
|
||||
+ suffix + "%S)&8: " + dead.Join(formatter));
|
||||
}
|
||||
|
||||
static void IncreaseAliveStats(Player p, ZombieGame game) {
|
||||
static void IncreaseAliveStats(Player p, ZSGame game) {
|
||||
if (p.Game.PledgeSurvive) {
|
||||
Player.Message(p, "You received &a5 %3" + ServerConfig.Currency +
|
||||
" %Sfor successfully pledging that you would survive.");
|
||||
@ -79,7 +79,7 @@ namespace MCGalaxy.Games.ZS {
|
||||
p.SetPrefix(); // stars before name
|
||||
}
|
||||
|
||||
static void GiveMoney(ZombieGame game, Player[] alive) {
|
||||
static void GiveMoney(ZSGame game, Player[] alive) {
|
||||
Player[] online = PlayerInfo.Online.Items;
|
||||
Random rand = new Random();
|
||||
|
||||
@ -108,7 +108,7 @@ namespace MCGalaxy.Games.ZS {
|
||||
}
|
||||
}
|
||||
|
||||
static void DoLottery(ZombieGame game) {
|
||||
static void DoLottery(ZSGame game) {
|
||||
string[] players = game.Lottery.Items;
|
||||
if (players.Length == 0) return;
|
||||
|
||||
|
@ -27,7 +27,7 @@ namespace MCGalaxy.Games.ZS {
|
||||
public override string creator { get { return Server.SoftwareName + " team"; } }
|
||||
public override string MCGalaxy_Version { get { return Server.VersionString; } }
|
||||
public override string name { get { return "Core_ZSPlugin"; } }
|
||||
public ZombieGame Game;
|
||||
public ZSGame Game;
|
||||
|
||||
public override void Load(bool startup) {
|
||||
OnTabListEntryAddedEvent.Register(HandleTabListEntryAdded, Priority.High);
|
||||
@ -36,6 +36,7 @@ namespace MCGalaxy.Games.ZS {
|
||||
OnPlayerDisconnectEvent.Register(HandlePlayerDisconnect, Priority.High);
|
||||
OnPlayerMoveEvent.Register(HandlePlayerMove, Priority.High);
|
||||
OnPlayerActionEvent.Register(HandlePlayerAction, Priority.High);
|
||||
OnPlayerSpawningEvent.Register(HandlePlayerSpawning, Priority.High);
|
||||
}
|
||||
|
||||
public override void Unload(bool shutdown) {
|
||||
@ -45,6 +46,7 @@ namespace MCGalaxy.Games.ZS {
|
||||
OnPlayerDisconnectEvent.Unregister(HandlePlayerDisconnect);
|
||||
OnPlayerMoveEvent.Unregister(HandlePlayerMove);
|
||||
OnPlayerActionEvent.Unregister(HandlePlayerAction);
|
||||
OnPlayerSpawningEvent.Unregister(HandlePlayerSpawning);
|
||||
}
|
||||
|
||||
void HandleTabListEntryAdded(Entity entity, ref string tabName, ref string tabGroup, Player dst) {
|
||||
@ -115,5 +117,13 @@ namespace MCGalaxy.Games.ZS {
|
||||
TabList.Add(p, p, Entities.SelfID);
|
||||
p.SetPrefix();
|
||||
}
|
||||
|
||||
void HandlePlayerSpawning(Player p, ref Position pos, ref byte yaw, ref byte pitch, bool respawning) {
|
||||
if (p.level != Game.CurLevel) return;
|
||||
|
||||
if (!p.Game.Referee && !p.Game.Infected && Game.RoundInProgress) {
|
||||
Game.InfectPlayer(p, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ using MCGalaxy.Network;
|
||||
|
||||
namespace MCGalaxy.Games {
|
||||
|
||||
public sealed partial class ZombieGame {
|
||||
public sealed partial class ZSGame {
|
||||
|
||||
void MainLoop() {
|
||||
// Make sure that in the worst case, we do not crash the entire server.
|
||||
|
@ -21,7 +21,7 @@ using MCGalaxy.Games.ZS;
|
||||
|
||||
namespace MCGalaxy.Games {
|
||||
|
||||
public sealed partial class ZombieGame : IGame {
|
||||
public sealed partial class ZSGame : IGame {
|
||||
|
||||
/// <summary> Whether players are allowed to teleport to others when not in referee mode. </summary>
|
||||
public override bool TeleportAllowed { get { return !RoundInProgress; } }
|
||||
|
@ -35,7 +35,7 @@ namespace MCGalaxy.Games {
|
||||
|
||||
public enum ZombieGameStatus { NotStarted, InfiniteRounds, SingleRound, VariableRounds, LastRound }
|
||||
|
||||
public sealed partial class ZombieGame {
|
||||
public sealed partial class ZSGame {
|
||||
|
||||
public const string InfectCol = "&infect";
|
||||
|
||||
|
@ -32,7 +32,7 @@ namespace MCGalaxy.Games {
|
||||
public int TotalRounds, MaxRounds, TotalInfected, MaxInfected;
|
||||
}
|
||||
|
||||
public sealed partial class ZombieGame {
|
||||
public sealed partial class ZSGame {
|
||||
ZSPlugin plugin = new ZSPlugin();
|
||||
|
||||
public void Start(ZombieGameStatus status, Level level, int rounds) {
|
||||
|
@ -38,7 +38,6 @@ namespace MCGalaxy {
|
||||
public byte rotx, roty;
|
||||
public ushort spawnx, spawny, spawnz;
|
||||
public Position SpawnPos { get { return new Position(16 + spawnx * 32, 32 + spawny * 32, 16 + spawnz * 32); } }
|
||||
public Orientation SpawnRot { get { return new Orientation(rotx, roty); } }
|
||||
|
||||
public BlockDefinition[] CustomBlockDefs = new BlockDefinition[Block.Count];
|
||||
public BlockProps[] BlockProps = new BlockProps[Block.Count * 2];
|
||||
|
@ -113,7 +113,7 @@ namespace MCGalaxy {
|
||||
/// saved to the BlockDB and .lvl files. </summary>
|
||||
public bool ShouldSaveChanges() {
|
||||
if (!saveLevel) return false;
|
||||
ZombieGame zs = Server.zombie;
|
||||
ZSGame zs = Server.zombie;
|
||||
|
||||
if (zs.Running && !ZSConfig.SaveLevelBlockchanges &&
|
||||
(name.CaselessEq(zs.CurLevelName) || name.CaselessEq(zs.LastLevelName)))
|
||||
@ -124,7 +124,7 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
public bool ShouldShowJoinMessage(Level prev) {
|
||||
ZombieGame zs = Server.zombie;
|
||||
ZSGame zs = Server.zombie;
|
||||
if (zs.Running && name.CaselessEq(zs.CurLevelName) &&
|
||||
(prev == this || zs.LastLevelName == "" || prev.name.CaselessEq(zs.LastLevelName)))
|
||||
return false;
|
||||
|
@ -398,9 +398,6 @@ namespace MCGalaxy {
|
||||
//}
|
||||
Game.team.SpawnPlayer(this);
|
||||
//this.health = 100;
|
||||
} else if ( Server.Countdown.Remaining.Contains(this) ) {
|
||||
Server.Countdown.Death(this);
|
||||
Command.all.Find("spawn").Use(this, "");
|
||||
} else if ( PlayingTntWars ) {
|
||||
TntWarsKillStreak = 0;
|
||||
TntWarsScoreMultiplier = 1f;
|
||||
|
@ -186,8 +186,11 @@ namespace MCGalaxy {
|
||||
Game.InfectMessages = PlayerDB.GetInfectMessages(this);
|
||||
Server.lava.PlayerJoinedServer(this);
|
||||
|
||||
Pos = level.SpawnPos;
|
||||
SetYawPitch(level.rotx, level.roty);
|
||||
Position pos = level.SpawnPos;
|
||||
byte yaw = level.rotx, pitch = level.roty;
|
||||
OnPlayerSpawningEvent.Call(this, ref pos, ref yaw, ref pitch, true);
|
||||
Pos = pos;
|
||||
SetYawPitch(yaw, pitch);
|
||||
|
||||
Entities.SpawnEntities(this, true);
|
||||
PlayerActions.CheckGamesJoin(this, null);
|
||||
|
@ -74,7 +74,7 @@ namespace MCGalaxy {
|
||||
if (target == null) return true; // not a player
|
||||
|
||||
bool mayBeHidden = target.hidden;
|
||||
mayBeHidden |= (target.Game.Referee || target.Game.Invisible) && Server.zombie.Running;
|
||||
mayBeHidden |= (target.Game.Referee || target.Game.Invisible) && Server.zombie.Running;
|
||||
if (!mayBeHidden || this == other) return true;
|
||||
|
||||
if (target.Game.Referee && !Game.Referee && Server.zombie.Running) return false;
|
||||
|
@ -116,7 +116,10 @@ namespace MCGalaxy {
|
||||
p.level = lvl;
|
||||
p.SendMap(oldLevel);
|
||||
|
||||
Entities.SpawnEntities(p, lvl.SpawnPos, lvl.SpawnRot);
|
||||
Position pos = lvl.SpawnPos;
|
||||
byte yaw = lvl.rotx, pitch = lvl.roty;
|
||||
OnPlayerSpawningEvent.Call(p, ref pos, ref yaw, ref pitch, false);
|
||||
Entities.SpawnEntities(p, pos, new Orientation(yaw, pitch));
|
||||
CheckGamesJoin(p, oldLevel);
|
||||
|
||||
if (p.level.ShouldShowJoinMessage(oldLevel)) {
|
||||
|
@ -89,7 +89,7 @@ namespace MCGalaxy {
|
||||
public static ExtrasCollection Extras = new ExtrasCollection();
|
||||
|
||||
// Games
|
||||
public static ZombieGame zombie;
|
||||
public static ZSGame zombie;
|
||||
|
||||
public static int YesVotes = 0, NoVotes = 0;
|
||||
public static bool voting = false, votingforlevel = false;
|
||||
|
@ -107,7 +107,7 @@ namespace MCGalaxy {
|
||||
MoveOutdatedFiles();
|
||||
|
||||
lava = new LavaSurvival();
|
||||
zombie = new ZombieGame();
|
||||
zombie = new ZSGame();
|
||||
Countdown = new CountdownGame();
|
||||
LoadAllSettings();
|
||||
SrvProperties.GenerateSalt();
|
||||
|
Loading…
x
Reference in New Issue
Block a user