Exemplo n.º 1
0
    private void UpdatePlacing()
    {
        if (!InBuildMode)
        {
            return;
        }

        if (!InputManager.InputPressed("Shoot"))
        {
            return;
        }

        int x = (int)InputManager.GetMousePos().x;
        int y = (int)InputManager.GetMousePos().y;

        if (CanPlace(x, y) != null)
        {
            return;
        }

        if (Player.Local == null)
        {
            return;
        }

        if (BuildingUI.Instance == null)
        {
            return;
        }

        BuildingItem item = GetSelectedItem();

        if (item != null)
        {
            // Place tile using the pending building system.
            // My god the code in this project is horrible :/
            string layer = "Foreground";
            switch (item.Type)
            {
            case BuildingItemType.FURNITURE:
                Furniture f = item.GetFurniture();
                layer = f.Layer;
                break;

            case BuildingItemType.TILE:
                BaseTile tile = item.GetTile();
                layer = tile.Layer;
                break;
            }

            PendingBuildingManager.Instance.AddPending(x, y, item.Prefab, item.Type, layer);
        }
    }
Exemplo n.º 2
0
    public string CanPlace(int x, int y)
    {
        bool inBounds = World.Instance.TileMap.InBounds(x, y);

        if (!inBounds)
        {
            return("Out of world bounds!");
        }

        bool placementMode = InBuildMode && !menuOpen;

        if (!placementMode)
        {
            return("Not in placement mode!");
        }

        BuildingItem item        = GetSelectedItem();
        bool         hasSelected = item != null;

        if (!hasSelected)
        {
            return("No buildable selected! Hold [" + InputManager.GetInput("Toggle Build Mode") + "] to open menu.");
        }

        if (item.Type == BuildingItemType.TILE)
        {
            BaseTile oldTile = World.Instance.TileMap.GetLayer(item.GetTile().Layer).GetTile(x, y);

            if (oldTile != null)
            {
                return("Space already occupied!");
            }

            bool canPlaceTile = World.Instance.TileMap.GetLayer(item.GetTile().Layer).CanPlaceTile(x, y);
            if (!canPlaceTile)
            {
                return("Space already occupied!");
            }
        }
        else if (item.Type == BuildingItemType.FURNITURE)
        {
            bool canPlaceFurniture = !World.Instance.Furniture.IsFurnitureAt(x, y) && World.Instance.TileMap.GetLayer(item.GetFurniture().Layer).GetTile(x, y) == null;
            if (!canPlaceFurniture)
            {
                return("Space already occupied!");
            }
        }

        return(null);
    }