namespace Supercell.Laser.Logic.Home { using System; using System.Collections.Generic; using System.IO; using Newtonsoft.Json; using Supercell.Laser.Logic.Home.Items; public class CustomOfferModel { public int Id { get; set; } public string Title { get; set; } public int Cost { get; set; } public int OldCost { get; set; } public int Currency { get; set; } // 0 = Gems, 1 = Gold, 3 = StarPoints public int DaysLeft { get; set; } = 7; public List WhoBuy { get; set; } = new List(); public List Items { get; set; } = new List(); } public class CustomOfferItemModel { public int Type { get; set; } // 10 = MegaBox, 14 = BigBox, 6 = BrawlBox, 1 = Coin, 16 = Gems public int Count { get; set; } public int ItemDataId { get; set; } public int SkinDataId { get; set; } } public static class CustomOffers { private static readonly object LockObj = new object(); public static string GetFilePath() { if (File.Exists("/var/www/cdn/v27/src/Supercell.Laser.Server/offers.json")) return "/var/www/cdn/v27/src/Supercell.Laser.Server/offers.json"; if (File.Exists("offers.json")) return "offers.json"; return "/var/www/cdn/v27/src/Supercell.Laser.Server/offers.json"; } public static List LoadOffers() { lock (LockObj) { try { string path = GetFilePath(); if (File.Exists(path)) { string json = File.ReadAllText(path); var list = JsonConvert.DeserializeObject>(json); if (list != null) return list; } } catch { } return new List(); } } public static void SaveOffers(List offers) { lock (LockObj) { try { string path = GetFilePath(); string json = JsonConvert.SerializeObject(offers, Formatting.Indented); File.WriteAllText(path, json); } catch { } } } public static void MarkAsBought(int offerId, long accountId) { lock (LockObj) { var offers = LoadOffers(); var target = offers.Find(o => o.Id == offerId); if (target != null) { if (target.WhoBuy == null) target.WhoBuy = new List(); string accStr = accountId.ToString(); if (!target.WhoBuy.Contains(accStr)) { target.WhoBuy.Add(accStr); SaveOffers(offers); } } } } } }