Exemple #1
0
    public override void interact(GameObject interactor)
    {
        Player player = interactor.GetComponent <Player>();
        int    item   = player.PlayerInventory.getNextItem();

        // if is vegetable then cost can be determined from vegetable data
        if (Vegetables.isRawVegetable(item))
        {
            VegetableData vegData = ChefSaladManager.getVegetableData(item);
            if (onItemTrashed != null)
            {
                onItemTrashed.Invoke(player.GetId, vegData.Penalty);
            }
        }
        else  // if it is salad we get each individual vegetable by bit shifting vegetable integer and finding its vegetable data
        {
            float cost     = 0;
            int   itemMask = item;
            for (int i = 0; i < (int)Vegies.count; i++)
            {
                if ((itemMask & 1) > 0)
                {
                    int           veg     = (int)Mathf.Pow(2, i);
                    VegetableData vegData = ChefSaladManager.getVegetableData(veg);
                    cost += vegData.Penalty;
                }
                itemMask >>= 1;
            }
            if (onItemTrashed != null)
            {
                onItemTrashed.Invoke(player.GetId, cost);
            }
        }
    }
Exemple #2
0
    IEnumerator startCooking()
    {
        int veg = currentLockedPlayer.PlayerInventory.peekNextItem();

        if (!Vegetables.isRawVegetable(veg))// if only it is vegetable then allow cooking.
        {
            resetData();
            yield break;
        }

        // Enable salad canvas
        if (!saladCanvas.gameObject.activeSelf)
        {
            saladCanvas.gameObject.SetActive(true);
        }

        veg              = currentLockedPlayer.PlayerInventory.getNextItem();
        currentStack    |= (int)Vegies.oneItemSaladHandle;// Adding salad handler enum value
        preparingVegData = ChefSaladManager.getVegetableData(veg);
        prepareTimeLeft  = preparingVegData.preparationTime;

        // Wait and pass on this frame so calculation start from next frame.
        yield return(new WaitForEndOfFrame());

        while (true)
        {
            // Moving player to stove's preparation point
            if ((stoveStandingSpot.position - currentLockedPlayer.transform.position).magnitude > 0.02)
            {
                currentLockedPlayer.transform.position += 2 * (stoveStandingSpot.position - currentLockedPlayer.transform.position)
                                                          * Time.deltaTime;
                currentLockedPlayer.transform.rotation = stoveStandingSpot.rotation;
            }
            prepareTimeLeft -= Time.deltaTime;
            if (prepareTimeLeft <= 0)// if preparation time ends it means vegetable is prepared.
            {
                ingredientPrepared(veg);
                // Check for if player has more vegetable to add if yes then continue with next item he has.
                if (currentLockedPlayer.PlayerInventory.hasAnyItem())
                {
                    veg = currentLockedPlayer.PlayerInventory.peekNextItem();

                    // if next ingredient is already added then stop cooking or if salad still has space to add ingredient
                    if ((currentStack & veg) != 0 || currentIngredientCount >= ChefSaladManager.MAX_INGREDIENT_COUNT)
                    {
                        break;
                    }
                    veg = currentLockedPlayer.PlayerInventory.getNextItem();
                    preparingVegData = ChefSaladManager.getVegetableData(veg);
                    prepareTimeLeft  = preparingVegData.preparationTime;
                }
                else
                {
                    break;
                }
            }
            yield return(new WaitForEndOfFrame());
        }
        resetData();
    }
Exemple #3
0
 /// <summary>
 /// Resets stove data this is usually done when player finishes interaction with stove and unlocks player controller
 /// </summary>
 private void resetData()
 {
     prepareTimeLeft  = 0;
     preparingVegData = null;
     ((PlayerController)currentLockedPlayer.controller).setInputActive(true);
     currentLockedPlayer = null;
     isBeingUsed         = false;
 }
Exemple #4
0
    public override void interact(GameObject interactor)
    {
        BasicPawn pawn = interactor.GetComponent <BasicPawn>();

        if (pawn.controller is NpcController) // If is NPC then set all data that customer is bringing in to counter.
        {
            resetData();
            waitingController = (NpcController)pawn.controller;

            progressionBar.gameObject.SetActive(true);

            // Make controller stop
            waitingController.IsMobile = false;
            // Hard coded value to make npc go off screen after waiting
            waitingController.MoveTo = new Vector3(transform.parent.position.x, transform.parent.position.y + 7,
                                                   waitingController.GetControlledPawn.transform.position.z);

            int itemMask = waitingController.attributes.salad;
            for (int i = 0; i < (int)Vegies.count; i++)// Using bit shifting to find ingredients.
            {
                if ((itemMask & 1) > 0)
                {
                    int           veg     = (int)Mathf.Pow(2, i);
                    VegetableData vegData = ChefSaladManager.getVegetableData(veg);
                    scoreOnSuccess   += vegData.Reward;
                    penaltyOnFailure += vegData.Penalty;
                    saladCanvas.addItem(vegData);
                }
                itemMask >>= 1;
            }
            scoreOnSuccess   += scoreOnSuccess * waitingController.attributes.scoreMultiplier;
            penaltyOnFailure += waitingController.attributes.scoreMultiplier;
        }
        else //If it is player then get salad and do the processing.
        {
            Player player = (Player)pawn;
            int    salad  = player.PlayerInventory.getFirstItem(false) & (~(int)Vegies.oneItemSaladHandle);
#if GAME_DEBUG
            Debug.Log("Player Serving salad " + salad + " Customer requested salad " + waitingController.attributes.salad);
#endif
            if ((salad ^ waitingController.attributes.salad) == 0) // If salad ingredient match required ingredient do below
            {
                playerIds.Clear();
                playerIds.Add(player.GetId);
                waitOver(scoreOnSuccess);
            }
            else // If not matching then add the player to player ids that needs to be affected by penalty.
            {
                playerIds.Add(player.GetId);
                if (timeMultiplier == 1)// Only increase time multiplier once rest of failure does not affect
                {
                    timeMultiplier *= waitingController.attributes.failureTimeMultiplier;
                }
            }
        }
    }
Exemple #5
0
    /// <summary>
    /// Adds a vegetable to salad
    /// </summary>
    /// <param name="vegData">Vegetable data of vegetable being added</param>
    /// <returns>true if added successfully.</returns>
    public bool addItem(VegetableData vegData)
    {
        if (items.Count == 0)
        {
            // If Queued Item icons are used already then return as this means ingredient count reached max(this case won't happen)
            // ,else fill it manually
            if (itemsContainerWidget.transform.childCount > 0)
            {
                return(false);
            }
            else
            {
                // This needs to be done as in some cases after spawn start gets executed only in
                // next frame and we need it in same frame.
                fillQueue();
            }
        }
        SaladIngredientCanvasScript item = items.Dequeue();

        item.itemImageSprite.sprite = vegData.vegTexture;
        item.transform.SetParent(itemsContainerWidget.transform);
        return(true);
    }
    /// <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);
    }