249 lines
9.9 KiB
C#
249 lines
9.9 KiB
C#
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
namespace TKS
|
||
{
|
||
/// <summary>
|
||
/// 컨텐츠 모드 배치 표 1줄(개발 요청서 A-2 · 칸 = 1장 학습 판 tutorial_layout 과 같음 + s_tag · n_spawn_turn · s_name_ko).
|
||
/// 좌표 = 전장 20 × 32 · 가운데 0,0 · 아군이 아래. e_side = ally · ally_slot · npc · enemy · gimmick · mark · ref.
|
||
/// </summary>
|
||
public class ContentLayoutRow
|
||
{
|
||
public int slot;
|
||
public string side = "";
|
||
public string unitId = "";
|
||
public string type = "";
|
||
public string gimmickId = "";
|
||
public string shape = "";
|
||
public Vector2 pos;
|
||
public float wOrR;
|
||
public float h;
|
||
public float hpMult = 1f;
|
||
public float atkMult = 1f;
|
||
public bool boss;
|
||
public bool general;
|
||
public string tag = "";
|
||
public int spawnTurn;
|
||
public string nameKo = "";
|
||
public string line = "";
|
||
/// <summary>연의 전기 = 그 적의 타격 횟수(scenario_layout n_hits · 비면 scenario_tune 역할값).</summary>
|
||
public int hits;
|
||
|
||
public bool HasHits
|
||
{
|
||
get { return hits > 0; }
|
||
}
|
||
|
||
public static ContentLayoutRow From(ContentRow r)
|
||
{
|
||
return new ContentLayoutRow
|
||
{
|
||
slot = r.I("n_slot"),
|
||
side = r.S("e_side"),
|
||
unitId = r.S("s_unit_id"),
|
||
type = r.S("e_type"),
|
||
gimmickId = r.S("s_gimmick_id"),
|
||
shape = r.S("e_shape"),
|
||
pos = new Vector2(r.F("f_x"), r.F("f_y")),
|
||
wOrR = r.F("f_w_or_r"),
|
||
h = r.F("f_h"),
|
||
hpMult = r.F("f_hp_mult", 1f),
|
||
atkMult = r.F("f_atk_mult", 1f),
|
||
boss = r.B("b_boss"),
|
||
general = r.B("b_general"),
|
||
tag = r.S("s_tag"),
|
||
spawnTurn = r.I("n_spawn_turn"),
|
||
nameKo = r.S("s_name_ko"),
|
||
line = r.Line,
|
||
hits = r.I("n_hits"),
|
||
};
|
||
}
|
||
|
||
public bool HasType
|
||
{
|
||
get { return type.Length > 0; }
|
||
}
|
||
|
||
public UnitType UnitType
|
||
{
|
||
get
|
||
{
|
||
UnitType t;
|
||
UnitTypeInfo.TryParseKey(type, out t);
|
||
return t;
|
||
}
|
||
}
|
||
|
||
/// <summary>기믹 배치(모양 = circle | rect) — 기믹 레이어 생성용.</summary>
|
||
public GimmickPlacement Placement()
|
||
{
|
||
return new GimmickPlacement
|
||
{
|
||
stage = "", gimmickId = gimmickId,
|
||
shape = shape == "rect" ? GimmickShapeType.Rect : GimmickShapeType.Circle,
|
||
cx = pos.x, cy = pos.y, wOrR = wOrR, h = h, rot = 0f,
|
||
};
|
||
}
|
||
}
|
||
|
||
/// <summary>배치 표 읽기 · 기믹 놓기 공용(병법 훈련 · 연의 전기 · 보급전 자리 표).</summary>
|
||
public static class ContentLayout
|
||
{
|
||
/// <summary>표에서 키 칸(keyCol) 값이 key 인 줄(n_slot 순).</summary>
|
||
public static List<ContentLayoutRow> Rows(string file, string keyCol, string key)
|
||
{
|
||
var res = new List<ContentLayoutRow>();
|
||
foreach (var r in ContentTables.Rows(file))
|
||
if (r.S(keyCol) == key) res.Add(ContentLayoutRow.From(r));
|
||
res.Sort((a, b) => a.slot.CompareTo(b.slot));
|
||
return res;
|
||
}
|
||
|
||
/// <summary>기믹 1개를 전장에 놓는다(정의가 없으면 오류 기록 후 null).</summary>
|
||
public static GimmickInstance SpawnGimmick(GimmickLayer layer, ContentLayoutRow r)
|
||
{
|
||
if (layer == null || r == null) return null;
|
||
var db = GimmickTables.Db;
|
||
var def = db != null ? db.Get(r.gimmickId) : null;
|
||
if (def == null)
|
||
{
|
||
ContentTables.Errors.Add(r.line + ": 기믹 정의 없음 " + r.gimmickId + " (gimmicks.csv)");
|
||
return null;
|
||
}
|
||
return layer.Spawn(def, r.Placement(), false);
|
||
}
|
||
|
||
/// <summary>배치 표의 적 줄 → 연무장 적 편성(기준 수치 = ContentEnemyRef · 배율 = 표 f_hp_mult · f_atk_mult).</summary>
|
||
public static BalanceConfig.EnemySpawn Enemy(BalanceConfig cfg, int refChapter, ContentLayoutRow r)
|
||
{
|
||
float hp, atk;
|
||
string art;
|
||
ContentEnemyRef.Of(cfg, refChapter, r.UnitType, r.boss, r.general, out hp, out atk, out art);
|
||
return new BalanceConfig.EnemySpawn
|
||
{
|
||
name = r.nameKo.Length > 0 ? r.nameKo : UnitTypeInfo.Korean(r.UnitType),
|
||
type = r.UnitType, position = r.pos, hpMult = hp * r.hpMult, atkMult = atk * r.atkMult,
|
||
isBoss = r.boss, isGeneral = r.general || r.boss, art = art,
|
||
};
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 컨텐츠 모드 적 수치의 기준(개발 요청서 §H-2 — 기획 식 = unit_base_stats × stage_enemy × enemy_roles 는 게임에 아직 없음).
|
||
/// 기획 세션 답이 오기 전 임시(2026-11-17 질문 보냄): 「그 장의 마지막 일반 스테이지의 실제 게임 적」 = 병종 기본값(BalanceConfig) × 그 스테이지 적의 배율.
|
||
/// 식을 바꾸면 이 함수 하나만 고친다.
|
||
/// </summary>
|
||
public static class ContentEnemyRef
|
||
{
|
||
/// <summary>그 장의 마지막 일반(normal) 스테이지 · 없으면 그 장 마지막 스테이지 · 장이 없으면 가장 가까운 아래 장.</summary>
|
||
public static BalanceConfig.StageDef RefStage(BalanceConfig cfg, int chapter)
|
||
{
|
||
if (cfg == null || cfg.stages == null) return null;
|
||
for (int ch = Mathf.Max(1, chapter); ch >= 1; ch--)
|
||
{
|
||
BalanceConfig.StageDef lastNormal = null, last = null;
|
||
foreach (var s in cfg.stages)
|
||
{
|
||
if (s.chapter != ch) continue;
|
||
if (last == null || s.stage > last.stage) last = s;
|
||
if (s.kind == StageKind.Normal && (lastNormal == null || s.stage > lastNormal.stage)) lastNormal = s;
|
||
}
|
||
if (lastNormal != null) return lastNormal;
|
||
if (last != null) return last;
|
||
}
|
||
return null;
|
||
}
|
||
|
||
/// <summary>그 장의 마지막 스테이지(보스 판 포함 · 삼형제 · 허수아비 기준).</summary>
|
||
public static BalanceConfig.StageDef LastStage(BalanceConfig cfg, int chapter)
|
||
{
|
||
if (cfg == null || cfg.stages == null) return null;
|
||
BalanceConfig.StageDef last = null;
|
||
foreach (var s in cfg.stages)
|
||
if (s.chapter == chapter && (last == null || s.stage > last.stage)) last = s;
|
||
return last ?? RefStage(cfg, chapter);
|
||
}
|
||
|
||
/// <summary>기준 배율(체력 · 공격력)과 그림 — 병사 = 그 스테이지의 같은 병종 병사 · 무장 = 무장 · 보스 = 보스.</summary>
|
||
public static void Of(BalanceConfig cfg, int chapter, UnitType type, bool boss, bool general, out float hp, out float atk, out string art)
|
||
{
|
||
Of(RefStage(cfg, chapter), cfg, type, boss, general, out hp, out atk, out art);
|
||
}
|
||
|
||
public static void Of(BalanceConfig.StageDef st, BalanceConfig cfg, UnitType type, bool boss, bool general, out float hp, out float atk, out string art)
|
||
{
|
||
hp = atk = 1f;
|
||
art = "";
|
||
if (st == null) return;
|
||
BalanceConfig.EnemySpawn same = null, anySoldier = null, gen = null, bossSpawn = null;
|
||
foreach (var e in st.enemies)
|
||
{
|
||
if (e.isBoss)
|
||
{
|
||
if (bossSpawn == null) bossSpawn = e;
|
||
continue;
|
||
}
|
||
if (e.isGeneral)
|
||
{
|
||
if (gen == null) gen = e;
|
||
continue;
|
||
}
|
||
if (anySoldier == null) anySoldier = e;
|
||
if (same == null && e.type == type) same = e;
|
||
}
|
||
string prefix = SoldierPrefix(same ?? anySoldier);
|
||
art = prefix.Length > 0 ? prefix + "_" + UnitTypeInfo.Key(type) : "";
|
||
if (boss)
|
||
{
|
||
if (bossSpawn != null)
|
||
{
|
||
hp = bossSpawn.hpMult;
|
||
atk = bossSpawn.atkMult;
|
||
}
|
||
else
|
||
{
|
||
hp = cfg.bossGeneralHpMult;
|
||
atk = cfg.bossGeneralAtkMult;
|
||
}
|
||
return;
|
||
}
|
||
if (general)
|
||
{
|
||
if (gen != null)
|
||
{
|
||
hp = gen.hpMult;
|
||
atk = gen.atkMult;
|
||
}
|
||
else
|
||
{
|
||
hp = cfg.eliteGeneralHpMult;
|
||
atk = cfg.eliteGeneralAtkMult;
|
||
}
|
||
return;
|
||
}
|
||
if (same != null)
|
||
{
|
||
hp = same.hpMult;
|
||
atk = same.atkMult;
|
||
}
|
||
}
|
||
|
||
/// <summary>병사 그림 접두(「hgj_infantry」 → 「hgj」).</summary>
|
||
static string SoldierPrefix(BalanceConfig.EnemySpawn e)
|
||
{
|
||
if (e == null || string.IsNullOrEmpty(e.art)) return "";
|
||
int i = e.art.LastIndexOf('_');
|
||
return i > 0 ? e.art.Substring(0, i) : e.art;
|
||
}
|
||
|
||
/// <summary>그 병종의 기준 체력(병종 기본값 × 기준 배율 · 보스 = × bossHpMult) — 허수아비 · 판정 목표 계산.</summary>
|
||
public static int Hp(BalanceConfig cfg, BalanceConfig.StageDef st, UnitType type, bool boss)
|
||
{
|
||
float hp, atk;
|
||
string art;
|
||
Of(st, cfg, type, boss, false, out hp, out atk, out art);
|
||
return Mathf.Max(1, Mathf.RoundToInt(cfg.GetStats(type).maxHp * hp * (boss ? cfg.bossHpMult : 1f)));
|
||
}
|
||
}
|
||
}
|