ReplaceAll should only count blocks actually being replaced, since otherwise it's useless for majority of maps. (Thanks dzidq)

This commit is contained in:
UnknownShadow200 2017-07-24 21:45:14 +10:00
parent 0b4387fbe4
commit 2b5f0406af
23 changed files with 117 additions and 69 deletions

View File

@ -76,7 +76,7 @@ namespace MCGalaxy.Gui {
rank_cbAfk.Checked = grp.AfkKicked;
rank_numAfk.Value = grp.AfkKickMinutes;
rank_numDraw.Value = grp.MaxBlocks;
rank_numDraw.Value = grp.DrawLimit;
rank_numUndo.Value = grp.MaxUndo;
rank_numMaps.Value = grp.OverseerMaps;
rank_numGen.Value = grp.GenVolume;
@ -124,7 +124,7 @@ namespace MCGalaxy.Gui {
void rank_numDraw_ValueChanged(object sender, EventArgs e) {
copiedGroups[rank_list.SelectedIndex].MaxBlocks = (int)rank_numDraw.Value;
copiedGroups[rank_list.SelectedIndex].DrawLimit = (int)rank_numDraw.Value;
}
void rank_numUndo_ValueChanged(object sender, EventArgs e) {

View File

@ -69,7 +69,7 @@ namespace MCGalaxy.Commands.Info {
if (grp.Permission >= LevelPermission.Nobody) continue; // Note that -1 means max undo. Undo anything and everything.
int count = grp.Players.Count;
Player.Message(p, "{0} %S- Cmd: {2}, Undo: {3}, Perm: {4}",
grp.ColoredName, count, grp.MaxBlocks,
grp.ColoredName, count, grp.DrawLimit,
grp.MaxUndo == -1 ? "max" : grp.MaxUndo.ToString(), (int)grp.Permission);
}
}

View File

@ -61,7 +61,7 @@ namespace MCGalaxy.Commands.Maintenance {
case "dl":
case "drawlimit":
Chat.MessageGlobal("{0}%S's draw limit set to &b{1}", grp.ColoredName, limit);
grp.MaxBlocks = limit; break;
grp.DrawLimit = limit; break;
case "mu":
case "maxundo":
Chat.MessageGlobal("{0}%S's undo limit set to &b{1}", grp.ColoredName, limit);

View File

@ -119,9 +119,9 @@ namespace MCGalaxy.Commands.Building {
index++;
}
if (cState.UsedBlocks > p.group.MaxBlocks) {
if (cState.UsedBlocks > p.group.DrawLimit) {
Player.Message(p, "You tried to copy {0} blocks. You cannot copy more than {1} blocks.",
cState.UsedBlocks, p.group.MaxBlocks);
cState.UsedBlocks, p.group.DrawLimit);
cState.Clear(); cState = null;
return false;
}

View File

@ -39,9 +39,9 @@ namespace MCGalaxy.Commands.Building {
block = p.level.GetBlock(x, y, z);
int dist = (ushort)state, numBlocks = (3 * 3) * dist;
if (numBlocks > p.group.MaxBlocks) {
if (numBlocks > p.group.DrawLimit) {
Player.Message(p, "You tried to drill " + numBlocks + " blocks.");
Player.Message(p, "You cannot drill more than " + p.group.MaxBlocks + ".");
Player.Message(p, "You cannot drill more than " + p.group.DrawLimit + ".");
return false;
}

View File

@ -65,7 +65,7 @@ namespace MCGalaxy.Commands.Building {
int count = op.Positions.Count;
bool confirmed = IsConfirmed(dArgs.Message), success = true;
if (count < p.group.MaxBlocks && count > p.level.ReloadThreshold && !confirmed) {
if (count < p.group.DrawLimit && count > p.level.ReloadThreshold && !confirmed) {
Player.Message(p, "This fill would affect {0} blocks.", count);
Player.Message(p, "If you still want to fill, type %T/fill {0} confirm", dArgs.Message);
} else {

View File

@ -0,0 +1,81 @@
/*
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
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;
using MCGalaxy.Drawing.Brushes;
using MCGalaxy.Drawing.Ops;
using MCGalaxy.Maths;
namespace MCGalaxy.Commands.Building {
public sealed class CmdReplaceAll : Command {
public override string name { get { return "replaceall"; } }
public override string shortcut { get { return "ra"; } }
public override string type { get { return CommandTypes.Building; } }
public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
public override void Use(Player p, string message) {
BrushArgs args = new BrushArgs(p, message.ToLower(), ExtBlock.Air);
Brush brush = BrushFactory.Find("replace").Construct(args);
if (brush == null) return;
Vec3S32 max = new Vec3S32(p.level.Width - 1, p.level.Height - 1, p.level.Length - 1);
Vec3S32[] marks = new Vec3S32[] { Vec3S32.Zero, max };
MeasureDrawOp measure = new MeasureDrawOp();
DrawOpPerformer.Setup(measure, p, marks);
measure.Perform(marks, brush, null);
if (measure.Total > p.group.DrawLimit) {
Player.Message(p, "You tried to replace " + measure.Total + " blocks.");
Player.Message(p, "You cannot draw more than " + p.group.DrawLimit + ".");
return;
}
DrawOp op = new CuboidDrawOp();
op.AffectedByTransform = false;
if (!DrawOpPerformer.Do(op, brush, p, marks, false)) return;
Player.Message(p, "&4/replaceall finished!");
}
class MeasureDrawOp : DrawOp {
public override string Name { get { return null; } }
public override long BlocksAffected(Level lvl, Vec3S32[] marks) { return 0; }
public int Total = 0;
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
for (ushort y = p1.Y; y <= p2.Y; y++)
for (ushort z = p1.Z; z <= p2.Z; z++)
for (ushort x = p1.X; x <= p2.X; x++)
{
Coords.X = x; Coords.Y = y; Coords.Z = z;
if (!brush.NextBlock(this).IsInvalid) Total++;
}
}
}
public override void Help(Player p) {
Player.Message(p, "%T/replaceall [block] [block2].. [new]");
Player.Message(p, "%HReplaces [block] with [new] for the entire map.");
Player.Message(p, "%H If more than one [block] is given, they are all replaced.");
Player.Message(p, "%H If only [block] is given, replaces with your held block.");
}
}
}

View File

@ -55,34 +55,4 @@ namespace MCGalaxy.Commands.Building {
Player.Message(p, "%H If only [block] is given, replaces with your held block.");
}
}
public sealed class CmdReplaceAll : Command {
public override string name { get { return "replaceall"; } }
public override string shortcut { get { return "ra"; } }
public override string type { get { return CommandTypes.Building; } }
public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
public override void Use(Player p, string message) {
ushort x2 = (ushort)(p.level.Width - 1);
ushort y2 = (ushort)(p.level.Height - 1);
ushort z2 = (ushort)(p.level.Length - 1);
BrushArgs args = new BrushArgs(p, message.ToLower(), ExtBlock.Air);
Brush brush = BrushFactory.Find("replace").Construct(args);
if (brush == null) return;
DrawOp op = new CuboidDrawOp();
if (!DrawOpPerformer.Do(op, brush, p, 0, 0, 0, x2, y2, z2))
return;
Player.Message(p, "&4/replaceall finished!");
}
public override void Help(Player p) {
Player.Message(p, "%T/replaceall [block] [block2].. [new]");
Player.Message(p, "%HReplaces [block] with [new] for the entire map.");
Player.Message(p, "%H If more than one [block] is given, they are all replaced.");
Player.Message(p, "%H If only [block] is given, replaces with your held block.");
}
}
}

View File

@ -22,7 +22,7 @@ using MCGalaxy.Maths;
namespace MCGalaxy.Drawing.Ops {
public class CuboidDrawOp : DrawOp {
public class CuboidDrawOp : DrawOp {
public override string Name { get { return "Cuboid"; } }
public override long BlocksAffected(Level lvl, Vec3S32[] marks) {

View File

@ -74,7 +74,7 @@ namespace MCGalaxy.Drawing.Ops {
public abstract string Name { get; }
/// <summary> Whether the output blocks this draw operation are affected by the player's current Transform. </summary>
public virtual bool AffectedByTransform { get { return true; } }
public bool AffectedByTransform = true;
/// <summary> Estimates the total number of blocks that the drawing commands affects. <br/>
/// Note that this estimate assumes that all possibly affected blocks will be changed by the drawing command. </summary>
@ -83,9 +83,9 @@ namespace MCGalaxy.Drawing.Ops {
public abstract void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output);
public virtual bool CanDraw(Vec3S32[] marks, Player p, long affected) {
if (p != null && affected > p.group.MaxBlocks) {
if (p != null && affected > p.group.DrawLimit) {
Player.Message(p, "You tried to draw " + affected + " blocks.");
Player.Message(p, "You cannot draw more than " + p.group.MaxBlocks + ".");
Player.Message(p, "You cannot draw more than " + p.group.DrawLimit + ".");
return false;
}
return true;

View File

@ -37,12 +37,6 @@ namespace MCGalaxy.Drawing.Ops {
public static class DrawOpPerformer {
public static bool Do(DrawOp op, Brush brush, Player p,
ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2) {
Vec3S32[] marks = new Vec3S32[] { new Vec3S32(x1, y1, z1), new Vec3S32(x2, y2, z2) };
return Do(op, brush, p, marks);
}
public static Level Setup(DrawOp op, Player p, Vec3S32[] marks) {
op.SetMarks(marks);
Level lvl = p == null ? null : p.level;

View File

@ -31,19 +31,19 @@ namespace MCGalaxy.Drawing.Ops {
public FillDrawOp() {
Flags = BlockDBFlags.Filled;
AffectedByTransform = false;
}
public override string Name { get { return "Fill"; } }
public override bool AffectedByTransform { get { return false; } }
public override long BlocksAffected(Level lvl, Vec3S32[] marks) {
return Positions.Count;
}
public override bool CanDraw(Vec3S32[] marks, Player p, long affected) {
if (affected > p.group.MaxBlocks) {
if (affected > p.group.DrawLimit) {
Player.Message(p, "You rank can only fill up to {0} blocks. " +
"This fill would affect more than {0} blocks.", p.group.MaxBlocks);
"This fill would affect more than {0} blocks.", p.group.DrawLimit);
return false;
}
return true;
@ -70,7 +70,7 @@ namespace MCGalaxy.Drawing.Ops {
int* pos = stackalloc int[max];
pos[0] = index; count++;
while (count > 0 && buffer.Count <= p.group.MaxBlocks) {
while (count > 0 && buffer.Count <= p.group.DrawLimit) {
index = pos[count - 1]; count--;
ushort x = (ushort)(index % lvl.Width);
ushort y = (ushort)((index / lvl.Width) / lvl.Length);

View File

@ -27,7 +27,6 @@ namespace MCGalaxy.Drawing.Ops {
public class HighlightDrawOp : DrawOp {
public override string Name { get { return "Highlight"; } }
public override bool AffectedByTransform { get { return false; } }
/// <summary> Point in time that the /highlight should go backwards up to. </summary>
public DateTime Start = DateTime.MinValue;
@ -46,6 +45,7 @@ namespace MCGalaxy.Drawing.Ops {
public HighlightDrawOp() {
Flags = 0;
Undoable = false;
AffectedByTransform = false;
}
public override long BlocksAffected(Level lvl, Vec3S32[] marks) { return -1; }

View File

@ -25,7 +25,6 @@ namespace MCGalaxy.Drawing.Ops {
public class RedoSelfDrawOp : DrawOp {
public override string Name { get { return "RedoSelf"; } }
public override bool AffectedByTransform { get { return false; } }
/// <summary> Point in time that the /undo should go backwards up to. </summary>
public DateTime Start = DateTime.MinValue;
@ -35,6 +34,7 @@ namespace MCGalaxy.Drawing.Ops {
public RedoSelfDrawOp() {
Flags = BlockDBFlags.RedoSelf;
AffectedByTransform = false;
}
public override long BlocksAffected(Level lvl, Vec3S32[] marks) { return -1; }

View File

@ -30,10 +30,10 @@ namespace MCGalaxy.Drawing.Ops {
public ReplaceDrawOp(ExtBlock include) {
Include = include;
Flags = BlockDBFlags.Replaced;
AffectedByTransform = false;
}
public override string Name { get { return "Replace"; } }
public override bool AffectedByTransform { get { return false; } }
public override long BlocksAffected(Level lvl, Vec3S32[] marks) {
return (Max.X - Min.X + 1) * (Max.Y - Min.Y + 1) * (Max.Z - Min.Z + 1);
@ -58,10 +58,10 @@ namespace MCGalaxy.Drawing.Ops {
public ReplaceNotDrawOp(ExtBlock exclude) {
Exclude = exclude;
Flags = BlockDBFlags.Replaced;
AffectedByTransform = false;
}
public override string Name { get { return "ReplaceNot"; } }
public override bool AffectedByTransform { get { return false; } }
public override long BlocksAffected(Level lvl, Vec3S32[] marks) {
return (Max.X - Min.X + 1) * (Max.Y - Min.Y + 1) * (Max.Z - Min.Z + 1);

View File

@ -24,7 +24,6 @@ namespace MCGalaxy.Drawing.Ops {
public class RestoreSelectionDrawOp : DrawOp {
public override string Name { get { return "RestoreSelection"; } }
public override bool AffectedByTransform { get { return false; } }
public override long BlocksAffected(Level lvl, Vec3S32[] marks) {
return (Max.X - Min.X + 1) * (Max.Y - Min.Y + 1) * (Max.Z - Min.Z + 1);
@ -32,6 +31,7 @@ namespace MCGalaxy.Drawing.Ops {
public RestoreSelectionDrawOp() {
Flags = BlockDBFlags.Restored;
AffectedByTransform = false;
}
public Level Source;

View File

@ -36,7 +36,6 @@ namespace MCGalaxy.Drawing.Ops {
public class UndoDrawOp : DrawOp {
public override string Name { get { return "Undo"; } }
public override bool AffectedByTransform { get { return false; } }
/// <summary> Point in time that the /undo should go backwards up to. </summary>
public DateTime Start = DateTime.MinValue;
@ -50,6 +49,7 @@ namespace MCGalaxy.Drawing.Ops {
public UndoDrawOp() {
Flags = BlockDBFlags.UndoOther;
AffectedByTransform = false;
}
public override long BlocksAffected(Level lvl, Vec3S32[] marks) { return -1; }

View File

@ -23,10 +23,12 @@ using MCGalaxy.Maths;
namespace MCGalaxy.Drawing.Ops {
public class UndoPhysicsDrawOp : DrawOp {
public override string Name { get { return "UndoPhysics"; } }
public override bool AffectedByTransform { get { return false; } }
public override string Name { get { return "UndoPhysics"; } }
internal DateTime Start;
public UndoPhysicsDrawOp() {
AffectedByTransform = false;
}
public override long BlocksAffected(Level lvl, Vec3S32[] marks) { return -1; }

View File

@ -153,6 +153,7 @@
<Compile Include="Commands\building\CmdPyramid.cs" />
<Compile Include="Commands\building\CmdRainbow.cs" />
<Compile Include="Commands\building\CmdRedo.cs" />
<Compile Include="Commands\building\CmdReplaceAll.cs" />
<Compile Include="Commands\building\CmdReplaceBrush.cs" />
<Compile Include="Commands\building\CmdSphere.cs" />
<Compile Include="Commands\building\CmdTransform.cs" />

View File

@ -43,7 +43,7 @@ namespace MCGalaxy {
public LevelPermission Permission = LevelPermission.Null;
/// <summary> Maximum number of blocks members of this group can use in draw commands. </summary>
public int MaxBlocks;
public int DrawLimit;
/// <summary> Maximum number of seconds members of this group can /undo up to. </summary>
public int MaxUndo;
@ -81,7 +81,7 @@ namespace MCGalaxy {
private Group(LevelPermission perm, int maxB, int maxUn, string name, char colCode) {
Permission = perm;
MaxBlocks = maxB;
DrawLimit = maxB;
MaxUndo = maxUn;
Name = name;
Color = "&" + colCode;
@ -115,7 +115,7 @@ namespace MCGalaxy {
public Group CopyConfig() {
Group copy = new Group();
copy.Name = Name; copy.Color = Color; copy.Permission = Permission;
copy.MaxBlocks = MaxBlocks; copy.MaxUndo = MaxUndo; copy.MOTD = MOTD;
copy.DrawLimit = DrawLimit; copy.MaxUndo = MaxUndo; copy.MOTD = MOTD;
copy.GenVolume = GenVolume; copy.OverseerMaps = OverseerMaps;
copy.AfkKicked = AfkKicked; copy.AfkKickMinutes = AfkKickMinutes;
copy.Prefix = Prefix; copy.filename = filename;

View File

@ -68,7 +68,7 @@ namespace MCGalaxy {
} break;
case "limit":
temp.MaxBlocks = int.Parse(value);
temp.DrawLimit = int.Parse(value);
break;
case "maxundo":
temp.MaxUndo = int.Parse(value);
@ -173,7 +173,7 @@ namespace MCGalaxy {
foreach (Group grp in givenList) {
w.WriteLine("RankName = " + grp.Name);
w.WriteLine("Permission = " + (int)grp.Permission);
w.WriteLine("Limit = " + grp.MaxBlocks);
w.WriteLine("Limit = " + grp.DrawLimit);
w.WriteLine("MaxUndo = " + grp.MaxUndo);
w.WriteLine("Color = " + grp.Color[1]);
w.WriteLine("MOTD = " + grp.MOTD);

View File

@ -598,7 +598,6 @@ namespace MCGalaxy {
public void HandleCommand(string cmd, string message) {
cmd = cmd.ToLower();
try {
if (!CheckCommand(cmd)) return;
Command command = GetCommand(ref cmd, ref message);
if (command == null) return;
@ -620,7 +619,6 @@ namespace MCGalaxy {
string cmd = parts[0].ToLower();
string message = parts.Length > 1 ? parts[1] : "";
if (!CheckCommand(cmd)) return;
Command command = GetCommand(ref cmd, ref message);
if (command == null) return;
@ -658,6 +656,7 @@ namespace MCGalaxy {
}
Command GetCommand(ref string cmd, ref string cmdArgs) {
if (!CheckCommand(cmd)) return null;
Command.Search(ref cmd, ref cmdArgs);
byte bindIndex;

View File

@ -92,6 +92,7 @@ namespace MCGalaxy.Maths {
public struct Vec3S32 : IEquatable<Vec3S32> {
public int X, Y, Z;
public static Vec3S32 Zero = new Vec3S32(0);
public Vec3S32(int x, int y, int z) {
X = x; Y = y; Z = z;