diff --git a/Commands/Fun/CmdAka.cs b/Commands/Fun/CmdAka.cs index 8a71054c6..39e65cd8e 100644 --- a/Commands/Fun/CmdAka.cs +++ b/Commands/Fun/CmdAka.cs @@ -18,9 +18,9 @@ using System; namespace MCGalaxy.Commands { - + public sealed class CmdAka : Command { - + public override string name { get { return "aka"; } } public override string shortcut { get { return ""; } } public override string type { get { return CommandTypes.Games; } } @@ -32,12 +32,13 @@ namespace MCGalaxy.Commands { Player[] players = PlayerInfo.Online.Items; foreach (Player pl in players) { - if (pl.level != p.level || p == pl || !Player.CanSee(p, pl) || pl.referee) continue; + if (pl.level != p.level || p == pl || !Player.CanSee(p, pl) || pl.referee) continue; p.SendDespawn(pl.id); string name = null; - if (pl.infected && showInfected) { - name = Server.zombie.ZombieName != "" ? Colors.red + Server.zombie.ZombieName : Colors.red + pl.name; + if (pl.infected) { + name = (Server.zombie.ZombieName != "" && showInfected) ? + Colors.red + Server.zombie.ZombieName : Colors.red + pl.name; } else { name = pl.color + pl.name; } diff --git a/Commands/Fun/CmdMapSet.cs b/Commands/Fun/CmdMapSet.cs index c1fb044a2..548bbc309 100644 --- a/Commands/Fun/CmdMapSet.cs +++ b/Commands/Fun/CmdMapSet.cs @@ -44,7 +44,7 @@ namespace MCGalaxy.Commands { if (args[0].CaselessEq("author") || args[0].CaselessEq("authors")) { p.level.Authors = args[1].Replace(" ", "%S, "); - Player.SendMessage(p, "Sets the authors of the map to: " + args[1]; + Player.SendMessage(p, "Sets the authors of the map to: " + args[1]); } else if (args[0].CaselessEq("pillar") || args[0].CaselessEq("pillaring")) { bool value; if (!bool.TryParse(args[1], out value)) { diff --git a/Commands/Fun/ZombieSurvival/CmdQueue.cs b/Commands/Fun/ZombieSurvival/CmdQueue.cs index c7c270207..17c8fcdfd 100644 --- a/Commands/Fun/ZombieSurvival/CmdQueue.cs +++ b/Commands/Fun/ZombieSurvival/CmdQueue.cs @@ -38,13 +38,13 @@ namespace MCGalaxy.Commands if (who == null) return; p.SendMessage(value + " was queued."); - Server.zombie.queZombie = true; - Server.zombie.nextZombie = value; + Server.zombie.QueuedZombie = value; } else if (args[0].CaselessEq("level")) { if (LevelInfo.ExistsOffline(value)) { p.SendMessage(value + " was queued."); - Server.zombie.queLevel = true; - Server.zombie.nextLevel = value.ToLower(); + Server.zombie.QueuedLevel = value.ToLower(); + if (Server.zombie.CurrentLevel != null) + Server.zombie.CurrentLevel.ChatLevel(value + " was queued as the next map."); } else { p.SendMessage("Level does not exist."); } diff --git a/Economy/ZombieItems.cs b/Economy/ZombieItems.cs index a64dc9d3f..f462465b7 100644 --- a/Economy/ZombieItems.cs +++ b/Economy/ZombieItems.cs @@ -53,7 +53,7 @@ namespace MCGalaxy.Eco { public override string Name { get { return "QueueLevel"; } } protected override void OnBuyCommand(Player p, string message, string[] args) { - if (Server.zombie.queLevel) { + if (Server.zombie.QueuedLevel != null) { Player.SendMessage(p, "Someone else has already queued a level."); return; } if (!LevelInfo.ExistsOffline(message)) { diff --git a/Games/ZombieSurvival/ZombieGame.Core.cs b/Games/ZombieSurvival/ZombieGame.Core.cs index de4c471a7..5259f51d8 100644 --- a/Games/ZombieSurvival/ZombieGame.Core.cs +++ b/Games/ZombieSurvival/ZombieGame.Core.cs @@ -65,15 +65,7 @@ namespace MCGalaxy.Games { List players = DoRoundCountdown(); RoundInProgress = true; Random random = new Random(); - - pickFirst: - int firstinfect = random.Next(players.Count()); - Player first = null; - if (queZombie) first = PlayerInfo.Find(nextZombie); - else first = players[firstinfect]; - queZombie = false; - - if (!first.level.name.CaselessEq(CurrentLevelName)) goto pickFirst; + Player first = PickFirstZombie(random, players); CurrentLevel.ChatLevel(first.color + first.name + " %Sstarted the infection!"); first.infected = true; @@ -104,11 +96,17 @@ namespace MCGalaxy.Games { } } + Player PickFirstZombie(Random random, List players) { + Player first = null; + do { + first = QueuedZombie != null ? + PlayerInfo.Find(QueuedZombie) : players[random.Next(players.Count)]; + } while (first == null || !first.level.name.CaselessEq(CurrentLevelName)); + return first; + } + List DoRoundCountdown() { while (true) { - string logMessage = ChangeLevels + " " + Server.ZombieOnlyServer + " " + UseLevelList; - Server.s.Log(logMessage); - RoundStart = DateTime.UtcNow.AddSeconds(30); CurrentLevel.ChatLevel("%4Round Start:%f 30..."); Thread.Sleep(20000); if (!Server.ZombieModeOn) return null; @@ -142,8 +140,17 @@ namespace MCGalaxy.Games { void DoCoreGame(Random random) { Player[] alive = null; + string lastTimespan = null; 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; + string timespan = GetTimespan(seconds); + if (lastTimespan != timespan) { + UpdateAllPlayerStatus(timespan); + lastTimespan = timespan; + } + foreach (Player pKiller in infected) { pKiller.infected = true; UpdatePlayerColor(pKiller, Colors.red); @@ -181,18 +188,18 @@ namespace MCGalaxy.Games { Colors.red + pKiller.DisplayName + Colors.yellow, Colors.red + pAlive.DisplayName + Colors.yellow)); - CheckAssertHuman(pAlive); + CheckHumanPledge(pAlive); CheckBounty(pAlive, pKiller); UpdatePlayerColor(pAlive, Colors.red); } } if (aliveChanged) alive = Alive.Items; } - Thread.Sleep(50); + Thread.Sleep(25); } } - void CheckAssertHuman(Player pAlive) { + void CheckHumanPledge(Player pAlive) { if (!pAlive.pledgeSurvive) return; pAlive.pledgeSurvive = false; CurrentLevel.ChatLevel(pAlive.FullName + "%Sbroke their pledge of not being infected."); @@ -255,7 +262,7 @@ namespace MCGalaxy.Games { } else { foreach (Player pl in alive) { if (pl.pledgeSurvive) { - pl.SendMessage("You received &a5 %3" + Server.moneys + + pl.SendMessage("You received &a5 %3" + Server.moneys + "%s for successfully pledging that you would survive."); pl.money += 5; pl.OnMoneyChanged(); @@ -313,7 +320,7 @@ namespace MCGalaxy.Games { } void ChooseNextLevel() { - if (queLevel) { ChangeLevel(nextLevel); return; } + if (QueuedLevel != null) { ChangeLevel(QueuedLevel); return; } if (!ChangeLevels) return; try diff --git a/Games/ZombieSurvival/ZombieGame.Game.cs b/Games/ZombieSurvival/ZombieGame.Game.cs index 042afeb5f..f632ca830 100644 --- a/Games/ZombieSurvival/ZombieGame.Game.cs +++ b/Games/ZombieSurvival/ZombieGame.Game.cs @@ -120,7 +120,7 @@ namespace MCGalaxy.Games { } public override void PlayerJoinedServer(Player p) { - if (Status == ZombieGameStatus.NotStarted) return; + if (Status == ZombieGameStatus.NotStarted || Server.ZombieOnlyServer) return; Player.SendMessage(p, "A Zombie Survival game is running! " + "Type %T/g " + CurrentLevelName + " %Sto join."); } @@ -146,14 +146,14 @@ namespace MCGalaxy.Games { if (CurrentLevel.Authors != "") p.SendMessage("It was created by " + CurrentLevel.Authors); - p.SendCpeMessage(CpeMessageType.BottomRight1, "%SYou have &a" + p.money + " %S" + Server.moneys); + p.SendCpeMessage(CpeMessageType.Status3, "%SYou have &a" + p.money + " %S" + Server.moneys); UpdatePlayerStatus(p); return; } - p.SendCpeMessage(CpeMessageType.BottomRight1, ""); p.SendCpeMessage(CpeMessageType.Status1, ""); p.SendCpeMessage(CpeMessageType.Status2, ""); + p.SendCpeMessage(CpeMessageType.Status3, ""); Alive.Remove(p); Infected.Remove(p); } @@ -161,7 +161,7 @@ namespace MCGalaxy.Games { public override void PlayerMoneyChanged(Player p) { if (Status == ZombieGameStatus.NotStarted || !p.level.name.CaselessEq(CurrentLevelName)) return; - p.SendCpeMessage(CpeMessageType.BottomRight1, "%SYou have &a" + p.money + " %S" + Server.moneys); + p.SendCpeMessage(CpeMessageType.Status3, "%SYou have &a" + p.money + " %S" + Server.moneys); } } } diff --git a/Games/ZombieSurvival/ZombieGame.cs b/Games/ZombieSurvival/ZombieGame.cs index 044002feb..09b555cc5 100644 --- a/Games/ZombieSurvival/ZombieGame.cs +++ b/Games/ZombieSurvival/ZombieGame.cs @@ -1,5 +1,5 @@ /* - Copyright 2010 MCLawl Team - + Copyright 2010 MCLawl Team - Created by Snowl (David D.) and Cazzar (Cayde D.) Dual-licensed under the Educational Community License, Version 2.0 and @@ -15,7 +15,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.Collections; using System.Collections.Generic; @@ -78,16 +78,20 @@ namespace MCGalaxy.Games { /// List of dead/infected players. public VolatileArray Infected = new VolatileArray(false); - static string[] messages = new string[] { "{0} WIKIWOO'D {1}", "{0} stuck their teeth into {1}", - "{0} licked {1}'s brain ", "{0} danubed {1}", "{0} made {1} meet their maker", "{0} tripped {1}", - "{0} made some zombie babies with {1}", "{0} made {1} see the dark side", "{0} tweeted {1}", + /// Name of the player queued to be the first zombie in the next round. + public string QueuedZombie; + + /// Name of the level queued to be used for the next round. + public string QueuedLevel; + + static string[] messages = new string[] { "{0} WIKIWOO'D {1}", "{0} stuck their teeth into {1}", + "{0} licked {1}'s brain ", "{0} danubed {1}", "{0} made {1} meet their maker", "{0} tripped {1}", + "{0} made some zombie babies with {1}", "{0} made {1} see the dark side", "{0} tweeted {1}", "{0} made {1} open source", "{0} infected {1}", "{0} iDotted {1}", "{1} got nommed on", "{0} transplanted {1}'s living brain" }; internal bool noRespawn = true, noPillaring = true; internal string ZombieName = ""; - internal bool queLevel = false, queZombie = false; - internal string nextZombie = "", nextLevel = ""; internal bool ChangeLevels = true, UseLevelList = false; internal List LevelList = new List(); @@ -168,8 +172,7 @@ namespace MCGalaxy.Games { } CurrentLevelName = next; - queLevel = false; - nextLevel = ""; + QueuedLevel = null; Command.all.Find("load").Use(null, next.ToLower() + " 0"); CurrentLevel = LevelInfo.Find(next); if (Server.ZombieOnlyServer) @@ -191,9 +194,9 @@ namespace MCGalaxy.Games { public void ResetState() { Status = ZombieGameStatus.NotStarted; - MaxRounds = 0; - initialChangeLevel = false; - Server.ZombieModeOn = false; + MaxRounds = 0; + initialChangeLevel = false; + Server.ZombieModeOn = false; RoundInProgress = false; RoundStart = DateTime.MinValue; RoundEnd = DateTime.MinValue; @@ -209,16 +212,42 @@ namespace MCGalaxy.Games { } void UpdatePlayerStatus(Player p) { - string message = "&a{0} %Salive, &c{1} %Sinfected"; - message = String.Format(message, Alive.Count, Infected.Count); - p.SendCpeMessage(CpeMessageType.Status1, message, true); + int seconds = (int)(RoundEnd - DateTime.UtcNow).TotalSeconds; + string status = GetStatusMessage(GetTimespan(seconds)); + p.SendCpeMessage(CpeMessageType.Status1, status, true); } internal void UpdateAllPlayerStatus() { + int seconds = (int)(RoundEnd - DateTime.UtcNow).TotalSeconds; + UpdateAllPlayerStatus(GetTimespan(seconds)); + } + + internal void UpdateAllPlayerStatus(string timespan) { + string message = GetStatusMessage(timespan); Player[] players = Alive.Items; - foreach (Player p in players) UpdatePlayerStatus(p); + foreach (Player p in players) + p.SendCpeMessage(CpeMessageType.Status1, message, true); players = Infected.Items; - foreach (Player p in players) UpdatePlayerStatus(p); + foreach (Player p in players) + p.SendCpeMessage(CpeMessageType.Status1, message, true); + } + + string GetStatusMessage(string timespan) { + if (timespan.Length > 0) { + const string format = "&a{0} %Salive, &c{1} %Sinfected ({2})"; + return String.Format(format, Alive.Count, Infected.Count, timespan); + } else { + const string format = "&a{0} %Salive, &c{1} %Sinfected"; + return String.Format(format, Alive.Count, Infected.Count); + } + } + + string GetTimespan(int seconds) { + if (seconds < 0) return ""; + if (seconds <= 10) return "10 secs left"; + if (seconds <= 30) return "30 secs left"; + if (seconds <= 60) return "1 min left"; + return ((seconds + 59) / 60) + " mins left"; } } } diff --git a/Player/Player.cs b/Player/Player.cs index c8d1169ea..d71279914 100644 --- a/Player/Player.cs +++ b/Player/Player.cs @@ -341,8 +341,8 @@ namespace MCGalaxy { byte head = level.GetTile(x, y, z); byte feet = level.GetTile(x, (ushort)(y - 1), z); - return (Block.Walkthrough(Block.Convert(head)) || head == Block.Zero) - && (Block.Walkthrough(Block.Convert(feet)) || feet == Block.Zero); + 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.. @@ -494,9 +494,9 @@ namespace MCGalaxy { if (p.level != other.level || (p.hidden && !self)) continue; if (p != other) { - if (Server.ZombieModeOn && !other.aka) { + if (Server.ZombieModeOn) { if (p.infected) { - if (Server.zombie.ZombieName != "") + if (Server.zombie.ZombieName != "" && !other.aka) other.SendSpawn(p.id, Colors.red + Server.zombie.ZombieName + possession, x, y, z, rotx, roty); else other.SendSpawn(p.id, Colors.red + p.name + possession, x, y, z, rotx, roty);