Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Building
- public static void AddTileToCursor(int type, bool isWall = false, bool isBigBrush = false)
- {
- foreach (Point pos in CreateBrush(isBigBrush))
- {
- Create(pos.X, pos.Y, type, isWall);
- }
- }
- public static void DestroyTileFromCursor(bool isWall = false, bool isBigBrush = false)
- {
- foreach (Point pos in CreateBrush(isBigBrush))
- {
- Destroy(pos.X, pos.Y, isWall);
- }
- }
- public static IEnumerable<Point> CreateBrush(bool isBigBrush = false)
- {
- int x = tileTargetX, y = tileTargetY;
- if (isBigBrush)
- {
- for (int y2 = y - 1; y2 < y + 2; y2++)
- {
- for (int x2 = x - 1; x2 < x + 2; x2++)
- {
- yield return new Point(x2, y2);
- }
- }
- }
- else
- {
- yield return new Point(x, y);
- }
- }
- public static void CreateLineTile(Vector2 pos1, Vector2 pos2, int type, bool isWall = false)
- {
- foreach (Point pos in CreateLine(pos1, pos2))
- {
- Create(pos.X, pos.Y, type, isWall);
- }
- }
- public static void DestroyLineTile(Vector2 pos1, Vector2 pos2, bool isWall = false)
- {
- foreach (Point pos in CreateLine(pos1, pos2))
- {
- Destroy(pos.X, pos.Y, isWall);
- }
- }
- private const int MaxLineLength = 100;
- public static IEnumerable<Point> CreateLine(Vector2 pos1, Vector2 pos2)
- {
- float width = Math.Abs(pos1.X - pos2.X);
- float height = Math.Abs(pos1.Y - pos2.Y);
- if (width > height)
- {
- // Horizontal
- int left = (int)Math.Min(pos1.X, pos2.X);
- int right = left + (int)Math.Min(width, MaxLineLength);
- int y = (int)pos1.Y;
- for (int x = left; x <= right; x++)
- {
- yield return new Point(x, y);
- }
- }
- else
- {
- // Vertical
- int top = (int)Math.Min(pos1.Y, pos2.Y);
- int bottom = top + (int)Math.Min(height, MaxLineLength);
- int x = (int)pos1.X;
- for (int y = top; y <= bottom; y++)
- {
- yield return new Point(x, y);
- }
- }
- }
- public static void Create(int x, int y, int type, bool isWall)
- {
- if (isWall)
- {
- CreateWall(x, y, type);
- }
- else
- {
- CreateTile(x, y, type);
- }
- }
- public static void CreateTile(int x, int y, int type)
- {
- if (!Main.tile[x, y].active)
- {
- WorldGen.PlaceTile(x, y, type, false, false, Main.myPlayer);
- if (Main.tile[x, y].type == type && Main.netMode == 1)
- {
- NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", (int)TileCommand.PlaceTile, (float)x, (float)y, type);
- }
- }
- }
- public static void CreateWall(int x, int y, int type)
- {
- if (Main.tile[x, y].wall != type)
- {
- WorldGen.PlaceWall(x, y, type, false);
- if (Main.tile[x, y].wall == type && Main.netMode == 1)
- {
- NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", (int)TileCommand.PlaceWall, (float)x, (float)y, type);
- }
- }
- }
- public static void Destroy(int x, int y, bool isWall)
- {
- if (isWall)
- {
- DestroyWall(x, y);
- }
- else
- {
- DestroyTile(x, y);
- }
- }
- public static void DestroyTile(int x, int y)
- {
- if (Main.tile[x, y].active)
- {
- WorldGen.KillTile(x, y, false, false, true);
- if (Main.netMode == 1)
- {
- NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", (int)TileCommand.KillTileNoItem, (float)x, (float)y, 0f);
- }
- }
- }
- public static void DestroyWall(int x, int y)
- {
- if (Main.tile[x, y].wall > 0)
- {
- WorldGen.KillWall(x, y, false);
- if (Main.netMode == 1)
- {
- NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", (int)TileCommand.KillWall, (float)x, (float)y, 0f);
- }
- }
- }
- #endregion Building
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement