예제 #1
0
    public override string Execute(object[] args)
    {
        string type   = ((string)args[0]).Trim().ToLower();
        string prefab = ((string)args[1]).Trim();
        int    count  = (int)args[2];

        if (count <= 0)
        {
            return("Count must be greater than 0");
        }

        if (type == "tile")
        {
            Player.Local.BuildingInventory.AddItems(BaseTile.GetTile(prefab), count);
            return(null);
        }
        else if (type == "furniture" || type == "furn")
        {
            Player.Local.BuildingInventory.AddItems(Furniture.GetFurniture(prefab), count);
            return(null);
        }
        else
        {
            return("Invalid type param. Must be 'tile' or 'furniture'.");
        }
    }
예제 #2
0
    public BaseTile GetTile()
    {
        if (Type != BuildingItemType.TILE)
        {
            Debug.LogError("This is not a tile! (" + Name + ", " + Prefab + ")");
            return(null);
        }

        return(BaseTile.GetTile(Prefab));
    }
예제 #3
0
    public static BaseTile[][] MakeChunk(string str, int chunkSize, UnityAction <string> error = null, bool rle = true)
    {
        BaseTile[][] chunk = new BaseTile[chunkSize][];

        if (rle && str != null)
        {
            str = UnRLE(str);
        }

        string[] parts = str.Split(',');

        if (parts.Length != chunkSize * chunkSize)
        {
            if (error != null)
            {
                error.Invoke("Incorrect number of tiles for chunk: found " + parts.Length + " when " + chunkSize * chunkSize + " were expected.");
            }
            return(null);
        }

        for (int x = 0; x < chunkSize; x++)
        {
            chunk[x] = new BaseTile[chunkSize];
            for (int y = 0; y < chunkSize; y++)
            {
                int index = x + chunkSize * y;

                string prefab = parts[index].Trim();

                if (prefab == NULL_ERROR.ToString())
                {
                    continue;
                }

                if (BaseTile.ContainsTile(prefab))
                {
                    chunk[x][y] = BaseTile.GetTile(prefab);
                }
                else
                {
                    if (error != null)
                    {
                        error.Invoke("Tile '" + prefab + "' not found @ local position " + x + ", " + y + ".");
                    }
                }
            }
        }

        return(chunk);
    }
예제 #4
0
    public void ApplyPendingOperationsToChunk(int index, bool destroyList = false)
    {
        // Applies pending tile operations from clients to a loaded chunk on the server.
        if (AnyPendingOperationsFor(index))
        {
            if (!IsChunkLoaded(index))
            {
                if (!IsChunkLoading(index))
                {
                    Debug.LogError("The chunk for index " + index + " is not loaded or loading, cannot apply pending operations.");
                }
            }

            Chunk chunk = GetChunkFromIndex(index);

            // Set tiles based on the pending tile operations.
            foreach (NetPendingTile op in PendingOperations[index])
            {
                bool     empty = op.PrefabIsNull();
                BaseTile tile  = null;
                if (!empty)
                {
                    if (!BaseTile.ContainsTile(op.Prefab))
                    {
                        Debug.LogError("Pending operation requested tile '" + op.Prefab + "', but the server could not find it.");
                        continue;
                    }

                    tile = BaseTile.GetTile(op.Prefab);
                }

                int globalX = op.X + chunk.X * ChunkSize;
                int globalY = op.Y + chunk.Y * ChunkSize;

                // Set the tile, locally on the server, without networking.
                SetTile_Server(tile, globalX, globalY, false);
            }

            // Clear those pending operations, they are no longer pending!
            if (!destroyList)
            {
                PendingOperations[index].Clear();
            }
            else
            {
                PendingOperations.Remove(index);
            }
        }
    }
예제 #5
0
    public void RecievedTileChange(Msg_SendTile data)
    {
        // Called on clients when a tile has been set.

        // Confirm to the pending placement system...
        PendingBuildingManager.Instance.ConfirmPlaced(PendingBuildingManager.MakeID(data.X, data.Y));

        // If we are a host, just stop. Tile has already been set.
        if (isServer)
        {
            return;
        }

        // Check if is in bounds.
        if (!InLayerBounds(data.X, data.Y))
        {
            Debug.LogError("Why did the server send me coordinates out of bounds?!?! (" + data.X + ", " + data.Y + ")");
            return;
        }

        // Check if it is loaded. If it is not ignore this. TODO if it is loading, make it be applied once loaded.
        if (IsChunkLoaded(GetChunkIndexFromTileCoords(data.X, data.Y)))
        {
            // Place tile in position.
            BaseTile oldTile = Tiles[data.X][data.Y];

            BaseTile tile = data.Prefab == null ? null : BaseTile.GetTile(data.Prefab);

            Chunk c = GetChunkFromIndex(GetChunkIndexFromTileCoords(data.X, data.Y));

            if (oldTile != null)
            {
                TileRemoved(data.X, data.Y, oldTile, c);
            }

            // Apply tile.
            Tiles[data.X][data.Y] = tile;

            // Update tiles sourrounding and update physics bodies.
            TilePlaced(data.X, data.Y, tile, c);
        }
    }
    public void AddPending(int x, int y, string prefab, BuildingItemType type, string layer)
    {
        if (IsPendingAt(x, y))
        {
            return;
        }

        PendingBuildData data = new PendingBuildData();

        data.Prefab = prefab;
        data.Type   = type;
        data.Layer  = layer;
        data.X      = x;
        data.Y      = y;

        Pending.Add(data.GetID(), data);

        // TODO: This can still mess up when the server cannot place a tile.
        // The tile or furniture should be returned to the client in that case.

        // TODO only remove once the tile is placed.
        // Now do the real placing request...
        switch (data.Type)
        {
        case BuildingItemType.TILE:

            // Place tile.
            BaseTile tile = BaseTile.GetTile(data.Prefab);
            World.Instance.TileMap.GetLayer(layer).SetTile(tile, x, y);

            break;

        case BuildingItemType.FURNITURE:

            // Place furniture
            World.Instance.Furniture.PlaceFurniture(data.Prefab, x, y);

            break;
        }
    }
예제 #7
0
    public void CmdRequestTileChange(string prefab, int x, int y, string layer)
    {
        BaseTile tile = (string.IsNullOrEmpty(prefab) ? null : BaseTile.GetTile(prefab));

        World.Instance.TileMap.GetLayer(layer).ClientRequestingTileChange(tile, x, y);
    }