From 446560bf4fbf8f5643370179ba5cc7d8c1389977 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 20 Mar 2016 23:54:11 +1100 Subject: [PATCH] Can like and dislike maps now for zombie survival and lava survival. --- Commands/Fun/RateMapCmds.cs | 67 +++++++++++++++++++++++++ Games/ZombieSurvival/ZombieGame.Game.cs | 2 + Games/ZombieSurvival/ZombieGame.cs | 13 ++++- Levels/IO/LvlProperties.cs | 11 +++- Levels/Level.cs | 1 + MCGalaxy_.csproj | 1 + Player/Player.cs | 1 + 7 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 Commands/Fun/RateMapCmds.cs diff --git a/Commands/Fun/RateMapCmds.cs b/Commands/Fun/RateMapCmds.cs new file mode 100644 index 000000000..a1376f4de --- /dev/null +++ b/Commands/Fun/RateMapCmds.cs @@ -0,0 +1,67 @@ +/* + Copyright 2015 MCGalaxy + + 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.Threading; + +namespace MCGalaxy.Commands { + + public sealed class MapLikeCmd : Command { + public override string name { get { return "maplike"; } } + public override string shortcut { get { return "like"; } } + public override string type { get { return CommandTypes.Games; } } + public override bool museumUsable { get { return true; } } + public override LevelPermission defaultRank { get { return LevelPermission.Banned; } } + public override bool Enabled { get { return Server.ZombieModeOn || Server.lava.active; } } + + public override void Use(Player p, string message) { + if (p == null) { MessageInGameOnly(p); return; } + if (p.ratedMap) { Player.SendMessage(p, "You have already liked this map."); return; } + p.level.Likes++; + p.ratedMap = true; + Player.SendMessage(p, "You have liked this map."); + } + + public override void Help(Player p) { + Player.SendMessage(p, "%T/maplike"); + Player.SendMessage(p, "%HIncrements the number of times this map has been liked."); + } + } + + public sealed class MapDislikeCmd : Command { + public override string name { get { return "mapdislike"; } } + public override string shortcut { get { return "dislike"; } } + public override string type { get { return CommandTypes.Games; } } + public override bool museumUsable { get { return true; } } + public override LevelPermission defaultRank { get { return LevelPermission.Banned; } } + public override bool Enabled { get { return Server.ZombieModeOn || Server.lava.active; } } + + public override void Use(Player p, string message) { + if (p == null) { MessageInGameOnly(p); return; } + if (p.ratedMap) { Player.SendMessage(p, "You have already disliked this map."); return; } + p.level.Dislikes++; + p.ratedMap = true; + Player.SendMessage(p, "You have disliked this map."); + } + + public override void Help(Player p) { + Player.SendMessage(p, "%T/mapdislike"); + Player.SendMessage(p, "%HIncrements the number of times this map has been disliked."); + } + } +} diff --git a/Games/ZombieSurvival/ZombieGame.Game.cs b/Games/ZombieSurvival/ZombieGame.Game.cs index 22fe24b0d..7ff967fed 100644 --- a/Games/ZombieSurvival/ZombieGame.Game.cs +++ b/Games/ZombieSurvival/ZombieGame.Game.cs @@ -109,6 +109,8 @@ namespace MCGalaxy.Games { double startLeft = (RoundStart - DateTime.UtcNow).TotalSeconds; if (startLeft >= 0) 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.BottomRight1, "%SYou have &a" + p.money + " %S" + Server.moneys); UpdatePlayerStatus(p); return; diff --git a/Games/ZombieSurvival/ZombieGame.cs b/Games/ZombieSurvival/ZombieGame.cs index fe1b4d8ba..536c29431 100644 --- a/Games/ZombieSurvival/ZombieGame.cs +++ b/Games/ZombieSurvival/ZombieGame.cs @@ -156,7 +156,13 @@ namespace MCGalaxy.Games { } void ChangeLevel(string next) { + Player[] online = PlayerInfo.Online.Items; if (CurrentLevel != null) { + bool saveSettings = false; + foreach (Player pl in online) + saveSettings |= pl.ratedMap; + if (saveSettings) Level.SaveSettings(CurrentLevel); + CurrentLevel.ChatLevel("The next map has been chosen - " + Colors.red + next.ToLower()); CurrentLevel.ChatLevel("Please wait while you are transfered."); } @@ -169,8 +175,9 @@ namespace MCGalaxy.Games { if (Server.ZombieOnlyServer) Server.mainLevel = CurrentLevel; - Player[] online = PlayerInfo.Online.Items; + online = PlayerInfo.Online.Items; foreach (Player pl in online) { + pl.ratedMap = 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); @@ -192,6 +199,10 @@ namespace MCGalaxy.Games { LastLevelName = ""; CurrentLevelName = ""; CurrentLevel = null; + + Player[] online = PlayerInfo.Online.Items; + foreach (Player pl in online) + pl.ratedMap = false; } void UpdatePlayerStatus(Player p) { diff --git a/Levels/IO/LvlProperties.cs b/Levels/IO/LvlProperties.cs index e33ed1b41..3b5173597 100644 --- a/Levels/IO/LvlProperties.cs +++ b/Levels/IO/LvlProperties.cs @@ -14,7 +14,7 @@ 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.IO; @@ -76,6 +76,9 @@ namespace MCGalaxy.Levels.IO { writer.WriteLine("Weather = " + level.weather); writer.WriteLine("Texture = " + level.terrainUrl); writer.WriteLine("TexturePack = " + level.texturePackUrl); + + writer.WriteLine("Likes = " + level.Likes); + writer.WriteLine("Dislikes = " + level.Dislikes); } static string GetName(LevelPermission perm) { @@ -207,11 +210,15 @@ namespace MCGalaxy.Levels.IO { case "texture": level.terrainUrl = value; break; case "texturepack": - level.texturePackUrl = value; break; + level.texturePackUrl = value; break; case "buildable": level.Buildable = bool.Parse(value); break; case "deletable": level.Deletable = bool.Parse(value); break; + case "likes": + level.Likes = int.Parse(value); break; + case "dislikes": + level.Dislikes = int.Parse(value); break; } } diff --git a/Levels/Level.cs b/Levels/Level.cs index 8c71c6342..b102b63a7 100644 --- a/Levels/Level.cs +++ b/Levels/Level.cs @@ -204,6 +204,7 @@ namespace MCGalaxy BufferedBlockSender bulkSender; public List C4list = new List(); + public int Likes, Dislikes; public Level(string n, ushort x, ushort y, ushort z, string type, int seed = 0, bool useSeed = false) { diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj index 5f7caae24..d1d93e451 100644 --- a/MCGalaxy_.csproj +++ b/MCGalaxy_.csproj @@ -187,6 +187,7 @@ + diff --git a/Player/Player.cs b/Player/Player.cs index d6b8072b2..9393b15c3 100644 --- a/Player/Player.cs +++ b/Player/Player.cs @@ -199,6 +199,7 @@ namespace MCGalaxy { public bool flipHead = true; public int playersInfected = 0; internal string lastSpawnColor = ""; + internal bool ratedMap = false; //Tnt Wars public bool PlayingTntWars = false;