Cleanup /draw.

This commit is contained in:
UnknownShadow200 2016-01-04 11:50:54 +11:00
parent 3bebd876b5
commit 321ce469e6
3 changed files with 196 additions and 511 deletions

View File

@ -14,7 +14,7 @@
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
*/
using System;
namespace MCGalaxy.Commands
{
@ -27,379 +27,151 @@ namespace MCGalaxy.Commands
public override LevelPermission defaultRank { get { return LevelPermission.Builder; } }
public CmdDraw() { }
public override void Use(Player p, string message)
{
int height;
int radius;
if (p != null)
{
if (p.level.permissionbuild > p.group.Permission)
{
p.SendMessage("You can not edit this map.");
return;
public override void Use(Player p, string message) {
if (p == null) {
Player.SendMessage(p, "This command can only be used in-game!"); return;
}
string[] message2 = message.Split(' ');
#region cones
if (message2[0].ToLower() == "cone")
{
if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this, 1)) { Player.SendMessage(p, "That commands addition is for " + Group.findPermInt(CommandOtherPerms.GetPerm(this, 1)).name + "+"); return; }
if (message2.Length != 3)
goto Help;
try
{
height = Convert.ToUInt16(message2[1].Trim());
radius = Convert.ToUInt16(message2[2].Trim());
p.BcVar = new int[2] { height, radius };
}
catch
{
goto Help;
if (p.level.permissionbuild > p.group.Permission) {
p.SendMessage("You can not edit this map."); return;
}
p.SendMessage("Place a block");
string[] parts = message.Split(' ');
Player.BlockchangeEventHandler newHandler = null;
bool help;
switch (parts[0].ToLower()) {
case "cone":
if (!CheckTwoArgs(p, 1, parts, out help)) { if (help) Help(p); return; }
newHandler = new Player.BlockchangeEventHandler(BlockchangeCone); break;
case "hcone":
if (!CheckTwoArgs(p, 1, parts, out help)) { if (help) Help(p); return; }
newHandler = new Player.BlockchangeEventHandler(BlockchangeHCone); break;
case "icone":
if (!CheckTwoArgs(p, 1, parts, out help)) { if (help) Help(p); return; }
newHandler = new Player.BlockchangeEventHandler(BlockchangeICone); break;
case "hicone":
if (!CheckTwoArgs(p, 1, parts, out help)) { if (help) Help(p); return; }
newHandler = new Player.BlockchangeEventHandler(BlockchangeHICone); break;
case "pyramid":
if (!CheckTwoArgs(p, 2, parts, out help)) { if (help) Help(p); return; }
newHandler = new Player.BlockchangeEventHandler(BlockchangePyramid); break;
case "hpyramid":
if (!CheckTwoArgs(p, 2, parts, out help)) { if (help) Help(p); return; }
newHandler = new Player.BlockchangeEventHandler(BlockchangeHPyramid); break;
case "ipyramid":
if (!CheckTwoArgs(p, 2, parts, out help)) { if (help) Help(p); return; }
newHandler = new Player.BlockchangeEventHandler(BlockchangeIPyramid); break;
case "hipyramid":
if (!CheckTwoArgs(p, 2, parts, out help)) { if (help) Help(p); return; }
newHandler = new Player.BlockchangeEventHandler(BlockchangeHIPyramid); break;
case "sphere":
if (!CheckOneArg(p, 3, parts, out help)) { if (help) Help(p); return; }
newHandler = new Player.BlockchangeEventHandler(BlockchangeSphere); break;
case "hsphere":
if (!CheckOneArg(p, 3, parts, out help)) { if (help) Help(p); return; }
newHandler = new Player.BlockchangeEventHandler(BlockchangeHSphere); break;
case "volcano":
if (!CheckTwoArgs(p, 4, parts, out help)) { if (help) Help(p); return; }
newHandler = new Player.BlockchangeEventHandler(BlockchangeVolcano); break;
}
Player.SendMessage(p, "Place a block");
p.ClearBlockchange();
p.Blockchange += new Player.BlockchangeEventHandler(BlockchangeCone);
return;
}
if (message2[0].ToLower() == "hcone")
{
if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this, 1)) { Player.SendMessage(p, "That commands addition is for " + Group.findPermInt(CommandOtherPerms.GetPerm(this, 1)).name + "+"); return; }
if (message2.Length != 3)
goto Help;
try
{
height = Convert.ToUInt16(message2[1].Trim());
radius = Convert.ToUInt16(message2[2].Trim());
p.BcVar = new int[2] { height, radius };
}
catch
{
goto Help;
p.Blockchange += newHandler;
}
p.SendMessage("Place a block");
p.ClearBlockchange();
p.Blockchange += new Player.BlockchangeEventHandler(BlockchangeHCone);
return;
bool CheckTwoArgs(Player p, int addition, string[] parts, out bool help) {
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 + "+");
help = false; return false;
}
if (message2[0].ToLower() == "icone")
{
if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this, 1)) { Player.SendMessage(p, "That commands addition is for " + Group.findPermInt(CommandOtherPerms.GetPerm(this, 1)).name + "+"); return; }
if (message2.Length != 3)
goto Help;
try
{
height = Convert.ToUInt16(message2[1].Trim());
radius = Convert.ToUInt16(message2[2].Trim());
p.BcVar = new int[2] { height, radius };
}
catch
{
goto Help;
help = true;
if (parts.Length != 3)
return false;
ushort height, radius;
if (!ushort.TryParse(parts[1], out height) || !ushort.TryParse(parts[2], out radius))
return false;
p.BcVar = new int[] { height, radius };
return true;
}
p.SendMessage("Place a block");
p.ClearBlockchange();
p.Blockchange += new Player.BlockchangeEventHandler(BlockchangeICone);
return;
}
if (message2[0].ToLower() == "hicone")
{
if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this, 1)) { Player.SendMessage(p, "That commands addition is for " + Group.findPermInt(CommandOtherPerms.GetPerm(this, 1)).name + "+"); return; }
if (message2.Length != 3)
goto Help;
try
{
height = Convert.ToUInt16(message2[1].Trim());
radius = Convert.ToUInt16(message2[2].Trim());
p.BcVar = new int[2] { height, radius };
}
catch
{
goto Help;
bool CheckOneArg(Player p, int addition, string[] parts, out bool help) {
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 + "+");
help = false; return false;
}
p.SendMessage("Place a block");
p.ClearBlockchange();
p.Blockchange += new Player.BlockchangeEventHandler(BlockchangeHICone);
return;
}
#endregion
#region pyramids
if (message2[0].ToLower() == "pyramid")
{
if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this, 2)) { Player.SendMessage(p, "That commands addition is for " + Group.findPermInt(CommandOtherPerms.GetPerm(this, 2)).name + "+"); return; }
if (message2.Length != 3)
goto Help;
try
{
height = Convert.ToUInt16(message2[1].Trim());
radius = Convert.ToUInt16(message2[2].Trim());
p.BcVar = new int[2] { height, radius };
}
catch
{
goto Help;
help = true;
if (parts.Length != 2)
return false;
ushort radius;
if (!ushort.TryParse(parts[1], out radius))
return false;
p.BcVar = new int[] { 0, radius };
return true;
}
p.SendMessage("Place a block");
p.ClearBlockchange();
p.Blockchange += new Player.BlockchangeEventHandler(BlockchangePyramid);
return;
}
if (message2[0].ToLower() == "hpyramid")
{
if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this, 2)) { Player.SendMessage(p, "That commands addition is for " + Group.findPermInt(CommandOtherPerms.GetPerm(this, 2)).name + "+"); return; }
if (message2.Length != 3)
goto Help;
try
{
height = Convert.ToUInt16(message2[1].Trim());
radius = Convert.ToUInt16(message2[2].Trim());
p.BcVar = new int[2] { height, radius };
}
catch
{
goto Help;
public void BlockchangeCone(Player p, ushort x, ushort y, ushort z, byte type) {
RevertAndClearState(p, x, y, z);
Util.SCOGenerator.Cone(p, x, y, z, p.BcVar[0], p.BcVar[1], type);
}
p.SendMessage("Place a block");
p.ClearBlockchange();
p.Blockchange += new Player.BlockchangeEventHandler(BlockchangeHPyramid);
return;
}
if (message2[0].ToLower() == "ipyramid")
{
if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this, 2)) { Player.SendMessage(p, "That commands addition is for " + Group.findPermInt(CommandOtherPerms.GetPerm(this, 2)).name + "+"); return; }
if (message2.Length != 3)
goto Help;
try
{
height = Convert.ToUInt16(message2[1].Trim());
radius = Convert.ToUInt16(message2[2].Trim());
p.BcVar = new int[2] { height, radius };
}
catch
{
goto Help;
public void BlockchangeHCone(Player p, ushort x, ushort y, ushort z, byte type) {
RevertAndClearState(p, x, y, z);
Util.SCOGenerator.HCone(p, x, y, z, p.BcVar[0], p.BcVar[1], type);
}
p.SendMessage("Place a block");
p.ClearBlockchange();
p.Blockchange += new Player.BlockchangeEventHandler(BlockchangeIPyramid);
return;
}
if (message2[0].ToLower() == "hipyramid")
{
if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this, 2)) { Player.SendMessage(p, "That commands addition is for " + Group.findPermInt(CommandOtherPerms.GetPerm(this, 2)).name + "+"); return; }
if (message2.Length != 3)
goto Help;
try
{
height = Convert.ToUInt16(message2[1].Trim());
radius = Convert.ToUInt16(message2[2].Trim());
p.BcVar = new int[2] { height, radius };
}
catch
{
goto Help;
public void BlockchangeICone(Player p, ushort x, ushort y, ushort z, byte type) {
RevertAndClearState(p, x, y, z);
Util.SCOGenerator.ICone(p, x, y, z, p.BcVar[0], p.BcVar[1], type);
}
p.SendMessage("Place a block");
p.ClearBlockchange();
p.Blockchange += new Player.BlockchangeEventHandler(BlockchangeHIPyramid);
return;
}
#endregion
#region spheres
if (message2[0].ToLower() == "sphere")
{
if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this, 3)) { Player.SendMessage(p, "That commands addition is for " + Group.findPermInt(CommandOtherPerms.GetPerm(this, 3)).name + "+"); return; }
if (message2.Length != 2)
goto Help;
try
{
radius = Convert.ToUInt16(message2[1].Trim());
p.BcVar = new int[2] { 0, radius };
}
catch
{
goto Help;
public void BlockchangeHICone(Player p, ushort x, ushort y, ushort z, byte type) {
RevertAndClearState(p, x, y, z);
Util.SCOGenerator.HICone(p, x, y, z, p.BcVar[0], p.BcVar[1], type);
}
p.SendMessage("Place a block");
p.ClearBlockchange();
p.Blockchange += new Player.BlockchangeEventHandler(BlockchangeSphere);
return;
}
if (message2[0].ToLower() == "hsphere")
{
if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this, 3)) { Player.SendMessage(p, "That commands addition is for " + Group.findPermInt(CommandOtherPerms.GetPerm(this, 3)).name + "+"); return; }
if (message2.Length != 2)
goto Help;
try
{
radius = Convert.ToUInt16(message2[1].Trim());
p.BcVar = new int[2] { 0, radius };
}
catch
{
goto Help;
public void BlockchangePyramid(Player p, ushort x, ushort y, ushort z, byte type) {
RevertAndClearState(p, x, y, z);
Util.SCOGenerator.Pyramid(p, x, y, z, p.BcVar[0], p.BcVar[1], type);
}
p.SendMessage("Place a block");
p.ClearBlockchange();
p.Blockchange += new Player.BlockchangeEventHandler(BlockchangeHSphere);
return;
}
#endregion
#region other
if (message2[0].ToLower() == "volcano")
{
if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this, 4)) { Player.SendMessage(p, "That commands addition is for " + Group.findPermInt(CommandOtherPerms.GetPerm(this, 4)).name + "+"); return; }
if (message2.Length != 3)
goto Help;
try
{
height = Convert.ToUInt16(message2[1].Trim());
radius = Convert.ToUInt16(message2[2].Trim());
p.BcVar = new int[2] { height, radius };
}
catch
{
goto Help;
public void BlockchangeHPyramid(Player p, ushort x, ushort y, ushort z, byte type) {
RevertAndClearState(p, x, y, z);
Util.SCOGenerator.HPyramid(p, x, y, z, p.BcVar[0], p.BcVar[1], type);
}
p.SendMessage("Place a block");
p.ClearBlockchange();
p.Blockchange += new Player.BlockchangeEventHandler(BlockchangeVolcano);
return;
public void BlockchangeIPyramid(Player p, ushort x, ushort y, ushort z, byte type) {
RevertAndClearState(p, x, y, z);
Util.SCOGenerator.IPyramid(p, x, y, z, p.BcVar[0], p.BcVar[1], type);
}
#endregion
Help:
Help(p);
return;
public void BlockchangeHIPyramid(Player p, ushort x, ushort y, ushort z, byte type) {
RevertAndClearState(p, x, y, z);
Util.SCOGenerator.HIPyramid(p, x, y, z, p.BcVar[0], p.BcVar[1], type);
}
public void BlockchangeSphere(Player p, ushort x, ushort y, ushort z, byte type) {
RevertAndClearState(p, x, y, z);
Util.SCOGenerator.Sphere(p, x, y, z, p.BcVar[1], type);
}
Player.SendMessage(p, "This command can only be used in-game!");
public void BlockchangeHSphere(Player p, ushort x, ushort y, ushort z, byte type) {
RevertAndClearState(p, x, y, z);
Util.SCOGenerator.HSphere(p, x, y, z, p.BcVar[1], type);
}
public override void Help(Player p)
{
public void BlockchangeVolcano(Player p, ushort x, ushort y, ushort z, byte type) {
RevertAndClearState(p, x, y, z);
Util.SCOGenerator.Volcano(p, x, y, z, p.BcVar[0], p.BcVar[1]);
}
public override void Help(Player p) {
p.SendMessage("/draw <shape> <height> <baseradius> - Draw an object in game- Valid Types cones, spheres, and pyramids, hspheres (hollow sphere), and hpyramids (hollow pyramid)");
}
#region Cone Blockchanges
public void BlockchangeCone(Player p, ushort x, ushort y, ushort z, byte type)
{
int height = p.BcVar[0];
int radius = p.BcVar[1];
RevertAndClearState(p, x, y, z);
Util.SCOGenerator.Cone(p, x, y, z, height, radius, type);
}
public void BlockchangeHCone(Player p, ushort x, ushort y, ushort z, byte type)
{
int height = p.BcVar[0];
int radius = p.BcVar[1];
RevertAndClearState(p, x, y, z);
Util.SCOGenerator.HCone(p, x, y, z, height, radius, type);
}
public void BlockchangeICone(Player p, ushort x, ushort y, ushort z, byte type)
{
int height = p.BcVar[0];
int radius = p.BcVar[1];
RevertAndClearState(p, x, y, z);
Util.SCOGenerator.ICone(p, x, y, z, height, radius, type);
}
public void BlockchangeHICone(Player p, ushort x, ushort y, ushort z, byte type)
{
int height = p.BcVar[0];
int radius = p.BcVar[1];
RevertAndClearState(p, x, y, z);
Util.SCOGenerator.HICone(p, x, y, z, height, radius, type);
}
#endregion
#region Pyramid Blockchanges
public void BlockchangePyramid(Player p, ushort x, ushort y, ushort z, byte type)
{
int height = p.BcVar[0];
int radius = p.BcVar[1];
RevertAndClearState(p, x, y, z);
Util.SCOGenerator.Pyramid(p, x, y, z, height, radius, type);
}
public void BlockchangeHPyramid(Player p, ushort x, ushort y, ushort z, byte type)
{
int height = p.BcVar[0];
int radius = p.BcVar[1];
RevertAndClearState(p, x, y, z);
Util.SCOGenerator.HPyramid(p, x, y, z, height, radius, type);
}
public void BlockchangeIPyramid(Player p, ushort x, ushort y, ushort z, byte type)
{
int height = p.BcVar[0];
int radius = p.BcVar[1];
RevertAndClearState(p, x, y, z);
Util.SCOGenerator.IPyramid(p, x, y, z, height, radius, type);
}
public void BlockchangeHIPyramid(Player p, ushort x, ushort y, ushort z, byte type)
{
int height = p.BcVar[0];
int radius = p.BcVar[1];
RevertAndClearState(p, x, y, z);
Util.SCOGenerator.HIPyramid(p, x, y, z, height, radius, type);
}
#endregion
#region Sphere Blockchanges
public void BlockchangeSphere(Player p, ushort x, ushort y, ushort z, byte type)
{
int height = p.BcVar[0];
int radius = p.BcVar[1];
RevertAndClearState(p, x, y, z);
Util.SCOGenerator.Sphere(p, x, y, z, radius, type);
}
public void BlockchangeHSphere(Player p, ushort x, ushort y, ushort z, byte type)
{
int height = p.BcVar[0];
int radius = p.BcVar[1];
RevertAndClearState(p, x, y, z);
Util.SCOGenerator.HSphere(p, x, y, z, radius, type);
}
#endregion
#region Special Blockchanges
public void BlockchangeVolcano(Player p, ushort x, ushort y, ushort z, byte type)
{
int height = p.BcVar[0];
int radius = p.BcVar[1];
RevertAndClearState(p, x, y, z);
Util.SCOGenerator.Volcano(p, x, y, z, height, radius);
}
#endregion
}
}

View File

@ -37,18 +37,14 @@ namespace MCGalaxy {
}
public sealed class RainbowBrush : Brush {
readonly Random rnd;
public RainbowBrush() {
rnd = new Random();
}
public RainbowBrush(int seed) {
rnd = new Random(seed);
}
byte curBlock = Block.red;
public override byte NextBlock() {
return (byte)rnd.Next(Block.red, Block.darkgrey);
byte block = curBlock;
curBlock++;
if (curBlock > Block.darkpink)
curBlock = Block.red;
return block;
}
}
@ -64,4 +60,20 @@ namespace MCGalaxy {
return (byte)rnd.Next(1, 11) <= 5 ? block : Block.Zero;
}
}
public sealed class RandomRainbowBrush : Brush {
readonly Random rnd;
public RandomRainbowBrush() {
rnd = new Random();
}
public RandomRainbowBrush(int seed) {
rnd = new Random(seed);
}
public override byte NextBlock() {
return (byte)rnd.Next(Block.red, Block.darkgrey);
}
}
}

View File

@ -211,13 +211,7 @@ namespace MCGalaxy.Util
{
if ((z + m) < 0 || (z + m) > p.level.Length) continue;
int ox = x;
int oy = y;
int oz = z;
int cx = (x + j);
int cy = (y + k);
int cz = (z + m);
int cx = (x + j), cy = (y + k), cz = (z + m);
double currentheight = height - k;
@ -273,13 +267,7 @@ namespace MCGalaxy.Util
{
if ((z + m) < 0 || (z + m) > p.level.Length) continue;
int ox = x;
int oy = y;
int oz = z;
int cx = (x + j);
int cy = (y + k);
int cz = (z + m);
int cx = (x + j), cy = (y + k), cz = (z + m);
double currentheight = height - k;
@ -335,13 +323,7 @@ namespace MCGalaxy.Util
{
if ((z + m) < 0 || (z + m) > p.level.Length) continue;
int ox = x;
int oy = y;
int oz = z;
int cx = (x + j);
int cy = (y + k);
int cz = (z + m);
int cx = (x + j), cy = (y + k), cz = (z + m);
double currentheight = k;
@ -396,13 +378,7 @@ namespace MCGalaxy.Util
{
if ((z + m) < 0 || (z + m) > p.level.Length) continue;
int ox = x;
int oy = y;
int oz = z;
int cx = (x + j);
int cy = (y + k);
int cz = (z + m);
int cx = (x + j), cy = (y + k), cz = (z + m);
double currentheight = k;
@ -457,13 +433,7 @@ namespace MCGalaxy.Util
{
if ((z + m) < 0 || (z + m) > p.level.Length) continue;
int ox = x;
int oy = y;
int oz = z;
int cx = (x + j);
int cy = (y + k);
int cz = (z + m);
int cx = (x + j), cy = (y + k), cz = (z + m);
double currentheight = height - k;
@ -515,13 +485,7 @@ namespace MCGalaxy.Util
{
if ((z + m) < 0 || (z + m) > p.level.Length) continue;
int ox = x;
int oy = y;
int oz = z;
int cx = (x + j);
int cy = (y + k);
int cz = (z + m);
int cx = (x + j), cy = (y + k), cz = (z + m);
double currentheight = height - k;
@ -573,13 +537,7 @@ namespace MCGalaxy.Util
{
if ((z + m) < 0 || (z + m) > p.level.Length) continue;
int ox = x;
int oy = y;
int oz = z;
int cx = (x + j);
int cy = (y + k);
int cz = (z + m);
int cx = (x + j), cy = (y + k), cz = (z + m);
double currentheight = k;
@ -631,13 +589,7 @@ namespace MCGalaxy.Util
{
if ((z + m) < 0 || (z + m) > p.level.Length) continue;
int ox = x;
int oy = y;
int oz = z;
int cx = (x + j);
int cy = (y + k);
int cz = (z + m);
int cx = (x + j), cy = (y + k), cz = (z + m);
double currentheight = k;
@ -781,13 +733,7 @@ namespace MCGalaxy.Util
{
if ((z + m) < 0 || (z + m) > p.level.Length) continue;
int ox = x;
int oy = y;
int oz = z;
int cx = (x + j);
int cy = (y + k);
int cz = (z + m);
int cx = (x + j), cy = (y + k), cz = (z + m);
double currentheight = height - k;
@ -840,51 +786,6 @@ namespace MCGalaxy.Util
buffer = null;
}
#region Stuff that's not used in MCGalaxy (at least not yet)
//public void ToAirMethod(List<string> toair)
//{
// if (toair.Count >= 1)
// {
// foreach (string s in toair)
// {
// try
// {
// string[] k = s.Split('^');
// Level l = Level.Find(k[0]);
// ushort x = Convert.ToUInt16(k[1]);
// ushort y = Convert.ToUInt16(k[2]);
// ushort z = Convert.ToUInt16(k[3]);
// l.Blockchange(x, y, z, 0);
// }
// catch { }
// }
// }
//}
//public void TNTthreader() //We may leave this because i cant think of an efficient way to do this.
//{
// while (true)
// {
// try
// {
// foreach (string t in TNTCHAIN.ToArray())
// {
// TNTCHAIN.Remove(t); //do first so if it fails its not there anymore :D
// string[] t2 = t.Split('^');
// Level l = Level.Find(t2[0]);
// ushort x = Convert.ToUInt16(t2[1]);
// ushort y = Convert.ToUInt16(t2[2]);
// ushort z = Convert.ToUInt16(t2[3]);
// TNT(l, x, y, z);
// }
// }
// catch { }
// Thread.Sleep(100);
// }
//}
#endregion
#region utilities
static private double sqrt(double x)
{