TNT wars: zone commands now don't share a global variable

This commit is contained in:
UnknownShadow200 2018-06-27 13:16:20 +10:00
parent ae7e9ee21b
commit ec01bb4826
2 changed files with 88 additions and 146 deletions

View File

@ -31,7 +31,6 @@ namespace MCGalaxy.Commands.Fun {
public override CommandPerm[] ExtraPerms { public override CommandPerm[] ExtraPerms {
get { return new[] { new CommandPerm(LevelPermission.Operator, "can manage TNT wars") }; } get { return new[] { new CommandPerm(LevelPermission.Operator, "can manage TNT wars") }; }
} }
bool NoTntZone = false;
public override void Use(Player p, string message) { public override void Use(Player p, string message) {
string[] text = new string[] { "", "", "", "", "" }; string[] text = new string[] { "", "", "", "", "" };
@ -764,40 +763,92 @@ namespace MCGalaxy.Commands.Fun {
} }
void HandleZone(Player p, TntWarsGame it, bool noTntZone, string[] text) { void HandleZone(Player p, TntWarsGame it, bool noTntZone, string[] text) {
NoTntZone = noTntZone;
string msg = noTntZone ? "no TNT" : "no blocks deleted on explosions"; string msg = noTntZone ? "no TNT" : "no blocks deleted on explosions";
List<TntWarsGame.Zone> zones = noTntZone ? it.NoTNTplacableZones : it.NoBlockDeathZones;
switch (text[3]) { if (IsCreateCommand(text[3])) {
case "add": Player.Message(p, "TNT Wars: Place 2 blocks to create the zone for {0}!", msg);
case "a": p.MakeSelection(2, zones, AddZoneCallback);
case "new": } else if (IsDeleteCommand(text[3])) {
Player.Message(p, "TNT Wars: Place 2 blocks to create the zone for {0}!", msg); if (!text[4].CaselessEq("all")) {
p.MakeSelection(2, null, AddZoneCallback);
break;
case "delete":
case "d":
case "remove":
case "r":
if (text[4] == "all" || text[4] == "a") {
if (noTntZone) it.NoTNTplacableZones.Clear();
else it.NoBlockDeathZones.Clear();
Player.Message(p, "TNT Wars: Deleted all zones for {0}!", msg);
return;
}
Player.Message(p, "TNT Wars: Place a block to delete the zone for {0}!", msg); Player.Message(p, "TNT Wars: Place a block to delete the zone for {0}!", msg);
p.MakeSelection(1, null, DeleteZoneCallback); p.MakeSelection(1, zones, DeleteZoneCallback);
break; } else {
zones.Clear();
case "check": Player.Message(p, "TNT Wars: Deleted all zones for {0}!", msg);
case "c": }
Player.Message(p, "TNT Wars: Place a block to check for no {0}!", msg); } else if (text[3].CaselessEq("check")) {
p.MakeSelection(1, null, CheckZoneCallback); Player.Message(p, "TNT Wars: Place a block to check for {0}!", msg);
break; p.MakeSelection(1, zones, CheckZoneCallback);
} }
} }
static bool AddZoneCallback(Player p, Vec3S32[] marks, object state, BlockID block) {
Vec3U16 p1 = (Vec3U16)marks[0], p2 = (Vec3U16)marks[1];
TntWarsGame.Zone zn = new TntWarsGame.Zone();
zn.MinX = Math.Min(p1.X, p2.X);
zn.MinY = Math.Min(p1.Y, p2.Y);
zn.MinZ = Math.Min(p1.Z, p2.Z);
zn.MaxX = Math.Max(p1.X, p2.X);
zn.MaxY = Math.Max(p1.Y, p2.Y);
zn.MaxZ = Math.Max(p1.Z, p2.Z);
TntWarsGame it = TntWarsGame.GameIn(p);
if (it == null) {
Player.Message(p, "TNT Wars Error: Couldn't find your game!"); return false;
}
List<TntWarsGame.Zone> zones = (List<TntWarsGame.Zone>)state;
zones.Add(zn);
Player.Message(p, "TNT Wars: Zonr added!");
return false;
}
static 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);
if (it == null) {
Player.Message(p, "TNT Wars Error: Couldn't find your game!"); return false;
}
List<TntWarsGame.Zone> zones = (List<TntWarsGame.Zone>)state;
foreach (TntWarsGame.Zone zn in zones) {
if (x >= zn.MinX && x <= zn.MaxX && y >= zn.MinY && y <= zn.MaxY && z >= zn.MinZ && z <= zn.MaxZ) {
zones.Remove(zn);
Player.Message(p, "TNT Wars: Zone deleted!");
return false;
}
}
Player.Message(p, "TNT Wars Error: You weren't in any zone");
return false;
}
static bool CheckZoneCallback(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);
if (it == null) {
Player.Message(p, "TNT Wars Error: Couldn't find your game!"); return false;
}
List<TntWarsGame.Zone> zones = (List<TntWarsGame.Zone>)state;
if (zones == it.NoTNTplacableZones) {
if (it.InZone(x, y, z, zones)) {
Player.Message(p, "TNT Wars: You are currently in a no TNT zone!");
} else {
Player.Message(p, "TNT Wars: You are not currently in a no TNT zone!");
}
} else if (zones == it.NoBlockDeathZones) {
if (it.InZone(x, y, z, zones)) {
Player.Message(p, "TNT Wars: You are currently in a no TNT block explosion zone (explosions won't destroy blocks)!");
} else {
Player.Message(p, "TNT Wars: You are currently in a TNT block explosion zone (explosions will destroy blocks)!");
}
}
return false;
}
static void SetDifficulty(TntWarsGame it, TntWarsGame.TntWarsDifficulty difficulty, static void SetDifficulty(TntWarsGame it, TntWarsGame.TntWarsDifficulty difficulty,
bool teamKill, string name, Player p) { bool teamKill, string name, Player p) {
if (it.Difficulty == difficulty) { if (it.Difficulty == difficulty) {
@ -945,64 +996,6 @@ namespace MCGalaxy.Commands.Fun {
} }
} }
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);
if (it == null) {
Player.Message(p, "TNT Wars Error: Couldn't find your game!");
} else if (it.InZone(x, y, z, NoTntZone)) {
it.DeleteZone(x, y, z, NoTntZone, p);
}
return false;
}
bool CheckZoneCallback(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);
if (it == null) {
Player.Message(p, "TNT Wars Error: Couldn't find your game!");
} else if (NoTntZone) {
if (it.InZone(x, y, z, NoTntZone)) {
Player.Message(p, "TNT Wars: You are currently in a no TNT zone!");
} else {
Player.Message(p, "TNT Wars: You are not currently in a no TNT zone!");
}
} else {
if (it.InZone(x, y, z, NoTntZone)) {
Player.Message(p, "TNT Wars: You are currently in a no TNT block explosion zone (explosions won't destroy blocks)!");
} else {
Player.Message(p, "TNT Wars: You are currently in a TNT block explosion zone (explosions will destroy blocks)!");
}
}
return false;
}
bool AddZoneCallback(Player p, Vec3S32[] marks, object state, BlockID block) {
Vec3U16 p1 = (Vec3U16)marks[0], p2 = (Vec3U16)marks[1];
TntWarsGame.Zone Zn = new TntWarsGame.Zone();
Zn.smallX = Math.Min(p1.X, p2.X);
Zn.smallY = Math.Min(p1.Y, p2.Y);
Zn.smallZ = Math.Min(p1.Z, p2.Z);
Zn.bigX = Math.Max(p1.X, p2.X);
Zn.bigY = Math.Max(p1.Y, p2.Y);
Zn.bigZ = Math.Max(p1.Z, p2.Z);
TntWarsGame it = TntWarsGame.GameIn(p);
if (it == null) {
Player.Message(p, "TNT Wars Error: Couldn't find your game!");
} else if (NoTntZone) {
it.NoTNTplacableZones.Add(Zn);
} else {
it.NoBlockDeathZones.Add(Zn);
}
Player.Message(p, "Added zone");
return false;
}
public override void Help(Player p) { public override void Help(Player p) {
Player.Message(p, "/tw list {l} - Lists all running games"); Player.Message(p, "/tw list {l} - Lists all running games");

View File

@ -77,14 +77,8 @@ namespace MCGalaxy.Games
//Zones //Zones
public List<Zone> NoTNTplacableZones = new List<Zone>(); public List<Zone> NoTNTplacableZones = new List<Zone>();
public List<Zone> NoBlockDeathZones = new List<Zone>(); public List<Zone> NoBlockDeathZones = new List<Zone>();
public class Zone public class Zone {
{ public ushort MinX, MinY, MinZ, MaxX, MaxY, MaxZ;
public ushort bigX;
public ushort bigY;
public ushort bigZ;
public ushort smallX;
public ushort smallY;
public ushort smallZ;
} }
//During Game Main Methods //During Game Main Methods
@ -536,60 +530,15 @@ namespace MCGalaxy.Games
return InZone(x, y, z, zones); return InZone(x, y, z, zones);
} }
bool InZone(ushort x, ushort y, ushort z, List<Zone> zones) { public bool InZone(ushort x, ushort y, ushort z, List<Zone> zones) {
foreach (Zone Zn in zones) { foreach (Zone Zn in zones) {
if (x >= Zn.smallX && y >= Zn.smallY && z >= Zn.smallZ if (x >= Zn.MinX && y >= Zn.MinY && z >= Zn.MinZ
&& x <= Zn.bigX && y <= Zn.bigY && z <= Zn.bigZ) return true; && x <= Zn.MaxX && y <= Zn.MaxY && z <= Zn.MaxZ) return true;
} }
return false; return false;
} }
public void DeleteZone(ushort x, ushort y, ushort z, bool NoTntZone, Player p = null) public bool TeamKill(Player p1, Player p2)
{
try
{
Zone Z = new Zone();
if (NoTntZone)
{
foreach (Zone Zn in NoTNTplacableZones)
{
if (Zn.smallX <= x && x <= Zn.bigX && Zn.smallY <= y && y <= Zn.bigY && Zn.smallZ <= z && z <= Zn.bigZ)
{
Z = Zn;
}
}
NoTNTplacableZones.Remove(Z);
if (p != null)
{
Player.Message(p, "TNT Wars: Zone Deleted!");
}
return;
}
else
{
foreach (Zone Zn in NoBlockDeathZones)
{
if (Zn.smallX <= x && x <= Zn.bigX && Zn.smallY <= y && y <= Zn.bigY && Zn.smallZ <= z && z <= Zn.bigZ)
{
Z = Zn;
}
}
NoBlockDeathZones.Remove(Z);
if (p != null)
{
Player.Message(p, "TNT Wars: Zone Deleted!");
}
return;
}
}
catch
{
Player.Message(p, "TNT Wars Error: Zone not deleted!");
}
}
public bool TeamKill (Player p1, Player p2)
{ {
return TeamKill(FindPlayer(p1), FindPlayer(p2)); return TeamKill(FindPlayer(p1), FindPlayer(p2));
} }