408 lines
19 KiB
C#
408 lines
19 KiB
C#
using System.Collections;
|
||
using NUnit.Framework;
|
||
using TKS.OutGame;
|
||
using UnityEngine;
|
||
using UnityEngine.SceneManagement;
|
||
using UnityEngine.TestTools;
|
||
|
||
namespace TKS.Tests
|
||
{
|
||
/// <summary>
|
||
/// 1장 학습 판(개발 요청서 C5 · 2026-11-12) — 고정 편성 · 배치 표 · 구출 대상 · 턴 제한 · 안내 진행 + 기획 세션이 손으로 계산한 배치 5건(1-2 · 1-5 · 1-6 · 1-7 · 1-8)을 실제 규칙으로 확인.
|
||
/// 다른 테스트는 메모리 세이브라 학습 판이 꺼져 있다(TutorialRules.Mode Auto) — 여기서만 ForceOn. 값은 표·자산에서 읽는다(C45).
|
||
/// </summary>
|
||
public class TutorialTests
|
||
{
|
||
BattleManager bm;
|
||
BalanceConfig cfg;
|
||
|
||
[UnitySetUp]
|
||
public IEnumerator SetUp()
|
||
{
|
||
WorldProgress.Reset();
|
||
SaveStore.UseMemory(true);
|
||
SceneManager.LoadScene("Battle");
|
||
yield return null;
|
||
yield return null;
|
||
bm = BattleManager.Instance;
|
||
Assert.IsNotNull(bm);
|
||
cfg = bm.Config;
|
||
Assert.IsNotNull(TutorialTables.Db, "TutorialDb(TKS/Import Tutorial)");
|
||
TutorialRules.Mode = TutorialMode.ForceOn;
|
||
Time.timeScale = 20f;
|
||
}
|
||
|
||
[UnityTearDown]
|
||
public IEnumerator TearDown()
|
||
{
|
||
TutorialRules.Mode = TutorialMode.Auto;
|
||
Time.timeScale = 1f;
|
||
yield return null;
|
||
}
|
||
|
||
/// <summary>1장 n 번 판 시작(보스 판 = 등장 연출을 끊고 바로 아군 차례).</summary>
|
||
IEnumerator Enter(int stage)
|
||
{
|
||
int idx = -1;
|
||
for (int i = 0; i < cfg.stages.Length; i++)
|
||
if (cfg.stages[i].chapter == 1 && cfg.stages[i].stage == stage) idx = i;
|
||
Assert.GreaterOrEqual(idx, 0, "1-" + stage);
|
||
var hud = Object.FindFirstObjectByType<BattleHUD>(FindObjectsInactive.Include);
|
||
if (hud != null) hud.gameObject.SetActive(true);
|
||
bm.StartStage(idx);
|
||
yield return null;
|
||
if (bm.Phase == BattlePhase.Setup)
|
||
{
|
||
BossIntro.Abort();
|
||
bm.ForcePhase(BattlePhase.PlayerTurn);
|
||
}
|
||
yield return null;
|
||
Assert.IsNotNull(bm.Tutorial, "1-" + stage + " 학습 판 계획");
|
||
}
|
||
|
||
Unit Slot(int slot)
|
||
{
|
||
var u = bm.Tutorial.UnitAt(slot);
|
||
Assert.IsNotNull(u, "슬롯 " + slot + " 유닛");
|
||
return u;
|
||
}
|
||
|
||
/// <summary>u 를 dir 방향으로 최대 당김 × pull 만큼 쏘고 행동이 끝날 때까지 기다린다.</summary>
|
||
IEnumerator Shoot(Unit u, Vector2 dir, float pull)
|
||
{
|
||
Vector2 target = bm.Board.ClampInside(u.Position + dir.normalized * SkillMods.SlingMax(u) * pull, u.Radius);
|
||
Assert.IsTrue(bm.RequestPlayerAction(u, target), u.DisplayName + " 행동 시작");
|
||
float t0 = Time.realtimeSinceStartup;
|
||
while (bm.Phase == BattlePhase.Resolving && Time.realtimeSinceStartup - t0 < 30f) yield return null;
|
||
Assert.AreNotEqual(BattlePhase.Resolving, bm.Phase, "행동이 끝나지 않음");
|
||
}
|
||
|
||
float Cfg(string key)
|
||
{
|
||
Assert.IsTrue(TutorialTables.Db.Has(key), "tutorial_config " + key);
|
||
return TutorialTables.Db.Num(key, 0f);
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator Stage1_1_FixedLineup_Layout_Npc_NoDefeat()
|
||
{
|
||
yield return Enter(1);
|
||
var row = bm.Tutorial.Row;
|
||
Assert.AreEqual(row.lineup.Length, bm.Deployed.Count, "고정 편성 = 표의 영웅 수");
|
||
Assert.AreEqual(row.lineup[0], bm.Deployed[0].id);
|
||
int enemies = 0, npcs = 0;
|
||
foreach (var l in bm.Tutorial.Layout)
|
||
{
|
||
if (l.side == TutSide.Gimmick) continue;
|
||
var u = Slot(l.slot);
|
||
Assert.Less(Vector2.Distance(u.Position, l.pos), 0.01f, "슬롯 " + l.slot + " 자리 = 배치 표");
|
||
if (l.side == TutSide.Enemy) enemies++;
|
||
if (l.side == TutSide.Npc)
|
||
{
|
||
npcs++;
|
||
Assert.IsTrue(u.Npc);
|
||
Assert.AreEqual(Faction.Player, u.Faction);
|
||
Assert.IsFalse(bm.CanAct(u), "구출 대상 = 조작 불가");
|
||
u.TakeDamage(u.MaxHp * 10);
|
||
Assert.IsTrue(u.IsAlive, "b_no_defeat = 쓰러지지 않음");
|
||
Assert.AreEqual(Mathf.RoundToInt(Cfg("npc_guard_hp")), u.Hp);
|
||
}
|
||
}
|
||
Assert.AreEqual(row.npcs.Length, npcs);
|
||
Assert.AreEqual(enemies, bm.AliveCount(Faction.Enemy));
|
||
Assert.AreEqual(bm.Stage.enemies.Count, enemies, "배치 표 적 수 = stages.csv 행");
|
||
Assert.AreEqual(0, bm.TurnLimit);
|
||
// 구출 대상은 반격하지 않는다
|
||
var npc = Slot(3);
|
||
var foe = Slot(4);
|
||
Assert.AreEqual(0, Combat.CounterDamage(cfg, npc, foe, bm.Rng), "구출 대상 반격 없음");
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator Stage1_1_Guide_Popup_Drag_AimHint_ThenBar()
|
||
{
|
||
yield return Enter(1);
|
||
var d = TutorialDirector.Current;
|
||
Assert.IsNotNull(d);
|
||
yield return null;
|
||
Assert.IsTrue(d.GuideOn);
|
||
var steps = TutorialTables.Db.Guide(1, 1);
|
||
Assert.IsNotNull(d.ActiveStep, "첫 단계");
|
||
Assert.AreEqual(steps[0].step, d.ActiveStep.step);
|
||
Assert.AreEqual(GuideMode.Popup, d.ActiveStep.mode);
|
||
Assert.IsTrue(d.Ui.CardVisible);
|
||
Assert.AreEqual(steps[0].textKo, d.Ui.CardText);
|
||
Assert.IsTrue(d.BlocksInput, "카드 = 전장 조작 막음");
|
||
|
||
d.TapForTest();
|
||
yield return null;
|
||
Assert.AreEqual(steps[1].step, d.ActiveStep.step, "카드 닫힘 → 끌기 안내");
|
||
Assert.AreEqual(GuideMode.Drag, d.ActiveStep.mode);
|
||
yield return null;
|
||
Assert.IsTrue(d.Ui.FingerVisible, "손가락");
|
||
var liubei = Slot(1);
|
||
var foe = Slot(2);
|
||
Assert.IsTrue(d.Locked);
|
||
Assert.IsFalse(d.AllowPress(new Vector2(-9999f, -9999f), null), "잠금 = 다른 곳 누름 불가");
|
||
Assert.IsTrue(d.AllowPress(new Vector2(-9999f, -9999f), liubei));
|
||
// 목표 반대쪽으로는 발사 불가 · 목표 쪽 + 충분히 당김 = 발사
|
||
Vector2 away = liubei.Position - (foe.Position - liubei.Position).normalized * SkillMods.SlingMax(liubei);
|
||
Assert.IsFalse(d.AllowShot(liubei, away));
|
||
float max = SkillMods.SlingMax(liubei);
|
||
Vector2 near = liubei.Position + (foe.Position - liubei.Position).normalized * max * Cfg("drag_lock_min_pull") * 0.5f;
|
||
Assert.AreEqual(near, d.SnapAim(liubei, near), "덜 당김 = 맞추지 않음");
|
||
Assert.IsFalse(d.AllowShot(liubei, near), "덜 당김 = 발사 불가");
|
||
// 비스듬히 · 최소 당김보다 조금 더 = 목표 방향 · 정해진 세기로 맞춰 발사(화면 아래쪽이라 끝까지 못 당겨도 진행)
|
||
Vector2 skew = liubei.Position + (Vector2)(Quaternion.Euler(0f, 0f, Cfg("drag_lock_angle_deg") * 0.5f) * (foe.Position - liubei.Position).normalized) * max * (Cfg("drag_lock_min_pull") + 0.1f);
|
||
Vector2 snapped = d.SnapAim(liubei, skew);
|
||
Assert.Less(Vector2.Angle(snapped - liubei.Position, foe.Position - liubei.Position), 0.1f, "허용 각도 안 = 목표 방향으로 맞춤");
|
||
Assert.AreEqual(max * Cfg("drag_lock_shot_pull"), Vector2.Distance(snapped, liubei.Position), 0.01f, "발사 세기 = 표의 비율");
|
||
Assert.IsTrue(d.AllowShot(liubei, snapped));
|
||
|
||
// 유닛을 잡으면 조준 안내(다음 단계 문구) · 쏘면 둘 다 끝나고 행동 끝 안내로
|
||
d.OnSelect(liubei);
|
||
Assert.IsNotNull(d.HintStep);
|
||
Assert.AreEqual(steps[2].step, d.HintStep.step);
|
||
Assert.AreEqual(steps[2].textKo, d.Ui.BarText);
|
||
d.OnAimCancelled();
|
||
Assert.IsNull(d.HintStep, "손을 떼면 끌기 안내로");
|
||
Assert.AreEqual(steps[1].textKo, d.Ui.BarText);
|
||
d.OnSelect(liubei);
|
||
yield return Shoot(liubei, foe.Position - liubei.Position, 1f);
|
||
yield return null;
|
||
Assert.IsFalse(foe.IsAlive, "첫 건달 = 한 대에 쓰러짐");
|
||
Assert.IsNotNull(d.ActiveStep, "행동 끝 안내");
|
||
Assert.AreEqual(steps[3].step, d.ActiveStep.step);
|
||
Assert.AreEqual(GuideMode.Bar, d.ActiveStep.mode);
|
||
Assert.IsFalse(d.BlocksInput);
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator Stage1_2_PushAlly_Dash_TurnLimitChip()
|
||
{
|
||
foreach (float pull in Pulls(2))
|
||
{
|
||
yield return Enter(2);
|
||
var d = TutorialDirector.Current;
|
||
Assert.AreEqual(bm.Tutorial.Row.turnLimit, bm.TurnLimit);
|
||
Assert.Greater(bm.TurnLimit, 0);
|
||
Assert.IsTrue(d.Ui.TurnChipVisible, "남은 턴 칩");
|
||
StringAssert.Contains(bm.TurnLimit.ToString(), d.Ui.TurnChipText);
|
||
|
||
var liubei = Slot(1);
|
||
var zhangfei = Slot(2);
|
||
var e4 = Slot(4);
|
||
var e5 = Slot(5);
|
||
var e6 = Slot(6);
|
||
Vector2 before = zhangfei.Position;
|
||
yield return Shoot(liubei, zhangfei.Position - liubei.Position, pull);
|
||
Assert.Greater(zhangfei.Position.y - before.y, 0.5f, "당김 " + pull + ": 장비가 밀려남(" + before + " → " + zhangfei.Position + ")");
|
||
Assert.IsFalse(e4.IsAlive, "당김 " + pull + ": 밀린 장비가 4번 척후에 닿아 그 자리 공격 → 쓰러짐(장비 " + zhangfei.Position + " · 4번 HP " + e4.Hp + ")");
|
||
Assert.IsTrue(bm.CanAct(zhangfei), "밀린 아군은 행동을 쓰지 않는다");
|
||
yield return Shoot(zhangfei, Vector2.up, pull);
|
||
Assert.IsFalse(e5.IsAlive, "당김 " + pull + ": 장비 돌진 한 줄 1(5번 HP " + e5.Hp + ")");
|
||
Assert.IsFalse(e6.IsAlive, "당김 " + pull + ": 장비 돌진 한 줄 2(6번 HP " + e6.Hp + ")");
|
||
}
|
||
}
|
||
|
||
/// <summary>잠금 끌기 안내가 쏘는 세기(tutorial_config drag_lock_shot_pull — 방향이 맞으면 이 세기로 맞춘다).</summary>
|
||
float[] Pulls(int stage)
|
||
{
|
||
string own = "drag_lock_shot_pull_1_" + stage; // 판별 값이 있으면 그 값(TutorialDirector.ShotPull 과 같은 규칙 · 2026-11-16)
|
||
return new[] { TutorialTables.Db.Has(own) ? TutorialTables.Db.Num(own, 0f) : Cfg("drag_lock_shot_pull") };
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator Stage1_2_NpcSurvivesThreeTurns_ThenTurnLimitDefeat()
|
||
{
|
||
yield return Enter(2);
|
||
var guanyu = Slot(3);
|
||
Assert.IsTrue(guanyu.Npc);
|
||
int limit = bm.TurnLimit;
|
||
for (int t = 1; t <= limit && bm.Phase != BattlePhase.Defeat && bm.Phase != BattlePhase.StageClear; t++)
|
||
{
|
||
foreach (var u in bm.AliveUnits(Faction.Player)) u.MarkActed(); // 아군이 아무것도 하지 않는 최악의 경우
|
||
yield return bm.RunEnemyTurn();
|
||
}
|
||
Assert.AreEqual(BattlePhase.Defeat, bm.Phase, "턴 제한 = 실패");
|
||
Assert.IsTrue(guanyu.IsAlive, "관우가 " + limit + "턴을 버틴다(HP " + guanyu.Hp + "/" + guanyu.MaxHp + ")");
|
||
StringAssert.Contains("턴 종료", bm.LastMessage);
|
||
yield return null;
|
||
var d = TutorialDirector.Current;
|
||
Assert.IsTrue(d.Ui.CardVisible, "실패 카드(매번)");
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator Stage1_2_NpcDown_IsDefeat()
|
||
{
|
||
yield return Enter(2);
|
||
var guanyu = Slot(3);
|
||
guanyu.TakeDamage(guanyu.MaxHp * 10);
|
||
Assert.IsFalse(guanyu.IsAlive);
|
||
Assert.IsTrue(bm.CheckBattleEnd());
|
||
Assert.AreEqual(BattlePhase.Defeat, bm.Phase, "구출 대상이 쓰러지면 실패");
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator Stage1_5_BoulderReachesEnemy_AtMinPull()
|
||
{
|
||
foreach (float pull in Pulls(5))
|
||
{
|
||
yield return Enter(5);
|
||
var guanyu = Slot(1);
|
||
var e9 = Slot(9);
|
||
yield return Shoot(guanyu, Vector2.up, pull);
|
||
Assert.Less(e9.Hp, e9.MaxHp, "당김 " + pull + ": 굴러간 바위가 9번 적에 닿음");
|
||
}
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator Stage1_6_InfantryGraze_ChainsToSecondEnemy()
|
||
{
|
||
foreach (float pull in Pulls(6))
|
||
{
|
||
yield return Enter(6);
|
||
var liubei = Slot(1);
|
||
var e4 = Slot(4);
|
||
var e5 = Slot(5);
|
||
var guide = TutorialTables.Db.Guide(1, 6)[0];
|
||
Assert.AreEqual(GuideTargetKind.Drag, guide.Target.kind);
|
||
yield return Shoot(liubei, guide.Target.point - liubei.Position, pull);
|
||
Assert.Less(e5.Hp, e5.MaxHp, "당김 " + pull + ": 5번 적(연쇄 첫째) 피해");
|
||
Assert.Less(e4.Hp, e4.MaxHp, "당김 " + pull + ": 4번 적(꺾여 나가 닿는 둘째) 피해 · 유비 " + liubei.Position);
|
||
}
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator Stage1_7_CavalryPiercesFourInARow_TrapsShown()
|
||
{
|
||
foreach (float pull in Pulls(7))
|
||
{
|
||
yield return Enter(7);
|
||
var zf = Slot(3);
|
||
var last = Slot(7);
|
||
yield return Shoot(zf, last.Position - zf.Position, pull);
|
||
for (int s = 4; s <= 7; s++)
|
||
{
|
||
var e = Slot(s);
|
||
Assert.Less(e.Hp, e.MaxHp, "당김 " + pull + ": " + s + "번 보병 피해(장비 관통 · 장비 " + zf.Position + ")");
|
||
}
|
||
Assert.Less(zf.Position.x, Slot(4).Position.x - zf.Radius, "당김 " + pull + ": 넷을 모두 지나 그 너머에 선다(지날 때마다 거리가 줄어도 · 장비 " + zf.Position + ")");
|
||
}
|
||
int shown = 0;
|
||
foreach (var g in bm.Gimmicks.Items)
|
||
if (g.Zone == GimmickZone.Trap && g.View != null && g.View.Body != null && g.View.Body.gameObject.activeSelf) shown++;
|
||
Assert.AreEqual(2, shown, "이 판은 함정 자리를 보여 준다");
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator Stage1_8_SpearPushesEnemyIntoFire_AtMinPull()
|
||
{
|
||
foreach (float pull in Pulls(8))
|
||
{
|
||
yield return Enter(8);
|
||
var guanyu = Slot(2);
|
||
var e8 = Slot(8);
|
||
Vector2 g0 = guanyu.Position, e0 = e8.Position;
|
||
float sling = SkillMods.SlingMax(guanyu);
|
||
yield return Shoot(guanyu, e8.Position - guanyu.Position, pull);
|
||
GimmickInstance band = null;
|
||
foreach (var g in bm.Gimmicks.Items)
|
||
if (g.Zone == GimmickZone.Burn && g.Shape.Type == GimmickShapeType.Rect) band = g;
|
||
Assert.IsNotNull(band, "불길 띠");
|
||
Assert.IsTrue(!e8.IsAlive || band.Shape.Contains(e8.Position), "당김 " + pull + ": 8번 적이 불길 띠 안에서 멈춤(8번 " + e0 + " → " + e8.Position + " · HP " + e8.Hp + "/" + e8.MaxHp
|
||
+ " · 관우 " + g0 + " → " + guanyu.Position + " · 슬링 " + sling + " · 메시지 " + bm.LastMessage + ")");
|
||
}
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator Stage1_4_MatchupMarks_OnFromConfigStage()
|
||
{
|
||
yield return Enter(3);
|
||
var sling = bm.Sling;
|
||
Assert.IsNotNull(sling.Matchup);
|
||
sling.Matchup.Show(bm, Slot(1));
|
||
Assert.AreEqual(0, sling.Matchup.Count, "1-3 까지는 상성 표시 없음");
|
||
yield return Enter(4);
|
||
var guanyu = Slot(2); // 창병
|
||
sling.Matchup.Show(bm, guanyu);
|
||
int want = 0;
|
||
foreach (var e in bm.AliveUnits(Faction.Enemy))
|
||
if (Mathf.Abs(cfg.Matchup(guanyu.Type, e.Type) - 1f) > 0.001f) want++;
|
||
Assert.Greater(want, 0);
|
||
Assert.AreEqual(want, sling.Matchup.Count, "유리·불리인 적마다 표시");
|
||
sling.Matchup.Hide();
|
||
Assert.AreEqual(0, sling.Matchup.Count);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 안내 화면 자체 확인용 캡처(평소 실행 안 함 · 이름으로 지정 + --include-explicit) → <프로젝트>/Logs/tutorial_capture/*.png
|
||
/// 카드(대상 구멍) · 끌기 손가락 · 남은 턴 강조 · 바위 강조 · 불길 강조 · 상성 표시 · 실패 카드.
|
||
/// </summary>
|
||
[UnityTest, Explicit]
|
||
public IEnumerator Capture_GuideScreens()
|
||
{
|
||
string dir = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.dataPath), "Logs", "tutorial_capture");
|
||
System.IO.Directory.CreateDirectory(dir);
|
||
var cam = Camera.main;
|
||
var d = TutorialDirector.Current;
|
||
System.Func<string, IEnumerator> shot = name => CaptureUtil.Capture(cam, 540, 960, System.IO.Path.Combine(dir, name + ".png"));
|
||
|
||
yield return Enter(1);
|
||
yield return new WaitForSecondsRealtime(0.8f);
|
||
yield return shot("1-1_step1_card");
|
||
d.TapForTest();
|
||
yield return new WaitForSecondsRealtime(0.9f);
|
||
yield return shot("1-1_step2_drag");
|
||
d.OnSelect(Slot(1));
|
||
yield return new WaitForSecondsRealtime(0.3f);
|
||
yield return shot("1-1_step3_aimhint");
|
||
|
||
yield return Enter(2);
|
||
yield return new WaitForSecondsRealtime(0.5f);
|
||
d.TapForTest();
|
||
yield return new WaitForSecondsRealtime(0.5f);
|
||
yield return shot("1-2_step2_turn_highlight");
|
||
d.TapForTest();
|
||
yield return null;
|
||
d.TapForTest();
|
||
yield return new WaitForSecondsRealtime(1.0f);
|
||
yield return shot("1-2_step4_drag");
|
||
|
||
yield return Enter(5);
|
||
yield return new WaitForSecondsRealtime(0.8f);
|
||
yield return shot("1-5_step1_boulder");
|
||
|
||
yield return Enter(8);
|
||
yield return new WaitForSecondsRealtime(0.8f);
|
||
yield return shot("1-8_step1_fire");
|
||
|
||
yield return Enter(4);
|
||
d.TapForTest();
|
||
yield return null;
|
||
bm.Sling.Matchup.Show(bm, Slot(2));
|
||
yield return new WaitForSecondsRealtime(0.6f);
|
||
yield return shot("1-4_matchup_marks");
|
||
bm.Sling.Matchup.Hide();
|
||
|
||
yield return Enter(2);
|
||
var guanyu = Slot(3);
|
||
guanyu.TakeDamage(guanyu.MaxHp * 10);
|
||
bm.CheckBattleEnd();
|
||
yield return new WaitForSecondsRealtime(0.8f);
|
||
yield return shot("1-2_fail_card");
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator AutoMode_MemorySave_IsPlainStage()
|
||
{
|
||
TutorialRules.Mode = TutorialMode.Auto;
|
||
int idx = 0;
|
||
bm.StartStage(idx);
|
||
yield return null;
|
||
Assert.IsNull(bm.Tutorial, "메모리 세이브(자동 테스트·캡처) = 학습 판 꺼짐");
|
||
Assert.AreEqual(bm.Stage.enemies.Count, bm.AliveCount(Faction.Enemy));
|
||
}
|
||
}
|
||
}
|