void OnEnable()
    {
        moneyStatScript = FindObjectOfType <moneyStatScript>();

        //Shitty fix for reseting price when restarting game.
        Lesson x           = gameObject.AddComponent <Lesson>();
        bool   foundLesson = false;

        foreach (Item l in MyInventory)
        {
            if (l.GetType() == x.GetType())
            {
                foundLesson = true;
                break;
            }
        }
        if (!foundLesson)
        {
            foreach (Item l in ShopInventory)
            {
                if (l.GetType() == x.GetType())
                {
                    ((Lesson)l).ResetPrice();
                }
            }
        }
        Destroy(x);

        FetchShopUIElements();
    }
    void Start()
    {
        AudioManager.instance.Play("rullband");
        AudioManager.instance.Play("hiss");
        StatReference = GameObject.Find("angstObject").GetComponent <angstStatScript>();
        moneyStats    = GameObject.Find("moneyObject").GetComponent <moneyStatScript>();
        productList   = new List <GameObject>(); //Skapar en lista
        angst         = StatReference.getAmount();

        if (GameManager.IsFirstWorkRun)
        {
            GameManager.IsFirstWorkRun = !GameManager.IsFirstWorkRun;
            WorkTut.Run();
        }
    }
Esempio n. 3
0
    public void EndGame(bool victory = true)
    {
        EndGamePanel.SetActive(true);
        FindObjectOfType <TimingString>().enabled = false;

        MusicWithLeadAudioSource.Stop();
        MusicWithoutLeadAudioSource.Stop();
        NoteGenerationAudioSource.Stop();

        angstStatScript angst       = FindObjectOfType <angstStatScript>();
        metalStatScript metal       = FindObjectOfType <metalStatScript>();
        fameStatScript  fame        = FindObjectOfType <fameStatScript>();
        moneyStatScript money       = FindObjectOfType <moneyStatScript>();
        float           metalGained = 0;
        float           fameGained  = 0;
        float           moneyGained = 0;
        float           angstGained = 0;

        //Practice always goes to victory, except if you quit via pause-menu.
        if (victory)
        {
            //Victory sound.
            SwitchMusicSource(true);
            if (ShopSystem.MyInventory.Contains(HardGuitar))
            {
                MusicWithLeadAudioSource.PlayOneShot(VictorySoundHard);
            }
            else if (ShopSystem.MyInventory.Contains(MediumGuitar))
            {
                MusicWithLeadAudioSource.PlayOneShot(VictorySoundMedium);
            }
            else
            {
                MusicWithLeadAudioSource.PlayOneShot(VictorySoundEasy);
            }


            //Calculate rewards then apply them.
            #region Calculations
            float metalBase        = 20;
            float metalStatMltp    = (1 / (1 + (angst.getAmount() / 100)));
            float metalPerformance = ((1.5f * NotesTotal) / (NotesTotal + (2 * TimingSystem.FailedTimingCounter)));
            float metalItemMltp    = TimingString.MetalMultiplier;
            metalGained = Mathf.CeilToInt(metalBase * metalStatMltp * metalPerformance * metalItemMltp * ProficiencyBonus);

            float fameBase        = 50;
            float fameStatMltp    = (2 / (10 - (metal.getAmount() / 15)));
            float famePerformance = ((1.5f * NotesTotal) / (NotesTotal + TimingSystem.FailedTimingCounter));
            float fameItemMltp    = 1;
            fameGained = Mathf.CeilToInt(fameBase * fameStatMltp * famePerformance * fameItemMltp * ProficiencyBonus);

            float moneyBase        = 3000;
            float moneyStatMltp    = (6 / (100 - fame.getAmount()));
            float moneyPerformance = 1;
            float moneyItemMltp    = 1;
            moneyGained = Mathf.CeilToInt(moneyBase * moneyStatMltp * moneyPerformance * moneyItemMltp * ProficiencyBonus);

            float angstBase        = -15;
            float angstStatMltp    = 1;
            float angstPerformance = ((1.5f * NotesTotal) / (NotesTotal + (2 * TimingSystem.FailedTimingCounter)));
            float angstItemMltp    = 1;
            angstGained = Mathf.CeilToInt(angstBase * angstStatMltp * angstPerformance * angstItemMltp * ProficiencyBonus);

            if (moneyGained > money.getMax() || moneyGained < 0)
            {
                moneyGained = money.getMax();
            }
            if (fameGained > fame.getMax() || fameGained < 0)
            {
                fameGained = fame.getMax();
            }
            if (metalGained > metal.getMax() || metalGained < 0)
            {
                metalGained = metal.getMax();
            }
            //if (angstGained > angst.getMax() || angstGained < 0)
            //    angstGained = angst.getMax();
            #endregion


            UpdateScoreBoard(MetalText, metalBase, metalStatMltp, metalPerformance, metalItemMltp, metalGained);
            UpdateScoreBoard(AngstText, angstBase, angstStatMltp, angstPerformance, angstItemMltp, angstGained);

            metal.addOrRemoveAmount(metalGained);
            angst.addOrRemoveAmount(angstGained);

            if (GigBackgroundManager.GigSession)
            {
                FameText.transform.parent.gameObject.SetActive(true);
                MoneyText.transform.parent.gameObject.SetActive(true);

                UpdateScoreBoard(FameText, fameBase, fameStatMltp, famePerformance, fameItemMltp, fameGained);
                UpdateScoreBoard(MoneyText, moneyBase, moneyStatMltp, moneyPerformance, moneyItemMltp, moneyGained);

                fame.addOrRemoveAmount(fameGained);
                money.addOrRemoveAmount(moneyGained);

                if (fame.getAmount() >= fame.getMax())
                {
                    GameManager.ToEndGame = true;
                }
            }
            else if (!GigBackgroundManager.GigSession)
            {
                ProficiencyBonus += ProficiencyGainPerPractice;
            }
        }
        else
        {
            SwitchMusicSource(true);
            MusicWithLeadAudioSource.PlayOneShot(DefeatSound);

            if (GigBackgroundManager.GigSession)
            {
                FameText.transform.parent.gameObject.SetActive(true);
                MoneyText.transform.parent.gameObject.SetActive(true);

                UpdateScoreBoard(FameText, -10, 1, 1, 1, -10);
                UpdateScoreBoard(MetalText, -20, 1, 1, 1, -20);
                UpdateScoreBoard(AngstText, 20, 1, 1, 1, 20);
                UpdateScoreBoard(MoneyText, 150, 1, 1, 1, 150);

                fame.addOrRemoveAmount(-10);
                metal.addOrRemoveAmount(-20);
                angst.addOrRemoveAmount(20);
                money.addOrRemoveAmount(150);
            }
        }
    }