public void Draw(Bitmap img)
{
//guess how big the draw will be
int white = System.Drawing.Color.White.ToArgb();
int left, right, top, bottom;
int count = Crop(img, out left, out right, out top, out bottom);
//check if player can make the drawing
if (!player.CanDraw(count))
{
player.Message(String.Format("You are only allowed to run commands that affect up to {0} blocks. " +
"This one would affect {1} blocks.",
player.Info.Rank.DrawLimit, count));
return;
}
int dirX = 0, dirY = 0;
if (direction == Direction.PlusX)
{
dirX = 1;
}
if (direction == Direction.MinusX)
{
dirX = -1;
}
if (direction == Direction.PlusZ)
{
dirY = 1;
}
if (direction == Direction.MinusZ)
{
dirY = -1;
}
if (dirX == 0 && dirY == 0)
{
return; //if blockcount = 0, message is shown and returned
}
for (int yy = top; yy <= bottom; yy++)
{
for (int xx = left; xx <= right; xx++)
{
if (img.GetPixel(xx, yy).ToArgb() == white)
{
continue;
}
int dx = xx - left, dy = bottom - yy;
Vector3I coords = new Vector3I(origin.X + dirX * dx, origin.Y + dirY * dx, origin.Z + dy);
BuildingCommands.DrawOneBlock(
player, player.World.Map, blockColor,
coords, BlockChangeContext.Drawn,
ref blocks, ref blocksDenied, undoState);
blockCount++;
}
}
}