Esempio n. 1
0
    public void StopAttraction()
    {
        if (running)
        {
            running = false;
            StopAnimation();

            bool aborted = false;

            // Abort or regular stop?
            if (timeLeft > 0)
            {
                aborted = true;
            }

            PlaySound(aborted);

            // Unlock player
            PlayerMovement player = FindObjectOfType <PlayerMovement>();
            if (player)
            {
                player.UnlockMovement();
            }

            if (!aborted)
            {
                if (game.happinessPopupTextPrefab != null)
                {
                    float      gainedHappiness = npcsActive.Count * game.rewardSatisfiedRide;
                    GameObject popup           = (GameObject)Instantiate(game.happinessPopupTextPrefab);
                    popup.transform.position = entrancePosition.transform.position + (Vector3.up);
                    popup.transform.SetParent(entrancePosition.transform);
                    popup.GetComponent <TMPro.TextMeshPro>().text = "+" + gainedHappiness.ToString("N0");
                }
                completedRides++;
                GameStatistics.AddTotalNumberOfSatisfiedVisitors(npcsActive.Count);
                GameStatistics.AddTotalNumberOfDrivenAttractions(1);
            }
            else
            {
                GameStatistics.AddTotalNumberOfStoppedAttractions(1);
            }

            while (npcsActive.Count > 0)
            {
                GameObject npc = npcsActive[0];
                npcsActive.Remove(npc);
                NPC npcScript = npc.GetComponent <NPC>();

                npcScript.SetStatus(NPC.status.IDLE);
                if (aborted)
                {
                    npcScript.UpdateHappiness(game.penaltyUnsatisfiedRide);
                }
                else
                {
                    npcScript.UpdateHappiness(game.rewardSatisfiedRide);
                    Debug.Log("AttractionController::Done Attraction, giving visitors happiness");
                }
                if (timeLeft <= 0)
                {
                    npcScript.DoneAttraction();
                }
            }

            visitorMangager.CalculateHappiness();
        }
    }