//adds and ingredient into the appliance public void addIngToApp(FoodObject food, HashSet <FoodObject> foodSet) { Transform onHead = player.GetChild(2); onHead.SetParent(null, true); StartCoroutine(Slerp(onHead)); food.subOneQ(); PlayerData.player.SetCurrentFood(food); food = new FoodObject(food); food.setQuantity(1); foreach (FoodObject ing in foodSet) { if (ing.getName() == food.getName()) { Debug.Log("match"); ing.addOneQ(); prevIng = food.getName(); return; } } foodSet.Add(food); prevIng = food.getName(); }
public bool AddFoodItem(FoodObject food) { List <FoodObject> location = playerInfo.bag; // find if foodItem exists for (int i = 0; i < 15; ++i) { if (location[i] != null && food.getName() == location[i].getName()) { location[i].setQuantity(location[i].getQuantity() + food.getQuantity()); return(true); } } // if foodItem does not exist create new copy of foodItem and add to first null slot for (int i = 0; i < 15; ++i) { if (location[i] == null) { location[i] = new FoodObject(food); return(true); } } return(false); }
public static void AddToApp(HashSet <FoodObject> foodSet, FoodObject food) { Debug.Log(food.getQuantity()); bool notFound = true; food.setQuantity(1); if (food.getName() != "Plate") { foreach (FoodObject ing in foodSet) { if (ing.getName() == food.getName()) { ing.addOneQ(); notFound = false; break; } } if (notFound) { foodSet.Add(food); } } else { foodSet.Clear(); } if (SceneManager.GetActiveScene().name == "KitchenScene") { GameObject appIng = GameObject.Find("AppIng"); if (appIng != null) { appIng.GetComponent <AppIng>().Refresh(); } } }
public void RemoveFoodItem(FoodObject food) { for (int i = 0; i < playerInfo.fridge.Count; ++i) { if (food.getName() == playerInfo.fridge[i].getName()) { // subtract 1 from quantity playerInfo.fridge[i].setQuantity(playerInfo.fridge[i].getQuantity() - 1); if (playerInfo.fridge[i].getQuantity() <= 0) { playerInfo.fridge.RemoveAt(i); } return; } } }
public void Setup(FoodObject currentFood, ShopScrollList currentScrollList) { food = currentFood; nameLabel.text = food.getName(); priceLabel.text = food.getPrice().ToString(); iconImage.sprite = Resources.Load <Sprite>(food.getIcon()); scrollList = currentScrollList; if (scrollList.isPlayer) { quantityLabel.text = "x" + food.getQuantity().ToString(); } else { quantityLabel.text = ""; // blank } }
private void RefreshPage(int pageNum) { Debug.Log("Currently on page #" + pageNum); FoodObject food = levelList[currentPage - 1]; FoodNameLabel.text = food.getName(); FoodImage.sprite = Resources.Load <Sprite>(food.getIcon()); foreach (GameObject obj in ingredientList) { Destroy(obj); } ingredientList.Clear(); foreach (FoodObject ing in food.getIngNeeded()) { GameObject newObj = Instantiate(ingInfo, ScrollViewContent); ingredientList.Add(newObj); IngredientInfo ingredientInfo = newObj.GetComponent <IngredientInfo>(); ingredientInfo.Setup(ing); } if (currentPage == 1) { ButtonBackPage.interactable = false; } else { ButtonBackPage.interactable = true; } if (currentPage == maxPage) { ButtonNextPage.interactable = false; } else { ButtonNextPage.interactable = true; } }
public void SetCurrentFood(FoodObject food) { GameObject player = GameObject.FindWithTag("Player"); GameObject buttonEat = GameObject.Find("/Canvas/ButtonEat"); if (food == null || food.getQuantity() <= 0) { playerInfo.currentFood = null; playerInfo.bag[15] = null; if (player != null) { for (int i = player.transform.childCount - 1; i >= 2; --i) { Destroy(player.transform.GetChild(i).gameObject); // third child is hat } } Debug.Log("you currently have NOTHING"); buttonEat.GetComponent <Image>().enabled = false; ClientSend.PlayerFood("null"); return; } playerInfo.currentFood = new FoodObject(food); playerInfo.bag[15] = food; if (player != null) { for (int i = player.transform.childCount - 1; i >= 2; --i) { Destroy(player.transform.GetChild(i).gameObject); // third child is hat } Instantiate(Resources.Load(playerInfo.currentFood.getModel()), player.transform); } Debug.Log("you currently have " + playerInfo.currentFood.getName()); ClientSend.PlayerFood(food.getName()); if (playerInfo.currentFood.getName() != "Plate") { buttonEat.GetComponent <Image>().enabled = true; } }
private void AddFoodItem(FoodObject foodToAdd, ShopScrollList shopList) { if (shopList.isPlayer) // if shop that we add to is the player's: { cost += foodToAdd.getPrice(); // find if foodItem exists, then increment quantity for (int i = 0; i < shopList.foodList.Count; ++i) { if (shopList.foodList[i].getName() == foodToAdd.getName()) { shopList.foodList[i].addOneQ(); return; } } // if foodItem not found in list then add it to the list with quantity 1 foodToAdd.setQuantity(1); shopList.foodList.Add(foodToAdd); } }
private void RemoveFoodItem(FoodObject foodToRemove, ShopScrollList shopList) { if (shopList.isPlayer) { cost -= foodToRemove.getPrice(); // find the foodItem in the list for (int i = shopList.foodList.Count - 1; i >= 0; --i) { if (shopList.foodList[i].getName() == foodToRemove.getName()) { // decrease quantity shopList.foodList[i].subOneQ(); if (shopList.foodList[i].getQuantity() <= 0) { // remove if quantity is 0 shopList.foodList.RemoveAt(i); } } } } }
public static void UpdateCounter(int num) { using (Packet _packet = new Packet((int)ClientPackets.updateCounter)) { _packet.Write(num); FoodObject food = PlayerData.player.GetCounterFood(num); if (food != null) { _packet.Write(food.getName()); _packet.Write(food.getQuantity()); } else { _packet.Write("null"); _packet.Write(0); } SendTCPData(_packet); } }
public static void UpdateFridge(int slot) { using (Packet _packet = new Packet((int)ClientPackets.updateFridge)) { _packet.Write(slot); FoodObject food = PlayerData.player.GetFridge()[slot]; if (food != null) { _packet.Write(food.getName()); _packet.Write(food.getQuantity()); } else { _packet.Write("null"); _packet.Write(0); } SendTCPData(_packet); } }
public void OnPointerDown(PointerEventData data) { float distance = Vector3.Distance(player.transform.position, gameObject.transform.position); if (distance <= range) { if (PlayerData.player.GetCurrentFood() != null && PlayerData.player.GetCounterFood(counterNum) == null) { // place ONE food on counter FoodObject food = PlayerData.player.GetCurrentFood(); food.subOneQ(); PlayerData.player.SetCurrentFood(food); FoodObject counter = new FoodObject(food); counter.setQuantity(1); PlayerData.player.SetCounterFood(counterNum, counter); Refresh(); } else if (PlayerData.player.GetCurrentFood() != null && PlayerData.player.GetCounterFood(counterNum) != null) { // stack food back if same name FoodObject food = PlayerData.player.GetCurrentFood(); if (PlayerData.player.GetCounterFood(counterNum).getName() == food.getName()) { food.addOneQ(); PlayerData.player.SetCurrentFood(food); PlayerData.player.SetCounterFood(counterNum, null); Refresh(); } } else if (PlayerData.player.GetCurrentFood() == null && PlayerData.player.GetCounterFood(counterNum) != null) { // remove food from counter PlayerData.player.SetCurrentFood(PlayerData.player.GetCounterFood(counterNum)); PlayerData.player.SetCounterFood(counterNum, null); Refresh(); } } }
public void Setup(FoodObject currentFood) { nameLabel.text = currentFood.getName() + " x" + currentFood.getQuantity().ToString();; iconImage.sprite = Resources.Load <Sprite>(currentFood.getIcon()); }