Show player statuses as CPE messages.

This commit is contained in:
UnknownShadow200 2016-03-20 22:48:08 +11:00
parent 551f66145f
commit e34e306363
5 changed files with 69 additions and 36 deletions

View File

@ -43,6 +43,7 @@ namespace MCGalaxy.Commands {
Player.GlobalSpawn(p, p.pos[0], p.pos[1], p.pos[2], p.rot[0], p.rot[1], false);
Server.zombie.Infected.Remove(p);
Server.zombie.Alive.Add(p);
Server.zombie.UpdateAllPlayerStatus();
p.color = p.group.color;
}
} else {
@ -51,6 +52,7 @@ namespace MCGalaxy.Commands {
Player.GlobalDespawn(p, false);
Server.zombie.Alive.Remove(p);
Server.zombie.Infected.Remove(p);
Server.zombie.UpdateAllPlayerStatus();
p.color = p.group.color;
if (Server.zombie.RoundInProgress)
Server.zombie.AssignFirstZombie();

View File

@ -94,6 +94,7 @@ namespace MCGalaxy.Games {
Infected.Clear();
Infected.Add(first);
UpdateAllPlayerStatus();
DoCoreGame(random);
if (Status == ZombieGameStatus.NotStarted) {
@ -148,6 +149,7 @@ namespace MCGalaxy.Games {
while ((alive = Alive.Items).Length > 0) {
Player[] infected = Infected.Items;
foreach (Player pKiller in infected) {
pKiller.infected = true;
UpdatePlayerColor(pKiller, Colors.red);
bool aliveChanged = false;
foreach (Player pAlive in alive) {
@ -160,9 +162,7 @@ namespace MCGalaxy.Games {
if (!pAlive.infected && pKiller.infected && !pAlive.referee && !pKiller.referee && pKiller != pAlive
&& pKiller.level.name.CaselessEq(CurrentLevelName) && pAlive.level.name.CaselessEq(CurrentLevelName))
{
pAlive.infected = true;
Infected.Add(pAlive);
Alive.Remove(pAlive);
InfectPlayer(pAlive);
aliveChanged = true;
pAlive.blockCount = 25;
@ -281,6 +281,7 @@ namespace MCGalaxy.Games {
}
Alive.Clear();
Infected.Clear();
UpdateAllPlayerStatus();
}
void ResetPlayer(Player p, ref string playersString) {

View File

@ -87,6 +87,7 @@ namespace MCGalaxy.Games {
Alive.Remove(p);
Infected.Remove(p);
AssignFirstZombie();
UpdateAllPlayerStatus();
}
public override void PlayerJoinedServer(Player p) {
@ -96,7 +97,6 @@ namespace MCGalaxy.Games {
}
public override void PlayerJoinedLevel(Player p, Level oldLvl) {
Server.s.Log("CHECK " + p.name);
if (RoundInProgress && p.level.name.CaselessEq(CurrentLevelName)) {
if (Status != ZombieGameStatus.NotStarted && p != null) {
p.SendMessage("You joined in the middle of a round. &cYou are now infected!");
@ -109,11 +109,13 @@ namespace MCGalaxy.Games {
double startLeft = (RoundStart - DateTime.UtcNow).TotalSeconds;
if (startLeft >= 0)
p.SendMessage("%a" + (int)startLeft + " %Sseconds left until the round starts. %aRun!");
//p.SendMessage(CpeMessageType.BottomRight1, "%SYou have &a" + p.money + " %S" + Server.moneys);
p.SendCpeMessage(CpeMessageType.BottomRight1, "%SYou have &a" + p.money + " %S" + Server.moneys);
UpdatePlayerStatus(p);
return;
}
p.SendMessage(CpeMessageType.BottomRight1, "");
p.SendCpeMessage(CpeMessageType.BottomRight1, "");
p.SendCpeMessage(CpeMessageType.Status1, "");
Alive.Remove(p);
Infected.Remove(p);
}

View File

@ -143,6 +143,7 @@ namespace MCGalaxy.Games {
Alive.Remove(p);
p.infected = true;
UpdatePlayerColor(p, Colors.red);
UpdateAllPlayerStatus();
}
public void DisinfectPlayer(Player p) {
@ -151,6 +152,7 @@ namespace MCGalaxy.Games {
Alive.Add(p);
p.infected = false;
UpdatePlayerColor(p, p.group.color);
UpdateAllPlayerStatus();
}
void ChangeLevel(string next) {
@ -190,5 +192,18 @@ namespace MCGalaxy.Games {
CurrentLevelName = "";
CurrentLevel = null;
}
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);
}
internal void UpdateAllPlayerStatus() {
Player[] players = Alive.Items;
foreach (Player p in players) UpdatePlayerStatus(p);
players = Infected.Items;
foreach (Player p in players) UpdatePlayerStatus(p);
}
}
}

View File

@ -177,44 +177,20 @@ namespace MCGalaxy {
else
Server.IRC.Pm(Server.IRC.usedCmd, message);
} else {
p.SendMessage(CpeMessageType.Normal, Server.DefaultColor + message, colorParse);
p.SendMessage(0, Server.DefaultColor + message, colorParse);
}
}
public void SendMessage(string message) {
SendMessage(CpeMessageType.Normal, Server.DefaultColor + message, true);
SendMessage(0, Server.DefaultColor + message, true);
}
public void SendMessage(string message, bool colorParse) {
SendMessage(CpeMessageType.Normal, Server.DefaultColor + message, colorParse);
SendMessage(0, Server.DefaultColor + message, colorParse);
}
[Obsolete("Use the overload with the CpeMessageType parameter.")]
public void SendMessage(byte id, string message, bool colorParse = true) {
SendMessage((CpeMessageType)id, message, colorParse);
}
public void SendMessage(CpeMessageType id, string message, bool colorParse = true) {
if (id != CpeMessageType.Normal && !HasCpeExt(CpeExt.MessageTypes)) {
if (id == CpeMessageType.Announcement) id = CpeMessageType.Normal;
else return;
}
if (colorParse)
message = Colors.EscapeColors(message);
StringBuilder sb = new StringBuilder(message);
if (colorParse)
ParseColors(sb);
Chat.ApplyTokens(sb, this, colorParse);
if ( Server.parseSmiley && parseSmiley ) {
sb.Replace(":)", "(darksmile)");
sb.Replace(":D", "(smile)");
sb.Replace("<3", "(heart)");
}
message = EmotesHandler.ReplaceEmoteKeywords(sb.ToString());
message = FullCP437Handler.Replace(message);
public void SendMessage(byte id, string message, bool colorParse = true) {
message = ConvertMessage(message, colorParse);
int totalTries = 0;
if ( MessageRecieve != null )
MessageRecieve(this, message);
@ -225,6 +201,7 @@ namespace MCGalaxy {
cancelmessage = false;
return;
}
retryTag: try {
foreach ( string line in Wordwrap(message) ) {
string newLine = line;
@ -237,7 +214,7 @@ namespace MCGalaxy {
buffer[0] = Opcode.Message;
buffer[1] = (byte)id;
if (HasCpeExt(CpeExt.FullCP437))
NetUtils.WriteCP437(newLine, buffer, 2);
NetUtils.WriteCP437(newLine, buffer, 2);
else
NetUtils.WriteAscii(newLine, buffer, 2);
SendRaw(buffer);
@ -249,7 +226,43 @@ namespace MCGalaxy {
else Server.ErrorLog(e);
}
}
public void SendCpeMessage(CpeMessageType id, string message, bool colorParse = true) {
if (id != CpeMessageType.Normal && !HasCpeExt(CpeExt.MessageTypes)) {
if (id == CpeMessageType.Announcement) id = CpeMessageType.Normal;
else return;
}
message = ConvertMessage(message, colorParse);
byte[] buffer = new byte[66];
buffer[0] = Opcode.Message;
buffer[1] = (byte)id;
if (HasCpeExt(CpeExt.FullCP437))
NetUtils.WriteCP437(message, buffer, 2);
else
NetUtils.WriteAscii(message, buffer, 2);
SendRaw(buffer);
}
string ConvertMessage(string message, bool colorParse) {
if (colorParse)
message = Colors.EscapeColors(message);
StringBuilder sb = new StringBuilder(message);
if (colorParse)
ParseColors(sb);
Chat.ApplyTokens(sb, this, colorParse);
if ( Server.parseSmiley && parseSmiley ) {
sb.Replace(":)", "(darksmile)");
sb.Replace(":D", "(smile)");
sb.Replace("<3", "(heart)");
}
message = EmotesHandler.ReplaceEmoteKeywords(sb.ToString());
message = FullCP437Handler.Replace(message);
return message;
}
void ParseColors(StringBuilder sb) {
for (int i = 0; i < 128; i++) {
if (Colors.IsStandardColor((char)i)) {