using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace TKS.OutGame { /// /// 연의 전기 화면(컨텐츠 모드 기획 10판 ② · 2026-11-18) — 표 Resources/UI/Scenario 가 있으면 확정 아트 화면(ArenaScenario · PD 2026-11-18 「연의 전기 통과」 · 서재 · 탭 5 · 두루마리 · 펼침 연출 · 세로 두루마리 상세) · /// 표·그림이 없으면 예전 **더미 UI**(편 목록(편 · 해금 · 연의/열전 진행 ●○) → 편을 누르면 전투 정보 팝업(승리 조건 · 도전 조건 2 · 고정 편성 · 기믹) → 연의 · 열전 입장). /// public partial class ArenaScreen { public const int ScenarioPage = 5; ArenaScenario scenario; // 확정 아트 화면(표 Resources/UI/Scenario · 없으면 null = 더미 UI) RectTransform scenarioSlot; /// 연의 전기 아트 화면(없으면 null · 테스트). public ArenaScenario Scenario { get { return scenario; } } /// 지금 연의 전기 아트 화면이 보이는가(테스트). public bool ScenarioVisible { get { return scenario != null && scenario.Built && scenarioSlot != null && scenarioSlot.gameObject.activeInHierarchy; } } /// Build 에서 제목 띠보다 먼저(화면 전체 · 제목 띠 · 본문 뒤) — 표만 읽음(그림은 처음 열 때). void LoadScenarioView() { scenario = ArenaScenario.Load(this); if (scenario == null) return; scenarioSlot = UiKit.Fill("Scenario", Rt); scenarioSlot.gameObject.SetActive(false); } /// 연의 전기 쪽 = 아트 화면을 켜고 지금 탭을 다시 채움 · 표 없음 · 배경 없음 = false(호출 쪽 = 더미 UI). bool ShowScenarioView() { if (scenario == null || scenarioSlot == null) return false; scenarioSlot.gameObject.SetActive(true); if (scenario.Show(scenarioSlot)) return true; scenarioSlot.gameObject.SetActive(false); // 배경 그림 없음 = 더미 UI(다시 시도하지 않음) scenario = null; return false; } /// 연의 전기 쪽을 떠날 때 · 다시 들어올 때(처음 탭 다시 고름) · 뒤로 = 상세 닫기. void ScenarioPageChanged(int prev, int next) { if (scenario == null) return; if (next != ScenarioPage) scenario.CloseDetail(); else if (prev != ScenarioPage) scenario.ResetTab(); } bool ScenarioBack() { if (page != ScenarioPage || scenario == null || !scenario.DetailOpen) return false; scenario.CloseDetail(); return true; } void ScenarioEntryButton() { UiKit.Btn("Scenario", root, "연의 전기 — 명전 16편", 40, UiKit.Purple, UiKit.White, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -1490f), new Vector2(1032f, 110f), () => SetPage(ScenarioPage)); } void BuildScenario() { ContentTables.Reload(); var d = S.Save; Title("연의 전기"); UiKit.Label(root, "고정 편성 · 고정 능력치(모든 유저 같은 스펙) · 입장 군량 " + ContentTables.Int("scenario", "stamina_cost") + " · 지면 환급", 26, UiKit.InkSoft, TextAnchor.MiddleCenter, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -112f), new Vector2(1032f, 44f), false); var list = ScenarioModeRules.Battles(); float w = 508f, h = 160f; for (int i = 0; i < list.Count; i++) { var b = list[i]; string id = b.S("s_id"); float x = 24f + (i % 2) * (w + 16f), y = 166f + (i / 2) * (h + 10f); bool open = b.I("n_no") > 0 && ScenarioModeRules.Unlocked(d, b); var cell = UiKit.Btn("Ep_" + id, root, "", 26, open ? UiKit.Paper : UiKit.Slot, UiKit.Ink, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(x, -y), new Vector2(w, h), () => ScenarioInfo(id)); var e = d.scenario.Get(id, false); string stars = e == null ? "○○○ / ○○○" : Dots(e.normal) + " / " + Dots(e.hard); UiKit.Label(cell.transform, b.I("n_no") + ". " + b.S("s_title_ko") + " " + b.I("n_year") + " · " + b.S("s_part") + "", 30, UiKit.Ink, TextAnchor.UpperLeft, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(14f, -10f), new Vector2(w - 28f, 50f), false); UiKit.Label(cell.transform, (open ? "주역 " + b.S("l_fixed_hero_ko").Replace(";", " · ") : (b.I("n_no") == 0 ? "서장 = 1장 학습 판" : b.S("s_unlock_ko") + " 뒤 열림")) + "\n연의 · 열전 " + stars, 22, UiKit.InkSoft, TextAnchor.UpperLeft, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(14f, -62f), new Vector2(w - 28f, 90f), false); } } static string Dots(bool[] a) { var s = ""; foreach (var x in a) s += x ? "●" : "○"; return s; } void ScenarioInfo(string id) { var b = ContentTables.Find("scenario_battles", "s_id", id); if (b == null) return; var d = S.Save; string body = "승리 " + b.S("s_win_cond_ko") + "\n도전 1 " + b.S("s_challenge1_ko") + "\n도전 2 " + b.S("s_challenge2_ko") + "\n출전 " + b.S("l_fixed_hero_ko").Replace(";", " · ") + (b.S("l_companion_ko").Length > 0 ? " + " + b.S("l_companion_ko").Replace(";", " · ") : "") + "\n전장 " + b.S("s_gimmick_ko"); var bt = new List(); var wn = ScenarioModeRules.Can(S.Db, d, id, false, S.Now); bt.Add(new OutGameRoot.ModalButton(wn == null ? "연의 출전" : "연의 — " + wn, wn == null ? UiKit.Red : UiKit.Disabled, () => ScenarioGo(id, false))); var wh = ScenarioModeRules.Can(S.Db, d, id, true, S.Now); bt.Add(new OutGameRoot.ModalButton(wh == null ? "열전 출전" : "열전 — " + wh, wh == null ? UiKit.Purple : UiKit.Disabled, () => ScenarioGo(id, true))); bt.Add(new OutGameRoot.ModalButton("닫기", UiKit.Dark, null)); Root.Modal(b.S("s_title_ko"), body, bt.ToArray()); } /// /// 서장(편 n_no 0 · 도원결의 = 출정 n_spec_chapter 장 학습 판 1 ~ n_acts) 출전 — 아직 안 깬 첫 막(모두 깼으면 1막)을 일반 출정으로 연다 /// (월드맵 경유 · 군량 · 시나리오 이벤트 · 학습 안내 · 보상 = 출정 규칙 그대로). false = 서장 아님. /// 2026-11-18 PD 「이 PC 에서 연의전기가 실행이 안돼」 — 서장은 「1장 학습 판」 알림만 띄우고 들어가지 않았음. /// static int prologueLast; internal bool PrologueGo(string id) { var b = ContentTables.Find("scenario_battles", "s_id", id); if (b == null || b.I("n_no") != 0) return false; var map = Root.Map; var cfg = Root.Battle.Config; if (map == null || !map.HasData) { Root.Toast("월드맵 자료 없음"); return true; } int ch = b.I("n_spec_chapter"), acts = Mathf.Max(1, b.I("n_acts")), pick = 0; for (int s = acts; s >= 1; s--) { var st = S.Save.Stage(ch, s, false); if (st == null || st.clears == 0) pick = s; // 안 깬 막 중 가장 앞 } if (pick == 0) pick = prologueLast % acts + 1; // 모두 깼으면 1막 → 2막 → 3막 차례로 다시 보기 prologueLast = pick; int ci = -1; for (int i = 0; i < cfg.chapters.Length; i++) if (cfg.chapters[i].no == ch) ci = i; var list = ci >= 0 ? cfg.StagesOfChapter(ch) : new List(); int node = -1; for (int n = 0; n < list.Count; n++) if (cfg.stages[list[n]].stage == pick) node = n; if (node < 0) { Root.Toast(ch + "-" + pick + " 스테이지 없음"); return true; } if (map.TryEnter != null && !map.TryEnter(list[node])) return true; // 군량(시험 메뉴 「군량 면제」면 통과) ScenarioEvent.AllowReplay(ch, pick); // 연의 전기에서 들어오면 깬 판이어도 시작·승리 연출을 다시 튼다 Root.OpenWorldMap(); map.EnterStage(ci, node); return true; } /// 편 id 출전(연의 · 열전) — 아트 화면 상세의 출전 버튼도 이것. internal void ScenarioGo(string id, bool hard) { if (PrologueGo(id)) return; var cfg = Root.Battle.Config; var stage = new BalanceConfig.StageDef { title = id, subtitle = "연의 전기", kind = StageKind.Normal, aiAccuracy = 1f, aiAggroRange = 999f }; var b = ContentTables.Find("scenario_battles", "s_id", id); int ch, st; var refSt = b != null && ArenaRules.ParseStageKey(b.S("s_unlock_stage"), out ch, out st) ? ContentEnemyRef.RefStage(cfg, ch) : null; if (refSt != null) { stage.aiAccuracy = refSt.aiAccuracy; stage.aiAggroRange = refSt.aiAggroRange; stage.bgTheme = refSt.bgTheme; } var rules = new ScenarioRules { BattleId = id, Hard = hard, Config = cfg }; var why = rules.Prepare(stage); if (why != null) { Root.Toast(why); return; } var w = S.ScenarioEnter(id, hard); if (w != null) { Root.Toast(w); return; } Root.StartMode(ScenarioModeRules.Kind, id, hard ? 1 : 0, stage, rules.TurnLimitValue, ScenarioPage, rules); } } }