2026-11-12 14:41:13 +00:00
using System.Collections.Generic ;
using System.Globalization ;
using UnityEngine ;
namespace TKS
{
/// <summary>
/// 시나리오 이벤트 표(2026-11-12 PD 「스테이지 선택 때 전장 설명 · 보스 등장 포커스 + 대사 + 등장 연출」 · 개발 요청서 C1·C2).
/// SOT = 조직 레포 `공유/기획팀_산출물/삼국지슬링샷/tables/` → 사본 `Assets/Resources/Scenario/*.csv`(utf-8-sig · 고친 뒤 기획 tables 도 같이).
/// stage_story.csv = n_chapter,n_stage,s_desc_ko,Memo · boss_intro.csv = n_chapter,n_stage,n_order,s_boss_id,s_title_ko,s_line_ko,Memo ·
/// boss_intro_config.csv = s_key,f_value,Memo — 값은 전부 표에서 읽는다(C45 · 코드에 값 없음).
2026-11-18 07:46:32 +00:00
/// 2026-11-18 추가: boss_talk.csv(보스 등장 주고받기) · scenario_event.csv(시나리오 이벤트 명령) · scenario_actor.csv(연출 이름표) ·
/// scenario_emote.csv(머리 위 표시) · scenario_event_config.csv(이벤트 연출 값).
2026-11-12 14:41:13 +00:00
/// </summary>
public static class ScenarioData
{
public const string Root = "Scenario/" ;
public class BossLine
{
public int chapter ;
public int stage ;
public int order ;
public string id ;
public string title ;
public string line ;
}
2026-11-18 07:46:32 +00:00
/// <summary>보스 등장 주고받기 한 줄(boss_talk.csv · 2026-11-18 PD 「보스 등장 대사 구성」) — 같은 n_order 의 줄은 대안(앞 줄의 화자가 전장에 없으면 다음 줄).</summary>
public class TalkLine
{
public int chapter ;
public int stage ;
public int order ;
/// <summary>보스 그림 id(ArtId) · 영웅 id(HeroId) · ally(아군 첫 유닛).</summary>
public string speaker ;
public string text ;
}
/// <summary>시나리오 이벤트 명령 한 줄(scenario_event.csv · 2026-11-18 PD 「연의전기 시나리오 이벤트」 · 요청서 §4).</summary>
public class EventRow
{
public string id ;
public string battle ;
public int chapter ;
public int stage ;
public string trigger ;
public int turn ;
public int order ;
public string cmd ;
public string actor ;
public string target ;
public float x = float . NaN ;
public float y = float . NaN ;
public float sec = float . NaN ;
public string arg ;
public string text ;
public bool HasPos
{
get { return ! float . IsNaN ( x ) & & ! float . IsNaN ( y ) ; }
}
}
public class Emote
{
public string glyph ;
public Color color ;
}
/// <summary>표가 약속한 명령 · 발동(요청서 §4) — 이 밖의 값은 데이터 검사 실패.</summary>
public static readonly string [ ] EventCommands = { "fade" , "caption" , "bg" , "hide" , "show" , "extra" , "move" , "face" , "say" , "emote" , "focus" , "attack" , "hit" , "faint" , "wake" , "shake" , "wait" , "tap" } ;
public static readonly string [ ] EventTriggers = { "stage_start" , "turn_start" , "win" } ;
2026-11-12 14:41:13 +00:00
static bool loaded ;
static readonly Dictionary < long , string > desc = new Dictionary < long , string > ( ) ;
static readonly List < BossLine > bosses = new List < BossLine > ( ) ;
2026-11-18 07:46:32 +00:00
static readonly List < TalkLine > talks = new List < TalkLine > ( ) ;
static readonly List < EventRow > events = new List < EventRow > ( ) ;
static readonly Dictionary < string , string > actorNames = new Dictionary < string , string > ( ) ;
static readonly Dictionary < string , Emote > emotes = new Dictionary < string , Emote > ( ) ;
2026-11-12 14:41:13 +00:00
static readonly Dictionary < string , float > cfg = new Dictionary < string , float > ( ) ;
2026-11-18 07:46:32 +00:00
static readonly Dictionary < string , float > evCfg = new Dictionary < string , float > ( ) ;
2026-11-12 14:41:13 +00:00
static readonly HashSet < string > missingReported = new HashSet < string > ( ) ;
/// <summary>읽기 오류(형식 · 빠진 칸 · 없는 키) — 데이터 검사 테스트가 0 인지 본다.</summary>
public static readonly List < string > Errors = new List < string > ( ) ;
public static void Reload ( )
{
loaded = false ;
Load ( ) ;
}
static void Load ( )
{
if ( loaded ) return ;
loaded = true ;
desc . Clear ( ) ;
bosses . Clear ( ) ;
2026-11-18 07:46:32 +00:00
talks . Clear ( ) ;
events . Clear ( ) ;
actorNames . Clear ( ) ;
emotes . Clear ( ) ;
2026-11-12 14:41:13 +00:00
cfg . Clear ( ) ;
2026-11-18 07:46:32 +00:00
evCfg . Clear ( ) ;
2026-11-12 14:41:13 +00:00
Errors . Clear ( ) ;
missingReported . Clear ( ) ;
foreach ( var r in Rows ( "stage_story" ) )
{
int c = Int ( r , "n_chapter" , "stage_story" ) , s = Int ( r , "n_stage" , "stage_story" ) ;
desc [ Key ( c , s ) ] = Get ( r , "s_desc_ko" ) ;
}
foreach ( var r in Rows ( "boss_intro" ) )
{
bosses . Add ( new BossLine
{
chapter = Int ( r , "n_chapter" , "boss_intro" ) ,
stage = Int ( r , "n_stage" , "boss_intro" ) ,
order = Int ( r , "n_order" , "boss_intro" ) ,
id = Get ( r , "s_boss_id" ) ,
title = Get ( r , "s_title_ko" ) ,
line = Get ( r , "s_line_ko" ) ,
} ) ;
}
bosses . Sort ( ( a , b ) = > a . chapter ! = b . chapter ? a . chapter . CompareTo ( b . chapter ) : a . stage ! = b . stage ? a . stage . CompareTo ( b . stage ) : a . order . CompareTo ( b . order ) ) ;
foreach ( var r in Rows ( "boss_intro_config" ) )
{
float v ;
if ( float . TryParse ( Get ( r , "f_value" ) , NumberStyles . Float , CultureInfo . InvariantCulture , out v ) ) cfg [ Get ( r , "s_key" ) ] = v ;
else Errors . Add ( "boss_intro_config.csv 행 " + Get ( r , "#" ) + ": f_value 숫자 아님" ) ;
}
2026-11-18 07:46:32 +00:00
foreach ( var r in Rows ( "scenario_event_config" ) )
{
float v ;
if ( float . TryParse ( Get ( r , "f_value" ) , NumberStyles . Float , CultureInfo . InvariantCulture , out v ) ) evCfg [ Get ( r , "s_key" ) ] = v ;
else Errors . Add ( "scenario_event_config.csv 행 " + Get ( r , "#" ) + ": f_value 숫자 아님" ) ;
}
int maxChars = cfg . ContainsKey ( "bubble_max_chars" ) ? Mathf . RoundToInt ( cfg [ "bubble_max_chars" ] ) : 0 ;
foreach ( var r in Rows ( "boss_talk" ) )
{
var t = new TalkLine
{
chapter = Int ( r , "n_chapter" , "boss_talk" ) ,
stage = Int ( r , "n_stage" , "boss_talk" ) ,
order = Int ( r , "n_order" , "boss_talk" ) ,
speaker = Get ( r , "s_speaker" ) ,
text = Get ( r , "s_text_ko" ) ,
} ;
if ( t . speaker . Length = = 0 ) Errors . Add ( "boss_talk.csv 행 " + Get ( r , "#" ) + ": s_speaker 빈칸" ) ;
if ( maxChars > 0 & & t . text . Length > maxChars ) Errors . Add ( "boss_talk.csv 행 " + Get ( r , "#" ) + ": 대사 " + t . text . Length + "자 > bubble_max_chars " + maxChars ) ;
talks . Add ( t ) ;
}
// 같은 n_order 의 대안 줄은 표에 적힌 순서를 지킨다(안정 정렬)
var sortedTalks = new List < TalkLine > ( talks ) ;
talks . Clear ( ) ;
talks . AddRange ( System . Linq . Enumerable . OrderBy ( sortedTalks , t = > t . chapter * 1000000L + t . stage * 1000L + t . order ) ) ;
foreach ( var r in Rows ( "scenario_event" ) )
{
var e = new EventRow
{
id = Get ( r , "s_event_id" ) ,
battle = Get ( r , "s_battle_id" ) ,
chapter = Int ( r , "n_chapter" , "scenario_event" ) ,
stage = Int ( r , "n_stage" , "scenario_event" ) ,
trigger = Get ( r , "e_trigger" ) ,
turn = OptInt ( Get ( r , "n_turn" ) ) ,
order = Int ( r , "n_order" , "scenario_event" ) ,
cmd = Get ( r , "e_cmd" ) ,
actor = Get ( r , "s_actor" ) ,
target = Get ( r , "s_target" ) ,
x = OptFloat ( Get ( r , "f_x" ) ) ,
y = OptFloat ( Get ( r , "f_y" ) ) ,
sec = OptFloat ( Get ( r , "f_sec" ) ) ,
arg = Get ( r , "s_arg" ) ,
text = Get ( r , "s_text_ko" ) ,
} ;
string at = "scenario_event.csv 행 " + Get ( r , "#" ) + "(" + e . id + " " + e . order + "): " ;
if ( System . Array . IndexOf ( EventCommands , e . cmd ) < 0 ) Errors . Add ( at + "모르는 명령 " + e . cmd ) ;
if ( System . Array . IndexOf ( EventTriggers , e . trigger ) < 0 ) Errors . Add ( at + "모르는 발동 " + e . trigger ) ;
if ( e . cmd = = "say" & & maxChars > 0 & & e . text . Length > maxChars ) Errors . Add ( at + "대사 " + e . text . Length + "자 > bubble_max_chars " + maxChars ) ;
if ( ( e . cmd = = "say" | | e . cmd = = "move" | | e . cmd = = "extra" | | e . cmd = = "faint" | | e . cmd = = "wake" | | e . cmd = = "attack" | | e . cmd = = "emote" | | e . cmd = = "face" ) & & e . actor . Length = = 0 ) Errors . Add ( at + e . cmd + " 에 s_actor 빈칸" ) ;
events . Add ( e ) ;
}
events . Sort ( ( a , b ) = > string . CompareOrdinal ( a . id , b . id ) ! = 0 ? string . CompareOrdinal ( a . id , b . id ) : a . order . CompareTo ( b . order ) ) ;
foreach ( var r in Rows ( "scenario_actor" ) )
actorNames [ ActorKey ( Int ( r , "n_chapter" , "scenario_actor" ) , Int ( r , "n_stage" , "scenario_actor" ) , Get ( r , "s_actor" ) ) ] = Get ( r , "s_name_ko" ) ;
foreach ( var r in Rows ( "scenario_emote" ) )
{
Color c ;
if ( ! ColorUtility . TryParseHtmlString ( Get ( r , "s_color" ) , out c ) )
{
Errors . Add ( "scenario_emote.csv 행 " + Get ( r , "#" ) + ": s_color 색 아님" ) ;
c = Color . white ;
}
emotes [ Get ( r , "s_id" ) ] = new Emote { glyph = Get ( r , "s_glyph" ) , color = c } ;
}
2026-11-12 14:41:13 +00:00
foreach ( var e in Errors ) Debug . LogError ( "[TKS] 시나리오 표 " + e ) ;
}
2026-11-18 07:46:32 +00:00
static string ActorKey ( int chapter , int stage , string actor )
{
return chapter + "-" + stage + ":" + actor ;
}
static float OptFloat ( string s )
{
float v ;
return s . Length > 0 & & float . TryParse ( s , NumberStyles . Float , CultureInfo . InvariantCulture , out v ) ? v : float . NaN ;
}
static int OptInt ( string s )
{
int v ;
return s . Length > 0 & & int . TryParse ( s , NumberStyles . Integer , CultureInfo . InvariantCulture , out v ) ? v : 0 ;
}
2026-11-12 14:41:13 +00:00
static List < Dictionary < string , string > > Rows ( string file )
{
var ta = Resources . Load < TextAsset > ( Root + file ) ;
if ( ta = = null )
{
Errors . Add ( "Resources/" + Root + file + ".csv 없음" ) ;
return new List < Dictionary < string , string > > ( ) ;
}
return StageTable . ReadCsv ( ta . text , file + ".csv" , Errors ) ;
}
static long Key ( int chapter , int stage )
{
return chapter * 1000L + stage ;
}
static string Get ( Dictionary < string , string > r , string k )
{
string v ;
return r . TryGetValue ( k , out v ) ? v : "" ;
}
static int Int ( Dictionary < string , string > r , string k , string file )
{
int v ;
if ( int . TryParse ( Get ( r , k ) , NumberStyles . Integer , CultureInfo . InvariantCulture , out v ) ) return v ;
Errors . Add ( file + ".csv 행 " + Get ( r , "#" ) + ": " + k + " 정수 아님" ) ;
return 0 ;
}
/// <summary>스테이지 선택 팝업의 전장 설명(없으면 "").</summary>
public static string Desc ( int chapter , int stage )
{
Load ( ) ;
string s ;
return desc . TryGetValue ( Key ( chapter , stage ) , out s ) ? s : "" ;
}
/// <summary>그 스테이지의 보스 등장 행(n_order 순 · 없으면 빈 목록).</summary>
public static List < BossLine > Bosses ( int chapter , int stage )
{
Load ( ) ;
return bosses . FindAll ( b = > b . chapter = = chapter & & b . stage = = stage ) ;
}
public static IList < BossLine > AllBosses
{
get
{
Load ( ) ;
return bosses ;
}
}
public static IEnumerable < KeyValuePair < long , string > > AllDesc
{
get
{
Load ( ) ;
return desc ;
}
}
/// <summary>연출 값(boss_intro_config.csv) — 키가 없으면 콘솔 오류 1회 + 0.</summary>
public static float Cfg ( string key )
{
Load ( ) ;
float v ;
if ( cfg . TryGetValue ( key , out v ) ) return v ;
if ( missingReported . Add ( key ) )
{
Errors . Add ( "boss_intro_config.csv 에 키 없음: " + key ) ;
Debug . LogError ( "[TKS] boss_intro_config.csv 에 키 없음: " + key ) ;
}
return 0f ;
}
public static bool HasCfg ( string key )
{
Load ( ) ;
return cfg . ContainsKey ( key ) ;
}
2026-11-18 07:46:32 +00:00
/// <summary>보스 등장 주고받기 줄(n_order 순 · 같은 order = 대안 · 없으면 빈 목록).</summary>
public static List < TalkLine > Talks ( int chapter , int stage )
{
Load ( ) ;
return talks . FindAll ( t = > t . chapter = = chapter & & t . stage = = stage ) ;
}
public static IList < TalkLine > AllTalks
{
get
{
Load ( ) ;
return talks ;
}
}
/// <summary>그 판 · 그 발동의 이벤트 묶음(s_event_id 별 · n_order 순). turn_start 는 n_turn 이 같은 것만.</summary>
public static List < List < EventRow > > Events ( int chapter , int stage , string trigger , int turn )
{
Load ( ) ;
var outList = new List < List < EventRow > > ( ) ;
List < EventRow > cur = null ;
foreach ( var e in events )
{
if ( e . chapter ! = chapter | | e . stage ! = stage | | e . trigger ! = trigger ) continue ;
if ( trigger = = "turn_start" & & e . turn ! = turn ) continue ;
if ( cur = = null | | cur [ 0 ] . id ! = e . id )
{
cur = new List < EventRow > ( ) ;
outList . Add ( cur ) ;
}
cur . Add ( e ) ;
}
return outList ;
}
public static IList < EventRow > AllEvents
{
get
{
Load ( ) ;
return events ;
}
}
/// <summary>연출 배우의 이름표(scenario_actor.csv) — 없으면 "".</summary>
public static string ActorName ( int chapter , int stage , string actor )
{
Load ( ) ;
string s ;
return actorNames . TryGetValue ( ActorKey ( chapter , stage , actor ) , out s ) ? s : "" ;
}
/// <summary>머리 위 표시(scenario_emote.csv · 그림 대신 글자) — 없으면 null.</summary>
public static Emote EmoteOf ( string id )
{
Load ( ) ;
Emote e ;
return emotes . TryGetValue ( id ? ? "" , out e ) ? e : null ;
}
/// <summary>이벤트 연출 값(scenario_event_config.csv) — 키가 없으면 콘솔 오류 1회 + 0.</summary>
public static float EvCfg ( string key )
{
Load ( ) ;
float v ;
if ( evCfg . TryGetValue ( key , out v ) ) return v ;
if ( missingReported . Add ( "ev:" + key ) )
{
Errors . Add ( "scenario_event_config.csv 에 키 없음: " + key ) ;
Debug . LogError ( "[TKS] scenario_event_config.csv 에 키 없음: " + key ) ;
}
return 0f ;
}
2026-11-12 14:41:13 +00:00
}
}