public override void HandleInteractions() { if (Vector3.Distance(player.transform.position, this.transform.position) < 0.4f) { if (fermentationDone && inventory.CheckForItemInInventory("empty_wine_barrel")) { mySpriteRenderer.sprite = emptyJarSprite; isBeingUsed = false; inventory.RemoveItem("empty_wine_barrel", 1); inventory.AddItem("full_wine_barrel", 1); fermentationDone = false; return; } if (!fermentationDone && fermenting) { notificationsManager.StartSpawningText("The wine is still fermenting!"); return; } if (fermentationDone && !inventory.CheckForItemInInventory("empty_wine_barrel")) { notificationsManager.StartSpawningText("You need an empty wine barrel to store the fermented wine"); return; } return; } notificationsManager.StartSpawningText("Too far away!"); }
void OnMouseOver() { if (Input.GetMouseButtonDown(1)) { if (Vector2.Distance(player.transform.position, transform.position) < 0.4f) { if (empty) { inventory.AddItem("empty_wine_barrel", 1); this.gameObject.SetActive(false); return; } if (doneAging) { inventory.AddItem("aged_wine_barrel", 1); this.gameObject.SetActive(false); return; } notificationsManager.StartSpawningText("The wine in this barrel is still fermenting"); return; } notificationsManager.StartSpawningText("Too far away"); return; } }
public void OnDrop(PointerEventData eventData) { if (Vector3.Distance(player.transform.position, this.transform.position) < 0.4f) { if (eventData.pointerDrag.GetComponent <ItemData>().item.itemSlug != null) { if (eventData.pointerDrag.GetComponent <ItemData>().item.itemSlug == "empty_wine_bottle") { inventory.RemoveItem("empty_wine_bottle", 1); foreach (GameObject slot in listOfBottleSlots) { if (!slot.transform.GetChild(0).gameObject.activeSelf) { slot.transform.GetChild(0).gameObject.SetActive(true); slot.transform.GetChild(0).GetComponent <Bottle>().myType = Bottle.BottleType.empty; slot.transform.GetChild(0).GetComponent <Bottle>().ShowBottle(); return; } } notificationsManager.StartSpawningText("This bottle rack is full"); return; } if (eventData.pointerDrag.GetComponent <ItemData>().item.itemSlug == "full_wine_bottle") { inventory.RemoveItem("full_wine_bottle", 1); foreach (GameObject slot in listOfBottleSlots) { if (!slot.transform.GetChild(0).gameObject.activeSelf) { slot.transform.GetChild(0).gameObject.SetActive(true); slot.transform.GetChild(0).GetComponent <Bottle>().myType = Bottle.BottleType.full; slot.transform.GetChild(0).GetComponent <Bottle>().ShowBottle(); return; } } notificationsManager.StartSpawningText("This bottle rack is full"); return; } } } notificationsManager.StartSpawningText("Too far away!"); }
public void OnDrop(PointerEventData eventData) { if (Vector2.Distance(player.transform.position, transform.position) <= 0.5f) { if (eventData.pointerDrag.GetComponent <ItemData>().item.itemSlug == "full_grape_basket_s") { if (!isBeingUsed && isEmpty) { stompingMinigameController.wineBucket = this.gameObject; if (inventory.CheckForItemInInventory("full_grape_basket_s")) { inventory.RemoveItem("full_grape_basket_s", 1); inventory.AddItem("empty_grape_basket", 1); mySpriteRender.sprite = fullStateImage; isEmpty = false; return; } } else if (!isBeingUsed && !isEmpty) { notificationsManager.StartSpawningText("The stomping bucket is already full"); return; } } if (!isBeingUsed && !isEmpty) { notificationsManager.StartSpawningText("The stomping bucket is already full"); return; } notificationsManager.StartSpawningText("Bring a basket of sorted grapes to fill this stomping bucket"); return; } notificationsManager.StartSpawningText("Too far away!"); return; }
public void OnDrop(PointerEventData eventData) { if (Vector3.Distance(player.transform.position, this.transform.position) < 0.4f) { if (eventData.pointerDrag.GetComponent <ItemData>().item.itemSlug == "empty_grape_basket_u") { if (!isBeingUsed && inventory.CheckForItemInInventory("full_grape_basket_u") == true) { sortingMiniGameController.StartTheSortingMiniGame(); Destroy(cameraUIManager.currentlyVisibleMenu); cameraUIManager.menuSpawned = false; return; } } notificationsManager.StartSpawningText("You need to bring unsorted grapes to use this table"); return; } notificationsManager.StartSpawningText("Too far away!"); return; }
public void OnDrop(PointerEventData eventData) { if (eventData.pointerDrag.GetComponent <ItemData>().item.itemSlug != null) { if (eventData.pointerDrag.GetComponent <ItemData>().item.itemSlug == "empty_wine_barrel") { inventory.RemoveItem("empty_wine_barrel", 1); foreach (GameObject slot in listOfBarrelSlots) { if (!slot.transform.GetChild(0).gameObject.activeSelf) { slot.transform.GetChild(0).gameObject.SetActive(true); slot.transform.GetChild(0).GetComponent <Barrel>().ShowEmptyBarrel(); break; } notificationsManager.StartSpawningText("This barrel rack is full"); } } if (eventData.pointerDrag.GetComponent <ItemData>().item.itemSlug == "full_wine_barrel") { inventory.RemoveItem("full_wine_barrel", 1); foreach (GameObject slot in listOfBarrelSlots) { if (!slot.transform.GetChild(0).gameObject.activeSelf) { slot.transform.GetChild(0).gameObject.SetActive(true); slot.transform.GetChild(0).GetComponent <Barrel>().ShowFullBarrel(); break; } notificationsManager.StartSpawningText("This barrel rack is full"); } } } }
public override void HandleInteractions() { if (!isBeingUsed && Vector2.Distance(player.transform.position, transform.position) <= 0.5f && !isPickedClean) { if (inventory.CheckForItemInInventory("empty_grape_basket")) { player.isUsingSomething = true; isBeingUsed = true; StartCoroutine(DeleteGrapesFromTree()); Destroy(cameraUIManager.currentlyVisibleMenu); cameraUIManager.menuSpawned = false; return; } notificationsManager.StartSpawningText("You need an empty bucket to pick grapes"); } }
public Item AddItem(string slug, int amountOfItem) // Method that adds items by slug and amount to add { Item itemToAdd = itemDatabase.GetItem(slug); // Grabbing the item we want to add from the database if (!CheckIfInventoryHasEmptySlots()) { notificationsManager.StartSpawningText("Inventory is full!"); return(null); } if (amountOfItem >= 20) { for (int i = 0; i < inventoryItems.Count; i++) // Go through the items in inventory { if (inventoryItems[i].itemSlug == null) // Add this item to an empty slot if the item is not stackable or there isn't an instance of this item in the inventory { inventoryItems[i] = itemToAdd; GameObject invObj = Instantiate(inventoryItem); // Spawning the inventory item prefab to then fill out with the passed item's properties invObj.transform.SetParent(slots[i].transform); // Parent the item prefab to the current slot invObj.transform.position = Vector2.zero; // Center the prefab invObj.transform.localScale = new Vector3(1, 1, 1); // Normalize its size invObj.GetComponent <Image>().sprite = itemToAdd.itemIcon; // Change its image to one of the added item var itemData = invObj.GetComponent <ItemData>(); itemData.currentSlot = i; // Set the item's slot to current slot itemData.amount = amountOfItem; // Set the amount to the amount we added itemData.item = itemToAdd; // Notify the profab that it is the added item invObj.GetComponentInChildren <Text>().text = invObj.GetComponent <ItemData>().amount.ToString(); // Write the amount of item in the bottom right corner invObj.name = itemToAdd.itemName; // Change the prefab's name to that of the item it will represent notificationsManager.StartSpawningText("+ " + " " + itemData.amount + " " + itemData.name); lastAddedItem = slots[i].gameObject.GetComponentInChildren <ItemData>().gameObject; return(inventoryItems[i]); } } } for (int i = 0; i < inventoryItems.Count; i++) // Go through the items in inventory { if (inventoryItems[i].itemSlug == null) // Add this item to an empty slot if the item is not stackable or there isn't an instance of this item in the inventory { inventoryItems[i] = itemToAdd; GameObject invObj = Instantiate(inventoryItem); // Spawning the inventory item prefab to then fill out with the passed item's properties invObj.transform.SetParent(slots[i].transform); // Parent the item prefab to the current slot slots[i].GetComponent <Slot>().myCurrentItem = invObj; slots[i].GetComponent <Slot>().myCurrentItem = invObj; invObj.transform.localPosition = new Vector3(0, 0, 0); // Center the prefab //Debug.Log("Added the " + itemToAdd.itemName + " to the inventory"); invObj.transform.localScale = new Vector3(1, 1, 1); // Normalize its size invObj.GetComponent <Image>().sprite = itemToAdd.itemIcon; // Change its image to one of the added item var itemData = invObj.GetComponent <ItemData>(); itemData.currentSlot = i; // Set the item's slot to current slot itemData.amount = amountOfItem; // Set the amount to the amount we added itemData.item = itemToAdd; // Notify the profab that it is the added item invObj.GetComponentInChildren <Text>().text = invObj.GetComponent <ItemData>().amount.ToString(); // Write the amount of item in the bottom right corner invObj.name = itemToAdd.itemName; // Change the prefab's name to that of the item it will represent notificationsManager.StartSpawningText("+ " + " " + itemData.amount + " " + itemData.name); lastAddedItem = slots[i].gameObject.GetComponentInChildren <ItemData>().gameObject; return(inventoryItems[i]); } else if ((inventoryItems[i].itemSlug == itemToAdd.itemSlug && itemToAdd.itemStackable && amountOfItem >= 20)) { int differenceToTwenty = 20 - slots[i].GetComponentInChildren <ItemData>().amount; slots[i].GetComponentInChildren <ItemData>().amount += (differenceToTwenty); // Add the passed amount to the slot with the same item slots[i].GetComponentInChildren <Text>().text = slots[i].GetComponentInChildren <ItemData>().amount.ToString(); // Write the new amount of item out int remainingAmount = amountOfItem - differenceToTwenty; AddRemainingAmountOfItem(itemToAdd, remainingAmount); lastAddedItem = slots[i].gameObject.GetComponentInChildren <ItemData>().gameObject; return(inventoryItems[i]); } else if ((inventoryItems[i].itemSlug == itemToAdd.itemSlug && itemToAdd.itemStackable && (slots[i].transform.GetChild(0).GetComponent <ItemData>().amount + amountOfItem) >= 20f)) { int differenceToTwenty = 20 - slots[i].GetComponentInChildren <ItemData>().amount; slots[i].GetComponentInChildren <ItemData>().amount += (differenceToTwenty); // Add the passed amount to the slot with the same item slots[i].GetComponentInChildren <Text>().text = slots[i].GetComponentInChildren <ItemData>().amount.ToString(); // Write the new amount of item out int remainingAmount = amountOfItem - differenceToTwenty; AddRemainingAmountOfItem(itemToAdd, remainingAmount); notificationsManager.StartSpawningText("+ " + " " + amountOfItem.ToString() + " " + itemDatabase.GetItem(slug).itemName); lastAddedItem = slots[i].gameObject.GetComponentInChildren <ItemData>().gameObject; return(inventoryItems[i]); } else if (inventoryItems[i].itemSlug == itemToAdd.itemSlug && itemToAdd.itemStackable && amountOfItem > 0) // Add the amount of this item to an already existing stack { inventoryItems[i] = itemToAdd; // Put the item we're adding in the inventory at this ID slots[i].GetComponentInChildren <ItemData>().currentSlot = i; // Make sure this item's internal ID matches the slot's ID slots[i].GetComponentInChildren <ItemData>().amount += amountOfItem; // Add the passed amount to the slot with the same item slots[i].GetComponentInChildren <Text>().text = slots[i].GetComponentInChildren <ItemData>().amount.ToString(); // Write the new amount of item out notificationsManager.StartSpawningText("+ " + " " + amountOfItem.ToString() + " " + itemDatabase.GetItem(slug).itemName); lastAddedItem = slots[i].gameObject.GetComponentInChildren <ItemData>().gameObject; return(inventoryItems[i]); } } return(null); }
// BELOW IS AN ALTERNATUVE WAY TO REVEAL BUILDING INTERIORS BASED ON RAYCASTS (IT HAS PERFORMANCE PROBLEMS, SO DISCARDED FOR NOW) //RaycastForInteriors(); /*void RaycastForInteriors() * { * RaycastHit2D[] hits = Physics2D.RaycastAll(playerInteriorChecker.transform.position, Vector2.zero, 100f, buildingLayerMask); * * for (int i = 0; i < hits.Length; i++) * { * Transform currentHit = hits[i].transform; * * if (hits[i].transform.gameObject.CompareTag("Building") && hits[i].transform.gameObject.GetComponent<BuildingActions>().hasInterior) * { * Renderer currentRend = currentHit.transform.GetComponent<Renderer>(); * * * if (currentRend) * { * * trackedBuildings.Add(currentRend.transform); * currentRend.enabled = false; * * } * * } * } * * //Clean the list of objects that are in the list but not currently hit. * for (int j = 0; j< trackedBuildings.Count; j++) * { * bool isHit = false; * * print("Set ishit to false"); * //Check every object in the list against every hit * for (int i = 0; i < hits.Length; i++) * { * if (hits[i].transform == trackedBuildings[j]) * { * isHit = true; * } * } * * if (!isHit) * { * print("Set to default"); * Transform wasHidden = trackedBuildings[j]; * wasHidden.GetComponent<Renderer>().enabled = true; * trackedBuildings.RemoveAt(j); * * * j--; * } * * * * * } * * }*/ void OnRightClick(GameObject currentlySelectedBuilding) { RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if (!hit) { if (menuSpawned) { Destroy(currentlyVisibleMenu); currentlyVisibleMenu = null; menuSpawned = false; return; } } else { //print("The raycast hit " + hit.collider.gameObject); if (hit.collider.gameObject.tag == "Building") { if (hit.collider.gameObject != lastSelectedBuilding) { gameManager.selectedBuilding = hit.collider.gameObject; lastSelectedBuilding = gameManager.selectedBuilding; gameManager.selectedConstructionSlot = hit.collider.transform.parent.gameObject; if (!menuSpawned) { Transform placeToInstantiateBuildingUI = gameManager.selectedBuilding.GetComponentInChildren <BuildingUISocket>().transform; currentlyVisibleMenu = Instantiate(buildingMenuPrefab, placeToInstantiateBuildingUI.transform.position, Quaternion.identity, placeToInstantiateBuildingUI.transform); menuSpawned = true; } else if (menuSpawned) { Destroy(currentlyVisibleMenu); currentlyVisibleMenu = null; menuSpawned = false; return; } } else if (hit.collider.gameObject.name == lastSelectedBuilding.name) { if (menuSpawned) { Destroy(currentlyVisibleMenu); currentlyVisibleMenu = null; menuSpawned = false; return; } else if (!menuSpawned) { Transform placeToInstantiateBuildingUI = gameManager.selectedBuilding.GetComponentInChildren <BuildingUISocket>().transform; currentlyVisibleMenu = Instantiate(buildingMenuPrefab, placeToInstantiateBuildingUI.transform.position, Quaternion.identity, placeToInstantiateBuildingUI.transform); menuSpawned = true; } } } if (hit.collider.gameObject.tag == "LandExtender") { if (inventoryManager.CurrentBalance >= 10000f) { inventoryManager.UpdateBalance(-10000f); Transform slotToInstantiateIn = hit.collider.gameObject.transform.parent; Destroy(hit.collider.gameObject); if (slotToInstantiateIn.position.x < FindObjectOfType <HomeActions>().transform.position.x) { GameObject leftExtendedLand = Instantiate(leftLandExtender, slotToInstantiateIn.transform.position, Quaternion.identity, slotToInstantiateIn); Instantiate(leftLandExtWarning, leftExtendedLand.GetComponentInChildren <ExtenderSlot>().transform.position, Quaternion.identity, leftExtendedLand.GetComponentInChildren <ExtenderSlot>().transform); } else if (slotToInstantiateIn.position.x > FindObjectOfType <HomeActions>().transform.position.x) { GameObject rightExtendedLand = Instantiate(rightLandExtender, slotToInstantiateIn.transform.position, Quaternion.identity, slotToInstantiateIn); Instantiate(rightLandExtWarning, rightExtendedLand.GetComponentInChildren <ExtenderSlot>().transform.position, Quaternion.identity, rightExtendedLand.GetComponentInChildren <ExtenderSlot>().transform); } } notificationsManager.StartSpawningText("Not enough money!"); } } }