/// <summary> /// Creates new NPC Attributes and sends the customer to chosen counter. /// </summary> private void createCustomer() { int index = -1; GameObject counter = ChefSaladManager.selectRandomUsableCounter(out index);// Select random available counter. if (counter == null) { return; } // Register to customer leaving that counter event of the counter. counter.GetComponentInChildren <CustomerCounter>().onCustomerLeaving += onNpcReturning; // Get NPC Controller of the counter. NpcController controller = (NpcController)ChefSaladManager.getNpcController(index); // Get Next NPC pawn from queue. NpcPawn pawn = npcsAvailable.Dequeue(); // Set Pawn's start position. pawn.transform.position = new Vector3(counter.transform.position.x, counter.transform.position.y + 7, pawn.transform.position.z); // Set controller variables and attributes. controller.MoveTo = new Vector3(counter.transform.position.x, counter.transform.position.y, pawn.transform.position.z); controller.IsMobile = true; controller.counterTransform = counter.transform; controller.attributes.failureTimeMultiplier = UnityEngine.Random.Range(minFailureTimeMultiplier, maxFailureTimeMultiplier); controller.attributes.scoreMultiplier = UnityEngine.Random.Range(minScoreMultiplier, maxScoreMultiplier); controller.attributes.maxWaitTime = 0; // Chose random number of ingredients. int noOfIngredient = UnityEngine.Random.Range(1, ChefSaladManager.MAX_INGREDIENT_COUNT); int salad = 0; // Selecting vegetable that the salad needs to be made of randomly and not repeating. for (int i = 0, trial = 0; i < noOfIngredient; i++, trial = 0) { int choosen = 0; int pow = 0; VegetableData vegData = null; while (trial < 3 && choosen == 0) { pow = UnityEngine.Random.Range(0, (int)Vegies.count); choosen = (int)Mathf.Pow(2, pow); if ((choosen & salad) == 0) { salad |= choosen; vegData = ChefSaladManager.getVegetableData(choosen); controller.attributes.maxWaitTime += (int)(vegData.preparationTime + (vegData.preparationTime * 4f)); } else { choosen = 0; trial++; } } if (choosen != 0) { continue; } pow = UnityEngine.Random.Range(0, (int)Vegies.count); choosen = (int)Mathf.Pow(2, pow); while ((choosen & salad) != 0) { pow++; choosen = (int)Mathf.Pow(2, pow % (int)Vegies.count); } vegData = ChefSaladManager.getVegetableData(choosen); controller.attributes.maxWaitTime += (int)(vegData.preparationTime + (vegData.preparationTime * 4f)); salad |= choosen; } controller.attributes.salad = salad; // Starting to control the selected pawn from selected controller. controller.controlPawn(pawn); }