nactive() public method

public nactive ( ) : bool
return bool
        public void Update()
        {
            Main.tileSolid[379] = true;
            Tile tile  = Main.tile[x - 1, y];
            Tile tile2 = Main.tile[x + 1, y];
            Tile tile3 = Main.tile[x, y - 1];
            Tile tile4 = Main.tile[x, y + 1];
            Tile tile5 = Main.tile[x, y];

            if (tile5.nactive() && Main.tileSolid[tile5.type] && !Main.tileSolidTop[tile5.type])
            {
                ushort type = tile5.type;
                int    num5 = 10;
                kill = 9;
                return;
            }
            byte  liquid = tile5.liquid;
            float num    = 0f;

            if (y > Main.maxTilesY - 200 && tile5.liquidType() == 0 && tile5.liquid > 0)
            {
                byte b = 2;
                if (tile5.liquid < b)
                {
                    b = tile5.liquid;
                }
                tile5.liquid -= b;
            }
            if (tile5.liquid == 0)
            {
                kill = 9;
                return;
            }
            if (tile5.lava())
            {
                LavaCheck(x, y);
                if (!quickFall)
                {
                    if (delay < 5)
                    {
                        delay++;
                        return;
                    }
                    delay = 0;
                }
            }
            else
            {
                if (tile.lava())
                {
                    AddWater(x - 1, y);
                }
                if (tile2.lava())
                {
                    AddWater(x + 1, y);
                }
                if (tile3.lava())
                {
                    AddWater(x, y - 1);
                }
                if (tile4.lava())
                {
                    AddWater(x, y + 1);
                }
                if (tile5.honey())
                {
                    HoneyCheck(x, y);
                    if (!quickFall)
                    {
                        if (delay < 10)
                        {
                            delay++;
                            return;
                        }
                        delay = 0;
                    }
                }
                else
                {
                    if (tile.honey())
                    {
                        AddWater(x - 1, y);
                    }
                    if (tile2.honey())
                    {
                        AddWater(x + 1, y);
                    }
                    if (tile3.honey())
                    {
                        AddWater(x, y - 1);
                    }
                    if (tile4.honey())
                    {
                        AddWater(x, y + 1);
                    }
                }
            }
            if ((!tile4.nactive() || !Main.tileSolid[tile4.type] || Main.tileSolidTop[tile4.type]) && (tile4.liquid <= 0 || tile4.liquidType() == tile5.liquidType()) && tile4.liquid < byte.MaxValue)
            {
                num = 255 - tile4.liquid;
                if (num > (float)(int)tile5.liquid)
                {
                    num = (int)tile5.liquid;
                }
                tile5.liquid -= (byte)num;
                tile4.liquid += (byte)num;
                tile4.liquidType(tile5.liquidType());
                AddWater(x, y + 1);
                tile4.skipLiquid(true);
                tile5.skipLiquid(true);
                if (tile5.liquid > 250)
                {
                    tile5.liquid = byte.MaxValue;
                }
                else
                {
                    AddWater(x - 1, y);
                    AddWater(x + 1, y);
                }
            }
            if (tile5.liquid > 0)
            {
                bool flag  = true;
                bool flag2 = true;
                bool flag3 = true;
                bool flag4 = true;
                if (tile.nactive() && Main.tileSolid[tile.type] && !Main.tileSolidTop[tile.type])
                {
                    flag = false;
                }
                else if (tile.liquid > 0 && tile.liquidType() != tile5.liquidType())
                {
                    flag = false;
                }
                else if (Main.tile[x - 2, y].nactive() && Main.tileSolid[Main.tile[x - 2, y].type] && !Main.tileSolidTop[Main.tile[x - 2, y].type])
                {
                    flag3 = false;
                }
                else if (Main.tile[x - 2, y].liquid == 0)
                {
                    flag3 = false;
                }
                else if (Main.tile[x - 2, y].liquid > 0 && Main.tile[x - 2, y].liquidType() != tile5.liquidType())
                {
                    flag3 = false;
                }
                if (tile2.nactive() && Main.tileSolid[tile2.type] && !Main.tileSolidTop[tile2.type])
                {
                    flag2 = false;
                }
                else if (tile2.liquid > 0 && tile2.liquidType() != tile5.liquidType())
                {
                    flag2 = false;
                }
                else if (Main.tile[x + 2, y].nactive() && Main.tileSolid[Main.tile[x + 2, y].type] && !Main.tileSolidTop[Main.tile[x + 2, y].type])
                {
                    flag4 = false;
                }
                else if (Main.tile[x + 2, y].liquid == 0)
                {
                    flag4 = false;
                }
                else if (Main.tile[x + 2, y].liquid > 0 && Main.tile[x + 2, y].liquidType() != tile5.liquidType())
                {
                    flag4 = false;
                }
                int num2 = 0;
                if (tile5.liquid < 3)
                {
                    num2 = -1;
                }
                if (flag && flag2)
                {
                    if (flag3 && flag4)
                    {
                        bool flag5 = true;
                        bool flag6 = true;
                        if (Main.tile[x - 3, y].nactive() && Main.tileSolid[Main.tile[x - 3, y].type] && !Main.tileSolidTop[Main.tile[x - 3, y].type])
                        {
                            flag5 = false;
                        }
                        else if (Main.tile[x - 3, y].liquid == 0)
                        {
                            flag5 = false;
                        }
                        else if (Main.tile[x - 3, y].liquidType() != tile5.liquidType())
                        {
                            flag5 = false;
                        }
                        if (Main.tile[x + 3, y].nactive() && Main.tileSolid[Main.tile[x + 3, y].type] && !Main.tileSolidTop[Main.tile[x + 3, y].type])
                        {
                            flag6 = false;
                        }
                        else if (Main.tile[x + 3, y].liquid == 0)
                        {
                            flag6 = false;
                        }
                        else if (Main.tile[x + 3, y].liquidType() != tile5.liquidType())
                        {
                            flag6 = false;
                        }
                        if (flag5 && flag6)
                        {
                            num = tile.liquid + tile2.liquid + Main.tile[x - 2, y].liquid + Main.tile[x + 2, y].liquid + Main.tile[x - 3, y].liquid + Main.tile[x + 3, y].liquid + tile5.liquid + num2;
                            num = (float)Math.Round(num / 7f);
                            int num3 = 0;
                            tile.liquidType(tile5.liquidType());
                            if (tile.liquid != (byte)num)
                            {
                                tile.liquid = (byte)num;
                                AddWater(x - 1, y);
                            }
                            else
                            {
                                num3++;
                            }
                            tile2.liquidType(tile5.liquidType());
                            if (tile2.liquid != (byte)num)
                            {
                                tile2.liquid = (byte)num;
                                AddWater(x + 1, y);
                            }
                            else
                            {
                                num3++;
                            }
                            Main.tile[x - 2, y].liquidType(tile5.liquidType());
                            if (Main.tile[x - 2, y].liquid != (byte)num)
                            {
                                Main.tile[x - 2, y].liquid = (byte)num;
                                AddWater(x - 2, y);
                            }
                            else
                            {
                                num3++;
                            }
                            Main.tile[x + 2, y].liquidType(tile5.liquidType());
                            if (Main.tile[x + 2, y].liquid != (byte)num)
                            {
                                Main.tile[x + 2, y].liquid = (byte)num;
                                AddWater(x + 2, y);
                            }
                            else
                            {
                                num3++;
                            }
                            Main.tile[x - 3, y].liquidType(tile5.liquidType());
                            if (Main.tile[x - 3, y].liquid != (byte)num)
                            {
                                Main.tile[x - 3, y].liquid = (byte)num;
                                AddWater(x - 3, y);
                            }
                            else
                            {
                                num3++;
                            }
                            Main.tile[x + 3, y].liquidType(tile5.liquidType());
                            if (Main.tile[x + 3, y].liquid != (byte)num)
                            {
                                Main.tile[x + 3, y].liquid = (byte)num;
                                AddWater(x + 3, y);
                            }
                            else
                            {
                                num3++;
                            }
                            if (tile.liquid != (byte)num || tile5.liquid != (byte)num)
                            {
                                AddWater(x - 1, y);
                            }
                            if (tile2.liquid != (byte)num || tile5.liquid != (byte)num)
                            {
                                AddWater(x + 1, y);
                            }
                            if (Main.tile[x - 2, y].liquid != (byte)num || tile5.liquid != (byte)num)
                            {
                                AddWater(x - 2, y);
                            }
                            if (Main.tile[x + 2, y].liquid != (byte)num || tile5.liquid != (byte)num)
                            {
                                AddWater(x + 2, y);
                            }
                            if (Main.tile[x - 3, y].liquid != (byte)num || tile5.liquid != (byte)num)
                            {
                                AddWater(x - 3, y);
                            }
                            if (Main.tile[x + 3, y].liquid != (byte)num || tile5.liquid != (byte)num)
                            {
                                AddWater(x + 3, y);
                            }
                            if (num3 != 6 || tile3.liquid <= 0)
                            {
                                tile5.liquid = (byte)num;
                            }
                        }
                        else
                        {
                            int num4 = 0;
                            num = tile.liquid + tile2.liquid + Main.tile[x - 2, y].liquid + Main.tile[x + 2, y].liquid + tile5.liquid + num2;
                            num = (float)Math.Round(num / 5f);
                            tile.liquidType(tile5.liquidType());
                            if (tile.liquid != (byte)num)
                            {
                                tile.liquid = (byte)num;
                                AddWater(x - 1, y);
                            }
                            else
                            {
                                num4++;
                            }
                            tile2.liquidType(tile5.liquidType());
                            if (tile2.liquid != (byte)num)
                            {
                                tile2.liquid = (byte)num;
                                AddWater(x + 1, y);
                            }
                            else
                            {
                                num4++;
                            }
                            Main.tile[x - 2, y].liquidType(tile5.liquidType());
                            if (Main.tile[x - 2, y].liquid != (byte)num)
                            {
                                Main.tile[x - 2, y].liquid = (byte)num;
                                AddWater(x - 2, y);
                            }
                            else
                            {
                                num4++;
                            }
                            Main.tile[x + 2, y].liquidType(tile5.liquidType());
                            if (Main.tile[x + 2, y].liquid != (byte)num)
                            {
                                Main.tile[x + 2, y].liquid = (byte)num;
                                AddWater(x + 2, y);
                            }
                            else
                            {
                                num4++;
                            }
                            if (tile.liquid != (byte)num || tile5.liquid != (byte)num)
                            {
                                AddWater(x - 1, y);
                            }
                            if (tile2.liquid != (byte)num || tile5.liquid != (byte)num)
                            {
                                AddWater(x + 1, y);
                            }
                            if (Main.tile[x - 2, y].liquid != (byte)num || tile5.liquid != (byte)num)
                            {
                                AddWater(x - 2, y);
                            }
                            if (Main.tile[x + 2, y].liquid != (byte)num || tile5.liquid != (byte)num)
                            {
                                AddWater(x + 2, y);
                            }
                            if (num4 != 4 || tile3.liquid <= 0)
                            {
                                tile5.liquid = (byte)num;
                            }
                        }
                    }
                    else if (flag3)
                    {
                        num = tile.liquid + tile2.liquid + Main.tile[x - 2, y].liquid + tile5.liquid + num2;
                        num = (float)Math.Round((double)(num / 4f) + 0.001);
                        tile.liquidType(tile5.liquidType());
                        if (tile.liquid != (byte)num || tile5.liquid != (byte)num)
                        {
                            tile.liquid = (byte)num;
                            AddWater(x - 1, y);
                        }
                        tile2.liquidType(tile5.liquidType());
                        if (tile2.liquid != (byte)num || tile5.liquid != (byte)num)
                        {
                            tile2.liquid = (byte)num;
                            AddWater(x + 1, y);
                        }
                        Main.tile[x - 2, y].liquidType(tile5.liquidType());
                        if (Main.tile[x - 2, y].liquid != (byte)num || tile5.liquid != (byte)num)
                        {
                            Main.tile[x - 2, y].liquid = (byte)num;
                            AddWater(x - 2, y);
                        }
                        tile5.liquid = (byte)num;
                    }
                    else if (flag4)
                    {
                        num = tile.liquid + tile2.liquid + Main.tile[x + 2, y].liquid + tile5.liquid + num2;
                        num = (float)Math.Round((double)(num / 4f) + 0.001);
                        tile.liquidType(tile5.liquidType());
                        if (tile.liquid != (byte)num || tile5.liquid != (byte)num)
                        {
                            tile.liquid = (byte)num;
                            AddWater(x - 1, y);
                        }
                        tile2.liquidType(tile5.liquidType());
                        if (tile2.liquid != (byte)num || tile5.liquid != (byte)num)
                        {
                            tile2.liquid = (byte)num;
                            AddWater(x + 1, y);
                        }
                        Main.tile[x + 2, y].liquidType(tile5.liquidType());
                        if (Main.tile[x + 2, y].liquid != (byte)num || tile5.liquid != (byte)num)
                        {
                            Main.tile[x + 2, y].liquid = (byte)num;
                            AddWater(x + 2, y);
                        }
                        tile5.liquid = (byte)num;
                    }
                    else
                    {
                        num = tile.liquid + tile2.liquid + tile5.liquid + num2;
                        num = (float)Math.Round((double)(num / 3f) + 0.001);
                        tile.liquidType(tile5.liquidType());
                        if (tile.liquid != (byte)num)
                        {
                            tile.liquid = (byte)num;
                        }
                        if (tile5.liquid != (byte)num || tile.liquid != (byte)num)
                        {
                            AddWater(x - 1, y);
                        }
                        tile2.liquidType(tile5.liquidType());
                        if (tile2.liquid != (byte)num)
                        {
                            tile2.liquid = (byte)num;
                        }
                        if (tile5.liquid != (byte)num || tile2.liquid != (byte)num)
                        {
                            AddWater(x + 1, y);
                        }
                        tile5.liquid = (byte)num;
                    }
                }
                else if (flag)
                {
                    num = tile.liquid + tile5.liquid + num2;
                    num = (float)Math.Round((double)(num / 2f) + 0.001);
                    if (tile.liquid != (byte)num)
                    {
                        tile.liquid = (byte)num;
                    }
                    tile.liquidType(tile5.liquidType());
                    if (tile5.liquid != (byte)num || tile.liquid != (byte)num)
                    {
                        AddWater(x - 1, y);
                    }
                    tile5.liquid = (byte)num;
                }
                else if (flag2)
                {
                    num = tile2.liquid + tile5.liquid + num2;
                    num = (float)Math.Round((double)(num / 2f) + 0.001);
                    if (tile2.liquid != (byte)num)
                    {
                        tile2.liquid = (byte)num;
                    }
                    tile2.liquidType(tile5.liquidType());
                    if (tile5.liquid != (byte)num || tile2.liquid != (byte)num)
                    {
                        AddWater(x + 1, y);
                    }
                    tile5.liquid = (byte)num;
                }
            }
            if (tile5.liquid != liquid)
            {
                if (tile5.liquid == 254 && liquid == byte.MaxValue)
                {
                    tile5.liquid = byte.MaxValue;
                    kill++;
                }
                else
                {
                    AddWater(x, y - 1);
                    kill = 0;
                }
            }
            else
            {
                kill++;
            }
        }
Example #2
0
        public static bool CanPlace(
            int x,
            int y,
            int type,
            int style,
            int dir,
            out TileObject objectData,
            bool onlyCheck = false)
        {
            TileObjectData tileData1 = TileObjectData.GetTileData(type, style, 0);

            objectData = TileObject.Empty;
            if (tileData1 == null)
            {
                return(false);
            }
            int num1 = x - (int)tileData1.Origin.X;
            int num2 = y - (int)tileData1.Origin.Y;

            if (num1 < 0 || num1 + tileData1.Width >= Main.maxTilesX || (num2 < 0 || num2 + tileData1.Height >= Main.maxTilesY))
            {
                return(false);
            }
            bool flag1 = tileData1.RandomStyleRange > 0;

            if (TileObjectPreviewData.placementCache == null)
            {
                TileObjectPreviewData.placementCache = new TileObjectPreviewData();
            }
            TileObjectPreviewData.placementCache.Reset();
            int num3 = 0;

            if (tileData1.AlternatesCount != 0)
            {
                num3 = tileData1.AlternatesCount;
            }
            float          num4           = -1f;
            float          num5           = -1f;
            int            num6           = 0;
            TileObjectData tileObjectData = (TileObjectData)null;
            int            alternate      = 0 - 1;

            while (alternate < num3)
            {
                ++alternate;
                TileObjectData tileData2 = TileObjectData.GetTileData(type, style, alternate);
                if (tileData2.Direction == TileObjectDirection.None || (tileData2.Direction != TileObjectDirection.PlaceLeft || dir != 1) && (tileData2.Direction != TileObjectDirection.PlaceRight || dir != -1))
                {
                    int num7 = x - (int)tileData2.Origin.X;
                    int num8 = y - (int)tileData2.Origin.Y;
                    if (num7 < 5 || num7 + tileData2.Width > Main.maxTilesX - 5 || (num8 < 5 || num8 + tileData2.Height > Main.maxTilesY - 5))
                    {
                        return(false);
                    }
                    Rectangle rectangle = new Rectangle(0, 0, tileData2.Width, tileData2.Height);
                    int       X         = 0;
                    int       Y         = 0;
                    if (tileData2.AnchorTop.tileCount != 0)
                    {
                        if (rectangle.Y == 0)
                        {
                            rectangle.Y = -1;
                            ++rectangle.Height;
                            ++Y;
                        }
                        int checkStart = tileData2.AnchorTop.checkStart;
                        if (checkStart < rectangle.X)
                        {
                            rectangle.Width += rectangle.X - checkStart;
                            X          += rectangle.X - checkStart;
                            rectangle.X = checkStart;
                        }
                        int num9  = checkStart + tileData2.AnchorTop.tileCount - 1;
                        int num10 = rectangle.X + rectangle.Width - 1;
                        if (num9 > num10)
                        {
                            rectangle.Width += num9 - num10;
                        }
                    }
                    if (tileData2.AnchorBottom.tileCount != 0)
                    {
                        if (rectangle.Y + rectangle.Height == tileData2.Height)
                        {
                            ++rectangle.Height;
                        }
                        int checkStart = tileData2.AnchorBottom.checkStart;
                        if (checkStart < rectangle.X)
                        {
                            rectangle.Width += rectangle.X - checkStart;
                            X          += rectangle.X - checkStart;
                            rectangle.X = checkStart;
                        }
                        int num9  = checkStart + tileData2.AnchorBottom.tileCount - 1;
                        int num10 = rectangle.X + rectangle.Width - 1;
                        if (num9 > num10)
                        {
                            rectangle.Width += num9 - num10;
                        }
                    }
                    if (tileData2.AnchorLeft.tileCount != 0)
                    {
                        if (rectangle.X == 0)
                        {
                            rectangle.X = -1;
                            ++rectangle.Width;
                            ++X;
                        }
                        int checkStart = tileData2.AnchorLeft.checkStart;
                        if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            --checkStart;
                        }
                        if (checkStart < rectangle.Y)
                        {
                            rectangle.Width += rectangle.Y - checkStart;
                            Y          += rectangle.Y - checkStart;
                            rectangle.Y = checkStart;
                        }
                        int num9 = checkStart + tileData2.AnchorLeft.tileCount - 1;
                        if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            num9 += 2;
                        }
                        int num10 = rectangle.Y + rectangle.Height - 1;
                        if (num9 > num10)
                        {
                            rectangle.Height += num9 - num10;
                        }
                    }
                    if (tileData2.AnchorRight.tileCount != 0)
                    {
                        if (rectangle.X + rectangle.Width == tileData2.Width)
                        {
                            ++rectangle.Width;
                        }
                        int checkStart = tileData2.AnchorLeft.checkStart;
                        if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            --checkStart;
                        }
                        if (checkStart < rectangle.Y)
                        {
                            rectangle.Width += rectangle.Y - checkStart;
                            Y          += rectangle.Y - checkStart;
                            rectangle.Y = checkStart;
                        }
                        int num9 = checkStart + tileData2.AnchorRight.tileCount - 1;
                        if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            num9 += 2;
                        }
                        int num10 = rectangle.Y + rectangle.Height - 1;
                        if (num9 > num10)
                        {
                            rectangle.Height += num9 - num10;
                        }
                    }
                    if (onlyCheck)
                    {
                        TileObject.objectPreview.Reset();
                        TileObject.objectPreview.Active      = true;
                        TileObject.objectPreview.Type        = (ushort)type;
                        TileObject.objectPreview.Style       = (short)style;
                        TileObject.objectPreview.Alternate   = alternate;
                        TileObject.objectPreview.Size        = new Point16(rectangle.Width, rectangle.Height);
                        TileObject.objectPreview.ObjectStart = new Point16(X, Y);
                        TileObject.objectPreview.Coordinates = new Point16(num7 - X, num8 - Y);
                    }
                    float num11 = 0.0f;
                    float num12 = (float)(tileData2.Width * tileData2.Height);
                    float num13 = 0.0f;
                    float num14 = 0.0f;
                    for (int index1 = 0; index1 < tileData2.Width; ++index1)
                    {
                        for (int index2 = 0; index2 < tileData2.Height; ++index2)
                        {
                            Tile tileSafely = Framing.GetTileSafely(num7 + index1, num8 + index2);
                            bool flag2      = !tileData2.LiquidPlace(tileSafely);
                            bool flag3      = false;
                            if (tileData2.AnchorWall)
                            {
                                ++num14;
                                if (!tileData2.isValidWallAnchor((int)tileSafely.wall))
                                {
                                    flag3 = true;
                                }
                                else
                                {
                                    ++num13;
                                }
                            }
                            bool flag4 = false;
                            if (tileSafely.active() && (!Main.tileCut[(int)tileSafely.type] || tileSafely.type == (ushort)484) && !TileID.Sets.BreakableWhenPlacing[(int)tileSafely.type])
                            {
                                flag4 = true;
                            }
                            if (flag4 | flag2 | flag3)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[index1 + X, index2 + Y] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[index1 + X, index2 + Y] = 1;
                                }
                                ++num11;
                            }
                        }
                    }
                    AnchorData anchorBottom = tileData2.AnchorBottom;
                    if (anchorBottom.tileCount != 0)
                    {
                        num14 += (float)anchorBottom.tileCount;
                        int height = tileData2.Height;
                        for (int index = 0; index < anchorBottom.tileCount; ++index)
                        {
                            int  num9       = anchorBottom.checkStart + index;
                            Tile tileSafely = Framing.GetTileSafely(num7 + num9, num8 + height);
                            bool flag2      = false;
                            if (tileSafely.nactive())
                            {
                                if ((anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile && Main.tileSolid[(int)tileSafely.type] && (!Main.tileSolidTop[(int)tileSafely.type] && !Main.tileNoAttach[(int)tileSafely.type]) && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                                {
                                    flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                }
                                if (!flag2 && ((anchorBottom.type & AnchorType.SolidWithTop) == AnchorType.SolidWithTop || (anchorBottom.type & AnchorType.Table) == AnchorType.Table))
                                {
                                    if (TileID.Sets.Platforms[(int)tileSafely.type])
                                    {
                                        int num10 = (int)tileSafely.frameX / TileObjectData.PlatformFrameWidth();
                                        if (!tileSafely.halfBrick() && WorldGen.PlatformProperTopFrame(tileSafely.frameX))
                                        {
                                            flag2 = true;
                                        }
                                    }
                                    else if (Main.tileSolid[(int)tileSafely.type] && Main.tileSolidTop[(int)tileSafely.type])
                                    {
                                        flag2 = true;
                                    }
                                }
                                if (!flag2 && (anchorBottom.type & AnchorType.Table) == AnchorType.Table && (!TileID.Sets.Platforms[(int)tileSafely.type] && Main.tileTable[(int)tileSafely.type]) && tileSafely.blockType() == 0)
                                {
                                    flag2 = true;
                                }
                                if (!flag2 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type]))
                                {
                                    switch (tileSafely.blockType())
                                    {
                                    case 4:
                                    case 5:
                                        flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                        break;
                                    }
                                }
                                if (!flag2 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely.type))
                                {
                                    flag2 = true;
                                }
                            }
                            else if (!flag2 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag2 = true;
                            }
                            if (!flag2)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num9 + X, height + Y] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num9 + X, height + Y] = 1;
                                }
                                ++num13;
                            }
                        }
                    }
                    AnchorData anchorTop = tileData2.AnchorTop;
                    if (anchorTop.tileCount != 0)
                    {
                        num14 += (float)anchorTop.tileCount;
                        int num9 = -1;
                        for (int index = 0; index < anchorTop.tileCount; ++index)
                        {
                            int  num10      = anchorTop.checkStart + index;
                            Tile tileSafely = Framing.GetTileSafely(num7 + num10, num8 + num9);
                            bool flag2      = false;
                            if (tileSafely.nactive())
                            {
                                if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && !Main.tileNoAttach[(int)tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                                {
                                    flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                }
                                if (!flag2 && (anchorTop.type & AnchorType.SolidBottom) == AnchorType.SolidBottom && (Main.tileSolid[(int)tileSafely.type] && (!Main.tileSolidTop[(int)tileSafely.type] || TileID.Sets.Platforms[(int)tileSafely.type] && (tileSafely.halfBrick() || tileSafely.topSlope())) || (tileSafely.halfBrick() || tileSafely.topSlope())) && (!TileID.Sets.NotReallySolid[(int)tileSafely.type] && !tileSafely.bottomSlope()))
                                {
                                    flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                }
                                if (!flag2 && (anchorTop.type & AnchorType.SolidSide) == AnchorType.SolidSide && (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type]))
                                {
                                    switch (tileSafely.blockType())
                                    {
                                    case 2:
                                    case 3:
                                        flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                        break;
                                    }
                                }
                                if (!flag2 && (anchorTop.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely.type))
                                {
                                    flag2 = true;
                                }
                            }
                            else if (!flag2 && (anchorTop.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag2 = true;
                            }
                            if (!flag2)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num10 + X, num9 + Y] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num10 + X, num9 + Y] = 1;
                                }
                                ++num13;
                            }
                        }
                    }
                    AnchorData anchorRight = tileData2.AnchorRight;
                    if (anchorRight.tileCount != 0)
                    {
                        num14 += (float)anchorRight.tileCount;
                        int width = tileData2.Width;
                        for (int index = 0; index < anchorRight.tileCount; ++index)
                        {
                            int  num9        = anchorRight.checkStart + index;
                            Tile tileSafely1 = Framing.GetTileSafely(num7 + width, num8 + num9);
                            bool flag2       = false;
                            if (tileSafely1.nactive())
                            {
                                if (Main.tileSolid[(int)tileSafely1.type] && !Main.tileSolidTop[(int)tileSafely1.type] && !Main.tileNoAttach[(int)tileSafely1.type] && (tileData2.FlattenAnchors || tileSafely1.blockType() == 0))
                                {
                                    flag2 = tileData2.isValidTileAnchor((int)tileSafely1.type);
                                }
                                if (!flag2 && (anchorRight.type & AnchorType.SolidSide) == AnchorType.SolidSide && (Main.tileSolid[(int)tileSafely1.type] && !Main.tileSolidTop[(int)tileSafely1.type]))
                                {
                                    switch (tileSafely1.blockType())
                                    {
                                    case 2:
                                    case 4:
                                        flag2 = tileData2.isValidTileAnchor((int)tileSafely1.type);
                                        break;
                                    }
                                }
                                if (!flag2 && (anchorRight.type & AnchorType.Tree) == AnchorType.Tree && TileID.Sets.IsATreeTrunk[(int)tileSafely1.type])
                                {
                                    flag2 = true;
                                    if (index == 0)
                                    {
                                        ++num14;
                                        Tile tileSafely2 = Framing.GetTileSafely(num7 + width, num8 + num9 - 1);
                                        if (tileSafely2.nactive() && TileID.Sets.IsATreeTrunk[(int)tileSafely2.type])
                                        {
                                            ++num13;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[width + X, num9 + Y - 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[width + X, num9 + Y - 1] = 2;
                                        }
                                    }
                                    if (index == anchorRight.tileCount - 1)
                                    {
                                        ++num14;
                                        Tile tileSafely2 = Framing.GetTileSafely(num7 + width, num8 + num9 + 1);
                                        if (tileSafely2.nactive() && TileID.Sets.IsATreeTrunk[(int)tileSafely2.type])
                                        {
                                            ++num13;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[width + X, num9 + Y + 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[width + X, num9 + Y + 1] = 2;
                                        }
                                    }
                                }
                                if (!flag2 && (anchorRight.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely1.type))
                                {
                                    flag2 = true;
                                }
                            }
                            else if (!flag2 && (anchorRight.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag2 = true;
                            }
                            if (!flag2)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[width + X, num9 + Y] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[width + X, num9 + Y] = 1;
                                }
                                ++num13;
                            }
                        }
                    }
                    AnchorData anchorLeft = tileData2.AnchorLeft;
                    if (anchorLeft.tileCount != 0)
                    {
                        num14 += (float)anchorLeft.tileCount;
                        int num9 = -1;
                        for (int index = 0; index < anchorLeft.tileCount; ++index)
                        {
                            int  num10       = anchorLeft.checkStart + index;
                            Tile tileSafely1 = Framing.GetTileSafely(num7 + num9, num8 + num10);
                            bool flag2       = false;
                            if (tileSafely1.nactive())
                            {
                                if (Main.tileSolid[(int)tileSafely1.type] && !Main.tileSolidTop[(int)tileSafely1.type] && !Main.tileNoAttach[(int)tileSafely1.type] && (tileData2.FlattenAnchors || tileSafely1.blockType() == 0))
                                {
                                    flag2 = tileData2.isValidTileAnchor((int)tileSafely1.type);
                                }
                                if (!flag2 && (anchorLeft.type & AnchorType.SolidSide) == AnchorType.SolidSide && (Main.tileSolid[(int)tileSafely1.type] && !Main.tileSolidTop[(int)tileSafely1.type]))
                                {
                                    switch (tileSafely1.blockType())
                                    {
                                    case 3:
                                    case 5:
                                        flag2 = tileData2.isValidTileAnchor((int)tileSafely1.type);
                                        break;
                                    }
                                }
                                if (!flag2 && (anchorLeft.type & AnchorType.Tree) == AnchorType.Tree && TileID.Sets.IsATreeTrunk[(int)tileSafely1.type])
                                {
                                    flag2 = true;
                                    if (index == 0)
                                    {
                                        ++num14;
                                        Tile tileSafely2 = Framing.GetTileSafely(num7 + num9, num8 + num10 - 1);
                                        if (tileSafely2.nactive() && TileID.Sets.IsATreeTrunk[(int)tileSafely2.type])
                                        {
                                            ++num13;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[num9 + X, num10 + Y - 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[num9 + X, num10 + Y - 1] = 2;
                                        }
                                    }
                                    if (index == anchorLeft.tileCount - 1)
                                    {
                                        ++num14;
                                        Tile tileSafely2 = Framing.GetTileSafely(num7 + num9, num8 + num10 + 1);
                                        if (tileSafely2.nactive() && TileID.Sets.IsATreeTrunk[(int)tileSafely2.type])
                                        {
                                            ++num13;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[num9 + X, num10 + Y + 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[num9 + X, num10 + Y + 1] = 2;
                                        }
                                    }
                                }
                                if (!flag2 && (anchorLeft.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely1.type))
                                {
                                    flag2 = true;
                                }
                            }
                            else if (!flag2 && (anchorLeft.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag2 = true;
                            }
                            if (!flag2)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num9 + X, num10 + Y] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num9 + X, num10 + Y] = 1;
                                }
                                ++num13;
                            }
                        }
                    }
                    if (tileData2.HookCheckIfCanPlace.hook != null)
                    {
                        if (tileData2.HookCheckIfCanPlace.processedCoordinates)
                        {
                            Point16 origin1 = tileData2.Origin;
                            Point16 origin2 = tileData2.Origin;
                        }
                        if (tileData2.HookCheckIfCanPlace.hook(x, y, type, style, dir, alternate) == tileData2.HookCheckIfCanPlace.badReturn && tileData2.HookCheckIfCanPlace.badResponse == 0)
                        {
                            num13 = 0.0f;
                            num11 = 0.0f;
                            TileObject.objectPreview.AllInvalid();
                        }
                    }
                    float num15 = num13 / num14;
                    float num16 = num11 / num12;
                    if ((double)num16 == 1.0 && (double)num14 == 0.0)
                    {
                        num15 = 1f;
                        num16 = 1f;
                    }
                    if ((double)num15 == 1.0 && (double)num16 == 1.0)
                    {
                        num4           = 1f;
                        num5           = 1f;
                        num6           = alternate;
                        tileObjectData = tileData2;
                        break;
                    }
                    if ((double)num15 > (double)num4 || (double)num15 == (double)num4 && (double)num16 > (double)num5)
                    {
                        TileObjectPreviewData.placementCache.CopyFrom(TileObject.objectPreview);
                        num4           = num15;
                        num5           = num16;
                        tileObjectData = tileData2;
                        num6           = alternate;
                    }
                }
            }
            int num17 = -1;

            if (flag1)
            {
                if (TileObjectPreviewData.randomCache == null)
                {
                    TileObjectPreviewData.randomCache = new TileObjectPreviewData();
                }
                bool flag2 = false;
                if ((int)TileObjectPreviewData.randomCache.Type == type)
                {
                    Point16 coordinates = TileObjectPreviewData.randomCache.Coordinates;
                    Point16 objectStart = TileObjectPreviewData.randomCache.ObjectStart;
                    int     num7        = (int)coordinates.X + (int)objectStart.X;
                    int     num8        = (int)coordinates.Y + (int)objectStart.Y;
                    int     num9        = x - (int)tileData1.Origin.X;
                    int     num10       = y - (int)tileData1.Origin.Y;
                    if (num7 != num9 || num8 != num10)
                    {
                        flag2 = true;
                    }
                }
                else
                {
                    flag2 = true;
                }
                num17 = !flag2 ? TileObjectPreviewData.randomCache.Random : Main.rand.Next(tileData1.RandomStyleRange);
            }
            if (onlyCheck)
            {
                if ((double)num4 != 1.0 || (double)num5 != 1.0)
                {
                    TileObject.objectPreview.CopyFrom(TileObjectPreviewData.placementCache);
                    alternate = num6;
                }
                TileObject.objectPreview.Random = num17;
                if (tileData1.RandomStyleRange > 0)
                {
                    TileObjectPreviewData.randomCache.CopyFrom(TileObject.objectPreview);
                }
            }
            if (!onlyCheck)
            {
                objectData.xCoord    = x - (int)tileObjectData.Origin.X;
                objectData.yCoord    = y - (int)tileObjectData.Origin.Y;
                objectData.type      = type;
                objectData.style     = style;
                objectData.alternate = alternate;
                objectData.random    = num17;
            }
            return((double)num4 == 1.0 && (double)num5 == 1.0);
        }
Example #3
0
        public static bool CanPlace(int x, int y, int type, int style, int dir, out TileObject objectData, bool onlyCheck = false)
        {
            TileObjectData tileData = TileObjectData.GetTileData(type, style);

            objectData = Empty;
            if (tileData == null)
            {
                return(false);
            }
            int num  = x - tileData.Origin.X;
            int num2 = y - tileData.Origin.Y;

            if (num < 0 || num + tileData.Width >= Main.maxTilesX || num2 < 0 || num2 + tileData.Height >= Main.maxTilesY)
            {
                return(false);
            }
            bool flag = tileData.RandomStyleRange > 0;

            if (TileObjectPreviewData.placementCache == null)
            {
                TileObjectPreviewData.placementCache = new TileObjectPreviewData();
            }
            TileObjectPreviewData.placementCache.Reset();
            int num3 = 0;

            if (tileData.AlternatesCount != 0)
            {
                num3 = tileData.AlternatesCount;
            }
            float          num4           = -1f;
            float          num5           = -1f;
            int            num6           = 0;
            TileObjectData tileObjectData = null;
            int            num7           = -1;

            while (num7 < num3)
            {
                num7++;
                TileObjectData tileData2 = TileObjectData.GetTileData(type, style, num7);
                if (tileData2.Direction != 0 && ((tileData2.Direction == TileObjectDirection.PlaceLeft && dir == 1) || (tileData2.Direction == TileObjectDirection.PlaceRight && dir == -1)))
                {
                    continue;
                }
                int num8 = x - tileData2.Origin.X;
                int num9 = y - tileData2.Origin.Y;
                if (num8 < 5 || num8 + tileData2.Width > Main.maxTilesX - 5 || num9 < 5 || num9 + tileData2.Height > Main.maxTilesY - 5)
                {
                    return(false);
                }
                Rectangle rectangle = new Rectangle(0, 0, tileData2.Width, tileData2.Height);
                int       num10     = 0;
                int       num11     = 0;
                if (tileData2.AnchorTop.tileCount != 0)
                {
                    if (rectangle.Y == 0)
                    {
                        rectangle.Y = -1;
                        rectangle.Height++;
                        num11++;
                    }
                    int checkStart = tileData2.AnchorTop.checkStart;
                    if (checkStart < rectangle.X)
                    {
                        rectangle.Width += rectangle.X - checkStart;
                        num10           += rectangle.X - checkStart;
                        rectangle.X      = checkStart;
                    }
                    int num12 = checkStart + tileData2.AnchorTop.tileCount - 1;
                    int num13 = rectangle.X + rectangle.Width - 1;
                    if (num12 > num13)
                    {
                        rectangle.Width += num12 - num13;
                    }
                }
                if (tileData2.AnchorBottom.tileCount != 0)
                {
                    if (rectangle.Y + rectangle.Height == tileData2.Height)
                    {
                        rectangle.Height++;
                    }
                    int checkStart2 = tileData2.AnchorBottom.checkStart;
                    if (checkStart2 < rectangle.X)
                    {
                        rectangle.Width += rectangle.X - checkStart2;
                        num10           += rectangle.X - checkStart2;
                        rectangle.X      = checkStart2;
                    }
                    int num14 = checkStart2 + tileData2.AnchorBottom.tileCount - 1;
                    int num15 = rectangle.X + rectangle.Width - 1;
                    if (num14 > num15)
                    {
                        rectangle.Width += num14 - num15;
                    }
                }
                if (tileData2.AnchorLeft.tileCount != 0)
                {
                    if (rectangle.X == 0)
                    {
                        rectangle.X = -1;
                        rectangle.Width++;
                        num10++;
                    }
                    int num16 = tileData2.AnchorLeft.checkStart;
                    if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
                    {
                        num16--;
                    }
                    if (num16 < rectangle.Y)
                    {
                        rectangle.Width += rectangle.Y - num16;
                        num11           += rectangle.Y - num16;
                        rectangle.Y      = num16;
                    }
                    int num17 = num16 + tileData2.AnchorLeft.tileCount - 1;
                    if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
                    {
                        num17 += 2;
                    }
                    int num18 = rectangle.Y + rectangle.Height - 1;
                    if (num17 > num18)
                    {
                        rectangle.Height += num17 - num18;
                    }
                }
                if (tileData2.AnchorRight.tileCount != 0)
                {
                    if (rectangle.X + rectangle.Width == tileData2.Width)
                    {
                        rectangle.Width++;
                    }
                    int num19 = tileData2.AnchorLeft.checkStart;
                    if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
                    {
                        num19--;
                    }
                    if (num19 < rectangle.Y)
                    {
                        rectangle.Width += rectangle.Y - num19;
                        num11           += rectangle.Y - num19;
                        rectangle.Y      = num19;
                    }
                    int num20 = num19 + tileData2.AnchorRight.tileCount - 1;
                    if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
                    {
                        num20 += 2;
                    }
                    int num21 = rectangle.Y + rectangle.Height - 1;
                    if (num20 > num21)
                    {
                        rectangle.Height += num20 - num21;
                    }
                }
                if (onlyCheck)
                {
                    objectPreview.Reset();
                    objectPreview.Active      = true;
                    objectPreview.Type        = (ushort)type;
                    objectPreview.Style       = (short)style;
                    objectPreview.Alternate   = num7;
                    objectPreview.Size        = new Point16(rectangle.Width, rectangle.Height);
                    objectPreview.ObjectStart = new Point16(num10, num11);
                    objectPreview.Coordinates = new Point16(num8 - num10, num9 - num11);
                }
                float num22 = 0f;
                float num23 = tileData2.Width * tileData2.Height;
                float num24 = 0f;
                float num25 = 0f;
                for (int i = 0; i < tileData2.Width; i++)
                {
                    for (int j = 0; j < tileData2.Height; j++)
                    {
                        Tile tileSafely = Framing.GetTileSafely(num8 + i, num9 + j);
                        bool flag2      = !tileData2.LiquidPlace(tileSafely);
                        bool flag3      = false;
                        if (tileData2.AnchorWall)
                        {
                            num25 += 1f;
                            if (!tileData2.isValidWallAnchor(tileSafely.wall))
                            {
                                flag3 = true;
                            }
                            else
                            {
                                num24 += 1f;
                            }
                        }
                        bool flag4 = false;
                        if (tileSafely.active() && (!Main.tileCut[tileSafely.type] || tileSafely.type == 484) && !TileID.Sets.BreakableWhenPlacing[tileSafely.type])
                        {
                            flag4 = true;
                        }
                        if (flag4 | flag2 | flag3)
                        {
                            if (onlyCheck)
                            {
                                objectPreview[i + num10, j + num11] = 2;
                            }
                            continue;
                        }
                        if (onlyCheck)
                        {
                            objectPreview[i + num10, j + num11] = 1;
                        }
                        num22 += 1f;
                    }
                }
                AnchorData anchorBottom = tileData2.AnchorBottom;
                if (anchorBottom.tileCount != 0)
                {
                    num25 += (float)anchorBottom.tileCount;
                    int height = tileData2.Height;
                    for (int k = 0; k < anchorBottom.tileCount; k++)
                    {
                        int  num26      = anchorBottom.checkStart + k;
                        Tile tileSafely = Framing.GetTileSafely(num8 + num26, num9 + height);
                        bool flag5      = false;
                        if (tileSafely.nactive())
                        {
                            if ((anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                            {
                                flag5 = tileData2.isValidTileAnchor(tileSafely.type);
                            }
                            if (!flag5 && ((anchorBottom.type & AnchorType.SolidWithTop) == AnchorType.SolidWithTop || (anchorBottom.type & AnchorType.Table) == AnchorType.Table))
                            {
                                if (TileID.Sets.Platforms[tileSafely.type])
                                {
                                    _ = tileSafely.frameX / TileObjectData.PlatformFrameWidth();
                                    if (!tileSafely.halfBrick() && WorldGen.PlatformProperTopFrame(tileSafely.frameX))
                                    {
                                        flag5 = true;
                                    }
                                }
                                else if (Main.tileSolid[tileSafely.type] && Main.tileSolidTop[tileSafely.type])
                                {
                                    flag5 = true;
                                }
                            }
                            if (!flag5 && (anchorBottom.type & AnchorType.Table) == AnchorType.Table && !TileID.Sets.Platforms[tileSafely.type] && Main.tileTable[tileSafely.type] && tileSafely.blockType() == 0)
                            {
                                flag5 = true;
                            }
                            if (!flag5 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
                            {
                                int num27 = tileSafely.blockType();
                                if ((uint)(num27 - 4) <= 1u)
                                {
                                    flag5 = tileData2.isValidTileAnchor(tileSafely.type);
                                }
                            }
                            if (!flag5 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor(tileSafely.type))
                            {
                                flag5 = true;
                            }
                        }
                        else if (!flag5 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                        {
                            flag5 = true;
                        }
                        if (!flag5)
                        {
                            if (onlyCheck)
                            {
                                objectPreview[num26 + num10, height + num11] = 2;
                            }
                            continue;
                        }
                        if (onlyCheck)
                        {
                            objectPreview[num26 + num10, height + num11] = 1;
                        }
                        num24 += 1f;
                    }
                }
                anchorBottom = tileData2.AnchorTop;
                if (anchorBottom.tileCount != 0)
                {
                    num25 += (float)anchorBottom.tileCount;
                    int num28 = -1;
                    for (int l = 0; l < anchorBottom.tileCount; l++)
                    {
                        int  num29      = anchorBottom.checkStart + l;
                        Tile tileSafely = Framing.GetTileSafely(num8 + num29, num9 + num28);
                        bool flag6      = false;
                        if (tileSafely.nactive())
                        {
                            if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                            {
                                flag6 = tileData2.isValidTileAnchor(tileSafely.type);
                            }
                            if (!flag6 && (anchorBottom.type & AnchorType.SolidBottom) == AnchorType.SolidBottom && ((Main.tileSolid[tileSafely.type] && (!Main.tileSolidTop[tileSafely.type] || (TileID.Sets.Platforms[tileSafely.type] && (tileSafely.halfBrick() || tileSafely.topSlope())))) || tileSafely.halfBrick() || tileSafely.topSlope()) && !TileID.Sets.NotReallySolid[tileSafely.type] && !tileSafely.bottomSlope())
                            {
                                flag6 = tileData2.isValidTileAnchor(tileSafely.type);
                            }
                            if (!flag6 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
                            {
                                int num27 = tileSafely.blockType();
                                if ((uint)(num27 - 2) <= 1u)
                                {
                                    flag6 = tileData2.isValidTileAnchor(tileSafely.type);
                                }
                            }
                            if (!flag6 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor(tileSafely.type))
                            {
                                flag6 = true;
                            }
                        }
                        else if (!flag6 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                        {
                            flag6 = true;
                        }
                        if (!flag6)
                        {
                            if (onlyCheck)
                            {
                                objectPreview[num29 + num10, num28 + num11] = 2;
                            }
                            continue;
                        }
                        if (onlyCheck)
                        {
                            objectPreview[num29 + num10, num28 + num11] = 1;
                        }
                        num24 += 1f;
                    }
                }
                anchorBottom = tileData2.AnchorRight;
                if (anchorBottom.tileCount != 0)
                {
                    num25 += (float)anchorBottom.tileCount;
                    int width = tileData2.Width;
                    for (int m = 0; m < anchorBottom.tileCount; m++)
                    {
                        int  num30      = anchorBottom.checkStart + m;
                        Tile tileSafely = Framing.GetTileSafely(num8 + width, num9 + num30);
                        bool flag7      = false;
                        if (tileSafely.nactive())
                        {
                            if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                            {
                                flag7 = tileData2.isValidTileAnchor(tileSafely.type);
                            }
                            if (!flag7 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
                            {
                                int num27 = tileSafely.blockType();
                                if (num27 == 2 || num27 == 4)
                                {
                                    flag7 = tileData2.isValidTileAnchor(tileSafely.type);
                                }
                            }
                            if (!flag7 && (anchorBottom.type & AnchorType.Tree) == AnchorType.Tree && TileID.Sets.IsATreeTrunk[tileSafely.type])
                            {
                                flag7 = true;
                                if (m == 0)
                                {
                                    num25 += 1f;
                                    Tile tileSafely2 = Framing.GetTileSafely(num8 + width, num9 + num30 - 1);
                                    if (tileSafely2.nactive() && TileID.Sets.IsATreeTrunk[tileSafely2.type])
                                    {
                                        num24 += 1f;
                                        if (onlyCheck)
                                        {
                                            objectPreview[width + num10, num30 + num11 - 1] = 1;
                                        }
                                    }
                                    else if (onlyCheck)
                                    {
                                        objectPreview[width + num10, num30 + num11 - 1] = 2;
                                    }
                                }
                                if (m == anchorBottom.tileCount - 1)
                                {
                                    num25 += 1f;
                                    Tile tileSafely3 = Framing.GetTileSafely(num8 + width, num9 + num30 + 1);
                                    if (tileSafely3.nactive() && TileID.Sets.IsATreeTrunk[tileSafely3.type])
                                    {
                                        num24 += 1f;
                                        if (onlyCheck)
                                        {
                                            objectPreview[width + num10, num30 + num11 + 1] = 1;
                                        }
                                    }
                                    else if (onlyCheck)
                                    {
                                        objectPreview[width + num10, num30 + num11 + 1] = 2;
                                    }
                                }
                            }
                            if (!flag7 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor(tileSafely.type))
                            {
                                flag7 = true;
                            }
                        }
                        else if (!flag7 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                        {
                            flag7 = true;
                        }
                        if (!flag7)
                        {
                            if (onlyCheck)
                            {
                                objectPreview[width + num10, num30 + num11] = 2;
                            }
                            continue;
                        }
                        if (onlyCheck)
                        {
                            objectPreview[width + num10, num30 + num11] = 1;
                        }
                        num24 += 1f;
                    }
                }
                anchorBottom = tileData2.AnchorLeft;
                if (anchorBottom.tileCount != 0)
                {
                    num25 += (float)anchorBottom.tileCount;
                    int num31 = -1;
                    for (int n = 0; n < anchorBottom.tileCount; n++)
                    {
                        int  num32      = anchorBottom.checkStart + n;
                        Tile tileSafely = Framing.GetTileSafely(num8 + num31, num9 + num32);
                        bool flag8      = false;
                        if (tileSafely.nactive())
                        {
                            if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                            {
                                flag8 = tileData2.isValidTileAnchor(tileSafely.type);
                            }
                            if (!flag8 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
                            {
                                int num27 = tileSafely.blockType();
                                if (num27 == 3 || num27 == 5)
                                {
                                    flag8 = tileData2.isValidTileAnchor(tileSafely.type);
                                }
                            }
                            if (!flag8 && (anchorBottom.type & AnchorType.Tree) == AnchorType.Tree && TileID.Sets.IsATreeTrunk[tileSafely.type])
                            {
                                flag8 = true;
                                if (n == 0)
                                {
                                    num25 += 1f;
                                    Tile tileSafely4 = Framing.GetTileSafely(num8 + num31, num9 + num32 - 1);
                                    if (tileSafely4.nactive() && TileID.Sets.IsATreeTrunk[tileSafely4.type])
                                    {
                                        num24 += 1f;
                                        if (onlyCheck)
                                        {
                                            objectPreview[num31 + num10, num32 + num11 - 1] = 1;
                                        }
                                    }
                                    else if (onlyCheck)
                                    {
                                        objectPreview[num31 + num10, num32 + num11 - 1] = 2;
                                    }
                                }
                                if (n == anchorBottom.tileCount - 1)
                                {
                                    num25 += 1f;
                                    Tile tileSafely5 = Framing.GetTileSafely(num8 + num31, num9 + num32 + 1);
                                    if (tileSafely5.nactive() && TileID.Sets.IsATreeTrunk[tileSafely5.type])
                                    {
                                        num24 += 1f;
                                        if (onlyCheck)
                                        {
                                            objectPreview[num31 + num10, num32 + num11 + 1] = 1;
                                        }
                                    }
                                    else if (onlyCheck)
                                    {
                                        objectPreview[num31 + num10, num32 + num11 + 1] = 2;
                                    }
                                }
                            }
                            if (!flag8 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor(tileSafely.type))
                            {
                                flag8 = true;
                            }
                        }
                        else if (!flag8 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                        {
                            flag8 = true;
                        }
                        if (!flag8)
                        {
                            if (onlyCheck)
                            {
                                objectPreview[num31 + num10, num32 + num11] = 2;
                            }
                            continue;
                        }
                        if (onlyCheck)
                        {
                            objectPreview[num31 + num10, num32 + num11] = 1;
                        }
                        num24 += 1f;
                    }
                }
                if (tileData2.HookCheckIfCanPlace.hook != null)
                {
                    if (tileData2.HookCheckIfCanPlace.processedCoordinates)
                    {
                        _ = tileData2.Origin;
                        _ = tileData2.Origin;
                    }
                    if (tileData2.HookCheckIfCanPlace.hook(x, y, type, style, dir, num7) == tileData2.HookCheckIfCanPlace.badReturn && tileData2.HookCheckIfCanPlace.badResponse == 0)
                    {
                        num24 = 0f;
                        num22 = 0f;
                        objectPreview.AllInvalid();
                    }
                }
                float num33 = num24 / num25;
                float num34 = num22 / num23;
                if (num34 == 1f && num25 == 0f)
                {
                    num23 = 1f;
                    num25 = 1f;
                    num33 = 1f;
                    num34 = 1f;
                }
                if (num33 == 1f && num34 == 1f)
                {
                    num4           = 1f;
                    num5           = 1f;
                    num6           = num7;
                    tileObjectData = tileData2;
                    break;
                }
                if (num33 > num4 || (num33 == num4 && num34 > num5))
                {
                    TileObjectPreviewData.placementCache.CopyFrom(objectPreview);
                    num4           = num33;
                    num5           = num34;
                    tileObjectData = tileData2;
                    num6           = num7;
                }
            }
            int num35 = -1;

            if (flag)
            {
                if (TileObjectPreviewData.randomCache == null)
                {
                    TileObjectPreviewData.randomCache = new TileObjectPreviewData();
                }
                bool flag9 = false;
                if (TileObjectPreviewData.randomCache.Type == type)
                {
                    Point16 coordinates = TileObjectPreviewData.randomCache.Coordinates;
                    Point16 objectStart = TileObjectPreviewData.randomCache.ObjectStart;
                    int     num36       = coordinates.X + objectStart.X;
                    int     num37       = coordinates.Y + objectStart.Y;
                    int     num38       = x - tileData.Origin.X;
                    int     num39       = y - tileData.Origin.Y;
                    if (num36 != num38 || num37 != num39)
                    {
                        flag9 = true;
                    }
                }
                else
                {
                    flag9 = true;
                }
                num35 = ((!flag9) ? TileObjectPreviewData.randomCache.Random : Main.rand.Next(tileData.RandomStyleRange));
            }
            if (onlyCheck)
            {
                if (num4 != 1f || num5 != 1f)
                {
                    objectPreview.CopyFrom(TileObjectPreviewData.placementCache);
                    num7 = num6;
                }
                objectPreview.Random = num35;
                if (tileData.RandomStyleRange > 0)
                {
                    TileObjectPreviewData.randomCache.CopyFrom(objectPreview);
                }
            }
            if (!onlyCheck)
            {
                objectData.xCoord    = x - tileObjectData.Origin.X;
                objectData.yCoord    = y - tileObjectData.Origin.Y;
                objectData.type      = type;
                objectData.style     = style;
                objectData.alternate = num7;
                objectData.random    = num35;
            }
            if (num4 == 1f)
            {
                return(num5 == 1f);
            }
            return(false);
        }
        public static void DelWater(int l)
        {
            int  num   = Main.liquid[l].x;
            int  num2  = Main.liquid[l].y;
            Tile tile  = Main.tile[num - 1, num2];
            Tile tile2 = Main.tile[num + 1, num2];
            Tile tile3 = Main.tile[num, num2 + 1];
            Tile tile4 = Main.tile[num, num2];
            byte b     = 2;

            if (tile4.liquid < b)
            {
                tile4.liquid = 0;
                if (tile.liquid < b)
                {
                    tile.liquid = 0;
                }
                else
                {
                    AddWater(num - 1, num2);
                }
                if (tile2.liquid < b)
                {
                    tile2.liquid = 0;
                }
                else
                {
                    AddWater(num + 1, num2);
                }
            }
            else if (tile4.liquid < 20)
            {
                if ((tile.liquid < tile4.liquid && (!tile.nactive() || !Main.tileSolid[tile.type] || Main.tileSolidTop[tile.type])) || (tile2.liquid < tile4.liquid && (!tile2.nactive() || !Main.tileSolid[tile2.type] || Main.tileSolidTop[tile2.type])) || (tile3.liquid < byte.MaxValue && (!tile3.nactive() || !Main.tileSolid[tile3.type] || Main.tileSolidTop[tile3.type])))
                {
                    tile4.liquid = 0;
                }
            }
            else if (tile3.liquid < byte.MaxValue && (!tile3.nactive() || !Main.tileSolid[tile3.type] || Main.tileSolidTop[tile3.type]) && !stuck)
            {
                Main.liquid[l].kill = 0;
                return;
            }
            if (tile4.liquid < 250 && Main.tile[num, num2 - 1].liquid > 0)
            {
                AddWater(num, num2 - 1);
            }
            if (tile4.liquid == 0)
            {
                tile4.liquidType(0);
            }
            else
            {
                if ((tile2.liquid > 0 && Main.tile[num + 1, num2 + 1].liquid < 250 && !Main.tile[num + 1, num2 + 1].active()) || (tile.liquid > 0 && Main.tile[num - 1, num2 + 1].liquid < 250 && !Main.tile[num - 1, num2 + 1].active()))
                {
                    AddWater(num - 1, num2);
                    AddWater(num + 1, num2);
                }
                if (tile4.lava())
                {
                    LavaCheck(num, num2);
                    for (int i = num - 1; i <= num + 1; i++)
                    {
                        for (int j = num2 - 1; j <= num2 + 1; j++)
                        {
                            Tile tile5 = Main.tile[i, j];
                            if (!tile5.active())
                            {
                                continue;
                            }
                            if (tile5.type == 2 || tile5.type == 23 || tile5.type == 109 || tile5.type == 199)
                            {
                                tile5.type = 0;
                                WorldGen.SquareTileFrame(i, j);
                                if (Main.netMode == 2)
                                {
                                    NetMessage.SendTileSquare(-1, num, num2, 3);
                                }
                            }
                            else if (tile5.type == 60 || tile5.type == 70)
                            {
                                tile5.type = 59;
                                WorldGen.SquareTileFrame(i, j);
                                if (Main.netMode == 2)
                                {
                                    NetMessage.SendTileSquare(-1, num, num2, 3);
                                }
                            }
                        }
                    }
                }
                else if (tile4.honey())
                {
                    HoneyCheck(num, num2);
                }
            }
            if (Main.netMode == 2)
            {
                NetSendLiquid(num, num2);
            }
            numLiquid--;
            Main.tile[Main.liquid[l].x, Main.liquid[l].y].checkingLiquid(false);
            Main.liquid[l].x    = Main.liquid[numLiquid].x;
            Main.liquid[l].y    = Main.liquid[numLiquid].y;
            Main.liquid[l].kill = Main.liquid[numLiquid].kill;
            if (Main.tileAlch[tile4.type])
            {
                WorldGen.CheckAlch(num, num2);
            }
        }
Example #5
0
        public static bool CanPlace(int x, int y, int type, int style, int dir, out TileObject objectData, bool onlyCheck = false)
        {
            TileObjectData tileData1 = TileObjectData.GetTileData(type, style, 0);

            objectData = TileObject.Empty;
            if (tileData1 == null)
            {
                return(false);
            }
            int num1 = x - (int)tileData1.Origin.X;
            int num2 = y - (int)tileData1.Origin.Y;

            if (num1 < 0 || num1 + tileData1.Width >= Main.maxTilesX || (num2 < 0 || num2 + tileData1.Height >= Main.maxTilesY))
            {
                return(false);
            }
            bool flag1 = tileData1.RandomStyleRange > 0;

            if (TileObjectPreviewData.placementCache == null)
            {
                TileObjectPreviewData.placementCache = new TileObjectPreviewData();
            }
            TileObjectPreviewData.placementCache.Reset();
            int num3 = 0;
            int num4 = 0;

            if (tileData1.AlternatesCount != 0)
            {
                num4 = tileData1.AlternatesCount;
            }
            float          num5           = -1f;
            float          num6           = -1f;
            int            num7           = 0;
            TileObjectData tileObjectData = (TileObjectData)null;
            int            alternate      = num3 - 1;

            while (alternate < num4)
            {
                ++alternate;
                TileObjectData tileData2 = TileObjectData.GetTileData(type, style, alternate);
                if (tileData2.Direction == TileObjectDirection.None || (tileData2.Direction != TileObjectDirection.PlaceLeft || dir != 1) && (tileData2.Direction != TileObjectDirection.PlaceRight || dir != -1))
                {
                    int num8 = x - (int)tileData2.Origin.X;
                    int num9 = y - (int)tileData2.Origin.Y;
                    if (num8 < 5 || num8 + tileData2.Width > Main.maxTilesX - 5 || (num9 < 5 || num9 + tileData2.Height > Main.maxTilesY - 5))
                    {
                        return(false);
                    }
                    Rectangle rectangle;
                    // ISSUE: explicit reference operation
                    ((Rectangle)@rectangle).\u002Ector(0, 0, tileData2.Width, tileData2.Height);
                    int X = 0;
                    int Y = 0;
                    if (tileData2.AnchorTop.tileCount != 0)
                    {
                        if (rectangle.Y == null)
                        {
                            rectangle.Y = (__Null) - 1;
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Height + 1;
                            // ISSUE: explicit reference operation
                            (^ local).Height = (__Null)num10;
                            ++Y;
                        }
                        int checkStart = tileData2.AnchorTop.checkStart;
                        if (checkStart < rectangle.X)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Width + (rectangle.X - checkStart);
                            // ISSUE: explicit reference operation
                            (^ local).Width = (__Null)num10;
                            X          += rectangle.X - checkStart;
                            rectangle.X = (__Null)checkStart;
                        }
                        int num11 = checkStart + tileData2.AnchorTop.tileCount - 1;
                        int num12 = rectangle.X + rectangle.Width - 1;
                        if (num11 > num12)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Width + (num11 - num12);
                            // ISSUE: explicit reference operation
                            (^ local).Width = (__Null)num10;
                        }
                    }
                    if (tileData2.AnchorBottom.tileCount != 0)
                    {
                        if (rectangle.Y + rectangle.Height == tileData2.Height)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Height + 1;
                            // ISSUE: explicit reference operation
                            (^ local).Height = (__Null)num10;
                        }
                        int checkStart = tileData2.AnchorBottom.checkStart;
                        if (checkStart < rectangle.X)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Width + (rectangle.X - checkStart);
                            // ISSUE: explicit reference operation
                            (^ local).Width = (__Null)num10;
                            X          += rectangle.X - checkStart;
                            rectangle.X = (__Null)checkStart;
                        }
                        int num11 = checkStart + tileData2.AnchorBottom.tileCount - 1;
                        int num12 = rectangle.X + rectangle.Width - 1;
                        if (num11 > num12)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Width + (num11 - num12);
                            // ISSUE: explicit reference operation
                            (^ local).Width = (__Null)num10;
                        }
                    }
                    if (tileData2.AnchorLeft.tileCount != 0)
                    {
                        if (rectangle.X == null)
                        {
                            rectangle.X = (__Null) - 1;
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Width + 1;
                            // ISSUE: explicit reference operation
                            (^ local).Width = (__Null)num10;
                            ++X;
                        }
                        int checkStart = tileData2.AnchorLeft.checkStart;
                        if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            --checkStart;
                        }
                        if (checkStart < rectangle.Y)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Width + (rectangle.Y - checkStart);
                            // ISSUE: explicit reference operation
                            (^ local).Width = (__Null)num10;
                            Y          += rectangle.Y - checkStart;
                            rectangle.Y = (__Null)checkStart;
                        }
                        int num11 = checkStart + tileData2.AnchorLeft.tileCount - 1;
                        if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            num11 += 2;
                        }
                        int num12 = rectangle.Y + rectangle.Height - 1;
                        if (num11 > num12)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Height + (num11 - num12);
                            // ISSUE: explicit reference operation
                            (^ local).Height = (__Null)num10;
                        }
                    }
                    if (tileData2.AnchorRight.tileCount != 0)
                    {
                        if (rectangle.X + rectangle.Width == tileData2.Width)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Width + 1;
                            // ISSUE: explicit reference operation
                            (^ local).Width = (__Null)num10;
                        }
                        int checkStart = tileData2.AnchorLeft.checkStart;
                        if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            --checkStart;
                        }
                        if (checkStart < rectangle.Y)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Width + (rectangle.Y - checkStart);
                            // ISSUE: explicit reference operation
                            (^ local).Width = (__Null)num10;
                            Y          += rectangle.Y - checkStart;
                            rectangle.Y = (__Null)checkStart;
                        }
                        int num11 = checkStart + tileData2.AnchorRight.tileCount - 1;
                        if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            num11 += 2;
                        }
                        int num12 = rectangle.Y + rectangle.Height - 1;
                        if (num11 > num12)
                        {
                            // ISSUE: explicit reference operation
                            // ISSUE: variable of a reference type
                            Rectangle& local = @rectangle;
                            // ISSUE: explicit reference operation
                            int num10 = (^ local).Height + (num11 - num12);
                            // ISSUE: explicit reference operation
                            (^ local).Height = (__Null)num10;
                        }
                    }
                    if (onlyCheck)
                    {
                        TileObject.objectPreview.Reset();
                        TileObject.objectPreview.Active      = true;
                        TileObject.objectPreview.Type        = (ushort)type;
                        TileObject.objectPreview.Style       = (short)style;
                        TileObject.objectPreview.Alternate   = alternate;
                        TileObject.objectPreview.Size        = new Point16((int)rectangle.Width, (int)rectangle.Height);
                        TileObject.objectPreview.ObjectStart = new Point16(X, Y);
                        TileObject.objectPreview.Coordinates = new Point16(num8 - X, num9 - Y);
                    }
                    float num13 = 0.0f;
                    float num14 = (float)(tileData2.Width * tileData2.Height);
                    float num15 = 0.0f;
                    float num16 = 0.0f;
                    for (int index1 = 0; index1 < tileData2.Width; ++index1)
                    {
                        for (int index2 = 0; index2 < tileData2.Height; ++index2)
                        {
                            Tile tileSafely = Framing.GetTileSafely(num8 + index1, num9 + index2);
                            bool flag2      = !tileData2.LiquidPlace(tileSafely);
                            bool flag3      = false;
                            if (tileData2.AnchorWall)
                            {
                                ++num16;
                                if (!tileData2.isValidWallAnchor((int)tileSafely.wall))
                                {
                                    flag3 = true;
                                }
                                else
                                {
                                    ++num15;
                                }
                            }
                            bool flag4 = false;
                            if (tileSafely.active() && !Main.tileCut[(int)tileSafely.type])
                            {
                                flag4 = true;
                            }
                            if (flag4 || flag2 || flag3)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[index1 + X, index2 + Y] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[index1 + X, index2 + Y] = 1;
                                }
                                ++num13;
                            }
                        }
                    }
                    AnchorData anchorBottom = tileData2.AnchorBottom;
                    if (anchorBottom.tileCount != 0)
                    {
                        num16 += (float)anchorBottom.tileCount;
                        int height = tileData2.Height;
                        for (int index = 0; index < anchorBottom.tileCount; ++index)
                        {
                            int  num10      = anchorBottom.checkStart + index;
                            Tile tileSafely = Framing.GetTileSafely(num8 + num10, num9 + height);
                            bool flag2      = false;
                            if (tileSafely.nactive())
                            {
                                if ((anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile && Main.tileSolid[(int)tileSafely.type] && (!Main.tileSolidTop[(int)tileSafely.type] && !Main.tileNoAttach[(int)tileSafely.type]) && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                                {
                                    flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                }
                                if (!flag2 && ((anchorBottom.type & AnchorType.SolidWithTop) == AnchorType.SolidWithTop || (anchorBottom.type & AnchorType.Table) == AnchorType.Table))
                                {
                                    if (TileID.Sets.Platforms[(int)tileSafely.type])
                                    {
                                        int num11 = (int)tileSafely.frameX / TileObjectData.PlatformFrameWidth();
                                        if (!tileSafely.halfBrick() && num11 >= 0 && num11 <= 7 || (num11 >= 12 && num11 <= 16 || num11 >= 25 && num11 <= 26))
                                        {
                                            flag2 = true;
                                        }
                                    }
                                    else if (Main.tileSolid[(int)tileSafely.type] && Main.tileSolidTop[(int)tileSafely.type])
                                    {
                                        flag2 = true;
                                    }
                                }
                                if (!flag2 && (anchorBottom.type & AnchorType.Table) == AnchorType.Table && (!TileID.Sets.Platforms[(int)tileSafely.type] && Main.tileTable[(int)tileSafely.type]) && tileSafely.blockType() == 0)
                                {
                                    flag2 = true;
                                }
                                if (!flag2 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type]))
                                {
                                    switch (tileSafely.blockType())
                                    {
                                    case 4:
                                    case 5:
                                        flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                        break;
                                    }
                                }
                                if (!flag2 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely.type))
                                {
                                    flag2 = true;
                                }
                            }
                            else if (!flag2 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag2 = true;
                            }
                            if (!flag2)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num10 + X, height + Y] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num10 + X, height + Y] = 1;
                                }
                                ++num15;
                            }
                        }
                    }
                    AnchorData anchorTop = tileData2.AnchorTop;
                    if (anchorTop.tileCount != 0)
                    {
                        num16 += (float)anchorTop.tileCount;
                        int num10 = -1;
                        for (int index = 0; index < anchorTop.tileCount; ++index)
                        {
                            int  num11      = anchorTop.checkStart + index;
                            Tile tileSafely = Framing.GetTileSafely(num8 + num11, num9 + num10);
                            bool flag2      = false;
                            if (tileSafely.nactive())
                            {
                                if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && !Main.tileNoAttach[(int)tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                                {
                                    flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                }
                                if (!flag2 && (anchorTop.type & AnchorType.SolidBottom) == AnchorType.SolidBottom && (Main.tileSolid[(int)tileSafely.type] && (!Main.tileSolidTop[(int)tileSafely.type] || TileID.Sets.Platforms[(int)tileSafely.type] && (tileSafely.halfBrick() || tileSafely.topSlope())) || (tileSafely.halfBrick() || tileSafely.topSlope())) && (!TileID.Sets.NotReallySolid[(int)tileSafely.type] && !tileSafely.bottomSlope()))
                                {
                                    flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                }
                                if (!flag2 && (anchorTop.type & AnchorType.SolidSide) == AnchorType.SolidSide && (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type]))
                                {
                                    switch (tileSafely.blockType())
                                    {
                                    case 2:
                                    case 3:
                                        flag2 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                        break;
                                    }
                                }
                                if (!flag2 && (anchorTop.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely.type))
                                {
                                    flag2 = true;
                                }
                            }
                            else if (!flag2 && (anchorTop.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag2 = true;
                            }
                            if (!flag2)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num11 + X, num10 + Y] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num11 + X, num10 + Y] = 1;
                                }
                                ++num15;
                            }
                        }
                    }
                    AnchorData anchorRight = tileData2.AnchorRight;
                    if (anchorRight.tileCount != 0)
                    {
                        num16 += (float)anchorRight.tileCount;
                        int width = tileData2.Width;
                        for (int index = 0; index < anchorRight.tileCount; ++index)
                        {
                            int  num10       = anchorRight.checkStart + index;
                            Tile tileSafely1 = Framing.GetTileSafely(num8 + width, num9 + num10);
                            bool flag2       = false;
                            if (tileSafely1.nactive())
                            {
                                if (Main.tileSolid[(int)tileSafely1.type] && !Main.tileSolidTop[(int)tileSafely1.type] && !Main.tileNoAttach[(int)tileSafely1.type] && (tileData2.FlattenAnchors || tileSafely1.blockType() == 0))
                                {
                                    flag2 = tileData2.isValidTileAnchor((int)tileSafely1.type);
                                }
                                if (!flag2 && (anchorRight.type & AnchorType.SolidSide) == AnchorType.SolidSide && (Main.tileSolid[(int)tileSafely1.type] && !Main.tileSolidTop[(int)tileSafely1.type]))
                                {
                                    switch (tileSafely1.blockType())
                                    {
                                    case 2:
                                    case 4:
                                        flag2 = tileData2.isValidTileAnchor((int)tileSafely1.type);
                                        break;
                                    }
                                }
                                if (!flag2 && (anchorRight.type & AnchorType.Tree) == AnchorType.Tree && (int)tileSafely1.type == 5)
                                {
                                    flag2 = true;
                                    if (index == 0)
                                    {
                                        ++num16;
                                        Tile tileSafely2 = Framing.GetTileSafely(num8 + width, num9 + num10 - 1);
                                        if (tileSafely2.nactive() && (int)tileSafely2.type == 5)
                                        {
                                            ++num15;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[width + X, num10 + Y - 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[width + X, num10 + Y - 1] = 2;
                                        }
                                    }
                                    if (index == anchorRight.tileCount - 1)
                                    {
                                        ++num16;
                                        Tile tileSafely2 = Framing.GetTileSafely(num8 + width, num9 + num10 + 1);
                                        if (tileSafely2.nactive() && (int)tileSafely2.type == 5)
                                        {
                                            ++num15;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[width + X, num10 + Y + 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[width + X, num10 + Y + 1] = 2;
                                        }
                                    }
                                }
                                if (!flag2 && (anchorRight.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely1.type))
                                {
                                    flag2 = true;
                                }
                            }
                            else if (!flag2 && (anchorRight.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag2 = true;
                            }
                            if (!flag2)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[width + X, num10 + Y] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[width + X, num10 + Y] = 1;
                                }
                                ++num15;
                            }
                        }
                    }
                    AnchorData anchorLeft = tileData2.AnchorLeft;
                    if (anchorLeft.tileCount != 0)
                    {
                        num16 += (float)anchorLeft.tileCount;
                        int num10 = -1;
                        for (int index = 0; index < anchorLeft.tileCount; ++index)
                        {
                            int  num11       = anchorLeft.checkStart + index;
                            Tile tileSafely1 = Framing.GetTileSafely(num8 + num10, num9 + num11);
                            bool flag2       = false;
                            if (tileSafely1.nactive())
                            {
                                if (Main.tileSolid[(int)tileSafely1.type] && !Main.tileSolidTop[(int)tileSafely1.type] && !Main.tileNoAttach[(int)tileSafely1.type] && (tileData2.FlattenAnchors || tileSafely1.blockType() == 0))
                                {
                                    flag2 = tileData2.isValidTileAnchor((int)tileSafely1.type);
                                }
                                if (!flag2 && (anchorLeft.type & AnchorType.SolidSide) == AnchorType.SolidSide && (Main.tileSolid[(int)tileSafely1.type] && !Main.tileSolidTop[(int)tileSafely1.type]))
                                {
                                    switch (tileSafely1.blockType())
                                    {
                                    case 3:
                                    case 5:
                                        flag2 = tileData2.isValidTileAnchor((int)tileSafely1.type);
                                        break;
                                    }
                                }
                                if (!flag2 && (anchorLeft.type & AnchorType.Tree) == AnchorType.Tree && (int)tileSafely1.type == 5)
                                {
                                    flag2 = true;
                                    if (index == 0)
                                    {
                                        ++num16;
                                        Tile tileSafely2 = Framing.GetTileSafely(num8 + num10, num9 + num11 - 1);
                                        if (tileSafely2.nactive() && (int)tileSafely2.type == 5)
                                        {
                                            ++num15;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[num10 + X, num11 + Y - 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[num10 + X, num11 + Y - 1] = 2;
                                        }
                                    }
                                    if (index == anchorLeft.tileCount - 1)
                                    {
                                        ++num16;
                                        Tile tileSafely2 = Framing.GetTileSafely(num8 + num10, num9 + num11 + 1);
                                        if (tileSafely2.nactive() && (int)tileSafely2.type == 5)
                                        {
                                            ++num15;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[num10 + X, num11 + Y + 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[num10 + X, num11 + Y + 1] = 2;
                                        }
                                    }
                                }
                                if (!flag2 && (anchorLeft.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely1.type))
                                {
                                    flag2 = true;
                                }
                            }
                            else if (!flag2 && (anchorLeft.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag2 = true;
                            }
                            if (!flag2)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num10 + X, num11 + Y] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num10 + X, num11 + Y] = 1;
                                }
                                ++num15;
                            }
                        }
                    }
                    if (tileData2.HookCheck.hook != null)
                    {
                        if (tileData2.HookCheck.processedCoordinates)
                        {
                            int x1 = (int)tileData2.Origin.X;
                            int y1 = (int)tileData2.Origin.Y;
                        }
                        if (tileData2.HookCheck.hook.Invoke(x, y, type, style, dir) == tileData2.HookCheck.badReturn && tileData2.HookCheck.badResponse == 0)
                        {
                            num15 = 0.0f;
                            num13 = 0.0f;
                            TileObject.objectPreview.AllInvalid();
                        }
                    }
                    float num17 = num15 / num16;
                    float num18 = num13 / num14;
                    if ((double)num18 == 1.0 && (double)num16 == 0.0)
                    {
                        num17 = 1f;
                        num18 = 1f;
                    }
                    if ((double)num17 == 1.0 && (double)num18 == 1.0)
                    {
                        num5           = 1f;
                        num6           = 1f;
                        num7           = alternate;
                        tileObjectData = tileData2;
                        break;
                    }
                    if ((double)num17 > (double)num5 || (double)num17 == (double)num5 && (double)num18 > (double)num6)
                    {
                        TileObjectPreviewData.placementCache.CopyFrom(TileObject.objectPreview);
                        num5           = num17;
                        num6           = num18;
                        tileObjectData = tileData2;
                        num7           = alternate;
                    }
                }
            }
            int num19 = -1;

            if (flag1)
            {
                if (TileObjectPreviewData.randomCache == null)
                {
                    TileObjectPreviewData.randomCache = new TileObjectPreviewData();
                }
                bool flag2 = false;
                if ((int)TileObjectPreviewData.randomCache.Type == type)
                {
                    Point16 coordinates = TileObjectPreviewData.randomCache.Coordinates;
                    Point16 objectStart = TileObjectPreviewData.randomCache.ObjectStart;
                    int     num8        = (int)coordinates.X + (int)objectStart.X;
                    int     num9        = (int)coordinates.Y + (int)objectStart.Y;
                    int     num10       = x - (int)tileData1.Origin.X;
                    int     num11       = y - (int)tileData1.Origin.Y;
                    if (num8 != num10 || num9 != num11)
                    {
                        flag2 = true;
                    }
                }
                else
                {
                    flag2 = true;
                }
                num19 = !flag2 ? TileObjectPreviewData.randomCache.Random : Main.rand.Next(tileData1.RandomStyleRange);
            }
            if (onlyCheck)
            {
                if ((double)num5 != 1.0 || (double)num6 != 1.0)
                {
                    TileObject.objectPreview.CopyFrom(TileObjectPreviewData.placementCache);
                    alternate = num7;
                }
                TileObject.objectPreview.Random = num19;
                if (tileData1.RandomStyleRange > 0)
                {
                    TileObjectPreviewData.randomCache.CopyFrom(TileObject.objectPreview);
                }
            }
            if (!onlyCheck)
            {
                objectData.xCoord    = x - (int)tileObjectData.Origin.X;
                objectData.yCoord    = y - (int)tileObjectData.Origin.Y;
                objectData.type      = type;
                objectData.style     = style;
                objectData.alternate = alternate;
                objectData.random    = num19;
            }
            if ((double)num5 == 1.0)
            {
                return((double)num6 == 1.0);
            }
            return(false);
        }
Example #6
0
 public static bool AnchorValid(Tile tileCache, AnchorType anchor)
 {
     bool flag = false;
     if (tileCache.nactive())
     {
         if ((anchor & AnchorType.SolidTile) == AnchorType.SolidTile && Main.tileSolid[(int)tileCache.type] && !Main.tileSolidTop[(int)tileCache.type] && !Main.tileNoAttach[(int)tileCache.type] && tileCache.blockType() == 0)
         {
             flag = true;
         }
         if ((anchor & AnchorType.SolidBottom) == AnchorType.SolidBottom && !Main.tileNoAttach[(int)tileCache.type] && ((Main.tileSolid[(int)tileCache.type] && (!Main.tileSolidTop[(int)tileCache.type] || (tileCache.type == 19 && (tileCache.halfBrick() || tileCache.topSlope())))) || tileCache.topSlope() || tileCache.halfBrick()) && !TileID.Sets.NotReallySolid[(int)tileCache.type] && !tileCache.bottomSlope())
         {
             flag = true;
         }
         if (!flag && ((anchor & AnchorType.SolidWithTop) == AnchorType.SolidWithTop || (anchor & AnchorType.Table) == AnchorType.Table))
         {
             if (tileCache.type == 19)
             {
                 int num = (int)tileCache.frameX / TileObjectData.PlatformFrameWidth();
                 if ((!tileCache.halfBrick() && num >= 0 && num <= 7) || (num >= 12 && num <= 16) || (num >= 25 && num <= 26))
                 {
                     flag = true;
                 }
             }
             else if (Main.tileSolid[(int)tileCache.type] && Main.tileSolidTop[(int)tileCache.type])
             {
                 flag = true;
             }
         }
         if (!flag && (anchor & AnchorType.Table) == AnchorType.Table && tileCache.type != 19 && Main.tileTable[(int)tileCache.type] && tileCache.blockType() == 0)
         {
             flag = true;
         }
         if (!flag && (anchor & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[(int)tileCache.type] && !Main.tileSolidTop[(int)tileCache.type])
         {
             switch (tileCache.blockType())
             {
                 case 4:
                 case 5:
                     flag = true;
                     break;
             }
         }
     }
     else if (!flag && (anchor & AnchorType.EmptyTile) == AnchorType.EmptyTile)
     {
         flag = true;
     }
     return flag;
 }
Example #7
0
        public static bool CanPlace(int x, int y, int type, int style, int dir, out TileObject objectData, bool onlyCheck = false)
        {
            TileObjectData tileData = TileObjectData.GetTileData(type, style);

            objectData = Empty;
            if (tileData == null)
            {
                return(false);
            }
            int num  = x - tileData.Origin.X;
            int num2 = y - tileData.Origin.Y;

            if (num < 0 || num + tileData.Width >= Main.maxTilesX || num2 < 0 || num2 + tileData.Height >= Main.maxTilesY)
            {
                return(false);
            }
            bool flag = tileData.RandomStyleRange > 0;

            if (TileObjectPreviewData.placementCache == null)
            {
                TileObjectPreviewData.placementCache = new TileObjectPreviewData();
            }
            TileObjectPreviewData.placementCache.Reset();
            int num3 = 0;
            int num4 = 0;

            if (tileData.AlternatesCount != 0)
            {
                num4 = tileData.AlternatesCount;
            }
            float          num5           = -1f;
            float          num6           = -1f;
            int            num7           = 0;
            TileObjectData tileObjectData = null;
            int            num8           = num3 - 1;

            while (num8 < num4)
            {
                num8++;
                TileObjectData tileData2 = TileObjectData.GetTileData(type, style, num8);
                if (tileData2.Direction != 0 && ((tileData2.Direction == TileObjectDirection.PlaceLeft && dir == 1) || (tileData2.Direction == TileObjectDirection.PlaceRight && dir == -1)))
                {
                    continue;
                }
                int num9  = x - tileData2.Origin.X;
                int num10 = y - tileData2.Origin.Y;
                if (num9 < 5 || num9 + tileData2.Width > Main.maxTilesX - 5 || num10 < 5 || num10 + tileData2.Height > Main.maxTilesY - 5)
                {
                    return(false);
                }
                Rectangle rectangle = new Rectangle(0, 0, tileData2.Width, tileData2.Height);
                int       num11     = 0;
                int       num12     = 0;
                if (tileData2.AnchorTop.tileCount != 0)
                {
                    if (rectangle.Y == 0)
                    {
                        rectangle.Y = -1;
                        rectangle.Height++;
                        num12++;
                    }
                    int checkStart = tileData2.AnchorTop.checkStart;
                    if (checkStart < rectangle.X)
                    {
                        rectangle.Width += rectangle.X - checkStart;
                        num11           += rectangle.X - checkStart;
                        rectangle.X      = checkStart;
                    }
                    int num13 = checkStart + tileData2.AnchorTop.tileCount - 1;
                    int num14 = rectangle.X + rectangle.Width - 1;
                    if (num13 > num14)
                    {
                        rectangle.Width += num13 - num14;
                    }
                }
                if (tileData2.AnchorBottom.tileCount != 0)
                {
                    if (rectangle.Y + rectangle.Height == tileData2.Height)
                    {
                        rectangle.Height++;
                    }
                    int checkStart2 = tileData2.AnchorBottom.checkStart;
                    if (checkStart2 < rectangle.X)
                    {
                        rectangle.Width += rectangle.X - checkStart2;
                        num11           += rectangle.X - checkStart2;
                        rectangle.X      = checkStart2;
                    }
                    int num15 = checkStart2 + tileData2.AnchorBottom.tileCount - 1;
                    int num16 = rectangle.X + rectangle.Width - 1;
                    if (num15 > num16)
                    {
                        rectangle.Width += num15 - num16;
                    }
                }
                if (tileData2.AnchorLeft.tileCount != 0)
                {
                    if (rectangle.X == 0)
                    {
                        rectangle.X = -1;
                        rectangle.Width++;
                        num11++;
                    }
                    int num17 = tileData2.AnchorLeft.checkStart;
                    if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
                    {
                        num17--;
                    }
                    if (num17 < rectangle.Y)
                    {
                        rectangle.Width += rectangle.Y - num17;
                        num12           += rectangle.Y - num17;
                        rectangle.Y      = num17;
                    }
                    int num18 = num17 + tileData2.AnchorLeft.tileCount - 1;
                    if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
                    {
                        num18 += 2;
                    }
                    int num19 = rectangle.Y + rectangle.Height - 1;
                    if (num18 > num19)
                    {
                        rectangle.Height += num18 - num19;
                    }
                }
                if (tileData2.AnchorRight.tileCount != 0)
                {
                    if (rectangle.X + rectangle.Width == tileData2.Width)
                    {
                        rectangle.Width++;
                    }
                    int num20 = tileData2.AnchorLeft.checkStart;
                    if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
                    {
                        num20--;
                    }
                    if (num20 < rectangle.Y)
                    {
                        rectangle.Width += rectangle.Y - num20;
                        num12           += rectangle.Y - num20;
                        rectangle.Y      = num20;
                    }
                    int num21 = num20 + tileData2.AnchorRight.tileCount - 1;
                    if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
                    {
                        num21 += 2;
                    }
                    int num22 = rectangle.Y + rectangle.Height - 1;
                    if (num21 > num22)
                    {
                        rectangle.Height += num21 - num22;
                    }
                }
                if (onlyCheck)
                {
                    objectPreview.Reset();
                    objectPreview.Active      = true;
                    objectPreview.Type        = (ushort)type;
                    objectPreview.Style       = (short)style;
                    objectPreview.Alternate   = num8;
                    objectPreview.Size        = new Point16(rectangle.Width, rectangle.Height);
                    objectPreview.ObjectStart = new Point16(num11, num12);
                    objectPreview.Coordinates = new Point16(num9 - num11, num10 - num12);
                }
                float num23 = 0f;
                float num24 = tileData2.Width * tileData2.Height;
                float num25 = 0f;
                float num26 = 0f;
                for (int i = 0; i < tileData2.Width; i++)
                {
                    for (int j = 0; j < tileData2.Height; j++)
                    {
                        Tile tileSafely = Framing.GetTileSafely(num9 + i, num10 + j);
                        bool flag2      = !tileData2.LiquidPlace(tileSafely);
                        bool flag3      = false;
                        if (tileData2.AnchorWall)
                        {
                            num26 += 1f;
                            if (!tileData2.isValidWallAnchor(tileSafely.wall))
                            {
                                flag3 = true;
                            }
                            else
                            {
                                num25 += 1f;
                            }
                        }
                        bool flag4 = false;
                        if (tileSafely.active() && !Main.tileCut[tileSafely.type])
                        {
                            flag4 = true;
                        }
                        if (flag4 || flag2 || flag3)
                        {
                            if (onlyCheck)
                            {
                                objectPreview[i + num11, j + num12] = 2;
                            }
                            continue;
                        }
                        if (onlyCheck)
                        {
                            objectPreview[i + num11, j + num12] = 1;
                        }
                        num23 += 1f;
                    }
                }
                AnchorData anchorBottom = tileData2.AnchorBottom;
                if (anchorBottom.tileCount != 0)
                {
                    num26 += (float)anchorBottom.tileCount;
                    int height = tileData2.Height;
                    for (int k = 0; k < anchorBottom.tileCount; k++)
                    {
                        int  num27      = anchorBottom.checkStart + k;
                        Tile tileSafely = Framing.GetTileSafely(num9 + num27, num10 + height);
                        bool flag5      = false;
                        if (tileSafely.nactive())
                        {
                            if ((anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                            {
                                flag5 = tileData2.isValidTileAnchor(tileSafely.type);
                            }
                            if (!flag5 && ((anchorBottom.type & AnchorType.SolidWithTop) == AnchorType.SolidWithTop || (anchorBottom.type & AnchorType.Table) == AnchorType.Table))
                            {
                                if (tileSafely.type == 19)
                                {
                                    int num28 = tileSafely.frameX / TileObjectData.PlatformFrameWidth();
                                    if ((!tileSafely.halfBrick() && num28 >= 0 && num28 <= 7) || (num28 >= 12 && num28 <= 16) || (num28 >= 25 && num28 <= 26))
                                    {
                                        flag5 = true;
                                    }
                                }
                                else if (Main.tileSolid[tileSafely.type] && Main.tileSolidTop[tileSafely.type])
                                {
                                    flag5 = true;
                                }
                            }
                            if (!flag5 && (anchorBottom.type & AnchorType.Table) == AnchorType.Table && tileSafely.type != 19 && Main.tileTable[tileSafely.type] && tileSafely.blockType() == 0)
                            {
                                flag5 = true;
                            }
                            if (!flag5 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
                            {
                                switch (tileSafely.blockType())
                                {
                                case 4:
                                case 5:
                                    flag5 = tileData2.isValidTileAnchor(tileSafely.type);
                                    break;
                                }
                            }
                            if (!flag5 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor(tileSafely.type))
                            {
                                flag5 = true;
                            }
                        }
                        else if (!flag5 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                        {
                            flag5 = true;
                        }
                        if (!flag5)
                        {
                            if (onlyCheck)
                            {
                                objectPreview[num27 + num11, height + num12] = 2;
                            }
                            continue;
                        }
                        if (onlyCheck)
                        {
                            objectPreview[num27 + num11, height + num12] = 1;
                        }
                        num25 += 1f;
                    }
                }
                anchorBottom = tileData2.AnchorTop;
                if (anchorBottom.tileCount != 0)
                {
                    num26 += (float)anchorBottom.tileCount;
                    int num29 = -1;
                    for (int l = 0; l < anchorBottom.tileCount; l++)
                    {
                        int  num30      = anchorBottom.checkStart + l;
                        Tile tileSafely = Framing.GetTileSafely(num9 + num30, num10 + num29);
                        bool flag6      = false;
                        if (tileSafely.nactive())
                        {
                            if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                            {
                                flag6 = tileData2.isValidTileAnchor(tileSafely.type);
                            }
                            if (!flag6 && (anchorBottom.type & AnchorType.SolidBottom) == AnchorType.SolidBottom && ((Main.tileSolid[tileSafely.type] && (!Main.tileSolidTop[tileSafely.type] || (tileSafely.type == 19 && (tileSafely.halfBrick() || tileSafely.topSlope())))) || tileSafely.halfBrick() || tileSafely.topSlope()) && !TileID.Sets.NotReallySolid[tileSafely.type] && !tileSafely.bottomSlope())
                            {
                                flag6 = tileData2.isValidTileAnchor(tileSafely.type);
                            }
                            if (!flag6 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
                            {
                                switch (tileSafely.blockType())
                                {
                                case 2:
                                case 3:
                                    flag6 = tileData2.isValidTileAnchor(tileSafely.type);
                                    break;
                                }
                            }
                            if (!flag6 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor(tileSafely.type))
                            {
                                flag6 = true;
                            }
                        }
                        else if (!flag6 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                        {
                            flag6 = true;
                        }
                        if (!flag6)
                        {
                            if (onlyCheck)
                            {
                                objectPreview[num30 + num11, num29 + num12] = 2;
                            }
                            continue;
                        }
                        if (onlyCheck)
                        {
                            objectPreview[num30 + num11, num29 + num12] = 1;
                        }
                        num25 += 1f;
                    }
                }
                anchorBottom = tileData2.AnchorRight;
                if (anchorBottom.tileCount != 0)
                {
                    num26 += (float)anchorBottom.tileCount;
                    int width = tileData2.Width;
                    for (int m = 0; m < anchorBottom.tileCount; m++)
                    {
                        int  num31      = anchorBottom.checkStart + m;
                        Tile tileSafely = Framing.GetTileSafely(num9 + width, num10 + num31);
                        bool flag7      = false;
                        if (tileSafely.nactive())
                        {
                            if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                            {
                                flag7 = tileData2.isValidTileAnchor(tileSafely.type);
                            }
                            if (!flag7 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
                            {
                                switch (tileSafely.blockType())
                                {
                                case 2:
                                case 4:
                                    flag7 = tileData2.isValidTileAnchor(tileSafely.type);
                                    break;
                                }
                            }
                            if (!flag7 && (anchorBottom.type & AnchorType.Tree) == AnchorType.Tree && tileSafely.type == 5)
                            {
                                flag7 = true;
                                if (m == 0)
                                {
                                    num26 += 1f;
                                    Tile tileSafely2 = Framing.GetTileSafely(num9 + width, num10 + num31 - 1);
                                    if (tileSafely2.nactive() && tileSafely2.type == 5)
                                    {
                                        num25 += 1f;
                                        if (onlyCheck)
                                        {
                                            objectPreview[width + num11, num31 + num12 - 1] = 1;
                                        }
                                    }
                                    else if (onlyCheck)
                                    {
                                        objectPreview[width + num11, num31 + num12 - 1] = 2;
                                    }
                                }
                                if (m == anchorBottom.tileCount - 1)
                                {
                                    num26 += 1f;
                                    Tile tileSafely3 = Framing.GetTileSafely(num9 + width, num10 + num31 + 1);
                                    if (tileSafely3.nactive() && tileSafely3.type == 5)
                                    {
                                        num25 += 1f;
                                        if (onlyCheck)
                                        {
                                            objectPreview[width + num11, num31 + num12 + 1] = 1;
                                        }
                                    }
                                    else if (onlyCheck)
                                    {
                                        objectPreview[width + num11, num31 + num12 + 1] = 2;
                                    }
                                }
                            }
                            if (!flag7 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor(tileSafely.type))
                            {
                                flag7 = true;
                            }
                        }
                        else if (!flag7 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                        {
                            flag7 = true;
                        }
                        if (!flag7)
                        {
                            if (onlyCheck)
                            {
                                objectPreview[width + num11, num31 + num12] = 2;
                            }
                            continue;
                        }
                        if (onlyCheck)
                        {
                            objectPreview[width + num11, num31 + num12] = 1;
                        }
                        num25 += 1f;
                    }
                }
                anchorBottom = tileData2.AnchorLeft;
                if (anchorBottom.tileCount != 0)
                {
                    num26 += (float)anchorBottom.tileCount;
                    int num32 = -1;
                    for (int n = 0; n < anchorBottom.tileCount; n++)
                    {
                        int  num33      = anchorBottom.checkStart + n;
                        Tile tileSafely = Framing.GetTileSafely(num9 + num32, num10 + num33);
                        bool flag8      = false;
                        if (tileSafely.nactive())
                        {
                            if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                            {
                                flag8 = tileData2.isValidTileAnchor(tileSafely.type);
                            }
                            if (!flag8 && (anchorBottom.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
                            {
                                switch (tileSafely.blockType())
                                {
                                case 3:
                                case 5:
                                    flag8 = tileData2.isValidTileAnchor(tileSafely.type);
                                    break;
                                }
                            }
                            if (!flag8 && (anchorBottom.type & AnchorType.Tree) == AnchorType.Tree && tileSafely.type == 5)
                            {
                                flag8 = true;
                                if (n == 0)
                                {
                                    num26 += 1f;
                                    Tile tileSafely4 = Framing.GetTileSafely(num9 + num32, num10 + num33 - 1);
                                    if (tileSafely4.nactive() && tileSafely4.type == 5)
                                    {
                                        num25 += 1f;
                                        if (onlyCheck)
                                        {
                                            objectPreview[num32 + num11, num33 + num12 - 1] = 1;
                                        }
                                    }
                                    else if (onlyCheck)
                                    {
                                        objectPreview[num32 + num11, num33 + num12 - 1] = 2;
                                    }
                                }
                                if (n == anchorBottom.tileCount - 1)
                                {
                                    num26 += 1f;
                                    Tile tileSafely5 = Framing.GetTileSafely(num9 + num32, num10 + num33 + 1);
                                    if (tileSafely5.nactive() && tileSafely5.type == 5)
                                    {
                                        num25 += 1f;
                                        if (onlyCheck)
                                        {
                                            objectPreview[num32 + num11, num33 + num12 + 1] = 1;
                                        }
                                    }
                                    else if (onlyCheck)
                                    {
                                        objectPreview[num32 + num11, num33 + num12 + 1] = 2;
                                    }
                                }
                            }
                            if (!flag8 && (anchorBottom.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor(tileSafely.type))
                            {
                                flag8 = true;
                            }
                        }
                        else if (!flag8 && (anchorBottom.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                        {
                            flag8 = true;
                        }
                        if (!flag8)
                        {
                            if (onlyCheck)
                            {
                                objectPreview[num32 + num11, num33 + num12] = 2;
                            }
                            continue;
                        }
                        if (onlyCheck)
                        {
                            objectPreview[num32 + num11, num33 + num12] = 1;
                        }
                        num25 += 1f;
                    }
                }
                if (tileData2.HookCheck.hook != null)
                {
                    if (tileData2.HookCheck.processedCoordinates)
                    {
                        short x2 = tileData2.Origin.X;
                        short y2 = tileData2.Origin.Y;
                    }
                    if (tileData2.HookCheck.hook(x, y, type, style, dir) == tileData2.HookCheck.badReturn && tileData2.HookCheck.badResponse == 0)
                    {
                        num25 = 0f;
                        num23 = 0f;
                        objectPreview.AllInvalid();
                    }
                }
                float num34 = num25 / num26;
                float num35 = num23 / num24;
                if (num34 == 1f && num35 == 1f)
                {
                    num5           = 1f;
                    num6           = 1f;
                    num7           = num8;
                    tileObjectData = tileData2;
                    break;
                }
                if (num34 > num5 || (num34 == num5 && num35 > num6))
                {
                    TileObjectPreviewData.placementCache.CopyFrom(objectPreview);
                    num5           = num34;
                    num6           = num35;
                    tileObjectData = tileData2;
                    num7           = num8;
                }
            }
            int num36 = -1;

            if (flag)
            {
                if (TileObjectPreviewData.randomCache == null)
                {
                    TileObjectPreviewData.randomCache = new TileObjectPreviewData();
                }
                bool flag9 = false;
                if (TileObjectPreviewData.randomCache.Type == type)
                {
                    Point16 coordinates = TileObjectPreviewData.randomCache.Coordinates;
                    Point16 objectStart = TileObjectPreviewData.randomCache.ObjectStart;
                    int     num37       = coordinates.X + objectStart.X;
                    int     num38       = coordinates.Y + objectStart.Y;
                    int     num39       = x - tileData.Origin.X;
                    int     num40       = y - tileData.Origin.Y;
                    if (num37 != num39 || num38 != num40)
                    {
                        flag9 = true;
                    }
                }
                else
                {
                    flag9 = true;
                }
                num36 = ((!flag9) ? TileObjectPreviewData.randomCache.Random : Main.rand.Next(tileData.RandomStyleRange));
            }
            if (onlyCheck)
            {
                if (num5 != 1f || num6 != 1f)
                {
                    objectPreview.CopyFrom(TileObjectPreviewData.placementCache);
                    num8 = num7;
                }
                objectPreview.Random = num36;
                if (tileData.RandomStyleRange > 0)
                {
                    TileObjectPreviewData.randomCache.CopyFrom(objectPreview);
                }
            }
            if (!onlyCheck)
            {
                objectData.xCoord    = x - tileObjectData.Origin.X;
                objectData.yCoord    = y - tileObjectData.Origin.Y;
                objectData.type      = type;
                objectData.style     = style;
                objectData.alternate = num8;
                objectData.random    = num36;
            }
            if (num5 == 1f)
            {
                return(num6 == 1f);
            }
            return(false);
        }
		public static bool CanPlace(int x, int y, int type, int style, int dir, out TileObject objectData, bool onlyCheck = false)
		{
			Tile tileSafely;
			TileObjectData tileData = TileObjectData.GetTileData(type, style, 0);
			objectData = TileObject.Empty;
			if (tileData == null)
			{
				return false;
			}
			int num = x - tileData.Origin.X;
			int num1 = y - tileData.Origin.Y;
			if (num < 0 || num + tileData.Width >= Main.maxTilesX || num1 < 0 || num1 + tileData.Height >= Main.maxTilesY)
			{
				return false;
			}
			bool randomStyleRange = tileData.RandomStyleRange > 0;
			if (TileObjectPreviewData.placementCache == null)
			{
				TileObjectPreviewData.placementCache = new TileObjectPreviewData();
			}
			TileObjectPreviewData.placementCache.Reset();
			int num2 = 0;
			int alternatesCount = 0;
			if (tileData.AlternatesCount != 0)
			{
				alternatesCount = tileData.AlternatesCount;
			}
			float single = -1f;
			float single1 = -1f;
			int num3 = 0;
			TileObjectData tileObjectDatum = null;
			int num4 = num2 - 1;
			while (num4 < alternatesCount)
			{
				num4++;
				TileObjectData tileData1 = TileObjectData.GetTileData(type, style, num4);
				if (tileData1.Direction != TileObjectDirection.None && (tileData1.Direction == TileObjectDirection.PlaceLeft && dir == 1 || tileData1.Direction == TileObjectDirection.PlaceRight && dir == -1))
				{
					continue;
				}
				int num5 = x - tileData1.Origin.X;
				int num6 = y - tileData1.Origin.Y;
				if (num5 < 5 || num5 + tileData1.Width > Main.maxTilesX - 5 || num6 < 5 || num6 + tileData1.Height > Main.maxTilesY - 5)
				{
					return false;
				}
				Rectangle rectangle = new Rectangle(0, 0, tileData1.Width, tileData1.Height);
				int num7 = 0;
				int num8 = 0;
				if (tileData1.AnchorTop.tileCount != 0)
				{
					if (rectangle.Y == 0)
					{
						rectangle.Y = -1;
						rectangle.Height = rectangle.Height + 1;
						num8++;
					}
					int anchorTop = tileData1.AnchorTop.checkStart;
					if (anchorTop < rectangle.X)
					{
						rectangle.Width = rectangle.Width + (rectangle.X - anchorTop);
						num7 = num7 + (rectangle.X - anchorTop);
						rectangle.X = anchorTop;
					}
					int anchorTop1 = anchorTop + tileData1.AnchorTop.tileCount - 1;
					int num9 = rectangle.X + rectangle.Width - 1;
					if (anchorTop1 > num9)
					{
						rectangle.Width = rectangle.Width + (anchorTop1 - num9);
					}
				}
				if (tileData1.AnchorBottom.tileCount != 0)
				{
					if (rectangle.Y + rectangle.Height == tileData1.Height)
					{
						rectangle.Height = rectangle.Height + 1;
					}
					int anchorBottom = tileData1.AnchorBottom.checkStart;
					if (anchorBottom < rectangle.X)
					{
						rectangle.Width = rectangle.Width + (rectangle.X - anchorBottom);
						num7 = num7 + (rectangle.X - anchorBottom);
						rectangle.X = anchorBottom;
					}
					int anchorBottom1 = anchorBottom + tileData1.AnchorBottom.tileCount - 1;
					int num10 = rectangle.X + rectangle.Width - 1;
					if (anchorBottom1 > num10)
					{
						rectangle.Width = rectangle.Width + (anchorBottom1 - num10);
					}
				}
				if (tileData1.AnchorLeft.tileCount != 0)
				{
					if (rectangle.X == 0)
					{
						rectangle.X = -1;
						rectangle.Width = rectangle.Width + 1;
						num7++;
					}
					int anchorLeft = tileData1.AnchorLeft.checkStart;
					if ((tileData1.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
					{
						anchorLeft--;
					}
					if (anchorLeft < rectangle.Y)
					{
						rectangle.Width = rectangle.Width + (rectangle.Y - anchorLeft);
						num8 = num8 + (rectangle.Y - anchorLeft);
						rectangle.Y = anchorLeft;
					}
					int anchorLeft1 = anchorLeft + tileData1.AnchorLeft.tileCount - 1;
					if ((tileData1.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
					{
						anchorLeft1 = anchorLeft1 + 2;
					}
					int num11 = rectangle.Y + rectangle.Height - 1;
					if (anchorLeft1 > num11)
					{
						rectangle.Height = rectangle.Height + (anchorLeft1 - num11);
					}
				}
				if (tileData1.AnchorRight.tileCount != 0)
				{
					if (rectangle.X + rectangle.Width == tileData1.Width)
					{
						rectangle.Width = rectangle.Width + 1;
					}
					int anchorLeft2 = tileData1.AnchorLeft.checkStart;
					if ((tileData1.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
					{
						anchorLeft2--;
					}
					if (anchorLeft2 < rectangle.Y)
					{
						rectangle.Width = rectangle.Width + (rectangle.Y - anchorLeft2);
						num8 = num8 + (rectangle.Y - anchorLeft2);
						rectangle.Y = anchorLeft2;
					}
					int anchorRight = anchorLeft2 + tileData1.AnchorRight.tileCount - 1;
					if ((tileData1.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
					{
						anchorRight = anchorRight + 2;
					}
					int num12 = rectangle.Y + rectangle.Height - 1;
					if (anchorRight > num12)
					{
						rectangle.Height = rectangle.Height + (anchorRight - num12);
					}
				}
				if (onlyCheck)
				{
					TileObject.objectPreview.Reset();
					TileObject.objectPreview.Active = true;
					TileObject.objectPreview.Type = (ushort)type;
					TileObject.objectPreview.Style = (short)style;
					TileObject.objectPreview.Alternate = num4;
					TileObject.objectPreview.Size = new Point16(rectangle.Width, rectangle.Height);
					TileObject.objectPreview.ObjectStart = new Point16(num7, num8);
					TileObject.objectPreview.Coordinates = new Point16(num5 - num7, num6 - num8);
				}
				float single2 = 0f;
				float width = (float)(tileData1.Width * tileData1.Height);
				float single3 = 0f;
				float single4 = 0f;
				for (int i = 0; i < tileData1.Width; i++)
				{
					for (int j = 0; j < tileData1.Height; j++)
					{
						tileSafely = Framing.GetTileSafely(num5 + i, num6 + j);
						bool flag = !tileData1.LiquidPlace(tileSafely);
						bool flag1 = false;
						if (tileData1.AnchorWall)
						{
							single4 = single4 + 1f;
							if (tileData1.isValidWallAnchor((int)tileSafely.wall))
							{
								single3 = single3 + 1f;
							}
							else
							{
								flag1 = true;
							}
						}
						bool flag2 = false;
						if (tileSafely.active() && !Main.tileCut[tileSafely.type])
						{
							flag2 = true;
						}
						if (!flag2 && !flag && !flag1)
						{
							if (onlyCheck)
							{
								TileObject.objectPreview[i + num7, j + num8] = 1;
							}
							single2 = single2 + 1f;
						}
						else if (onlyCheck)
						{
							TileObject.objectPreview[i + num7, j + num8] = 2;
						}
					}
				}
				AnchorData anchorDatum = tileData1.AnchorBottom;
				if (anchorDatum.tileCount != 0)
				{
					single4 = single4 + (float)anchorDatum.tileCount;
					int height = tileData1.Height;
					for (int k = 0; k < anchorDatum.tileCount; k++)
					{
						int num13 = anchorDatum.checkStart + k;
						tileSafely = Framing.GetTileSafely(num5 + num13, num6 + height);
						bool flag3 = false;
						if (tileSafely.nactive())
						{
							if ((anchorDatum.type & AnchorType.SolidTile) == AnchorType.SolidTile && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData1.FlattenAnchors || tileSafely.blockType() == 0))
							{
								flag3 = tileData1.isValidTileAnchor((int)tileSafely.type);
							}
							if (!flag3 && ((anchorDatum.type & AnchorType.SolidWithTop) == AnchorType.SolidWithTop || (anchorDatum.type & AnchorType.Table) == AnchorType.Table))
							{
								if (tileSafely.type == 19)
								{
									int num14 = tileSafely.frameX / TileObjectData.PlatformFrameWidth();
									if (!tileSafely.halfBrick() && num14 >= 0 && num14 <= 7 || num14 >= 12 && num14 <= 16 || num14 >= 25 && num14 <= 26)
									{
										flag3 = true;
									}
								}
								else if (Main.tileSolid[tileSafely.type] && Main.tileSolidTop[tileSafely.type])
								{
									flag3 = true;
								}
							}
							if (!flag3 && (anchorDatum.type & AnchorType.Table) == AnchorType.Table && tileSafely.type != 19 && Main.tileTable[tileSafely.type] && tileSafely.blockType() == 0)
							{
								flag3 = true;
							}
							if (!flag3 && (anchorDatum.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
							{
								switch (tileSafely.blockType())
								{
									case 4:
									case 5:
									{
										flag3 = tileData1.isValidTileAnchor((int)tileSafely.type);
										break;
									}
								}
							}
							if (!flag3 && (anchorDatum.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData1.isValidAlternateAnchor((int)tileSafely.type))
							{
								flag3 = true;
							}
						}
						else if (!flag3 && (anchorDatum.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
						{
							flag3 = true;
						}
						if (flag3)
						{
							if (onlyCheck)
							{
								TileObject.objectPreview[num13 + num7, height + num8] = 1;
							}
							single3 = single3 + 1f;
						}
						else if (onlyCheck)
						{
							TileObject.objectPreview[num13 + num7, height + num8] = 2;
						}
					}
				}
				anchorDatum = tileData1.AnchorTop;
				if (anchorDatum.tileCount != 0)
				{
					single4 = single4 + (float)anchorDatum.tileCount;
					int num15 = -1;
					for (int l = 0; l < anchorDatum.tileCount; l++)
					{
						int num16 = anchorDatum.checkStart + l;
						tileSafely = Framing.GetTileSafely(num5 + num16, num6 + num15);
						bool flag4 = false;
						if (tileSafely.nactive())
						{
							if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData1.FlattenAnchors || tileSafely.blockType() == 0))
							{
								flag4 = tileData1.isValidTileAnchor((int)tileSafely.type);
							}
							if (!flag4 && (anchorDatum.type & AnchorType.SolidBottom) == AnchorType.SolidBottom && (Main.tileSolid[tileSafely.type] && (!Main.tileSolidTop[tileSafely.type] || tileSafely.type == 19 && (tileSafely.halfBrick() || tileSafely.topSlope())) || tileSafely.halfBrick() || tileSafely.topSlope()) && !tileSafely.bottomSlope())
							{
								flag4 = tileData1.isValidTileAnchor((int)tileSafely.type);
							}
							if (!flag4 && (anchorDatum.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
							{
								switch (tileSafely.blockType())
								{
									case 2:
									case 3:
									{
										flag4 = tileData1.isValidTileAnchor((int)tileSafely.type);
										break;
									}
								}
							}
							if (!flag4 && (anchorDatum.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData1.isValidAlternateAnchor((int)tileSafely.type))
							{
								flag4 = true;
							}
						}
						else if (!flag4 && (anchorDatum.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
						{
							flag4 = true;
						}
						if (flag4)
						{
							if (onlyCheck)
							{
								TileObject.objectPreview[num16 + num7, num15 + num8] = 1;
							}
							single3 = single3 + 1f;
						}
						else if (onlyCheck)
						{
							TileObject.objectPreview[num16 + num7, num15 + num8] = 2;
						}
					}
				}
				anchorDatum = tileData1.AnchorRight;
				if (anchorDatum.tileCount != 0)
				{
					single4 = single4 + (float)anchorDatum.tileCount;
					int width1 = tileData1.Width;
					for (int m = 0; m < anchorDatum.tileCount; m++)
					{
						int num17 = anchorDatum.checkStart + m;
						tileSafely = Framing.GetTileSafely(num5 + width1, num6 + num17);
						bool flag5 = false;
						if (tileSafely.nactive())
						{
							if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData1.FlattenAnchors || tileSafely.blockType() == 0))
							{
								flag5 = tileData1.isValidTileAnchor((int)tileSafely.type);
							}
							if (!flag5 && (anchorDatum.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
							{
								switch (tileSafely.blockType())
								{
									case 2:
									case 4:
									{
										flag5 = tileData1.isValidTileAnchor((int)tileSafely.type);
										break;
									}
								}
							}
							if (!flag5 && (anchorDatum.type & AnchorType.Tree) == AnchorType.Tree && tileSafely.type == 5)
							{
								flag5 = true;
								if (m == 0)
								{
									single4 = single4 + 1f;
									Tile tile = Framing.GetTileSafely(num5 + width1, num6 + num17 - 1);
									if (tile.nactive() && tile.type == TileID.Trees)
									{
										single3 = single3 + 1f;
										if (onlyCheck)
										{
											TileObject.objectPreview[width1 + num7, num17 + num8 - 1] = 1;
										}
									}
									else if (onlyCheck)
									{
										TileObject.objectPreview[width1 + num7, num17 + num8 - 1] = 2;
									}
								}
								if (m == anchorDatum.tileCount - 1)
								{
									single4 = single4 + 1f;
									Tile tileSafely1 = Framing.GetTileSafely(num5 + width1, num6 + num17 + 1);
									if (tileSafely1.nactive() && tileSafely1.type == 5)
									{
										single3 = single3 + 1f;
										if (onlyCheck)
										{
											TileObject.objectPreview[width1 + num7, num17 + num8 + 1] = 1;
										}
									}
									else if (onlyCheck)
									{
										TileObject.objectPreview[width1 + num7, num17 + num8 + 1] = 2;
									}
								}
							}
							if (!flag5 && (anchorDatum.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData1.isValidAlternateAnchor((int)tileSafely.type))
							{
								flag5 = true;
							}
						}
						else if (!flag5 && (anchorDatum.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
						{
							flag5 = true;
						}
						if (flag5)
						{
							if (onlyCheck)
							{
								TileObject.objectPreview[width1 + num7, num17 + num8] = 1;
							}
							single3 = single3 + 1f;
						}
						else if (onlyCheck)
						{
							TileObject.objectPreview[width1 + num7, num17 + num8] = 2;
						}
					}
				}
				anchorDatum = tileData1.AnchorLeft;
				if (anchorDatum.tileCount != 0)
				{
					single4 = single4 + (float)anchorDatum.tileCount;
					int num18 = -1;
					for (int n = 0; n < anchorDatum.tileCount; n++)
					{
						int num19 = anchorDatum.checkStart + n;
						tileSafely = Framing.GetTileSafely(num5 + num18, num6 + num19);
						bool flag6 = false;
						if (tileSafely.nactive())
						{
							if (Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type] && !Main.tileNoAttach[tileSafely.type] && (tileData1.FlattenAnchors || tileSafely.blockType() == 0))
							{
								flag6 = tileData1.isValidTileAnchor((int)tileSafely.type);
							}
							if (!flag6 && (anchorDatum.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[tileSafely.type] && !Main.tileSolidTop[tileSafely.type])
							{
								switch (tileSafely.blockType())
								{
									case 3:
									case 5:
									{
										flag6 = tileData1.isValidTileAnchor((int)tileSafely.type);
										break;
									}
								}
							}
							if (!flag6 && (anchorDatum.type & AnchorType.Tree) == AnchorType.Tree && tileSafely.type == 5)
							{
								flag6 = true;
								if (n == 0)
								{
									single4 = single4 + 1f;
									Tile tile1 = Framing.GetTileSafely(num5 + num18, num6 + num19 - 1);
									if (tile1.nactive() && tile1.type == 5)
									{
										single3 = single3 + 1f;
										if (onlyCheck)
										{
											TileObject.objectPreview[num18 + num7, num19 + num8 - 1] = 1;
										}
									}
									else if (onlyCheck)
									{
										TileObject.objectPreview[num18 + num7, num19 + num8 - 1] = 2;
									}
								}
								if (n == anchorDatum.tileCount - 1)
								{
									single4 = single4 + 1f;
									Tile tileSafely2 = Framing.GetTileSafely(num5 + num18, num6 + num19 + 1);
									if (tileSafely2.nactive() && tileSafely2.type == 5)
									{
										single3 = single3 + 1f;
										if (onlyCheck)
										{
											TileObject.objectPreview[num18 + num7, num19 + num8 + 1] = 1;
										}
									}
									else if (onlyCheck)
									{
										TileObject.objectPreview[num18 + num7, num19 + num8 + 1] = 2;
									}
								}
							}
							if (!flag6 && (anchorDatum.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData1.isValidAlternateAnchor((int)tileSafely.type))
							{
								flag6 = true;
							}
						}
						else if (!flag6 && (anchorDatum.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
						{
							flag6 = true;
						}
						if (flag6)
						{
							if (onlyCheck)
							{
								TileObject.objectPreview[num18 + num7, num19 + num8] = 1;
							}
							single3 = single3 + 1f;
						}
						else if (onlyCheck)
						{
							TileObject.objectPreview[num18 + num7, num19 + num8] = 2;
						}
					}
				}
				if (tileData1.HookCheck.hook != null)
				{
					if (tileData1.HookCheck.processedCoordinates)
					{
						short num20 = tileData1.Origin.X;
						short num21 = tileData1.Origin.Y;
					}
					if (tileData1.HookCheck.hook(x, y, type, style, dir) == tileData1.HookCheck.badReturn && tileData1.HookCheck.badResponse == 0)
					{
						single3 = 0f;
						single2 = 0f;
						TileObject.objectPreview.AllInvalid();
					}
				}
				float single5 = single3 / single4;
				float single6 = single2 / width;
				if (single5 != 1f || single6 != 1f)
				{
					if (single5 <= single && (single5 != single || single6 <= single1))
					{
						continue;
					}
					TileObjectPreviewData.placementCache.CopyFrom(TileObject.objectPreview);
					single = single5;
					single1 = single6;
					tileObjectDatum = tileData1;
					num3 = num4;
				}
				else
				{
					single = 1f;
					single1 = 1f;
					num3 = num4;
					tileObjectDatum = tileData1;
					break;
				}
			}
			int num22 = -1;
			if (randomStyleRange)
			{
				if (TileObjectPreviewData.randomCache == null)
				{
					TileObjectPreviewData.randomCache = new TileObjectPreviewData();
				}
				bool flag7 = false;
				if (TileObjectPreviewData.randomCache.Type != type)
				{
					flag7 = true;
				}
				else
				{
					Point16 coordinates = TileObjectPreviewData.randomCache.Coordinates;
					Point16 objectStart = TileObjectPreviewData.randomCache.ObjectStart;
					int num23 = coordinates.X + objectStart.X;
					int num24 = coordinates.Y + objectStart.Y;
					int num25 = x - tileData.Origin.X;
					int num26 = y - tileData.Origin.Y;
					if (num23 != num25 || num24 != num26)
					{
						flag7 = true;
					}
				}
				num22 = (!flag7 ? TileObjectPreviewData.randomCache.Random : Main.rand.Next(tileData.RandomStyleRange));
			}
			if (onlyCheck)
			{
				if (single != 1f || single1 != 1f)
				{
					TileObject.objectPreview.CopyFrom(TileObjectPreviewData.placementCache);
					num4 = num3;
				}
				TileObject.objectPreview.Random = num22;
				if (tileData.RandomStyleRange > 0)
				{
					TileObjectPreviewData.randomCache.CopyFrom(TileObject.objectPreview);
				}
			}
			if (!onlyCheck)
			{
				objectData.xCoord = x - tileObjectDatum.Origin.X;
				objectData.yCoord = y - tileObjectDatum.Origin.Y;
				objectData.type = type;
				objectData.style = style;
				objectData.alternate = num4;
				objectData.random = num22;
			}
			if (single != 1f)
			{
				return false;
			}
			return single1 == 1f;
		}
Example #9
0
        // Token: 0x060001A6 RID: 422 RVA: 0x0002ECC8 File Offset: 0x0002CEC8
        public static bool CanPlace(int x, int y, int type, int style, int dir, out TileObject objectData, bool onlyCheck = false)
        {
            TileObjectData tileData = TileObjectData.GetTileData(type, style, 0);

            objectData = TileObject.Empty;
            if (tileData == null)
            {
                return(false);
            }
            int num  = x - (int)tileData.Origin.X;
            int num2 = y - (int)tileData.Origin.Y;

            if (num < 0 || num + tileData.Width >= Main.maxTilesX || num2 < 0 || num2 + tileData.Height >= Main.maxTilesY)
            {
                return(false);
            }
            bool flag = tileData.RandomStyleRange > 0;

            if (TileObjectPreviewData.placementCache == null)
            {
                TileObjectPreviewData.placementCache = new TileObjectPreviewData();
            }
            TileObjectPreviewData.placementCache.Reset();
            int arg_AF_0 = 0;
            int num3     = 0;

            if (tileData.AlternatesCount != 0)
            {
                num3 = tileData.AlternatesCount;
            }
            float          num4           = -1f;
            float          num5           = -1f;
            int            num6           = 0;
            TileObjectData tileObjectData = null;
            int            i = arg_AF_0 - 1;

            while (i < num3)
            {
                i++;
                TileObjectData tileData2 = TileObjectData.GetTileData(type, style, i);
                if (tileData2.Direction == TileObjectDirection.None || ((tileData2.Direction != TileObjectDirection.PlaceLeft || dir != 1) && (tileData2.Direction != TileObjectDirection.PlaceRight || dir != -1)))
                {
                    int num7 = x - (int)tileData2.Origin.X;
                    int num8 = y - (int)tileData2.Origin.Y;
                    if (num7 < 5 || num7 + tileData2.Width > Main.maxTilesX - 5 || num8 < 5 || num8 + tileData2.Height > Main.maxTilesY - 5)
                    {
                        return(false);
                    }
                    Rectangle rectangle = new Rectangle(0, 0, tileData2.Width, tileData2.Height);
                    int       num9      = 0;
                    int       num10     = 0;
                    if (tileData2.AnchorTop.tileCount != 0)
                    {
                        if (rectangle.Y == 0)
                        {
                            rectangle.Y = -1;
                            rectangle.Height++;
                            num10++;
                        }
                        int checkStart = tileData2.AnchorTop.checkStart;
                        if (checkStart < rectangle.X)
                        {
                            rectangle.Width += rectangle.X - checkStart;
                            num9            += rectangle.X - checkStart;
                            rectangle.X      = checkStart;
                        }
                        int num11 = checkStart + tileData2.AnchorTop.tileCount - 1;
                        int num12 = rectangle.X + rectangle.Width - 1;
                        if (num11 > num12)
                        {
                            rectangle.Width += num11 - num12;
                        }
                    }
                    if (tileData2.AnchorBottom.tileCount != 0)
                    {
                        if (rectangle.Y + rectangle.Height == tileData2.Height)
                        {
                            rectangle.Height++;
                        }
                        int checkStart2 = tileData2.AnchorBottom.checkStart;
                        if (checkStart2 < rectangle.X)
                        {
                            rectangle.Width += rectangle.X - checkStart2;
                            num9            += rectangle.X - checkStart2;
                            rectangle.X      = checkStart2;
                        }
                        int num13 = checkStart2 + tileData2.AnchorBottom.tileCount - 1;
                        int num14 = rectangle.X + rectangle.Width - 1;
                        if (num13 > num14)
                        {
                            rectangle.Width += num13 - num14;
                        }
                    }
                    if (tileData2.AnchorLeft.tileCount != 0)
                    {
                        if (rectangle.X == 0)
                        {
                            rectangle.X = -1;
                            rectangle.Width++;
                            num9++;
                        }
                        int num15 = tileData2.AnchorLeft.checkStart;
                        if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            num15--;
                        }
                        if (num15 < rectangle.Y)
                        {
                            rectangle.Width += rectangle.Y - num15;
                            num10           += rectangle.Y - num15;
                            rectangle.Y      = num15;
                        }
                        int num16 = num15 + tileData2.AnchorLeft.tileCount - 1;
                        if ((tileData2.AnchorLeft.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            num16 += 2;
                        }
                        int num17 = rectangle.Y + rectangle.Height - 1;
                        if (num16 > num17)
                        {
                            rectangle.Height += num16 - num17;
                        }
                    }
                    if (tileData2.AnchorRight.tileCount != 0)
                    {
                        if (rectangle.X + rectangle.Width == tileData2.Width)
                        {
                            rectangle.Width++;
                        }
                        int num18 = tileData2.AnchorLeft.checkStart;
                        if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            num18--;
                        }
                        if (num18 < rectangle.Y)
                        {
                            rectangle.Width += rectangle.Y - num18;
                            num10           += rectangle.Y - num18;
                            rectangle.Y      = num18;
                        }
                        int num19 = num18 + tileData2.AnchorRight.tileCount - 1;
                        if ((tileData2.AnchorRight.type & AnchorType.Tree) == AnchorType.Tree)
                        {
                            num19 += 2;
                        }
                        int num20 = rectangle.Y + rectangle.Height - 1;
                        if (num19 > num20)
                        {
                            rectangle.Height += num19 - num20;
                        }
                    }
                    if (onlyCheck)
                    {
                        TileObject.objectPreview.Reset();
                        TileObject.objectPreview.Active      = true;
                        TileObject.objectPreview.Type        = (ushort)type;
                        TileObject.objectPreview.Style       = (short)style;
                        TileObject.objectPreview.Alternate   = i;
                        TileObject.objectPreview.Size        = new Point16(rectangle.Width, rectangle.Height);
                        TileObject.objectPreview.ObjectStart = new Point16(num9, num10);
                        TileObject.objectPreview.Coordinates = new Point16(num7 - num9, num8 - num10);
                    }
                    float num21 = 0f;
                    float num22 = (float)(tileData2.Width * tileData2.Height);
                    float num23 = 0f;
                    float num24 = 0f;
                    for (int j = 0; j < tileData2.Width; j++)
                    {
                        for (int k = 0; k < tileData2.Height; k++)
                        {
                            Tile tileSafely = Framing.GetTileSafely(num7 + j, num8 + k);
                            bool flag2      = !tileData2.LiquidPlace(tileSafely);
                            bool flag3      = false;
                            if (tileData2.AnchorWall)
                            {
                                num24 += 1f;
                                if (!tileData2.isValidWallAnchor((int)tileSafely.wall))
                                {
                                    flag3 = true;
                                }
                                else
                                {
                                    num23 += 1f;
                                }
                            }
                            bool flag4 = false;
                            if (tileSafely.active() && !Main.tileCut[(int)tileSafely.type])
                            {
                                flag4 = true;
                            }
                            if (flag4 | flag2 | flag3)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[j + num9, k + num10] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[j + num9, k + num10] = 1;
                                }
                                num21 += 1f;
                            }
                        }
                    }
                    AnchorData anchorData = tileData2.AnchorBottom;
                    if (anchorData.tileCount != 0)
                    {
                        num24 += (float)anchorData.tileCount;
                        int height = tileData2.Height;
                        for (int l = 0; l < anchorData.tileCount; l++)
                        {
                            int  num25      = anchorData.checkStart + l;
                            Tile tileSafely = Framing.GetTileSafely(num7 + num25, num8 + height);
                            bool flag5      = false;
                            if (tileSafely.nactive())
                            {
                                if ((anchorData.type & AnchorType.SolidTile) == AnchorType.SolidTile && Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && !Main.tileNoAttach[(int)tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                                {
                                    flag5 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                }
                                if (!flag5 && ((anchorData.type & AnchorType.SolidWithTop) == AnchorType.SolidWithTop || (anchorData.type & AnchorType.Table) == AnchorType.Table))
                                {
                                    if (TileID.Sets.Platforms[(int)tileSafely.type])
                                    {
                                        int num26 = (int)tileSafely.frameX / TileObjectData.PlatformFrameWidth();
                                        if ((!tileSafely.halfBrick() && num26 >= 0 && num26 <= 7) || (num26 >= 12 && num26 <= 16) || (num26 >= 25 && num26 <= 26))
                                        {
                                            flag5 = true;
                                        }
                                    }
                                    else if (Main.tileSolid[(int)tileSafely.type] && Main.tileSolidTop[(int)tileSafely.type])
                                    {
                                        flag5 = true;
                                    }
                                }
                                if (!flag5 && (anchorData.type & AnchorType.Table) == AnchorType.Table && !TileID.Sets.Platforms[(int)tileSafely.type] && Main.tileTable[(int)tileSafely.type] && tileSafely.blockType() == 0)
                                {
                                    flag5 = true;
                                }
                                if (!flag5 && (anchorData.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type])
                                {
                                    int num27 = tileSafely.blockType();
                                    if (num27 - 4 <= 1)
                                    {
                                        flag5 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                    }
                                }
                                if (!flag5 && (anchorData.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely.type))
                                {
                                    flag5 = true;
                                }
                            }
                            else if (!flag5 && (anchorData.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag5 = true;
                            }
                            if (!flag5)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num25 + num9, height + num10] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num25 + num9, height + num10] = 1;
                                }
                                num23 += 1f;
                            }
                        }
                    }
                    anchorData = tileData2.AnchorTop;
                    if (anchorData.tileCount != 0)
                    {
                        num24 += (float)anchorData.tileCount;
                        int num28 = -1;
                        for (int m = 0; m < anchorData.tileCount; m++)
                        {
                            int  num29      = anchorData.checkStart + m;
                            Tile tileSafely = Framing.GetTileSafely(num7 + num29, num8 + num28);
                            bool flag6      = false;
                            if (tileSafely.nactive())
                            {
                                if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && !Main.tileNoAttach[(int)tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                                {
                                    flag6 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                }
                                if (!flag6 && (anchorData.type & AnchorType.SolidBottom) == AnchorType.SolidBottom && ((Main.tileSolid[(int)tileSafely.type] && (!Main.tileSolidTop[(int)tileSafely.type] || (TileID.Sets.Platforms[(int)tileSafely.type] && (tileSafely.halfBrick() || tileSafely.topSlope())))) || tileSafely.halfBrick() || tileSafely.topSlope()) && !TileID.Sets.NotReallySolid[(int)tileSafely.type] && !tileSafely.bottomSlope())
                                {
                                    flag6 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                }
                                if (!flag6 && (anchorData.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type])
                                {
                                    int num27 = tileSafely.blockType();
                                    if (num27 - 2 <= 1)
                                    {
                                        flag6 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                    }
                                }
                                if (!flag6 && (anchorData.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely.type))
                                {
                                    flag6 = true;
                                }
                            }
                            else if (!flag6 && (anchorData.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag6 = true;
                            }
                            if (!flag6)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num29 + num9, num28 + num10] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num29 + num9, num28 + num10] = 1;
                                }
                                num23 += 1f;
                            }
                        }
                    }
                    anchorData = tileData2.AnchorRight;
                    if (anchorData.tileCount != 0)
                    {
                        num24 += (float)anchorData.tileCount;
                        int width = tileData2.Width;
                        for (int n = 0; n < anchorData.tileCount; n++)
                        {
                            int  num30      = anchorData.checkStart + n;
                            Tile tileSafely = Framing.GetTileSafely(num7 + width, num8 + num30);
                            bool flag7      = false;
                            if (tileSafely.nactive())
                            {
                                if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && !Main.tileNoAttach[(int)tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                                {
                                    flag7 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                }
                                if (!flag7 && (anchorData.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type])
                                {
                                    int num27 = tileSafely.blockType();
                                    if (num27 == 2 || num27 == 4)
                                    {
                                        flag7 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                    }
                                }
                                if (!flag7 && (anchorData.type & AnchorType.Tree) == AnchorType.Tree && tileSafely.type == 5)
                                {
                                    flag7 = true;
                                    if (n == 0)
                                    {
                                        num24 += 1f;
                                        Tile tileSafely2 = Framing.GetTileSafely(num7 + width, num8 + num30 - 1);
                                        if (tileSafely2.nactive() && tileSafely2.type == 5)
                                        {
                                            num23 += 1f;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[width + num9, num30 + num10 - 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[width + num9, num30 + num10 - 1] = 2;
                                        }
                                    }
                                    if (n == anchorData.tileCount - 1)
                                    {
                                        num24 += 1f;
                                        Tile tileSafely3 = Framing.GetTileSafely(num7 + width, num8 + num30 + 1);
                                        if (tileSafely3.nactive() && tileSafely3.type == 5)
                                        {
                                            num23 += 1f;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[width + num9, num30 + num10 + 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[width + num9, num30 + num10 + 1] = 2;
                                        }
                                    }
                                }
                                if (!flag7 && (anchorData.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely.type))
                                {
                                    flag7 = true;
                                }
                            }
                            else if (!flag7 && (anchorData.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag7 = true;
                            }
                            if (!flag7)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[width + num9, num30 + num10] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[width + num9, num30 + num10] = 1;
                                }
                                num23 += 1f;
                            }
                        }
                    }
                    anchorData = tileData2.AnchorLeft;
                    if (anchorData.tileCount != 0)
                    {
                        num24 += (float)anchorData.tileCount;
                        int num31 = -1;
                        for (int num32 = 0; num32 < anchorData.tileCount; num32++)
                        {
                            int  num33      = anchorData.checkStart + num32;
                            Tile tileSafely = Framing.GetTileSafely(num7 + num31, num8 + num33);
                            bool flag8      = false;
                            if (tileSafely.nactive())
                            {
                                if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && !Main.tileNoAttach[(int)tileSafely.type] && (tileData2.FlattenAnchors || tileSafely.blockType() == 0))
                                {
                                    flag8 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                }
                                if (!flag8 && (anchorData.type & AnchorType.SolidSide) == AnchorType.SolidSide && Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type])
                                {
                                    int num27 = tileSafely.blockType();
                                    if (num27 == 3 || num27 == 5)
                                    {
                                        flag8 = tileData2.isValidTileAnchor((int)tileSafely.type);
                                    }
                                }
                                if (!flag8 && (anchorData.type & AnchorType.Tree) == AnchorType.Tree && tileSafely.type == 5)
                                {
                                    flag8 = true;
                                    if (num32 == 0)
                                    {
                                        num24 += 1f;
                                        Tile tileSafely4 = Framing.GetTileSafely(num7 + num31, num8 + num33 - 1);
                                        if (tileSafely4.nactive() && tileSafely4.type == 5)
                                        {
                                            num23 += 1f;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[num31 + num9, num33 + num10 - 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[num31 + num9, num33 + num10 - 1] = 2;
                                        }
                                    }
                                    if (num32 == anchorData.tileCount - 1)
                                    {
                                        num24 += 1f;
                                        Tile tileSafely5 = Framing.GetTileSafely(num7 + num31, num8 + num33 + 1);
                                        if (tileSafely5.nactive() && tileSafely5.type == 5)
                                        {
                                            num23 += 1f;
                                            if (onlyCheck)
                                            {
                                                TileObject.objectPreview[num31 + num9, num33 + num10 + 1] = 1;
                                            }
                                        }
                                        else if (onlyCheck)
                                        {
                                            TileObject.objectPreview[num31 + num9, num33 + num10 + 1] = 2;
                                        }
                                    }
                                }
                                if (!flag8 && (anchorData.type & AnchorType.AlternateTile) == AnchorType.AlternateTile && tileData2.isValidAlternateAnchor((int)tileSafely.type))
                                {
                                    flag8 = true;
                                }
                            }
                            else if (!flag8 && (anchorData.type & AnchorType.EmptyTile) == AnchorType.EmptyTile)
                            {
                                flag8 = true;
                            }
                            if (!flag8)
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num31 + num9, num33 + num10] = 2;
                                }
                            }
                            else
                            {
                                if (onlyCheck)
                                {
                                    TileObject.objectPreview[num31 + num9, num33 + num10] = 1;
                                }
                                num23 += 1f;
                            }
                        }
                    }
                    if (tileData2.HookCheck.hook != null)
                    {
                        if (tileData2.HookCheck.processedCoordinates)
                        {
                            Point16 arg_103B_0 = tileData2.Origin;
                            Point16 arg_1043_0 = tileData2.Origin;
                        }
                        if (tileData2.HookCheck.hook(x, y, type, style, dir) == tileData2.HookCheck.badReturn && tileData2.HookCheck.badResponse == 0)
                        {
                            num23 = 0f;
                            num21 = 0f;
                            TileObject.objectPreview.AllInvalid();
                        }
                    }
                    float num34 = num23 / num24;
                    float num35 = num21 / num22;
                    if (num35 == 1f && num24 == 0f)
                    {
                        num34 = 1f;
                        num35 = 1f;
                    }
                    if (num34 == 1f && num35 == 1f)
                    {
                        num4           = 1f;
                        num5           = 1f;
                        num6           = i;
                        tileObjectData = tileData2;
                        break;
                    }
                    if (num34 > num4 || (num34 == num4 && num35 > num5))
                    {
                        TileObjectPreviewData.placementCache.CopyFrom(TileObject.objectPreview);
                        num4           = num34;
                        num5           = num35;
                        tileObjectData = tileData2;
                        num6           = i;
                    }
                }
            }
            int num36 = -1;

            if (flag)
            {
                if (TileObjectPreviewData.randomCache == null)
                {
                    TileObjectPreviewData.randomCache = new TileObjectPreviewData();
                }
                bool flag9 = false;
                if ((int)TileObjectPreviewData.randomCache.Type == type)
                {
                    Point16 arg_116E_0  = TileObjectPreviewData.randomCache.Coordinates;
                    Point16 objectStart = TileObjectPreviewData.randomCache.ObjectStart;
                    int     num37       = (int)(arg_116E_0.X + objectStart.X);
                    int     num38       = (int)(arg_116E_0.Y + objectStart.Y);
                    int     num39       = x - (int)tileData.Origin.X;
                    int     num40       = y - (int)tileData.Origin.Y;
                    if (num37 != num39 || num38 != num40)
                    {
                        flag9 = true;
                    }
                }
                else
                {
                    flag9 = true;
                }
                if (flag9)
                {
                    num36 = Main.rand.Next(tileData.RandomStyleRange);
                }
                else
                {
                    num36 = TileObjectPreviewData.randomCache.Random;
                }
            }
            if (onlyCheck)
            {
                if (num4 != 1f || num5 != 1f)
                {
                    TileObject.objectPreview.CopyFrom(TileObjectPreviewData.placementCache);
                    i = num6;
                }
                TileObject.objectPreview.Random = num36;
                if (tileData.RandomStyleRange > 0)
                {
                    TileObjectPreviewData.randomCache.CopyFrom(TileObject.objectPreview);
                }
            }
            if (!onlyCheck)
            {
                objectData.xCoord    = x - (int)tileObjectData.Origin.X;
                objectData.yCoord    = y - (int)tileObjectData.Origin.Y;
                objectData.type      = type;
                objectData.style     = style;
                objectData.alternate = i;
                objectData.random    = num36;
            }
            return(num4 == 1f && num5 == 1f);
        }