mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Prefer MakeSelection to using blockchange
This commit is contained in:
parent
2c1698d7b6
commit
a44b630464
@ -31,7 +31,7 @@ namespace MCGalaxy.Commands.Fun {
|
||||
public override CommandPerm[] ExtraPerms {
|
||||
get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can use admin commands for tntwars") }; }
|
||||
}
|
||||
bool DeleteZone = false, CheckZone = false, NoTntZone = false;
|
||||
bool NoTntZone = false;
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
string[] text = new string[] { "", "", "", "", "" };
|
||||
@ -498,7 +498,7 @@ namespace MCGalaxy.Commands.Fun {
|
||||
int number = 1;
|
||||
if (!CommandParser.GetInt(p, text[2], "TNT at a time", ref number, 0)) return;
|
||||
|
||||
Player.Message(p, "TNT Wars: Number of TNTs placeable by a player at a time is now {0}",
|
||||
Player.Message(p, "TNT Wars: Number of TNTs placeable by a player at a time is now {0}",
|
||||
number == 0 ? "unlimited" : number.ToString());
|
||||
it.CheckAllSetUp(p);
|
||||
break;
|
||||
@ -946,20 +946,13 @@ namespace MCGalaxy.Commands.Fun {
|
||||
void HandleZone(Player p, TntWarsGame it, bool noTntZone, string[] text) {
|
||||
NoTntZone = noTntZone;
|
||||
string msg = noTntZone ? "no TNT" : "no blocks deleted on explosions";
|
||||
DeleteZone = false;
|
||||
CheckZone = false;
|
||||
Vec3U16 cpos = default(Vec3U16);
|
||||
p.blockchangeObject = cpos;
|
||||
|
||||
switch (text[3]) {
|
||||
case "add":
|
||||
case "a":
|
||||
case "new":
|
||||
DeleteZone = false;
|
||||
CheckZone = false;
|
||||
Player.Message(p, "TNT Wars: Place 2 blocks to create the zone for {0}!", msg);
|
||||
//p.ClearBlockchange();
|
||||
p.Blockchange += PlacedMark1;
|
||||
p.MakeSelection(2, null, AddZoneCallback);
|
||||
break;
|
||||
|
||||
case "delete":
|
||||
@ -972,20 +965,15 @@ namespace MCGalaxy.Commands.Fun {
|
||||
Player.Message(p, "TNT Wars: Deleted all zones for {0}!", msg);
|
||||
return;
|
||||
}
|
||||
DeleteZone = true;
|
||||
CheckZone = false;
|
||||
|
||||
Player.Message(p, "TNT Wars: Place a block to delete the zone for {0}!", msg);
|
||||
p.ClearBlockchange();
|
||||
p.Blockchange += PlacedMark1;
|
||||
p.MakeSelection(1, null, DeleteZoneCallback);
|
||||
break;
|
||||
|
||||
case "check":
|
||||
case "c":
|
||||
DeleteZone = false;
|
||||
CheckZone = true;
|
||||
Player.Message(p, "TNT Wars: Place a block to check for no {0}!", msg);
|
||||
p.ClearBlockchange();
|
||||
p.Blockchange += PlacedMark1;
|
||||
p.MakeSelection(1, null, CheckZoneCallback);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1157,63 +1145,62 @@ namespace MCGalaxy.Commands.Fun {
|
||||
}
|
||||
}
|
||||
|
||||
void PlacedMark1(Player p, ushort x, ushort y, ushort z, ExtBlock block) {
|
||||
RevertAndClearState(p, x, y, z);
|
||||
Vec3U16 bp = (Vec3U16)p.blockchangeObject;
|
||||
bp.X = x; bp.Y = y; bp.Z = z;
|
||||
p.blockchangeObject = bp;
|
||||
|
||||
if (!DeleteZone && !CheckZone) {
|
||||
Player.Message(p, "TNT Wars: Place another block to mark the other corner of the zone!");
|
||||
p.Blockchange += PlacedMark2;
|
||||
return;
|
||||
}
|
||||
|
||||
bool DeleteZoneCallback(Player p, Vec3S32[] marks, object state, ExtBlock block) {
|
||||
ushort x = (ushort)marks[0].X, y = (ushort)marks[0].Y, z = (ushort)marks[0].Z;
|
||||
TntWarsGame it = TntWarsGame.GetTntWarsGame(p);
|
||||
if (DeleteZone) {
|
||||
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);
|
||||
}
|
||||
} else if (CheckZone && NoTntZone) {
|
||||
if (it == null) {
|
||||
Player.Message(p, "TNT Wars Error: Couldn't find your game!");
|
||||
} else if (it.InZone(x, y, z, true)) {
|
||||
|
||||
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, ExtBlock block) {
|
||||
ushort x = (ushort)marks[0].X, y = (ushort)marks[0].Y, z = (ushort)marks[0].Z;
|
||||
TntWarsGame it = TntWarsGame.GetTntWarsGame(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 (CheckZone && !NoTntZone) {
|
||||
if (it == null) {
|
||||
Player.Message(p, "TNT Wars Error: Couldn't find your game!");
|
||||
} else if (it.InZone(x, y, z, true)) {
|
||||
} 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;
|
||||
}
|
||||
|
||||
void PlacedMark2(Player p, ushort x, ushort y, ushort z, ExtBlock block) {
|
||||
RevertAndClearState(p, x, y, z);
|
||||
Vec3U16 cpos = (Vec3U16)p.blockchangeObject;
|
||||
|
||||
bool AddZoneCallback(Player p, Vec3S32[] marks, object state, ExtBlock block) {
|
||||
Vec3U16 p1 = (Vec3U16)marks[0], p2 = (Vec3U16)marks[1];
|
||||
TntWarsGame.Zone Zn = new TntWarsGame.Zone();
|
||||
|
||||
Zn.smallX = Math.Min(cpos.X, x);
|
||||
Zn.smallY = Math.Min(cpos.Y, y);
|
||||
Zn.smallZ = Math.Min(cpos.Z, z);
|
||||
Zn.bigX = Math.Max(cpos.X, x);
|
||||
Zn.bigY = Math.Max(cpos.Y, y);
|
||||
Zn.bigZ = Math.Max(cpos.Z, z);
|
||||
|
||||
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.GetTntWarsGame(p);
|
||||
if (it == null) {
|
||||
Player.Message(p, "TNT Wars Error: Couldn't find your game!"); return;
|
||||
Player.Message(p, "TNT Wars Error: Couldn't find your game!");
|
||||
} else if (NoTntZone) {
|
||||
it.NoTNTplacableZones.Add(Zn);
|
||||
} else {
|
||||
it.NoBlockDeathZones.Add(Zn);
|
||||
}
|
||||
if (NoTntZone) it.NoTNTplacableZones.Add(Zn);
|
||||
else it.NoBlockDeathZones.Add(Zn);
|
||||
|
||||
Player.Message(p, "Added zone");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ namespace MCGalaxy.Commands.Fun {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected struct CatchPos { public ushort x, y, z; public EndType ending; }
|
||||
protected struct CatchPos { public EndType ending; }
|
||||
protected enum EndType { Invalid, Normal, Destroy, Teleport, Explode, Laser };
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using MCGalaxy.DB;
|
||||
using MCGalaxy.SQL;
|
||||
using MCGalaxy.Maths;
|
||||
|
||||
namespace MCGalaxy.Commands.Info {
|
||||
public sealed class CmdAbout : Command {
|
||||
@ -36,16 +37,13 @@ namespace MCGalaxy.Commands.Info {
|
||||
public override void Use(Player p, string message) {
|
||||
if (Player.IsSuper(p)) { MessageInGameOnly(p); return; }
|
||||
Player.Message(p, "Break/build a block to display information.");
|
||||
p.ClearBlockchange();
|
||||
p.Blockchange += PlacedBlock;
|
||||
p.MakeSelection(1, null, PlacedMark);
|
||||
}
|
||||
|
||||
void PlacedBlock(Player p, ushort x, ushort y, ushort z, ExtBlock block) {
|
||||
if (!p.staticCommands) p.ClearBlockchange();
|
||||
bool PlacedMark(Player p, Vec3S32[] marks, object state, ExtBlock block) {
|
||||
ushort x = (ushort)marks[0].X, y = (ushort)marks[0].Y, z = (ushort)marks[0].Z;
|
||||
block = p.level.GetExtBlock(x, y, z);
|
||||
if (block.IsInvalid) return;
|
||||
p.RevertBlock(x, y, z);
|
||||
|
||||
p.RevertBlock(x, y, z);
|
||||
Dictionary<int, string> names = new Dictionary<int, string>();
|
||||
|
||||
Player.Message(p, "Retrieving block change records..");
|
||||
@ -57,7 +55,7 @@ namespace MCGalaxy.Commands.Info {
|
||||
entry => OutputEntry(p, ref foundAny, names, entry));
|
||||
} else {
|
||||
Player.Message(p, "&cUnable to accquire read lock on BlockDB after 30 seconds, aborting.");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,6 +68,7 @@ namespace MCGalaxy.Commands.Info {
|
||||
BlockDBChange.OutputMessageBlock(p, block, x, y, z);
|
||||
BlockDBChange.OutputPortal(p, block, x, y, z);
|
||||
Server.DoGC();
|
||||
return true;
|
||||
}
|
||||
|
||||
static void ListFromDatabase(Player p, ref bool foundAny, Dictionary<int, string> names,
|
||||
|
@ -30,7 +30,6 @@ namespace MCGalaxy.Commands.Building {
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
Player.Message(p, "Place or break two blocks to determine the edges.");
|
||||
p.ClearBlockchange();
|
||||
p.MakeSelection(2, null, DoCentre);
|
||||
}
|
||||
|
||||
|
@ -147,18 +147,17 @@ namespace MCGalaxy.Commands.Building {
|
||||
Player.Message(p, format, cState.UsedBlocks);
|
||||
if (cArgs.offsetIndex != -1) {
|
||||
Player.Message(p, "Place a block to determine where to paste from");
|
||||
p.Blockchange += BlockchangeOffset;
|
||||
p.MakeSelection(1, null, PlacedOffsetMark);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void BlockchangeOffset(Player p, ushort x, ushort y, ushort z, ExtBlock block) {
|
||||
RevertAndClearState(p, x, y, z);
|
||||
CopyState state = p.CopyBuffer;
|
||||
|
||||
state.Offset.X = state.OriginX - x;
|
||||
state.Offset.Y = state.OriginY - y;
|
||||
state.Offset.Z = state.OriginZ - z;
|
||||
bool PlacedOffsetMark(Player p, Vec3S32[] marks, object state, ExtBlock block) {
|
||||
CopyState copy = p.CopyBuffer;
|
||||
copy.Offset.X = copy.OriginX - marks[0].X;
|
||||
copy.Offset.Y = copy.OriginY - marks[0].Y;
|
||||
copy.Offset.Z = copy.OriginZ - marks[0].Z;
|
||||
return false;
|
||||
}
|
||||
|
||||
struct CopyArgs { public int type, offsetIndex; }
|
||||
|
@ -20,6 +20,7 @@ using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using MCGalaxy.Blocks;
|
||||
using MCGalaxy.Blocks.Extended;
|
||||
using MCGalaxy.Maths;
|
||||
using MCGalaxy.SQL;
|
||||
using MCGalaxy.Util;
|
||||
|
||||
@ -59,10 +60,8 @@ namespace MCGalaxy.Commands.Building {
|
||||
if (!CheckCommand(p, cmd)) return;
|
||||
}
|
||||
|
||||
p.blockchangeObject = data;
|
||||
Player.Message(p, "Place where you wish the message block to go.");
|
||||
p.ClearBlockchange();
|
||||
p.Blockchange += PlacedMark;
|
||||
p.MakeSelection(1, data, PlacedMark);
|
||||
}
|
||||
|
||||
ExtBlock GetBlock(Player p, string name, ref bool allMessage) {
|
||||
@ -110,9 +109,9 @@ namespace MCGalaxy.Commands.Building {
|
||||
return message.CaselessEq(cmd) || message.CaselessStarts(cmd + " ");
|
||||
}
|
||||
|
||||
void PlacedMark(Player p, ushort x, ushort y, ushort z, ExtBlock block) {
|
||||
p.ClearBlockchange();
|
||||
MBData data = (MBData)p.blockchangeObject;
|
||||
bool PlacedMark(Player p, Vec3S32[] marks, object state, ExtBlock block) {
|
||||
ushort x = (ushort)marks[0].X, y = (ushort)marks[0].Y, z = (ushort)marks[0].Z;
|
||||
MBData data = (MBData)state;
|
||||
|
||||
ExtBlock old = p.level.GetExtBlock(x, y, z);
|
||||
if (p.level.CheckAffectPermissions(p, x, y, z, old, data.Block)) {
|
||||
@ -121,10 +120,8 @@ namespace MCGalaxy.Commands.Building {
|
||||
Player.Message(p, "Message block created.");
|
||||
} else {
|
||||
Player.Message(p, "Failed to create a message block.");
|
||||
}
|
||||
p.RevertBlock(x, y, z);
|
||||
|
||||
if (p.staticCommands) p.Blockchange += PlacedMark;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void UpdateDatabase(Player p, MBData data, ushort x, ushort y, ushort z) {
|
||||
|
@ -145,6 +145,7 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
/// <summary> Called when the player has finished providing all the marks for a selection. </summary>
|
||||
/// <returns> Whether to repeat this selection, if /static mode is enabled. </returns>
|
||||
public delegate bool SelectionHandler(Player p, Vec3S32[] marks, object state, ExtBlock block);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user