예제 #1
0
    /*
     * Check if the user tried planting and if so, check that location is
     * a valid place to plant. Then plant it and handle inventory changes.
     */
    void TryPlanting()
    {
        bool isUsingItem = RBInput.GetButtonDownForPlayer(InputStrings.ITEM, PlayerIndex, playerDevice);

        if (isUsingItem)
        {
            if (actionTile != null)
            {
                GroundTile tile = (GroundTile)actionTile.GetComponent <GroundTile> ();
                //TODO This violates MVC, fix it
                if (tile.isSoil() && tile.getPlant() == null)
                {
                    Inventory inventory = (Inventory)GetComponent <Inventory> ();
                    if (inventory.GetEquippedItem() != null)
                    {
                        GameObject plant = inventory.GetEquippedItem().plantPrefab;
                        tile.Plant(plant);
                        inventory.RemoveItem(inventory.GetEquippedItem().id, 1);
                    }
                }
            }
        }
    }