Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 13.13 KB | None | 0 0
  1. if(UpdateChance(GrowCactus) && Cactus.Tile.Conditions(Nactive, NotHalfBrick, NoSlope, NoLiquidOnTile))
  2.             {
  3.                 if (Cactus.Tile.IsOneOf(Sand, Ebonsand, Pearlsand, Crimsand) && !TileLoader.CanGrowModCactus(Cactus.Tile.type))
  4.                 {
  5.                     return;
  6.                 }
  7.                 if (Cactus.Tile.IsOneOf(Sand, Ebonsand, Pearlsand, Crimsand) || TileLoader.CanGrowModCactus(Cactus.Tile.type))
  8.                 {
  9.                     // If the three tiles above are open.
  10.                     if (Cactus.TileAbove.active() || Cactus.TileTLCorner.active() || Cactus.TileTRCorner.active())
  11.                     {
  12.                         return;
  13.                     }
  14.                     // This is to store the count of how tall the cactus is
  15.                     int CactusHeightCounter = 0;
  16.                     int SandCounter = 0;
  17.                     // This searches the amount of cacti and sand in the area.
  18.                     for (int XIndex = Cactus.Location.X - 6; XIndex <= Cactus.Location.X + 6; XIndex++)
  19.                     {
  20.                         for (int YIndex = Cactus.Location.Y - 3; YIndex <= Cactus.Location.Y + 1; YIndex++)
  21.                         {
  22.                             Tile CurrentTile = tile[XIndex, YIndex];
  23.                            
  24.                                 if (CurrentTile.active())
  25.                                 {
  26.                                     if (CurrentTile.type == TileID.Cactus)
  27.                                     {
  28.                                         CactusHeightCounter++;
  29.                                         if (CactusHeightCounter >= MaxCactusHeight)
  30.                                         {
  31.                                             return;
  32.                                         }
  33.                                     }
  34.                                     if (CurrentTile.IsOneOf(Sand, Ebonsand, Pearlsand, Crimsand) || TileLoader.CanGrowModCactus(CurrentTile.type))
  35.                                     {
  36.                                         SandCounter++;
  37.                                     }
  38.                                 }
  39.                             }
  40.                         }
  41.                    
  42.                     if (SandCounter > 10)
  43.                     {
  44.                         Cactus.TileAbove.active(true);
  45.                         Cactus.TileAbove.type = TileID.Cactus;
  46.                         if (netMode == 2)
  47.                         {
  48.                             NetMessage.SendTileSquare(-1, Cactus.Location.X, Cactus.Location.Y - 1, 1, TileChangeType.None);
  49.                         }
  50.                         SquareTileFrame(Cactus.Location.X, Cactus.Location.Y - 1, true);
  51.                         return;
  52.                     }
  53.                     return;
  54.                 }
  55.                 else
  56.                 {
  57.                     if (Cactus.Tile.type != TileID.Cactus)
  58.                     {
  59.                         return;
  60.                     }
  61.  
  62.                     // The purpose of this while loop is to find the base of a cactus if it picked a tile
  63.                     //   that was not the base of the cactus against the ground.
  64.                     //   By the end of the loop buffer X and buffer Y will contain coordinates of the basetile of the cactus.
  65.                     while (Buffer.Tile.active() && Buffer.Tile.type == TileID.Cactus)
  66.                     {
  67.                         // Go down one tile
  68.                         BufferY++;
  69.                         // Until you reach a tile with no cactus.
  70.                         if (!Buffer.Tile.active() || Buffer.Tile.type != TileID.Cactus)
  71.                         {
  72.                             // If cactus tile to the left or corner, move left.
  73.                             if (Buffer.TileLeft.active() && Buffer.TileLeft.type == TileID.Cactus &&
  74.                                 Buffer.TileLLCorner.active() && Buffer.TileLLCorner.Is(TileID.Cactus) &&
  75.                                 BufferX >= Cactus.Location.X)
  76.                             {
  77.                                 BufferX--;
  78.                             }
  79.                             // Same concept but move right.
  80.                             if (Buffer.TileRight.active() && Buffer.TileRight.type == TileID.Cactus &&
  81.                                 Buffer.TileTRCorner.active() && Buffer.TileTRCorner.type == 80 &&
  82.                                 BufferX <= Cactus.Location.X)
  83.                             {
  84.                                 BufferX++;
  85.                             }
  86.                         }
  87.                         // Update struct to contain changed buffers.
  88.                         Buffer = new TileAt(BufferX,BufferY);
  89.                     }
  90.  
  91.                     // Increments the buffer Y position to the base of the cactus.
  92.                     BufferY--;
  93.  
  94.                    // The Y offset of one tile up vs starting tile
  95.        /*was num5 */int YBaseOffset = BufferY - Cactus.Location.Y;
  96.                     // Seems to be the X offset from the base tile.
  97.        /*was num6 */int XBaseOffset = Cactus.Location.X - BufferX;
  98.  
  99.                     // buffers are now changed to the top left of an rectangle encompassing the cactus.
  100.                     BufferX = Cactus.Location.X - XBaseOffset;
  101.                     BufferY = Cactus.Location.Y;
  102.  
  103.                     // Cactii have 11 as the default maximum height.
  104.        /*was num7 */int MaxHeight = MaxCacHeight - YBaseOffset;
  105.                     // Used to basically say how many pieces of cacti tile this cactus have.
  106.                     int CactusCounter = 0;
  107.  
  108.                     // This counts the total amount of tiles of cacti are around for this cactus.
  109.                     for (int XIndex = BufferX - 2; XIndex <= BufferX + 2; XIndex++)
  110.                     {
  111.                         for (int YIndex = BufferY - MaxHeight; YIndex <= BufferY + YBaseOffset; YIndex++)
  112.                         {
  113.                             if (tile[XIndex, YIndex].IsActiveAndType(TileID.Cactus))
  114.                             {
  115.                                 CactusCounter++;
  116.                             }
  117.                         }
  118.                     }
  119.  
  120.  
  121.  
  122.                     // If this cactus is made up of less than 11 to 13 pieces.
  123.                     if (CactusCounter < genRand.Next(11, 13))
  124.                     {
  125.                         // Reset buffers back to updating tile's location.
  126.                         BufferX = Cactus.Location.X;
  127.                         BufferY = Cactus.Location.Y;
  128.                         Buffer = new TileAt(BufferX, BufferY);
  129.  
  130.                         if (XBaseOffset == 0)
  131.                         {
  132.                             if (YBaseOffset == 0)
  133.                             {
  134.                                 // This chain of logic basically occurs when the cactus only had a single tile making up its whole body.
  135.  
  136.                                 //This cancels control of the method if there is a solid tile blocking the way.
  137.                                 if (Main.tile[BufferX, BufferY - 1].active())
  138.                                 {
  139.                                     return;
  140.                                 }
  141.  
  142.                                 // Set and activate Tile and then send the appropriate networking data if running on a server.
  143.                                 Buffer.TileAbove.SetTypeAndActivate(TileID.Cactus);
  144.  
  145.                                 SquareTileFrame(BufferX, BufferY - 1, true);
  146.                                 if (netMode == 2)
  147.                                 {
  148.                                     NetMessage.SendTileSquare(-1, BufferX, BufferY - 1, 1, TileChangeType.None);
  149.                                     return;
  150.                                 }
  151.                                 return;
  152.                             }
  153.                             else
  154.                             {
  155.                                 bool flag = false;
  156.                                 bool flag2 = false;
  157.                                 if (Buffer.TileAbove.IsActiveAndType(TileID.Cactus))
  158.                                 {
  159.                                     if (!Main.tile[BufferX - 1, BufferY].active() && !Main.tile[BufferX - 2, BufferY + 1].active() && !Main.tile[BufferX - 1, BufferY - 1].active() && !Main.tile[BufferX - 1, BufferY + 1].active() && !Main.tile[BufferX - 2, BufferY].active())
  160.                                     {
  161.                                         flag = true;
  162.                                     }
  163.                                     if (!Main.tile[BufferX + 1, BufferY].active() && !Main.tile[BufferX + 2, BufferY + 1].active() && !Main.tile[BufferX + 1, BufferY - 1].active() && !Main.tile[BufferX + 1, BufferY + 1].active() && !Main.tile[BufferX + 2, BufferY].active())
  164.                                     {
  165.                                         flag2 = true;
  166.                                     }
  167.                                 }
  168.                                 int num9 = WorldGen.genRand.Next(3);
  169.                                 if (num9 == 0 && flag)
  170.                                 {
  171.                                     Main.tile[BufferX - 1, BufferY].active(true);
  172.                                     Main.tile[BufferX - 1, BufferY].type = 80;
  173.                                     WorldGen.SquareTileFrame(BufferX - 1, BufferY, true);
  174.                                     if (Main.netMode == 2)
  175.                                     {
  176.                                         NetMessage.SendTileSquare(-1, BufferX - 1, BufferY, 1, TileChangeType.None);
  177.                                         return;
  178.                                     }
  179.                                     return;
  180.                                 }
  181.                                 else if (num9 == 1 && flag2)
  182.                                 {
  183.                                     Main.tile[BufferX + 1, BufferY].active(true);
  184.                                     Main.tile[BufferX + 1, BufferY].type = 80;
  185.                                     WorldGen.SquareTileFrame(BufferX + 1, BufferY, true);
  186.                                     if (Main.netMode == 2)
  187.                                     {
  188.                                         NetMessage.SendTileSquare(-1, BufferX + 1, BufferY, 1, TileChangeType.None);
  189.                                         return;
  190.                                     }
  191.                                     return;
  192.                                 }
  193.                                 else
  194.                                 {
  195.                                     if (num5 >= WorldGen.genRand.Next(2, 8))
  196.                                     {
  197.                                         return;
  198.                                     }
  199.                                     if (Main.tile[BufferX - 1, BufferY - 1].active())
  200.                                     {
  201.                                         ushort arg_6E7_0 = Main.tile[BufferX - 1, BufferY - 1].type;
  202.                                     }
  203.                                     if (Main.tile[BufferX + 1, BufferY - 1].active() && Main.tile[BufferX + 1, BufferY - 1].type == 80)
  204.                                     {
  205.                                         return;
  206.                                     }
  207.                                     if (Main.tile[BufferX, BufferY - 1].active())
  208.                                     {
  209.                                         return;
  210.                                     }
  211.                                     Main.tile[BufferX, BufferY - 1].active(true);
  212.                                     Main.tile[BufferX, BufferY - 1].type = 80;
  213.                                     WorldGen.SquareTileFrame(BufferX, BufferY - 1, true);
  214.                                     if (Main.netMode == 2)
  215.                                     {
  216.                                         NetMessage.SendTileSquare(-1, BufferX, BufferY - 1, 1, TileChangeType.None);
  217.                                         return;
  218.                                     }
  219.                                     return;
  220.                                 }
  221.                             }
  222.                         }
  223.                         else
  224.                         {
  225.                             if (Main.tile[BufferX, BufferY - 1].active() || Main.tile[BufferX, BufferY - 2].active() || Main.tile[BufferX + num6, BufferY - 1].active() || !Main.tile[BufferX - num6, BufferY - 1].active() || Main.tile[BufferX - num6, BufferY - 1].type != 80)
  226.                             {
  227.                                 return;
  228.                             }
  229.                             Main.tile[BufferX, BufferY - 1].active(true);
  230.                             Main.tile[BufferX, BufferY - 1].type = 80;
  231.                             WorldGen.SquareTileFrame(BufferX, BufferY - 1, true);
  232.                             if (Main.netMode == 2)
  233.                             {
  234.                                 NetMessage.SendTileSquare(-1, BufferX, BufferY - 1, 1, TileChangeType.None);
  235.                                 return;
  236.                             }
  237.                             return;
  238.                         }
  239.                     }
  240.                 }
  241.             }
  242.         }
  243.         }
  244.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement