From 10465903fefd6a3c6abd15f6f74792710f41c749 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 24 Jun 2018 22:00:14 +1000 Subject: [PATCH] You can change LS settings while game is running --- MCGalaxy/Commands/Fun/CTF/CmdCtf.cs | 16 +++--- MCGalaxy/Commands/Fun/CmdCountdown.cs | 2 +- MCGalaxy/Commands/Fun/CmdLavaSurvival.cs | 1 - MCGalaxy/Games/CTF/CtfConfig.cs | 57 +++++++-------------- MCGalaxy/Games/CTF/CtfGame.Plugin.cs | 7 ++- MCGalaxy/Games/CTF/CtfGame.cs | 11 ++-- MCGalaxy/Games/LavaSurvival/LSGame.Round.cs | 4 -- MCGalaxy/Games/LavaSurvival/LSGame.cs | 4 ++ MCGalaxy/Player/Warp.cs | 4 +- 9 files changed, 43 insertions(+), 63 deletions(-) diff --git a/MCGalaxy/Commands/Fun/CTF/CmdCtf.cs b/MCGalaxy/Commands/Fun/CTF/CmdCtf.cs index 73fd48d92..07b55cd11 100644 --- a/MCGalaxy/Commands/Fun/CTF/CmdCtf.cs +++ b/MCGalaxy/Commands/Fun/CTF/CmdCtf.cs @@ -51,11 +51,11 @@ namespace MCGalaxy.Commands.Fun { } else if (IsDeleteCommand(prop)) { HandleRemove(p); } if (prop.CaselessEq("bluespawn")) { - cfg.BlueSpawnX = p.Pos.X; cfg.BlueSpawnY = p.Pos.Y; cfg.BlueSpawnZ = p.Pos.Z; + cfg.BlueSpawn = (Vec3U16)p.Pos.FeetBlockCoords; Player.Message(p, "Set spawn of blue team to your position."); UpdateConfig(p, cfg); } else if (prop.CaselessEq("redspawn")) { - cfg.RedSpawnX = p.Pos.X; cfg.RedSpawnY = p.Pos.Y; cfg.RedSpawnZ = p.Pos.Z; + cfg.RedSpawn = (Vec3U16)p.Pos.FeetBlockCoords; Player.Message(p, "Set spawn of red team to your position."); UpdateConfig(p, cfg); } else if (prop.CaselessEq("blueflag")) { @@ -100,11 +100,11 @@ namespace MCGalaxy.Commands.Fun { static bool BlueFlagCallback(Player p, Vec3S32[] marks, object state, BlockID block) { CtfMapConfig cfg = RetrieveConfig(p); - Vec3S32 P = marks[0]; - cfg.BlueFlagX = P.X; cfg.BlueFlagY = P.Y; cfg.BlueFlagZ = P.Z; + Vec3U16 P = (Vec3U16)marks[0]; + cfg.BlueFlagPos = P; Player.Message(p, "Set flag position of blue team to ({0})", P); - block = p.level.GetBlock((ushort)P.X, (ushort)P.Y, (ushort)P.Z); + block = p.level.GetBlock(P.X, P.Y, P.Z); if (block == Block.Air) block = Block.Blue; cfg.BlueFlagBlock = block; Player.Message(p, "Set flag block of blue team to {0}", Block.GetName(p, block)); @@ -115,11 +115,11 @@ namespace MCGalaxy.Commands.Fun { static bool RedFlagCallback(Player p, Vec3S32[] marks, object state, BlockID block) { CtfMapConfig cfg = RetrieveConfig(p); - Vec3S32 P = marks[0]; - cfg.RedFlagX = P.X; cfg.RedFlagY = P.Y; cfg.RedFlagZ = P.Z; + Vec3U16 P = (Vec3U16)marks[0]; + cfg.RedFlagPos = P; Player.Message(p, "Set flag position of red team to ({0})", P); - block = p.level.GetBlock((ushort)P.X, (ushort)P.Y, (ushort)P.Z); + block = p.level.GetBlock(P.X, P.Y, P.Z); if (block == Block.Air) block = Block.Red; cfg.RedFlagBlock = block; Player.Message(p, "Set flag block of red team to {0}", Block.GetName(p, block)); diff --git a/MCGalaxy/Commands/Fun/CmdCountdown.cs b/MCGalaxy/Commands/Fun/CmdCountdown.cs index 215351fa2..5d6826d72 100644 --- a/MCGalaxy/Commands/Fun/CmdCountdown.cs +++ b/MCGalaxy/Commands/Fun/CmdCountdown.cs @@ -107,7 +107,7 @@ namespace MCGalaxy.Commands.Fun { } game.FreezeMode = mode == "freeze" || mode == "frozen"; - game.SpeedType = speed; + game.SpeedType = speed; game.Start(p, "countdown", int.MaxValue); } diff --git a/MCGalaxy/Commands/Fun/CmdLavaSurvival.cs b/MCGalaxy/Commands/Fun/CmdLavaSurvival.cs index 1eebf72a0..4876804ea 100644 --- a/MCGalaxy/Commands/Fun/CmdLavaSurvival.cs +++ b/MCGalaxy/Commands/Fun/CmdLavaSurvival.cs @@ -41,7 +41,6 @@ namespace MCGalaxy.Commands.Fun { if (p == null) { Player.Message(p, "/{0} setup can only be used in-game.", name); return; } if (args.Length < 2) { SetupHelp(p); return; } - if (game.Running) { Player.Message(p, "You cannot configure Lava Survival while a game is active."); return; } string group = args[1]; LSGame ls = (LSGame)game; diff --git a/MCGalaxy/Games/CTF/CtfConfig.cs b/MCGalaxy/Games/CTF/CtfConfig.cs index 7488292a5..00064f42e 100644 --- a/MCGalaxy/Games/CTF/CtfConfig.cs +++ b/MCGalaxy/Games/CTF/CtfConfig.cs @@ -20,43 +20,26 @@ using System; using System.IO; using MCGalaxy.Config; +using MCGalaxy.Maths; using BlockID = System.UInt16; namespace MCGalaxy.Games { public sealed class CtfMapConfig { - - [ConfigInt("base.red.x", null, 0)] - public int RedFlagX; - [ConfigInt("base.red.y", null, 0)] - public int RedFlagY; - [ConfigInt("base.red.z", null, 0)] - public int RedFlagZ; + + [ConfigVec3("base.red.pos", null)] + public Vec3U16 RedFlagPos; [ConfigBlock("base.red.block", null, Block.Air)] public BlockID RedFlagBlock; + [ConfigVec3("base.red.spawn", null)] + public Vec3U16 RedSpawn; - [ConfigInt("base.blue.x", null, 0)] - public int BlueFlagX; - [ConfigInt("base.blue.y", null, 0)] - public int BlueFlagY; - [ConfigInt("base.blue.z", null, 0)] - public int BlueFlagZ; + [ConfigVec3("base.blue.pos", null)] + public Vec3U16 BlueFlagPos; [ConfigBlock("base.blue.block", null, Block.Air)] public BlockID BlueFlagBlock; - - [ConfigInt("base.red.spawnx", null, 0)] - public int RedSpawnX; - [ConfigInt("base.red.spawny", null, 0)] - public int RedSpawnY; - [ConfigInt("base.red.spawnz", null, 0)] - public int RedSpawnZ; - - [ConfigInt("base.blue.spawnx", null, 0)] - public int BlueSpawnX; - [ConfigInt("base.blue.spawny", null, 0)] - public int BlueSpawnY; - [ConfigInt("base.blue.spawnz", null, 0)] - public int BlueSpawnZ; + [ConfigVec3("base.blue.spawn", null)] + public Vec3U16 BlueSpawn; [ConfigInt("map.line.z", null, 0)] public int ZDivider; @@ -72,20 +55,16 @@ namespace MCGalaxy.Games { public int Capture_PointsLost; - /// Sets the default CTF config values for the given map. - public void SetDefaults(Level map) { - ZDivider = map.Length / 2; - RedFlagBlock = Block.Red; + public void SetDefaults(Level lvl) { + ZDivider = lvl.Length / 2; + RedFlagBlock = Block.Red; BlueFlagBlock = Block.Blue; - int midX = map.Width / 2, maxZ = map.Length - 1; + ushort midX = (ushort)(lvl.Width / 2), maxZ = (ushort)(lvl.Length - 1); - RedFlagX = midX; RedSpawnX = midX * 32; - RedFlagY = 6; RedSpawnY = 4 * 32 + Entities.CharacterHeight; - RedFlagZ = 0; RedSpawnZ = 0 * 32; - - BlueFlagX = midX; BlueSpawnX = midX * 32; - BlueFlagY = 6; BlueSpawnY = 4 * 32 + Entities.CharacterHeight; - BlueFlagZ = maxZ; BlueSpawnZ = maxZ * 32; + RedFlagPos = new Vec3U16(midX, 6, 0); + RedSpawn = new Vec3U16(midX, 4, 0); + BlueFlagPos = new Vec3U16(midX, 6, maxZ); + BlueSpawn = new Vec3U16(midX, 4, maxZ); RoundPoints = 3; Tag_PointsGained = 5; diff --git a/MCGalaxy/Games/CTF/CtfGame.Plugin.cs b/MCGalaxy/Games/CTF/CtfGame.Plugin.cs index 7893f087a..122ca7d10 100644 --- a/MCGalaxy/Games/CTF/CtfGame.Plugin.cs +++ b/MCGalaxy/Games/CTF/CtfGame.Plugin.cs @@ -120,8 +120,11 @@ namespace MCGalaxy.Games { if (p.level != Map) return; CtfTeam team = TeamOf(p); - if (team != null) pos = team.SpawnPos; - if (team != null && respawning) DropFlag(p, team); + if (team == null) return; + if (respawning) DropFlag(p, team); + + Vec3U16 coords = team.SpawnPos; + pos = Position.FromFeetBlockCoords(coords.X, coords.Y, coords.Z); } void HandleTabListEntryAdded(Entity entity, ref string tabName, ref string tabGroup, Player dst) { diff --git a/MCGalaxy/Games/CTF/CtfGame.cs b/MCGalaxy/Games/CTF/CtfGame.cs index 6b32cfe88..03043b3e5 100644 --- a/MCGalaxy/Games/CTF/CtfGame.cs +++ b/MCGalaxy/Games/CTF/CtfGame.cs @@ -37,8 +37,7 @@ namespace MCGalaxy.Games { public string Name, Color; public string ColoredName { get { return Color + Name; } } public int Captures; - public Vec3U16 FlagPos; - public Position SpawnPos; + public Vec3U16 FlagPos, SpawnPos; public BlockID FlagBlock; public VolatileArray Members = new VolatileArray(); @@ -83,12 +82,12 @@ namespace MCGalaxy.Games { CtfMapConfig cfg = Config; Red.FlagBlock = cfg.RedFlagBlock; - Red.FlagPos = new Vec3U16((ushort)cfg.RedFlagX, (ushort)cfg.RedFlagY, (ushort)cfg.RedFlagZ); - Red.SpawnPos = new Position(cfg.RedSpawnX, cfg.RedSpawnY, cfg.RedSpawnZ); + Red.FlagPos = cfg.RedFlagPos; + Red.SpawnPos = cfg.RedSpawn; Blue.FlagBlock = cfg.BlueFlagBlock; - Blue.FlagPos = new Vec3U16((ushort)cfg.BlueFlagX, (ushort)cfg.BlueFlagY, (ushort)cfg.BlueFlagZ); - Blue.SpawnPos = new Position(cfg.BlueSpawnX, cfg.BlueSpawnY, cfg.BlueSpawnZ); + Blue.FlagPos = cfg.BlueFlagPos; + Blue.SpawnPos = cfg.BlueSpawn; } diff --git a/MCGalaxy/Games/LavaSurvival/LSGame.Round.cs b/MCGalaxy/Games/LavaSurvival/LSGame.Round.cs index 1b62956d5..96a33d66d 100644 --- a/MCGalaxy/Games/LavaSurvival/LSGame.Round.cs +++ b/MCGalaxy/Games/LavaSurvival/LSGame.Round.cs @@ -104,10 +104,6 @@ namespace MCGalaxy.Games { protected override bool SetMap(string map) { bool success = base.SetMap(map); if (!success) return false; - - cfg = new LSMapConfig(); - cfg.SetDefaults(Map); - cfg.Load(Map.name); UpdateMapConfig(); Map.SetPhysics(destroyMode ? 2 : 1); diff --git a/MCGalaxy/Games/LavaSurvival/LSGame.cs b/MCGalaxy/Games/LavaSurvival/LSGame.cs index 8cb8385e5..458fbd870 100644 --- a/MCGalaxy/Games/LavaSurvival/LSGame.cs +++ b/MCGalaxy/Games/LavaSurvival/LSGame.cs @@ -55,6 +55,10 @@ namespace MCGalaxy.Games { } public void UpdateMapConfig() { + cfg = new LSMapConfig(); + cfg.SetDefaults(Map); + cfg.Load(Map.name); + killerMode = rand.Next(1, 101) <= cfg.KillerChance; destroyMode = rand.Next(1, 101) <= cfg.DestroyChance; waterMode = rand.Next(1, 101) <= cfg.WaterChance; diff --git a/MCGalaxy/Player/Warp.cs b/MCGalaxy/Player/Warp.cs index 2b3fdef77..6a9cc9b45 100644 --- a/MCGalaxy/Player/Warp.cs +++ b/MCGalaxy/Player/Warp.cs @@ -101,12 +101,12 @@ namespace MCGalaxy { string[] parts = line.Split(':'); Warp warp = new Warp(); try { - warp.Name = parts[0]; + warp.Name = parts[0]; warp.Level = parts[1]; warp.Pos.X = int.Parse(parts[2]); warp.Pos.Y = int.Parse(parts[3]); warp.Pos.Z = int.Parse(parts[4]); - warp.Yaw = byte.Parse(parts[5]); + warp.Yaw = byte.Parse(parts[5]); warp.Pitch = byte.Parse(parts[6]); Items.Add(warp); } catch {