From 3646407eefe54693742465b2808cd2fe3c0da372 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 21 Mar 2016 13:22:05 +1100 Subject: [PATCH] Add build types (normal/nomodify/modifyonly) --- Commands/Fun/CmdMapSet.cs | 3 ++- Commands/Fun/ZombieSurvival/CmdHuman.cs | 10 +++++----- Games/LavaSurvival/LavaSurvival.cs | 2 +- Games/ZombieSurvival/ZombieGame.Core.cs | 10 +++++----- Games/ZombieSurvival/ZombieGame.Game.cs | 17 +++++++++++++++-- Games/ZombieSurvival/ZombieGame.cs | 4 ++-- Levels/BlockDefinitions.cs | 4 ++-- Levels/IO/LvlFile.cs | 2 ++ Levels/Level.cs | 21 ++++++++++----------- Player/Player.CPE.cs | 9 +++------ Player/Player.cs | 7 +++---- 11 files changed, 50 insertions(+), 39 deletions(-) diff --git a/Commands/Fun/CmdMapSet.cs b/Commands/Fun/CmdMapSet.cs index f031f7a62..b78e40327 100644 --- a/Commands/Fun/CmdMapSet.cs +++ b/Commands/Fun/CmdMapSet.cs @@ -34,8 +34,9 @@ namespace MCGalaxy.Commands { if (message == "") { Player.SendMessage(p, "Map authors: " + p.level.Authors); Player.SendMessage(p, "Pillaring allowed: " + p.level.Pillaring); + Player.SendMessage(p, "Build type: " + p.level.BuildType); } - p.level.Authors = message.Replace(" ", "%S, ") + p.level.Authors = message.Replace(" ", "%S, "); Player.SendMessage(p, "Sets the authors of the map to: " + message); } diff --git a/Commands/Fun/ZombieSurvival/CmdHuman.cs b/Commands/Fun/ZombieSurvival/CmdHuman.cs index 42575e782..e0fc4ad2c 100644 --- a/Commands/Fun/ZombieSurvival/CmdHuman.cs +++ b/Commands/Fun/ZombieSurvival/CmdHuman.cs @@ -30,17 +30,17 @@ namespace MCGalaxy.Commands { public override void Use(Player p, string message) { if (p == null) { MessageInGameOnly(p); return; } - if (p.assertingSurvive) { - Player.SendMessage(p, "You cannot un-assert that you will be infected."); return; + if (p.pledgeSurvive) { + Player.SendMessage(p, "You cannot un-pledge that you will be infected."); return; } - p.assertingSurvive = true; + p.pledgeSurvive = true; Server.zombie.CurrentLevel - .ChatLevel(p.FullName + " %Sasserts that they will not succumb to the infection!"); + .ChatLevel(p.FullName + " %Spledges that they will not succumb to the infection!"); } public override void Help(Player p) { - Player.SendMessage(p, "%T/human %H- asserts that you will not be infected."); + Player.SendMessage(p, "%T/human %H- pledges that you will not be infected."); Player.SendMessage(p, "%HIf you survive, you receive an &aextra 5 %3" + Server.moneys); Player.SendMessage(p, "%HHowever, if you are infected, you will &close 2 %3" + Server.moneys); } diff --git a/Games/LavaSurvival/LavaSurvival.cs b/Games/LavaSurvival/LavaSurvival.cs index fbc7dbe9d..1be2be4f1 100644 --- a/Games/LavaSurvival/LavaSurvival.cs +++ b/Games/LavaSurvival/LavaSurvival.cs @@ -303,7 +303,7 @@ namespace MCGalaxy.Games Player[] online = PlayerInfo.Online.Items; foreach (Player pl in online) { pl.ratedMap = false; - pl.assertingSurvive = false; + pl.pledgeSurvive = false; if (pl.level == oldMap) { if (sendAfkMain && Server.afkset.Contains(pl.name)) Command.all.Find("main").Use(pl, ""); diff --git a/Games/ZombieSurvival/ZombieGame.Core.cs b/Games/ZombieSurvival/ZombieGame.Core.cs index 490bb0919..721cec675 100644 --- a/Games/ZombieSurvival/ZombieGame.Core.cs +++ b/Games/ZombieSurvival/ZombieGame.Core.cs @@ -193,9 +193,9 @@ namespace MCGalaxy.Games { } void CheckAssertHuman(Player pAlive) { - if (!pAlive.assertingSurvive) return; - pAlive.assertingSurvive = false; - CurrentLevel.ChatLevel(pAlive.FullName + "%Sfailed the challenge of not being infected."); + if (!pAlive.pledgeSurvive) return; + pAlive.pledgeSurvive = false; + CurrentLevel.ChatLevel(pAlive.FullName + "%Sbroke their pledge of not being infected."); pAlive.money = Math.Max(pAlive.money - 2, 0); pAlive.OnMoneyChanged(); } @@ -254,9 +254,9 @@ namespace MCGalaxy.Games { ResetPlayer(pl, ref playersString); } else { foreach (Player pl in alive) { - if (pl.assertingSurvive) { + if (pl.pledgeSurvive) { pl.SendMessage("You received &a5 %3" + Server.moneys + - "%s for successfully asserting that you would survive."); + "%s for successfully pledging that you would survive."); pl.money += 5; pl.OnMoneyChanged(); } diff --git a/Games/ZombieSurvival/ZombieGame.Game.cs b/Games/ZombieSurvival/ZombieGame.Game.cs index fd9a1e8a7..dc64ad4fa 100644 --- a/Games/ZombieSurvival/ZombieGame.Game.cs +++ b/Games/ZombieSurvival/ZombieGame.Game.cs @@ -24,6 +24,14 @@ namespace MCGalaxy.Games { public override bool HandlesManualChange(Player p, ushort x, ushort y, ushort z, byte action, byte tile, byte b) { + + if (CurrentLevel.BuildType == BuildType.NoModify) { + p.RevertBlock(x, y, z); return true; + } else if (CurrentLevel.BuildType == BuildType.ModifyOnly + && p.level.GetTile(x, y, z) == Block.op_air) { + p.RevertBlock(x, y, z); return true; + } + if (action == 1 && !CurrentLevel.Pillaring && !p.referee) { if (p.lastYblock == y - 1 && p.lastXblock == x && p.lastZblock == z ) { p.blocksStacked++; @@ -113,8 +121,8 @@ namespace MCGalaxy.Games { public override void PlayerJoinedServer(Player p) { if (Status == ZombieGameStatus.NotStarted) return; - Player.SendMessage(p, "There is a Zombie Survival game currently in-progress! " + - "Join it by typing /g " + CurrentLevelName); + Player.SendMessage(p, "A Zombie Survival game is running! " + + "Type %T/g " + CurrentLevelName + " %Sto join."); } public override void PlayerJoinedLevel(Player p, Level oldLvl) { @@ -132,6 +140,10 @@ namespace MCGalaxy.Games { p.SendMessage("%a" + (int)startLeft + " %Sseconds left until the round starts. %aRun!"); p.SendMessage("This map has &a" + CurrentLevel.Likes + " likes %Sand &c" + CurrentLevel.Dislikes + " dislikes"); + p.SendCpeMessage(CpeMessageType.Status2, + "%SPillaring " + (CurrentLevel.Pillaring ? "&aAllowed" : "&cForbidden") + + "%S, Type is &a" + CurrentLevel.BuildType); + if (CurrentLevel.Authors != "") p.SendMessage("It was created by " + CurrentLevel.Authors); p.SendCpeMessage(CpeMessageType.BottomRight1, "%SYou have &a" + p.money + " %S" + Server.moneys); @@ -141,6 +153,7 @@ namespace MCGalaxy.Games { p.SendCpeMessage(CpeMessageType.BottomRight1, ""); p.SendCpeMessage(CpeMessageType.Status1, ""); + p.SendCpeMessage(CpeMessageType.Status2, ""); Alive.Remove(p); Infected.Remove(p); } diff --git a/Games/ZombieSurvival/ZombieGame.cs b/Games/ZombieSurvival/ZombieGame.cs index 582a12708..044002feb 100644 --- a/Games/ZombieSurvival/ZombieGame.cs +++ b/Games/ZombieSurvival/ZombieGame.cs @@ -178,7 +178,7 @@ namespace MCGalaxy.Games { online = PlayerInfo.Online.Items; foreach (Player pl in online) { pl.ratedMap = false; - pl.assertingSurvive = false; + pl.pledgeSurvive = false; if (!pl.level.name.CaselessEq(next) && pl.level.name.CaselessEq(LastLevelName)) { pl.SendMessage("Going to the next map!"); Command.all.Find("goto").Use(pl, next); @@ -204,7 +204,7 @@ namespace MCGalaxy.Games { Player[] online = PlayerInfo.Online.Items; foreach (Player pl in online) { pl.ratedMap = false; - pl.assertingSurvive = false; + pl.pledgeSurvive = false; } } diff --git a/Levels/BlockDefinitions.cs b/Levels/BlockDefinitions.cs index d03ea2a2e..56cc9072e 100644 --- a/Levels/BlockDefinitions.cs +++ b/Levels/BlockDefinitions.cs @@ -156,7 +156,7 @@ namespace MCGalaxy { SendDefineBlock(pl, def); if (pl.HasCpeExt(CpeExt.BlockPermissions)) - pl.SendSetBlockPermission(def.BlockID, pl.level.Buildable, pl.level.Deletable); + pl.SendSetBlockPermission(def.BlockID, pl.level.CanPlace, pl.level.CanDelete); } Save(global, level); } @@ -197,7 +197,7 @@ namespace MCGalaxy { SendDefineBlock(pl, def); if (pl.HasCpeExt(CpeExt.BlockPermissions)) - pl.SendSetBlockPermission(def.BlockID, pl.level.Buildable, pl.level.Deletable); + pl.SendSetBlockPermission(def.BlockID, pl.level.CanPlace, pl.level.CanDelete); } } diff --git a/Levels/IO/LvlFile.cs b/Levels/IO/LvlFile.cs index 3107e8f34..34ca7dd4e 100644 --- a/Levels/IO/LvlFile.cs +++ b/Levels/IO/LvlFile.cs @@ -21,6 +21,8 @@ using System.IO.Compression; namespace MCGalaxy.Levels.IO { + //WARNING! DO NOT CHANGE THE WAY THE LEVEL IS SAVED/LOADED! + //You MUST make it able to save and load as a new version other wise you will make old levels incompatible! public static class LvlFile { public static void Save(Level level, string file) { diff --git a/Levels/Level.cs b/Levels/Level.cs index 038b6d33c..56841935f 100644 --- a/Levels/Level.cs +++ b/Levels/Level.cs @@ -35,17 +35,13 @@ using MCGalaxy.Levels.IO; namespace MCGalaxy { - public enum LevelPermission //int is default - { - Banned = -20, - Guest = 0, - Builder = 30, - AdvBuilder = 50, - Operator = 80, - Admin = 100, - Nobody = 120, - Null = 150 + public enum LevelPermission { + Banned = -20, Guest = 0, Builder = 30, + AdvBuilder = 50, Operator = 80, + Admin = 100, Nobody = 120, Null = 150 } + + public enum BuildType { Normal, ModifyOnly, NoModify }; public sealed partial class Level : IDisposable { @@ -208,7 +204,10 @@ namespace MCGalaxy public int Likes, Dislikes; public string Authors = ""; public bool Pillaring = !Server.zombie.noPillaring; - + public BuildType BuildType = BuildType.Normal; + public bool CanPlace { get { return Buildable && BuildType != BuildType.NoModify; } } + public bool CanDelete { get { return Deletable && BuildType != BuildType.NoModify; } } + public Level(string n, ushort x, ushort y, ushort z, string type, int seed = 0, bool useSeed = false) { //onLevelSave += null; diff --git a/Player/Player.CPE.cs b/Player/Player.CPE.cs index 65efa0391..74d8cf295 100644 --- a/Player/Player.CPE.cs +++ b/Player/Player.CPE.cs @@ -239,18 +239,15 @@ namespace MCGalaxy public void SendCurrentBlockPermissions() { byte count = hasCustomBlocks ? Block.CpeCount : Block.OriginalCount; for (byte i = 0; i < count; i++) { - bool canPlace = Block.canPlace(this, i); - bool canDelete = canPlace; - - if (!level.Buildable) canPlace = false; - if (!level.Deletable) canDelete = false; + bool canPlace = Block.canPlace(this, i) && level.CanPlace; + bool canDelete = Block.canPlace(this, i) && level.CanDelete; SendSetBlockPermission(i, canPlace, canDelete); } if (!hasBlockDefs) return; for (int i = count; i < 256; i++) { if (level.CustomBlockDefs[i] == null) continue; - SendSetBlockPermission((byte)i, level.Buildable, level.Deletable); + SendSetBlockPermission((byte)i, level.CanPlace, level.CanDelete); } } } diff --git a/Player/Player.cs b/Player/Player.cs index cc7b0d3ca..c8d1169ea 100644 --- a/Player/Player.cs +++ b/Player/Player.cs @@ -198,7 +198,7 @@ namespace MCGalaxy { public int playersInfected = 0; internal string lastSpawnColor = ""; internal bool ratedMap = false; - internal bool assertingSurvive = false; + internal bool pledgeSurvive = false; //Tnt Wars public bool PlayingTntWars = false; @@ -341,9 +341,8 @@ namespace MCGalaxy { byte head = level.GetTile(x, y, z); byte feet = level.GetTile(x, (ushort)(y - 1), z); - if (Block.Walkthrough(Block.Convert(head)) && Block.Walkthrough(Block.Convert(feet))) - return false; - return Block.Convert(head) != Block.Zero && Block.Convert(head) != Block.op_air; + return (Block.Walkthrough(Block.Convert(head)) || head == Block.Zero) + && (Block.Walkthrough(Block.Convert(feet)) || feet == Block.Zero); } //This is so that plugin devs can declare a player without needing a socket..