506 lines
27 KiB
C#
506 lines
27 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using NUnit.Framework;
|
||
using UnityEngine;
|
||
using UnityEngine.SceneManagement;
|
||
using UnityEngine.TestTools;
|
||
|
||
namespace TKS.Tests
|
||
{
|
||
/// <summary>병종 4종 규칙(PD 2026-11-04 #1080 충돌 규칙 포함)·턴 흐름·승리 판정을 실제 씬에서 검증한다(헤드리스 실행 가능).</summary>
|
||
public class BattleFlowTests
|
||
{
|
||
BattleManager bm;
|
||
BalanceConfig cfg;
|
||
|
||
[UnitySetUp]
|
||
public IEnumerator SetUp()
|
||
{
|
||
SceneManager.LoadScene("Battle");
|
||
yield return null;
|
||
yield return null;
|
||
bm = BattleManager.Instance;
|
||
Assert.IsNotNull(bm, "GameBootstrap 이 BattleManager 를 만들어야 한다");
|
||
cfg = bm.Config;
|
||
Time.timeScale = 20f;
|
||
}
|
||
|
||
[UnityTearDown]
|
||
public IEnumerator TearDown()
|
||
{
|
||
Time.timeScale = 1f;
|
||
yield return null;
|
||
}
|
||
|
||
IEnumerator Fresh()
|
||
{
|
||
bm.StopAllCoroutines();
|
||
bm.ClearUnits();
|
||
bm.ForcePhase(BattlePhase.PlayerTurn);
|
||
yield return null; // 파괴된 콜라이더가 물리 월드에서 빠질 시간
|
||
}
|
||
|
||
/// <summary>경로 질의가 쓰는 접촉 거리(행동 유닛 캐스트 반지름 + 상대 반지름).</summary>
|
||
static float CastContact(Unit mover, Unit other)
|
||
{
|
||
return mover.Radius * Combat.CastRadiusScale + other.Radius;
|
||
}
|
||
|
||
static float Gap(Unit a, Unit b)
|
||
{
|
||
return Vector2.Distance(a.Position, b.Position) - a.Radius - b.Radius;
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator Bootstrap_SpawnsHeroesAndStageEnemies()
|
||
{
|
||
Assert.AreEqual(BattlePhase.PlayerTurn, bm.Phase);
|
||
Assert.AreEqual(Mathf.Min(5, cfg.heroes.Length), bm.AliveCount(Faction.Player));
|
||
Assert.AreEqual(cfg.stages[0].enemies.Count, bm.AliveCount(Faction.Enemy));
|
||
yield return null;
|
||
}
|
||
|
||
[Test]
|
||
public void Matchup_TriangleAndArcherWeakness()
|
||
{
|
||
var c = cfg != null ? cfg : Resources.Load<BalanceConfig>("BalanceConfig");
|
||
Assert.Greater(c.Matchup(UnitType.Infantry, UnitType.Spear), 1f);
|
||
Assert.Greater(c.Matchup(UnitType.Spear, UnitType.Cavalry), 1f);
|
||
Assert.Greater(c.Matchup(UnitType.Cavalry, UnitType.Infantry), 1f);
|
||
Assert.Less(c.Matchup(UnitType.Spear, UnitType.Infantry), 1f);
|
||
Assert.Less(c.Matchup(UnitType.Cavalry, UnitType.Spear), 1f);
|
||
Assert.Less(c.Matchup(UnitType.Infantry, UnitType.Cavalry), 1f);
|
||
Assert.Greater(c.Matchup(UnitType.Infantry, UnitType.Archer), 1f);
|
||
Assert.Greater(c.Matchup(UnitType.Cavalry, UnitType.Archer), 1f);
|
||
Assert.Greater(c.Matchup(UnitType.Spear, UnitType.Archer), 1f);
|
||
}
|
||
|
||
// ---------- 보병 ----------
|
||
|
||
[UnityTest]
|
||
public IEnumerator Infantry_HitsEnemy_StopsAtContact_PushesIt_BonusMoveOnFinalHit()
|
||
{
|
||
yield return Fresh();
|
||
var inf = bm.SpawnUnit(UnitType.Infantry, Faction.Player, new Vector2(0f, -3f), "보병");
|
||
var foe = bm.SpawnUnit(UnitType.Spear, Faction.Enemy, new Vector2(0f, 0f), "적창병");
|
||
float contactY = -3f + (3f - CastContact(inf, foe));
|
||
var o = new ActionOutcome();
|
||
yield return bm.ResolveForTest(inf, foe.Position, false, o);
|
||
|
||
Assert.Contains(foe, o.Attacked);
|
||
Assert.Less(foe.Hp, foe.MaxHp, "부딪힌 적을 공격");
|
||
Assert.IsTrue(o.BonusMove, "최종 목표점 명중 → 추가 이동");
|
||
float remaining = CastContact(inf, foe); // 당긴 거리 3 − 접촉까지 거리 = 남은 힘
|
||
Assert.AreEqual(contactY - remaining * cfg.collisionSelfBounceRatio, inf.Position.y, 0.1f, "보병 자신도 반대 방향으로 튕긴다(PD #1081 · 남은 힘 × 비율)");
|
||
Assert.Contains(foe, o.Pushed, "부딪힌 유닛은 밀려난다");
|
||
Assert.Greater(foe.Position.y, 0.3f, "적이 남은 힘만큼 밀려남");
|
||
Assert.Less(inf.Hp, inf.MaxHp, "근접 공격은 반격 피해를 받는다");
|
||
|
||
int foeHp = foe.Hp;
|
||
var o2 = new ActionOutcome();
|
||
yield return bm.ResolveForTest(inf, inf.Position + new Vector2(2.5f, 0f), true, o2);
|
||
Assert.AreEqual(0, o2.Attacked.Count, "추가 이동은 이동만");
|
||
Assert.AreEqual(foeHp, foe.Hp);
|
||
Assert.IsTrue(o2.MovedOnly);
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator Infantry_NoBonus_WhenTargetBeyondEnemy()
|
||
{
|
||
yield return Fresh();
|
||
var inf = bm.SpawnUnit(UnitType.Infantry, Faction.Player, new Vector2(0f, -3f), "보병");
|
||
var foe = bm.SpawnUnit(UnitType.Infantry, Faction.Enemy, new Vector2(0f, 0f), "적보병");
|
||
var o = new ActionOutcome();
|
||
yield return bm.ResolveForTest(inf, new Vector2(0f, 1.4f), false, o);
|
||
Assert.Contains(foe, o.Attacked);
|
||
Assert.IsFalse(o.BonusMove);
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator Infantry_PushesAlly_AllyAttacksTouchingEnemy_OncePerPush()
|
||
{
|
||
yield return Fresh();
|
||
// A(보병) 가 B(아군 창병)를 +x 로 밀어 적에게 붙이면 B 가 공격 · C 가 B 를 다시 밀면 B 가 또 공격 (규칙 ⑤)
|
||
var a = bm.SpawnUnit(UnitType.Infantry, Faction.Player, new Vector2(-3f, -2f), "보병A");
|
||
var b = bm.SpawnUnit(UnitType.Spear, Faction.Player, new Vector2(0f, -2f), "창병B");
|
||
float pushX = CastContact(a, b); // A 는 3 − 접촉거리 만큼 가서 닿으므로 남는 힘(= 밀리는 거리) = 접촉거리
|
||
var foe = bm.SpawnUnit(UnitType.Infantry, Faction.Enemy, new Vector2(pushX, -2f + b.Radius + 0.45f + 0.05f), "적보병");
|
||
Assert.AreEqual(b.MaxHp, b.Hp);
|
||
|
||
var o = new ActionOutcome();
|
||
yield return bm.ResolveForTest(a, new Vector2(0f, -2f), false, o);
|
||
Assert.AreEqual(0, o.Attacked.Count, "아군에 부딪힌 보병 자신은 공격하지 않음");
|
||
Assert.Contains(b, o.Pushed);
|
||
Assert.AreEqual(pushX, b.Position.x, 0.1f, "B 가 남은 힘만큼 밀려남");
|
||
Assert.LessOrEqual(Gap(b, foe), Combat.ContactTolerance + 0.05f, "밀려서 적과 닿음");
|
||
Assert.Less(foe.Hp, foe.MaxHp, "밀린 아군 B 가 적을 공격");
|
||
Assert.AreEqual(a.MaxHp, a.Hp, "A 는 피해 없음");
|
||
Assert.Less(a.Position.x, -pushX - 0.2f, "A 도 반대로 튕김(아군과 부딪혀도 알까기)");
|
||
Assert.IsFalse(b.ActedThisTurn, "B 의 공격은 자기 행동을 소모하지 않음");
|
||
Assert.AreEqual(1, o.Notes.Count);
|
||
|
||
int hp = foe.Hp;
|
||
var c = bm.SpawnUnit(UnitType.Infantry, Faction.Player, new Vector2(pushX, -5f), "보병C");
|
||
var o2 = new ActionOutcome();
|
||
yield return bm.ResolveForTest(c, new Vector2(pushX, -2.2f), false, o2);
|
||
Assert.Contains(b, o2.Pushed, "C 가 B 를 다시 밀었다");
|
||
Assert.Less(foe.Hp, hp, "B 가 C 의 기회로 또 공격");
|
||
Assert.AreEqual(0, o2.Attacked.Count);
|
||
}
|
||
|
||
// ---------- 기병 ----------
|
||
|
||
[UnityTest]
|
||
public IEnumerator Cavalry_PiercesAllOnPath_AndReturnsOnFinalHit()
|
||
{
|
||
yield return Fresh();
|
||
var cav = bm.SpawnUnit(UnitType.Cavalry, Faction.Player, new Vector2(0f, -4f), "기병");
|
||
var e1 = bm.SpawnUnit(UnitType.Infantry, Faction.Enemy, new Vector2(0f, -1.5f), "적1");
|
||
var e2 = bm.SpawnUnit(UnitType.Infantry, Faction.Enemy, new Vector2(0f, 1f), "적2");
|
||
var o = new ActionOutcome();
|
||
yield return bm.ResolveForTest(cav, e2.Position, false, o);
|
||
Assert.Less(e1.Hp, e1.MaxHp, "경로 위 첫 적 관통 피해");
|
||
Assert.Less(e2.Hp, e2.MaxHp, "경로 위 둘째 적 관통 피해");
|
||
Assert.IsTrue(o.Returned, "최종 목표점 명중 → 제자리 복귀");
|
||
Assert.Less(Vector2.Distance(cav.Position, new Vector2(0f, -4f)), 0.05f);
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator Cavalry_StaysAtEnd_WithoutFinalHit()
|
||
{
|
||
yield return Fresh();
|
||
var cav = bm.SpawnUnit(UnitType.Cavalry, Faction.Player, new Vector2(0f, -4f), "기병");
|
||
var e1 = bm.SpawnUnit(UnitType.Infantry, Faction.Enemy, new Vector2(0f, -1f), "적1");
|
||
var o = new ActionOutcome();
|
||
yield return bm.ResolveForTest(cav, new Vector2(0f, 2f), false, o);
|
||
Assert.Less(e1.Hp, e1.MaxHp);
|
||
Assert.IsFalse(o.Returned);
|
||
Assert.Greater(cav.Position.y, 1.5f, "목표점까지 이동");
|
||
Assert.GreaterOrEqual(Vector2.Distance(cav.Position, e1.Position), cav.Radius + e1.Radius - 0.05f, "적과 겹치지 않음");
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator Cavalry_PassesThroughAlly_OrStopsJustBeforeIt()
|
||
{
|
||
yield return Fresh();
|
||
var cav = bm.SpawnUnit(UnitType.Cavalry, Faction.Player, new Vector2(0f, -4f), "기병");
|
||
var ally = bm.SpawnUnit(UnitType.Infantry, Faction.Player, new Vector2(0f, -1.5f), "아군보병");
|
||
var o = new ActionOutcome();
|
||
yield return bm.ResolveForTest(cav, new Vector2(0f, 2f), false, o);
|
||
Assert.AreEqual(2f, cav.Position.y, 0.1f, "아군을 관통해 목표점까지");
|
||
Assert.AreEqual(-1.5f, ally.Position.y, 0.01f, "아군은 밀리지 않음");
|
||
Assert.AreEqual(0, o.Pushed.Count);
|
||
|
||
var cav2 = bm.SpawnUnit(UnitType.Cavalry, Faction.Player, new Vector2(4f, -4f), "기병2");
|
||
var ally2 = bm.SpawnUnit(UnitType.Infantry, Faction.Player, new Vector2(4f, -1.5f), "아군2");
|
||
float sum = cav2.Radius + ally2.Radius;
|
||
var o2 = new ActionOutcome();
|
||
yield return bm.ResolveForTest(cav2, new Vector2(4f, -1.5f + sum * 0.5f), false, o2); // 지나칠 거리가 안 나옴
|
||
Assert.AreEqual(-1.5f - sum, cav2.Position.y, 0.1f, "통과할 거리가 안 나오면 아군 직전에 멈춤");
|
||
Assert.GreaterOrEqual(Vector2.Distance(cav2.Position, ally2.Position), sum - 0.05f, "아군과 겹치지 않음");
|
||
Assert.AreEqual(-1.5f, ally2.Position.y, 0.01f);
|
||
}
|
||
|
||
// ---------- 궁병 ----------
|
||
|
||
[UnityTest]
|
||
public IEnumerator Archer_ShootsInPlace_WhenEnemyWithinSlingRange()
|
||
{
|
||
yield return Fresh();
|
||
var arc = bm.SpawnUnit(UnitType.Archer, Faction.Player, new Vector2(0f, -5f), "궁병");
|
||
Assert.AreEqual(arc.SlingMaxDistance, arc.AttackRange, 0.001f, "궁병 사거리 = 슬링샷 범위 (PD #1080)");
|
||
Assert.AreEqual(arc.SlingMaxDistance * cfg.archerRangeRatio, arc.ArcherMoveAllow, 0.001f, "접근 허용 = 슬링샷 × 비율");
|
||
var foe = bm.SpawnUnit(UnitType.Infantry, Faction.Enemy, new Vector2(0f, -1.5f), "적보병");
|
||
Assert.Less(3.5f - CastContact(arc, foe), arc.AttackRange, "전제: 적 가장자리가 사거리 안");
|
||
var o = new ActionOutcome();
|
||
yield return bm.ResolveForTest(arc, new Vector2(0f, -2.5f), false, o);
|
||
Assert.Contains(foe, o.Attacked, "사거리 안의 적을 사격");
|
||
Assert.Less(foe.Hp, foe.MaxHp);
|
||
Assert.Less(Vector2.Distance(arc.Position, new Vector2(0f, -5f)), 0.01f, "움직이지 않고 제자리에서");
|
||
Assert.AreEqual(arc.MaxHp, arc.Hp, "원거리 사격은 반격을 받지 않는다");
|
||
Assert.IsFalse(o.Crit);
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator Archer_StepsInOnlyAsNeeded_WhenEnemyInDonut()
|
||
{
|
||
yield return Fresh();
|
||
var arc = bm.SpawnUnit(UnitType.Archer, Faction.Player, new Vector2(0f, -5f), "궁병");
|
||
var foe = bm.SpawnUnit(UnitType.Infantry, Faction.Enemy, new Vector2(0f, 0.3f), "적보병");
|
||
float hitDist = 5.3f - CastContact(arc, foe);
|
||
Assert.Greater(hitDist, arc.AttackRange, "전제: 사거리 밖");
|
||
Assert.LessOrEqual(hitDist, arc.AttackRange + arc.ArcherMoveAllow, "전제: 공격 가능 범위(도넛) 안");
|
||
float need = hitDist - arc.AttackRange;
|
||
var o = new ActionOutcome();
|
||
yield return bm.ResolveForTest(arc, new Vector2(0f, -1f), false, o);
|
||
Assert.Contains(foe, o.Attacked, "사거리에 들어올 만큼만 다가가 사격");
|
||
Assert.AreEqual(-5f + need, arc.Position.y, 0.1f, "필요한 만큼만 이동");
|
||
Assert.AreEqual(arc.MaxHp, arc.Hp);
|
||
Assert.IsFalse(o.Crit);
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator Archer_MovesToTarget_WhenNoEnemyWithinReach()
|
||
{
|
||
yield return Fresh();
|
||
var arc = bm.SpawnUnit(UnitType.Archer, Faction.Player, new Vector2(0f, -5f), "궁병");
|
||
var foe = bm.SpawnUnit(UnitType.Infantry, Faction.Enemy, new Vector2(0f, 1f), "적보병");
|
||
Assert.Greater(6f - CastContact(arc, foe), arc.AttackRange + arc.ArcherMoveAllow, "전제: 공격 가능 범위 밖");
|
||
Assert.IsFalse(bm.AnyEnemyWithinArcherReach(arc), "공격 가능 범위 안에 적 없음(도넛 회색)");
|
||
var o = new ActionOutcome();
|
||
var target = new Vector2(0f, -1f);
|
||
yield return bm.ResolveForTest(arc, target, false, o);
|
||
Assert.IsTrue(o.MovedOnly, "공격 가능 범위에 적이 없으면 목표점까지 이동만 (PD 2026-11-04 2차 지시)");
|
||
Assert.AreEqual(0, o.Attacked.Count);
|
||
Assert.AreEqual(foe.MaxHp, foe.Hp);
|
||
Assert.Less(Vector2.Distance(arc.Position, target), 0.05f, "목표 지점까지 이동");
|
||
|
||
var near = bm.SpawnUnit(UnitType.Infantry, Faction.Enemy, new Vector2(2f, -1f), "가까운적");
|
||
Assert.IsTrue(bm.AnyEnemyWithinArcherReach(arc), "범위 안에 적이 생기면 도넛 붉게");
|
||
Assert.IsTrue(near.IsAlive);
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator Archer_CritOnFinalHit()
|
||
{
|
||
yield return Fresh();
|
||
var arc = bm.SpawnUnit(UnitType.Archer, Faction.Player, new Vector2(0f, -3f), "궁병");
|
||
var foe = bm.SpawnUnit(UnitType.Infantry, Faction.Enemy, new Vector2(0f, 0f), "적보병");
|
||
var o = new ActionOutcome();
|
||
yield return bm.ResolveForTest(arc, foe.Position, false, o);
|
||
Assert.Contains(foe, o.Attacked);
|
||
Assert.IsTrue(o.Crit, "최종 목표점 명중 → 크리티컬");
|
||
Assert.AreEqual(arc.MaxHp, arc.Hp);
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator Archer_MeleePenalty_DealsRatio_TakesRatio_RangedUnaffected()
|
||
{
|
||
yield return Fresh();
|
||
var arc = bm.SpawnUnit(UnitType.Archer, Faction.Player, new Vector2(0f, -5f), "궁병");
|
||
var arc2 = bm.SpawnUnit(UnitType.Archer, Faction.Player, new Vector2(2f, -5f), "궁병2");
|
||
var inf = bm.SpawnUnit(UnitType.Infantry, Faction.Enemy, new Vector2(4f, -5f), "적보병");
|
||
|
||
int ranged = Combat.Damage(cfg, arc, inf, false, new System.Random(7), false);
|
||
int melee = Combat.Damage(cfg, arc, inf, false, new System.Random(7), true);
|
||
Assert.AreEqual(ranged * cfg.archerMeleeDealtRatio, melee, 1f, "궁병이 근접 유닛과 근접 전투하면 주는 피해 × 비율(기본 50 %)");
|
||
|
||
int takenRanged = Combat.Damage(cfg, inf, arc, false, new System.Random(7), false);
|
||
int takenMelee = Combat.Damage(cfg, inf, arc, false, new System.Random(7), true);
|
||
Assert.AreEqual(takenRanged * cfg.archerMeleeTakenRatio, takenMelee, 1f, "근접 유닛에게 근접으로 맞으면 받는 피해 × 비율(기본 +50 %)");
|
||
|
||
int aa = Combat.Damage(cfg, arc, arc2, false, new System.Random(7), true);
|
||
int ab = Combat.Damage(cfg, arc, arc2, false, new System.Random(7), false);
|
||
Assert.AreEqual(ab, aa, "궁병끼리는 근접 패널티 없음(근접 유닛 상대만)");
|
||
yield return null;
|
||
}
|
||
|
||
// ---------- 창병 ----------
|
||
|
||
[UnityTest]
|
||
public IEnumerator Spear_PlowsEnemyForward_OverwatchOnFinalHit_DamagesMovingEnemy()
|
||
{
|
||
yield return Fresh();
|
||
var spear = bm.SpawnUnit(UnitType.Spear, Faction.Player, new Vector2(0f, -3f), "창병");
|
||
var foe = bm.SpawnUnit(UnitType.Infantry, Faction.Enemy, new Vector2(0f, 0f), "적보병");
|
||
var o = new ActionOutcome();
|
||
yield return bm.ResolveForTest(spear, foe.Position, false, o);
|
||
Assert.Contains(foe, o.Attacked);
|
||
Assert.Less(foe.Hp, foe.MaxHp, "부딪힌 적에게 피해");
|
||
Assert.Contains(foe, o.Pushed, "튕기지 않고 밀며 함께 전진");
|
||
Assert.Greater(foe.Position.y, 0.5f, "적이 남은 거리만큼 앞으로 밀림");
|
||
Assert.AreEqual(CastContact(spear, foe), foe.Position.y - spear.Position.y, 0.1f, "창병은 접촉 간격을 유지하며 따라감");
|
||
Assert.IsTrue(o.Overwatch && spear.Overwatch, "최종 목표점 명중 → 대기(견제)");
|
||
|
||
int hp = foe.Hp;
|
||
var path = new List<Vector2> { foe.Position, foe.Position + new Vector2(1.5f, 0f) };
|
||
yield return bm.ApplyOverwatch(foe, path);
|
||
Assert.Less(foe.Hp, hp, "반경 안에서 움직인 적에게 피해");
|
||
|
||
// 반경 밖에서만 움직인 적은 피해 없음
|
||
var far = bm.SpawnUnit(UnitType.Infantry, Faction.Enemy, new Vector2(5f, 6f), "먼적");
|
||
int farHp = far.Hp;
|
||
yield return bm.ApplyOverwatch(far, new List<Vector2> { far.Position, far.Position + new Vector2(-1f, 0f) });
|
||
Assert.AreEqual(farHp, far.Hp);
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator Spear_PlowsAlly_NoDamage_AllyAttacksWhenPushedOntoEnemy()
|
||
{
|
||
yield return Fresh();
|
||
var spear = bm.SpawnUnit(UnitType.Spear, Faction.Player, new Vector2(0f, -4f), "창병");
|
||
var ally = bm.SpawnUnit(UnitType.Infantry, Faction.Player, new Vector2(0f, -2f), "아군보병");
|
||
var foe = bm.SpawnUnit(UnitType.Infantry, Faction.Enemy, new Vector2(0f, 1.5f), "적보병");
|
||
int allyHp = ally.Hp;
|
||
var o = new ActionOutcome();
|
||
yield return bm.ResolveForTest(spear, new Vector2(0f, 0f), false, o);
|
||
Assert.AreEqual(0, o.Attacked.Count, "아군에 부딪힌 창병 자신은 공격하지 않음");
|
||
Assert.Contains(ally, o.Pushed);
|
||
Assert.Greater(ally.Position.y, 0.4f, "아군을 밀며 함께 전진(적에 닿을 때까지)");
|
||
Assert.LessOrEqual(Gap(ally, foe), Combat.ContactTolerance + 0.05f, "밀린 아군이 적과 닿음");
|
||
Assert.AreEqual(CastContact(spear, ally), ally.Position.y - spear.Position.y, 0.1f, "창병은 아군 바로 뒤까지 따라옴");
|
||
Assert.Less(foe.Hp, foe.MaxHp, "밀린 아군이 적을 공격(규칙 ⑤)");
|
||
Assert.AreEqual(spear.MaxHp, spear.Hp, "창병은 피해 없음");
|
||
Assert.AreEqual(1, o.Notes.Count);
|
||
Assert.IsTrue(allyHp >= ally.Hp, "아군은 밀려서 피해를 받지 않는다(근접 공격 반격만 가능)");
|
||
}
|
||
|
||
// ---------- 턴 · 승패 · AI · 카메라 · 표시 ----------
|
||
|
||
[UnityTest]
|
||
public IEnumerator EnemyTurn_RunsAndReturnsToPlayerTurn()
|
||
{
|
||
yield return Fresh();
|
||
var p = bm.SpawnUnit(UnitType.Infantry, Faction.Player, new Vector2(0f, -3f), "아군");
|
||
var e = bm.SpawnUnit(UnitType.Infantry, Faction.Enemy, new Vector2(0f, 3f), "적군");
|
||
p.MarkActed();
|
||
int turn = bm.TurnNumber;
|
||
yield return bm.RunEnemyTurn();
|
||
Assert.AreEqual(BattlePhase.PlayerTurn, bm.Phase);
|
||
Assert.AreEqual(turn + 1, bm.TurnNumber);
|
||
Assert.IsFalse(p.ActedThisTurn, "새 턴에 행동 플래그 초기화");
|
||
Assert.IsTrue(e.Position.y < 2.9f || p.Hp < p.MaxHp, "적이 접근하거나 공격했다");
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator PlayerActions_AutoEndTurn_ThenEnemyTurn()
|
||
{
|
||
yield return Fresh();
|
||
var p = bm.SpawnUnit(UnitType.Infantry, Faction.Player, new Vector2(-3f, -5f), "아군");
|
||
var e = bm.SpawnUnit(UnitType.Archer, Faction.Enemy, new Vector2(3f, 6f), "적궁병");
|
||
Assert.IsTrue(bm.RequestPlayerAction(p, p.Position + new Vector2(0f, 2f)));
|
||
float t0 = Time.realtimeSinceStartup;
|
||
while (bm.Phase != BattlePhase.PlayerTurn && Time.realtimeSinceStartup - t0 < 10f) yield return null;
|
||
Assert.AreEqual(BattlePhase.PlayerTurn, bm.Phase, "버튼 없이 모든 유닛 행동 → 적군 턴 → 아군 턴");
|
||
Assert.AreEqual(2, bm.TurnNumber);
|
||
Assert.IsTrue(e.IsAlive);
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator Win_WhenAllEnemiesDead()
|
||
{
|
||
yield return Fresh();
|
||
var p = bm.SpawnUnit(UnitType.Infantry, Faction.Player, new Vector2(0f, -3f), "아군");
|
||
var e = bm.SpawnUnit(UnitType.Archer, Faction.Enemy, new Vector2(0f, -1f), "적궁병");
|
||
e.Hp = 1;
|
||
Assert.IsTrue(bm.RequestPlayerAction(p, e.Position));
|
||
float t0 = Time.realtimeSinceStartup;
|
||
while (bm.Phase == BattlePhase.Resolving && Time.realtimeSinceStartup - t0 < 10f) yield return null;
|
||
Assert.AreEqual(BattlePhase.StageClear, bm.Phase);
|
||
Assert.IsFalse(e.IsAlive);
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator EnemyAI_HoldsOutsideAggroRange_ActsInside()
|
||
{
|
||
yield return Fresh();
|
||
var p = bm.SpawnUnit(UnitType.Infantry, Faction.Player, new Vector2(0f, -13f), "아군");
|
||
var far = bm.SpawnUnit(UnitType.Infantry, Faction.Enemy, new Vector2(0f, 10f), "먼적");
|
||
var near = bm.SpawnUnit(UnitType.Infantry, Faction.Enemy, new Vector2(0f, -5f), "가까운적");
|
||
var players = bm.AliveUnits(Faction.Player);
|
||
Assert.IsFalse(EnemyAI.Decide(far, players, 1f, 11f, bm.Rng, bm.Board).HasValue, "교전 범위 밖 → 대기");
|
||
Assert.IsTrue(EnemyAI.Decide(near, players, 1f, 11f, bm.Rng, bm.Board).HasValue, "교전 범위 안 → 행동");
|
||
Assert.IsTrue(p.IsAlive);
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator Camera_BoardWiderThanView_ClampsAndPans()
|
||
{
|
||
var cc = Camera.main.GetComponent<CameraController>();
|
||
Assert.IsNotNull(cc, "넓은 전장 카메라 컨트롤러");
|
||
Assert.Greater(bm.Config.boardSize.y, bm.Config.cameraViewHeight, "전장이 화면보다 넓어야 스크롤이 의미 있다");
|
||
var r = bm.Board.Rect;
|
||
cc.SnapTo(new Vector2(1000f, 1000f));
|
||
var v = cc.ViewRect;
|
||
Assert.LessOrEqual(v.yMax, r.yMax + cc.TopMargin + 0.01f, "전장 위쪽 밖으로 못 나감(HUD 여유만큼만)");
|
||
Assert.LessOrEqual(v.xMax, r.xMax + cc.Margin + 0.01f + Mathf.Max(0f, v.width - r.width), "전장 오른쪽 밖으로 못 나감");
|
||
cc.SnapTo(Vector2.zero);
|
||
cc.PanBy(new Vector2(0f, 2f));
|
||
Assert.AreEqual(2f, cc.transform.position.y, 0.01f, "빈 곳 드래그 스크롤");
|
||
yield return null;
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator RangeIndicator_ShowsSlingRadius_ArcherDonut_EnemyRange()
|
||
{
|
||
yield return Fresh();
|
||
var sling = bm.Sling;
|
||
Assert.IsNotNull(sling, "GameBootstrap 이 SlingshotInput 을 만들어야 한다");
|
||
var arc = bm.SpawnUnit(UnitType.Archer, Faction.Player, new Vector2(0f, -5f), "궁병");
|
||
var inf = bm.SpawnUnit(UnitType.Infantry, Faction.Player, new Vector2(3f, -5f), "보병");
|
||
var foe = bm.SpawnUnit(UnitType.Spear, Faction.Enemy, new Vector2(0f, 4f), "적창병");
|
||
yield return null;
|
||
|
||
var r = sling.Range;
|
||
sling.Select(arc);
|
||
Assert.IsTrue(r.RingVisible, "플레이어 터치 → 사거리(슬링샷 범위) 얇은 원");
|
||
Assert.AreEqual(arc.SlingMaxDistance * 2f, r.RingDiameter, 0.01f);
|
||
Assert.IsTrue(r.DonutVisible, "궁병 → 공격 가능 범위 도넛");
|
||
Assert.AreEqual(arc.SlingMaxDistance * (1f + cfg.archerRangeRatio) * 2f, r.DonutDiameter, 0.01f, "도넛 바깥 = 슬링샷 범위 + 비율");
|
||
Assert.AreEqual(arc.Position, (Vector2)r.transform.position);
|
||
|
||
sling.Select(inf);
|
||
Assert.IsTrue(r.RingVisible);
|
||
Assert.IsFalse(r.DonutVisible, "궁병이 아니면 도넛 없음");
|
||
Assert.AreEqual(inf.SlingMaxDistance * 2f, r.RingDiameter, 0.01f);
|
||
|
||
sling.Select(foe);
|
||
Assert.IsTrue(r.RingVisible, "적 유닛 터치 → 적의 사거리");
|
||
Assert.AreEqual(foe.SlingMaxDistance * 2f, r.RingDiameter, 0.01f);
|
||
Assert.AreEqual(foe.Position, (Vector2)r.transform.position);
|
||
|
||
sling.Select(null);
|
||
Assert.IsFalse(r.RingVisible);
|
||
Assert.IsFalse(r.DonutVisible);
|
||
}
|
||
|
||
[UnityTest]
|
||
public IEnumerator UnitArt_HeroWithArt_PlaysBackIdle_UnitWithoutArt_IsShape()
|
||
{
|
||
// 부트스트랩 스테이지 1: 유비·관우·장비 = 스켈레탈 세션 아트(Resources/Units/liubei·guanyu·zhangfei) · 조운·황충 = 도형
|
||
Unit liubei = null;
|
||
Unit shape = null;
|
||
foreach (var u in bm.AliveUnits(Faction.Player))
|
||
{
|
||
if (u.DisplayName == "유비") liubei = u;
|
||
if (string.IsNullOrEmpty(u.ArtId)) shape = u;
|
||
}
|
||
Assert.IsNotNull(liubei);
|
||
Assert.IsTrue(liubei.View.HasArt, "유비 아트(back/front 클립)가 Resources/Units/liubei 에 있어야 한다");
|
||
Assert.AreEqual("back_idle", liubei.View.Anim.Current, "아군은 뒷모습 대기");
|
||
Assert.IsNotNull(liubei.View.Anim.Renderer.sprite);
|
||
Assert.Greater(liubei.View.Anim.Renderer.bounds.size.y, 0.5f, "스프라이트가 월드 크기로 보인다");
|
||
|
||
Assert.IsNotNull(shape, "아트 없는 유닛(조운·황충)은 도형");
|
||
Assert.IsFalse(shape.View.HasArt);
|
||
|
||
liubei.View.PlayAttack();
|
||
Assert.AreEqual("back_action", liubei.View.Anim.Current, "공격 자세 클립");
|
||
|
||
// 원화 세션 1차 납품(2026-11-04): 황건적 5종 정지 그림(front_idle 1장) + 전장 배경
|
||
int enemyArt = 0;
|
||
foreach (var e in bm.AliveUnits(Faction.Enemy))
|
||
{
|
||
if (e.View.HasArt)
|
||
{
|
||
enemyArt++;
|
||
Assert.AreEqual("front_idle", e.View.Anim.Current, "적은 앞모습 정지 그림");
|
||
}
|
||
}
|
||
Assert.AreEqual(bm.AliveCount(Faction.Enemy), enemyArt, "스테이지 1 황건적은 전원 원화(hgj_*)로 표시");
|
||
Assert.IsTrue(bm.Board.HasArt, "전장 배경 = Resources/Board/" + cfg.boardArt);
|
||
|
||
// 원화 2차 납품(2026-11-04): 동탁군 보·창·기·궁 4종 반영 · 여포(dz_boss_lvbu)는 보류 → 도형
|
||
bm.StartStage(1);
|
||
yield return null;
|
||
foreach (var e in bm.AliveUnits(Faction.Enemy))
|
||
{
|
||
if (e.IsBoss) continue;
|
||
Assert.IsTrue(e.View.HasArt, "스테이지 2 동탁군 병종 4종은 원화(" + e.ArtId + ")");
|
||
}
|
||
bm.StartStage(0);
|
||
yield return null;
|
||
}
|
||
}
|
||
}
|