Add /replacebrush and /replacenotbrush.

This commit is contained in:
UnknownShadow200 2016-03-10 13:23:12 +11:00
parent bcaf2e43d3
commit 3bb6f9aa45
11 changed files with 128 additions and 65 deletions

View File

@ -221,7 +221,9 @@ namespace MCGalaxy
all.Add(new CmdRepeat());
all.Add(new CmdReplace());
all.Add(new CmdReplaceAll());
all.Add(new CmdReplaceBrush());
all.Add(new CmdReplaceNot());
all.Add(new CmdReplaceNotBrush());
all.Add(new CmdReport());
all.Add(new CmdResetBot());
all.Add(new CmdResetPass());

View File

@ -38,7 +38,7 @@ namespace MCGalaxy.Commands {
}
string src = args[0], dst = args[1];
if (!p.group.CanExecute(Command.all.Find("newlvl"))) {
if (!p.group.CanExecute("newlvl")) {
Player.SendMessage(p, "You cannot use /copylvl as you cannot use /newlvl."); return;
}
if (!Player.ValidName(src)) { Player.SendMessage(p, "\"" + src + "\" is not a valid level name."); return; }

View File

@ -105,7 +105,7 @@ namespace MCGalaxy.Commands {
if (!p.ignorePermission && p.group.Permission < lvl.permissionvisit) {
Player.SendMessage(p, "You're not allowed to go to " + lvl.name + "."); return false;
}
if (!p.ignorePermission && p.group.Permission > lvl.pervisitmax && !p.group.CanExecute(Command.all.Find("pervisitmax"))) {
if (!p.ignorePermission && p.group.Permission > lvl.pervisitmax && !p.group.CanExecute("pervisitmax")) {
Player.SendMessage(p, "Your rank must be " + lvl.pervisitmax + " or lower to go there!"); return false;
}
if (File.Exists("text/lockdown/map/" + message.ToLower())) {

View File

@ -17,38 +17,98 @@
*/
using System;
using MCGalaxy;
using MCGalaxy.Drawing;
using MCGalaxy.Drawing.Brushes;
namespace MCGalaxy.Commands {
public sealed class CmdReplaceBrush : Command {
public override string name { get { return "replacebrush"; } }
public override string shortcut { get { return "rb"; } }
public override string type { get { return CommandTypes.Building; } }
public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
static char[] trimChars = {' '};
using MCGalaxy.Drawing.Ops;
public override void Use(Player p, string message) {
// TODO: make sure can use or brush first.
if (message == "") { Help(p); return; }
if (p == null) { MessageInGameOnly(p); return; }
string[] args = message.Split(trimChars, 3);
if (args.Length < 2) { Help(p); return }
byte extType = 0;
byte type = DrawCmd.GetBlock(p, args[0], out extType);
string brush = CmdBrush.FindBrush(args[1]);
if (brush == null) {
Player.SendMessage(p, "No brush found with name \"" + message + "\".");
Player.SendMessage(p, "Available brushes: " + CmdBrush.AvailableBrushes);
return;
}
}
public override void Help(Player p) {
Player.SendMessage(p, "/replace [block] [block2].. [new] - replace block with new inside a selected cuboid");
Player.SendMessage(p, "If more than one [block] is specified, they will all be replaced.");
}
}
namespace MCGalaxy.Commands {
public class CmdReplaceBrush : Command {
public override string name { get { return "replacebrush"; } }
public override string shortcut { get { return "rb"; } }
public override string type { get { return CommandTypes.Building; } }
public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
static char[] trimChars = {' '};
public override void Use(Player p, string message) {
if (message == "") { Help(p); return; }
if (p == null) { MessageInGameOnly(p); return; }
string replaceCmd = ReplaceNot ? "replacenot" : "replace";
if (!p.group.CanExecute(replaceCmd) || !p.group.CanExecute("brush")) {
Player.SendMessage(p, "You cannot use /brush and/or /" + replaceCmd +
", so therefore cannot use this command."); return;
}
CatchPos cpos = default(CatchPos);
cpos.message = message.ToLower();
p.blockchangeObject = cpos;
Player.SendMessage(p, "Place two blocks to determine the edges.");
p.ClearBlockchange();
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
}
void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z);
CatchPos bp = (CatchPos)p.blockchangeObject;
bp.x = x; bp.y = y; bp.z = z;
p.blockchangeObject = bp;
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange2);
}
void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z);
CatchPos cpos = (CatchPos)p.blockchangeObject;
type = type < 128 ? p.bindings[type] : type;
string[] parts = cpos.message.Split(trimChars, 3);
if (parts.Length < 2) { Help(p); return; }
byte extTile = 0;
byte tile = DrawCmd.GetBlock(p, parts[0], out extTile);
if (tile == Block.Zero) return;
string brushName = CmdBrush.FindBrush(parts[1]);
if (brushName == null) {
Player.SendMessage(p, "No brush found with name \"" + parts[1] + "\".");
Player.SendMessage(p, "Available brushes: " + CmdBrush.AvailableBrushes);
return;
}
string brushMessage = parts.Length > 2 ? parts[2].ToLower() : "";
BrushArgs args = new BrushArgs(p, brushMessage, type, extType);
Brush brush = Brush.Brushes[brushName](args);
if (brush == null) return;
DrawOp drawOp = null;
if (ReplaceNot) drawOp = new ReplaceNotDrawOp(tile, extTile);
else drawOp = new ReplaceDrawOp(tile, extTile);
if (!DrawOp.DoDrawOp(drawOp, brush, p, cpos.x, cpos.y, cpos.z, x, y, z))
return;
if (p.staticCommands)
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
}
protected virtual bool ReplaceNot { get { return false; } }
struct CatchPos { public ushort x, y, z; public string message; }
public override void Help(Player p) {
Player.SendMessage(p, "/replace [block] [block2].. [new] - replace block with new inside a selected cuboid");
Player.SendMessage(p, "If more than one [block] is specified, they will all be replaced.");
}
}
public class CmdReplaceNotBrush : CmdReplaceBrush {
public override string name { get { return "replacenotbrush"; } }
public override string shortcut { get { return "r b"; } }
protected override bool ReplaceNot { get { return true; } }
public override void Help(Player p) {
Player.SendMessage(p, "/replace [block] [block2].. [new] - replace block with new inside a selected cuboid");
Player.SendMessage(p, "If more than one [block] is specified, they will all be replaced.");
}
}
}

View File

@ -127,7 +127,7 @@ namespace MCGalaxy.Commands
if (p != null && (int)p.group.Permission < CommandOtherPerms.GetPerm(this, 2)) {
Player.SendMessage(p, "Reserved for " + Group.findPermInt(CommandOtherPerms.GetPerm(this, 2)).name + "+"); return;
}
if (p != null && !p.group.CanExecute(Command.all.Find("physics"))) {
if (p != null && !p.group.CanExecute("physics")) {
Player.SendMessage(p, "You can only undo physics if you can use /physics."); return;
}
Command.all.Find("physics").Use(p, "0");

View File

@ -31,7 +31,7 @@ namespace MCGalaxy.Commands {
public override void Use(Player p, string message) {
if (p == null) { MessageInGameOnly(p); return; }
if (!p.group.CanExecute(Command.all.Find("write"))) {
if (!p.group.CanExecute("write")) {
Player.SendMessage(p, "You must be able to use /write to use /writetext."); return;
}

View File

@ -23,7 +23,13 @@ namespace MCGalaxy {
public struct FillPos { public ushort X, Y, Z; }
public struct ExtBlock { public byte Type, ExtType; }
public struct ExtBlock {
public byte Type, ExtType;
public ExtBlock(byte type, byte extType) {
Type = type; ExtType = extType;
}
}
}
namespace MCGalaxy.Drawing.Ops {

View File

@ -22,8 +22,11 @@ namespace MCGalaxy.Drawing.Ops {
public class ReplaceDrawOp : DrawOp {
public ExtBlock[] ToReplace;
public ExtBlock Target;
public ExtBlock Include;
public ReplaceDrawOp(byte type, byte extType) {
Include = new ExtBlock(type, extType);
}
public override string Name { get { return "Replace"; } }
@ -33,8 +36,6 @@ namespace MCGalaxy.Drawing.Ops {
public override void Perform(ushort x1, ushort y1, ushort z1, ushort x2,
ushort y2, ushort z2, Player p, Level lvl, Brush brush) {
ExtBlock[] toReplace = ToReplace;
ExtBlock target = Target;
for (ushort y = y1; y <= y2; y++)
for (ushort z = z1; z <= z2; z++)
for (ushort x = x1; x <= x2; x++)
@ -42,20 +43,19 @@ namespace MCGalaxy.Drawing.Ops {
byte tile = lvl.GetTile(x, y, z), extTile = 0;
if (tile == Block.custom_block) extTile = lvl.GetExtTile(x, y, z);
for (int i = 0; i < toReplace.Length; i++) {
ExtBlock block = toReplace[i];
if (tile == block.Type && (tile != Block.custom_block || extTile == block.ExtType)) {
PlaceBlock(p, lvl, x, y, z, target.Type, target.ExtType); break;
}
}
if (tile == Include.Type && (tile != Block.custom_block || extTile == Include.ExtType))
PlaceBlock(p, lvl, x, y, z, brush);
}
}
}
public class ReplaceNotDrawOp : DrawOp {
public ExtBlock[] ToReplace;
public ExtBlock Target;
public ExtBlock Exclude;
public ReplaceNotDrawOp(byte type, byte extType) {
Exclude = new ExtBlock(type, extType);
}
public override string Name { get { return "ReplaceNot"; } }
@ -65,8 +65,6 @@ namespace MCGalaxy.Drawing.Ops {
public override void Perform(ushort x1, ushort y1, ushort z1, ushort x2,
ushort y2, ushort z2, Player p, Level lvl, Brush brush) {
ExtBlock[] toReplace = ToReplace;
ExtBlock target = Target;
for (ushort y = y1; y <= y2; y++)
for (ushort z = z1; z <= z2; z++)
for (ushort x = x1; x <= x2; x++)
@ -74,16 +72,10 @@ namespace MCGalaxy.Drawing.Ops {
byte tile = lvl.GetTile(x, y, z), extTile = 0;
if (tile == Block.custom_block) extTile = lvl.GetExtTile(x, y, z);
bool place = true;
for (int i = 0; i < toReplace.Length; i++) {
ExtBlock block = toReplace[i];
if (tile == block.Type || (tile == Block.custom_block && extTile == block.ExtType)) {
place = false; break;
}
if (tile != Exclude.Type || (tile == Block.custom_block && extTile != Exclude.ExtType)) {
PlaceBlock(p, lvl, x, y, z, brush);
}
if (place)
PlaceBlock(p, lvl, x, y, z, target.Type, target.ExtType);
}
}
}
}
}

View File

@ -273,8 +273,7 @@ namespace MCGalaxy {
return false;
}
if (p.group.Permission > perbuildmax && (!inZone || !AllowBuild) &&
!p.group.CanExecute(Command.all.Find("perbuildmax"))) {
if (p.group.Permission > perbuildmax && (!inZone || !AllowBuild) && !p.group.CanExecute("perbuildmax")) {
if (p.ZoneSpam.AddSeconds(2) <= DateTime.UtcNow) {
Player.SendMessage(p, "Your rank must be " + perbuildmax + " or lower to build here!");
p.ZoneSpam = DateTime.UtcNow;

View File

@ -127,6 +127,7 @@
<Compile Include="Commands\Building\CmdPortal.cs" />
<Compile Include="Commands\Building\CmdPyramid.cs" />
<Compile Include="Commands\Building\CmdRedo.cs" />
<Compile Include="Commands\building\CmdReplaceBrush.cs" />
<Compile Include="Commands\building\ReplaceCmd.cs" />
<Compile Include="Commands\Building\CmdRestartPhysics.cs" />
<Compile Include="Commands\Building\CmdSpheroid.cs" />

View File

@ -99,9 +99,12 @@ namespace MCGalaxy
GrpCommands.AddCommands(out _commands, Permission);
commands = _commands;
}
/// <summary>
/// Check to see if this group can excute cmd
/// </summary>
public bool CanExecute(string cmdName) {
return commands.Contains(Command.all.Find(cmdName));
}
/// <summary> Check to see if this group can excute cmd </summary>
/// <param name="cmd">The command object to check</param>
/// <returns>True if this group can use it, false if they cant</returns>
public bool CanExecute(Command cmd) { return commands.Contains(cmd); }