using System; using System.Collections.Generic; using UnityEngine; namespace TKS.OutGame { /// 연의 전기 편 1개의 진행(연의 = normal · 열전 = hard · [승리, 도전 1, 도전 2]). [Serializable] public class ScenarioEpisode { public string id = ""; public bool[] normal = new bool[3]; public bool[] hard = new bool[3]; public bool allStar; } [Serializable] public class ScenarioState { public List episodes = new List(); [Tooltip("보유하지 않은 영웅의 조각(주역 조각 · 모아서 획득 · 필요 수 = 추후)")] public List heroShards = new List(); public bool serverView; public List serverUnlocked = new List(); public ScenarioEpisode Get(string id, bool create) { foreach (var e in episodes) if (e.id == id) return e; if (!create) return null; var n = new ScenarioEpisode { id = id }; episodes.Add(n); return n; } } /// /// 연의 전기 규칙(기기 세이브 모드 · 서버 `/tks/modes/scenario` 와 같은 보상) — 입장 군량 scenario.stamina_cost · 지면 refund_on_lose_pct 환급 · /// 첫 승리 reward_normal / reward_hard · 도전 조건마다 *_challenge_gem · 6개 모두 reward_all_star · 주역 조각 = 보유 여부와 관계없이(reward_hero_shard always). /// public static class ScenarioModeRules { public const string Kind = "scenario"; const string M = "scenario"; public static List Battles() { var res = new List(ContentTables.Rows("scenario_battles")); res.Sort((a, b) => a.I("n_no").CompareTo(b.I("n_no"))); return res; } public static bool Unlocked(SaveData d, ContentRow b) { if (d.scenario.serverView) return d.scenario.serverUnlocked.Contains(b.S("s_id")); int ch, st; if (!ArenaRules.ParseStageKey(b.S("s_unlock_stage"), out ch, out st)) return true; var s = d.Stage(ch, st, false); return s != null && s.clears > 0; } public static bool HardOpen(SaveData d, string id) { var e = d.scenario.Get(id, false); return e != null && e.normal[0]; } public static string Can(OutGameData db, SaveData d, string id, bool hard, DateTime nowUtc) { var b = ContentTables.Find("scenario_battles", "s_id", id); if (b == null) return "없는 편"; if (b.I("n_no") == 0) return "서장 = 1장 학습 판(본편 1-1 ~ 1-3)"; if (!Unlocked(d, b)) return b.S("s_unlock_ko") + " 뒤 열림"; if (hard && !HardOpen(d, id)) return "열전 = 연의를 이긴 뒤"; EconomyRules.TickStamina(db, d, nowUtc); int cost = ContentTables.Int(M, "stamina_cost"); if (d.stamina < cost) return "군량이 부족합니다 — 필요 " + cost; return null; } /// 입장 = 군량 사용. public static string Enter(OutGameData db, SaveData d, string id, bool hard, DateTime nowUtc) { var why = Can(db, d, id, hard, nowUtc); if (why != null) return why; EconomyRules.SpendStamina(db, d, ContentTables.Int(M, "stamina_cost"), nowUtc); return null; } /// 끝(기기 세이브 모드) — 보상 · 진행 기록 · 지면 군량 환급. public static ModeResult Result(OutGameData db, SaveData d, string id, bool hard, bool win, bool[] challenges, List lines, DateTime nowUtc, System.Random rng) { var b = ContentTables.Find("scenario_battles", "s_id", id); var m = new ModeResult { kind = Kind, win = win, title = (b != null ? b.S("s_title_ko") : id) + (hard ? " (열전)" : " (연의)") }; if (lines != null) m.lines.AddRange(lines); if (!win) { int back = Mathf.RoundToInt(ContentTables.Int(M, "stamina_cost") * ContentTables.Num(M, "refund_on_lose_pct") / 100f); if (back > 0) EconomyRules.AddStamina(db, d, back, nowUtc); m.lines.Add("패배 — 군량 " + back + " 환급"); return m; } var e = d.scenario.Get(id, true); var st = hard ? e.hard : e.normal; var got = new List(); if (!st[0]) GiveParts(db, d, b, ContentTables.Str(M, hard ? "reward_hard" : "reward_normal"), rng, got); else if (ContentTables.Str(M, "reward_hero_shard") == "always") // 다시 이겨도 주역 조각(보유 여부 무관 · 양 = 첫 승리 꾸러미의 shard) foreach (var kv in ContentTables.ParseMap(ContentTables.Str(M, hard ? "reward_hard" : "reward_normal"))) if (kv.Key == "shard") GiveShard(d, b, Mathf.RoundToInt(kv.Value), db, got); st[0] = true; int gem = ContentTables.Int(M, hard ? "reward_hard_challenge_gem" : "reward_normal_challenge_gem"); for (int i = 0; i < 2 && challenges != null && i < challenges.Length; i++) if (challenges[i] && !st[i + 1]) { st[i + 1] = true; d.gem += gem; got.Add("도전 " + (i + 1) + " 보옥 +" + gem); } if (!e.allStar && Array.TrueForAll(e.normal, x => x) && Array.TrueForAll(e.hard, x => x)) { e.allStar = true; GiveParts(db, d, b, ContentTables.Str(M, "reward_all_star"), rng, got); } if (got.Count > 0) m.lines.Add(string.Join(" · ", got.ToArray())); return m; } static void GiveParts(OutGameData db, SaveData d, ContentRow b, string parts, System.Random rng, List got) { foreach (var kv in ContentTables.ParseMap(parts)) { int n = Mathf.RoundToInt(kv.Value); if (kv.Key == "gem") { d.gem += n; got.Add("보옥 +" + n); } else if (kv.Key == "gold") { d.gold += n; got.Add("골드 +" + n); } else if (kv.Key == "shard") GiveShard(d, b, n, db, got); else if (kv.Key.EndsWith("_chest")) for (int i = 0; i < n; i++) { var c = TreasureRules.AddChest(db, d, kv.Key.Substring(0, kv.Key.Length - "_chest".Length), rng); if (c != null) got.Add(db.Chests.Get(c).nameKo); } } } static void GiveShard(SaveData d, ContentRow b, int n, OutGameData db, List got) { if (b == null || n <= 0) return; string hero = b.S("s_reward_hero"); var h = d.Hero(hero); if (h != null) h.shards += n; else Counts.Add(d.scenario.heroShards, hero, n); // 보유하지 않은 영웅 = 따로 모은다(얻는 데 드는 수 = 추후) var def = db.Heroes.Get(hero); got.Add((def != null ? def.nameKo : hero) + " 조각 +" + n); } } }