From d1764a7ee00f114028b1effa545a6430ae8045cb Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 30 Mar 2016 08:25:05 +1100 Subject: [PATCH] More modularisation in ZombieGame code. --- Commands/Information/CmdWhois.cs | 6 +- Commands/building/CmdMode.cs | 4 +- Commands/other/CmdPass.cs | 17 ++-- Commands/other/CmdSetPass.cs | 5 +- Games/ZombieSurvival/ZombieGame.Core.cs | 101 +++++++++++++----------- 5 files changed, 68 insertions(+), 65 deletions(-) diff --git a/Commands/Information/CmdWhois.cs b/Commands/Information/CmdWhois.cs index dee83369d..b379f7197 100644 --- a/Commands/Information/CmdWhois.cs +++ b/Commands/Information/CmdWhois.cs @@ -38,10 +38,10 @@ namespace MCGalaxy.Commands } Player.SendMessage(p, who.color + who.name + " %S(" + who.DisplayName + ") %Sis on &b" + who.level.name); - Player.SendMessage(p, who.FullName + Server.DefaultColor + " %Shas :"); + Player.SendMessage(p, who.FullName + " %Shas :"); Player.SendMessage(p, "> > the rank of " + who.group.color + who.group.name); if (Economy.Enabled) - Player.SendMessage(p, "> > &a" + who.money + Server.DefaultColor + " " + Server.moneys); + Player.SendMessage(p, "> > &a" + who.money + " %S" + Server.moneys); Player.SendMessage(p, "> > &cdied &a" + who.overallDeath + Server.DefaultColor + " times"); Player.SendMessage(p, "> > &bmodified &a" + who.overallBlocks + " &eblocks &eand &a" + who.loginBlocks + " &ewere changed &9since logging in&e."); @@ -50,7 +50,7 @@ namespace MCGalaxy.Commands Player.SendMessage(p, "> > time spent on server: " + time.Days + " Days, " + time.Hours + " Hours, " + time.Minutes + " Minutes, " + time.Seconds + " Seconds."); Player.SendMessage(p, "> > been logged in for &a" + storedTime); Player.SendMessage(p, "> > first logged into the server on &a" + who.firstLogin.ToString("yyyy-MM-dd") + " at " + who.firstLogin.ToString("HH:mm:ss")); - Player.SendMessage(p, "> > logged in &a" + who.totalLogins + Server.DefaultColor + " times, &c" + who.totalKicked + Server.DefaultColor + " of which ended in a kick."); + Player.SendMessage(p, "> > logged in &a" + who.totalLogins + " %Stimes, &c" + who.totalKicked + " %Sof which ended in a kick."); Player.SendMessage(p, "> > " + Awards.awardAmount(who.name) + " awards"); if (Ban.IsBanned(who.name)) { string[] data = Ban.GetBanData(who.name); diff --git a/Commands/building/CmdMode.cs b/Commands/building/CmdMode.cs index 9223a9e00..a03a4db13 100644 --- a/Commands/building/CmdMode.cs +++ b/Commands/building/CmdMode.cs @@ -59,13 +59,13 @@ namespace MCGalaxy.Commands if (p.modeType == b) { - Player.SendMessage(p, "&b" + Block.Name(p.modeType)[0].ToString().ToUpper() + Block.Name(p.modeType).Remove(0, 1).ToLower() + Server.DefaultColor + " %Smode: &cOFF"); + Player.SendMessage(p, "&b" + Block.Name(p.modeType)[0].ToString().ToUpper() + Block.Name(p.modeType).Remove(0, 1).ToLower() + " %Smode: &cOFF"); p.modeType = 0; } else { p.modeType = b; - Player.SendMessage(p, "&b" + Block.Name(p.modeType)[0].ToString().ToUpper() + Block.Name(p.modeType).Remove(0, 1).ToLower() + Server.DefaultColor + " %Smode: &aON"); + Player.SendMessage(p, "&b" + Block.Name(p.modeType)[0].ToString().ToUpper() + Block.Name(p.modeType).Remove(0, 1).ToLower() + " %Smode: &aON"); } } } diff --git a/Commands/other/CmdPass.cs b/Commands/other/CmdPass.cs index bfd877ed6..823cacd1f 100644 --- a/Commands/other/CmdPass.cs +++ b/Commands/other/CmdPass.cs @@ -69,13 +69,13 @@ namespace MCGalaxy.Commands if (number > 1) { - Player.SendMessage(p, "Your password must be &cone " + Server.DefaultColor + "word!"); + Player.SendMessage(p, "Your password must be &cone %Sword!"); return; } if (!Directory.Exists("extra/passwords")) { - Player.SendMessage(p, "You have not &cset a password, " + Server.DefaultColor + "use &a/setpass [Password] &cto set one!"); + Player.SendMessage(p, "You have not &cset a password, %Suse &a/setpass [Password] &cto set one!"); return; } @@ -83,23 +83,20 @@ namespace MCGalaxy.Commands FileInfo[] fi = di.GetFiles("*.dat"); if (!File.Exists("extra/passwords/" + p.name + ".dat")) { - Player.SendMessage(p, "You have not &cset a password, " + Server.DefaultColor + "use &a/setpass [Password] &cto set one!"); + Player.SendMessage(p, "You have not &cset a password, %Suse &a/setpass [Password] &cto set one!"); return; } if (PasswordHasher.MatchesPass(p.name, message)) { - Player.SendMessage(p, "Thank you, " + p.color + p.name + Server.DefaultColor + "! You have now &averified " + Server.DefaultColor + "and have &aaccess to admin commands and features!"); - if (p.adminpen) - { - p.adminpen = false; - } + Player.SendMessage(p, "Thank you, " + p.color + p.name + "%S! You have now &averified %Sand have &aaccess to admin commands and features!"); + p.adminpen = false; return; } p.passtries++; - Player.SendMessage(p, "&cWrong Password. " + Server.DefaultColor + "Remember your password is &ccase sensitive!"); - Player.SendMessage(p, "Forgot your password? " + Server.DefaultColor + "Contact the owner so they can reset it!"); + Player.SendMessage(p, "&cWrong Password. %SRemember your password is &ccase sensitive!"); + Player.SendMessage(p, "Forgot your password? %SContact the owner so they can reset it!"); } public override void Help(Player p) diff --git a/Commands/other/CmdSetPass.cs b/Commands/other/CmdSetPass.cs index 392191dce..2821743ad 100644 --- a/Commands/other/CmdSetPass.cs +++ b/Commands/other/CmdSetPass.cs @@ -36,7 +36,7 @@ namespace MCGalaxy.Commands Directory.CreateDirectory("extra/passwords"); if (p.group.Permission < Server.verifyadminsrank) { - Player.SendMessage(p, "You do not have the &crequired rank " + Server.DefaultColor + "to use this command!"); + Player.SendMessage(p, "You do not have the &crequired rank %Sto use this command!"); return; } if (!Server.verifyadmins) @@ -48,7 +48,8 @@ namespace MCGalaxy.Commands { if (File.Exists("extra/passwords/" + p.name + ".dat")) { - Player.SendMessage(p, "&cYou already have a password set. " + Server.DefaultColor + "You &ccannot change " + Server.DefaultColor + "it unless &cyou verify it with &a/pass [Password]. " + Server.DefaultColor + "If you have &cforgotten " + Server.DefaultColor + "your password, contact &c" + Server.server_owner + Server.DefaultColor + " and they can &creset it!"); + Player.SendMessage(p, "&cYou already have a password set. %SYou &ccannot change %Sit unless &cyou verify it with &a/pass [Password]. " + + "%SIf you have &cforgotten %Syour password, contact &c" + Server.server_owner + " %Sand they can &creset it!"); return; } } diff --git a/Games/ZombieSurvival/ZombieGame.Core.cs b/Games/ZombieSurvival/ZombieGame.Core.cs index 9756e6b09..d17d45e23 100644 --- a/Games/ZombieSurvival/ZombieGame.Core.cs +++ b/Games/ZombieSurvival/ZombieGame.Core.cs @@ -100,9 +100,9 @@ namespace MCGalaxy.Games { } Player PickFirstZombie(Random random, List players) { - Player first = null; - do { - first = QueuedZombie != null ? + Player first = null; + do { + first = QueuedZombie != null ? PlayerInfo.FindExact(QueuedZombie) : players[random.Next(players.Count)]; QueuedZombie = null; } while (first == null || !first.level.name.CaselessEq(CurLevelName)); @@ -148,13 +148,13 @@ namespace MCGalaxy.Games { while ((alive = Alive.Items).Length > 0) { Player[] infected = Infected.Items; // Update the round time left shown in the top right - int seconds = (int)(RoundEnd - DateTime.UtcNow).TotalSeconds; + int seconds = (int)(RoundEnd - DateTime.UtcNow).TotalSeconds; string timespan = GetTimespan(seconds); if (lastTimespan != timespan) { UpdateAllPlayerStatus(timespan); lastTimespan = timespan; } - + foreach (Player pKiller in infected) { pKiller.Game.Infected = true; UpdatePlayerColor(pKiller, InfectCol); @@ -206,18 +206,18 @@ namespace MCGalaxy.Games { pAlive.money = Math.Max(pAlive.money - 2, 0); pAlive.OnMoneyChanged(); } - + void ShowInfectMessage(Random random, Player pAlive, Player pKiller) { string text = null; List infectMsgs = pKiller.Game.InfectMessages; if (infectMsgs != null && random.Next(0, 10) < 5) - text = infectMsgs[random.Next(infectMsgs.Count)]; + text = infectMsgs[random.Next(infectMsgs.Count)]; else text = messages[random.Next(messages.Length)]; CurLevel.ChatLevel(String.Format(text, - Colors.red + pKiller.DisplayName + Colors.yellow, - Colors.red + pAlive.DisplayName + Colors.yellow)); + Colors.red + pKiller.DisplayName + Colors.yellow, + Colors.red + pAlive.DisplayName + Colors.yellow)); } void CheckBounty(Player pAlive, Player pKiller) { @@ -226,7 +226,7 @@ namespace MCGalaxy.Games { Bounties.Remove(pAlive.name); if (bounty != null) { CurLevel.ChatLevel(pKiller.FullName + " %Scollected the bounty of &a" + - bounty.Amount + " %S" + Server.moneys + " on " + pAlive.FullName + "%S."); + bounty.Amount + " %S" + Server.moneys + " on " + pAlive.FullName + "%S."); bounty.Origin.money = Math.Max(0, bounty.Origin.money - bounty.Amount); bounty.Origin.OnMoneyChanged(); pKiller.money += bounty.Amount; @@ -289,19 +289,8 @@ namespace MCGalaxy.Games { online = PlayerInfo.Online.Items; Random rand = new Random(); foreach (Player pl in online) { - int money = 0; if (!pl.level.name.CaselessEq(CurLevelName)) continue; - bool inBlock = pl.CheckIfInsideBlock(); - - if (pl.CheckIfInsideBlock()) { - money = -1; - } else if (alive.Length == 0) { - money = rand.Next(1 + pl.Game.NumInfected, 5 + pl.Game.NumInfected); - } else if (alive.Length == 1 && !pl.Game.Infected) { - money = rand.Next(5, 10); - } else if (alive.Length > 1 && !pl.Game.Infected) { - money = rand.Next(2, 6); - } + int money = GetMoney(pl, alive, rand); Player.GlobalDespawn(pl, false); Player.GlobalSpawn(pl, pl.pos[0], pl.pos[1], pl.pos[2], pl.rot[0], pl.rot[1], false); @@ -323,7 +312,20 @@ namespace MCGalaxy.Games { } UpdateAllPlayerStatus(); Alive.Clear(); - Infected.Clear(); + Infected.Clear(); + } + + int GetMoney(Player pl, Player[] alive, Random rand) { + if (pl.CheckIfInsideBlock()) return -1; + + if (alive.Length == 0) { + return rand.Next(1 + pl.Game.NumInfected, 5 + pl.Game.NumInfected); + } else if (alive.Length == 1 && !pl.Game.Infected) { + return rand.Next(5, 10); + } else if (alive.Length > 1 && !pl.Game.Infected) { + return rand.Next(2, 6); + } + return 0; } void ResetPlayer(Player p, ref string playersString) { @@ -346,7 +348,7 @@ namespace MCGalaxy.Games { if (levels.Count <= 2 && UseLevelList) { Server.s.Log("You must have more than 2 levels in your level list to change levels in Zombie Survival"); return; } - string selectedLevel1 = "", selectedLevel2 = ""; + string picked1 = "", picked2 = ""; Random r = new Random(); LevelChoice: @@ -355,52 +357,55 @@ namespace MCGalaxy.Games { if (level == lastLevel1 || level == lastLevel2 || level == CurLevelName || level2 == lastLevel1 || level2 == lastLevel2 || level2 == CurLevelName || - level == selectedLevel1) { + level == picked1) { goto LevelChoice; - } else if (selectedLevel1 == "") { - selectedLevel1 = level; goto LevelChoice; + } else if (picked1 == "") { + picked1 = level; goto LevelChoice; } else { - selectedLevel2 = level2; + picked2 = level2; } Level1Vote = 0; Level2Vote = 0; Level3Vote = 0; - lastLevel1 = selectedLevel1; lastLevel2 = selectedLevel2; + lastLevel1 = picked1; lastLevel2 = picked2; if (!Running || Status == ZombieGameStatus.LastRound) return; if (initialChangeLevel) { Server.votingforlevel = true; - Player[] players = PlayerInfo.Online.Items; + Player[] players = PlayerInfo.Online.Items; foreach (Player pl in players) { if (pl.level != CurLevel) continue; - SendVoteMessage(pl, selectedLevel1, selectedLevel2); + SendVoteMessage(pl, picked1, picked2); } System.Threading.Thread.Sleep(15000); Server.votingforlevel = false; } else { Level1Vote = 1; Level2Vote = 0; Level3Vote = 0; } if (!Running || Status == ZombieGameStatus.LastRound) return; - - if (Level1Vote >= Level2Vote) { - if (Level3Vote > Level1Vote && Level3Vote > Level2Vote) { - ChangeLevel(levels[r.Next(0, levels.Count)]); - } else { - ChangeLevel(selectedLevel1); - } - } else { - if (Level3Vote > Level1Vote && Level3Vote > Level2Vote) { - ChangeLevel(levels[r.Next(0, levels.Count)]); - } else { - ChangeLevel(selectedLevel2); - } - } - Player[] online = PlayerInfo.Online.Items; - foreach (Player pl in online) - pl.voted = false; + MoveToNextLevel(r, levels, picked1, picked2); } catch (Exception ex) { Server.ErrorLog(ex); } } + void MoveToNextLevel(Random r, List levels, string picked1, string picked2) { + if (Level1Vote >= Level2Vote) { + if (Level3Vote > Level1Vote && Level3Vote > Level2Vote) { + ChangeLevel(levels[r.Next(0, levels.Count)]); + } else { + ChangeLevel(picked1); + } + } else { + if (Level3Vote > Level1Vote && Level3Vote > Level2Vote) { + ChangeLevel(levels[r.Next(0, levels.Count)]); + } else { + ChangeLevel(picked2); + } + } + Player[] online = PlayerInfo.Online.Items; + foreach (Player pl in online) + pl.voted = false; + } + List GetCandidateLevels() { if (UseLevelList) return LevelList;