90 lines
2.6 KiB
C#

using UnityEngine;
using UnityEngine.Events;
/// <summary>
///Кошелек. При использовании предполагается что это единственный глобальный кошелек для всей игры.<br/>
///Зависимости:<br/>
///- ComWrapper<br/>
///- SettingsManager<br/>
/// </summary>
public static class SingleWallet
{
static bool saveMoneyBetweenSessions = true; //это надо из конфига тянуть!
public static int Balance;
public static UnityEvent<int> onCoinAdded;
public static UnityEvent<int> onCoinRemoved;
public static void Initialize()
{
if (!saveMoneyBetweenSessions) PlayerPrefs.SetInt("CoinsCount", 0);
Balance = PlayerPrefs.GetInt("CoinsCount", 0);
onCoinAdded = new UnityEvent<int>();
onCoinRemoved = new UnityEvent<int>();
ComWrapper.PaymentReceived.AddListener(AddCredit);
}
public static bool Pay(int amount)
{
//блок проверки оплаты
if (SettingsManager.GetBool("Freeplay", false))
{
return true;
}
if (Balance >= amount)
{
Balance -= amount;
PlayerPrefs.SetInt("CoinsCount", Balance);
onCoinRemoved?.Invoke(Balance);
return true;
}
return false;
}
public static void AddCredit()
{
int recieved = PlayerPrefs.GetInt("ValutaPerImpulse", 10);
Balance = Balance + recieved;
PlayerPrefs.SetInt("CoinsCount", Balance);
//Счетчики выручки
PlayerPrefs.SetInt(PrizeSystem.key_cash, PlayerPrefs.GetInt(PrizeSystem.key_cash) + recieved);
PlayerPrefs.SetInt(PrizeSystem.key_cashNul, PlayerPrefs.GetInt(PrizeSystem.key_cashNul) + recieved);
if (SettingsManager.GetString("BaseBotDifficulty", "Фиксированная") == "Повышенная")
{
int nowPulses = PlayerPrefs.GetInt("PulsesCounter", 0) + 1;
PlayerPrefs.SetInt("PulsesCounter", nowPulses);
}
onCoinAdded?.Invoke(Balance);
}
public static void AddCreditNoCounters(int amount)
{
Balance = Balance + amount;
PlayerPrefs.SetInt("CoinsCount", Balance);
onCoinAdded?.Invoke(Balance);
}
public static void ReturnCredits(GameMode gameMode)
{
string gamemodePriceKey = gameMode == GameMode.pvp ? "PricePVP" : "PricePVE";
int gamemodePrice = PlayerPrefs.GetInt(gamemodePriceKey, 10);
Balance += gamemodePrice;
PlayerPrefs.SetInt("CoinsCount", Balance);
onCoinAdded?.Invoke(Balance);
}
}