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

@ -36,8 +36,9 @@ namespace MCGalaxy.Commands {
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;
}

View File

@ -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)) {

View File

@ -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.");
}

View File

@ -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)) {

View File

@ -65,15 +65,7 @@ namespace MCGalaxy.Games {
List<Player> 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<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() {
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.");
@ -313,7 +320,7 @@ namespace MCGalaxy.Games {
}
void ChooseNextLevel() {
if (queLevel) { ChangeLevel(nextLevel); return; }
if (QueuedLevel != null) { ChangeLevel(QueuedLevel); return; }
if (!ChangeLevels) return;
try

View File

@ -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);
}
}
}

View File

@ -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,6 +78,12 @@ namespace MCGalaxy.Games {
/// <summary> List of dead/infected players. </summary>
public VolatileArray<Player> Infected = new VolatileArray<Player>(false);
/// <summary> Name of the player queued to be the first zombie in the next round. </summary>
public string QueuedZombie;
/// <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}",
@ -86,8 +92,6 @@ namespace MCGalaxy.Games {
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<string> LevelList = new List<string>();
@ -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)
@ -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";
}
}
}

View File

@ -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);