using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using TKS.OutGame;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.TestTools;
namespace TKS.Tests
{
///
/// 첫 실행 흐름(PD 2026-11-24 「최초 게임 실행 시 게임 Flow」 · 요청서 §4 + 2차 지시) — 새 세이브(영웅 없음): 인트로 → 서장 1 → 2막(결과 화면 없음) → 3막 = 결과 화면(유비 획득) →
/// 본영(유비만 편성) + 대사 → 「등용」 → 「1회 등용」(무료 · 첫 장 = 가신) → 편성 안내(가신을 세움) → 「출정」 → 1-1: 스킬 튜토리얼(적 대사 → 유비 스킬 → 모인 적 일격 → 가신 회복) → 자유 플레이 → 승리 → 군영 소개(장소 포커스) → 끝 기록.
/// 서장을 끝낸 세이브 = 로비 · 메모리 세이브 = 건너뜀 · 도중 종료 뒤 이어서 · 첫 등용을 이미 한 세이브 · 튜토리얼 조건이 안 맞는 판.
/// 흐름은 메모리 세이브에서 꺼져 있다 → 여기서만 FirstFlow.ForceOn(연출 · 학습 판도 ForceOn). 값(영웅 · 배너 · 줄 · 문구)은 표에서 읽는다(C45).
///
public class FirstFlowTests
{
static readonly DateTime T0 = new DateTime(2026, 11, 24, 3, 0, 0, DateTimeKind.Utc);
OutGameRoot og;
BattleManager bm;
static OutGameData Db { get { return OutGameData.Default; } }
static BalanceConfig Cfg { get { return Resources.Load("BalanceConfig"); } }
static string PrologueId { get { return FirstFlowData.Str("prologue_battle"); } }
static int PrologueActs { get { return ContentTables.Find("scenario_battles", "s_id", PrologueId).I("n_acts"); } }
static string Retainer { get { return Db.Gacha.FirstPullHero; } }
static string Victim { get { return ContentTables.Find("scenario_battles", "s_id", PrologueId).S("s_reward_hero"); } }
[SetUp]
public void SetUp()
{
WorldProgress.Reset();
FirstFlowData.Reload();
}
[UnityTearDown]
public IEnumerator TearDown()
{
ScenarioEvent.Abort();
FirstFlow.ForceOn = false;
TutorialRules.Mode = TutorialMode.Auto;
ScenarioEvent.Mode = TutorialMode.Auto;
Time.timeScale = 1f;
if (IntroScreen.Current != null) UnityEngine.Object.Destroy(IntroScreen.Current.gameObject);
yield return null;
}
/// Battle 씬을 연다 — fresh = 새 메모리 세이브 · false = 앞에서 쓴 메모리 세이브 그대로(앱을 껐다 켠 것) · flow = 첫 실행 흐름을 켬.
IEnumerator Boot(bool fresh, bool flow)
{
SaveStore.UseMemory(fresh);
FirstFlow.ForceOn = flow;
TutorialRules.Mode = TutorialMode.ForceOn;
ScenarioEvent.Mode = TutorialMode.ForceOn;
SceneManager.LoadScene("Battle");
yield return null;
yield return null;
og = OutGameRoot.Instance;
bm = BattleManager.Instance;
Assert.IsNotNull(og);
Assert.IsNotNull(bm);
Time.timeScale = 1f;
}
SaveData Save { get { return og.Session.Save; } }
PrologueRules Rules { get { return bm.Mode != null ? bm.Mode.rules as PrologueRules : null; } }
static IEnumerator Until(Func cond, float timeout, string what)
{
float t0 = Time.realtimeSinceStartup;
while (!cond() && Time.realtimeSinceStartup - t0 < timeout) yield return null;
Assert.IsTrue(cond(), what + " — " + timeout + "초 안에 되지 않음");
}
/// 서장을 모두 이긴 세이브로(연의 규칙 그대로 · 보상 포함).
void ClearPrologue()
{
var s = og.Session;
for (int a = 1; a <= PrologueActs; a++) ScenarioModeRules.ActResult(s.Db, s.Save, PrologueId, a, PrologueActs, true, new List(), s.Now, new System.Random(1));
}
/// 서장을 끝낸 흐름 세이브(line 줄까지 끝남)로 다시 켠다.
IEnumerator BootAtLine(int line, Action more = null)
{
yield return Boot(true, false);
ClearPrologue();
Save.firstFlow.started = true;
Save.firstFlow.intro = true;
Save.firstFlow.line = line;
if (more != null) more(Save);
og.Session.Commit();
yield return Boot(false, true);
}
IEnumerator UntilLine(int step, float timeout = 6f)
{
Func on = () => og.Flow.Current != null && og.Flow.Current.step == step && og.Flow.Guide != null && og.Flow.Guide.Shown;
float t0 = Time.realtimeSinceStartup;
while (!on() && Time.realtimeSinceStartup - t0 < timeout) yield return null;
Assert.IsTrue(on(), "대사 줄 " + step + " — " + timeout + "초 안에 뜨지 않음 · " + og.Flow.DebugState());
}
/// 대사 넘김 = 누름 2번(한 글자씩 나오는 중이면 전부 표시 → 다음).
IEnumerator TapLine()
{
og.Flow.TapForTest();
og.Flow.TapForTest();
yield return null;
yield return null;
}
IEnumerator UntilPlayerTurn(float timeout = 12f)
{
float t0 = Time.realtimeSinceStartup;
while ((bm.Phase != BattlePhase.PlayerTurn || ScenarioEvent.Running) && Time.realtimeSinceStartup - t0 < timeout)
{
if (ScenarioEvent.Running) ScenarioEvent.SkipForTest();
yield return null;
}
Assert.AreEqual(BattlePhase.PlayerTurn, bm.Phase, "아군 차례");
}
void KillEnemies()
{
foreach (var e in bm.AliveUnits(Faction.Enemy)) e.TakeDamage(e.MaxHp * 10);
bm.CheckBattleEnd();
}
/// 지금 막: 시작 연출을 건너뛰고 적을 모두 쓰러뜨린 뒤 승리 연출을 건너뜀 — 마지막 막이 아니면 결과 화면 없이 다음 막 · 마지막 막 = 결과 화면.
IEnumerator WinAct(int act)
{
yield return Until(() => Rules != null && Rules.Act == act, 6f, act + "막 시작");
Assert.IsNotNull(Rules.WinContinue, "첫 실행 흐름이 연 막");
yield return UntilPlayerTurn();
Assert.IsFalse(og.ScreensVisible, "연의 전기 화면을 거치지 않음");
KillEnemies();
yield return null;
var was = Rules;
bool last = was.LastAct;
float t0 = Time.realtimeSinceStartup;
while (Time.realtimeSinceStartup - t0 < 12f)
{
if (ScenarioEvent.Running) ScenarioEvent.SkipForTest();
if (!last)
{
Assert.IsFalse(og.ResultVisible, act + "막 승리 뒤 결과 화면이 뜸");
Assert.AreNotEqual(BattlePhase.StageClear, bm.Phase, act + "막 승리 = 결과 단계로 가지 않음");
if (Rules != was) break; // 다음 막이 놓임
}
else if (bm.Phase == BattlePhase.StageClear && og.ResultVisible) break; // 마지막 막 = 결과 화면(서장 보상 알림)
yield return null;
}
}
// ---------- 표 · 규칙 ----------
[Test]
public void Tables_NoErrors_RetainerIsFirstPullHero()
{
var errors = FirstFlowData.Check(Db, Cfg);
Assert.AreEqual(0, errors.Count, string.Join("\n", errors.ToArray()));
Assert.Greater(Retainer.Length, 0, "gacha.csv first_pull_hero");
Assert.IsNotNull(Db.Heroes.Get(Retainer), "가신이 heroes.csv 에 있음");
Assert.IsNotNull(Db.Heroes.Get(Victim), "서장 보상 영웅이 heroes.csv 에 있음");
Assert.AreEqual(FirstFlowData.LastStep, FirstFlowData.Lines.Count, "줄 번호 = 1부터 차례");
Assert.IsFalse(Db.Gacha.FreeFirstTen, "첫 10회 무료 없음(PD 2026-11-24 「뽑기는 1회만 무료」)");
}
/// 첫 실행 흐름 세이브의 첫 등용 = 첫 장이 표의 영웅(무료 = 상시 배너의 오늘 무료 1회) · 두 번째부터 · 흐름이 아닌 세이브 = 확률 그대로(같은 씨앗이면 같은 결과).
[Test]
public void FirstPull_FixedHero_OnlyInFlowSave()
{
var g = Db.Gacha;
var b = g.Get(FirstFlowData.Arg(FirstFlowData.LineOf(5).onShow, FirstFlowData.OnShowBanner));
Assert.IsNotNull(b, "줄 5 가 고르는 등용 배너");
const int Seed = 1147;
var d = HeroRules.NewSave(Db, Cfg.playerSpawnPoints.Length, T0);
d.heroes.Clear();
d.firstFlow.started = true;
int gem = d.gem;
Assert.IsTrue(GachaRules.UsesFree(Db, d, b, 1, T0), "첫 1회 = 무료(상시 배너 오늘 무료)");
var one = GachaRules.Draw(Db, d, b, 1, new System.Random(Seed), T0);
Assert.AreEqual(1, one.Count);
Assert.AreEqual(Retainer, one[0].heroId, "첫 장 = 가신");
Assert.IsTrue(one[0].fixedPick);
Assert.IsTrue(one[0].isNew);
Assert.AreEqual(gem, d.gem, "무료");
Assert.IsFalse(GachaRules.UsesFree(Db, d, b, 1, T0), "무료는 1회만");
d.gem = g.CostSingle;
Assert.IsFalse(GachaRules.Draw(Db, d, b, 1, new System.Random(Seed), T0)[0].fixedPick, "두 번째 등용 = 확정 없음");
// 흐름이 아닌 세이브 = 확정 없음 · 키를 지운 표와 같은 결과(예전 규칙 그대로)
var plain = HeroRules.NewSave(Db, Cfg.playerSpawnPoints.Length, T0);
var a = GachaRules.Draw(Db, plain, b, 1, new System.Random(Seed), T0);
Assert.IsFalse(a[0].fixedPick);
var entries = g.values.entries;
var entry = entries.Find(x => x.key == "first_pull_hero");
Assert.IsNotNull(entry);
entries.Remove(entry);
try
{
var flow = HeroRules.NewSave(Db, Cfg.playerSpawnPoints.Length, T0);
flow.firstFlow.started = true;
var c = GachaRules.Draw(Db, flow, b, 1, new System.Random(Seed), T0);
Assert.AreEqual(a[0].heroId, c[0].heroId, "키 없음 = 확률 그대로");
Assert.IsFalse(c[0].fixedPick);
}
finally
{
entries.Add(entry);
}
}
// ---------- 새 세이브 = 전체 흐름 ----------
[UnityTest]
public IEnumerator NewSave_FullFlow()
{
yield return Boot(true, true);
var flow = og.Flow;
Assert.IsTrue(flow.Active, "새 세이브 = 첫 실행 흐름");
Assert.AreEqual(0, Save.heroes.Count, "새 유저 = 영웅 없음(서장 보상 · 등용으로 얻음)");
Assert.IsNotNull(IntroScreen.Current, "타이틀 뒤 = 인트로");
Assert.IsFalse(og.LobbyVisible, "로비를 띄우지 않음");
IntroScreen.Current.Tap();
Assert.AreEqual(1, IntroScreen.Current.CutIndex, "터치 = 다음 장");
IntroScreen.Current.Skip();
yield return Until(() => IntroScreen.Current == null, 3f, "인트로 끝");
Assert.IsTrue(Save.firstFlow.intro);
// 서장: 1 → 2막 = 결과 화면 없이 이어짐 · 3막 = 결과 화면(유비 획득) → 닫으면 본영(유비만 편성)
for (int act = 1; act <= PrologueActs; act++) yield return WinAct(act);
Assert.AreEqual(BattlePhase.StageClear, bm.Phase, "마지막 막 = 결과 화면");
Assert.IsTrue(og.ResultVisible);
Assert.IsTrue(Save.Owns(Victim), "서장 보상 = 영웅 획득");
Assert.AreEqual(Db.Heroes.Get(Victim).rarity, Save.Hero(Victim).star, "별 = 태생 희귀도");
Assert.AreEqual(1, Save.heroes.Count);
Assert.IsTrue(og.Session.LastMode.lines.Exists(x => x.Contains(Db.Heroes.Get(Victim).nameKo)), "결과 화면에 획득 알림");
bm.ContinueAfterResult();
yield return Until(() => og.LobbyVisible, 3f, "결과 화면을 닫으면 본영 로비");
var slots = Save.ActivePreset.slots;
Assert.AreEqual(Victim, slots[0], "로비 = 유비만 배치");
Assert.AreEqual(1, slots.FindAll(x => !string.IsNullOrEmpty(x)).Count);
// 줄 1 ~ 3 = 여인의 인사 · 줄 4 = 「등용」 · 줄 5 = 「1회 등용」(무료 · 가신)
yield return UntilLine(1);
Assert.AreEqual(FirstFlowData.Talk, flow.Guide.Mode);
Assert.AreEqual(FirstFlowData.T("ff_name_helper"), flow.Guide.SpeakerName);
Assert.IsTrue(flow.Guide.PortraitShown);
for (int n = 1; n <= 3; n++)
{
yield return UntilLine(n);
yield return TapLine();
}
yield return UntilLine(4);
Assert.AreEqual(FirstFlowData.Press, flow.Guide.Mode);
Assert.IsTrue(flow.Guide.FingerShown);
yield return TapLine();
Assert.AreEqual(4, flow.Current.step, "누르기 줄 = 화면을 눌러도 넘어가지 않음");
Assert.IsTrue(flow.PressTargetForTest());
Assert.AreEqual(og.Trade, og.Current, "명장 등용 화면");
yield return UntilLine(5);
Assert.AreEqual(FirstFlowData.Arg(FirstFlowData.LineOf(5).onShow, FirstFlowData.OnShowBanner), og.Trade.Banner.id, "표가 정한 등용 쪽");
int gem = Save.gem;
Assert.IsTrue(flow.PressTargetForTest());
Assert.AreEqual(1, og.Trade.LastPulls.Count, "1회 등용");
Assert.AreEqual(Retainer, og.Trade.LastPulls[0].heroId, "가신 확정");
Assert.AreEqual(gem, Save.gem, "무료");
Assert.IsTrue(Save.Owns(Retainer));
Assert.AreEqual(2, Save.heroes.Count, "보유 = 유비 + 가신");
Assert.AreEqual(5, Save.firstFlow.line);
yield return null;
yield return null;
Assert.IsNull(flow.Current, "뽑기 연출 동안 대사 없음");
og.Trade.RevealAll();
og.Trade.CloseResult();
// 줄 6 = 가신의 한마디 · 줄 7 = 편성 안내 → 본영 · 줄 8 = 「편성」 · 줄 9 = 가신 카드(세우고 저장) · 줄 10 = 여인(PD 원문) → 본영 · 줄 11 = 「출정」
yield return UntilLine(6);
Assert.AreEqual(Db.Heroes.Get(Retainer).nameKo, flow.Guide.SpeakerName);
yield return TapLine();
yield return UntilLine(7);
yield return TapLine();
yield return UntilLine(8);
Assert.IsTrue(og.LobbyVisible);
Assert.IsTrue(flow.PressTargetForTest());
Assert.AreEqual(og.Formation, og.Current, "편성 화면");
yield return UntilLine(9);
Assert.IsFalse(Save.ActivePreset.slots.Contains(Retainer));
Assert.IsTrue(flow.PressTargetForTest());
Assert.IsTrue(Save.ActivePreset.slots.Contains(Retainer), "가신을 세운 편성이 저장됨");
Assert.IsTrue(Save.ActivePreset.slots.Contains(Victim));
yield return UntilLine(10);
yield return TapLine();
yield return UntilLine(11);
Assert.IsTrue(og.LobbyVisible, "대사 뒤 스스로 본영 로비");
Assert.IsTrue(flow.PressTargetForTest());
Assert.IsTrue(og.Map.IsVisible, "월드맵");
// 출정 1-1(유비 + 가신) — 스킬 튜토리얼: 적 대사 → 유비 스킬 안내 → 모인 적 일격(유비 체력 50 %) → 가신 대사 · 회복 안내 → 자유 플레이 → 승리
int ch, st;
Assert.IsTrue(FirstFlowData.ParseStage(FirstFlowData.Str("sortie_stage"), out ch, out st));
og.Map.Show(ch - 1);
og.Map.OpenPopup(st - 1);
og.Map.ConfirmPopup();
yield return null;
var so = flow.Sortie;
Assert.AreEqual(FirstFlowSortie.Step.Intro, so.State, "그 스테이지 첫 진입 = 튜토리얼");
Assert.AreEqual(FirstFlowData.List("sortie_cluster").Length, so.Cluster.Count, "적 셋을 유비 앞에 모아 놓음");
Assert.AreEqual(2, bm.AliveUnits(Faction.Player).Count, "출전 = 유비 + 가신");
float t0 = Time.realtimeSinceStartup;
while (so.State != FirstFlowSortie.Step.SkillGuide && Time.realtimeSinceStartup - t0 < 20f)
{
so.TapForTest(); // 말풍선 · 안내 카드 넘김
yield return null;
}
Assert.AreEqual(FirstFlowSortie.Step.SkillGuide, so.State, "대사 뒤 유비 스킬 안내");
Assert.AreEqual(BattlePhase.PlayerTurn, bm.Phase);
var victim = so.Victim;
var retainer = so.Retainer;
Assert.AreEqual(Victim, victim.HeroId);
Assert.AreEqual(Retainer, retainer.HeroId);
yield return null;
Assert.AreEqual(FirstFlowData.T("ff_sortie_bar_skill"), so.Bar, "유비가 골라진 채 = 스킬 버튼 안내");
bm.Skills.TapActive(victim);
Assert.IsTrue(bm.Skills.Of(victim).Reserved, "유비 스킬");
yield return null;
Assert.AreEqual(FirstFlowData.T("ff_sortie_bar_attack"), so.Bar);
int foes = bm.AliveUnits(Faction.Enemy).Count, group = so.Cluster.Count;
yield return bm.ResolveForTest(victim, so.Cluster[1].Position, false, new ActionOutcome());
yield return new WaitForSeconds(0.3f);
Assert.AreEqual(foes - group, bm.AliveUnits(Faction.Enemy).Count, "모여 있던 적 = 한 번에 쓰러짐");
Assert.AreEqual(Mathf.Max(1, Mathf.RoundToInt(victim.MaxHp * FirstFlowData.Num("sortie_hp_pct"))), victim.Hp, "유비 체력 = 표의 비율");
t0 = Time.realtimeSinceStartup;
while (so.State != FirstFlowSortie.Step.HealGuide && Time.realtimeSinceStartup - t0 < 20f)
{
so.TapForTest(); // 가신 대사 · 안내 카드 넘김
yield return null;
}
Assert.AreEqual(FirstFlowSortie.Step.HealGuide, so.State, "가신 대사 뒤 회복 안내");
Assert.AreEqual(BattlePhase.PlayerTurn, bm.Phase);
Assert.IsTrue(bm.CanAct(retainer), "가신 행동 가능");
int half = victim.Hp;
yield return null;
Assert.AreEqual(FirstFlowData.T("ff_sortie_bar_skill"), so.Bar, "가신이 골라진 채 = 스킬 버튼 안내");
bm.Skills.TapActive(retainer);
Assert.IsTrue(bm.Skills.Of(retainer).Reserved, "가신 스킬");
yield return null;
Assert.AreEqual(FirstFlowData.T("ff_sortie_bar_aim").Replace("{0}", victim.DisplayName), so.Bar);
yield return bm.ResolveForTest(retainer, victim.Position, false, new ActionOutcome());
yield return new WaitForSeconds(0.3f);
Assert.Greater(victim.Hp, half, "가신의 스킬 = 아군 회복");
Assert.AreEqual(FirstFlowSortie.Step.Done, so.State, "안내 끝 = 자유 플레이");
Assert.AreEqual("", so.Bar);
Assert.Greater(bm.AliveUnits(Faction.Enemy).Count, 0, "남은 적 = 유저가 섬멸");
KillEnemies();
yield return Until(() => bm.Phase == BattlePhase.StageClear && og.ResultVisible, 8f, "섬멸 = 승리 · 결과 화면");
Assert.AreEqual(1, Save.Stage(ch, st, false).clears);
bm.ContinueAfterResult();
// 줄 12 = 가신의 진언 → 본영 · 줄 13 = 「군영」 · 줄 14 ~ 20 = 군영 소개(장소로 화면을 옮겨 가리킴)
yield return UntilLine(12);
Assert.AreEqual(Db.Heroes.Get(Retainer).nameKo, flow.Guide.SpeakerName);
yield return TapLine();
yield return UntilLine(13);
Assert.IsTrue(og.LobbyVisible);
Assert.IsTrue(flow.PressTargetForTest());
Assert.AreEqual(og.Arena, og.Current, "군영 화면");
for (int n = 14; n <= FirstFlowData.LastStep; n++)
{
yield return UntilLine(n);
var l = FirstFlowData.LineOf(n);
Assert.AreEqual(l.mode, flow.Guide.Mode, "줄 " + n + " 방식");
if (l.mode == FirstFlowData.Point)
{
Assert.IsNotNull(flow.Guide.Hole, "줄 " + n + " 장소만 밝게");
Assert.IsFalse(flow.PressTargetForTest(), "가리키기 = 누르게 하지 않음");
Assert.IsFalse(og.Arena.Hub.Fitter.Focusing, "화면이 옮겨 간 뒤 가리킴");
// 밝게 남긴 칸 = 화면을 옮긴 뒤의 그 장소 자리(장소 가운데가 화면 안 · 칸 안)
yield return null;
string spot = FirstFlowData.Arg(l.onShow, FirstFlowData.OnShowFocus);
Assert.IsNotNull(spot, "줄 " + n + " 장소 포커스");
RectTransform press = null;
foreach (var rt in og.Arena.Rt.GetComponentsInChildren(false))
if (rt.name == "Press_" + spot) press = rt;
Assert.IsNotNull(press);
var groot = (RectTransform)flow.Guide.transform;
var c = RectTransformUtility.CalculateRelativeRectTransformBounds(groot, press).center;
Assert.IsTrue(flow.Guide.Hole.Value.Contains(new Vector2(c.x, c.y)), "줄 " + n + " 밝은 칸이 그 장소 위");
Assert.IsTrue(groot.rect.Contains(new Vector2(c.x, c.y)), "줄 " + n + " 장소가 화면 안");
}
yield return TapLine();
}
yield return Until(() => Save.firstFlow.done, 3f, "끝 기록");
Assert.IsFalse(flow.Active);
Assert.IsFalse(flow.Guide.Shown);
}
// ---------- 흐름에 들어가지 않는 세이브 ----------
[UnityTest]
public IEnumerator MemorySave_SkipsFlow_LobbyInTwoFrames_KeepsStartHeroes()
{
yield return Boot(true, false);
Assert.IsTrue(og.LobbyVisible, "메모리 세이브 = 지금처럼 로비");
Assert.IsNull(IntroScreen.Current);
Assert.IsFalse(og.Flow.Available);
Assert.IsFalse(Save.firstFlow.started);
Assert.AreEqual(og.Session.Db.Economy.StartHeroes.Length, Save.heroes.Count, "흐름이 아닌 새 세이브 = 시작 영웅 그대로");
}
[UnityTest]
public IEnumerator PrologueDoneSave_GoesLobby_NoFlow()
{
yield return Boot(true, false);
ClearPrologue();
og.Session.Commit();
yield return Boot(false, true);
Assert.IsTrue(og.LobbyVisible, "서장을 끝낸 세이브 = 로비");
Assert.IsNull(IntroScreen.Current);
Assert.IsFalse(og.Flow.Active, "흐름에 들어가지 않음");
Assert.IsFalse(Save.firstFlow.started);
yield return new WaitForSecondsRealtime(1.2f);
Assert.IsTrue(og.Flow.Guide == null || !og.Flow.Guide.Shown, "대사 없음");
}
// ---------- 도중 종료 뒤 이어서 ----------
[UnityTest]
public IEnumerator Resume_MidPrologue_NextUnwonAct_NoIntroAgain()
{
yield return Boot(true, true);
IntroScreen.Current.Skip();
yield return Until(() => IntroScreen.Current == null && Rules != null, 3f, "1막 시작");
Assert.AreEqual(1, Rules.Act);
yield return Boot(false, true); // 1막 도중에 끔 → 다시 켬
Assert.IsNull(IntroScreen.Current, "인트로는 다시 나오지 않음");
Assert.AreEqual(1, Rules.Act, "아직 이기지 못한 첫 막");
Assert.AreEqual(0, Save.heroes.Count, "영웅 없음 그대로");
yield return WinAct(1);
yield return Until(() => Rules != null && Rules.Act == 2 && !og.Flow.Switching, 6f, "2막");
yield return Boot(false, true); // 2막 도중에 끔 → 다시 켬
Assert.IsNull(IntroScreen.Current);
Assert.AreEqual(2, Rules.Act);
}
[UnityTest]
public IEnumerator Resume_Lines_NextLine_GateLine_WaitForStage()
{
yield return BootAtLine(2);
Assert.IsTrue(og.LobbyVisible);
yield return UntilLine(3);
// 줄 5(명장 등용 화면)가 남은 채 본영 로비 = 그 화면으로 이끄는 줄(n_gate)을 다시 보여 줌 · 기록은 그대로
var l5 = FirstFlowData.LineOf(5);
Save.firstFlow.line = 4;
og.Session.Commit();
yield return Boot(false, true);
yield return UntilLine(l5.gate);
Assert.AreEqual(4, Save.firstFlow.line);
Assert.IsTrue(og.Flow.PressTargetForTest());
yield return UntilLine(5);
Assert.AreEqual(4, Save.firstFlow.line, "다시 보여 준 줄은 기록을 바꾸지 않음");
// 1-1 을 이긴 뒤에만 나오는 줄(s_wait)
var waitLine = FirstFlowData.Lines.Find(x => x.wait.Length > 0);
int ch, st;
FirstFlowData.ParseStage(FirstFlowData.Arg(waitLine.wait, FirstFlowData.WaitStageClear), out ch, out st);
Save.firstFlow.line = waitLine.step - 1;
og.Session.Commit();
yield return Boot(false, true);
yield return new WaitForSecondsRealtime(1.2f);
Assert.IsNull(og.Flow.Current, "1-1 을 이기기 전 = 대사 없음(여인의 배웅을 다시 하지 않음)");
Save.Stage(ch, st, true).clears = 1;
yield return UntilLine(waitLine.step);
}
/// 첫 등용을 이미 한 세이브 = 등용 줄을 건너뜀 · 가신이 이미 편성에 있는 세이브 = 편성 안내 줄을 건너뜀.
[UnityTest]
public IEnumerator Skips_FirstPullDone_RetainerPlaced()
{
var l4 = FirstFlowData.LineOf(4);
yield return BootAtLine(3, d => d.gacha.total = 1);
yield return UntilLine(l4.skipTo);
Assert.IsTrue(og.LobbyVisible, "등용 화면으로 보내지 않음");
var l7 = FirstFlowData.Lines.Find(x => x.skipIf == FirstFlowData.SkipRetainerPlaced);
yield return BootAtLine(l7.step - 1, d =>
{
d.gacha.total = 1;
HeroRules.Grant(Db, d, Db.Heroes.Get(Retainer), HeroRules.GearSlotCount(Db));
d.ActivePreset.slots[d.ActivePreset.slots.Count - 1] = Retainer;
});
yield return UntilLine(l7.skipTo);
Assert.IsTrue(og.LobbyVisible, "편성 화면으로 보내지 않음");
}
// ---------- 복병 조건 · 군영 스크롤 ----------
/// 출정 1-1 스킬 튜토리얼 = 가신이 판에 없으면 나오지 않음(지금 그대로) · 그 스테이지를 이미 깬 세이브도 나오지 않음(적 자리도 그대로).
[UnityTest]
public IEnumerator SortieTutorial_NotWithoutRetainer_NotAfterFirstClear()
{
int ch, st;
FirstFlowData.ParseStage(FirstFlowData.Str("sortie_stage"), out ch, out st);
yield return Boot(true, false);
FirstFlow.ForceOn = true; // 흐름은 켜되 시작 영웅 편성(가신 없음)
og.OpenWorldMap();
og.Map.Show(ch - 1);
og.Map.OpenPopup(st - 1);
og.Map.ConfirmPopup();
yield return null;
Assert.AreEqual(FirstFlowSortie.Step.Off, og.Flow.Sortie.State, "가신이 없으면 튜토리얼 없음");
yield return UntilPlayerTurn();
KillEnemies();
Assert.AreEqual(BattlePhase.StageClear, bm.Phase);
yield return null;
bm.ContinueAfterResult();
yield return null;
// 가신을 편성해도 이미 깬 스테이지 = 튜토리얼 없음
HeroRules.Grant(Db, Save, Db.Heroes.Get(Retainer), HeroRules.GearSlotCount(Db));
Save.ActivePreset.slots[Save.ActivePreset.slots.Count - 1] = Retainer;
og.Map.Show(ch - 1);
og.Map.OpenPopup(st - 1);
og.Map.ConfirmPopup();
yield return null;
Assert.AreEqual(FirstFlowSortie.Step.Off, og.Flow.Sortie.State, "처음 깨기 전에만");
Assert.AreEqual(0, og.Flow.Sortie.Cluster.Count);
}
/// 군영 화면 = 그림이 화면보다 큰 쪽(가로 · 세로)만 끌어서 볼 수 있음 · 장소 포커스 = 그 장소가 화면 가운데 쪽으로(그림 밖이 비지 않게).
[UnityTest]
public IEnumerator CampHub_ScrollsBothAxesWhenLarger_FocusMovesToSpot()
{
yield return Boot(true, false);
og.Arena.SetPage(0);
og.Show(og.Arena);
yield return null;
var hub = og.Arena.Hub;
Assert.IsTrue(og.Arena.HubVisible);
var fit = hub.Fitter;
var view = ((RectTransform)fit.transform).rect;
var size = hub.Content.sizeDelta * fit.Zoom;
Assert.AreEqual(size.x > view.width + 1f, hub.Scroll.horizontal, "가로 = 그림이 더 넓을 때만");
Assert.AreEqual(size.y > view.height + 1f, hub.Scroll.vertical, "세로 = 그림이 더 높을 때만");
float mx = Mathf.Max(0f, (size.x - view.width) * 0.5f), my = Mathf.Max(0f, (size.y - view.height) * 0.5f);
// 끝까지 끌기 = 그림 여백 끝까지
hub.Scroll.normalizedPosition = new Vector2(0f, 0f);
yield return null;
Assert.AreEqual(mx, hub.Content.anchoredPosition.x, 1f, "왼쪽 끝");
Assert.AreEqual(my, hub.Content.anchoredPosition.y, 1f, "아래 끝");
hub.Scroll.normalizedPosition = new Vector2(1f, 1f);
yield return null;
Assert.AreEqual(-mx, hub.Content.anchoredPosition.x, 1f, "오른쪽 끝");
Assert.AreEqual(-my, hub.Content.anchoredPosition.y, 1f, "위 끝");
foreach (var s in hub.Spots)
{
if (s.pressSize.x <= 0f) continue;
Assert.IsTrue(hub.Focus(s.id, 0f));
var p = hub.Content.anchoredPosition;
Assert.AreEqual(fit.PositionFor(s.press), p);
Assert.LessOrEqual(Mathf.Abs(p.x), mx + 0.5f, s.id + " 그림 밖이 비지 않음");
Assert.LessOrEqual(Mathf.Abs(p.y), my + 0.5f);
}
}
// ---------- 패배 · 연의 전기 화면의 서장 ----------
[UnityTest]
public IEnumerator Defeat_RestartsSameAct_NotScenarioScreen()
{
yield return Boot(true, true);
IntroScreen.Current.Skip();
yield return Until(() => IntroScreen.Current == null && Rules != null, 3f, "1막 시작");
yield return UntilPlayerTurn();
var hud = UnityEngine.Object.FindFirstObjectByType(FindObjectsInactive.Include);
hud.OpenGiveUp();
hud.ConfirmGiveUp();
Assert.AreEqual(BattlePhase.Defeat, bm.Phase, "포기 = 패배(지금 그대로)");
yield return null;
Assert.IsTrue(og.ResultVisible, "패배 결과 창");
var first = Rules;
bm.ContinueAfterResult();
yield return null;
Assert.IsNotNull(Rules, "그 막을 처음부터 다시");
Assert.AreNotSame(first, Rules);
Assert.AreEqual(1, Rules.Act);
Assert.IsFalse(og.ScreensVisible, "연의 전기 화면으로 나가지 않음");
}
/// 연의 전기 화면에서 여는 서장(막 버튼) = 막 승리 → 결과 화면(지금 그대로 · 흐름이 켜져 있어도) · 이미 유비를 가진 세이브의 서장 보상 = 조각(지금 그대로).
[UnityTest]
public IEnumerator ScenarioScreenPrologue_ActWin_StillShowsResult_OwnedHeroGetsShards()
{
yield return Boot(true, false);
int shards = Save.Hero(Victim).shards;
ClearPrologue();
Assert.Greater(Save.Hero(Victim).shards, shards, "이미 보유 = 조각");
og.Session.Commit();
yield return Boot(false, true);
og.Show(og.Arena);
og.Arena.SetPage(ArenaScreen.ScenarioPage);
yield return null;
og.Arena.Scenario.SetTab("p1_a");
og.Arena.Scenario.Open(PrologueId, true);
yield return null;
og.Arena.Scenario.GoAct(PrologueId, 1); // 막 버튼 ①
yield return null;
Assert.IsNotNull(Rules, "연의 전기 화면에서 연 서장 1막");
Assert.IsNull(Rules.WinContinue, "연의 전기 화면의 막 = 흐름 아님");
yield return UntilPlayerTurn();
KillEnemies();
yield return null;
float t0 = Time.realtimeSinceStartup;
while (bm.Phase != BattlePhase.StageClear && Time.realtimeSinceStartup - t0 < 12f)
{
if (ScenarioEvent.Running) ScenarioEvent.SkipForTest();
yield return null;
}
Assert.AreEqual(BattlePhase.StageClear, bm.Phase, "막 승리 = 결과 단계");
yield return null;
Assert.IsTrue(og.ResultVisible, "결과 화면");
Assert.AreEqual(1, Rules.Act, "다음 막으로 자동으로 넘어가지 않음");
}
/// 화면 확인용 캡처(Explicit) → Logs/firstflow/sortie_*.png — 출정 1-1 스킬 튜토리얼(말풍선 · 안내 카드 · 안내 띠와 강조).
[UnityTest, Explicit]
public IEnumerator Capture_Sortie()
{
string dir = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.dataPath), "Logs", "firstflow");
Func shot = name => CaptureUtil.Capture(Camera.main, 540, 960, System.IO.Path.Combine(dir, name + ".png"));
int ch, st;
FirstFlowData.ParseStage(FirstFlowData.Str("sortie_stage"), out ch, out st);
yield return BootAtLine(11, d =>
{
d.gacha.total = 1;
d.heroes.RemoveAll(h => h.id != Victim);
HeroRules.Grant(Db, d, Db.Heroes.Get(Retainer), HeroRules.GearSlotCount(Db));
HeroRules.Sanitize(Db, d, Cfg.playerSpawnPoints.Length);
d.ActivePreset.slots[1] = Retainer;
});
og.OpenWorldMap();
og.Map.Show(ch - 1);
og.Map.OpenPopup(st - 1);
og.Map.ConfirmPopup();
yield return null;
var so = og.Flow.Sortie;
for (int i = 1; i <= 5 && so.State == FirstFlowSortie.Step.Intro; i++)
{
yield return new WaitForSecondsRealtime(1.6f);
if (so.State != FirstFlowSortie.Step.Intro) break;
yield return shot("sortie_intro_" + i);
so.TapForTest();
yield return null;
so.TapForTest();
}
yield return Until(() => so.State == FirstFlowSortie.Step.SkillGuide, 10f, "유비 스킬 안내");
yield return new WaitForSecondsRealtime(0.5f);
yield return shot("sortie_guide_1_skill");
bm.Skills.TapActive(so.Victim);
yield return new WaitForSecondsRealtime(0.3f);
yield return shot("sortie_guide_2_attack");
yield return bm.ResolveForTest(so.Victim, so.Cluster[1].Position, false, new ActionOutcome());
for (int i = 1; i <= 4 && so.State != FirstFlowSortie.Step.HealGuide; i++)
{
yield return new WaitForSecondsRealtime(1.6f);
if (so.State == FirstFlowSortie.Step.HealGuide) break;
yield return shot("sortie_retainer_" + i);
so.TapForTest();
yield return null;
so.TapForTest();
}
yield return Until(() => so.State == FirstFlowSortie.Step.HealGuide, 10f, "가신 회복 안내");
yield return new WaitForSecondsRealtime(0.5f);
yield return shot("sortie_guide_3_heal_skill");
bm.Skills.TapActive(so.Retainer);
yield return new WaitForSecondsRealtime(0.3f);
yield return shot("sortie_guide_4_heal_aim");
}
/// 화면 확인용 캡처(Explicit) → Logs/firstflow/*.png — 대사 줄(말하기 · 누르기 · 가리키기) 배치를 눈으로 본다.
[UnityTest, Explicit]
public IEnumerator Capture_Screens()
{
string dir = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.dataPath), "Logs", "firstflow");
Func shot = name => CaptureUtil.Capture(Camera.main, 540, 960, System.IO.Path.Combine(dir, name + ".png"));
yield return BootAtLine(0, d =>
{
d.heroes.RemoveAll(h => h.id != Victim);
HeroRules.Sanitize(Db, d, Cfg.playerSpawnPoints.Length);
});
var flow = og.Flow;
for (int n = 1; n <= FirstFlowData.LastStep; n++)
{
var l = FirstFlowData.LineOf(n);
if (l.wait.Length > 0)
{
int ch, st;
FirstFlowData.ParseStage(FirstFlowData.Arg(l.wait, FirstFlowData.WaitStageClear), out ch, out st);
Save.Stage(ch, st, true).clears = 1;
og.ShowLobby();
}
yield return UntilLine(n);
flow.TapForTest(); // 대사 전부 표시
yield return new WaitForSecondsRealtime(0.25f);
yield return shot("line_" + n.ToString("00") + "_" + l.mode);
if (flow.Guide.Mode == FirstFlowData.Press)
{
Assert.IsTrue(flow.PressTargetForTest());
if (og.Trade.ResultVisible)
{
og.Trade.RevealAll();
og.Trade.CloseResult();
}
}
else flow.TapForTest();
yield return null;
}
}
}
}