chip-game/Assets/Scripts/Server/CountersCollector.cs

101 lines
3.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using PrizeSystem;
using System.Collections.Concurrent;
using System.Collections.Generic;
using UnityEngine;
public class CountersCollector : MonoBehaviour
{
public static ConcurrentDictionary<string, string> Counters = new();
void Awake()
{
InvokeRepeating("Refresh", 0, 5);
}
private static readonly CounterData[] _counterConfigs =
{
// Призовые счетчики глобальные
new CounterData(PrizeSystemManager.HopperPrizeCounter, "Хоппер", 0),
new CounterData(PrizeSystemManager.TicketPrizeCounter, "Тикетник", 0),
new CounterData(PrizeSystemManager.MarblesPrizeCounter, "Марблс", 0),
new CounterData(PrizeSystemManager.SpecialPrizeCounter, "Суперприз", 0),
// Призовые счетчики обнуляемые
new CounterData($"{PrizeSystemManager.HopperPrizeCounter}Nullable", "Хоппер (обнуляемый)", 0),
new CounterData($"{PrizeSystemManager.TicketPrizeCounter}Nullable", "Тикетник (обнуляемый)", 0),
new CounterData($"{PrizeSystemManager.MarblesPrizeCounter}Nullable", "Марблс (обнуляемый)", 0),
new CounterData($"{PrizeSystemManager.SpecialPrizeCounter}Nullable", "Суперприз (обнуляемый)", 0),
// Выручка
new CounterData(PrizeSystemManager.key_cash, "Выручка", 0),
new CounterData(PrizeSystemManager.key_cashNul, "Выручка (обнуляемый)", 0),
// Остаток призов
new CounterData(KeyVault.PRIZES_AVAILABLE, "Остаток призов", 0),
// Цены
new CounterData("PricePVP", "Цена на двоих", 10),
new CounterData("PricePVE", "Цена против бота", 10),
new CounterData("PriceRevenge", "Цена реванша", 10),
// Расчеты
new CounterData("ValutaName", "Название валюты", "руб."),
new CounterData("ValutaPerImpulse", "Валюта за импульс", 10),
// Другое
new CounterData("Number", "Номер телефона", "<не указан>"),
};
void Refresh()
{
Counters.Clear();
foreach (var config in _counterConfigs)
{
AddCounter(config);
}
}
void AddCounter(CounterData counterData)
{
string value = counterData.Type == SettingType.Int
? PlayerPrefs.GetInt(counterData.PrefsKey, counterData.DefaultIntValue).ToString()
: PlayerPrefs.GetString(counterData.PrefsKey, counterData.DefaultStringValue);
Counters[counterData.Alias] = value;
}
struct CounterData
{
public string PrefsKey;
public string Alias;
public SettingType Type;
public string DefaultStringValue;
public int DefaultIntValue;
/// <summary> Конструктор для строковых счетчиков </summary>
public CounterData(string prefsKey, string alias, string defaultValue)
{
PrefsKey = prefsKey;
Alias = alias;
Type = SettingType.String;
DefaultStringValue = defaultValue;
DefaultIntValue = 0;
}
/// <summary> Конструктор для целочисленных счетчиков </summary>
public CounterData(string prefsKey, string alias, int defaultValue)
{
PrefsKey = prefsKey;
Alias = alias;
Type = SettingType.Int;
DefaultStringValue = string.Empty;
DefaultIntValue = defaultValue;
}
}
}