/* * If tile has a plant and player isn't out of water, water it. */ void TryWatering() { bool isWatering = RBInput.GetButtonDownForPlayer(InputStrings.WEAPON2, PlayerIndex, playerDevice); if (isWatering) { if (actionTile != null) { GroundTile tile = (GroundTile)actionTile.GetComponent <GroundTile> (); Plant plant = tile.getPlant(); if (plant != null) { plant.Water(); } SpawnWaterFX(); } } }
/* * Check if the tile is a valid tile to be picked and if so, pick it * and handle inventory changes. */ void TryPicking() { bool isAction = RBInput.GetButtonDownForPlayer(InputStrings.ACTION, PlayerIndex, playerDevice); if (isAction) { //.TODO This violates MVC, fix it if (actionTile != null) { GroundTile tile = (GroundTile)actionTile.GetComponent <GroundTile> (); Plant plant = tile.getPlant(); if (plant != null && plant.isRipe()) { Inventory inventory = (Inventory)GetComponent <Inventory> (); int pickedItemID = tile.Pick(); inventory.AddItem(pickedItemID, 1); AudioSource.PlayClipAtPoint(backpackSound, transform.position); } } } }
/* * 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); } } } } }