Show round time left in the top right too for zombie survival.

This commit is contained in:
UnknownShadow200 2016-03-21 16:41:24 +11:00
parent 5f4ecc792d
commit 10acb965a0
8 changed files with 90 additions and 53 deletions

View File

@ -18,9 +18,9 @@
using System; using System;
namespace MCGalaxy.Commands { namespace MCGalaxy.Commands {
public sealed class CmdAka : Command { public sealed class CmdAka : Command {
public override string name { get { return "aka"; } } public override string name { get { return "aka"; } }
public override string shortcut { get { return ""; } } public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Games; } } public override string type { get { return CommandTypes.Games; } }
@ -32,12 +32,13 @@ namespace MCGalaxy.Commands {
Player[] players = PlayerInfo.Online.Items; Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) { 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); p.SendDespawn(pl.id);
string name = null; string name = null;
if (pl.infected && showInfected) { if (pl.infected) {
name = Server.zombie.ZombieName != "" ? Colors.red + Server.zombie.ZombieName : Colors.red + pl.name; name = (Server.zombie.ZombieName != "" && showInfected) ?
Colors.red + Server.zombie.ZombieName : Colors.red + pl.name;
} else { } else {
name = pl.color + pl.name; name = pl.color + pl.name;
} }

View File

@ -44,7 +44,7 @@ namespace MCGalaxy.Commands {
if (args[0].CaselessEq("author") || args[0].CaselessEq("authors")) { if (args[0].CaselessEq("author") || args[0].CaselessEq("authors")) {
p.level.Authors = args[1].Replace(" ", "%S, "); 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")) { } else if (args[0].CaselessEq("pillar") || args[0].CaselessEq("pillaring")) {
bool value; bool value;
if (!bool.TryParse(args[1], out value)) { if (!bool.TryParse(args[1], out value)) {

View File

@ -38,13 +38,13 @@ namespace MCGalaxy.Commands
if (who == null) return; if (who == null) return;
p.SendMessage(value + " was queued."); p.SendMessage(value + " was queued.");
Server.zombie.queZombie = true; Server.zombie.QueuedZombie = value;
Server.zombie.nextZombie = value;
} else if (args[0].CaselessEq("level")) { } else if (args[0].CaselessEq("level")) {
if (LevelInfo.ExistsOffline(value)) { if (LevelInfo.ExistsOffline(value)) {
p.SendMessage(value + " was queued."); p.SendMessage(value + " was queued.");
Server.zombie.queLevel = true; Server.zombie.QueuedLevel = value.ToLower();
Server.zombie.nextLevel = value.ToLower(); if (Server.zombie.CurrentLevel != null)
Server.zombie.CurrentLevel.ChatLevel(value + " was queued as the next map.");
} else { } else {
p.SendMessage("Level does not exist."); p.SendMessage("Level does not exist.");
} }

View File

@ -53,7 +53,7 @@ namespace MCGalaxy.Eco {
public override string Name { get { return "QueueLevel"; } } public override string Name { get { return "QueueLevel"; } }
protected override void OnBuyCommand(Player p, string message, string[] args) { 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; Player.SendMessage(p, "Someone else has already queued a level."); return;
} }
if (!LevelInfo.ExistsOffline(message)) { if (!LevelInfo.ExistsOffline(message)) {

View File

@ -65,15 +65,7 @@ namespace MCGalaxy.Games {
List<Player> players = DoRoundCountdown(); List<Player> players = DoRoundCountdown();
RoundInProgress = true; RoundInProgress = true;
Random random = new Random(); Random random = new Random();
Player first = PickFirstZombie(random, players);
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;
CurrentLevel.ChatLevel(first.color + first.name + " %Sstarted the infection!"); CurrentLevel.ChatLevel(first.color + first.name + " %Sstarted the infection!");
first.infected = true; first.infected = true;
@ -104,11 +96,17 @@ namespace MCGalaxy.Games {
} }
} }
Player PickFirstZombie(Random random, List<Player> 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<Player> DoRoundCountdown() { List<Player> DoRoundCountdown() {
while (true) { while (true) {
string logMessage = ChangeLevels + " " + Server.ZombieOnlyServer + " " + UseLevelList;
Server.s.Log(logMessage);
RoundStart = DateTime.UtcNow.AddSeconds(30); RoundStart = DateTime.UtcNow.AddSeconds(30);
CurrentLevel.ChatLevel("%4Round Start:%f 30..."); CurrentLevel.ChatLevel("%4Round Start:%f 30...");
Thread.Sleep(20000); if (!Server.ZombieModeOn) return null; Thread.Sleep(20000); if (!Server.ZombieModeOn) return null;
@ -142,8 +140,17 @@ namespace MCGalaxy.Games {
void DoCoreGame(Random random) { void DoCoreGame(Random random) {
Player[] alive = null; Player[] alive = null;
string lastTimespan = null;
while ((alive = Alive.Items).Length > 0) { while ((alive = Alive.Items).Length > 0) {
Player[] infected = Infected.Items; 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) { foreach (Player pKiller in infected) {
pKiller.infected = true; pKiller.infected = true;
UpdatePlayerColor(pKiller, Colors.red); UpdatePlayerColor(pKiller, Colors.red);
@ -181,18 +188,18 @@ namespace MCGalaxy.Games {
Colors.red + pKiller.DisplayName + Colors.yellow, Colors.red + pKiller.DisplayName + Colors.yellow,
Colors.red + pAlive.DisplayName + Colors.yellow)); Colors.red + pAlive.DisplayName + Colors.yellow));
CheckAssertHuman(pAlive); CheckHumanPledge(pAlive);
CheckBounty(pAlive, pKiller); CheckBounty(pAlive, pKiller);
UpdatePlayerColor(pAlive, Colors.red); UpdatePlayerColor(pAlive, Colors.red);
} }
} }
if (aliveChanged) alive = Alive.Items; if (aliveChanged) alive = Alive.Items;
} }
Thread.Sleep(50); Thread.Sleep(25);
} }
} }
void CheckAssertHuman(Player pAlive) { void CheckHumanPledge(Player pAlive) {
if (!pAlive.pledgeSurvive) return; if (!pAlive.pledgeSurvive) return;
pAlive.pledgeSurvive = false; pAlive.pledgeSurvive = false;
CurrentLevel.ChatLevel(pAlive.FullName + "%Sbroke their pledge of not being infected."); CurrentLevel.ChatLevel(pAlive.FullName + "%Sbroke their pledge of not being infected.");
@ -255,7 +262,7 @@ namespace MCGalaxy.Games {
} else { } else {
foreach (Player pl in alive) { foreach (Player pl in alive) {
if (pl.pledgeSurvive) { 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."); "%s for successfully pledging that you would survive.");
pl.money += 5; pl.money += 5;
pl.OnMoneyChanged(); pl.OnMoneyChanged();
@ -313,7 +320,7 @@ namespace MCGalaxy.Games {
} }
void ChooseNextLevel() { void ChooseNextLevel() {
if (queLevel) { ChangeLevel(nextLevel); return; } if (QueuedLevel != null) { ChangeLevel(QueuedLevel); return; }
if (!ChangeLevels) return; if (!ChangeLevels) return;
try try

View File

@ -120,7 +120,7 @@ namespace MCGalaxy.Games {
} }
public override void PlayerJoinedServer(Player p) { 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! " + Player.SendMessage(p, "A Zombie Survival game is running! " +
"Type %T/g " + CurrentLevelName + " %Sto join."); "Type %T/g " + CurrentLevelName + " %Sto join.");
} }
@ -146,14 +146,14 @@ namespace MCGalaxy.Games {
if (CurrentLevel.Authors != "") if (CurrentLevel.Authors != "")
p.SendMessage("It was created by " + 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); UpdatePlayerStatus(p);
return; return;
} }
p.SendCpeMessage(CpeMessageType.BottomRight1, "");
p.SendCpeMessage(CpeMessageType.Status1, ""); p.SendCpeMessage(CpeMessageType.Status1, "");
p.SendCpeMessage(CpeMessageType.Status2, ""); p.SendCpeMessage(CpeMessageType.Status2, "");
p.SendCpeMessage(CpeMessageType.Status3, "");
Alive.Remove(p); Alive.Remove(p);
Infected.Remove(p); Infected.Remove(p);
} }
@ -161,7 +161,7 @@ namespace MCGalaxy.Games {
public override void PlayerMoneyChanged(Player p) { public override void PlayerMoneyChanged(Player p) {
if (Status == ZombieGameStatus.NotStarted if (Status == ZombieGameStatus.NotStarted
|| !p.level.name.CaselessEq(CurrentLevelName)) return; || !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);
} }
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2010 MCLawl Team - Copyright 2010 MCLawl Team -
Created by Snowl (David D.) and Cazzar (Cayde D.) Created by Snowl (David D.) and Cazzar (Cayde D.)
Dual-licensed under the Educational Community License, Version 2.0 and 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 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
@ -78,16 +78,20 @@ namespace MCGalaxy.Games {
/// <summary> List of dead/infected players. </summary> /// <summary> List of dead/infected players. </summary>
public VolatileArray<Player> Infected = new VolatileArray<Player>(false); public VolatileArray<Player> Infected = new VolatileArray<Player>(false);
static string[] messages = new string[] { "{0} WIKIWOO'D {1}", "{0} stuck their teeth into {1}", /// <summary> Name of the player queued to be the first zombie in the next round. </summary>
"{0} licked {1}'s brain ", "{0} danubed {1}", "{0} made {1} meet their maker", "{0} tripped {1}", public string QueuedZombie;
"{0} made some zombie babies with {1}", "{0} made {1} see the dark side", "{0} tweeted {1}",
/// <summary> Name of the level queued to be used for the next round. </summary>
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} made {1} open source", "{0} infected {1}", "{0} iDotted {1}", "{1} got nommed on",
"{0} transplanted {1}'s living brain" }; "{0} transplanted {1}'s living brain" };
internal bool noRespawn = true, noPillaring = true; internal bool noRespawn = true, noPillaring = true;
internal string ZombieName = ""; internal string ZombieName = "";
internal bool queLevel = false, queZombie = false;
internal string nextZombie = "", nextLevel = "";
internal bool ChangeLevels = true, UseLevelList = false; internal bool ChangeLevels = true, UseLevelList = false;
internal List<string> LevelList = new List<string>(); internal List<string> LevelList = new List<string>();
@ -168,8 +172,7 @@ namespace MCGalaxy.Games {
} }
CurrentLevelName = next; CurrentLevelName = next;
queLevel = false; QueuedLevel = null;
nextLevel = "";
Command.all.Find("load").Use(null, next.ToLower() + " 0"); Command.all.Find("load").Use(null, next.ToLower() + " 0");
CurrentLevel = LevelInfo.Find(next); CurrentLevel = LevelInfo.Find(next);
if (Server.ZombieOnlyServer) if (Server.ZombieOnlyServer)
@ -191,9 +194,9 @@ namespace MCGalaxy.Games {
public void ResetState() { public void ResetState() {
Status = ZombieGameStatus.NotStarted; Status = ZombieGameStatus.NotStarted;
MaxRounds = 0; MaxRounds = 0;
initialChangeLevel = false; initialChangeLevel = false;
Server.ZombieModeOn = false; Server.ZombieModeOn = false;
RoundInProgress = false; RoundInProgress = false;
RoundStart = DateTime.MinValue; RoundStart = DateTime.MinValue;
RoundEnd = DateTime.MinValue; RoundEnd = DateTime.MinValue;
@ -209,16 +212,42 @@ namespace MCGalaxy.Games {
} }
void UpdatePlayerStatus(Player p) { void UpdatePlayerStatus(Player p) {
string message = "&a{0} %Salive, &c{1} %Sinfected"; int seconds = (int)(RoundEnd - DateTime.UtcNow).TotalSeconds;
message = String.Format(message, Alive.Count, Infected.Count); string status = GetStatusMessage(GetTimespan(seconds));
p.SendCpeMessage(CpeMessageType.Status1, message, true); p.SendCpeMessage(CpeMessageType.Status1, status, true);
} }
internal void UpdateAllPlayerStatus() { 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; 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; 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";
} }
} }
} }

View File

@ -341,8 +341,8 @@ namespace MCGalaxy {
byte head = level.GetTile(x, y, z); byte head = level.GetTile(x, y, z);
byte feet = level.GetTile(x, (ushort)(y - 1), z); byte feet = level.GetTile(x, (ushort)(y - 1), z);
return (Block.Walkthrough(Block.Convert(head)) || head == Block.Zero) return !(Block.Walkthrough(Block.Convert(head)) || head == Block.Zero)
&& (Block.Walkthrough(Block.Convert(feet)) || feet == Block.Zero); && !(Block.Walkthrough(Block.Convert(feet)) || feet == Block.Zero);
} }
//This is so that plugin devs can declare a player without needing a socket.. //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.level != other.level || (p.hidden && !self)) continue;
if (p != other) { if (p != other) {
if (Server.ZombieModeOn && !other.aka) { if (Server.ZombieModeOn) {
if (p.infected) { 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); other.SendSpawn(p.id, Colors.red + Server.zombie.ZombieName + possession, x, y, z, rotx, roty);
else else
other.SendSpawn(p.id, Colors.red + p.name + possession, x, y, z, rotx, roty); other.SendSpawn(p.id, Colors.red + p.name + possession, x, y, z, rotx, roty);