public Order(int food, int x, int y, ChairModelScript c, int custID) { this.food = food; this.x = x; this.y = y; this.c = c; this.custID = custID; }
//Set the item chosen to be displayed on this tile public void SetItem(ItemScript.itemType it) { if (chosen) { this.it = it; if (model.GetComponent <ItemScript> () != null) { model.GetComponent <ItemScript> ().enabled = false; } currentModel = Instantiate(this.model, new Vector3(transform.position.x, yOffset, transform.position.z), model.transform.rotation); currentModel.transform.parent = this.transform; if (it == ItemScript.itemType.table) { //Check all neighbours, if any are chairs call UpdateTableChosen on their ChairModelScripts foreach (TileScript t in neighbours) { if (t.it == ItemScript.itemType.chair) { ChairModelScript c = t.currentModel.GetComponent <ChairModelScript> (); c.UpdateTableChosen(currentModel); } } GameManager.itemAmount [0]++; GameManager.money -= GameManager.itemPrices [0]; } if (it == ItemScript.itemType.chair) { foreach (TileScript t in neighbours) { if (t.it == ItemScript.itemType.table) { ChairModelScript c = currentModel.GetComponent <ChairModelScript> (); c.UpdateTableChosen(t.currentModel); } } GameManager.itemAmount [1]++; GameManager.money -= GameManager.itemPrices [1]; } //Wont set an item down if it's waiter: will cause blockage. if (it != ItemScript.itemType.waiter) { itemSet = true; } else if (it == ItemScript.itemType.waiter) { GameManager.itemAmount [2]++; GameManager.money -= GameManager.itemPrices [2]; } } else { Debug.Log("Tile has not been chosen"); } }
public void AssignRandomSeat() { List <ChairModelScript> c = new List <ChairModelScript> (); foreach (TileScript t in GameManager.mapArray) { if (t.it == ItemScript.itemType.chair) { ChairModelScript currentScript = t.GetComponentInChildren <ChairModelScript> (); if (currentScript.tableChosen && currentScript.TableHasSpace() && !currentScript.occupied) { c.Add(currentScript); //Debug.Log ("Adding this chair at " + t.x + ", " + t.y); } } } if (c.Count > 0) { //Choose a random unoccupied seat int randomSeat = Random.Range(0, c.Count); //Debug.Log ("Random seat index: " + randomSeat); while (c [randomSeat].occupied == true) { randomSeat = Random.Range(0, c.Count); //Debug.Log ("Next seat: " + randomSeat); } int randomCust = Random.Range(0, GameManager.custNumber); //Debug.Log ("Random customer index: " + randomCust); while (GameManager.custList [randomCust].GetComponent <CustomerScript> ().isSeated == true) { randomCust = Random.Range(0, GameManager.custNumber); //Debug.Log ("Next customer: " + randomCust); } Vector2 freeSpacePosition = c [randomSeat].GetFreeSpace(); c [randomSeat].occupied = true; GameManager.custList [randomCust].transform.position = c [randomSeat].transform.position; GameManager.custList [randomCust].transform.LookAt(c [randomSeat].tableModel.transform); GameManager.custList [randomCust].GetComponent <CustomerScript> ().isSeated = true; AddOrder((int)freeSpacePosition.x, (int)freeSpacePosition.y, c[randomSeat], randomCust); } else { Debug.Log("No chairs to seat customers"); } }
public IEnumerator DeassignSeat(int foodType, ChairModelScript c, int custID) { yield return(new WaitForSeconds(timeToLeave)); // Send the customer back to the waiting zone and make the chair unoccupied GameManager.custList [custID].transform.position = new Vector3(31f, 0, 0); GameManager.custList [custID].GetComponent <CustomerScript> ().isSeated = false; c.occupied = false; //Pay the player for the type of food purchased GameManager.money += GameManager.foodPrices [foodType]; //TODO: Don't take orders that have negatives and deassign the seat anyway. }
public void AddOrder(int x, int y, ChairModelScript c, int custID) { //Formula to make the customer order the cheaper food item more often float[] percentages = new float[GameManager.foodPrices.Length]; int totalPrice = 0; foreach (int f in GameManager.foodPrices) { totalPrice += f; } for (int i = 0; i < percentages.Length; i++) { percentages [i] = (GameManager.foodPrices [i] / (float)totalPrice); //Debug.Log (i + ": " + percentages [i]); } float inversePercent = 0; foreach (float f in percentages) { inversePercent += 1 - f; } for (int i = 0; i < percentages.Length; i++) { percentages [i] = ((1 - percentages [i]) / inversePercent); //Debug.Log (i + ": " + percentages [i]); } float rand = Random.Range(0, 1f); bool randChosen = false; while (!randChosen) { if (rand < percentages [0] && GameManager.foodAmount [0] > 0) { GameManager.foodAmount [0]--; orderList.Add(new Order(0, x, y, c, custID)); Debug.Log("Burger order recieved at " + x + "," + y + ". Burgers left: " + GameManager.foodAmount [0]); randChosen = true; } else if (rand < percentages [0] + percentages [1] && GameManager.foodAmount [1] > 0) { GameManager.foodAmount [1]--; orderList.Add(new Order(1, x, y, c, custID)); Debug.Log("Pasta order recieved at " + x + "," + y + ". Pastas left: " + GameManager.foodAmount [1]); randChosen = true; } else if (rand < 1 && GameManager.foodAmount [2] > 0) { GameManager.foodAmount [2]--; orderList.Add(new Order(2, x, y, c, custID)); Debug.Log("Beverage order recieved at " + x + "," + y + ". Beverages left: " + GameManager.foodAmount [2]); randChosen = true; } else if (GameManager.foodAmount [0] + GameManager.foodAmount [1] + GameManager.foodAmount [2] <= 0) { Debug.Log("Ran out of food!"); GameManager.day++; GameObject.FindGameObjectWithTag("GM").GetComponent <GameManager>().ClearCustomers(); randChosen = true; SceneManager.LoadScene(2); } else { rand = Random.Range(0, 1f); //Debug.Log ("new rand: " + rand); } } //TODO: give the order to the closest free waiter. }