using UnityEngine; using TMPro; // МАГАЗИН: редкий PvE-торговец (синий кристалл за золото), бесплатный сундук раз в день, пакеты ресурсов за золото. // Лимиты пакетов сбрасываются в полночь; у торговца -- свои: не больше 2 кристаллов за 7 реальных суток. public class ShopPanel : BasePanel { TextMeshProUGUI timer; protected override void Build(RectTransform root) { var list = ScrollList(root); var wallet = UIKit.Row(list, 70, 20, UIKit.Theme.CardDark, 10); WalletItem(wallet, ResourceType.Gems); WalletItem(wallet, ResourceType.Gold); TraderCard(list); timer = UIKit.Text(list, "", 24, UIKit.Theme.TextDim, TextAlignmentOptions.Center, 40); Tick(); foreach (var item in GameData.ShopItems) { var it = item; bool free = item.price == 0 && !item.comingSoon; int bought = GP.BoughtToday(item.id); bool canBuy = GP.CanBuy(item); var card = UIKit.Card(list, free && canBuy ? UIKit.Theme.CardDone : UIKit.Theme.Card); var row = UIKit.Row(card, 130, 16); var iconColor = item.gives != null && item.gives.Length > 0 ? GameData.ResColor(item.gives[0].type) : UIKit.Theme.Gold; UIKit.Icon(row, iconColor, item.id == "free_chest" ? "?" : "", 110); var info = UIKit.Card(row, new Color(0, 0, 0, 0), 0, 4); UIKit.Size(info, -1, -1, 1); var title = UIKit.Text(info, item.title, 30); title.fontStyle = FontStyles.Bold; string gives = item.id == "free_chest" ? "Случайный набор ресурсов" : GameData.RewardsText(item.gives); UIKit.Text(info, gives, 24, UIKit.Theme.TextDim); if (item.dailyLimit > 0) UIKit.Text(info, "Сегодня: " + bought + " / " + item.dailyLimit, 22, UIKit.Theme.TextDim); string label; Color color; if (item.comingSoon) { label = item.priceLabel + "\nскоро"; color = UIKit.Theme.Gray; } else if (!canBuy) { label = "Лимит"; color = UIKit.Theme.Gray; } else if (free) { label = "Бесплатно"; color = UIKit.Theme.Green; } else { label = item.price + " " + GameData.ResName(item.priceType); color = UIKit.Theme.Blue; } var b = UIKit.Button(row, label, color, () => GP.Buy(it), 220, 100, 26); b.interactable = canBuy; } } // Редкий PvE-торговец (регламент валют 05.11, разд. 3): дорогой обмен золота на синий кристалл void TraderCard(Transform list) { var gp = GameProgress.Instance; int price = gp.TraderPrice; string block = gp.TraderBlockReason(); bool enough = price >= 0 && gp.Res(ResourceType.Gold) >= price; var card = UIKit.Card(list, UIKit.Theme.CardDark); var row = UIKit.Row(card, 150, 16); UIKit.Icon(row, GameData.ResColor(ResourceType.Gems), "", 110); var info = UIKit.Card(row, new Color(0, 0, 0, 0), 0, 4); UIKit.Size(info, -1, -1, 1); var title = UIKit.Text(info, "Редкий торговец: синий кристалл", 30); title.fontStyle = FontStyles.Bold; UIKit.Text(info, $"Куплено за 7 дней: {gp.TraderBought} / {gp.TraderMaxPurchases}. Входит в недельный предел новых кристаллов " + $"({gp.CrystalQuotaUsed} / {gp.CrystalQuotaLimit})", 22, UIKit.Theme.TextDim); if (block != null) UIKit.Text(info, block, 22, UIKit.Theme.Gold); string label = price < 0 ? "Недоступно" : price.ToString("N0") + " золота"; var b = UIKit.Button(row, label, block == null && enough ? UIKit.Theme.Blue : UIKit.Theme.Gray, () => { gp.BuyCrystalFromTrader(); RequestRebuild(); }, 260, 100, 24); b.interactable = block == null; } static void WalletItem(Transform parent, ResourceType t) { UIKit.Icon(parent, GameData.ResColor(t), "", 40); var txt = UIKit.Text(parent, GameData.ResName(t) + ": " + Mathf.FloorToInt(GameProgress.Instance.Res(t)).ToString("N0"), 28); UIKit.Size(txt, -1, -1, 1); } protected override void Tick() { if (timer != null) timer.text = "Лимиты обновятся через " + GameData.FormatTime(GameProgress.SecondsToNextDay); } }