namespace Supercell.Laser.Logic.Battle { using System; using System.IO; using System.Text.Json; using System.Collections.Generic; using Supercell.Laser.Logic.Listener; public static class CommunityEvent { // === НАСТРОЙКИ ИВЕНТА === public static readonly DateTime EventStart = new DateTime(2026, 7, 19, 8, 0, 0, DateTimeKind.Utc); public static readonly DateTime EventEnd = new DateTime(2026, 8, 12, 12, 0, 0, DateTimeKind.Utc); public static readonly int GoalWins = 10000; // цель побед public static readonly int GemsReward = 100; // гемов каждому // Этапы: при достижении X побед → Y гемов (до финала) public static readonly (int wins, int gems, string key)[] Milestones = new[] { (1000, 10, "event_milestone_1000"), (3000, 25, "event_milestone_3000"), (6000, 50, "event_milestone_6000"), (10000, 100, "event_milestone_10000"), }; // ======================== private static readonly string SavePath = "event_progress.json"; private static readonly object _lock = new object(); private static int _totalWins; private static HashSet _rewardedMilestones = new HashSet(); public static int TotalWins => _totalWins; public static void Load() { try { if (!File.Exists(SavePath)) { _totalWins = 0; return; } string json = File.ReadAllText(SavePath); var data = JsonSerializer.Deserialize(json); if (data != null) { _totalWins = data.TotalWins; _rewardedMilestones = new HashSet(data.RewardedMilestones ?? new List()); } } catch { _totalWins = 0; } } private static void Save() { try { var data = new EventData { TotalWins = _totalWins, RewardedMilestones = new List(_rewardedMilestones) }; File.WriteAllText(SavePath, JsonSerializer.Serialize(data)); } catch { } } public static void AddWin() { DateTime now = DateTime.UtcNow; if (now < EventStart || now > EventEnd) return; lock (_lock) { _totalWins++; Save(); CheckMilestones(); } } private static void CheckMilestones() { foreach (var (wins, gems, key) in Milestones) { if (_totalWins >= wins && !_rewardedMilestones.Contains(wins)) { _rewardedMilestones.Add(wins); Save(); RewardAllPlayers(gems, wins, key); } } } private static void RewardAllPlayers(int gems, int winsGoal, string notifKey) { Console.WriteLine($"[EVENT] Достигнуто {winsGoal} побед! Выдаём {gems} гемов всем игрокам..."); LogicServerListener.Instance.OnCommunityMilestone(gems, winsGoal, notifKey); } private class EventData { public int TotalWins { get; set; } public List RewardedMilestones { get; set; } } } }