void BuyBuff(ShopBuff item)
        {
            PlayerStatusData playerData = PlayerStatusService.LoadPlayerStatus();

            if (!item.HasReachedItemMax().Invoke())
            {
                PlayErrorSound();
                alertMessageManager.SetAlertMessage(itemMaxReachedMsg);
                return;
            }

            if (PlayerHasEnoughFundsToBuy(item.buffPrice))
            {
                playerScore -= item.buffPrice;

                item.BuyItem().Invoke();

                playerData.DecreaseScore(item.buffPrice);
                PlayerStatusService.SavePlayerStatus(playerData);
                LoadPlayerData();

                item.DeselectObject();
                selectedObjectManager.RemoveSelectedObject();
                PlayBuySound();
            }
            else
            {
                PlayErrorSound();
                alertMessageManager.SetAlertMessage(notEnoughMoneyMsg);
            }
        }
Example #2
0
    public void AddBuff(ShopBuff buff, bool isPoison = false)
    {
        for (int i = 0; i < buffs.Count; i++)
        {
            if (buffs[i].name == buff.name)
            {
                GameManager.Instance.notificationManager.ShowNotification(
                    "That event is ongoing!", NotificationId.Event);
                return;
            }
        }

        if (GameManager.Instance.SpendMoney(buff.cost))
        {
            // Particles
            if (!particleInstance)
            {
                particleInstance = Instantiate(particlePrefab, transform);
            }
            if (!poisonParticleInstance)
            {
                poisonParticleInstance = Instantiate(poisonParticlePrefab, transform);
            }
            particleInstance.SetActive(!isPoison);
            poisonParticleInstance.SetActive(isPoison);

            // Sound & notification
            if (!isPoison)
            {
                SFXManager.Instance.PlaySFX(partySfx);
            }
            GameManager.Instance.notificationManager.
            ShowNotification(buff.StartText(this));

            // Buff
            buffs.Add(buff.Clone());

            // Deselect window after buying event
            OnDeselect();
        }
        else
        {
            GameManager.Instance.notificationManager.
            ShowNotification("You don't have enough money!", NotificationId.Money);
        }
    }