Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.94 KB | None | 0 0
  1.         #region Building
  2.  
  3.         public static void AddTileToCursor(int type, bool isWall = false, bool isBigBrush = false)
  4.         {
  5.             foreach (Point pos in CreateBrush(isBigBrush))
  6.             {
  7.                 Create(pos.X, pos.Y, type, isWall);
  8.             }
  9.         }
  10.  
  11.         public static void DestroyTileFromCursor(bool isWall = false, bool isBigBrush = false)
  12.         {
  13.             foreach (Point pos in CreateBrush(isBigBrush))
  14.             {
  15.                 Destroy(pos.X, pos.Y, isWall);
  16.             }
  17.         }
  18.  
  19.         public static IEnumerable<Point> CreateBrush(bool isBigBrush = false)
  20.         {
  21.             int x = tileTargetX, y = tileTargetY;
  22.  
  23.             if (isBigBrush)
  24.             {
  25.                 for (int y2 = y - 1; y2 < y + 2; y2++)
  26.                 {
  27.                     for (int x2 = x - 1; x2 < x + 2; x2++)
  28.                     {
  29.                         yield return new Point(x2, y2);
  30.                     }
  31.                 }
  32.             }
  33.             else
  34.             {
  35.                 yield return new Point(x, y);
  36.             }
  37.         }
  38.  
  39.         public static void CreateLineTile(Vector2 pos1, Vector2 pos2, int type, bool isWall = false)
  40.         {
  41.             foreach (Point pos in CreateLine(pos1, pos2))
  42.             {
  43.                 Create(pos.X, pos.Y, type, isWall);
  44.             }
  45.         }
  46.  
  47.         public static void DestroyLineTile(Vector2 pos1, Vector2 pos2, bool isWall = false)
  48.         {
  49.             foreach (Point pos in CreateLine(pos1, pos2))
  50.             {
  51.                 Destroy(pos.X, pos.Y, isWall);
  52.             }
  53.         }
  54.  
  55.         private const int MaxLineLength = 100;
  56.  
  57.         public static IEnumerable<Point> CreateLine(Vector2 pos1, Vector2 pos2)
  58.         {
  59.             float width = Math.Abs(pos1.X - pos2.X);
  60.             float height = Math.Abs(pos1.Y - pos2.Y);
  61.  
  62.             if (width > height)
  63.             {
  64.                 // Horizontal
  65.                 int left =  (int)Math.Min(pos1.X, pos2.X);
  66.                 int right = left + (int)Math.Min(width, MaxLineLength);
  67.                 int y = (int)pos1.Y;
  68.  
  69.                 for (int x = left; x <= right; x++)
  70.                 {
  71.                     yield return new Point(x, y);
  72.                 }
  73.             }
  74.             else
  75.             {
  76.                 // Vertical
  77.                 int top =  (int)Math.Min(pos1.Y, pos2.Y);
  78.                 int bottom = top + (int)Math.Min(height, MaxLineLength);
  79.                 int x = (int)pos1.X;
  80.  
  81.                 for (int y = top; y <= bottom; y++)
  82.                 {
  83.                     yield return new Point(x, y);
  84.                 }
  85.             }
  86.         }
  87.  
  88.         public static void Create(int x, int y, int type, bool isWall)
  89.         {
  90.             if (isWall)
  91.             {
  92.                 CreateWall(x, y, type);
  93.             }
  94.             else
  95.             {
  96.                 CreateTile(x, y, type);
  97.             }
  98.         }
  99.  
  100.         public static void CreateTile(int x, int y, int type)
  101.         {
  102.             if (!Main.tile[x, y].active)
  103.             {
  104.                 WorldGen.PlaceTile(x, y, type, false, false, Main.myPlayer);
  105.  
  106.                 if (Main.tile[x, y].type == type && Main.netMode == 1)
  107.                 {
  108.                     NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", (int)TileCommand.PlaceTile, (float)x, (float)y, type);
  109.                 }
  110.             }
  111.         }
  112.  
  113.         public static void CreateWall(int x, int y, int type)
  114.         {
  115.             if (Main.tile[x, y].wall != type)
  116.             {
  117.                 WorldGen.PlaceWall(x, y, type, false);
  118.  
  119.                 if (Main.tile[x, y].wall == type && Main.netMode == 1)
  120.                 {
  121.                     NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", (int)TileCommand.PlaceWall, (float)x, (float)y, type);
  122.                 }
  123.             }
  124.         }
  125.  
  126.         public static void Destroy(int x, int y, bool isWall)
  127.         {
  128.             if (isWall)
  129.             {
  130.                 DestroyWall(x, y);
  131.             }
  132.             else
  133.             {
  134.                 DestroyTile(x, y);
  135.             }
  136.         }
  137.  
  138.         public static void DestroyTile(int x, int y)
  139.         {
  140.             if (Main.tile[x, y].active)
  141.             {
  142.                 WorldGen.KillTile(x, y, false, false, true);
  143.  
  144.                 if (Main.netMode == 1)
  145.                 {
  146.                     NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", (int)TileCommand.KillTileNoItem, (float)x, (float)y, 0f);
  147.                 }
  148.             }
  149.         }
  150.  
  151.         public static void DestroyWall(int x, int y)
  152.         {
  153.             if (Main.tile[x, y].wall > 0)
  154.             {
  155.                 WorldGen.KillWall(x, y, false);
  156.  
  157.                 if (Main.netMode == 1)
  158.                 {
  159.                     NetMessage.SendData((int)PacketTypes.Tile, -1, -1, "", (int)TileCommand.KillWall, (float)x, (float)y, 0f);
  160.                 }
  161.             }
  162.         }
  163.  
  164.         #endregion Building
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement