Minorly tidy up games code

This commit is contained in:
UnknownShadow200 2018-06-08 12:00:49 +10:00
parent 53751c4a8d
commit b5b9fc14ee
21 changed files with 251 additions and 274 deletions

View File

@ -54,7 +54,7 @@ namespace MCGalaxy.Commands.Fun {
case "players":
HandlePlayers(p, game); return;
case "rules":
HandleRules(p, arg1); return;
HandleRules(p); return;
case "download":
case "generate":
@ -148,7 +148,7 @@ namespace MCGalaxy.Commands.Fun {
}
}
void HandleRules(Player p, string target) {
void HandleRules(Player p) {
Player.Message(p, "The aim of the game is to stay alive the longest.");
Player.Message(p, "Don't fall in the lava!");
Player.Message(p, "Blocks on the ground will disapear randomly, first going yellow, then orange, then red and finally disappearing.");

View File

@ -179,60 +179,17 @@ namespace MCGalaxy.Commands.Fun {
}
void DoRules(Player p, string[] text) {
if (String.IsNullOrEmpty(text[1])) {
Player.Message(p, "TNT Wars Rules:");
SendRules(p); return;
}
if (!CheckExtraPerm(p, 1)) return;
switch (text[1]) {
case "all":
case "a":
Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) {
Player.Message(pl, "TNT Wars Rules: (sent to all players by " + p.ColoredName + " %S)");
SendRules(pl);
}
Player.Message(p, "TNT Wars: Sent rules to all players");
return;
case "level":
case "l":
foreach (Player pl in p.level.players) {
Player.Message(pl, "TNT Wars Rules: (sent to all players in map by " + p.ColoredName + " %S)");
SendRules(pl);
}
Player.Message(p, "TNT Wars: Sent rules to all current players in map");
return;
case "players":
case "p":
TntWarsGame gm = TntWarsGame.GameIn(p);
if (gm == null) { Player.Message(p, "TNT Wars Error: You aren't in a TNT Wars game!"); return; }
foreach (TntWarsGame.player pl in gm.Players) {
Player.Message(pl.p, "TNT Wars Rules: (sent to all current players by " + p.ColoredName + " %S)");
SendRules(pl.p);
}
Player.Message(p, "TNT Wars: Sent rules to all current players");
return;
default:
Player who = PlayerInfo.FindMatches(p, text[1]);
if (who == null) return;
Player.Message(who, "TNT Wars Rules: (sent to you by " + p.ColoredName + " %S)");
SendRules(who);
Player.Message(p, "TNT Wars: Sent rules to " + who.color + who.name);
return;
}
Player.Message(p, "TNT Wars Rules:");
Player.Message(p, "The aim of the game is to blow up people using TNT!");
Player.Message(p, "To place tnt simply place a TNT block and after a short delay it shall explode!");
Player.Message(p, "During the game the amount of TNT placable at one time may be limited!");
Player.Message(p, "You are not allowed to use hacks of any sort during the game!");
}
static void SendRules(Player p) {
Player.Message(p, "The aim of the game is to blow up people using TNT!");
Player.Message(p, "To place tnt simply place a TNT block and after a short delay it shall explode!");
Player.Message(p, "During the game the amount of TNT placable at one time may be limited!");
Player.Message(p, "You are not allowed to use hacks of any sort during the game!");
}
void DoScores(Player p, string[] text) {
@ -1009,23 +966,6 @@ namespace MCGalaxy.Commands.Fun {
}
}
public override void Help(Player p) {
Player.Message(p, "TNT Wars Help:");
Player.Message(p, "/tw list {l} - Lists all the current games");
Player.Message(p, "/tw join <team/level> - join a game on <level> or on <team>(red/blue)");
Player.Message(p, "/tw leave - leave the current game");
Player.Message(p, "/tw scores <top/team/me> - view the top score/team scores/your scores");
Player.Message(p, "/tw players {p} - view the current players in your game");
Player.Message(p, "/tw health {hp} - view your currrent amount of health left");
if (HasExtraPerm(p, 1)) {
Player.Message(p, "/tw rules <all/level/players/<playername>> - send the rules to yourself, all, your map, all players in your game or to one person!");
Player.Message(p, "/tw setup {s} - setup the game (do '/tntwars setup help' for more info!");
} else {
Player.Message(p, "/tw rules - read the rules");
}
}
bool DeleteZoneCallback(Player p, Vec3S32[] marks, object state, BlockID block) {
ushort x = (ushort)marks[0].X, y = (ushort)marks[0].Y, z = (ushort)marks[0].Z;
TntWarsGame it = TntWarsGame.GameIn(p);
@ -1083,5 +1023,20 @@ namespace MCGalaxy.Commands.Fun {
Player.Message(p, "Added zone");
return false;
}
public override void Help(Player p) {
Player.Message(p, "/tw list {l} - Lists all running games");
Player.Message(p, "/tw join <team/level> - join a game on <level> or on <team>(red/blue)");
Player.Message(p, "/tw leave - leave the current game");
Player.Message(p, "/tw scores <top/team/me> - view the top score/team scores/your scores");
Player.Message(p, "/tw players {p} - view the current players in your game");
Player.Message(p, "/tw health {hp} - view your currrent amount of health left");
Player.Message(p, "/tw rules - read the rules");
if (HasExtraPerm(p, 1)) {
Player.Message(p, "/tw setup {s} - setup the game (do '/tntwars setup help' for more info!");
}
}
}
}

View File

@ -103,7 +103,7 @@ namespace MCGalaxy.Commands.Fun {
Player.Message(p, "%HSets how far apart players are allowed to move in a " +
"movement packet before they are considered speedhacking. (32 units = 1 block).");
} else {
Help(p);
base.Help(p, message);
}
}
}

View File

@ -22,7 +22,6 @@ using MCGalaxy.DB;
using MCGalaxy.Maths;
using MCGalaxy.SQL;
using BlockID = System.UInt16;
using BlockRaw = System.Byte;
namespace MCGalaxy.Commands.Info {
public sealed class CmdAbout : Command {

View File

@ -14,12 +14,8 @@ permissions and limitations under the Licenses.
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using MCGalaxy.Blocks;
using BlockID = System.UInt16;
using BlockRaw = System.Byte;
namespace MCGalaxy.Commands.Info {
public class CmdSearch : Command {

View File

@ -61,7 +61,7 @@ namespace MCGalaxy {
static void LineProcessor(string key, string value, ref OldPerms perms) {
switch (key.ToLower()) {
// Backwards compatibility: some command extra permissions used to be part of server.properties
// Backwards compatibility: some command extra permissions used to be part of server.properties
case "review-enter-perm":
case "review-leave-perm":
return;
@ -76,7 +76,7 @@ namespace MCGalaxy {
case "adminchat-perm":
perms.adminchatPerm = int.Parse(value); return;
// Backwards compatibility: map generation volume used to be part of server.properties
// Backwards compatibility: map generation volume used to be part of server.properties
case "map-gen-limit-admin":
perms.mapGenLimitAdmin = int.Parse(value); return;
case "map-gen-limit":

View File

@ -68,6 +68,8 @@ namespace MCGalaxy.Eco {
w.WriteLine("enabled:" + Enabled);
foreach (Item item in Items) {
w.WriteLine();
w.WriteLine(item.Name + ":enabled:" + item.Enabled);
w.WriteLine(item.Name + ":purchaserank:" + (int)item.PurchaseRank);
item.Serialise(w);
}
}

View File

@ -105,9 +105,7 @@ namespace MCGalaxy.Eco {
}
public override void Serialise(StreamWriter writer) {
writer.WriteLine(Name + ":enabled:" + Enabled);
writer.WriteLine(Name + ":price:" + Price);
writer.WriteLine(Name + ":purchaserank:" + (int)PurchaseRank);
}
protected internal override void OnBuyCommand(Player p, string message, string[] args) {

View File

@ -60,17 +60,16 @@ namespace MCGalaxy.Eco {
}
public override void Serialise(StreamWriter writer) {
writer.WriteLine("level:enabled:" + Enabled);
writer.WriteLine("level:purchaserank:" + (int)PurchaseRank);
foreach (LevelPreset preset in Presets) {
writer.WriteLine();
writer.WriteLine("level:levels:" + preset.name + ":name:" + preset.name);
writer.WriteLine("level:levels:" + preset.name + ":price:" + preset.price);
writer.WriteLine("level:levels:" + preset.name + ":x:" + preset.x);
writer.WriteLine("level:levels:" + preset.name + ":y:" + preset.y);
writer.WriteLine("level:levels:" + preset.name + ":z:" + preset.z);
writer.WriteLine("level:levels:" + preset.name + ":type:" + preset.type);
string prefix = "level:levels:" + preset.name;
writer.WriteLine(prefix + ":name:" + preset.name);
writer.WriteLine(prefix + ":price:" + preset.price);
writer.WriteLine(prefix + ":x:" + preset.x);
writer.WriteLine(prefix + ":y:" + preset.y);
writer.WriteLine(prefix + ":z:" + preset.z);
writer.WriteLine(prefix + ":type:" + preset.type);
}
}

View File

@ -50,7 +50,7 @@ namespace MCGalaxy.Eco {
public sealed class NickItem : SimpleItem {
public NickItem() {
Aliases = new string[] { "nickname", "nick", "nicks", "name", "names" };
Aliases = new string[] { "nickname", "nick", "name" };
AllowsNoArgs = true;
}
@ -78,7 +78,7 @@ namespace MCGalaxy.Eco {
public sealed class TitleColorItem : SimpleItem {
public TitleColorItem() {
Aliases = new string[] { "tcolor", "tcolors", "titlecolor", "titlecolors", "tc" };
Aliases = new string[] { "tcolor", "tcolour", "titlecolor", "titlecolour" };
}
public override string Name { get { return "TitleColor"; } }
@ -100,7 +100,7 @@ namespace MCGalaxy.Eco {
public sealed class ColorItem : SimpleItem {
public ColorItem() {
Aliases = new string[] { "colors", "color", "colours", "colour" };
Aliases = new string[] { "color", "colour" };
}
public override string Name { get { return "Color"; } }

View File

@ -48,9 +48,6 @@ namespace MCGalaxy.Eco {
}
public override void Serialise(StreamWriter writer) {
writer.WriteLine("rank:enabled:" + Enabled);
writer.WriteLine("rank:purchaserank:" + (int)PurchaseRank);
foreach (RankEntry rank in Ranks) {
writer.WriteLine("rank:price:" + (int)rank.Perm + ":" + rank.Price);
}

View File

@ -98,6 +98,13 @@ namespace MCGalaxy.Games {
new ColumnDesc("Captures", ColumnType.UInt24),
new ColumnDesc("tags", ColumnType.UInt24),
};
protected override List<Player> GetPlayers() {
List<Player> playing = new List<Player>();
playing.AddRange(Red.Members.Items);
playing.AddRange(Blue.Members.Items);
return playing;
}
public override void Start(Player p, string map, int rounds) {
map = GetStartMap(map);

View File

@ -39,9 +39,7 @@ namespace MCGalaxy.Games {
if (Status != CountdownGameStatus.RoundCountdown) return;
int midX = Map.Width / 2, midY = Map.Height / 2, midZ = Map.Length / 2;
int xSpawn = (midX * 32 + 16);
int ySpawn = ((Map.Height - 2) * 32);
int zSpawn = (midZ * 32 + 16);
Position spawnPos = Position.FromFeetBlockCoords(midX, Map.Height - 2, midZ);
squaresLeft.Clear();
for (int zz = 6; zz < Map.Length - 6; zz += 3)
@ -54,7 +52,7 @@ namespace MCGalaxy.Games {
Map.ChatLevel("Countdown starting with difficulty " + SpeedType + " and mode normal in:");
Thread.Sleep(2000);
SpawnPlayers(xSpawn, ySpawn, zSpawn);
SpawnPlayers(spawnPos);
Map.ChatLevel("-----&b5%S-----");
if (Status != CountdownGameStatus.RoundCountdown) return;
@ -81,8 +79,7 @@ namespace MCGalaxy.Games {
DoRound();
}
void SpawnPlayers(int x, int y, int z) {
Position pos = new Position(x, y, z);
void SpawnPlayers(Position pos) {
Player[] players = Players.Items;
foreach (Player pl in players) {
@ -214,8 +211,8 @@ namespace MCGalaxy.Games {
Thread.Sleep(Interval);
Cuboid(x1, y, z1, x2, y, z2, Block.Air);
bulk.Send(true);
// Remove glass borders if neighbouring squared were previously removed.
// Remove glass borders, if neighbouring squares were previously removed
bool airMaxX = false, airMinZ = false, airMaxZ = false, airMinX = false;
if (Map.IsAirAt(x1, y, (ushort)(z2 + 2))) {
Map.Blockchange(x1, y, (ushort)(z2 + 1), Block.Air);
@ -238,7 +235,7 @@ namespace MCGalaxy.Games {
airMinX = true;
}
// Remove glass borders for diagonals too.
// Remove glass borders, if all neighbours to this corner have been removed
if (Map.IsAirAt((ushort)(x1 - 2), y, (ushort)(z1 - 2)) && airMinX && airMinZ) {
Map.Blockchange((ushort)(x1 - 1), y, (ushort)(z1 - 1), Block.Air);
}

View File

@ -45,126 +45,4 @@ namespace MCGalaxy.Games {
}
}
}
public abstract class RoundsGame : IGame {
public int RoundsLeft;
public bool RoundInProgress;
public string LastMap = "";
public LevelPicker Picker;
public abstract void Start(Player p, string map, int rounds);
protected abstract void DoRound();
public void RunGame() {
try {
while (Running && RoundsLeft > 0) {
RoundInProgress = false;
if (RoundsLeft != int.MaxValue) RoundsLeft--;
DoRound();
}
End();
} catch (Exception ex) {
Logger.LogError(ex);
Chat.MessageGlobal("&c" + GameName + " disabled due to an error.");
try { End(); }
catch (Exception ex2) { Logger.LogError(ex2); }
}
}
protected void VoteAndMoveToNextMap() {
Picker.AddRecentMap(Map.MapName);
if (RoundsLeft == 0) return;
string map = Picker.ChooseNextLevel(this);
if (map == null) return;
Map.ChatLevel("The next map has been chosen - &c" + map.ToLower());
Map.ChatLevel("Please wait while you are transfered.");
LastMap = Map.MapName;
if (!SetMap(map)) {
Map.ChatLevel("&cFailed to change map to " + map);
Map.ChatLevel("Continuing " + GameName + " on the same map");
} else {
TransferPlayers(LastMap);
Command.Find("Unload").Use(null, LastMap);
}
}
protected string GetStartMap(string forcedMap) {
if (forcedMap.Length > 0) return forcedMap;
List<string> maps = Picker.GetCandidateMaps();
if (maps == null || maps.Count == 0) return null;
return LevelPicker.GetRandomMap(new Random(), maps);
}
protected virtual bool SetMap(string map) {
Picker.QueuedMap = null;
Level next = LevelInfo.FindExact(map);
if (next == null) next = CmdLoad.LoadLevel(null, map);
if (next == null) return false;
Map = next;
Map.SaveChanges = false;
return true;
}
void TransferPlayers(string lastMap) {
Random rnd = new Random();
Player[] online = PlayerInfo.Online.Items;
List<Player> transfers = new List<Player>(online.Length);
foreach (Player pl in online) {
pl.Game.RatedMap = false;
pl.Game.PledgeSurvive = false;
if (pl.level != Map && pl.level.name.CaselessEq(lastMap)) { transfers.Add(pl); }
}
while (transfers.Count > 0) {
int i = rnd.Next(0, transfers.Count);
Player pl = transfers[i];
pl.SendMessage("Going to the next map - &a" + Map.MapName);
PlayerActions.ChangeMap(pl, Map);
transfers.RemoveAt(i);
}
}
protected void EndCommon() {
RoundsLeft = 0;
RoundInProgress = false;
Player[] online = PlayerInfo.Online.Items;
foreach (Player pl in online) {
if (pl.level != Map) continue;
TabList.Update(pl, true);
}
if (Map != null) Map.ChatLevel(GameName + " %Sgame ended");
Logger.Log(LogType.GameActivity, "[{0}] Game ended", GameName);
Picker.Clear();
LastMap = "";
Map = null;
}
protected void HandleJoinedCommon(Player p, Level prevLevel, Level level, ref bool announce) {
if (prevLevel == Map && level != Map) {
if (Picker.Voting) Picker.ResetVoteMessage(p);
} else if (level == Map) {
if (Picker.Voting) Picker.SendVoteMessage(p);
}
if (level != Map) return;
if (prevLevel == Map || LastMap.Length == 0 || prevLevel.name.CaselessEq(LastMap))
announce = false;
}
protected void HandleLevelUnload(Level lvl) {
if (lvl != Map) return;
Logger.Log(LogType.GameActivity, "Unload cancelled! A {0} game is currently going on!", GameName);
lvl.cancelunload = true;
}
}
}

View File

@ -27,7 +27,7 @@ namespace MCGalaxy.Games {
if (!running) return;
ResetPlayerDeaths();
startTime = DateTime.UtcNow;
RoundStart = DateTime.UtcNow;
RoundInProgress = true;
Logger.Log(LogType.GameActivity, "[Lava Survival] Round started. Map: " + Map.ColoredName);
@ -71,12 +71,12 @@ namespace MCGalaxy.Games {
}
internal string FloodTimeLeftMessage() {
double mins = Math.Ceiling((startTime.AddMinutes(mapSettings.floodTime) - DateTime.UtcNow).TotalMinutes);
double mins = Math.Ceiling((RoundStart.AddMinutes(mapSettings.floodTime) - DateTime.UtcNow).TotalMinutes);
return "&3" + mins + " minute" + (mins == 1 ? "" : "s") + " %Suntil the flood.";
}
internal string RoundTimeLeftMessage() {
double mins = Math.Ceiling((startTime.AddMinutes(mapSettings.roundTime) - DateTime.UtcNow).TotalMinutes);
double mins = Math.Ceiling((RoundStart.AddMinutes(mapSettings.roundTime) - DateTime.UtcNow).TotalMinutes);
return "&3" + mins + " minute" + (mins == 1 ? "" : "s") + " %Suntil the round ends.";
}

View File

@ -28,7 +28,6 @@ namespace MCGalaxy.Games {
const string propsDir = "properties/lavasurvival/";
List<string> maps;
Random rand = new Random();
DateTime startTime;
MapData data;
MapSettings mapSettings;
@ -52,7 +51,11 @@ namespace MCGalaxy.Games {
}
return (LSData)data;
}
protected override List<Player> GetPlayers() {
return Map.getPlayers();
}
public override void Start(Player p, string map, int rounds) {
map = GetStartMap(map);
if (map == null) {

View File

@ -0,0 +1,172 @@
/*
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;
using System.Collections.Generic;
using System.Threading;
using MCGalaxy.Commands.World;
namespace MCGalaxy.Games {
public abstract class RoundsGame : IGame {
public int RoundsLeft;
public bool RoundInProgress;
public DateTime RoundStart;
public string LastMap = "";
public LevelPicker Picker;
public abstract void Start(Player p, string map, int rounds);
protected abstract void DoRound();
protected abstract List<Player> GetPlayers();
public void RunGame() {
try {
while (Running && RoundsLeft > 0) {
RoundInProgress = false;
if (RoundsLeft != int.MaxValue) RoundsLeft--;
DoRound();
}
End();
} catch (Exception ex) {
Logger.LogError(ex);
Chat.MessageGlobal("&c" + GameName + " disabled due to an error.");
try { End(); }
catch (Exception ex2) { Logger.LogError(ex2); }
}
}
protected List<Player> DoRoundCountdown(int delay) {
while (true) {
RoundStart = DateTime.UtcNow.AddSeconds(delay);
if (!Running) return null;
const CpeMessageType type = CpeMessageType.Announcement;
for (int i = delay; i > 0 && Running; i--) {
if (i == 1) {
MessageMap(type, "&4Starting in &f1 &4seconds");
} else if (i < 10 || (i % 10) == 0) {
MessageMap(type, "&4Starting in &f" + i + " &4seconds");
}
Thread.Sleep(1000);
}
MessageMap(type, "");
if (!Running) return null;
List<Player> players = GetPlayers();
if (players.Count >= 2) return players;
Map.ChatLevel("&cNeed 2 or more non-ref players to start a round.");
}
}
protected void VoteAndMoveToNextMap() {
Picker.AddRecentMap(Map.MapName);
if (RoundsLeft == 0) return;
string map = Picker.ChooseNextLevel(this);
if (map == null) return;
Map.ChatLevel("The next map has been chosen - &c" + map.ToLower());
Map.ChatLevel("Please wait while you are transfered.");
LastMap = Map.MapName;
if (!SetMap(map)) {
Map.ChatLevel("&cFailed to change map to " + map);
Map.ChatLevel("Continuing " + GameName + " on the same map");
} else {
TransferPlayers(LastMap);
Command.Find("Unload").Use(null, LastMap);
}
}
protected string GetStartMap(string forcedMap) {
if (forcedMap.Length > 0) return forcedMap;
List<string> maps = Picker.GetCandidateMaps();
if (maps == null || maps.Count == 0) return null;
return LevelPicker.GetRandomMap(new Random(), maps);
}
protected virtual bool SetMap(string map) {
Picker.QueuedMap = null;
Level next = LevelInfo.FindExact(map);
if (next == null) next = CmdLoad.LoadLevel(null, map);
if (next == null) return false;
Map = next;
Map.SaveChanges = false;
return true;
}
void TransferPlayers(string lastMap) {
Random rnd = new Random();
Player[] online = PlayerInfo.Online.Items;
List<Player> transfers = new List<Player>(online.Length);
foreach (Player pl in online) {
pl.Game.RatedMap = false;
pl.Game.PledgeSurvive = false;
if (pl.level != Map && pl.level.name.CaselessEq(lastMap)) { transfers.Add(pl); }
}
while (transfers.Count > 0) {
int i = rnd.Next(0, transfers.Count);
Player pl = transfers[i];
pl.SendMessage("Going to the next map - &a" + Map.MapName);
PlayerActions.ChangeMap(pl, Map);
transfers.RemoveAt(i);
}
}
protected void EndCommon() {
RoundsLeft = 0;
RoundInProgress = false;
Player[] online = PlayerInfo.Online.Items;
foreach (Player pl in online) {
if (pl.level != Map) continue;
TabList.Update(pl, true);
}
if (Map != null) Map.ChatLevel(GameName + " %Sgame ended");
Logger.Log(LogType.GameActivity, "[{0}] Game ended", GameName);
Picker.Clear();
LastMap = "";
Map = null;
}
protected void HandleJoinedCommon(Player p, Level prevLevel, Level level, ref bool announce) {
if (prevLevel == Map && level != Map) {
if (Picker.Voting) Picker.ResetVoteMessage(p);
} else if (level == Map) {
if (Picker.Voting) Picker.SendVoteMessage(p);
}
if (level != Map) return;
if (prevLevel == Map || LastMap.Length == 0 || prevLevel.name.CaselessEq(LastMap))
announce = false;
}
protected void HandleLevelUnload(Level lvl) {
if (lvl != Map) return;
Logger.Log(LogType.GameActivity, "Unload cancelled! A {0} game is currently going on!", GameName);
lvl.cancelunload = true;
}
}
}

View File

@ -31,8 +31,8 @@ namespace MCGalaxy.Games {
int infectCombo = 0;
protected override void DoRound() {
if (!Running) return;
List<Player> players = DoRoundCountdown();
if (!running) return;
List<Player> players = DoRoundCountdown(30);
if (players == null) return;
if (!running) return;
@ -69,44 +69,6 @@ namespace MCGalaxy.Games {
InfectPlayer(first, null);
}
List<Player> DoRoundCountdown() {
while (true) {
RoundStart = DateTime.UtcNow.AddSeconds(30);
if (!running) return null;
SendLevelRaw("&4Starting in &f30 &4seconds", true);
Thread.Sleep(10000); if (!running) return null;
SendLevelRaw("&4Starting in &f20 &4seconds", true);
Thread.Sleep(10000); if (!running) return null;
SendLevelRaw("&4Starting in &f10 &4seconds", true);
Thread.Sleep(5000); if (!running) return null;
SendLevelRaw("&4Starting in &f5 &4seconds", true);
Thread.Sleep(1000); if (!running) return null;
SendLevelRaw("&4Starting in &f4 &4seconds", true);
Thread.Sleep(1000); if (!running) return null;
SendLevelRaw("&4Starting in &f3 &4seconds", true);
Thread.Sleep(1000); if (!running) return null;
SendLevelRaw("&4Starting in &f2 &4seconds", true);
Thread.Sleep(1000); if (!running) return null;
SendLevelRaw("&4Starting in &f1 &4second", true);
Thread.Sleep(1000); if (!running) return null;
SendLevelRaw("", true);
int nonRefPlayers = 0;
List<Player> players = new List<Player>();
Player[] online = PlayerInfo.Online.Items;
foreach (Player p in online) {
if (p.Game.Referee || p.level != Map) continue;
players.Add(p);
nonRefPlayers++;
}
if (!running) return null;
if (nonRefPlayers >= 2) return players;
Map.ChatLevel("&cNeed 2 or more non-ref players to start a round.");
}
}
void DoCoreGame() {
Player[] alive = Alive.Items;
string lastTimeLeft = null;

View File

@ -75,7 +75,7 @@ namespace MCGalaxy.Games {
public override bool Running { get { return running; } }
public ZSGame() { Picker = new ZSLevelPicker(); }
public DateTime RoundStart, RoundEnd;
public DateTime RoundEnd;
public VolatileArray<Player> Alive = new VolatileArray<Player>();
public VolatileArray<Player> Infected = new VolatileArray<Player>();
public string QueuedZombie;
@ -109,6 +109,17 @@ namespace MCGalaxy.Games {
data.MaxRoundsSurvived = stats.MaxRounds; data.TotalRoundsSurvived = stats.TotalRounds;
}
protected override List<Player> GetPlayers() {
Player[] players = PlayerInfo.Online.Items;
List<Player> playing = new List<Player>();
foreach (Player pl in players) {
if (pl.level != Map || pl.Game.Referee) continue;
playing.Add(pl);
}
return playing;
}
public override void Start(Player p, string map, int rounds) {
// ZS starts on current map by default
if (!Player.IsSuper(p) && map.Length == 0) map = p.level.name;
@ -366,10 +377,10 @@ namespace MCGalaxy.Games {
if (table.Rows.Count > 0) {
DataRow row = table.Rows[0];
stats.TotalRounds = int.Parse(row["TotalRounds"].ToString());
stats.MaxRounds = int.Parse(row["MaxRounds"].ToString());
stats.TotalInfected = int.Parse(row["TotalInfected"].ToString());
stats.MaxInfected = int.Parse(row["MaxInfected"].ToString());
stats.TotalRounds = PlayerData.ParseInt(row["TotalRounds"].ToString());
stats.MaxRounds = PlayerData.ParseInt(row["MaxRounds"].ToString());
stats.TotalInfected = PlayerData.ParseInt(row["TotalInfected"].ToString());
stats.MaxInfected = PlayerData.ParseInt(row["MaxInfected"].ToString());
}
table.Dispose();
return stats;

View File

@ -501,6 +501,7 @@
<Compile Include="Games\LavaSurvival\LSGame.Round.cs" />
<Compile Include="Games\LevelPicker.cs" />
<Compile Include="Games\MovementCheck.cs" />
<Compile Include="Games\RoundsGame.cs" />
<Compile Include="Games\Team.cs" />
<Compile Include="Games\TntWars\TntWars.cs" />
<Compile Include="Games\TntWars\TntWarsConfig.cs" />

View File

@ -151,13 +151,13 @@ namespace MCGalaxy {
return last.UnicodeToCp437() != last;
}
public void SendCpeMessage(CpeMessageType type, string message, bool colorParse = true) {
public void SendCpeMessage(CpeMessageType type, string message) {
if (type != CpeMessageType.Normal && !Supports(CpeExt.MessageTypes)) {
if (type == CpeMessageType.Announcement) type = CpeMessageType.Normal;
else return;
}
message = Chat.Format(message, this, colorParse);
message = Chat.Format(message, this);
Send(Packet.Message(message, type, hasCP437));
}