Ejemplo n.º 1
0
    /// <summary>
    /// Leave the store.
    /// </summary>
    public void Leave()
    {
        transform.GetChild(0).gameObject.SetActive(false);
        leaving = true;

        leavingState = LeavingStates.phase1;
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Initialise Data for customer.
    /// </summary>
    public void InitiateData()
    {
        customerSizeX = transform.lossyScale.x * 0.275f;
        customerSizeZ = transform.lossyScale.z * 0.275f;
        waitTiming    = Random.Range((waitTiming / 2), waitTiming);
        anim          = GetComponent <Animator>();
        SetAnim(idle, false);
        SetAnim(walking, true);
        leavingState   = LeavingStates.phase1;
        fightPositions = (FightPositions)customerId;
        dodge          = false;
        audio          = GetComponent <AudioSource>();

        var spawnPos = CustomerSpawner.Instance.spawnPoint.position;

        leavingPosition = new Vector3(spawnPos.x + customerSizeX * 0.75f, spawnPos.y, spawnPos.z + customerSizeZ);

        var hands = PauseManager.Instance.GetComponentsInChildren <HandPointer>();

        foreach (var hand in hands)
        {
            if (hand.currentHand == HandPointer.Hands.left)
            {
                playerLHand = hand;
            }
            else if (hand.currentHand == HandPointer.Hands.right)
            {
                playerRHand = hand;
            }
        }

        CalculateDir();
        InitiateColor();
        AllowHover(false);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Deactivates this GameObject and Reset its data for later use through The Object Pool.
    /// </summary>
    public void Destroy()
    {
        gameObject.SetActive(false);

        timerImage.fillAmount = 1f;
        movementSpeed         = 2.5f;
        reachedTarget         = false;
        orderedFood           = false;
        foodOrdered           = null;
        fighting       = false;
        othersFighting = false;
        leaving        = false;
        player         = null;
        timer          = 0f;
        clockHand      = null;
        leavingState   = LeavingStates.phase1;
        fightPositions = (FightPositions)customerId;
        dodge          = false;
    }
Ejemplo n.º 4
0
    private void Update()
    {
        // If the game is in Pause Status, do not do anything
        if (PauseManager.Instance != null && PauseManager.Instance.isPaused)
        {
            return;
        }

        // Debug Key => 1st customer leaves
        if (Input.GetKeyDown(KeyCode.L))
        {
            if (customerId == 1)
            {
                SetAnim(idle, false);
                SetAnim(happy, true);
                Leave();
            }
        }

        if (!leaving)
        {
            if (!fighting)
            {
                #region Move & Order State
                // Move towards the Target position
                if (Vector3.Distance(transform.position, targetPosition) >= 0.1f)
                {
                    SetAnim(idle, false);
                    SetAnim(walking, true);

                    // Rotate to face Wall
                    if (orderedFood && Vector3.Angle(transform.forward, new Vector3(1, 0, 0)) != 90f)
                    {
                        transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(transform.rotation.x, 180f, transform.rotation.z), rotateSpeed * Time.deltaTime);
                    }
                    else
                    {
                        transform.position += dir * movementSpeed * Time.deltaTime;
                    }
                }
                else
                {
                    reachedTarget = true;

                    // Rotate to face Player(Chef)
                    if (Vector3.Angle(transform.forward, new Vector3(1, 0, 0)) != 180f)
                    {
                        transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(transform.rotation.x, -90f, transform.rotation.z), rotateSpeed * Time.deltaTime);

                        if (Vector3.Angle(transform.forward, new Vector3(1, 0, 0)) == 180f)
                        {
                            SetAnim(walking, false);
                            SetAnim(idle, true);

                            if (!orderedFood)
                            {
                                OrderFood(foodOrder[Random.Range(0, foodOrder.Length)]);

                                if (Menu_Manager.Instance.Tutorial_Mode && !Guide.Instance.gameObject.activeSelf)
                                {
                                    Guide.Instance.Show();
                                }
                            }
                        }
                    }
                }
                #endregion Move & Order State

                #region Waiting State
                if (orderedFood)
                {
                    // Reduce fillAmount of Timer Filler Image(visual feedback) over waitTiming
                    timerImage.fillAmount -= (1f / waitTiming) * Time.deltaTime;
                    TurnClockHand(timerImage.fillAmount);

                    // Left more than half the time -> Image turning from green to yellow
                    if (timerImage.fillAmount >= 0.5f)
                    {
                        timerImage.color = greenYellowGradient.Evaluate(timerImage.fillAmount / 1f);
                    }
                    // Left less than half the time -> Image turning from yellow to red
                    else if (timerImage.fillAmount > 0f)
                    {
                        timerImage.color = yellowRedGradient.Evaluate(timerImage.fillAmount / 1f);
                    }
                    else if (timerImage.fillAmount <= 0f)
                    {
                        fighting = true;

                        foreach (CookingAppliance appliance in LevelManager.Instance.cookingAppliances)
                        {
                            if (!appliance.isDone)
                            {
                                appliance.NewFood();
                            }
                        }

                        player = Player.Instance.transform;

                        if (Guide.Instance != null)
                        {
                            Guide.Instance.gameObject.SetActive(true);
                        }

                        SetAnim(idle, false);
                        SetAnim(angry, true);

                        playerLHand.DropItem(null);
                        playerRHand.DropItem(null);
                    }
                }
                #endregion Waiting State
            }
            else
            {
                if (dodge)
                {
                    #region Dodge State
                    if (Vector3.Distance(transform.position, targetPosition) >= 0.1f)
                    {
                        transform.position += dir * (movementSpeed * movementSpeed) * Time.deltaTime;
                    }
                    else
                    {
                        dodge = false;
                    }
                    #endregion Dodge State
                }
                else
                {
                    #region Fighting State
                    // Hide Food Bubble Image
                    if (transform.GetChild(0).gameObject.activeSelf)
                    {
                        transform.GetChild(0).gameObject.SetActive(false);
                    }

                    timer += Time.deltaTime;
                    if (timer >= fireCD)
                    {
                        if (player)
                        {
                            // Shoot bullet towards hand icon
                            var Projectile = ObjectPool.Instance.GetPooledObject(customerBulletPrefab);

                            if (!Projectile)
                            {
                                return;
                            }

                            var a       = Random.Range(0.01f, 1f);
                            var randPos = new Vector3(Random.Range(player.position.x - a, player.position.x + a),
                                                      Random.Range(player.position.y - a, player.position.y + a),
                                                      Random.Range(player.position.z - a, player.position.z + a));

                            Projectile.transform.position = transform.GetChild(2).position;
                            Projectile.transform.rotation = Quaternion.identity;
                            Projectile.GetComponent <Projectile>().dir = (randPos - Projectile.transform.position).normalized;

                            // Scare off other customers
                            foreach (var pair in CustomerSpawner.Instance.customerDic)
                            {
                                if (pair.Value.customerId != customerId)
                                {
                                    if (!pair.Value.othersFighting)
                                    {
                                        pair.Value.othersFighting = true;
                                    }
                                    else
                                    {
                                        if (!pair.Value.leaving)
                                        {
                                            pair.Value.SetAnim(idle, false);
                                            pair.Value.SetAnim(angry, false);
                                            pair.Value.SetAnim(scared, true);
                                            pair.Value.Leave();
                                        }
                                    }
                                }
                            }

                            #region Dodge Decision State
                            var rand = Random.Range(1, 4);
                            if (rand == customerId || (FightPositions)rand == fightPositions)
                            {
                                dodge = false;
                            }
                            else
                            {
                                dodge          = true;
                                fightPositions = (FightPositions)rand;

                                switch (fightPositions)
                                {
                                case FightPositions.left:
                                {
                                    targetPosition = new Vector3(queuePosition.x, queuePosition.y, queuePosition.z + (customerSizeX * 2));
                                }
                                break;

                                case FightPositions.middle:
                                {
                                    targetPosition = new Vector3(queuePosition.x, queuePosition.y, queuePosition.z + customerSizeX);
                                }
                                break;

                                case FightPositions.right:
                                {
                                    targetPosition = queuePosition;
                                }
                                break;
                                }
                                dir = (targetPosition - transform.position).normalized;
                            }
                            #endregion Dodge Decision State
                        }
                        timer = 0f;
                    }
                    #endregion Fighting State
                }
            }
        }
        else
        {
            #region Leaving State

            if (Vector3.Distance(transform.position, leavingPosition) >= 0.1f)
            {
                switch (leavingState)
                {
                case LeavingStates.phase1:
                    if (Vector3.Angle(transform.forward, new Vector3(1, 0, 0)) > 2.0f)
                    {
                        transform.forward = Vector3.RotateTowards(transform.forward, new Vector3(1, 0, 0), 0.05f, 0.0f);
                    }
                    else
                    {
                        leavingState = LeavingStates.phase2;
                    }
                    break;

                case LeavingStates.phase2:
                    if (Vector3.Angle(transform.forward, leavingPosition - transform.position) != 0f)
                    {
                        Vector3 temp = leavingPosition - transform.position;
                        transform.forward   = Vector3.RotateTowards(transform.forward, new Vector3(temp.x, 0, temp.z), 0.075f, 0.0f);
                        transform.position += transform.forward * Time.deltaTime * 2f;
                    }
                    else
                    {
                        leavingState = LeavingStates.phase3;
                    }
                    break;

                case LeavingStates.phase3:
                {
                    transform.position += transform.forward * Time.deltaTime * 2f;
                }
                break;
                }
            }
            else
            {
                RemoveCustomer(customerId);
            }

            #endregion Leaving State
        }
    }