Stage 3: /draw now works with brushes. Still need to cleanup a few things.

This commit is contained in:
UnknownShadow200 2016-03-29 09:19:43 +11:00
parent 3e59cda393
commit 82f2a20b40
6 changed files with 98 additions and 202 deletions

View File

@ -31,33 +31,33 @@ namespace MCGalaxy.Commands
RevertAndClearState(p, x, y, z);
CatchPos cpos = (CatchPos)p.blockchangeObject;
GetRealBlock(type, extType, p, ref cpos);
DrawOp drawOp = null;
DrawOp op = null;
Func<BrushArgs, Brush> constructor = null;
switch (cpos.mode) {
case DrawMode.solid:
drawOp = new CuboidDrawOp();
op = new CuboidDrawOp();
constructor = SolidBrush.Process; break;
case DrawMode.normal:
drawOp = new CuboidDrawOp(); break;
op = new CuboidDrawOp(); break;
case DrawMode.hollow:
drawOp = new CuboidHollowsDrawOp(); break;
op = new CuboidHollowsDrawOp(); break;
case DrawMode.walls:
drawOp = new CuboidWallsDrawOp(); break;
op = new CuboidWallsDrawOp(); break;
case DrawMode.holes:
drawOp = new CuboidDrawOp();
op = new CuboidDrawOp();
constructor = CheckeredBrush.Process; break;
case DrawMode.wire:
drawOp = new CuboidWireframeDrawOp(); break;
op = new CuboidWireframeDrawOp(); break;
case DrawMode.random:
drawOp = new CuboidDrawOp();
op = new CuboidDrawOp();
constructor = RandomBrush.Process; break;
}
int brushOffset = cpos.mode == DrawMode.normal ? 0 : 1;
Brush brush = GetBrush(p, cpos, brushOffset, constructor);
if (brush == null) return;
if (!DrawOp.DoDrawOp(drawOp, brush, p, cpos.x, cpos.y, cpos.z, x, y, z))
if (!DrawOp.DoDrawOp(op, brush, p, cpos.x, cpos.y, cpos.z, x, y, z))
return;
if (p.staticCommands)
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);

View File

@ -21,199 +21,96 @@ using MCGalaxy.Drawing.Brushes;
using MCGalaxy.Drawing.Ops;
namespace MCGalaxy.Commands {
public sealed class CmdDraw : Command {
public sealed class CmdDraw : DrawCmd {
public override string name { get { return "draw"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Building; } }
public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.Builder; } }
public override CommandPerm[] AdditionalPerms {
get { return new[] {
new CommandPerm(defaultRank, "The lowest rank that can use cones with /draw", 1),
new CommandPerm(defaultRank, "The lowest rank that can use pyramids with /draw", 2),
new CommandPerm(defaultRank, "The lowest rank that can use spheres with /draw", 3),
new CommandPerm(defaultRank, "The lowest rank that can use volcanos with /draw", 4),
}; }
}
public override void Use(Player p, string message) {
if (p == null) { MessageInGameOnly(p); return; }
if (p.level.permissionbuild > p.group.Permission) {
p.SendMessage("You can not edit this map."); return;
}
string[] parts = message.Split(' ');
Player.BlockchangeEventHandler newHandler = null;
switch (parts[0].ToLower()) {
case "cone":
if (!CheckTwoArgs(p, 1, parts)) return;
newHandler = new Player.BlockchangeEventHandler(BlockchangeCone); break;
case "hcone":
if (!CheckTwoArgs(p, 1, parts)) return;
newHandler = new Player.BlockchangeEventHandler(BlockchangeHCone); break;
case "icone":
if (!CheckTwoArgs(p, 1, parts)) return;
newHandler = new Player.BlockchangeEventHandler(BlockchangeICone); break;
case "hicone":
if (!CheckTwoArgs(p, 1, parts)) return;
newHandler = new Player.BlockchangeEventHandler(BlockchangeHICone); break;
case "pyramid":
if (!CheckTwoArgs(p, 2, parts)) return;
newHandler = new Player.BlockchangeEventHandler(BlockchangePyramid); break;
case "hpyramid":
if (!CheckTwoArgs(p, 2, parts)) return;
newHandler = new Player.BlockchangeEventHandler(BlockchangeHPyramid); break;
case "ipyramid":
if (!CheckTwoArgs(p, 2, parts)) return;
newHandler = new Player.BlockchangeEventHandler(BlockchangeIPyramid); break;
case "hipyramid":
if (!CheckTwoArgs(p, 2, parts)) return;
newHandler = new Player.BlockchangeEventHandler(BlockchangeHIPyramid); break;
case "sphere":
if (!CheckOneArg(p, 3, parts)) return;
newHandler = new Player.BlockchangeEventHandler(BlockchangeSphere); break;
case "hsphere":
if (!CheckOneArg(p, 3, parts)) return;
newHandler = new Player.BlockchangeEventHandler(BlockchangeHSphere); break;
case "volcano":
if (!CheckTwoArgs(p, 4, parts)) return;
newHandler = new Player.BlockchangeEventHandler(BlockchangeVolcano); break;
}
Player.SendMessage(p, "Place a block");
p.ClearBlockchange();
p.Blockchange += newHandler;
protected override string PlaceMessage { get { return "Place a block to determine the origin."; } }
protected override DrawMode ParseMode(string msg) {
if (msg == "cone") return DrawMode.cone;
else if (msg == "hcone") return DrawMode.hcone;
else if (msg == "icone") return DrawMode.icone;
else if (msg == "hicone") return DrawMode.hicone;
else if (msg == "pyramid") return DrawMode.pyramid;
else if (msg == "hpyramid") return DrawMode.hpyramid;
else if (msg == "ipyramid") return DrawMode.ipyramid;
else if (msg == "hipyramid") return DrawMode.hipyramid;
else if (msg == "sphere") return DrawMode.sphere;
else if (msg == "hsphere") return DrawMode.hsphere;
else if (msg == "volcano") return DrawMode.volcano;
return DrawMode.normal;
}
bool CheckTwoArgs(Player p, int addition, string[] parts) {
if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this, addition)) {
Group group = Group.findPermInt(CommandOtherPerms.GetPerm(this, addition));
Player.SendMessage(p, "That commands addition is for " + group.name + "+");
return false;
}
protected override void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z);
CatchPos cpos = (CatchPos)p.blockchangeObject;
GetRealBlock(type, extType, p, ref cpos);
AdvDrawOp op = null;
switch (cpos.mode) {
case DrawMode.cone:
op = new AdvConeDrawOp(); break;
case DrawMode.hcone:
op = new AdvHollowConeDrawOp(); break;
case DrawMode.icone:
op = new AdvConeDrawOp(); op.Invert = true; break;
case DrawMode.hicone:
op = new AdvHollowConeDrawOp(); op.Invert = true; break;
case DrawMode.pyramid:
op = new AdvPyramidDrawOp(); break;
case DrawMode.hpyramid:
op = new AdvHollowPyramidDrawOp(); break;
case DrawMode.ipyramid:
op = new AdvPyramidDrawOp(); op.Invert = true; break;
case DrawMode.hipyramid:
op = new AdvHollowPyramidDrawOp(); op.Invert = true; break;
case DrawMode.sphere:
op = new AdvSphereDrawOp(); op.Invert = true; break;
case DrawMode.hsphere:
op = new AdvHollowSphereDrawOp(); op.Invert = true; break;
case DrawMode.volcano:
op = new AdvVolcanoDrawOp(); break;
default:
Help(p); return;
}
string[] args = cpos.message.Split(' ');
if ((op.UsesHeight && !CheckTwoArgs(p, op, args)) ||
(!op.UsesHeight && !CheckOneArg(p, op, args))) return;
if (parts.Length != 3) { Help(p); return false; }
ushort height, radius;
if (!ushort.TryParse(parts[1], out height) || height > 2000 ||
!ushort.TryParse(parts[2], out radius) || radius > 2000) {
int brushOffset = op.UsesHeight ? 3 : 2;
Brush brush = GetBrush(p, cpos, brushOffset);
if (brush == null) return;
if (!DrawOp.DoDrawOp(op, brush, p, new [] { new Vec3U16(x, y, z) }))
return;
if (p.staticCommands)
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
}
protected override void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) { }
bool CheckTwoArgs(Player p, AdvDrawOp op, string[] parts) {
if (parts.Length < 3) { Help(p); return false; }
if (!ushort.TryParse(parts[parts.Length - 3], out op.Height) || op.Height > 2000 ||
!ushort.TryParse(parts[parts.Length - 2], out op.Radius) || op.Radius > 2000) {
Player.SendMessage(p, "Radius and height must be positive integers less than 2000."); return false;
}
p.BcVar = new int[] { height, radius };
return true;
}
bool CheckOneArg(Player p, int addition, string[] parts) {
if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this, addition)) {
Group group = Group.findPermInt(CommandOtherPerms.GetPerm(this, addition));
Player.SendMessage(p, "That commands addition is for " + group.name + "+");
return false;
}
if (parts.Length != 2) { Help(p); return false; }
ushort radius;
if (!ushort.TryParse(parts[1], out radius) || radius > 2000) {
bool CheckOneArg(Player p, AdvDrawOp op, string[] parts) {
if (parts.Length < 2) { Help(p); return false; }
if (!ushort.TryParse(parts[parts.Length - 2], out op.Radius) || op.Radius > 2000) {
Player.SendMessage(p, "Radius must be a positive integer less than 2000."); return false;
}
p.BcVar = new int[] { 0, radius };
return true;
}
void BlockchangeCone(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z);
Cone(p, x, y, z, p.BcVar[0], p.BcVar[1], type, extType, false);
}
void BlockchangeHCone(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z);
HCone(p, x, y, z, p.BcVar[0], p.BcVar[1], type, extType, false);
}
void BlockchangeICone(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z);
Cone(p, x, y, z, p.BcVar[0], p.BcVar[1], type, extType, true);
}
void BlockchangeHICone(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z);
HCone(p, x, y, z, p.BcVar[0], p.BcVar[1], type, extType, true);
}
void BlockchangePyramid(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z);
Pyramid(p, x, y, z, p.BcVar[0], p.BcVar[1], type, extType, false);
}
void BlockchangeHPyramid(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z);
HPyramid(p, x, y, z, p.BcVar[0], p.BcVar[1], type, extType, false);
}
void BlockchangeIPyramid(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z);
Pyramid(p, x, y, z, p.BcVar[0], p.BcVar[1], type, extType, true);
}
void BlockchangeHIPyramid(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z);
HPyramid(p, x, y, z, p.BcVar[0], p.BcVar[1], type, extType, true);
}
void BlockchangeSphere(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z);
AdvSphereDrawOp op = new AdvSphereDrawOp();
op.Radius = p.BcVar[1];
Brush brush = new SolidBrush(type, extType);
DrawOp.DoDrawOp(op, brush, p, new [] { new Vec3U16(x, y, z) });
}
void BlockchangeHSphere(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z);
AdvHollowSphereDrawOp op = new AdvHollowSphereDrawOp();
op.Radius = p.BcVar[1];
Brush brush = new SolidBrush(type, extType);
DrawOp.DoDrawOp(op, brush, p, new [] { new Vec3U16(x, y, z) });
}
void BlockchangeVolcano(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
RevertAndClearState(p, x, y, z);
AdvVolcanoDrawOp op = new AdvVolcanoDrawOp();
op.Radius = p.BcVar[1]; op.Height = p.BcVar[1];
DrawOp.DoDrawOp(op, null, p, new [] { new Vec3U16(x, y, z) });
}
static void Cone(Player p, ushort x, ushort y, ushort z, int height, int radius, byte type, byte extType, bool invert) {
AdvConeDrawOp op = new AdvConeDrawOp();
op.Radius = radius; op.Height = height; op.Invert = invert;
Brush brush = new SolidBrush(type, extType);
DrawOp.DoDrawOp(op, brush, p, new [] { new Vec3U16(x, y, z) });
}
static void HCone(Player p, ushort x, ushort y, ushort z, int height, int radius, byte type, byte extType, bool invert) {
AdvHollowConeDrawOp op = new AdvHollowConeDrawOp();
op.Radius = radius; op.Height = height; op.Invert = invert;
Brush brush = new SolidBrush(type, extType);
DrawOp.DoDrawOp(op, brush, p, new [] { new Vec3U16(x, y, z) });
}
static void Pyramid(Player p, ushort x, ushort y, ushort z, int height, int radius, byte type, byte extType, bool invert) {
AdvPyramidDrawOp op = new AdvPyramidDrawOp();
op.Radius = radius; op.Height = height; op.Invert = invert;
Brush brush = new SolidBrush(type, extType);
DrawOp.DoDrawOp(op, brush, p, new [] { new Vec3U16(x, y, z) });
}
static void HPyramid(Player p, ushort x, ushort y, ushort z, int height, int radius, byte type, byte extType, bool invert) {
AdvHollowPyramidDrawOp op = new AdvHollowPyramidDrawOp();
op.Radius = radius; op.Height = height; op.Invert = invert;
Brush brush = new SolidBrush(type, extType);
DrawOp.DoDrawOp(op, brush, p, new [] { new Vec3U16(x, y, z) });
}
public override void Help(Player p) {
Player.SendMessage(p, "/draw <shape> <height> <baseradius> - Draw an object in game- " +
Player.SendMessage(p, "/draw <brush args> <height> <baseradius> <mode>- Draw an object in game- " +
"Valid Types cones, spheres, and pyramids, hspheres (hollow sphere), and hpyramids (hollow pyramid)");
}
}

View File

@ -72,15 +72,15 @@ namespace MCGalaxy.Commands {
totalFill = origins.Count;
}
FillDrawOp drawOp = new FillDrawOp();
drawOp.Positions = buffer;
FillDrawOp op = new FillDrawOp();
op.Positions = buffer;
int brushOffset = cpos.mode == DrawMode.normal ? 0 : 1;
Brush brush = GetBrush(p, cpos, brushOffset);
if (brush == null) return;
if (!DrawOp.DoDrawOp(drawOp, brush, p, cpos.x, cpos.y, cpos.z, cpos.x, cpos.y, cpos.z))
if (!DrawOp.DoDrawOp(op, brush, p, cpos.x, cpos.y, cpos.z, cpos.x, cpos.y, cpos.z))
return;
bits.Clear();
drawOp.Positions = null;
op.Positions = null;
if (p.staticCommands)
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);

View File

@ -31,7 +31,7 @@ namespace MCGalaxy.Commands {
RevertAndClearState(p, x, y, z);
CatchPos cpos = (CatchPos)p.blockchangeObject;
GetRealBlock(type, extType, p, ref cpos);
DrawOp drawOp = null;
DrawOp op = null;
int brushOffset = cpos.mode == DrawMode.normal ? 0 : 1;
Brush brush = GetBrush(p, cpos, brushOffset);
if (brush == null) return;
@ -39,14 +39,14 @@ namespace MCGalaxy.Commands {
switch (cpos.mode) {
case DrawMode.solid:
case DrawMode.normal:
drawOp = new EllipsoidDrawOp(); break;
op = new EllipsoidDrawOp(); break;
case DrawMode.hollow:
drawOp = new EllipsoidHollowDrawOp(); break;
op = new EllipsoidHollowDrawOp(); break;
case DrawMode.vertical:
drawOp = new CylinderDrawOp(); break;
op = new CylinderDrawOp(); break;
}
if (!DrawOp.DoDrawOp(drawOp, brush, p, cpos.x, cpos.y, cpos.z, x, y, z))
if (!DrawOp.DoDrawOp(op, brush, p, cpos.x, cpos.y, cpos.z, x, y, z))
return;
if (p.staticCommands)
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);

View File

@ -27,19 +27,16 @@ namespace MCGalaxy.Commands {
public override LevelPermission defaultRank { get { return LevelPermission.Builder; } }
public override void Use(Player p, string message) {
if (p == null) { MessageInGameOnly(p); return; }
message = message.ToLower();
string[] parts = message.Split(' ');
CatchPos cpos = default(CatchPos);
cpos.message = message;
cpos.mode = GetMode(message, parts);
OnUse(p, message, parts, ref cpos);
p.blockchangeObject = cpos;
if (PlaceMessage == null)
Player.SendMessage(p, "Place two blocks to determine the edges.");
else
Player.SendMessage(p, PlaceMessage);
p.blockchangeObject = cpos;
Player.SendMessage(p, PlaceMessage);
p.ClearBlockchange();
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
}
@ -53,7 +50,7 @@ namespace MCGalaxy.Commands {
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange2);
}
protected virtual string PlaceMessage { get { return null; } }
protected virtual string PlaceMessage { get { return "Place two blocks to determine the edges."; } }
protected abstract void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType);

View File

@ -26,12 +26,14 @@ using MCGalaxy.Drawing.Brushes;
namespace MCGalaxy.Drawing.Ops {
public abstract class AdvDrawOp : DrawOp {
public int Radius, Height;
public ushort Radius, Height;
public bool Invert;
public virtual bool UsesHeight { get { return true; } }
}
public class AdvSphereDrawOp : AdvDrawOp {
public override bool UsesHeight { get { return false; } }
public override string Name { get { return "Adv Sphere"; } }
public override long GetBlocksAffected(Level lvl, Vec3U16[] marks) {
@ -56,9 +58,9 @@ namespace MCGalaxy.Drawing.Ops {
}
}
public class AdvHollowSphereDrawOp : DrawOp {
public class AdvHollowSphereDrawOp : AdvDrawOp {
public int Radius;
public override bool UsesHeight { get { return false; } }
public override string Name { get { return "Adv Hollow Sphere"; } }
public override long GetBlocksAffected(Level lvl, Vec3U16[] marks) {