From 52fa4f53ca0e2d3c2fb099fc47d1bf4f42d71ba6 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 25 Jan 2016 17:18:10 +1100 Subject: [PATCH] Move more zombie game related code into IGame implementation, also refactor the code somewhat. --- Commands/other/CmdVote.cs | 79 ++++++++++++++------------------- Games/IGame.cs | 12 ++++++ Games/ZombieGame.Game.cs | 50 +++++++++++++++------ Games/ZombieGame.cs | 2 +- Player/Player.cs | 91 ++++++++++----------------------------- 5 files changed, 104 insertions(+), 130 deletions(-) diff --git a/Commands/other/CmdVote.cs b/Commands/other/CmdVote.cs index c53f09e0a..8df689f16 100644 --- a/Commands/other/CmdVote.cs +++ b/Commands/other/CmdVote.cs @@ -1,20 +1,20 @@ /* - Copyright 2011 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. -*/ + Copyright 2011 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. + */ namespace MCGalaxy.Commands { public sealed class CmdVote : Command @@ -26,38 +26,25 @@ namespace MCGalaxy.Commands public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public CmdVote() { } - public override void Use(Player p, string message) - { - if (message != "") - { - if (!Server.voting) - { - string temp = message.Substring(0, 1) == "%" ? "" : Server.DefaultColor; - Server.voting = true; - Server.NoVotes = 0; - Server.YesVotes = 0; - Player.GlobalMessage(" " + c.green + "VOTE: " + temp + message + "(" + c.green + "Yes " + Server.DefaultColor + "/" + c.red + "No" + Server.DefaultColor + ")"); - System.Threading.Thread.Sleep(15000); - Server.voting = false; - Player.GlobalMessage("The vote is in! " + c.green + "Y: " + Server.YesVotes + c.red + " N: " + Server.NoVotes); - Player.players.ForEach(delegate(Player winners) - { - winners.voted = false; - }); - } - else - { - p.SendMessage("A vote is in progress!"); - } - } - else - { - Help(p); + public override void Use(Player p, string message) { + if (message == "") { Help(p); return; } + + if (!Server.voting) { + Server.voting = true; + Server.NoVotes = 0; Server.YesVotes = 0; + Player.GlobalMessage(c.green + " VOTE: %S" + message + "%S(" + c.green + "Yes" + " %S/ " + c.red + "No" + "%S)"); + System.Threading.Thread.Sleep(15000); + + Server.voting = false; + Player.GlobalMessage("The votes are in! " + c.green + "Y: " + Server.YesVotes + c.red + " N: " + Server.NoVotes); + Player.players.ForEach(pl => pl.voted = false); + } else{ + p.SendMessage("A vote is in progress!"); } } - public override void Help(Player p) - { - p.SendMessage("/vote [message] - Obviously starts a vote!"); + + public override void Help(Player p) { + p.SendMessage("/vote [message] - Starts a vote for 15 seconds."); } } } diff --git a/Games/IGame.cs b/Games/IGame.cs index b39249a90..ec1170472 100644 --- a/Games/IGame.cs +++ b/Games/IGame.cs @@ -25,5 +25,17 @@ namespace MCGalaxy { byte action, byte tile, byte b) { return false; } + + public virtual bool HandlesChatMessage(Player p, string message) { + return false; + } + + public virtual void PlayerJoinedServer(Player p) { } + + public virtual void PlayerLeftServer(Player p) { } + + public virtual void PlayerJoinedGame(Player p) { } + + public virtual void PlayerLeftGame(Player p) { } } } diff --git a/Games/ZombieGame.Game.cs b/Games/ZombieGame.Game.cs index 8d6dda341..2bad79a57 100644 --- a/Games/ZombieGame.Game.cs +++ b/Games/ZombieGame.Game.cs @@ -1,16 +1,20 @@ /* -Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/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. + Copyright 2010 MCLawl Team - + Created by Snowl (David D.) and Cazzar (Cayde D.) + + 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.osedu.org/licenses/ECL-2.0 + 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; @@ -18,8 +22,8 @@ namespace MCGalaxy { public sealed partial class ZombieGame : IGame { - public override bool HandlesManualChange(Player p, ushort x, ushort y, ushort z, - byte action, byte tile, byte b) { + public override bool HandlesManualChange(Player p, ushort x, ushort y, ushort z, + byte action, byte tile, byte b) { if (action == 1 && Server.noPillaring && !p.referee) { if (p.lastYblock == y - 1 && p.lastXblock == x && p.lastZblock == z ) { p.blocksStacked++; @@ -52,5 +56,23 @@ namespace MCGalaxy { } return false; } + + public override bool HandlesChatMessage(Player p, string message) { + message = message.ToLower(); + if (Player.CheckVote(message, p, "1", "one", ref Server.Level1Vote) || + Player.CheckVote(message, p, "2", "two", ref Server.Level2Vote) || + Player.CheckVote(message, p, "3", "three", ref Server.Level3Vote)) + return true; + + if (!p.voice) { + p.SendMessage("Chat moderation is on while voting is on!"); + return true; + } + return false; + } + + public override void PlayerLeftServer(Player p) { + InfectedPlayerDC(); + } } } diff --git a/Games/ZombieGame.cs b/Games/ZombieGame.cs index 3a773081d..0e805fb6c 100644 --- a/Games/ZombieGame.cs +++ b/Games/ZombieGame.cs @@ -432,7 +432,7 @@ namespace MCGalaxy if (initialChangeLevel) { Server.votingforlevel = true; - Player.GlobalMessage(" " + c.black + "Level Vote: " + Server.DefaultColor + selectedLevel1 + ", " + selectedLevel2 + " or random " + "(" + c.lime + "1" + Server.DefaultColor + "/" + c.red + "2" + Server.DefaultColor + "/" + c.blue + "3" + Server.DefaultColor + ")"); + Player.GlobalMessage(" " + c.black + "Level Vote: " + Server.DefaultColor + selectedLevel1 + ", " + selectedLevel2 + " or random " + "(" + c.lime + "1%S/" + c.red + "2%S/" + c.blue + "3%S)"); System.Threading.Thread.Sleep(15000); Server.votingforlevel = false; } diff --git a/Player/Player.cs b/Player/Player.cs index 7e29d436e..e1d69413a 100644 --- a/Player/Player.cs +++ b/Player/Player.cs @@ -2177,82 +2177,25 @@ return; SendMessage(from, "Your vote for &5" + message.ToLower().Capitalize() + Server.DefaultColor + " has been placed. Thanks!"); Server.lava.map.ChatLevelOps(from.name + " voted for &5" + message.ToLower().Capitalize() + Server.DefaultColor + "."); return; - } - else { + } else { SendMessage(from, "&cYou already voted!"); return; } } - if ( Server.voting ) { - if ( message.ToLower() == "yes" || message.ToLower() == "ye" || message.ToLower() == "y" ) { - if ( !from.voted ) { - Server.YesVotes++; - SendMessage(from, c.red + "Thanks For Voting!"); - from.voted = true; - return; - } - else if ( !from.voice ) { - from.SendMessage("Chat moderation is on while voting is on!"); - return; - } - } - else if ( message.ToLower() == "no" || message.ToLower() == "n" ) { - if ( !from.voted ) { - Server.NoVotes++; - SendMessage(from, c.red + "Thanks For Voting!"); - from.voted = true; - return; - } - else if ( !from.voice ) { - from.SendMessage("Chat moderation is on while voting is on!"); - return; - } + if (Server.voting) { + string test = message.ToLower(); + if (CheckVote(test, from, "y", "yes", ref Server.YesVotes) || + CheckVote(test, from, "n", "no", ref Server.NoVotes)) return; + + if (!from.voice && (test == "y" || test == "n" || test == "yes" || test == "no")) { + from.SendMessage("Chat moderation is on while voting is on!"); return; } } - if ( Server.votingforlevel ) { - if ( message.ToLower() == "1" || message.ToLower() == "one" ) { - if ( !from.voted ) { - Server.Level1Vote++; - SendMessage(from, c.red + "Thanks For Voting!"); - from.voted = true; - return; - } - else if ( !from.voice ) { - from.SendMessage("Chat moderation is on while voting is on!"); - return; - } - } - else if ( message.ToLower() == "2" || message.ToLower() == "two" ) { - if ( !from.voted ) { - Server.Level2Vote++; - SendMessage(from, c.red + "Thanks For Voting!"); - from.voted = true; - return; - } - else if ( !from.voice ) { - from.SendMessage("Chat moderation is on while voting is on!"); - return; - } - } - else if ( message.ToLower() == "3" || message.ToLower() == "random" || message.ToLower() == "rand" ) { - if ( !from.voted ) { - Server.Level3Vote++; - SendMessage(from, c.red + "Thanks For Voting!"); - from.voted = true; - return; - } - else if ( !from.voice ) { - from.SendMessage("Chat moderation is on while voting is on!"); - return; - } - } - else if ( !from.voice ) { - from.SendMessage("Chat moderation is on while voting is on!"); - return; - } - } + if (Server.votingforlevel && Server.zombie.HandlesChatMessage(from, message)) + return; + if (Last50Chat.Count() == 50) Last50Chat.RemoveAt(0); var chatmessage = new ChatMessage(); @@ -2564,7 +2507,7 @@ level.Unload(); Server.s.Log(ip + " disconnected."); } - Server.zombie.InfectedPlayerDC(); + Server.zombie.PlayerLeftServer(this); } catch ( Exception e ) { Server.ErrorLog(e); } @@ -2913,5 +2856,15 @@ Next: continue; } return replacement + "/" + replacement2; } + + internal static bool CheckVote(string message, Player p, string a, string b, ref int totalVotes) { + if (!p.voted && (message == a || message == b)) { + totalVotes++; + p.SendMessage(c.red + "Thanks for voting!"); + p.voted = true; + return true; + } + return false; + } } }