90 lines
2.6 KiB
C#
90 lines
2.6 KiB
C#
using PrizeSystem;
|
|
using System;
|
|
using UnityEngine;
|
|
|
|
public static class SingleWallet
|
|
{
|
|
public static int Balance { get; private set; }
|
|
|
|
public static event Action<int> onCoinAdded;
|
|
public static event Action<int> onCoinRemoved;
|
|
public static event Action<int> OnBalanceChanged;
|
|
|
|
|
|
private static bool freeplay;
|
|
private static int valutaPerImpulse;
|
|
public static void Initialize()
|
|
{
|
|
Balance = LoadBalance();
|
|
ComWrapper.PaymentReceived += AddCredit;
|
|
|
|
PullSettings();
|
|
SettingsManager.OnSettingsChanged.AddListener(PullSettings);
|
|
}
|
|
|
|
public static bool TryPay(int amount)
|
|
{
|
|
if (freeplay) return true;
|
|
|
|
if (Balance >= amount)
|
|
{
|
|
ChangeBalance(-amount);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public static void AddCredit()
|
|
{
|
|
ChangeBalance(valutaPerImpulse);
|
|
|
|
//вот это вот некрасивое надо куда то девать.
|
|
PlayerPrefs.SetInt(PrizeSystemManager.key_cash, PlayerPrefs.GetInt(PrizeSystemManager.key_cash) + valutaPerImpulse);
|
|
PlayerPrefs.SetInt(PrizeSystemManager.key_cashNul, PlayerPrefs.GetInt(PrizeSystemManager.key_cashNul) + valutaPerImpulse);
|
|
|
|
if (SettingsManager.GetString("BaseBotDifficulty", "Фиксированная") == "Повышенная")
|
|
{
|
|
int nowPulses = PlayerPrefs.GetInt("PulsesCounter", 0) + 1;
|
|
PlayerPrefs.SetInt("PulsesCounter", nowPulses);
|
|
}
|
|
}
|
|
|
|
public static void AddCreditNoCounters(int amount) => ChangeBalance(amount);
|
|
|
|
public static void ReturnCredits(GameMode gameMode)
|
|
{
|
|
string gamemodePriceKey = gameMode == GameMode.pvp ? "PricePVP" : "PricePVE";
|
|
int gamemodePrice = PlayerPrefs.GetInt(gamemodePriceKey, 10);
|
|
|
|
ChangeBalance(gamemodePrice);
|
|
}
|
|
|
|
public static void ResetBalance()
|
|
{
|
|
int delta = -Balance;
|
|
ChangeBalance(delta);
|
|
}
|
|
|
|
private static void PullSettings()
|
|
{
|
|
freeplay = SettingsManager.GetBool("Freeplay", false);
|
|
valutaPerImpulse = PlayerPrefs.GetInt("ValutaPerImpulse", 10);
|
|
}
|
|
|
|
private static void ChangeBalance(int delta)
|
|
{
|
|
if (delta == 0) return;
|
|
|
|
Balance += delta;
|
|
Mathf.Max(Balance, 0);
|
|
SaveBalance();
|
|
|
|
if (delta > 0) onCoinAdded?.Invoke(delta);
|
|
else onCoinRemoved?.Invoke(delta);
|
|
OnBalanceChanged?.Invoke(Balance);
|
|
}
|
|
|
|
private static void SaveBalance() => PlayerPrefs.SetInt("CoinsCount", Balance);
|
|
private static int LoadBalance() => PlayerPrefs.GetInt("CoinsCount", 0);
|
|
} |