Beispiel #1
0
    IEnumerator FinishDay()
    {
        Debug.Log("Finishing day!");

        GameStatics.Loading = true;

        // Play sound
        MajorClick.Play();

        Player.Navigate(new List <Vector3> {
            new Vector3(6, 2, 1)
        }, playSelectSound: false);                                                          // Return to spawn loc

        // Show black screen
        NextDayScreen.gameObject.SetActive(true);
        StartCoroutine(NextDayScreen.ShowScreen(++Days));

        yield return(new WaitUntil(() => NextDayScreen.time >= 1));

        DiscordRichPresenceManager.UpdateActivity("Playing", Days); // Discord Rich Presence

        // Manage Debt
        if (Player.Money < 0)
        {
            if (InDebt)
            {
                Debug.Log("You are in debt");
                // Try to sell flowerbeds first to cover debt
                var shopItems = Shop.ShopItems.FindAll(shopItem => shopItem.IsDowngradable && shopItem.Level > 0);
                shopItems.Sort((shopItem1, shopItem2) => shopItem1.Price.CompareTo(shopItem2.Price));
                if (shopItems.Count == 0)
                {
                    // Display message
                    PopupManager.ShowWindowPopup("You've lost everything...", "Sadly, you've ended up with less money than you've started with. Luckily for you, your parents were nice enough to pay for your debts and give you a fresh start.", goodAlert: false);

                    // Reset values
                    Player.Money = 100;
                }
                else
                {
                    int shopItemIndex = 0;
                    while (shopItems[shopItemIndex].Price + Player.Money < 0 && shopItemIndex < shopItems.Count)
                    {
                        shopItemIndex++;
                    }

                    // Display message
                    PopupManager.ShowWindowPopup($"You sold your {shopItems[shopItemIndex].Name}", $"Since you were still in debt, you were forced to sell some things to help you get back on your feet.", goodAlert: false);

                    Player.Money += shopItems[shopItemIndex].Price; // Return money
                    int newLevel = --shopItems[shopItemIndex].Level;

                    if (shopItems[shopItemIndex].Name == "Flower Beds")            // flower bed edge case
                    {
                        FlowerBedManager.SendMessage("RemoveFlowerBed", newLevel); // Sell flowerbed
                    }
                    Shop.UpdateBuyButtonVisual(shopItems[shopItemIndex]);          // Update visuals
                }
            }
            else
            {
                InDebt = true;
                PopupManager.ShowWindowPopup("You're in debt!", "You are in debt! Get out of debt or you'll soon need to start selling your things!", goodAlert: false);
            }
        }
        else
        {
            InDebt = false;

            Player.Money -= FamilyPayment;                 // Pay family
            Player.Money -= BorrowMoney.TotalDailyPayment; // Pay loans
            BorrowMoney.UpdateDailyPayments();
        }

        // Game won?
        if (!finishedGame && Player.Money > 5000 && Shop.IsMaxedOut)
        {
            Debug.Log($"You've made a lot of money, your family is proud of you. The end! :) ({Days} days to complete game)");
            StorylineManager.ShowStoryline("The End");
            finishedGame = true;
        }


        // PLAYER
        Player.InHand = Player.Items.Nothing; // Empty hands

        // STORYLINE
        StorylineManager.CheckForNewStoryline(Days);

        // FLOWER BEDS
        // Get Flower Beds States
        var FlowerBedScripts = FlowerBeds.GetComponentsInChildren <FlowerBed>();


        // WEATHER
        Debug.Log(weather);

        // Apply logic to flower beds

        // Get chances for weather
        if (!WeatherLogicData.TryGetValue(weather, out var flowerbedStateChances))
        {
            WeatherLogicData.TryGetValue(Weather.Sunny, out flowerbedStateChances);
        }

        // Go through flowerbeds
        foreach (FlowerBed flowerBed in FlowerBedScripts)
        {
            if (!flowerbedStateChances.TryGetValue(flowerBed.state, out var chances))
            {
                continue;
            }
            float randomChance = Random.value;

            foreach (var possibleChance in chances)
            {
                if (possibleChance.Value > randomChance)
                {
                    flowerBed.UpdateFlowerbedState(possibleChance.Key);
                    break;
                }

                randomChance -= possibleChance.Value;
            }
        }

        RandomEvents.Run(); // Random events

        // Create new weather for tomorrow
        GenerateWeather();

        GameFunctions.SaveGame(true, "finish_day_backup").Wait(); // Save data everyday while making backup copies just in case

        GameStatics.Loading = false;
    }