Beispiel #1
0
        public static bool Place(TileObject toBePlaced)
        {
            TileObjectData tileData = TileObjectData.GetTileData(toBePlaced.type, toBePlaced.style, toBePlaced.alternate);

            if (tileData == null)
            {
                return(false);
            }
            if (tileData.HookPlaceOverride.hook != null)
            {
                int num1;
                int num2;
                if (tileData.HookPlaceOverride.processedCoordinates)
                {
                    num1 = toBePlaced.xCoord;
                    num2 = toBePlaced.yCoord;
                }
                else
                {
                    num1 = toBePlaced.xCoord + (int)tileData.Origin.X;
                    num2 = toBePlaced.yCoord + (int)tileData.Origin.Y;
                }
                if (tileData.HookPlaceOverride.hook(num1, num2, toBePlaced.type, toBePlaced.style, 1, toBePlaced.alternate) == tileData.HookPlaceOverride.badReturn)
                {
                    return(false);
                }
            }
            else
            {
                ushort type           = (ushort)toBePlaced.type;
                int    placementStyle = tileData.CalculatePlacementStyle(toBePlaced.style, toBePlaced.alternate, toBePlaced.random);
                int    num1           = 0;
                if (tileData.StyleWrapLimit > 0)
                {
                    num1            = placementStyle / tileData.StyleWrapLimit * tileData.StyleLineSkip;
                    placementStyle %= tileData.StyleWrapLimit;
                }
                int num2;
                int num3;
                if (tileData.StyleHorizontal)
                {
                    num2 = tileData.CoordinateFullWidth * placementStyle;
                    num3 = tileData.CoordinateFullHeight * num1;
                }
                else
                {
                    num2 = tileData.CoordinateFullWidth * num1;
                    num3 = tileData.CoordinateFullHeight * placementStyle;
                }
                int xCoord = toBePlaced.xCoord;
                int yCoord = toBePlaced.yCoord;
                for (int index1 = 0; index1 < tileData.Width; ++index1)
                {
                    for (int index2 = 0; index2 < tileData.Height; ++index2)
                    {
                        Tile tileSafely = Framing.GetTileSafely(xCoord + index1, yCoord + index2);
                        if (tileSafely.active() && tileSafely.type != (ushort)484 && (Main.tileCut[(int)tileSafely.type] || TileID.Sets.BreakableWhenPlacing[(int)tileSafely.type]))
                        {
                            WorldGen.KillTile(xCoord + index1, yCoord + index2, false, false, false);
                            if (!Main.tile[xCoord + index1, yCoord + index2].active() && Main.netMode == 1)
                            {
                                NetMessage.SendData(17, -1, -1, (NetworkText)null, 0, (float)(yCoord + index1), (float)(yCoord + index2), 0.0f, 0, 0, 0);
                            }
                        }
                    }
                }
                for (int index1 = 0; index1 < tileData.Width; ++index1)
                {
                    int num4 = num2 + index1 * (tileData.CoordinateWidth + tileData.CoordinatePadding);
                    int num5 = num3;
                    for (int index2 = 0; index2 < tileData.Height; ++index2)
                    {
                        Tile tileSafely = Framing.GetTileSafely(xCoord + index1, yCoord + index2);
                        if (!tileSafely.active())
                        {
                            tileSafely.active(true);
                            tileSafely.frameX = (short)num4;
                            tileSafely.frameY = (short)num5;
                            tileSafely.type   = type;
                        }
                        num5 += tileData.CoordinateHeights[index2] + tileData.CoordinatePadding;
                    }
                }
            }
            if (tileData.FlattenAnchors)
            {
                AnchorData anchorBottom = tileData.AnchorBottom;
                if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int num = toBePlaced.xCoord + anchorBottom.checkStart;
                    int j   = toBePlaced.yCoord + tileData.Height;
                    for (int index = 0; index < anchorBottom.tileCount; ++index)
                    {
                        Tile tileSafely = Framing.GetTileSafely(num + index, j);
                        if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && tileSafely.blockType() != 0)
                        {
                            WorldGen.SlopeTile(num + index, j, 0, false);
                        }
                    }
                }
                AnchorData anchorTop = tileData.AnchorTop;
                if (anchorTop.tileCount != 0 && (anchorTop.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int num = toBePlaced.xCoord + anchorTop.checkStart;
                    int j   = toBePlaced.yCoord - 1;
                    for (int index = 0; index < anchorTop.tileCount; ++index)
                    {
                        Tile tileSafely = Framing.GetTileSafely(num + index, j);
                        if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && tileSafely.blockType() != 0)
                        {
                            WorldGen.SlopeTile(num + index, j, 0, false);
                        }
                    }
                }
                AnchorData anchorRight = tileData.AnchorRight;
                if (anchorRight.tileCount != 0 && (anchorRight.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int i   = toBePlaced.xCoord + tileData.Width;
                    int num = toBePlaced.yCoord + anchorRight.checkStart;
                    for (int index = 0; index < anchorRight.tileCount; ++index)
                    {
                        Tile tileSafely = Framing.GetTileSafely(i, num + index);
                        if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && tileSafely.blockType() != 0)
                        {
                            WorldGen.SlopeTile(i, num + index, 0, false);
                        }
                    }
                }
                AnchorData anchorLeft = tileData.AnchorLeft;
                if (anchorLeft.tileCount != 0 && (anchorLeft.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int i   = toBePlaced.xCoord - 1;
                    int num = toBePlaced.yCoord + anchorLeft.checkStart;
                    for (int index = 0; index < anchorLeft.tileCount; ++index)
                    {
                        Tile tileSafely = Framing.GetTileSafely(i, num + index);
                        if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && tileSafely.blockType() != 0)
                        {
                            WorldGen.SlopeTile(i, num + index, 0, false);
                        }
                    }
                }
            }
            return(true);
        }
Beispiel #2
0
        public static void DrawPreview(SpriteBatch sb, TileObjectPreviewData op, Vector2 position)
        {
            Point16        coordinates    = op.Coordinates;
            Texture2D      texture        = TextureAssets.Tile[(int)op.Type].get_Value();
            TileObjectData tileData       = TileObjectData.GetTileData((int)op.Type, (int)op.Style, op.Alternate);
            int            placementStyle = tileData.CalculatePlacementStyle((int)op.Style, op.Alternate, op.Random);
            int            num1           = 0;
            int            drawYoffset    = tileData.DrawYOffset;
            int            drawXoffset    = tileData.DrawXOffset;
            int            num2           = placementStyle + tileData.DrawStyleOffset;
            int            styleWrapLimit = tileData.StyleWrapLimit;
            int            styleLineSkip  = tileData.StyleLineSkip;
            int?           nullable;

            if (tileData.StyleWrapLimitVisualOverride.HasValue)
            {
                nullable       = tileData.StyleWrapLimitVisualOverride;
                styleWrapLimit = nullable.Value;
            }
            nullable = tileData.styleLineSkipVisualOverride;
            if (nullable.HasValue)
            {
                nullable      = tileData.styleLineSkipVisualOverride;
                styleLineSkip = nullable.Value;
            }
            if (styleWrapLimit > 0)
            {
                num1  = num2 / styleWrapLimit * styleLineSkip;
                num2 %= styleWrapLimit;
            }
            int num3;
            int num4;

            if (tileData.StyleHorizontal)
            {
                num3 = tileData.CoordinateFullWidth * num2;
                num4 = tileData.CoordinateFullHeight * num1;
            }
            else
            {
                num3 = tileData.CoordinateFullWidth * num1;
                num4 = tileData.CoordinateFullHeight * num2;
            }
            for (int index1 = 0; index1 < (int)op.Size.X; ++index1)
            {
                int x = num3 + (index1 - (int)op.ObjectStart.X) * (tileData.CoordinateWidth + tileData.CoordinatePadding);
                int y = num4;
                for (int index2 = 0; index2 < (int)op.Size.Y; ++index2)
                {
                    int i    = (int)coordinates.X + index1;
                    int num5 = (int)coordinates.Y + index2;
                    if (index2 == 0 && tileData.DrawStepDown != 0 && WorldGen.SolidTile(Framing.GetTileSafely(i, num5 - 1)))
                    {
                        drawYoffset += tileData.DrawStepDown;
                    }
                    Color color1;
                    switch (op[index1, index2])
                    {
                    case 1:
                        color1 = Color.White;
                        break;

                    case 2:
                        color1 = Color.Red * 0.7f;
                        break;

                    default:
                        continue;
                    }
                    Color color2 = color1 * 0.5f;
                    if (index1 >= (int)op.ObjectStart.X && index1 < (int)op.ObjectStart.X + tileData.Width && (index2 >= (int)op.ObjectStart.Y && index2 < (int)op.ObjectStart.Y + tileData.Height))
                    {
                        SpriteEffects effects = SpriteEffects.None;
                        if (tileData.DrawFlipHorizontal && i % 2 == 0)
                        {
                            effects |= SpriteEffects.FlipHorizontally;
                        }
                        if (tileData.DrawFlipVertical && num5 % 2 == 0)
                        {
                            effects |= SpriteEffects.FlipVertically;
                        }
                        Rectangle rectangle = new Rectangle(x, y, tileData.CoordinateWidth, tileData.CoordinateHeights[index2 - (int)op.ObjectStart.Y]);
                        sb.Draw(texture, new Vector2((float)(i * 16 - (int)((double)position.X + (double)(tileData.CoordinateWidth - 16) / 2.0) + drawXoffset), (float)(num5 * 16 - (int)position.Y + drawYoffset)), new Rectangle?(rectangle), color2, 0.0f, Vector2.Zero, 1f, effects, 0.0f);
                        y += tileData.CoordinateHeights[index2 - (int)op.ObjectStart.Y] + tileData.CoordinatePadding;
                    }
                }
            }
        }
Beispiel #3
0
        public static bool Place(TileObject toBePlaced)
        {
            TileObjectData tileData = TileObjectData.GetTileData(toBePlaced.type, toBePlaced.style, toBePlaced.alternate);

            if (tileData == null)
            {
                return(false);
            }
            if (tileData.HookPlaceOverride.hook != null)
            {
                int arg;
                int arg2;
                if (tileData.HookPlaceOverride.processedCoordinates)
                {
                    arg  = toBePlaced.xCoord;
                    arg2 = toBePlaced.yCoord;
                }
                else
                {
                    arg  = toBePlaced.xCoord + tileData.Origin.X;
                    arg2 = toBePlaced.yCoord + tileData.Origin.Y;
                }
                if (tileData.HookPlaceOverride.hook(arg, arg2, toBePlaced.type, toBePlaced.style, 1, toBePlaced.alternate) == tileData.HookPlaceOverride.badReturn)
                {
                    return(false);
                }
            }
            else
            {
                ushort num  = (ushort)toBePlaced.type;
                int    num2 = 0;
                int    num3 = 0;
                int    num4 = tileData.CalculatePlacementStyle(toBePlaced.style, toBePlaced.alternate, toBePlaced.random);
                int    num5 = 0;
                if (tileData.StyleWrapLimit > 0)
                {
                    num5  = num4 / tileData.StyleWrapLimit * tileData.StyleLineSkip;
                    num4 %= tileData.StyleWrapLimit;
                }
                if (tileData.StyleHorizontal)
                {
                    num2 = tileData.CoordinateFullWidth * num4;
                    num3 = tileData.CoordinateFullHeight * num5;
                }
                else
                {
                    num2 = tileData.CoordinateFullWidth * num5;
                    num3 = tileData.CoordinateFullHeight * num4;
                }
                int num6 = toBePlaced.xCoord;
                int num7 = toBePlaced.yCoord;
                for (int i = 0; i < tileData.Width; i++)
                {
                    for (int j = 0; j < tileData.Height; j++)
                    {
                        Tile tileSafely = Framing.GetTileSafely(num6 + i, num7 + j);
                        if (tileSafely.active() && tileSafely.type != 484 && (Main.tileCut[tileSafely.type] || TileID.Sets.BreakableWhenPlacing[tileSafely.type]))
                        {
                            WorldGen.KillTile(num6 + i, num7 + j);
                            if (!Main.tile[num6 + i, num7 + j].active() && Main.netMode == 1)
                            {
                                NetMessage.SendData(17, -1, -1, null, 0, num7 + i, num7 + j);
                            }
                        }
                    }
                }
                for (int k = 0; k < tileData.Width; k++)
                {
                    int num8 = num2 + k * (tileData.CoordinateWidth + tileData.CoordinatePadding);
                    int num9 = num3;
                    for (int l = 0; l < tileData.Height; l++)
                    {
                        Tile tileSafely2 = Framing.GetTileSafely(num6 + k, num7 + l);
                        if (!tileSafely2.active())
                        {
                            tileSafely2.active(active: true);
                            tileSafely2.frameX = (short)num8;
                            tileSafely2.frameY = (short)num9;
                            tileSafely2.type   = num;
                        }
                        num9 += tileData.CoordinateHeights[l] + tileData.CoordinatePadding;
                    }
                }
            }
            if (tileData.FlattenAnchors)
            {
                AnchorData anchorBottom = tileData.AnchorBottom;
                if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int num10 = toBePlaced.xCoord + anchorBottom.checkStart;
                    int j2    = toBePlaced.yCoord + tileData.Height;
                    for (int m = 0; m < anchorBottom.tileCount; m++)
                    {
                        Tile tileSafely3 = Framing.GetTileSafely(num10 + m, j2);
                        if (Main.tileSolid[tileSafely3.type] && !Main.tileSolidTop[tileSafely3.type] && tileSafely3.blockType() != 0)
                        {
                            WorldGen.SlopeTile(num10 + m, j2);
                        }
                    }
                }
                anchorBottom = tileData.AnchorTop;
                if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int num11 = toBePlaced.xCoord + anchorBottom.checkStart;
                    int j3    = toBePlaced.yCoord - 1;
                    for (int n = 0; n < anchorBottom.tileCount; n++)
                    {
                        Tile tileSafely4 = Framing.GetTileSafely(num11 + n, j3);
                        if (Main.tileSolid[tileSafely4.type] && !Main.tileSolidTop[tileSafely4.type] && tileSafely4.blockType() != 0)
                        {
                            WorldGen.SlopeTile(num11 + n, j3);
                        }
                    }
                }
                anchorBottom = tileData.AnchorRight;
                if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int i2    = toBePlaced.xCoord + tileData.Width;
                    int num12 = toBePlaced.yCoord + anchorBottom.checkStart;
                    for (int num13 = 0; num13 < anchorBottom.tileCount; num13++)
                    {
                        Tile tileSafely5 = Framing.GetTileSafely(i2, num12 + num13);
                        if (Main.tileSolid[tileSafely5.type] && !Main.tileSolidTop[tileSafely5.type] && tileSafely5.blockType() != 0)
                        {
                            WorldGen.SlopeTile(i2, num12 + num13);
                        }
                    }
                }
                anchorBottom = tileData.AnchorLeft;
                if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int i3    = toBePlaced.xCoord - 1;
                    int num14 = toBePlaced.yCoord + anchorBottom.checkStart;
                    for (int num15 = 0; num15 < anchorBottom.tileCount; num15++)
                    {
                        Tile tileSafely6 = Framing.GetTileSafely(i3, num14 + num15);
                        if (Main.tileSolid[tileSafely6.type] && !Main.tileSolidTop[tileSafely6.type] && tileSafely6.blockType() != 0)
                        {
                            WorldGen.SlopeTile(i3, num14 + num15);
                        }
                    }
                }
            }
            return(true);
        }
Beispiel #4
0
        public static void DrawPreview(SpriteBatch sb, TileObjectPreviewData op, Vector2 position)
        {
            Point16        coordinates = op.Coordinates;
            Texture2D      value       = TextureAssets.Tile[op.Type].get_Value();
            TileObjectData tileData    = TileObjectData.GetTileData(op.Type, op.Style, op.Alternate);
            int            num         = 0;
            int            num2        = 0;
            int            num3        = tileData.CalculatePlacementStyle(op.Style, op.Alternate, op.Random);
            int            num4        = 0;
            int            num5        = tileData.DrawYOffset;
            int            drawXOffset = tileData.DrawXOffset;

            num3 += tileData.DrawStyleOffset;
            int num6 = tileData.StyleWrapLimit;
            int num7 = tileData.StyleLineSkip;

            if (tileData.StyleWrapLimitVisualOverride.HasValue)
            {
                num6 = tileData.StyleWrapLimitVisualOverride.Value;
            }
            if (tileData.styleLineSkipVisualOverride.HasValue)
            {
                num7 = tileData.styleLineSkipVisualOverride.Value;
            }
            if (num6 > 0)
            {
                num4  = num3 / num6 * num7;
                num3 %= num6;
            }
            if (tileData.StyleHorizontal)
            {
                num  = tileData.CoordinateFullWidth * num3;
                num2 = tileData.CoordinateFullHeight * num4;
            }
            else
            {
                num  = tileData.CoordinateFullWidth * num4;
                num2 = tileData.CoordinateFullHeight * num3;
            }
            for (int i = 0; i < op.Size.X; i++)
            {
                int x    = num + (i - op.ObjectStart.X) * (tileData.CoordinateWidth + tileData.CoordinatePadding);
                int num8 = num2;
                for (int j = 0; j < op.Size.Y; j++)
                {
                    int num9  = coordinates.X + i;
                    int num10 = coordinates.Y + j;
                    if (j == 0 && tileData.DrawStepDown != 0 && WorldGen.SolidTile(Framing.GetTileSafely(num9, num10 - 1)))
                    {
                        num5 += tileData.DrawStepDown;
                    }
                    int   num11 = op[i, j];
                    Color color;
                    if (num11 != 1)
                    {
                        if (num11 != 2)
                        {
                            continue;
                        }
                        color = Color.Red * 0.7f;
                    }
                    else
                    {
                        color = Color.White;
                    }
                    color *= 0.5f;
                    if (i >= op.ObjectStart.X && i < op.ObjectStart.X + tileData.Width && j >= op.ObjectStart.Y && j < op.ObjectStart.Y + tileData.Height)
                    {
                        SpriteEffects spriteEffects = SpriteEffects.None;
                        if (tileData.DrawFlipHorizontal && num9 % 2 == 0)
                        {
                            spriteEffects |= SpriteEffects.FlipHorizontally;
                        }
                        if (tileData.DrawFlipVertical && num10 % 2 == 0)
                        {
                            spriteEffects |= SpriteEffects.FlipVertically;
                        }
                        sb.Draw(sourceRectangle: new Rectangle(x, num8, tileData.CoordinateWidth, tileData.CoordinateHeights[j - op.ObjectStart.Y]), texture: value, position: new Vector2(num9 * 16 - (int)(position.X + (float)(tileData.CoordinateWidth - 16) / 2f) + drawXOffset, num10 * 16 - (int)position.Y + num5), color: color, rotation: 0f, origin: Vector2.Zero, scale: 1f, effects: spriteEffects, layerDepth: 0f);
                        num8 += tileData.CoordinateHeights[j - op.ObjectStart.Y] + tileData.CoordinatePadding;
                    }
                }
            }
        }
Beispiel #5
0
        public static void DrawPreview(SpriteBatch sb, TileObjectPreviewData op, Vector2 position)
        {
            Point16        coordinates    = op.Coordinates;
            Texture2D      texture2D      = Main.tileTexture[(int)op.Type];
            TileObjectData tileData       = TileObjectData.GetTileData((int)op.Type, (int)op.Style, op.Alternate);
            int            placementStyle = tileData.CalculatePlacementStyle((int)op.Style, op.Alternate, op.Random);
            int            num1           = 0;
            int            drawYoffset    = tileData.DrawYOffset;

            if (tileData.StyleWrapLimit > 0)
            {
                num1            = placementStyle / tileData.StyleWrapLimit * tileData.StyleLineSkip;
                placementStyle %= tileData.StyleWrapLimit;
            }
            int num2;
            int num3;

            if (tileData.StyleHorizontal)
            {
                num2 = tileData.CoordinateFullWidth * placementStyle;
                num3 = tileData.CoordinateFullHeight * num1;
            }
            else
            {
                num2 = tileData.CoordinateFullWidth * num1;
                num3 = tileData.CoordinateFullHeight * placementStyle;
            }
            for (int index1 = 0; index1 < (int)op.Size.X; ++index1)
            {
                int num4 = num2 + (index1 - (int)op.ObjectStart.X) * (tileData.CoordinateWidth + tileData.CoordinatePadding);
                int num5 = num3;
                for (int index2 = 0; index2 < (int)op.Size.Y; ++index2)
                {
                    int i    = (int)coordinates.X + index1;
                    int num6 = (int)coordinates.Y + index2;
                    if (index2 == 0 && tileData.DrawStepDown != 0 && WorldGen.SolidTile(Framing.GetTileSafely(i, num6 - 1)))
                    {
                        drawYoffset += tileData.DrawStepDown;
                    }
                    Color color1;
                    switch (op[index1, index2])
                    {
                    case 1:
                        color1 = Color.get_White();
                        break;

                    case 2:
                        color1 = Color.op_Multiply(Color.get_Red(), 0.7f);
                        break;

                    default:
                        continue;
                    }
                    Color color2 = Color.op_Multiply(color1, 0.5f);
                    if (index1 >= (int)op.ObjectStart.X && index1 < (int)op.ObjectStart.X + tileData.Width && (index2 >= (int)op.ObjectStart.Y && index2 < (int)op.ObjectStart.Y + tileData.Height))
                    {
                        SpriteEffects spriteEffects = (SpriteEffects)0;
                        if (tileData.DrawFlipHorizontal && index1 % 2 == 1)
                        {
                            spriteEffects = (SpriteEffects)(spriteEffects | 1);
                        }
                        if (tileData.DrawFlipVertical && index2 % 2 == 1)
                        {
                            spriteEffects = (SpriteEffects)(spriteEffects | 2);
                        }
                        Rectangle rectangle;
                        // ISSUE: explicit reference operation
                        ((Rectangle)@rectangle).\u002Ector(num4, num5, tileData.CoordinateWidth, tileData.CoordinateHeights[index2 - (int)op.ObjectStart.Y]);
                        sb.Draw(texture2D, new Vector2((float)(i * 16 - (int)(position.X + (double)(tileData.CoordinateWidth - 16) / 2.0)), (float)(num6 * 16 - (int)position.Y + drawYoffset)), new Rectangle?(rectangle), color2, 0.0f, Vector2.get_Zero(), 1f, spriteEffects, 0.0f);
                        num5 += tileData.CoordinateHeights[index2 - (int)op.ObjectStart.Y] + tileData.CoordinatePadding;
                    }
                }
            }
        }
Beispiel #6
0
        public static bool Place(TileObject toBePlaced)
        {
            TileObjectData tileData = TileObjectData.GetTileData(toBePlaced.type, toBePlaced.style, toBePlaced.alternate);

            if (tileData == null)
            {
                return(false);
            }
            if (tileData.HookPlaceOverride.hook != null)
            {
                int num1;
                int num2;
                if (tileData.HookPlaceOverride.processedCoordinates)
                {
                    num1 = toBePlaced.xCoord;
                    num2 = toBePlaced.yCoord;
                }
                else
                {
                    num1 = toBePlaced.xCoord + (int)tileData.Origin.X;
                    num2 = toBePlaced.yCoord + (int)tileData.Origin.Y;
                }
                if (tileData.HookPlaceOverride.hook(num1, num2, toBePlaced.type, toBePlaced.style, 1) == tileData.HookPlaceOverride.badReturn)
                {
                    return(false);
                }
            }
            else
            {
                ushort num1 = (ushort)toBePlaced.type;
                int    num2 = tileData.CalculatePlacementStyle(toBePlaced.style, toBePlaced.alternate, toBePlaced.random);
                int    num3 = 0;
                if (tileData.StyleWrapLimit > 0)
                {
                    num3  = num2 / tileData.StyleWrapLimit;
                    num2 %= tileData.StyleWrapLimit;
                }
                int num4;
                int num5;
                if (tileData.StyleHorizontal)
                {
                    num4 = tileData.CoordinateFullWidth * num2;
                    num5 = tileData.CoordinateFullHeight * num3;
                }
                else
                {
                    num4 = tileData.CoordinateFullWidth * num3;
                    num5 = tileData.CoordinateFullHeight * num2;
                }
                int num6 = toBePlaced.xCoord;
                int num7 = toBePlaced.yCoord;
                for (int index1 = 0; index1 < tileData.Width; ++index1)
                {
                    for (int index2 = 0; index2 < tileData.Height; ++index2)
                    {
                        Tile tileSafely = Framing.GetTileSafely(num6 + index1, num7 + index2);
                        if (tileSafely.active() && Main.tileCut[(int)tileSafely.type])
                        {
                            WorldGen.KillTile(num6 + index1, num7 + index2, false, false, false);
                        }
                    }
                }
                for (int index1 = 0; index1 < tileData.Width; ++index1)
                {
                    int num8 = num4 + index1 * (tileData.CoordinateWidth + tileData.CoordinatePadding);
                    int num9 = num5;
                    for (int index2 = 0; index2 < tileData.Height; ++index2)
                    {
                        Tile tileSafely = Framing.GetTileSafely(num6 + index1, num7 + index2);
                        if (!tileSafely.active())
                        {
                            tileSafely.active(true);
                            tileSafely.frameX = (short)num8;
                            tileSafely.frameY = (short)num9;
                            tileSafely.type   = num1;
                        }
                        num9 += tileData.CoordinateHeights[index2] + tileData.CoordinatePadding;
                    }
                }
            }
            if (tileData.FlattenAnchors)
            {
                AnchorData anchorData = tileData.AnchorBottom;
                if (anchorData.tileCount != 0 && (anchorData.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int num = toBePlaced.xCoord + anchorData.checkStart;
                    int j   = toBePlaced.yCoord + tileData.Height;
                    for (int index = 0; index < anchorData.tileCount; ++index)
                    {
                        Tile tileSafely = Framing.GetTileSafely(num + index, j);
                        if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && tileSafely.blockType() != 0)
                        {
                            WorldGen.SlopeTile(num + index, j, 0);
                        }
                    }
                }
                anchorData = tileData.AnchorTop;
                if (anchorData.tileCount != 0 && (anchorData.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int num = toBePlaced.xCoord + anchorData.checkStart;
                    int j   = toBePlaced.yCoord - 1;
                    for (int index = 0; index < anchorData.tileCount; ++index)
                    {
                        Tile tileSafely = Framing.GetTileSafely(num + index, j);
                        if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && tileSafely.blockType() != 0)
                        {
                            WorldGen.SlopeTile(num + index, j, 0);
                        }
                    }
                }
                anchorData = tileData.AnchorRight;
                if (anchorData.tileCount != 0 && (anchorData.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int i   = toBePlaced.xCoord + tileData.Width;
                    int num = toBePlaced.yCoord + anchorData.checkStart;
                    for (int index = 0; index < anchorData.tileCount; ++index)
                    {
                        Tile tileSafely = Framing.GetTileSafely(i, num + index);
                        if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && tileSafely.blockType() != 0)
                        {
                            WorldGen.SlopeTile(i, num + index, 0);
                        }
                    }
                }
                anchorData = tileData.AnchorLeft;
                if (anchorData.tileCount != 0 && (anchorData.type & AnchorType.SolidTile) == AnchorType.SolidTile)
                {
                    int i   = toBePlaced.xCoord - 1;
                    int num = toBePlaced.yCoord + anchorData.checkStart;
                    for (int index = 0; index < anchorData.tileCount; ++index)
                    {
                        Tile tileSafely = Framing.GetTileSafely(i, num + index);
                        if (Main.tileSolid[(int)tileSafely.type] && !Main.tileSolidTop[(int)tileSafely.type] && tileSafely.blockType() != 0)
                        {
                            WorldGen.SlopeTile(i, num + index, 0);
                        }
                    }
                }
            }
            return(true);
        }
Beispiel #7
0
        public static void DrawPreview(SpriteBatch sb, TileObjectPreviewData op, Vector2 position)
        {
            Point16        coordinates = op.Coordinates;
            Texture2D      texture     = Main.tileTexture[op.Type];
            TileObjectData tileData    = TileObjectData.GetTileData(op.Type, op.Style, op.Alternate);
            int            num         = 0;
            int            num2        = 0;
            int            num3        = tileData.CalculatePlacementStyle(op.Style, op.Alternate, op.Random);
            int            num4        = 0;
            int            num5        = tileData.DrawYOffset;

            if (tileData.StyleWrapLimit > 0)
            {
                num4  = num3 / tileData.StyleWrapLimit;
                num3 %= tileData.StyleWrapLimit;
            }
            if (tileData.StyleHorizontal)
            {
                num  = tileData.CoordinateFullWidth * num3;
                num2 = tileData.CoordinateFullHeight * num4;
            }
            else
            {
                num  = tileData.CoordinateFullWidth * num4;
                num2 = tileData.CoordinateFullHeight * num3;
            }
            for (int i = 0; i < op.Size.X; i++)
            {
                int x    = num + (i - op.ObjectStart.X) * (tileData.CoordinateWidth + tileData.CoordinatePadding);
                int num6 = num2;
                for (int j = 0; j < op.Size.Y; j++)
                {
                    int num7 = coordinates.X + i;
                    int num8 = coordinates.Y + j;
                    if (j == 0 && tileData.DrawStepDown != 0)
                    {
                        Tile tileSafely = Framing.GetTileSafely(num7, num8 - 1);
                        if (WorldGen.SolidTile(tileSafely))
                        {
                            num5 += tileData.DrawStepDown;
                        }
                    }
                    Color color;
                    switch (op[i, j])
                    {
                    case 2:
                        color = Color.Red * 0.7f;
                        break;

                    case 1:
                        color = Color.White;
                        break;

                    default:
                        continue;
                    }
                    color *= 0.5f;
                    if (i >= op.ObjectStart.X && i < op.ObjectStart.X + tileData.Width && j >= op.ObjectStart.Y && j < op.ObjectStart.Y + tileData.Height)
                    {
                        SpriteEffects spriteEffects = SpriteEffects.None;
                        if (tileData.DrawFlipHorizontal && i % 2 == 1)
                        {
                            spriteEffects |= SpriteEffects.FlipHorizontally;
                        }
                        if (tileData.DrawFlipVertical && j % 2 == 1)
                        {
                            spriteEffects |= SpriteEffects.FlipVertically;
                        }
                        sb.Draw(sourceRectangle: new Rectangle(x, num6, tileData.CoordinateWidth, tileData.CoordinateHeights[j - op.ObjectStart.Y]), texture: texture, position: new Vector2(num7 * 16 - (int)(position.X + (float)(tileData.CoordinateWidth - 16) / 2f), num8 * 16 - (int)position.Y + num5), color: color, rotation: 0f, origin: Vector2.Zero, scale: 1f, effects: spriteEffects, layerDepth: 0f);
                        num6 += tileData.CoordinateHeights[j - op.ObjectStart.Y] + tileData.CoordinatePadding;
                    }
                }
            }
        }
		public static bool Place(TileObject toBePlaced)
		{
			int num;
			int num1;
			TileObjectData tileData = TileObjectData.GetTileData(toBePlaced.type, toBePlaced.style, toBePlaced.alternate);
			if (tileData == null)
			{
				return false;
			}
			if (tileData.HookPlaceOverride.hook == null)
			{
				ushort num2 = (ushort)toBePlaced.type;
				int coordinateFullWidth = 0;
				int coordinateFullHeight = 0;
				int styleWrapLimit = tileData.CalculatePlacementStyle(toBePlaced.style, toBePlaced.alternate, toBePlaced.random);
				int styleWrapLimit1 = 0;
				if (tileData.StyleWrapLimit > 0)
				{
					styleWrapLimit1 = styleWrapLimit / tileData.StyleWrapLimit;
					styleWrapLimit = styleWrapLimit % tileData.StyleWrapLimit;
				}
				if (!tileData.StyleHorizontal)
				{
					coordinateFullWidth = tileData.CoordinateFullWidth * styleWrapLimit1;
					coordinateFullHeight = tileData.CoordinateFullHeight * styleWrapLimit;
				}
				else
				{
					coordinateFullWidth = tileData.CoordinateFullWidth * styleWrapLimit;
					coordinateFullHeight = tileData.CoordinateFullHeight * styleWrapLimit1;
				}
				int num3 = toBePlaced.xCoord;
				int num4 = toBePlaced.yCoord;
				for (int i = 0; i < tileData.Width; i++)
				{
					for (int j = 0; j < tileData.Height; j++)
					{
						Tile tileSafely = Framing.GetTileSafely(num3 + i, num4 + j);
						if (tileSafely.active() && Main.tileCut[tileSafely.type])
						{
							WorldGen.KillTile(num3 + i, num4 + j, false, false, false);
						}
					}
				}
				for (int k = 0; k < tileData.Width; k++)
				{
					int coordinateWidth = coordinateFullWidth + k * (tileData.CoordinateWidth + tileData.CoordinatePadding);
					int coordinateHeights = coordinateFullHeight;
					for (int l = 0; l < tileData.Height; l++)
					{
						Tile tile = Framing.GetTileSafely(num3 + k, num4 + l);
						if (!tile.active())
						{
							tile.active(true);
							tile.frameX = (short)coordinateWidth;
							tile.frameY = (short)coordinateHeights;
							tile.type = num2;
						}
						coordinateHeights = coordinateHeights + tileData.CoordinateHeights[l] + tileData.CoordinatePadding;
					}
				}
			}
			else
			{
				if (!tileData.HookPlaceOverride.processedCoordinates)
				{
					num = toBePlaced.xCoord + tileData.Origin.X;
					num1 = toBePlaced.yCoord + tileData.Origin.Y;
				}
				else
				{
					num = toBePlaced.xCoord;
					num1 = toBePlaced.yCoord;
				}
				if (tileData.HookPlaceOverride.hook(num, num1, toBePlaced.type, toBePlaced.style, 1) == tileData.HookPlaceOverride.badReturn)
				{
					return false;
				}
			}
			if (tileData.FlattenAnchors)
			{
				AnchorData anchorBottom = tileData.AnchorBottom;
				if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
				{
					int num5 = toBePlaced.xCoord + anchorBottom.checkStart;
					int num6 = toBePlaced.yCoord + tileData.Height;
					for (int m = 0; m < anchorBottom.tileCount; m++)
					{
						Tile tileSafely1 = Framing.GetTileSafely(num5 + m, num6);
						if (Main.tileSolid[tileSafely1.type] && !Main.tileSolidTop[tileSafely1.type] && tileSafely1.blockType() != 0)
						{
							WorldGen.SlopeTile(num5 + m, num6, 0);
						}
					}
				}
				anchorBottom = tileData.AnchorTop;
				if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
				{
					int num7 = toBePlaced.xCoord + anchorBottom.checkStart;
					int num8 = toBePlaced.yCoord - 1;
					for (int n = 0; n < anchorBottom.tileCount; n++)
					{
						Tile tile1 = Framing.GetTileSafely(num7 + n, num8);
						if (Main.tileSolid[tile1.type] && !Main.tileSolidTop[tile1.type] && tile1.blockType() != 0)
						{
							WorldGen.SlopeTile(num7 + n, num8, 0);
						}
					}
				}
				anchorBottom = tileData.AnchorRight;
				if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
				{
					int num9 = toBePlaced.xCoord + tileData.Width;
					int num10 = toBePlaced.yCoord + anchorBottom.checkStart;
					for (int o = 0; o < anchorBottom.tileCount; o++)
					{
						Tile tileSafely2 = Framing.GetTileSafely(num9, num10 + o);
						if (Main.tileSolid[tileSafely2.type] && !Main.tileSolidTop[tileSafely2.type] && tileSafely2.blockType() != 0)
						{
							WorldGen.SlopeTile(num9, num10 + o, 0);
						}
					}
				}
				anchorBottom = tileData.AnchorLeft;
				if (anchorBottom.tileCount != 0 && (anchorBottom.type & AnchorType.SolidTile) == AnchorType.SolidTile)
				{
					int num11 = toBePlaced.xCoord - 1;
					int num12 = toBePlaced.yCoord + anchorBottom.checkStart;
					for (int p = 0; p < anchorBottom.tileCount; p++)
					{
						Tile tile2 = Framing.GetTileSafely(num11, num12 + p);
						if (Main.tileSolid[tile2.type] && !Main.tileSolidTop[tile2.type] && tile2.blockType() != 0)
						{
							WorldGen.SlopeTile(num11, num12 + p, 0);
						}
					}
				}
			}
			return true;
		}
Beispiel #9
0
        // Token: 0x060001A7 RID: 423 RVA: 0x0002FF68 File Offset: 0x0002E168
        public static void DrawPreview(SpriteBatch sb, TileObjectPreviewData op, Vector2 position)
        {
            Point16        coordinates = op.Coordinates;
            Texture2D      texture     = Main.tileTexture[(int)op.Type];
            TileObjectData tileData    = TileObjectData.GetTileData((int)op.Type, (int)op.Style, op.Alternate);
            int            num         = tileData.CalculatePlacementStyle((int)op.Style, op.Alternate, op.Random);
            int            num2        = 0;
            int            num3        = tileData.DrawYOffset;

            if (tileData.StyleWrapLimit > 0)
            {
                num2 = num / tileData.StyleWrapLimit * tileData.StyleLineSkip;
                num %= tileData.StyleWrapLimit;
            }
            int num4;
            int num5;

            if (tileData.StyleHorizontal)
            {
                num4 = tileData.CoordinateFullWidth * num;
                num5 = tileData.CoordinateFullHeight * num2;
            }
            else
            {
                num4 = tileData.CoordinateFullWidth * num2;
                num5 = tileData.CoordinateFullHeight * num;
            }
            for (int i = 0; i < (int)op.Size.X; i++)
            {
                int x    = num4 + (i - (int)op.ObjectStart.X) * (tileData.CoordinateWidth + tileData.CoordinatePadding);
                int num6 = num5;
                int j    = 0;
                while (j < (int)op.Size.Y)
                {
                    int num7 = (int)coordinates.X + i;
                    int num8 = (int)coordinates.Y + j;
                    if (j == 0 && tileData.DrawStepDown != 0 && WorldGen.SolidTile(Framing.GetTileSafely(num7, num8 - 1)))
                    {
                        num3 += tileData.DrawStepDown;
                    }
                    int   num9 = op[i, j];
                    Color color;
                    if (num9 == 1)
                    {
                        color = Color.White;
                        goto IL_156;
                    }
                    if (num9 == 2)
                    {
                        color = Color.Red * 0.7f;
                        goto IL_156;
                    }
IL_289:
                    j++;
                    continue;
IL_156:
                    color *= 0.5f;
                    if (i >= (int)op.ObjectStart.X && i < (int)op.ObjectStart.X + tileData.Width && j >= (int)op.ObjectStart.Y && j < (int)op.ObjectStart.Y + tileData.Height)
                    {
                        SpriteEffects spriteEffects = SpriteEffects.None;
                        if (tileData.DrawFlipHorizontal && i % 2 == 1)
                        {
                            spriteEffects |= SpriteEffects.FlipHorizontally;
                        }
                        if (tileData.DrawFlipVertical && j % 2 == 1)
                        {
                            spriteEffects |= SpriteEffects.FlipVertically;
                        }
                        Rectangle value = new Rectangle(x, num6, tileData.CoordinateWidth, tileData.CoordinateHeights[j - (int)op.ObjectStart.Y]);
                        sb.Draw(texture, new Vector2((float)(num7 * 16 - (int)(position.X + (float)(tileData.CoordinateWidth - 16) / 2f)), (float)(num8 * 16 - (int)position.Y + num3)), new Rectangle?(value), color, 0f, Vector2.Zero, 1f, spriteEffects, 0f);
                        num6 += tileData.CoordinateHeights[j - (int)op.ObjectStart.Y] + tileData.CoordinatePadding;
                        goto IL_289;
                    }
                    goto IL_289;
                }
            }
        }