using System; using System.Collections.Generic; namespace TKS.OutGame { /// 떠돌이 상인이 오늘 내놓은 물품 1칸. [Serializable] public class WanderOffer { public string slot; public string heroId; public bool bought; } /// 떠돌이 상인의 오늘 물품(날이 바뀌면 다시 굴린다). [Serializable] public class WanderState { public string day = ""; public List offers = new List(); } /// /// 떠돌이 상인(PD 2026-11-24 「상점의 영웅 조각 판매는 상시가 아니라 랜덤 · ★1 · ★2 영웅 조각 = 골드 · ★3 영웅 조각 = 보옥으로만」) — 표 wander_shop(ContentModes): /// 칸(s_slot)마다 그날 나올 확률 f_appear_pct · 태생 ★ n_rarity 영웅 중 무작위 1명의 조각 n_amount 개 · 값 s_currency(gold · gem) n_price · 칸마다 하루 1번. /// 대상 = 명장 등용 풀(gacha_pool in_pool)의 영웅(병사 제외) · 보유 = 그 영웅 조각 · 미보유 = 영입 조각(GoodsRules.AddHeroShards). /// 날 경계 = EconomyRules.DayKey(승급 장비 상점과 같은 「매일 갱신」). /// public static class WanderRules { public const string Table = "wander_shop"; public const string Gold = "gold"; public const string Gem = "gem"; public static readonly string[] Currencies = { Gold, Gem }; public static List Rows() { return ContentTables.Rows(Table); } public static ContentRow Row(string slot) { return ContentTables.Find(Table, "s_slot", slot); } /// 그 태생 ★ 의 판매 대상 영웅(등용 풀 · 병사 제외). public static List Heroes(OutGameData db, int rarity) { var res = new List(); foreach (var p in db.Gacha.pool) { if (!p.inPool) continue; var h = db.Heroes.Get(p.heroId); if (h != null && !h.isSoldier && h.rarity == rarity) res.Add(h); } return res; } /// 오늘 물품을 새로 굴려야 하는가(처음 · 날이 바뀜). public static bool NeedsRoll(SaveData d, DateTime nowUtc) { return d.wander == null || d.wander.day != EconomyRules.DayKey(nowUtc); } /// 오늘의 물품(없을 수 있음) — 날이 바뀌었으면 칸마다 확률로 굴린다. public static List Today(OutGameData db, SaveData d, DateTime nowUtc, System.Random rng) { if (NeedsRoll(d, nowUtc)) { var st = new WanderState { day = EconomyRules.DayKey(nowUtc) }; foreach (var r in Rows()) { if (rng.NextDouble() * 100.0 >= r.F("f_appear_pct")) continue; var pool = Heroes(db, r.I("n_rarity")); if (pool.Count == 0) continue; st.offers.Add(new WanderOffer { slot = r.S("s_slot"), heroId = pool[rng.Next(pool.Count)].id }); } d.wander = st; } return d.wander.offers; } static WanderOffer Offer(SaveData d, string slot) { if (d.wander != null) foreach (var o in d.wander.offers) if (o.slot == slot) return o; return null; } /// null = 살 수 있음. public static string Can(OutGameData db, SaveData d, string slot, DateTime nowUtc) { if (NeedsRoll(d, nowUtc)) return "오늘 물품이 아닙니다"; var o = Offer(d, slot); var r = Row(slot); if (o == null || r == null) return "없는 물품"; if (o.bought) return "이미 구매했습니다(칸마다 하루 1번)"; int price = r.I("n_price"); if (r.S("s_currency") == Gem) { if (d.gem < price) return "보옥 부족 " + d.gem + " / " + price; } else if (d.gold < price) return "골드 부족 " + d.gold + " / " + price; return null; } /// 구매(기기 세이브 모드) → 얻은 것(gains) · 반환 = 실패 사유(null = 성공). public static string Buy(OutGameData db, SaveData d, string slot, DateTime nowUtc, List gains = null) { var why = Can(db, d, slot, nowUtc); if (why != null) return why; var o = Offer(d, slot); var r = Row(slot); int price = r.I("n_price"), n = r.I("n_amount"); if (r.S("s_currency") == Gem) d.gem -= price; else d.gold -= price; GoodsRules.AddHeroShards(d, o.heroId, n); o.bought = true; if (gains != null) { var def = db.Heroes.Get(o.heroId); GoodsRules.Add(gains, o.heroId, n, (def != null ? def.nameKo : o.heroId) + " 조각", "shard"); } return null; } /// 표 검사(데이터 테스트) — 칸 이름 · 태생 ★ · 확률 · 수량 · 값 · ★3 = 보옥 / ★1 · ★2 = 골드(PD 2026-11-24). public static List Validate(OutGameData db) { var e = new List(); const string f = Table + ".csv"; var seen = new HashSet(); var rows = Rows(); if (rows.Count == 0) e.Add(f + ": 줄 없음"); foreach (var r in rows) { string slot = r.S("s_slot"), cur = r.S("s_currency"); int rarity = r.I("n_rarity"); if (slot.Length == 0 || !seen.Add(slot)) e.Add(f + ": s_slot 「" + slot + "」 비었거나 중복"); if (rarity < 1 || rarity > 3) e.Add(f + ": " + slot + " n_rarity " + rarity + " = 1~3 이 아님"); else if (Heroes(db, rarity).Count == 0) e.Add(f + ": " + slot + " ★" + rarity + " 영웅이 등용 풀에 없음"); float pct = r.F("f_appear_pct"); if (pct < 0f || pct > 100f) e.Add(f + ": " + slot + " f_appear_pct " + pct + " = 0~100 이 아님"); if (r.I("n_amount") <= 0 || r.I("n_price") <= 0) e.Add(f + ": " + slot + " 수량 · 값 이상"); if (Array.IndexOf(Currencies, cur) < 0) e.Add(f + ": " + slot + " s_currency 「" + cur + "」 = gold · gem 이 아님"); else if ((rarity >= 3) != (cur == Gem)) e.Add(f + ": " + slot + " ★3 = 보옥 · ★1 · ★2 = 골드 여야 함"); } return e; } } }