From e169d19071baa70ac1f86caaa9fa9179b833ab82 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 14 Mar 2016 13:28:46 +1100 Subject: [PATCH] Fix bug when round was still considered to be as 'in progress', even though the 'error: need two or more players' message was shown. Modularise some games code more. --- Commands/Moderation/CmdZone.cs | 8 +- Commands/World/CmdGoto.cs | 46 +--- Games/IGame.cs | 2 + Games/LavaSurvival/LavaSurvival.Game.cs | 50 ++++ Games/LavaSurvival/LavaSurvival.Settings.cs | 261 +++++++++++++++++++ Games/{ => LavaSurvival}/LavaSurvival.cs | 238 +---------------- Games/{TntWarsGame.cs => TntWars/TntWars.cs} | 0 Games/ZombieSurvival/ZombieGame.Core.cs | 2 +- Games/ZombieSurvival/ZombieGame.Game.cs | 11 + MCGalaxy_.csproj | 8 +- Network/Player.Networking.cs | 38 +-- Player/Player.Handlers.cs | 68 +++-- Player/Player.cs | 1 - 13 files changed, 402 insertions(+), 331 deletions(-) create mode 100644 Games/LavaSurvival/LavaSurvival.Game.cs create mode 100644 Games/LavaSurvival/LavaSurvival.Settings.cs rename Games/{ => LavaSurvival}/LavaSurvival.cs (63%) rename Games/{TntWarsGame.cs => TntWars/TntWars.cs} (100%) diff --git a/Commands/Moderation/CmdZone.cs b/Commands/Moderation/CmdZone.cs index cd93c232f..0f3fe9cc1 100644 --- a/Commands/Moderation/CmdZone.cs +++ b/Commands/Moderation/CmdZone.cs @@ -24,7 +24,7 @@ namespace MCGalaxy.Commands { public override string name { get { return "zone"; } } public override string shortcut { get { return ""; } } - public override string type { get { return CommandTypes.Moderation; } } + public override string type { get { return CommandTypes.Moderation; } } public override bool museumUsable { get { return false; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public override CommandPerm[] AdditionalPerms { @@ -138,16 +138,14 @@ namespace MCGalaxy.Commands Player.SendMessage(p, "/zone del - Deletes the zone clicked"); } - public void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) - { + void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { RevertAndClearState(p, x, y, z); CatchPos bp = (CatchPos)p.blockchangeObject; bp.x = x; bp.y = y; bp.z = z; p.blockchangeObject = bp; p.Blockchange += new Player.BlockchangeEventHandler(Blockchange2); } - public void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) - { + void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { RevertAndClearState(p, x, y, z); CatchPos cpos = (CatchPos)p.blockchangeObject; diff --git a/Commands/World/CmdGoto.cs b/Commands/World/CmdGoto.cs index 83c50a041..b024ca370 100644 --- a/Commands/World/CmdGoto.cs +++ b/Commands/World/CmdGoto.cs @@ -139,7 +139,7 @@ namespace MCGalaxy.Commands { 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; - CheckGamesJoin(p, lvl); + CheckGamesJoin(p, oldLevel); if (!p.hidden) { Player.SendChatFrom(p, p.color + "*" + p.DisplayName + Server.DefaultColor + " went to &b" + lvl.name, false); @@ -148,40 +148,20 @@ namespace MCGalaxy.Commands { return true; } - void CheckGamesJoin(Player p, Level lvl) { - if (Server.lava.active && !Server.lava.sendingPlayers && Server.lava.map == p.level) { - if (Server.lava.roundActive) { - Server.lava.AnnounceRoundInfo(p); - Server.lava.AnnounceTimeLeft(!Server.lava.flooded, true, p); - } else { - Player.SendMessage(p, "Vote for the next map!"); - Player.SendMessage(p, "Choices: " + Server.lava.VoteString); - } - } - - if (Server.zombie.RoundInProgress) { - if (p.level.name == Server.zombie.currentLevelName) - Server.zombie.InfectedPlayerLogin(p); - } - - if (p.level.name != Server.zombie.currentLevelName) { - if(ZombieGame.alive.Contains(p)) - ZombieGame.alive.Remove(p); - if (ZombieGame.infectd.Contains(p)) - ZombieGame.infectd.Remove(p); - } - - if (p.inTNTwarsMap) - p.canBuild = true; + void CheckGamesJoin(Player p, Level oldLvl) { + Server.lava.PlayerJoinedLevel(p, oldLvl); + Server.zombie.PlayerJoinedLevel(p, oldLvl); + + if (p.inTNTwarsMap) p.canBuild = true; TntWarsGame game = TntWarsGame.Find(p.level); - if (game != null) { - if (game.GameStatus != TntWarsGame.TntWarsGameStatus.Finished && - game.GameStatus != TntWarsGame.TntWarsGameStatus.WaitingForPlayers) { - p.canBuild = false; - Player.SendMessage(p, "TNT Wars: Disabled your building because you are in a TNT Wars map!"); - } - p.inTNTwarsMap = true; + if (game == null) return; + + if (game.GameStatus != TntWarsGame.TntWarsGameStatus.Finished && + game.GameStatus != TntWarsGame.TntWarsGameStatus.WaitingForPlayers) { + p.canBuild = false; + Player.SendMessage(p, "TNT Wars: Disabled your building because you are in a TNT Wars map!"); } + p.inTNTwarsMap = true; } public override void Help(Player p) { diff --git a/Games/IGame.cs b/Games/IGame.cs index c4501518f..c2fcb03c7 100644 --- a/Games/IGame.cs +++ b/Games/IGame.cs @@ -42,5 +42,7 @@ namespace MCGalaxy { public virtual void PlayerJoinedGame(Player p) { } public virtual void PlayerLeftGame(Player p) { } + + public virtual void PlayerJoinedLevel(Player p, Level oldLvl) { } } } diff --git a/Games/LavaSurvival/LavaSurvival.Game.cs b/Games/LavaSurvival/LavaSurvival.Game.cs new file mode 100644 index 000000000..a17d73e99 --- /dev/null +++ b/Games/LavaSurvival/LavaSurvival.Game.cs @@ -0,0 +1,50 @@ +/* + 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 System; + +namespace MCGalaxy { + + public sealed partial class LavaSurvival : IGame { + + public override bool HandlesChatMessage(Player p, string message) { + message = message.ToLower(); + if (HasPlayer(p) && HasVote(message)) { + if (AddVote(p, message)) { + p.SendMessage("Your vote for &5" + message.Capitalize() + " %Shas been placed. Thanks!"); + return true; + } else { + p.SendMessage("&cYou already voted!"); + return true; + } + } + return false; + } + + public override void PlayerJoinedLevel(Player p, Level oldLevl) { + if (Server.lava.active && !Server.lava.sendingPlayers && Server.lava.map == p.level) { + if (Server.lava.roundActive) { + Server.lava.AnnounceRoundInfo(p); + Server.lava.AnnounceTimeLeft(!Server.lava.flooded, true, p); + } else { + Player.SendMessage(p, "Vote for the next map!"); + Player.SendMessage(p, "Choices: " + Server.lava.VoteString); + } + } + } + } +} diff --git a/Games/LavaSurvival/LavaSurvival.Settings.cs b/Games/LavaSurvival/LavaSurvival.Settings.cs new file mode 100644 index 000000000..eae59e7af --- /dev/null +++ b/Games/LavaSurvival/LavaSurvival.Settings.cs @@ -0,0 +1,261 @@ +/* + 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 System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Timers; + +namespace MCGalaxy +{ + public sealed partial class LavaSurvival + { + + public MapData GenerateMapData(MapSettings settings) + { + MapData data = new MapData(settings); + data.killer = rand.Next(1, 101) <= settings.killer; + data.destroy = rand.Next(1, 101) <= settings.destroy; + data.water = rand.Next(1, 101) <= settings.water; + data.layer = rand.Next(1, 101) <= settings.layer; + data.fast = rand.Next(1, 101) <= settings.fast && !data.water; + data.block = data.water ? (data.killer ? Block.activedeathwater : Block.water) : (data.fast ? (data.killer ? Block.fastdeathlava : Block.lava_fast) : (data.killer ? Block.activedeathlava : Block.lava)); + return data; + } + + public void LoadSettings() + { + if (!File.Exists("properties/lavasurvival.properties")) + { + SaveSettings(); + return; + } + + foreach (string line in File.ReadAllLines("properties/lavasurvival.properties")) + { + try + { + if (line[0] != '#') + { + string value = line.Substring(line.IndexOf(" = ") + 3); + switch (line.Substring(0, line.IndexOf(" = ")).ToLower()) + { + case "start-on-startup": + startOnStartup = bool.Parse(value); + break; + case "send-afk-to-main": + sendAfkMain = bool.Parse(value); + break; + case "vote-count": + voteCount = (byte)MathHelper.Clamp(decimal.Parse(value), 2, 10); + break; + case "vote-time": + voteTime = double.Parse(value); + break; + case "lives": + lifeNum = int.Parse(value); + break; + case "setup-rank": + if (Group.Find(value.ToLower()) != null) + setupRank = Group.Find(value.ToLower()).Permission; + break; + case "control-rank": + if (Group.Find(value.ToLower()) != null) + controlRank = Group.Find(value.ToLower()).Permission; + break; + case "maps": + foreach (string mapname in value.Split(',')) + if(!String.IsNullOrEmpty(mapname) && !maps.Contains(mapname)) maps.Add(mapname); + break; + } + } + } + catch (Exception e) { Server.ErrorLog(e); } + } + } + public void SaveSettings() + { + File.Create("properties/lavasurvival.properties").Dispose(); + using (StreamWriter SW = File.CreateText("properties/lavasurvival.properties")) + { + SW.WriteLine("#Lava Survival main properties"); + SW.WriteLine("start-on-startup = " + startOnStartup.ToString().ToLower()); + SW.WriteLine("send-afk-to-main = " + sendAfkMain.ToString().ToLower()); + SW.WriteLine("vote-count = " + voteCount.ToString()); + SW.WriteLine("vote-time = " + voteTime.ToString()); + SW.WriteLine("lives = " + lifeNum.ToString()); + SW.WriteLine("setup-rank = " + Level.PermissionToName(setupRank).ToLower()); + SW.WriteLine("control-rank = " + Level.PermissionToName(controlRank).ToLower()); + SW.WriteLine("maps = " + maps.Concatenate(",")); + } + } + + public MapSettings LoadMapSettings(string name) + { + MapSettings settings = new MapSettings(name); + if (!Directory.Exists(propsPath)) Directory.CreateDirectory(propsPath); + if (!File.Exists(propsPath + name + ".properties")) + { + SaveMapSettings(settings); + return settings; + } + + foreach (string line in File.ReadAllLines(propsPath + name + ".properties")) + { + try + { + if (line[0] != '#') + { + string[] sp; + string value = line.Substring(line.IndexOf(" = ") + 3); + switch (line.Substring(0, line.IndexOf(" = ")).ToLower()) + { + case "fast-chance": + settings.fast = (byte)MathHelper.Clamp(decimal.Parse(value), 0, 100); + break; + case "killer-chance": + settings.killer = (byte)MathHelper.Clamp(decimal.Parse(value), 0, 100); + break; + case "destroy-chance": + settings.destroy = (byte)MathHelper.Clamp(decimal.Parse(value), 0, 100); + break; + case "water-chance": + settings.water = (byte)MathHelper.Clamp(decimal.Parse(value), 0, 100); + break; + case "layer-chance": + settings.layer = (byte)MathHelper.Clamp(decimal.Parse(value), 0, 100); + break; + case "layer-height": + settings.layerHeight = int.Parse(value); + break; + case "layer-count": + settings.layerCount = int.Parse(value); + break; + case "layer-interval": + settings.layerInterval = double.Parse(value); + break; + case "round-time": + settings.roundTime = double.Parse(value); + break; + case "flood-time": + settings.floodTime = double.Parse(value); + break; + case "block-flood": + sp = value.Split(','); + settings.blockFlood = new Pos(ushort.Parse(sp[0]), ushort.Parse(sp[1]), ushort.Parse(sp[2])); + break; + case "block-layer": + sp = value.Split(','); + settings.blockLayer = new Pos(ushort.Parse(sp[0]), ushort.Parse(sp[1]), ushort.Parse(sp[2])); + break; + case "safe-zone": + sp = value.Split('-'); + string[] p1 = sp[0].Split(','), p2 = sp[1].Split(','); + settings.safeZone = new Pos[] { new Pos(ushort.Parse(p1[0]), ushort.Parse(p1[1]), ushort.Parse(p1[2])), new Pos(ushort.Parse(p2[0]), ushort.Parse(p2[1]), ushort.Parse(p2[2])) }; + break; + } + } + } + catch (Exception e) { Server.ErrorLog(e); } + } + return settings; + } + public void SaveMapSettings(MapSettings settings) + { + if (!Directory.Exists(propsPath)) Directory.CreateDirectory(propsPath); + + File.Create(propsPath + settings.name + ".properties").Dispose(); + using (StreamWriter SW = File.CreateText(propsPath + settings.name + ".properties")) + { + SW.WriteLine("#Lava Survival properties for " + settings.name); + SW.WriteLine("fast-chance = " + settings.fast); + SW.WriteLine("killer-chance = " + settings.killer); + SW.WriteLine("destroy-chance = " + settings.destroy); + SW.WriteLine("water-chance = " + settings.water); + SW.WriteLine("layer-chance = " + settings.layer); + SW.WriteLine("layer-height = " + settings.layerHeight); + SW.WriteLine("layer-count = " + settings.layerCount); + SW.WriteLine("layer-interval = " + settings.layerInterval); + SW.WriteLine("round-time = " + settings.roundTime); + SW.WriteLine("flood-time = " + settings.floodTime); + SW.WriteLine("block-flood = " + settings.blockFlood.ToString()); + SW.WriteLine("block-layer = " + settings.blockLayer.ToString()); + SW.WriteLine(String.Format("safe-zone = {0}-{1}", settings.safeZone[0].ToString(), settings.safeZone[1].ToString())); + } + } + + // Internal classes + public class MapSettings + { + public string name; + public byte fast, killer, destroy, water, layer; + public int layerHeight, layerCount; + public double layerInterval, roundTime, floodTime; + public Pos blockFlood, blockLayer; + public Pos[] safeZone; + + public MapSettings(string name) + { + this.name = name; + fast = 0; + killer = 100; + destroy = 0; + water = 0; + layer = 0; + layerHeight = 3; + layerCount = 10; + layerInterval = 2; + roundTime = 15; + floodTime = 5; + blockFlood = new Pos(); + blockLayer = new Pos(); + safeZone = new Pos[] { new Pos(), new Pos() }; + } + } + + public class MapData : IDisposable + { + public bool fast, killer, destroy, water, layer; + public byte block; + public int currentLayer; + public Timer roundTimer, floodTimer, layerTimer; + + public MapData(MapSettings settings) + { + fast = false; + killer = false; + destroy = false; + water = false; + layer = false; + block = Block.lava; + currentLayer = 1; + roundTimer = new Timer(TimeSpan.FromMinutes(settings.roundTime).TotalMilliseconds); roundTimer.AutoReset = false; + floodTimer = new Timer(TimeSpan.FromMinutes(settings.floodTime).TotalMilliseconds); floodTimer.AutoReset = false; + layerTimer = new Timer(TimeSpan.FromMinutes(settings.layerInterval).TotalMilliseconds); layerTimer.AutoReset = true; + } + + public void Dispose() + { + roundTimer.Dispose(); + floodTimer.Dispose(); + layerTimer.Dispose(); + } + } + } +} diff --git a/Games/LavaSurvival.cs b/Games/LavaSurvival/LavaSurvival.cs similarity index 63% rename from Games/LavaSurvival.cs rename to Games/LavaSurvival/LavaSurvival.cs index 7b6de5d7b..28095963b 100644 --- a/Games/LavaSurvival.cs +++ b/Games/LavaSurvival/LavaSurvival.cs @@ -24,7 +24,7 @@ using System.Timers; namespace MCGalaxy { - public sealed class LavaSurvival + public sealed partial class LavaSurvival { // Private variables private string propsPath = "properties/lavasurvival/"; @@ -440,179 +440,6 @@ namespace MCGalaxy return (deaths[name] >= lifeNum); } - public MapData GenerateMapData(MapSettings settings) - { - MapData data = new MapData(settings); - data.killer = rand.Next(1, 101) <= settings.killer; - data.destroy = rand.Next(1, 101) <= settings.destroy; - data.water = rand.Next(1, 101) <= settings.water; - data.layer = rand.Next(1, 101) <= settings.layer; - data.fast = rand.Next(1, 101) <= settings.fast && !data.water; - data.block = data.water ? (data.killer ? Block.activedeathwater : Block.water) : (data.fast ? (data.killer ? Block.fastdeathlava : Block.lava_fast) : (data.killer ? Block.activedeathlava : Block.lava)); - return data; - } - - public void LoadSettings() - { - if (!File.Exists("properties/lavasurvival.properties")) - { - SaveSettings(); - return; - } - - foreach (string line in File.ReadAllLines("properties/lavasurvival.properties")) - { - try - { - if (line[0] != '#') - { - string value = line.Substring(line.IndexOf(" = ") + 3); - switch (line.Substring(0, line.IndexOf(" = ")).ToLower()) - { - case "start-on-startup": - startOnStartup = bool.Parse(value); - break; - case "send-afk-to-main": - sendAfkMain = bool.Parse(value); - break; - case "vote-count": - voteCount = (byte)MathHelper.Clamp(decimal.Parse(value), 2, 10); - break; - case "vote-time": - voteTime = double.Parse(value); - break; - case "lives": - lifeNum = int.Parse(value); - break; - case "setup-rank": - if (Group.Find(value.ToLower()) != null) - setupRank = Group.Find(value.ToLower()).Permission; - break; - case "control-rank": - if (Group.Find(value.ToLower()) != null) - controlRank = Group.Find(value.ToLower()).Permission; - break; - case "maps": - foreach (string mapname in value.Split(',')) - if(!String.IsNullOrEmpty(mapname) && !maps.Contains(mapname)) maps.Add(mapname); - break; - } - } - } - catch (Exception e) { Server.ErrorLog(e); } - } - } - public void SaveSettings() - { - File.Create("properties/lavasurvival.properties").Dispose(); - using (StreamWriter SW = File.CreateText("properties/lavasurvival.properties")) - { - SW.WriteLine("#Lava Survival main properties"); - SW.WriteLine("start-on-startup = " + startOnStartup.ToString().ToLower()); - SW.WriteLine("send-afk-to-main = " + sendAfkMain.ToString().ToLower()); - SW.WriteLine("vote-count = " + voteCount.ToString()); - SW.WriteLine("vote-time = " + voteTime.ToString()); - SW.WriteLine("lives = " + lifeNum.ToString()); - SW.WriteLine("setup-rank = " + Level.PermissionToName(setupRank).ToLower()); - SW.WriteLine("control-rank = " + Level.PermissionToName(controlRank).ToLower()); - SW.WriteLine("maps = " + maps.Concatenate(",")); - } - } - - public MapSettings LoadMapSettings(string name) - { - MapSettings settings = new MapSettings(name); - if (!Directory.Exists(propsPath)) Directory.CreateDirectory(propsPath); - if (!File.Exists(propsPath + name + ".properties")) - { - SaveMapSettings(settings); - return settings; - } - - foreach (string line in File.ReadAllLines(propsPath + name + ".properties")) - { - try - { - if (line[0] != '#') - { - string[] sp; - string value = line.Substring(line.IndexOf(" = ") + 3); - switch (line.Substring(0, line.IndexOf(" = ")).ToLower()) - { - case "fast-chance": - settings.fast = (byte)MathHelper.Clamp(decimal.Parse(value), 0, 100); - break; - case "killer-chance": - settings.killer = (byte)MathHelper.Clamp(decimal.Parse(value), 0, 100); - break; - case "destroy-chance": - settings.destroy = (byte)MathHelper.Clamp(decimal.Parse(value), 0, 100); - break; - case "water-chance": - settings.water = (byte)MathHelper.Clamp(decimal.Parse(value), 0, 100); - break; - case "layer-chance": - settings.layer = (byte)MathHelper.Clamp(decimal.Parse(value), 0, 100); - break; - case "layer-height": - settings.layerHeight = int.Parse(value); - break; - case "layer-count": - settings.layerCount = int.Parse(value); - break; - case "layer-interval": - settings.layerInterval = double.Parse(value); - break; - case "round-time": - settings.roundTime = double.Parse(value); - break; - case "flood-time": - settings.floodTime = double.Parse(value); - break; - case "block-flood": - sp = value.Split(','); - settings.blockFlood = new Pos(ushort.Parse(sp[0]), ushort.Parse(sp[1]), ushort.Parse(sp[2])); - break; - case "block-layer": - sp = value.Split(','); - settings.blockLayer = new Pos(ushort.Parse(sp[0]), ushort.Parse(sp[1]), ushort.Parse(sp[2])); - break; - case "safe-zone": - sp = value.Split('-'); - string[] p1 = sp[0].Split(','), p2 = sp[1].Split(','); - settings.safeZone = new Pos[] { new Pos(ushort.Parse(p1[0]), ushort.Parse(p1[1]), ushort.Parse(p1[2])), new Pos(ushort.Parse(p2[0]), ushort.Parse(p2[1]), ushort.Parse(p2[2])) }; - break; - } - } - } - catch (Exception e) { Server.ErrorLog(e); } - } - return settings; - } - public void SaveMapSettings(MapSettings settings) - { - if (!Directory.Exists(propsPath)) Directory.CreateDirectory(propsPath); - - File.Create(propsPath + settings.name + ".properties").Dispose(); - using (StreamWriter SW = File.CreateText(propsPath + settings.name + ".properties")) - { - SW.WriteLine("#Lava Survival properties for " + settings.name); - SW.WriteLine("fast-chance = " + settings.fast); - SW.WriteLine("killer-chance = " + settings.killer); - SW.WriteLine("destroy-chance = " + settings.destroy); - SW.WriteLine("water-chance = " + settings.water); - SW.WriteLine("layer-chance = " + settings.layer); - SW.WriteLine("layer-height = " + settings.layerHeight); - SW.WriteLine("layer-count = " + settings.layerCount); - SW.WriteLine("layer-interval = " + settings.layerInterval); - SW.WriteLine("round-time = " + settings.roundTime); - SW.WriteLine("flood-time = " + settings.floodTime); - SW.WriteLine("block-flood = " + settings.blockFlood.ToString()); - SW.WriteLine("block-layer = " + settings.blockLayer.ToString()); - SW.WriteLine(String.Format("safe-zone = {0}-{1}", settings.safeZone[0].ToString(), settings.safeZone[1].ToString())); - } - } - public void AddMap(string name) { if (!String.IsNullOrEmpty(name) && !maps.Contains(name.ToLower())) @@ -642,9 +469,8 @@ namespace MCGalaxy public bool InSafeZone(ushort x, ushort y, ushort z) { if (mapSettings == null) return false; - if (x >= mapSettings.safeZone[0].x && x <= mapSettings.safeZone[1].x && y >= mapSettings.safeZone[0].y && y <= mapSettings.safeZone[1].y && z >= mapSettings.safeZone[0].z && z <= mapSettings.safeZone[1].z) - return true; - return false; + return x >= mapSettings.safeZone[0].x && x <= mapSettings.safeZone[1].x && y >= mapSettings.safeZone[0].y + && y <= mapSettings.safeZone[1].y && z >= mapSettings.safeZone[0].z && z <= mapSettings.safeZone[1].z; } // Accessors @@ -672,64 +498,6 @@ namespace MCGalaxy } } - // Internal classes - public class MapSettings - { - public string name; - public byte fast, killer, destroy, water, layer; - public int layerHeight, layerCount; - public double layerInterval, roundTime, floodTime; - public Pos blockFlood, blockLayer; - public Pos[] safeZone; - - public MapSettings(string name) - { - this.name = name; - fast = 0; - killer = 100; - destroy = 0; - water = 0; - layer = 0; - layerHeight = 3; - layerCount = 10; - layerInterval = 2; - roundTime = 15; - floodTime = 5; - blockFlood = new Pos(); - blockLayer = new Pos(); - safeZone = new Pos[] { new Pos(), new Pos() }; - } - } - - public class MapData : IDisposable - { - public bool fast, killer, destroy, water, layer; - public byte block; - public int currentLayer; - public Timer roundTimer, floodTimer, layerTimer; - - public MapData(MapSettings settings) - { - fast = false; - killer = false; - destroy = false; - water = false; - layer = false; - block = Block.lava; - currentLayer = 1; - roundTimer = new Timer(TimeSpan.FromMinutes(settings.roundTime).TotalMilliseconds); roundTimer.AutoReset = false; - floodTimer = new Timer(TimeSpan.FromMinutes(settings.floodTime).TotalMilliseconds); floodTimer.AutoReset = false; - layerTimer = new Timer(TimeSpan.FromMinutes(settings.layerInterval).TotalMilliseconds); layerTimer.AutoReset = true; - } - - public void Dispose() - { - roundTimer.Dispose(); - floodTimer.Dispose(); - layerTimer.Dispose(); - } - } - public struct Pos { public ushort x, y, z; diff --git a/Games/TntWarsGame.cs b/Games/TntWars/TntWars.cs similarity index 100% rename from Games/TntWarsGame.cs rename to Games/TntWars/TntWars.cs diff --git a/Games/ZombieSurvival/ZombieGame.Core.cs b/Games/ZombieSurvival/ZombieGame.Core.cs index fb03c9cc0..93eb9acad 100644 --- a/Games/ZombieSurvival/ZombieGame.Core.cs +++ b/Games/ZombieSurvival/ZombieGame.Core.cs @@ -63,6 +63,7 @@ namespace MCGalaxy { void DoRound() { if (Status == ZombieGameStatus.NotStarted) return; List players = DoRoundCountdown(); + RoundInProgress = true; theEnd: Random random = new Random(); @@ -123,7 +124,6 @@ namespace MCGalaxy { Thread.Sleep(1000); if (!Server.ZombieModeOn) return null; Player.GlobalMessage("%4Round Start:%f 1..."); Thread.Sleep(1000); if (!Server.ZombieModeOn) return null; - RoundInProgress = true; int nonRefPlayers = 0; List players = new List(); diff --git a/Games/ZombieSurvival/ZombieGame.Game.cs b/Games/ZombieSurvival/ZombieGame.Game.cs index 4c13e5147..a4417396d 100644 --- a/Games/ZombieSurvival/ZombieGame.Game.cs +++ b/Games/ZombieSurvival/ZombieGame.Game.cs @@ -94,5 +94,16 @@ namespace MCGalaxy { Player.SendMessage(p, "There is a Zombie Survival game currently in-progress! " + "Join it by typing /g " + Server.zombie.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) return; + if(ZombieGame.alive.Contains(p)) + ZombieGame.alive.Remove(p); + if (ZombieGame.infectd.Contains(p)) + ZombieGame.infectd.Remove(p); + } } } diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj index 7e5ef9ffa..7a7e7718f 100644 --- a/MCGalaxy_.csproj +++ b/MCGalaxy_.csproj @@ -415,7 +415,11 @@ + + + + @@ -506,7 +510,6 @@ EconomyWindow.cs - Form @@ -529,7 +532,6 @@ EditText.cs - @@ -719,6 +721,8 @@ + + diff --git a/Network/Player.Networking.cs b/Network/Player.Networking.cs index 3ace1ca89..afa7cb7b8 100644 --- a/Network/Player.Networking.cs +++ b/Network/Player.Networking.cs @@ -190,24 +190,8 @@ namespace MCGalaxy { if (colorParse) message = Colors.EscapeColors(message); StringBuilder sb = new StringBuilder(message); - - if (colorParse) { - for (int i = 0; i < 128; i++) { - if (Colors.IsStandardColor((char)i)) { - if (i >= 'A' && i <= 'F') // WoM does not work with uppercase color codes. - sb.Replace("&" + (char)i, "&" + (char)(i + ' ')); - continue; - } - - CustomColor col = Colors.ExtColors[i]; - if (col.Undefined) { - sb.Replace("&" + (char)i, ""); continue; - } - if (!hasTextColors) { - sb.Replace("&" + (char)i, "&" + col.Fallback); continue; - } - } - } + if (colorParse) + ParseColors(sb); Chat.ApplyTokens(sb, this, colorParse); if ( Server.parseSmiley && parseSmiley ) { @@ -253,6 +237,24 @@ namespace MCGalaxy { } } + void ParseColors(StringBuilder sb) { + for (int i = 0; i < 128; i++) { + if (Colors.IsStandardColor((char)i)) { + if (i >= 'A' && i <= 'F') // WoM does not work with uppercase color codes. + sb.Replace("&" + (char)i, "&" + (char)(i + ' ')); + continue; + } + + CustomColor col = Colors.ExtColors[i]; + if (col.Undefined) { + sb.Replace("&" + (char)i, ""); continue; + } + if (!hasTextColors) { + sb.Replace("&" + (char)i, "&" + col.Fallback); continue; + } + } + } + public void SendMotd() { byte[] buffer = new byte[131]; buffer[0] = Opcode.Handshake; diff --git a/Player/Player.Handlers.cs b/Player/Player.Handlers.cs index c0d1523bf..7a609052e 100644 --- a/Player/Player.Handlers.cs +++ b/Player/Player.Handlers.cs @@ -350,31 +350,7 @@ namespace MCGalaxy { LoadIgnores(); if (type == 0x42) { hasCpe = true; - - SendExtInfo(18); - SendExtEntry(CpeExt.ClickDistance, 1); - SendExtEntry(CpeExt.CustomBlocks, 1); - SendExtEntry(CpeExt.HeldBlock, 1); - - SendExtEntry(CpeExt.TextHotkey, 1); - SendExtEntry(CpeExt.EnvColors, 1); - SendExtEntry(CpeExt.SelectionCuboid, 1); - - SendExtEntry(CpeExt.BlockPermissions, 1); - SendExtEntry(CpeExt.ChangeModel, 1); - SendExtEntry(CpeExt.EnvMapAppearance, 2); - - SendExtEntry(CpeExt.EnvWeatherType, 1); - SendExtEntry(CpeExt.HackControl, 1); - SendExtEntry(CpeExt.EmoteFix, 1); - - SendExtEntry(CpeExt.FullCP437, 1); - SendExtEntry(CpeExt.LongerMessages, 1); - SendExtEntry(CpeExt.BlockDefinitions, 1); - - SendExtEntry(CpeExt.BlockDefinitionsExt, 2); - SendExtEntry(CpeExt.TextColors, 1); - SendExtEntry(CpeExt.BulkBlockUpdate, 1); + SendCpeExtensions(); } try { left.Remove(name.ToLower()); } @@ -393,6 +369,35 @@ namespace MCGalaxy { } } + void SendCpeExtensions() { + SendExtInfo(19); + SendExtEntry(CpeExt.ClickDistance, 1); + SendExtEntry(CpeExt.CustomBlocks, 1); + SendExtEntry(CpeExt.HeldBlock, 1); + + SendExtEntry(CpeExt.TextHotkey, 1); + SendExtEntry(CpeExt.EnvColors, 1); + SendExtEntry(CpeExt.SelectionCuboid, 1); + + SendExtEntry(CpeExt.BlockPermissions, 1); + SendExtEntry(CpeExt.ChangeModel, 1); + SendExtEntry(CpeExt.EnvMapAppearance, 2); + + SendExtEntry(CpeExt.EnvWeatherType, 1); + SendExtEntry(CpeExt.HackControl, 1); + SendExtEntry(CpeExt.EmoteFix, 1); + + SendExtEntry(CpeExt.FullCP437, 1); + SendExtEntry(CpeExt.LongerMessages, 1); + SendExtEntry(CpeExt.BlockDefinitions, 1); + + SendExtEntry(CpeExt.BlockDefinitionsExt, 2); + SendExtEntry(CpeExt.TextColors, 1); + SendExtEntry(CpeExt.BulkBlockUpdate, 1); + + SendExtEntry(CpeExt.MessageTypes, 1); + } + bool CheckWhitelist() { if (!Server.useWhitelist) return true; @@ -1404,17 +1409,6 @@ return; return true; } } - - if (Server.lava.HasPlayer(this) && Server.lava.HasVote(text.ToLower()) ) { - if (Server.lava.AddVote(this, text.ToLower())) { - SendMessage("Your vote for &5" + text.ToLower().Capitalize() + Server.DefaultColor + " has been placed. Thanks!"); - Server.lava.map.ChatLevelOps(name + " voted for &5" + text.ToLower().Capitalize() + Server.DefaultColor + "."); - return true; - } else { - SendMessage("&cYou already voted!"); - return true; - } - } if (Server.voting) { string test = text.ToLower(); @@ -1426,6 +1420,8 @@ return; } } + if (Server.lava.HandlesChatMessage(this, text)) + return false; if (Server.votingforlevel && Server.zombie.HandlesChatMessage(this, text)) return true; return false; diff --git a/Player/Player.cs b/Player/Player.cs index 894f31911..9a5ed4331 100644 --- a/Player/Player.cs +++ b/Player/Player.cs @@ -234,7 +234,6 @@ namespace MCGalaxy { public UndoCache UndoBuffer = new UndoCache(); public UndoCache RedoBuffer = new UndoCache(); - public bool showPortals = false; public bool showMBs = false;