mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Fix TNT wars not being properly reset at round end
This commit is contained in:
parent
d54fca0f33
commit
0458010040
@ -329,7 +329,7 @@ namespace MCGalaxy {
|
|||||||
// if custom block is replacing core block, need to always reload for fallback
|
// if custom block is replacing core block, need to always reload for fallback
|
||||||
if (block >= Block.CpeCount && !pl.level.MayHaveCustomBlocks) continue;
|
if (block >= Block.CpeCount && !pl.level.MayHaveCustomBlocks) continue;
|
||||||
|
|
||||||
LevelActions.ReloadMap(pl, pl, false);
|
LevelActions.ReloadFor(pl, pl, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ namespace MCGalaxy.Commands.World {
|
|||||||
if (parts[0].CaselessEq("all")) {
|
if (parts[0].CaselessEq("all")) {
|
||||||
if (!ReloadAll(p, parts)) return;
|
if (!ReloadAll(p, parts)) return;
|
||||||
} else {
|
} else {
|
||||||
LevelActions.ReloadMap(p, p, true);
|
LevelActions.ReloadFor(p, p, true);
|
||||||
}
|
}
|
||||||
Server.DoGC();
|
Server.DoGC();
|
||||||
}
|
}
|
||||||
@ -55,11 +55,7 @@ namespace MCGalaxy.Commands.World {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!CheckExtraPerm(p, 1)) return false;
|
if (!CheckExtraPerm(p, 1)) return false;
|
||||||
Player[] players = PlayerInfo.Online.Items;
|
LevelActions.ReloadAll(lvl, p, true);
|
||||||
foreach (Player who in players) {
|
|
||||||
if (who.level == lvl)
|
|
||||||
LevelActions.ReloadMap(p, who, true);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
Player[] players = PlayerInfo.Online.Items;
|
Player[] players = PlayerInfo.Online.Items;
|
||||||
foreach (Player pl in players) {
|
foreach (Player pl in players) {
|
||||||
if (pl.level.name.CaselessEq(lvl.name))
|
if (pl.level.name.CaselessEq(lvl.name))
|
||||||
LevelActions.ReloadMap(p, pl, true);
|
LevelActions.ReloadFor(p, pl, true);
|
||||||
}
|
}
|
||||||
Server.DoGC();
|
Server.DoGC();
|
||||||
}
|
}
|
||||||
|
@ -143,23 +143,43 @@ namespace MCGalaxy.Games {
|
|||||||
protected virtual void VoteAndMoveToNextMap() {
|
protected virtual void VoteAndMoveToNextMap() {
|
||||||
Picker.AddRecentMap(Map.MapName);
|
Picker.AddRecentMap(Map.MapName);
|
||||||
if (RoundsLeft == 0) return;
|
if (RoundsLeft == 0) return;
|
||||||
|
|
||||||
string map = Picker.ChooseNextLevel(this);
|
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("The next map has been chosen - &c" + map.ToLower());
|
||||||
Map.Message("Please wait while you are transfered.");
|
Map.Message("Please wait while you are transfered.");
|
||||||
LastMap = Map.MapName;
|
Level lastMap = Map; LastMap = Map.MapName;
|
||||||
|
|
||||||
if (!SetMap(map)) {
|
if (!SetMap(map)) {
|
||||||
Map.Message("%WFailed to change map to " + map);
|
Map.Message("%WFailed to change map to " + map);
|
||||||
Map.Message("Continuing " + GameName + " on the same map");
|
ContinueOnSameMap();
|
||||||
} else {
|
} else {
|
||||||
TransferPlayers(LastMap);
|
TransferPlayers(lastMap);
|
||||||
Command.Find("Unload").Use(null, 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();
|
Random rnd = new Random();
|
||||||
Player[] online = PlayerInfo.Online.Items;
|
Player[] online = PlayerInfo.Online.Items;
|
||||||
List<Player> transfers = new List<Player>(online.Length);
|
List<Player> transfers = new List<Player>(online.Length);
|
||||||
@ -167,7 +187,7 @@ namespace MCGalaxy.Games {
|
|||||||
foreach (Player pl in online) {
|
foreach (Player pl in online) {
|
||||||
pl.Game.RatedMap = false;
|
pl.Game.RatedMap = false;
|
||||||
pl.Game.PledgeSurvive = 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) {
|
while (transfers.Count > 0) {
|
||||||
|
@ -91,7 +91,7 @@ namespace MCGalaxy.Games {
|
|||||||
|
|
||||||
public void SetDefaults(Level lvl) {
|
public void SetDefaults(Level lvl) {
|
||||||
ushort midX = (ushort)(lvl.Width / 2);
|
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);
|
ushort maxZ = (ushort)(lvl.Length - 1);
|
||||||
|
|
||||||
RedSpawn = new Vec3U16(midX, midY, 0);
|
RedSpawn = new Vec3U16(midX, midY, 0);
|
||||||
|
@ -35,18 +35,7 @@ namespace MCGalaxy.Games {
|
|||||||
|
|
||||||
public sealed partial class TWGame : RoundsGame {
|
public sealed partial class TWGame : RoundsGame {
|
||||||
|
|
||||||
int backupNum;
|
|
||||||
protected override void DoRound() {
|
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;
|
Player[] all = allPlayers.Items;
|
||||||
foreach (Player p in all) {
|
foreach (Player p in all) {
|
||||||
Get(p).Reset(Config.Difficulty);
|
Get(p).Reset(Config.Difficulty);
|
||||||
@ -185,9 +174,6 @@ namespace MCGalaxy.Games {
|
|||||||
foreach (Player p in all) {
|
foreach (Player p in all) {
|
||||||
Player.Message(p, "TNT Wars: You scored &f" + Get(p).Score + " points");
|
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;
|
bool buildable = true, deletable = true;
|
||||||
|
@ -165,7 +165,7 @@ namespace MCGalaxy {
|
|||||||
foreach (Player pl in players) {
|
foreach (Player pl in players) {
|
||||||
if (pl.level != old) continue;
|
if (pl.level != old) continue;
|
||||||
pl.level = lvl;
|
pl.level = lvl;
|
||||||
ReloadMap(null, pl, false);
|
ReloadFor(null, pl, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
old.Unload(true, false);
|
old.Unload(true, false);
|
||||||
@ -201,21 +201,29 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void ReloadMap(Player p, Player who, bool announce) {
|
public static void ReloadAll(Level lvl, Player src, bool announce) {
|
||||||
who.Loading = true;
|
Player[] players = PlayerInfo.Online.Items;
|
||||||
Entities.DespawnEntities(who);
|
foreach (Player p in players) {
|
||||||
who.SendMap(who.level);
|
if (p.level != lvl) continue;
|
||||||
Entities.SpawnEntities(who);
|
LevelActions.ReloadFor(src, p, true);
|
||||||
who.Loading = false;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (!announce) return;
|
||||||
|
|
||||||
if (p == null || !Entities.CanSee(who, p)) {
|
if (src == null || !Entities.CanSee(p, src)) {
|
||||||
who.SendMessage("&bMap reloaded");
|
p.SendMessage("&bMap reloaded");
|
||||||
} else {
|
} else {
|
||||||
who.SendMessage("&bMap reloaded by " + p.ColoredName);
|
p.SendMessage("&bMap reloaded by " + src.ColoredName);
|
||||||
}
|
}
|
||||||
if (Entities.CanSee(p, who)) {
|
if (Entities.CanSee(src, p)) {
|
||||||
Player.Message(p, "&4Finished reloading for " + who.ColoredName);
|
Player.Message(src, "&4Finished reloading for " + p.ColoredName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ namespace MCGalaxy {
|
|||||||
if (motdOnly) {
|
if (motdOnly) {
|
||||||
pl.SendMapMotd();
|
pl.SendMapMotd();
|
||||||
} else {
|
} else {
|
||||||
LevelActions.ReloadMap(p, pl, false);
|
LevelActions.ReloadFor(p, pl, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user