mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 03:55:18 -04:00
Integrate HUD.cs into ZSGame.cs
This commit is contained in:
parent
4fa19ed577
commit
5795cb67fe
@ -16,7 +16,6 @@
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System;
|
||||
using MCGalaxy.Games.ZS;
|
||||
|
||||
namespace MCGalaxy.Commands.Fun {
|
||||
public sealed class CmdMapSet : Command {
|
||||
@ -52,7 +51,7 @@ namespace MCGalaxy.Commands.Fun {
|
||||
|
||||
p.level.Config.Pillaring = value;
|
||||
Player.Message(p, "Set pillaring allowed to: " + value);
|
||||
HUD.UpdateAllSecondary(Server.zombie);
|
||||
Server.zombie.UpdateAllStatus2();
|
||||
} else if (args[0].CaselessEq("build") || args[0].CaselessEq("buildtype")) {
|
||||
BuildType value = BuildType.Normal;
|
||||
if (!CommandParser.GetEnum(p, args[1], "Build type", ref value)) return;
|
||||
@ -60,7 +59,7 @@ namespace MCGalaxy.Commands.Fun {
|
||||
p.level.Config.BuildType = value;
|
||||
p.level.UpdateBlockPermissions();
|
||||
Player.Message(p, "Set build type to: " + value);
|
||||
HUD.UpdateAllSecondary(Server.zombie);
|
||||
Server.zombie.UpdateAllStatus2();
|
||||
} else if (args[0].CaselessEq("minroundtime") || args[0].CaselessEq("minround")) {
|
||||
int time = GetRoundTime(p, args[1]);
|
||||
if (time == 0) return;
|
||||
|
@ -112,8 +112,7 @@ namespace MCGalaxy.Games {
|
||||
Players.Clear();
|
||||
Remaining.Clear();
|
||||
squaresLeft.Clear();
|
||||
|
||||
MessageAllStatus();
|
||||
|
||||
EndCommon();
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,12 @@ namespace MCGalaxy.Games {
|
||||
public abstract void End();
|
||||
public abstract void EndRound();
|
||||
|
||||
protected void ResetHUD(Player p) {
|
||||
p.SendCpeMessage(CpeMessageType.Status1, "");
|
||||
p.SendCpeMessage(CpeMessageType.Status2, "");
|
||||
p.SendCpeMessage(CpeMessageType.Status3, "");
|
||||
}
|
||||
|
||||
public void MessageMap(CpeMessageType type, string message) {
|
||||
if (!Running) return;
|
||||
Player[] online = PlayerInfo.Online.Items;
|
||||
|
@ -147,6 +147,7 @@ namespace MCGalaxy.Games {
|
||||
foreach (Player pl in online) {
|
||||
if (pl.level != Map) continue;
|
||||
TabList.Update(pl, true);
|
||||
ResetHUD(pl);
|
||||
}
|
||||
|
||||
if (Map != null) Map.Message(GameName + " %Sgame ended");
|
||||
|
@ -1,89 +0,0 @@
|
||||
/*
|
||||
Copyright 2015 MCGalaxy
|
||||
|
||||
Dual-licensed under the Educational Community License, Version 2.0 and
|
||||
the GNU General Public License, Version 3 (the "Licenses"); you may
|
||||
not use this file except in compliance with the Licenses. You may
|
||||
obtain a copy of the Licenses at
|
||||
|
||||
http://www.opensource.org/licenses/ecl2.php
|
||||
http://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the Licenses are distributed on an "AS IS"
|
||||
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;
|
||||
|
||||
namespace MCGalaxy.Games.ZS {
|
||||
internal static class HUD {
|
||||
|
||||
internal static void UpdateAllPrimary(ZSGame game) {
|
||||
int left = (int)(game.RoundEnd - DateTime.UtcNow).TotalSeconds;
|
||||
string status = FormatPrimary(game, left);
|
||||
game.MessageMap(CpeMessageType.Status1, status);
|
||||
}
|
||||
|
||||
internal static void UpdatePrimary(ZSGame game, Player p) {
|
||||
int left = (int)(game.RoundEnd - DateTime.UtcNow).TotalSeconds;
|
||||
string status = FormatPrimary(game, left);
|
||||
p.SendCpeMessage(CpeMessageType.Status1, status);
|
||||
}
|
||||
|
||||
internal static void UpdateAllSecondary(ZSGame game) {
|
||||
string status = FormatSecondary(game);
|
||||
game.MessageMap(CpeMessageType.Status2, status);
|
||||
}
|
||||
|
||||
internal static void UpdateSecondary(ZSGame game, Player p) {
|
||||
string status = FormatSecondary(game);
|
||||
p.SendCpeMessage(CpeMessageType.Status2, status);
|
||||
}
|
||||
|
||||
internal static void UpdateTertiary(Player p, bool infected) {
|
||||
string status = FormatTertiary(p, infected);
|
||||
p.SendCpeMessage(CpeMessageType.Status3, status);
|
||||
}
|
||||
|
||||
|
||||
internal static string GetTimeLeft(int seconds) {
|
||||
if (seconds < 0) return "";
|
||||
if (seconds <= 10) return "10s left";
|
||||
if (seconds <= 30) return "30s left";
|
||||
if (seconds <= 60) return "1m left";
|
||||
return ((seconds + 59) / 60) + "m left";
|
||||
}
|
||||
|
||||
internal static void Reset(Player p) {
|
||||
p.SendCpeMessage(CpeMessageType.Status1, "");
|
||||
p.SendCpeMessage(CpeMessageType.Status2, "");
|
||||
p.SendCpeMessage(CpeMessageType.Status3, "");
|
||||
}
|
||||
|
||||
|
||||
static string FormatPrimary(ZSGame game, int seconds) {
|
||||
string timespan = GetTimeLeft(seconds);
|
||||
if (timespan.Length > 0) {
|
||||
return string.Format("&a{0} %Salive %S({2}, map: {1})",
|
||||
game.Alive.Count, game.Map.MapName, timespan);
|
||||
} else {
|
||||
return string.Format("&a{0} %Salive %S(map: {1})",
|
||||
game.Alive.Count, game.Map.MapName);
|
||||
}
|
||||
}
|
||||
|
||||
static string FormatSecondary(ZSGame game) {
|
||||
string pillar = "%SPillaring " + (game.Map.Config.Pillaring ? "&aYes" : "&cNo");
|
||||
string type = "%S, Type is &a" + game.Map.Config.BuildType;
|
||||
return pillar + type;
|
||||
}
|
||||
|
||||
static string FormatTertiary(Player p, bool infected) {
|
||||
string money = "&a" + p.money + " %S" + ServerConfig.Currency;
|
||||
string state = ", you are " + (infected ? "&cdead" : "&aalive");
|
||||
return money + state;
|
||||
}
|
||||
}
|
||||
}
|
@ -25,7 +25,6 @@ using MCGalaxy.Events.EntityEvents;
|
||||
using MCGalaxy.Events.LevelEvents;
|
||||
using MCGalaxy.Events.PlayerEvents;
|
||||
using MCGalaxy.Events.ServerEvents;
|
||||
using MCGalaxy.Games.ZS;
|
||||
using MCGalaxy.Network;
|
||||
using MCGalaxy.SQL;
|
||||
using BlockID = System.UInt16;
|
||||
@ -92,7 +91,7 @@ namespace MCGalaxy.Games {
|
||||
|
||||
void HandleMoneyChanged(Player p) {
|
||||
if (p.level != Map) return;
|
||||
HUD.UpdateTertiary(p, Get(p).Infected);
|
||||
UpdateStatus3(p, Get(p).Infected);
|
||||
}
|
||||
|
||||
void HandleEntitySpawned(Entity entity, ref string name, ref string skin, ref string model, Player dst) {
|
||||
@ -155,7 +154,7 @@ namespace MCGalaxy.Games {
|
||||
p.SetPrefix(); // TODO: Kinda hacky, not sure if needed
|
||||
|
||||
if (prevLevel == Map && level != Map) {
|
||||
HUD.Reset(p);
|
||||
ResetHUD(p);
|
||||
if (RoundInProgress) PlayerLeftGame(p);
|
||||
} else if (level != Map) { return; }
|
||||
PlayerJoinedGame(p);
|
||||
|
@ -21,7 +21,6 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using MCGalaxy.Commands.World;
|
||||
using MCGalaxy.Games.ZS;
|
||||
using MCGalaxy.Network;
|
||||
|
||||
namespace MCGalaxy.Games {
|
||||
@ -91,9 +90,9 @@ namespace MCGalaxy.Games {
|
||||
}
|
||||
|
||||
// Update the round time left shown in the top right
|
||||
string timeLeft = HUD.GetTimeLeft(seconds);
|
||||
string timeLeft = GetTimeLeft(seconds);
|
||||
if (lastTimeLeft != timeLeft) {
|
||||
HUD.UpdateAllPrimary(this);
|
||||
UpdateAllStatus1();
|
||||
lastTimeLeft = timeLeft;
|
||||
}
|
||||
|
||||
@ -244,7 +243,7 @@ namespace MCGalaxy.Games {
|
||||
RoundInProgress = false;
|
||||
RoundStart = DateTime.MinValue;
|
||||
RoundEnd = DateTime.MinValue;
|
||||
HUD.UpdateAllPrimary(this);
|
||||
UpdateAllStatus1();
|
||||
|
||||
if (!Running) return;
|
||||
Player[] alive = Alive.Items, dead = Infected.Items;
|
||||
@ -323,8 +322,8 @@ namespace MCGalaxy.Games {
|
||||
pl.SetMoney(pl.money + 1);
|
||||
}
|
||||
|
||||
ZSGame.RespawnPlayer(pl);
|
||||
HUD.UpdateTertiary(pl, data.Infected);
|
||||
RespawnPlayer(pl);
|
||||
UpdateStatus3(pl, data.Infected);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,6 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using MCGalaxy.DB;
|
||||
using MCGalaxy.Games.ZS;
|
||||
using MCGalaxy.SQL;
|
||||
|
||||
namespace MCGalaxy.Games {
|
||||
@ -182,8 +181,8 @@ namespace MCGalaxy.Games {
|
||||
data.BlocksLeft = infected ? 25 : 50;
|
||||
|
||||
ResetInvisibility(p, data);
|
||||
HUD.UpdateAllPrimary(this);
|
||||
HUD.UpdateTertiary(p, infected);
|
||||
UpdateAllStatus1();
|
||||
UpdateStatus3(p, infected);
|
||||
}
|
||||
|
||||
void ResetInvisibility(Player p, ZSData data) {
|
||||
@ -218,7 +217,6 @@ namespace MCGalaxy.Games {
|
||||
ZSData data = Get(pl);
|
||||
data.ResetState();
|
||||
ResetInvisibility(pl, data);
|
||||
HUD.Reset(pl);
|
||||
}
|
||||
|
||||
EndCommon();
|
||||
@ -236,9 +234,9 @@ namespace MCGalaxy.Games {
|
||||
public override void PlayerJoinedGame(Player p) {
|
||||
ZSData data = Get(p); // usually this Get() performs the expensive DB stats read
|
||||
p.SetPrefix();
|
||||
HUD.UpdatePrimary(this, p);
|
||||
HUD.UpdateSecondary(this, p);
|
||||
HUD.UpdateTertiary(p, data.Infected);
|
||||
p.SendCpeMessage(CpeMessageType.Status1, FormatStatus1());
|
||||
p.SendCpeMessage(CpeMessageType.Status2, FormatStatus2());
|
||||
UpdateStatus3(p, data.Infected);
|
||||
|
||||
if (RoundInProgress) {
|
||||
Player.Message(p, "You joined in the middle of a round. &cYou are now infected!");
|
||||
@ -331,6 +329,48 @@ namespace MCGalaxy.Games {
|
||||
|
||||
return ZSConfig.LevelList.Count == 0 || ZSConfig.LevelList.CaselessContains(name);
|
||||
}
|
||||
|
||||
void UpdateAllStatus1() {
|
||||
MessageMap(CpeMessageType.Status1, FormatStatus1());
|
||||
}
|
||||
|
||||
internal void UpdateAllStatus2() {
|
||||
MessageMap(CpeMessageType.Status2, FormatStatus2());
|
||||
}
|
||||
|
||||
void UpdateStatus3(Player p, bool infected) {
|
||||
string status = FormatStatus3(p, infected);
|
||||
p.SendCpeMessage(CpeMessageType.Status3, status);
|
||||
}
|
||||
|
||||
static string GetTimeLeft(int seconds) {
|
||||
if (seconds < 0) return "";
|
||||
if (seconds <= 10) return "10s left";
|
||||
if (seconds <= 30) return "30s left";
|
||||
if (seconds <= 60) return "1m left";
|
||||
return ((seconds + 59) / 60) + "m left";
|
||||
}
|
||||
|
||||
string FormatStatus1() {
|
||||
int left = (int)(RoundEnd - DateTime.UtcNow).TotalSeconds;
|
||||
string timespan = GetTimeLeft(left);
|
||||
|
||||
string format = timespan.Length == 0 ? "&a{0} %Salive %S(map: {1})" :
|
||||
"&a{0} %Salive %S({2}, map: {1})";
|
||||
return string.Format(format, Alive.Count, Map.MapName, timespan);
|
||||
}
|
||||
|
||||
string FormatStatus2() {
|
||||
string pillar = "%SPillaring " + (Map.Config.Pillaring ? "&aYes" : "&cNo");
|
||||
string type = "%S, Type is &a" + Map.Config.BuildType;
|
||||
return pillar + type;
|
||||
}
|
||||
|
||||
static string FormatStatus3(Player p, bool infected) {
|
||||
string money = "&a" + p.money + " %S" + ServerConfig.Currency;
|
||||
string state = ", you are " + (infected ? "&cdead" : "&aalive");
|
||||
return money + state;
|
||||
}
|
||||
}
|
||||
|
||||
internal class ZSLevelPicker : LevelPicker {
|
||||
|
@ -505,7 +505,6 @@
|
||||
<Compile Include="Games\Team.cs" />
|
||||
<Compile Include="Games\TntWars\TntWars.cs" />
|
||||
<Compile Include="Games\TntWars\TntWarsConfig.cs" />
|
||||
<Compile Include="Games\ZombieSurvival\HUD.cs" />
|
||||
<Compile Include="Games\ZombieSurvival\ZSGame.DB.cs" />
|
||||
<Compile Include="Games\ZombieSurvival\ZSGame.Round.cs" />
|
||||
<Compile Include="Games\ZombieSurvival\ZSGame.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user