Fix TNT wars not being properly reset at round end

This commit is contained in:
UnknownShadow200 2018-07-09 22:05:12 +10:00
parent d54fca0f33
commit 0458010040
8 changed files with 56 additions and 46 deletions

View File

@ -329,7 +329,7 @@ namespace MCGalaxy {
// if custom block is replacing core block, need to always reload for fallback
if (block >= Block.CpeCount && !pl.level.MayHaveCustomBlocks) continue;
LevelActions.ReloadMap(pl, pl, false);
LevelActions.ReloadFor(pl, pl, false);
}
}
}

View File

@ -38,7 +38,7 @@ namespace MCGalaxy.Commands.World {
if (parts[0].CaselessEq("all")) {
if (!ReloadAll(p, parts)) return;
} else {
LevelActions.ReloadMap(p, p, true);
LevelActions.ReloadFor(p, p, true);
}
Server.DoGC();
}
@ -55,11 +55,7 @@ namespace MCGalaxy.Commands.World {
}
if (!CheckExtraPerm(p, 1)) return false;
Player[] players = PlayerInfo.Online.Items;
foreach (Player who in players) {
if (who.level == lvl)
LevelActions.ReloadMap(p, who, true);
}
LevelActions.ReloadAll(lvl, p, true);
return true;
}

View File

@ -152,7 +152,7 @@ namespace MCGalaxy.Drawing.Ops {
Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) {
if (pl.level.name.CaselessEq(lvl.name))
LevelActions.ReloadMap(p, pl, true);
LevelActions.ReloadFor(p, pl, true);
}
Server.DoGC();
}

View File

@ -51,7 +51,7 @@ namespace MCGalaxy.Games {
Chat.MessageGlobal("A game of {0} is starting on {1}%S!", GameName, Map.ColoredName);
Logger.Log(LogType.GameActivity, "[{0}] Game started", GameName);
StartGame();
StartGame();
RoundsLeft = rounds;
Running = true;
@ -143,23 +143,43 @@ namespace MCGalaxy.Games {
protected virtual void VoteAndMoveToNextMap() {
Picker.AddRecentMap(Map.MapName);
if (RoundsLeft == 0) return;
string map = Picker.ChooseNextLevel(this);
if (map == null) return;
if (map == null) { ContinueOnSameMap(); return; }
Map.Message("The next map has been chosen - &c" + map.ToLower());
Map.Message("Please wait while you are transfered.");
LastMap = Map.MapName;
Map.Message("Please wait while you are transfered.");
Level lastMap = Map; LastMap = Map.MapName;
if (!SetMap(map)) {
Map.Message("%WFailed to change map to " + map);
Map.Message("Continuing " + GameName + " on the same map");
ContinueOnSameMap();
} else {
TransferPlayers(LastMap);
Command.Find("Unload").Use(null, LastMap);
TransferPlayers(lastMap);
lastMap.Unload();
}
}
void TransferPlayers(string lastMap) {
void ContinueOnSameMap() {
Map.Message("Continuing " + GameName + " on the same map");
Level old = Level.Load(Map.MapName);
if (old == null) {
Map.Message("%WCannot reset changes to map"); return;
}
if (old.Width != Map.Width || old.Height != Map.Height || old.Length != Map.Length) {
Map.Message("%WCannot reset changes to map"); return;
}
// Try to reset changes made to this map, if possible
// TODO: do this in a nicer way
Map.blocks = old.blocks;
Map.CustomBlocks = old.CustomBlocks;
LevelActions.ReloadAll(Map, null, false);
Map.Message("Reset map to latest backup");
}
void TransferPlayers(Level lastMap) {
Random rnd = new Random();
Player[] online = PlayerInfo.Online.Items;
List<Player> transfers = new List<Player>(online.Length);
@ -167,7 +187,7 @@ namespace MCGalaxy.Games {
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); }
if (pl.level != Map && pl.level == lastMap) transfers.Add(pl);
}
while (transfers.Count > 0) {
@ -221,6 +241,6 @@ namespace MCGalaxy.Games {
LastMap = "";
if (Map != null) Map.AutoUnload();
Map = null;
}
}
}
}

View File

@ -91,7 +91,7 @@ namespace MCGalaxy.Games {
public void SetDefaults(Level lvl) {
ushort midX = (ushort)(lvl.Width / 2);
ushort midY = (ushort)(lvl.Height / 2);
ushort midY = (ushort)(lvl.Height / 2 + 1);
ushort maxZ = (ushort)(lvl.Length - 1);
RedSpawn = new Vec3U16(midX, midY, 0);

View File

@ -35,18 +35,7 @@ namespace MCGalaxy.Games {
public sealed partial class TWGame : RoundsGame {
int backupNum;
protected override void DoRound() {
backupNum = Map.Backup(true);
if (backupNum <= 0) {
Map.Message("%WBacking up Level for TNT Wars failed, stopping game");
EndGame();
return;
}
Logger.Log(LogType.SystemActivity, "Backed up {0} ({1}) for TNT Wars", Map.name, backupNum);
Player[] all = allPlayers.Items;
foreach (Player p in all) {
Get(p).Reset(Config.Difficulty);
@ -185,9 +174,6 @@ namespace MCGalaxy.Games {
foreach (Player p in all) {
Player.Message(p, "TNT Wars: You scored &f" + Get(p).Score + " points");
}
// TODO: does this even work right
Command.Find("Restore").Use(null, backupNum + " " + Map.name);
}
bool buildable = true, deletable = true;

View File

@ -165,7 +165,7 @@ namespace MCGalaxy {
foreach (Player pl in players) {
if (pl.level != old) continue;
pl.level = lvl;
ReloadMap(null, pl, false);
ReloadFor(null, pl, false);
}
old.Unload(true, false);
@ -201,21 +201,29 @@ namespace MCGalaxy {
}
public static void ReloadMap(Player p, Player who, bool announce) {
who.Loading = true;
Entities.DespawnEntities(who);
who.SendMap(who.level);
Entities.SpawnEntities(who);
who.Loading = false;
public static void ReloadAll(Level lvl, Player src, bool announce) {
Player[] players = PlayerInfo.Online.Items;
foreach (Player p in players) {
if (p.level != lvl) continue;
LevelActions.ReloadFor(src, p, true);
}
}
public static void ReloadFor(Player src, Player p, bool announce) {
p.Loading = true;
Entities.DespawnEntities(p);
p.SendMap(p.level);
Entities.SpawnEntities(p);
p.Loading = false;
if (!announce) return;
if (p == null || !Entities.CanSee(who, p)) {
who.SendMessage("&bMap reloaded");
if (src == null || !Entities.CanSee(p, src)) {
p.SendMessage("&bMap reloaded");
} else {
who.SendMessage("&bMap reloaded by " + p.ColoredName);
p.SendMessage("&bMap reloaded by " + src.ColoredName);
}
if (Entities.CanSee(p, who)) {
Player.Message(p, "&4Finished reloading for " + who.ColoredName);
if (Entities.CanSee(src, p)) {
Player.Message(src, "&4Finished reloading for " + p.ColoredName);
}
}

View File

@ -96,7 +96,7 @@ namespace MCGalaxy {
if (motdOnly) {
pl.SendMapMotd();
} else {
LevelActions.ReloadMap(p, pl, false);
LevelActions.ReloadFor(p, pl, false);
}
}
}