示例#1
0
        // World replacement
        public static void ReplaceTiles(int i, int j, Hooks.TileData data, int style = 0)
        {
            WorldGen.PlaceTile(i, j, data.type, true, true, -1, style);
            if (data.wall != 0)
            {
                WorldGen.PlaceWall(i, j, data.wall, true);
            }

            OTAPI.Tile.ITile tile = Main.tile[i, j];
            tile.type = data.type;
            if (data.halfBrick)
            {
                tile.halfBrick(data.halfBrick);
            }
            else
            {
                tile.slope(data.slope);
            }
            //  TODO: sort out slopes after replacing the tiles. This is returning a System.IndexOutOfRangeException.
            int x = Netplay.GetSectionX(i);
            int y = Netplay.GetSectionY(j);

            foreach (RemoteClient sock in Netplay.Clients.Where(t => t.IsActive))
            {
                sock.TileSections[x, y] = false;
            }
        }
示例#2
0
 public async static Task <List <Item> > GetItemFromTile(int x, int y, OTAPI.Tile.ITile itile, MapManager.MapData map = null)
 {
     return(await Task.Run(() =>
     {
         List <Item> list = new List <Item>(2)
         {
             [0] = new Item(),
             [1] = new Item()
         };
         try
         {
             int id = 0;
             int stack = 0;
             int secondaryitem = 0;
             int secondarystack = 0;
             if (map == null)
             {
                 WorldGen.KillTile_GetItemDrops(x, y, itile, out id, out stack, out secondaryitem, out secondarystack);
             }
             else
             {
                 map.KillTile_GetItemDrops(x, y, itile, out id, out stack, out secondaryitem, out secondarystack);
             }
             list[0].SetDefaults(id);
             list[0].stack = stack;
             list[1].SetDefaults(id);
             list[1].stack = stack;
         }
         catch { }
         return list;
     }));
 }
示例#3
0
        /// <summary>
        /// Copies members from an ITile to a TEdit style Tile.
        /// </summary>
        /// <param name="dst"></param>
        /// <param name="src"></param>
        public static void CopyFrom(this Tile dst, OTAPI.Tile.ITile src)
        {
            //still needs support for wires.
            dst.Type       = src.type;
            dst.Wall       = src.wall;
            dst.LiquidType = (LiquidType)src.liquid;

            dst.IsActive  = src.active();
            dst.InActive  = src.inActive();
            dst.Actuator  = src.actuator();
            dst.TileColor = src.color();
            dst.WallColor = src.wallColor();

            if (!src.halfBrick())
            {
                dst.BrickStyle = BrickStyle.Full;
            }
            else
            {
                switch (src.slope())
                {
                case 2:
                    dst.BrickStyle = BrickStyle.SlopeTopRight;
                    break;

                case 3:
                    dst.BrickStyle = BrickStyle.SlopeTopLeft;
                    break;

                case 4:
                    dst.BrickStyle = BrickStyle.SlopeBottomRight;
                    break;

                case 5:
                    dst.BrickStyle = BrickStyle.SlopeBottomLeft;
                    break;

                default:
                    dst.BrickStyle = BrickStyle.HalfBrick;
                    break;
                }
            }

            dst.U = src.frameX;
            dst.V = src.frameY;
        }
示例#4
0
        /// <summary>
        /// Copies members from a TEdit style Tile to an OTAPI.Tile.ITile.
        /// </summary>
        /// <param name="dst"></param>
        /// <param name="src"></param>
        public static void CopyFrom(this OTAPI.Tile.ITile dst, Tile src)
        {
            //still needs support for wires.

            dst.type   = src.Type;
            dst.wall   = src.Wall;
            dst.liquid = (byte)src.LiquidType;

            //dst.sTileHeader = src.

            dst.active(src.IsActive);
            dst.inActive(src.InActive);
            dst.actuator(src.Actuator);
            dst.color(src.TileColor);
            dst.wallColor(src.WallColor);

            switch (src.BrickStyle)
            {
            case BrickStyle.Full:
                dst.halfBrick(false);
                break;

            case BrickStyle.HalfBrick:
                dst.halfBrick(true);
                break;

            case BrickStyle.SlopeTopRight:
            case BrickStyle.SlopeTopLeft:
            case BrickStyle.SlopeBottomRight:
            case BrickStyle.SlopeBottomLeft:
                dst.slope((byte)src.BrickStyle);
                break;
            }

            dst.frameX = src.U;
            dst.frameY = src.V;
        }
示例#5
0
        public static int SpawnMobAroundPlayer(TSPlayer player, CustomNPCDefinition definition)
        {
            const int SpawnSpaceX = 3;
            const int SpawnSpaceY = 3;

            //Search for a location
            int screenTilesX = (int)(NPC.sWidth / 16f);
            int screenTilesY = (int)(NPC.sHeight / 16f);
            int spawnRangeX  = (int)(screenTilesX * 0.7);
            int spawnRangeY  = (int)(screenTilesY * 0.7);
            int safeRangeX   = (int)(screenTilesX * 0.52);
            int safeRangeY   = (int)(screenTilesY * 0.52);

            Vector2 position    = player.TPlayer.position;
            int     playerTileX = (int)(position.X / 16f);
            int     playerTileY = (int)(position.Y / 16f);

            int spawnRangeMinX = Math.Max(0, Math.Min(Main.maxTilesX, playerTileX - spawnRangeX));
            int spawnRangeMaxX = Math.Max(0, Math.Min(Main.maxTilesX, playerTileX + spawnRangeX));
            int spawnRangeMinY = Math.Max(0, Math.Min(Main.maxTilesY, playerTileY - spawnRangeY));
            int spawnRangeMaxY = Math.Max(0, Math.Min(Main.maxTilesY, playerTileY + spawnRangeY));

            int safeRangeMinX = Math.Max(0, Math.Min(Main.maxTilesX, playerTileX - safeRangeX));
            int safeRangeMaxX = Math.Max(0, Math.Min(Main.maxTilesX, playerTileX + safeRangeX));
            int safeRangeMinY = Math.Max(0, Math.Min(Main.maxTilesY, playerTileY - safeRangeY));
            int safeRangeMaxY = Math.Max(0, Math.Min(Main.maxTilesY, playerTileY + safeRangeY));

            int spawnX = 0;
            int spawnY = 0;

            bool found    = false;
            int  attempts = 0;

            while (attempts < 50)
            {
                int testX = rand.Next(spawnRangeMinX, spawnRangeMaxX);
                int testY = rand.Next(spawnRangeMinY, spawnRangeMaxY);

                OTAPI.Tile.ITile testTile = Main.tile[testX, testY];
                if (testTile.nactive() && Main.tileSolid[testTile.type])
                {
                    attempts++;
                    continue;
                }

                if (!Main.wallHouse[testTile.wall])
                {
                    for (int y = testY; y < Main.maxTilesY; y++)
                    {
                        OTAPI.Tile.ITile test = Main.tile[testX, y];
                        if (test.nactive() && Main.tileSolid[test.type])
                        {
                            if (testX < safeRangeMinX || testX > safeRangeMaxX || y < safeRangeMinY || y > safeRangeMaxY)
                            {
                                spawnX = testX;
                                spawnY = y;
                                found  = true;
                                break;
                            }
                        }
                    }

                    if (!found)
                    {
                        attempts++;
                    }

                    int spaceMinX = spawnX - (SpawnSpaceX / 2);
                    int spaceMaxX = spawnX + (SpawnSpaceX / 2);
                    int spaceMinY = spawnY - SpawnSpaceY;
                    int spaceMaxY = spawnY;
                    if (spaceMinX < 0 || spaceMaxX > Main.maxTilesX)
                    {
                        attempts++;
                        continue;
                    }

                    if (spaceMinY < 0 || spaceMaxY > Main.maxTilesY)
                    {
                        attempts++;
                        continue;
                    }

                    if (found)
                    {
                        for (int x = spaceMinX; x < spaceMaxX; x++)
                        {
                            for (int y = spaceMinY; y < spaceMaxY; y++)
                            {
                                if (Main.tile[x, y].nactive() && Main.tileSolid[Main.tile[x, y].type])
                                {
                                    found = false;
                                    break;
                                }

                                if (Main.tile[x, y].lava())
                                {
                                    found = false;
                                    break;
                                }
                            }
                        }

                        if (!found)
                        {
                            attempts++;
                            continue;
                        }
                    }

                    if (spawnX >= safeRangeMinX && spawnX <= safeRangeMaxX)
                    {
                        if (!found)
                        {
                            attempts++;
                            continue;
                        }
                    }
                }
            }

            if (found)
            {
                return(SpawnCustomNPC((spawnX * 16) + 8, spawnY * 16, definition));
            }

            return(-1);
        }
        /// <summary>
        /// Sets a tile at position X and Y to the tile instance specified.
        /// </summary>
        /// <param name="tile">
        /// A tile instance in which to store
        /// </param>
        /// <param name="x">X coordinate of the tile to store</param>
        /// <param name="y">Y coordinate of the tile to store</param>
        /// <remarks>
        /// Virtual function that derivatives must override if they want to implement getting of a tile from
        /// its backing store.
        /// </remarks>
        protected virtual void SetTile(OTAPI.Tile.ITile tile, int x, int y)
        {
            HeapTile heapTile = new HeapTile(tileHeap, x, y);

            heapTile.CopyFrom(tile);
        }