2026-11-20 03:15:36 +00:00
using System ;
using System.Collections ;
using System.Collections.Generic ;
using System.IO ;
using System.Reflection ;
using System.Text ;
using NUnit.Framework ;
using TKS.OutGame ;
using UnityEngine ;
using UnityEngine.SceneManagement ;
using UnityEngine.TestTools ;
using UnityEngine.UI ;
namespace TKS.Tests
{
/// <summary>
/// 임무 메뉴(2026-11-20 PD 컨펌 · 개발 요청서 §2 규칙별) — ① 표 임포트 검증 ② 포인트 · 구간 보상 · 모두 받기 · 상한 = daily_full ③ 대체 임무(초기화 순간 판정 · 도중에 열려도 그대로)
/// ④ 초기화(안 받은 임무 자동 더함 → 닿은 구간 = 우편 · 자동 더함으로 닿아도 daily_full) ⑤ 주간 초기화 · weekly_full ⑥ 업적(지금 단계 · 연쇄 · 반복 · 정렬 · 빨간 점)
/// ⑦ 카운터(전투 1판 · 치명타 · 연쇄 · 밀기 · 액티브 · 성장 1회 · 보옥 사용) ⑧ 로비 버튼(잠김 → 열림 · 빨간 점 = 세 탭 합) · 화면 · 팝업 · 우편.
/// 기대값은 임무 표(MissionDb)에서 읽는다(C45).
/// </summary>
public class MissionTests
{
static readonly DateTime T0 = new DateTime ( 2026 , 11 , 18 , 3 , 0 , 0 , DateTimeKind . Utc ) ; // 수요일
readonly System . Random rng = new System . Random ( 7 ) ;
[TearDown]
public void TearDown ( )
{
SaveStore . UseMemory ( false ) ;
}
static OutGameData Db
{
get { return OutGameData . Default ; }
}
static SaveData NewSave ( )
{
return HeroRules . NewSave ( Db , 5 , T0 ) ;
}
/// <summary>그 기간 칸의 임무를 모두 끝낸 상태로(받지는 않음).</summary>
static void Finish ( SaveData d , MissionPeriod p , int upTo = int . MaxValue )
{
int i = 0 ;
foreach ( var id in p . slots )
{
if ( i + + > = upTo ) break ;
var m = Db . Missions . Get ( id ) ;
if ( Counts . Get ( p . counts , m . counter ) < m . goal ) Counts . Set ( p . counts , m . counter , m . goal ) ;
}
}
static int Gold ( string reward )
{
float v ;
return ContentTables . ParseMap ( reward ) . TryGetValue ( "gold" , out v ) ? Mathf . RoundToInt ( v ) : 0 ;
}
[Test]
public void Tables_Import_NoErrors_MainPointsEqualMax ( )
{
var dir = Path . Combine ( Application . dataPath , OutGameTables . Folder ) ;
var texts = new string [ OutGameTables . MissionFiles . Length ] ;
for ( int i = 0 ; i < texts . Length ; i + + ) texts [ i ] = File . ReadAllText ( Path . Combine ( dir , OutGameTables . MissionFiles [ i ] ) , Encoding . UTF8 ) ;
var e = new List < string > ( ) ;
var db = OutGameTables . ParseMissionsOnly ( texts , Db . Chests , e ) ;
Assert . AreEqual ( 0 , e . Count , string . Join ( "\n" , e . ToArray ( ) ) ) ;
Assert . IsNotNull ( Db . Missions , "Resources/OutGame/MissionDb.asset 없음 — TKS/Import Missions" ) ;
Assert . AreEqual ( db . missions . Count , Db . Missions . missions . Count , "임포트 자산 = 표" ) ;
Assert . AreEqual ( db . achievements . Count , Db . Missions . achievements . Count ) ;
foreach ( var kind in new [ ] { MissionDb . Daily , MissionDb . Weekly } )
{
int sum = 0 ;
foreach ( var m in db . Mains ( kind ) ) sum + = m . point ;
Assert . AreEqual ( db . PointMax ( kind ) , sum , kind + " Main 포인트 합 = 상한" ) ;
}
UnityEngine . Object . DestroyImmediate ( db ) ;
}
[Test]
public void Daily_Claim_Points_Box_ClaimAll_FullCounted ( )
{
var db = Db . Missions ;
var d = NewSave ( ) ;
MissionRules . Roll ( Db , d , T0 , rng ) ;
Assert . AreEqual ( 1 , Counts . Get ( d . mission . day . counts , "login" ) , "그날 첫 접속" ) ;
Assert . AreEqual ( 1 , Counts . Get ( d . mission . totals , "login_days" ) , "누적 접속일" ) ;
Assert . AreEqual ( db . Mains ( MissionDb . Daily ) . Count , MissionRules . Rows ( Db , d , MissionDb . Daily ) . Count , "일일 칸 수" ) ;
// 받기 → 포인트 +n_point
int badge = MissionRules . Badge ( Db , d , MissionDb . Daily ) ;
MissionRow first = null ;
foreach ( var r in MissionRules . Rows ( Db , d , MissionDb . Daily ) )
if ( r . Claimable ) first = r ;
Assert . IsNotNull ( first , "접속 임무 = 바로 받기" ) ;
Assert . AreEqual ( first . m . point , MissionRules . Claim ( Db , d , MissionDb . Daily , first . m . id ) ) ;
Assert . AreEqual ( 0 , MissionRules . Claim ( Db , d , MissionDb . Daily , first . m . id ) , "두 번 받기 없음" ) ;
Assert . AreEqual ( badge - 1 , MissionRules . Badge ( Db , d , MissionDb . Daily ) , "빨간 점 = 받기 줄 수" ) ;
// 구간 1 = 포인트가 닿아야 받는다
var steps = db . Steps ( MissionDb . Daily ) ;
Finish ( d , d . mission . day ) ;
foreach ( var r in MissionRules . Rows ( Db , d , MissionDb . Daily ) )
{
if ( MissionRules . Points ( d , MissionDb . Daily ) > = steps [ 0 ] . need ) break ;
if ( r . Claimable ) MissionRules . Claim ( Db , d , MissionDb . Daily , r . m . id ) ;
}
int gold = d . gold ;
Assert . AreEqual ( steps [ 0 ] . reward , MissionRules . ClaimBox ( Db , d , MissionDb . Daily , steps [ 0 ] . step , rng ) ) ;
Assert . AreEqual ( gold + Gold ( steps [ 0 ] . reward ) , d . gold , "구간 보상 지급" ) ;
Assert . IsNull ( MissionRules . ClaimBox ( Db , d , MissionDb . Daily , steps [ 0 ] . step , rng ) , "구간 두 번 받기 없음" ) ;
// 모두 받기 = 나머지 임무 + 닿은 구간 · 상한 = daily_full 1
int pts ;
var got = MissionRules . ClaimAll ( Db , d , MissionDb . Daily , rng , out pts ) ;
Assert . AreEqual ( db . PointMax ( MissionDb . Daily ) , MissionRules . Points ( d , MissionDb . Daily ) , "Main 포인트 합 = 상한" ) ;
Assert . AreEqual ( steps . Count - 1 , got . Count , "남은 구간 모두" ) ;
Assert . AreEqual ( 0 , MissionRules . Badge ( Db , d , MissionDb . Daily ) ) ;
Assert . AreEqual ( 1 , Counts . Get ( d . mission . week . counts , "daily_full" ) , "주간 카운터 daily_full" ) ;
Assert . AreEqual ( 1 , Counts . Get ( d . mission . totals , "daily_full" ) , "업적 누적 daily_full" ) ;
}
[Test]
public void Fallback_DecidedAtReset_StaysUntilNextReset ( )
{
var db = Db . Missions ;
var d = NewSave ( ) ; // 아무 판도 안 깬 계정 = cfg 해금 스테이지 잠김
MissionDb . Mission locked = null ;
foreach ( var m in db . Mains ( MissionDb . Daily ) )
if ( m . fallbackId ! = 0 & & ! MissionRules . ContentOpen ( d , m ) ) locked = m ;
Assert . IsNotNull ( locked , "잠긴 콘텐츠 칸이 있어야 대체 임무를 볼 수 있다" ) ;
MissionRules . Roll ( Db , d , T0 , rng ) ;
Assert . IsTrue ( d . mission . day . slots . Contains ( locked . fallbackId ) , "잠긴 칸 = 대체 임무" ) ;
Assert . IsFalse ( d . mission . day . slots . Contains ( locked . id ) ) ;
// 하루 도중에 열려도 그대로
int ch , st ;
Assert . IsTrue ( ArenaRules . ParseStageKey ( MissionRules . CfgRef ( locked . unlock ) , out ch , out st ) ) ;
d . Stage ( ch , st , true ) . clears = 1 ;
Assert . IsTrue ( MissionRules . ContentOpen ( d , locked ) ) ;
MissionRules . Roll ( Db , d , T0 . AddHours ( 1 ) , rng ) ;
Assert . IsTrue ( d . mission . day . slots . Contains ( locked . fallbackId ) , "도중에 열려도 다음 초기화까지 대체 임무" ) ;
// 다음 초기화 = 원래 임무
MissionRules . Roll ( Db , d , T0 . AddDays ( 1 ) , rng ) ;
Assert . IsTrue ( d . mission . day . slots . Contains ( locked . id ) , "초기화 뒤 = 원래 임무" ) ;
Assert . IsFalse ( d . mission . day . slots . Contains ( locked . fallbackId ) ) ;
}
[Test]
public void Reset_AutoAddsUnclaimed_ReachedBoxesGoToMail ( )
{
var db = Db . Missions ;
var d = NewSave ( ) ;
MissionRules . Roll ( Db , d , T0 , rng ) ;
var steps = db . Steps ( MissionDb . Daily ) ;
// 첫 구간만 손으로 받고 나머지 임무는 끝내기만
Finish ( d , d . mission . day ) ;
foreach ( var r in MissionRules . Rows ( Db , d , MissionDb . Daily ) )
{
if ( MissionRules . Points ( d , MissionDb . Daily ) > = steps [ 0 ] . need ) break ;
MissionRules . Claim ( Db , d , MissionDb . Daily , r . m . id ) ;
}
Assert . IsNotNull ( MissionRules . ClaimBox ( Db , d , MissionDb . Daily , steps [ 0 ] . step , rng ) ) ;
int full0 = Counts . Get ( d . mission . week . counts , "daily_full" ) ;
MissionRules . Roll ( Db , d , T0 . AddDays ( 1 ) , rng ) ;
Assert . AreEqual ( 1 , d . mail . items . Count , "닿았지만 안 받은 구간 = 우편 1통" ) ;
var expect = new List < string > ( ) ;
for ( int i = 1 ; i < steps . Count ; i + + ) expect . Add ( steps [ i ] . reward ) ;
Assert . AreEqual ( MissionRules . Merge ( expect ) , d . mail . items [ 0 ] . reward , "받은 구간(1)은 빼고 나머지 구간 보상 합" ) ;
Assert . AreEqual ( MissionRules . MailDaily , d . mail . items [ 0 ] . kind ) ;
Assert . AreEqual ( full0 + 1 , Counts . Get ( d . mission . week . counts , "daily_full" ) , "자동으로 더한 포인트로 닿아도 daily_full" ) ;
Assert . AreEqual ( 0 , MissionRules . Points ( d , MissionDb . Daily ) , "새 하루 = 0" ) ;
Assert . AreEqual ( 1 , Counts . Get ( d . mission . day . counts , "login" ) , "새 하루 첫 접속" ) ;
Assert . AreEqual ( 2 , Counts . Get ( d . mission . totals , "login_days" ) ) ;
// 우편 받기 = 보상 지급 · 목록에서 빠짐
int gold = d . gold ;
var got = MissionRules . ClaimMail ( Db , d , new List < int > { d . mail . items [ 0 ] . id } , rng ) ;
Assert . AreEqual ( 1 , got . Count ) ;
Assert . AreEqual ( gold + Gold ( MissionRules . Merge ( expect ) ) , d . gold ) ;
Assert . AreEqual ( 0 , d . mail . items . Count ) ;
// 아무것도 안 한 하루 → 우편 없음
MissionRules . Roll ( Db , d , T0 . AddDays ( 2 ) , rng ) ;
Assert . AreEqual ( 0 , d . mail . items . Count , "닿은 구간이 없으면 우편 없음" ) ;
}
[Test]
public void Weekly_Reset_FullAndMail ( )
{
var db = Db . Missions ;
var d = NewSave ( ) ;
MissionRules . Roll ( Db , d , T0 , rng ) ;
Assert . AreEqual ( db . Mains ( MissionDb . Weekly ) . Count , MissionRules . Rows ( Db , d , MissionDb . Weekly ) . Count , "주간 칸 수" ) ;
string wk = d . mission . week . key ;
MissionRules . Roll ( Db , d , T0 . AddDays ( 1 ) , rng ) ;
Assert . AreEqual ( wk , d . mission . week . key , "하루가 지나도 같은 주(수 → 목)" ) ;
Finish ( d , d . mission . week ) ;
MissionRules . Roll ( Db , d , T0 . AddDays ( 7 ) , rng ) ;
Assert . AreNotEqual ( wk , d . mission . week . key , "7일 뒤 = 새 주" ) ;
Assert . AreEqual ( 1 , Counts . Get ( d . mission . totals , "weekly_full" ) , "주간 상한 = weekly_full" ) ;
MailEntry weekly = null ;
foreach ( var m in d . mail . items )
if ( m . kind = = MissionRules . MailWeekly ) weekly = m ;
Assert . IsNotNull ( weekly , "주간 구간 보상 우편" ) ;
var all = new List < string > ( ) ;
foreach ( var s in db . Steps ( MissionDb . Weekly ) ) all . Add ( s . reward ) ;
Assert . AreEqual ( MissionRules . Merge ( all ) , weekly . reward ) ;
}
[Test]
public void Achievements_CurrentStep_Chain_Repeat_Sort_Badge ( )
{
var db = Db . Missions ;
var d = NewSave ( ) ;
MissionRules . Roll ( Db , d , T0 , rng ) ;
MissionDb . Achievement a = null ;
foreach ( var x in db . achievements )
if ( a = = null & & x . repeatAdd > 0 & & x . goals . Length > = 4 & & db . CounterOf ( x . counter ) . count = = MissionDb . Add ) a = x ;
Assert . IsNotNull ( a , "반복 단계가 있는 누적 업적" ) ;
// 3단계 목표까지 쌓임 → 지금 단계 1줄만 · 빨간 점 1(연쇄 단계는 세지 않음)
Counts . Set ( d . mission . totals , a . counter , a . goals [ 2 ] ) ;
int badge0 = MissionRules . AchBadge ( Db , d ) ;
var r = MissionRules . AchOf ( Db , d , a ) ;
Assert . AreEqual ( 1 , r . step ) ;
Assert . IsTrue ( r . Claimable ) ;
int gem = d . gem ;
Assert . AreEqual ( a . gems [ 0 ] , MissionRules . ClaimAch ( Db , d , a . id ) , "1단계 보옥" ) ;
Assert . AreEqual ( gem + a . gems [ 0 ] , d . gem ) ;
Assert . AreEqual ( 2 , MissionRules . AchOf ( Db , d , a ) . step , "받아야 다음 단계" ) ;
Assert . AreEqual ( badge0 , MissionRules . AchBadge ( Db , d ) , "같은 업적의 다음 단계도 받기 = 줄 수 그대로" ) ;
// 모두 받기 = 연쇄(2 · 3단계) 뒤 4단계에서 멈춤
var got = MissionRules . ClaimAllAch ( Db , d ) ;
int mine = 0 ;
foreach ( var g in got )
if ( g . a = = a ) mine + + ;
Assert . AreEqual ( 2 , mine , "연쇄로 2 · 3단계" ) ;
r = MissionRules . AchOf ( Db , d , a ) ;
Assert . AreEqual ( 4 , r . step ) ;
Assert . IsFalse ( r . Claimable ) ;
Assert . AreEqual ( 0 , MissionRules . AchBadge ( Db , d ) , "모두 받은 뒤 빨간 점 0" ) ;
// 정한 단계를 넘으면 반복 단계(+n_repeat_add 마다 n_repeat_gem)
int last = a . goals [ a . goals . Length - 1 ] ;
Counts . Set ( d . mission . totals , a . counter , last + a . repeatAdd * 2 ) ;
gem = d . gem ;
int before = Counts . Get ( d . mission . achieve , a . id ) ;
got = MissionRules . ClaimAllAch ( Db , d ) ;
int gems = 0 ;
for ( int i = before ; i < a . goals . Length ; i + + ) gems + = a . gems [ i ] ;
gems + = a . repeatGem * 2 ;
Assert . AreEqual ( a . goals . Length + 2 , Counts . Get ( d . mission . achieve , a . id ) , "반복 2단계까지" ) ;
r = MissionRules . AchOf ( Db , d , a ) ;
Assert . IsTrue ( r . repeat ) ;
Assert . AreEqual ( last + a . repeatAdd * 3 , r . goal , "다음 반복 목표" ) ;
int mineGems = 0 ;
foreach ( var g in got )
if ( g . a = = a ) mineGems + = g . gem ;
Assert . AreEqual ( gems , mineGems , "단계 보옥 + 반복 보옥" ) ;
// 반복 없는 업적은 끝 = 맨 아래 · 받기 = 맨 위
MissionDb . Achievement fin = null ;
foreach ( var x in db . achievements )
if ( fin = = null & & x . repeatAdd = = 0 & & db . CounterOf ( x . counter ) . count = = MissionDb . Add ) fin = x ;
if ( fin = = null )
foreach ( var x in db . achievements )
if ( fin = = null & & x . repeatAdd = = 0 & & x . counter = = "tower_floor" ) fin = x ;
Assert . IsNotNull ( fin , "반복 없는 업적" ) ;
if ( fin . counter = = "tower_floor" ) d . arena . towerFloor = fin . goals [ fin . goals . Length - 1 ] ;
else Counts . Set ( d . mission . totals , fin . counter , fin . goals [ fin . goals . Length - 1 ] ) ;
MissionRules . ClaimAllAch ( Db , d ) ;
Assert . IsTrue ( MissionRules . AchOf ( Db , d , fin ) . allDone ) ;
Counts . Set ( d . mission . totals , a . counter , r . goal ) ; // a = 받기
var rows = MissionRules . AchRows ( Db , d , "" ) ;
Assert . AreEqual ( db . achievements . Count , rows . Count , "종류마다 1줄" ) ;
Assert . IsTrue ( rows [ 0 ] . Claimable , "받기가 맨 위" ) ;
Assert . IsTrue ( rows [ rows . Count - 1 ] . allDone , "모두 완료가 맨 아래" ) ;
for ( int i = 1 ; i < rows . Count ; i + + )
if ( ! rows [ i - 1 ] . Claimable & & ! rows [ i - 1 ] . allDone & & ! rows [ i ] . Claimable & & ! rows [ i ] . allDone )
Assert . GreaterOrEqual ( rows [ i - 1 ] . Progress , rows [ i ] . Progress - 1e-6f , "진행 중 = 진행률 높은 순" ) ;
Assert . AreEqual ( MissionRules . Badge ( Db , d , MissionDb . Daily ) + MissionRules . Badge ( Db , d , MissionDb . Weekly ) + MissionRules . AchBadge ( Db , d ) , MissionRules . LobbyBadge ( Db , d ) , "로비 = 세 탭 합" ) ;
}
static IEnumerator Boot ( )
{
WorldProgress . Reset ( ) ;
SaveStore . UseMemory ( true ) ;
SceneManager . LoadScene ( "Battle" ) ;
yield return null ;
yield return null ;
}
[UnityTest]
public IEnumerator Counters_Battle_Events_Growth_Gem ( )
{
yield return Boot ( ) ;
var og = OutGameRoot . Instance ;
var s = og . Session ;
var d = s . Save ;
var bm = og . Battle ;
Func < string , int > total = k = > Counts . Get ( d . mission . totals , k ) ;
Func < string , int > day = k = > Counts . Get ( d . mission . day . counts , k ) ;
int win0 = total ( "stage_win" ) , dwin0 = day ( "stage_win" ) , kill0 = total ( "kill_any" ) , boss0 = total ( "boss_kill" ) ;
// 전투 1판(출정 1-1) — 적을 모두 쓰러뜨리고 승리
bm . StartStage ( 0 ) ;
yield return null ;
Assert . IsNull ( bm . Mode , "출정" ) ;
var p0 = bm . AliveUnits ( Faction . Player ) [ 0 ] ;
var e0 = bm . AliveUnits ( Faction . Enemy ) [ 0 ] ;
int crit0 = total ( "crit" ) , chain0 = total ( "chain" ) , push0 = total ( "push" ) , act0 = total ( "active_use" ) ;
BattleEvents . Raise ( BattleEvents . Crits , p0 ) ;
BattleEvents . Raise ( BattleEvents . Crits , e0 ) ;
BattleEvents . Raise ( BattleEvents . ChainHits , p0 , 2 ) ;
BattleEvents . Raise ( BattleEvents . Pushes , p0 ) ;
BattleEvents . Raise ( BattleEvents . ActiveUses , p0 ) ;
Assert . AreEqual ( crit0 + 1 , total ( "crit" ) , "아군 치명타만" ) ;
Assert . AreEqual ( chain0 + 2 , total ( "chain" ) , "연쇄 충돌" ) ;
Assert . AreEqual ( push0 + 1 , total ( "push" ) , "밀어내기 = 기존 키 pushes(s_code_now)" ) ;
Assert . AreEqual ( act0 + 1 , total ( "active_use" ) , "액티브 = 기존 키 active_uses" ) ;
Assert . AreEqual ( act0 + 1 , Counts . Get ( d . mission . day . counts , "active_use" ) , "일일 기간에도" ) ;
int enemies = 0 , bosses = 0 ;
var byType = new Dictionary < string , int > ( ) ;
foreach ( var u in bm . AliveUnits ( Faction . Enemy ) )
{
if ( u . Npc ) continue ;
enemies + + ;
if ( u . IsBoss ) bosses + + ;
string k = u . Type = = UnitType . Infantry ? "kill_inf" : u . Type = = UnitType . Spear ? "kill_spear" : u . Type = = UnitType . Cavalry ? "kill_cav" : u . Type = = UnitType . Archer ? "kill_arc" : "kill_stg" ;
int c ;
byType . TryGetValue ( k , out c ) ;
byType [ k ] = c + 1 ;
}
var before = new Dictionary < string , int > ( ) ;
foreach ( var k in byType . Keys ) before [ k ] = total ( k ) ;
foreach ( var u in bm . AliveUnits ( Faction . Enemy ) ) u . TakeDamage ( u . Hp ) ;
bm . CheckBattleEnd ( ) ;
yield return null ;
Assert . AreEqual ( BattlePhase . StageClear , bm . Phase ) ;
Assert . AreEqual ( win0 + 1 , total ( "stage_win" ) , "출정 승리(누적)" ) ;
Assert . AreEqual ( dwin0 + 1 , day ( "stage_win" ) , "출정 승리(일일)" ) ;
Assert . AreEqual ( kill0 + enemies , total ( "kill_any" ) , "처치" ) ;
Assert . AreEqual ( boss0 + bosses , total ( "boss_kill" ) , "적장" ) ;
foreach ( var kv in byType ) Assert . AreEqual ( before [ kv . Key ] + kv . Value , total ( kv . Key ) , kv . Key ) ;
bm . ContinueAfterResult ( ) ;
yield return null ;
// 성장 1회(영웅 레벨업 화면 동작) → hero_grow · hero_levelup
string hid = d . ActivePreset . slots [ 0 ] ;
d . gold + = 10000000 ;
d . Level ( hid ) . exp + = 1000000 ; // 레벨업 = 영웅 경험 + 골드(HeroRules.CanLevelUp)
s . Commit ( ) ;
og . ShowHero ( hid ) ;
yield return null ;
int grow0 = day ( "hero_grow" ) , lv0 = total ( "hero_levelup" ) , lvBefore = d . Level ( hid ) . lv ;
var m = og . HeroDetail . GetType ( ) . GetMethod ( "OnLevelUp" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
Assert . IsNotNull ( m , "영웅 상세 레벨업 동작" ) ;
m . Invoke ( og . HeroDetail , null ) ;
Assert . Greater ( d . Level ( hid ) . lv , lvBefore , "레벨업 성공" ) ;
Assert . AreEqual ( grow0 + 1 , day ( "hero_grow" ) , "영웅 성장 1회" ) ;
Assert . AreEqual ( lv0 + d . Level ( hid ) . lv - lvBefore , total ( "hero_levelup" ) , "레벨 오른 수" ) ;
// 보옥 사용 = 저장 사이에 줄어든 보옥(주간)
int gemSpent0 = Counts . Get ( d . mission . week . counts , "gem_spent" ) ;
d . gem - = 7 ;
s . Commit ( ) ;
Assert . AreEqual ( gemSpent0 + 7 , Counts . Get ( d . mission . week . counts , "gem_spent" ) , "보옥 사용" ) ;
}
[UnityTest]
public IEnumerator Lobby_Button_Lock_Badge_Screen_Popups_Mail ( )
{
yield return Boot ( ) ;
var og = OutGameRoot . Instance ;
var s = og . Session ;
var d = s . Save ;
var db = s . Db . Missions ;
og . ShowLobby ( ) ;
yield return null ;
var btn = og . Lobby . Rt . GetComponentsInChildren < Button > ( true ) ;
Button mission = null , mail = null ;
foreach ( var b in btn )
{
if ( b . name = = "Side_임무" ) mission = b ;
if ( b . name = = "Side_우편" ) mail = b ;
}
Assert . IsNotNull ( mission , "로비 임무 버튼" ) ;
int ch , st ;
Assert . IsTrue ( ArenaRules . ParseStageKey ( db . Value ( "unlock_stage" ) , out ch , out st ) ) ;
if ( ! MissionRules . MenuOpen ( s . Db , d ) )
{
var lk = mission . transform . Find ( "Lock" ) ;
Assert . IsTrue ( lk ! = null & & lk . gameObject . activeSelf , "열리기 전 = 자물쇠" ) ;
mission . onClick . Invoke ( ) ;
Assert . AreEqual ( og . Lobby , og . Current , "잠김 = 화면 안 열림" ) ;
StringAssert . Contains ( db . Value ( "unlock_stage" ) , og . LastToast , "잠김 안내 = 해금 스테이지" ) ;
}
d . Stage ( ch , st , true ) . clears = 1 ;
s . Commit ( ) ;
yield return null ;
Assert . IsTrue ( MissionRules . MenuOpen ( s . Db , d ) ) ;
var lock2 = mission . transform . Find ( "Lock" ) ;
Assert . IsTrue ( lock2 = = null | | ! lock2 . gameObject . activeSelf , "열림 = 자물쇠 없음" ) ;
var badge = mission . transform . Find ( "Alert" ) ;
int lobby = MissionRules . LobbyBadge ( s . Db , d ) ;
Assert . Greater ( lobby , 0 , "접속 임무 = 받기 1 이상" ) ;
Assert . IsTrue ( badge . gameObject . activeSelf ) ;
Assert . AreEqual ( lobby . ToString ( ) , badge . GetComponentInChildren < Text > ( ) . text , "로비 빨간 점 = 세 탭 합" ) ;
// 화면 · 탭 · 줄
mission . onClick . Invoke ( ) ;
yield return null ;
Assert . AreEqual ( og . Missions , og . Current , "임무 화면" ) ;
var scr = og . Missions ;
scr . SetTab ( MissionScreen . DailyTab ) ;
Assert . AreEqual ( MissionRules . Rows ( s . Db , d , MissionDb . Daily ) . Count , scr . RowStates . Count , "일일 줄 수" ) ;
Assert . IsTrue ( scr . RowStates . Contains ( "claim" ) , "받기 줄" ) ;
var tabBadge = scr . Rt . Find ( "Body/Fit/Tab0/Badge" ) ;
Assert . IsNotNull ( tabBadge ) ;
Assert . AreEqual ( MissionRules . Badge ( s . Db , d , MissionDb . Daily ) . ToString ( ) , tabBadge . GetComponentInChildren < Text > ( ) . text , "탭 빨간 점" ) ;
scr . SetTab ( MissionScreen . WeeklyTab ) ;
Assert . AreEqual ( MissionRules . Rows ( s . Db , d , MissionDb . Weekly ) . Count , scr . RowStates . Count , "주간 줄 수" ) ;
scr . SetTab ( MissionScreen . AchieveTab ) ;
Assert . AreEqual ( db . achievements . Count , scr . RowStates . Count , "업적 = 종류마다 1줄" ) ;
scr . SetCategory ( db . achievements [ 0 ] . category ) ;
int inCat = 0 ;
foreach ( var a in db . achievements )
if ( a . category = = db . achievements [ 0 ] . category ) inCat + + ;
Assert . AreEqual ( inCat , scr . RowStates . Count , "분류 칩" ) ;
scr . SetCategory ( "" ) ;
// 모두 받기 → 팝업(일일 = 포인트 · 구간)
scr . SetTab ( MissionScreen . DailyTab ) ;
Finish ( d , d . mission . day ) ;
s . Commit ( ) ;
scr . OnClaimAll ( MissionDb . Daily ) ;
Assert . IsTrue ( og . ModalVisible , "보상 팝업" ) ;
Assert . AreEqual ( MissionScreen . T ( "pop_all_title" ) , scr . LastPopup ) ;
Assert . AreEqual ( db . PointMax ( MissionDb . Daily ) , MissionRules . Points ( d , MissionDb . Daily ) ) ;
og . CloseModal ( ) ;
// 업적 연쇄 팝업
var ach = db . achievements [ 0 ] ;
Counts . Set ( d . mission . totals , ach . counter , ach . goals [ Mathf . Min ( 1 , ach . goals . Length - 1 ) ] ) ;
scr . SetTab ( MissionScreen . AchieveTab ) ;
scr . OnAchAll ( ) ;
Assert . IsTrue ( og . ModalVisible , "업적 팝업" ) ;
Assert . AreEqual ( MissionScreen . T ( "pop_ach_title" ) , scr . LastPopup ) ;
og . CloseModal ( ) ;
// 우편: 초기화 우편 → 로비 우편 빨간 점 · 우편함 받기
d . mail . items . Add ( new MailEntry { id = + + d . mail . seq , kind = MissionRules . MailDaily , args = new List < string > { "20261119" , "40;70" } , reward = "gold:123" } ) ;
s . Commit ( ) ;
og . ShowLobby ( ) ;
yield return null ;
Assert . IsNotNull ( mail ) ;
Assert . AreEqual ( d . mail . items . Count . ToString ( ) , mail . transform . Find ( "Alert" ) . GetComponentInChildren < Text > ( ) . text , "우편 빨간 점" ) ;
StringAssert . Contains ( "11" , MailBox . Body ( d . mail . items [ 0 ] ) , "우편 글 = 날짜" ) ;
mail . onClick . Invoke ( ) ;
Assert . IsTrue ( og . ModalVisible , "우편함" ) ;
int gold = d . gold ;
2026-11-21 04:50:28 +00:00
// 우편 버튼 = 「받기」 하나(= 보이는 우편 전부 · PD 2026-11-20 「우편 보상은 무조건 받기만」 · 모두 받기 · 닫기 버튼 폐지)
2026-11-20 03:15:36 +00:00
Button all = null ;
2026-11-21 04:50:28 +00:00
int claimBtns = 0 ;
foreach ( var b in og . TopRoot . GetComponentsInChildren < Button > ( true ) )
{
if ( b . name = = "MailClaim" ) all = b ;
var bt = b . GetComponentInChildren < Text > ( ) ;
if ( bt ! = null & & ( bt . text = = MissionScreen . T ( "mail_claim_all" ) | | bt . text = = MissionScreen . T ( "mail_close" ) ) ) claimBtns + + ;
}
Assert . IsNotNull ( all , "받기" ) ;
var unroll = og . TopRoot . GetComponentInChildren < UiUnroll > ( true ) ;
Assert . IsNotNull ( unroll , "두루마리 펼침(PD 2026-11-21)" ) ;
Assert . IsTrue ( all . transform . IsChildOf ( unroll . transform . Find ( "Reveal" ) ) , "받기 = 펼침 가림판(Reveal) 안 종이" ) ;
Assert . AreEqual ( MissionScreen . T ( "mail_claim" ) , all . GetComponentInChildren < Text > ( ) . text , "받기 글자" ) ;
Assert . AreEqual ( 0 , claimBtns , "모두 받기 · 닫기 버튼 없음" ) ;
2026-11-20 03:15:36 +00:00
all . onClick . Invoke ( ) ;
Assert . AreEqual ( gold + 123 , d . gold , "우편 보상" ) ;
Assert . AreEqual ( 0 , d . mail . items . Count ) ;
2026-11-21 04:50:28 +00:00
Assert . IsFalse ( og . ModalVisible , "전부 받으면 우편함 닫힘(mail_close_after)" ) ;
2026-11-20 03:15:36 +00:00
og . CloseModal ( ) ;
}
/// <summary>목업 대조 캡처(1080× 1920 · Logs/mission_capture/ · 직접 실행).</summary>
[UnityTest, Explicit]
public IEnumerator Capture_MissionScreens ( )
{
yield return Boot ( ) ;
string dir = Path . Combine ( Path . GetDirectoryName ( Application . dataPath ) , "Logs" , "mission_capture" ) ;
Directory . CreateDirectory ( dir ) ;
var og = OutGameRoot . Instance ;
var s = og . Session ;
var d = s . Save ;
var db = s . Db . Missions ;
var cam = og . Cam ! = null ? og . Cam : Camera . main ;
Func < string , IEnumerator > shot = name = > CaptureUtil . Capture ( cam , 1080 , 1920 , Path . Combine ( dir , name + ".png" ) ) ;
// 목업과 같은 상황: 1-10 클리어(보급전 열림) · 투기장 · 토벌전 잠김 → 대체 임무 2칸
int ch , st ;
ArenaRules . ParseStageKey ( db . Value ( "unlock_stage" ) , out ch , out st ) ;
d . Stage ( ch , st , true ) . clears = 1 ;
d . Stage ( 1 , 10 , true ) . clears = 1 ;
d . mission . day = new MissionPeriod ( ) ;
d . mission . week = new MissionPeriod ( ) ;
s . MissionRoll ( ) ;
var day = d . mission . day ;
int i = 0 ;
foreach ( var id in day . slots )
{
var m = db . Get ( id ) ;
int v = i < 6 ? m . goal : Mathf . Max ( 1 , m . goal * 3 / 5 ) ;
Counts . Set ( day . counts , m . counter , Mathf . Max ( Counts . Get ( day . counts , m . counter ) , v ) ) ;
i + + ;
}
// 일일 = 1 · 3 · 4 · 5번 받음 + 첫 구간 받음
var rows = MissionRules . Rows ( s . Db , d , MissionDb . Daily ) ;
foreach ( int k in new [ ] { 0 , 2 , 3 , 4 } )
if ( k < rows . Count ) MissionRules . Claim ( s . Db , d , MissionDb . Daily , rows [ k ] . m . id ) ;
MissionRules . ClaimBox ( s . Db , d , MissionDb . Daily , 1 , s . Rng ) ;
var week = d . mission . week ;
i = 0 ;
foreach ( var id in week . slots )
{
var m = db . Get ( id ) ;
Counts . Set ( week . counts , m . counter , i % 3 = = 0 ? Mathf . Max ( 1 , m . goal / 3 ) : m . goal ) ;
i + + ;
}
var wr = MissionRules . Rows ( s . Db , d , MissionDb . Weekly ) ;
for ( int k = 0 ; k < wr . Count ; k + + )
if ( k % 3 = = 1 ) MissionRules . Claim ( s . Db , d , MissionDb . Weekly , wr [ k ] . m . id ) ;
MissionRules . ClaimBox ( s . Db , d , MissionDb . Weekly , 1 , s . Rng ) ;
// 업적 = 목업 줄(창병 120 · 출석 14 …)
Counts . Set ( d . mission . totals , "kill_spear" , 120 ) ;
Counts . Set ( d . mission . achieve , "kill_spear" , 2 ) ;
Counts . Set ( d . mission . totals , "login_days" , 14 ) ;
Counts . Set ( d . mission . achieve , "login" , 3 ) ;
Counts . Set ( d . mission . totals , "hero_levelup" , 41 ) ;
Counts . Set ( d . mission . achieve , "hero_lv" , 2 ) ;
Counts . Set ( d . mission . totals , "kill_inf" , 72 ) ;
Counts . Set ( d . mission . achieve , "kill_inf" , 3 ) ;
Counts . Set ( d . mission . totals , "crit" , 31 ) ;
Counts . Set ( d . mission . achieve , "crit" , 2 ) ;
Counts . Set ( d . mission . totals , "gacha_pull" , 12 ) ;
Counts . Set ( d . mission . achieve , "gacha" , 1 ) ;
d . mail . items . Add ( new MailEntry { id = + + d . mail . seq , kind = MissionRules . MailDaily , args = new List < string > { "20261119" , "40;70" } , reward = MissionRules . Merge ( new [ ] { db . Steps ( MissionDb . Daily ) [ 1 ] . reward , db . Steps ( MissionDb . Daily ) [ 2 ] . reward } ) } ) ;
s . Commit ( ) ;
og . ShowLobby ( ) ;
yield return new WaitForSecondsRealtime ( 0.5f ) ;
yield return shot ( "01_lobby" ) ;
og . Show ( og . Missions ) ;
og . Missions . SetTab ( MissionScreen . DailyTab ) ;
yield return new WaitForSecondsRealtime ( 0.3f ) ;
yield return shot ( "02_daily" ) ;
og . Missions . SetTab ( MissionScreen . WeeklyTab ) ;
yield return new WaitForSecondsRealtime ( 0.3f ) ;
yield return shot ( "03_weekly" ) ;
og . Missions . SetTab ( MissionScreen . AchieveTab ) ;
yield return new WaitForSecondsRealtime ( 0.3f ) ;
yield return shot ( "04_achieve" ) ;
og . Missions . SetTab ( MissionScreen . DailyTab ) ;
// 구간 2 받기 팝업(포인트를 닿게)
var dr = MissionRules . Rows ( s . Db , d , MissionDb . Daily ) ;
foreach ( var r in dr )
if ( MissionRules . Points ( d , MissionDb . Daily ) < db . Steps ( MissionDb . Daily ) [ 1 ] . need & & r . Claimable ) MissionRules . Claim ( s . Db , d , MissionDb . Daily , r . m . id ) ;
s . Commit ( ) ;
og . Missions . OnBox ( MissionDb . Daily , db . Steps ( MissionDb . Daily ) [ 1 ] ) ;
yield return new WaitForSecondsRealtime ( 0.3f ) ;
yield return shot ( "05_pop_reward" ) ;
og . CloseModal ( ) ;
og . Missions . SetTab ( MissionScreen . AchieveTab ) ;
Counts . Set ( d . mission . totals , "kill_spear" , 120 ) ;
og . Missions . OnAchAll ( ) ;
yield return new WaitForSecondsRealtime ( 0.3f ) ;
yield return shot ( "06_pop_chain" ) ;
og . CloseModal ( ) ;
og . ShowLobby ( ) ;
yield return null ;
MailBox . Open ( og ) ;
2026-11-21 04:50:28 +00:00
// 두루마리 펼침 단계(진행 0 · 0.35 · 0.7 에서 멈춰 찍음) → 다 펼친 것
var ur = og . TopRoot . GetComponentInChildren < UiUnroll > ( true ) ;
if ( ur ! = null )
{
foreach ( var k in new [ ] { 0f , 0.35f , 0.7f } )
{
ur . Seek ( k ) ;
yield return null ;
yield return shot ( "07_unroll_" + Mathf . RoundToInt ( k * 100f ) . ToString ( "000" ) ) ;
}
ur . Finish ( ) ;
}
2026-11-20 03:15:36 +00:00
yield return new WaitForSecondsRealtime ( 0.3f ) ;
yield return shot ( "07_pop_mail" ) ;
og . CloseModal ( ) ;
Debug . Log ( "[TKS] 임무 캡처 → " + dir ) ;
}
}
}