ThreeKingdomsSlingshot/Assets/Scripts/Runtime/ContentModes/ContentTables.cs

261 lines
8.8 KiB
C#
Raw Normal View History

컨텐츠 모드 4종 구현 — 보급전 · 맹장 토벌전 · 연의 전기 · 투기장(교대 조작) · 더미 UI (PD 2026-11-17~18) - 전투 규칙 플러그인 ModeBattleRules(BattleMode.rules) + 훅(피해 · 처치 · 기믹 파괴 · 밀려 막힘 · 턴 시작 · 승패 · 제한 턴 · 출전 자리 · 고정 편성 · 바람 조준 · 교대 조작 · 좁힌 전장) - 표 = Resources/ContentModes/*.csv(기획 tables 사본 · 실행 중 읽음) · 적 수치 기준 = 게임 스테이지 적(common.enemy_ref) - ① 보급전 4곳(병법 훈련 조건 · 과제 · 별 / 군량고 / 연병장 허수아비 / 황건 삼형제) · 판정 · 보상 · 소탕 · 그날 완료 · 주간 도장 · 옛 던전 id 기록 이전 - ③ 맹장 7명(기본 공격 · 패턴 예고 · 기세 · 협공 · 벽 충돌 · 빈틈 · 딸린 것 · 철수) · 일정 · 점수 · 누적 단계 · 훈장 상점 - ② 연의 전기 15편(고정 편성 · 타격 횟수 기준 적 세기 · 조건 21 · 불 번짐 · 수공 · 바람 · 원군 · 연전 · 돌진) · 보상 · 주역 조각 - ④ 투기장 교대 조작(AlternateStep) · 12x18 전장 · 시즌 지형 · 점수 · 등급 · 상대 3 - 서버 /tks/modes/* 연결 · gimmicks.csv 5줄(granary · lowland · dry_grass · warship · camp) · Fable QA 11건 반영 - 테스트: 전체 189 중 187 통과 · 실패 2(보스 판 첫 프레임 · 보물 상자 크기 = 기존 실패로 추정) · 기믹 행 수 기대값 21 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 16:03:13 +00:00
using System.Collections.Generic;
using System.Globalization;
using UnityEngine;
namespace TKS
{
/// <summary>
/// 컨텐츠 모드 표(2026-11-17 컨텐츠 모드 기획 10판 · 개발 요청서 A-1) — SOT = 조직 레포 `공유/기획팀_산출물/삼국지슬링샷/tables/` →
/// 사본 `Assets/Resources/ContentModes/*.csv`(utf-8-sig · 시나리오 표와 같은 방식: 임포트 없이 실행 중에 읽는다 → 표만 바꾸면 다음 전투 · 화면부터 반영).
/// 값은 전부 표에서 읽는다(C45 · 코드에 수치 없음). 공통 설정 = content_modes_config(s_mode, s_key, s_value).
/// </summary>
public static class ContentTables
{
public const string Root = "ContentModes/";
public const string Config = "content_modes_config";
static readonly Dictionary<string, List<ContentRow>> cache = new Dictionary<string, List<ContentRow>>();
static Dictionary<string, string> cfg;
/// <summary>읽기 오류(파일 없음 · 칸 수 · 숫자 아님) — 데이터 검사 테스트가 0 인지 본다.</summary>
public static readonly List<string> Errors = new List<string>();
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
static void ResetStatics()
{
Reload();
}
/// <summary>다시 읽기(전투 · 화면을 열 때 부른다 — 표를 고친 뒤 바로 반영).</summary>
public static void Reload()
{
cache.Clear();
cfg = null;
Errors.Clear();
}
public static List<ContentRow> Rows(string file)
{
List<ContentRow> rows;
if (cache.TryGetValue(file, out rows)) return rows;
rows = new List<ContentRow>();
var ta = Resources.Load<TextAsset>(Root + file);
if (ta == null) Errors.Add("Resources/" + Root + file + ".csv 없음");
else
foreach (var d in StageTable.ReadCsv(ta.text, file + ".csv", Errors))
rows.Add(new ContentRow(file, d));
cache[file] = rows;
return rows;
}
/// <summary>그 칸 값이 v 인 첫 줄(없으면 null).</summary>
public static ContentRow Find(string file, string col, string v)
{
foreach (var r in Rows(file))
if (r.S(col) == v) return r;
return null;
}
// ---------- 공통 설정(content_modes_config) ----------
static Dictionary<string, string> CfgMap()
{
if (cfg != null) return cfg;
cfg = new Dictionary<string, string>();
foreach (var r in Rows(Config)) cfg[r.S("s_mode") + "." + r.S("s_key")] = r.S("s_value");
return cfg;
}
public static bool Has(string mode, string key)
{
return CfgMap().ContainsKey(mode + "." + key);
}
public static string Str(string mode, string key)
{
string v;
if (CfgMap().TryGetValue(mode + "." + key, out v)) return v;
Missing(mode, key);
return "";
}
public static float Num(string mode, string key)
{
float v;
var s = Str(mode, key);
if (s.Length > 0 && TryNum(s, out v)) return v;
if (s.Length > 0) Errors.Add(Config + ".csv " + mode + "." + key + ": 숫자 아님 「" + s + "」");
return 0f;
}
public static int Int(string mode, string key)
{
return Mathf.RoundToInt(Num(mode, key));
}
/// <summary>「a:1;b:2」 → { a:1, b:2 } (값이 숫자가 아닌 칸은 건너뜀).</summary>
public static Dictionary<string, float> Map(string mode, string key)
{
return ParseMap(Str(mode, key));
}
/// <summary>「a;b;c」 → [a, b, c].</summary>
public static List<string> List(string mode, string key)
{
return SplitList(Str(mode, key));
}
/// <summary>「1:5;6:6;8:7」 처럼 「그 단계부터 이 값」 계단 표에서 n 에 해당하는 값(없으면 def).</summary>
public static float Step(string mode, string key, int n, float def)
{
float best = def;
int at = int.MinValue;
foreach (var kv in Map(mode, key))
{
int k;
if (!int.TryParse(kv.Key, NumberStyles.Integer, CultureInfo.InvariantCulture, out k)) continue;
if (k <= n && k > at)
{
at = k;
best = kv.Value;
}
}
return best;
}
static readonly HashSet<string> missing = new HashSet<string>();
static void Missing(string mode, string key)
{
string k = mode + "." + key;
if (missing.Add(k)) Errors.Add(Config + ".csv 에 " + k + " 줄 없음");
}
// ---------- 해석 도우미 ----------
public static bool TryNum(string s, out float v)
{
return float.TryParse((s ?? "").Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out v);
}
public static Dictionary<string, float> ParseMap(string s)
{
var res = new Dictionary<string, float>();
foreach (var part in SplitList(s))
{
int i = part.LastIndexOf(':');
if (i <= 0) continue;
float v;
if (TryNum(part.Substring(i + 1), out v)) res[part.Substring(0, i).Trim()] = v;
}
return res;
}
/// <summary>
/// 글자 속 숫자들(「{a} 피해 +50 % · 나머지 −20 %」 → [50, −20]) — 기획 표가 값을 설명 글로만 준 칸(훈련 조건 · 허수아비 체력)을 읽는다.
/// {n} {a} 같은 자리 표시는 건너뛴다. 「−」(유니코드 빼기)도 음수로 읽는다.
/// </summary>
public static List<float> Numbers(string s)
{
var res = new List<float>();
if (string.IsNullOrEmpty(s)) return res;
int i = 0;
while (i < s.Length)
{
char c = s[i];
bool neg = (c == '-' || c == '−') && i + 1 < s.Length && char.IsDigit(s[i + 1]);
if (!char.IsDigit(c) && !neg)
{
i++;
continue;
}
int st = neg ? i + 1 : i;
int j = st;
while (j < s.Length && (char.IsDigit(s[j]) || s[j] == '.')) j++;
float v;
if (TryNum(s.Substring(st, j - st), out v)) res.Add(neg ? -v : v);
i = j;
}
return res;
}
public static List<string> SplitList(string s)
{
var res = new List<string>();
if (string.IsNullOrEmpty(s)) return res;
foreach (var p in s.Split(';'))
{
var t = p.Trim();
if (t.Length > 0) res.Add(t);
}
return res;
}
}
/// <summary>표 1줄 — 칸 이름으로 읽는다(접두어 n_ 정수 · f_ 실수 · s_ 문자 · l_ 목록 · b_ 0/1 · e_ 낱말).</summary>
public class ContentRow
{
public readonly string File;
readonly Dictionary<string, string> d;
public ContentRow(string file, Dictionary<string, string> d)
{
File = file;
this.d = d;
}
public bool Has(string k)
{
return d.ContainsKey(k);
}
public string S(string k)
{
string v;
return d.TryGetValue(k, out v) ? v : "";
}
public float F(string k, float def = 0f)
{
float v;
var s = S(k);
return s.Length > 0 && ContentTables.TryNum(s, out v) ? v : def;
}
public int I(string k, int def = 0)
{
float v;
var s = S(k);
return s.Length > 0 && ContentTables.TryNum(s, out v) ? Mathf.RoundToInt(v) : def;
}
public bool B(string k)
{
var s = S(k);
return s == "1" || s == "true" || s == "TRUE";
}
public List<string> L(string k)
{
return ContentTables.SplitList(S(k));
}
public List<float> LF(string k)
{
var res = new List<float>();
foreach (var p in L(k))
{
float v;
if (ContentTables.TryNum(p, out v)) res.Add(v);
}
return res;
}
/// <summary>파일 줄 번호(오류 안내).</summary>
public string Line
{
get { return File + ".csv 줄 " + S("#"); }
}
}
}