1456 lines
73 KiB
C#
1456 lines
73 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using TKS.OutGame;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using static TKS.ScenarioUi;
|
||
|
||
namespace TKS
|
||
{
|
||
/// <summary>
|
||
/// 시나리오 이벤트 연출(2026-11-18 PD 「연의전기의 각 시나리오 이벤트를 기획 및 제작 · 1장 도원결의부터」 · 요청서 `연의전기_이벤트_요청서.md` §4).
|
||
/// 표 = scenario_event.csv(한 줄 = 명령 하나 · s_event_id 묶음 · n_order 순 차례 실행) · 이름표 = scenario_actor.csv · 머리 위 표시 = scenario_emote.csv ·
|
||
/// 값 = scenario_event_config.csv(C45 · 코드에 값 없음) · 말풍선 = ScenarioUi.Say(보스 등장과 같은 PD 확정 시안).
|
||
/// 발동 = stage_start(판이 놓인 직후 · 학습 안내 전 · Setup = 조작 잠금) · win(승리 직후 · 결과·결말 카드 전) · 처음 깰 때만(다시 하기 = 건너뜀) · 가상 실행·연무장 모드 제외.
|
||
/// 배우 = slot<N>(학습 판 배치 표 n_slot) · 영웅 id(그 판의 아군·구출 대상) · extra 로 만든 이름(연출 전용 · 끝나면 사라짐).
|
||
/// 건너뛰기 = 남은 명령을 기다림 없이 끝 상태로 적용(자리 · 숨김 · 바닥 · 기절) → stage_start 는 끝에 판 유닛을 시작 자리·보임으로 되돌림(요청서 약속 3).
|
||
/// </summary>
|
||
public class ScenarioEvent : MonoBehaviour
|
||
{
|
||
static ScenarioEvent current;
|
||
|
||
/// <summary>연출 중인가(테스트·캡처 확인용).</summary>
|
||
public static bool Running
|
||
{
|
||
get { return current != null; }
|
||
}
|
||
|
||
class Actor
|
||
{
|
||
public string key;
|
||
public Unit unit;
|
||
public GameObject extra;
|
||
public FrameAnimator anim;
|
||
public SpriteRenderer shape;
|
||
public string name;
|
||
public Color tag;
|
||
public bool artLeft; // 연출 인물 그림이 왼쪽을 보고 그려짐(meta.json faceLeft)
|
||
|
||
public Vector2 Pos
|
||
{
|
||
get { return unit != null ? unit.Position : (Vector2)extra.transform.position; }
|
||
set
|
||
{
|
||
if (unit != null) unit.Position = value;
|
||
else extra.transform.position = new Vector3(value.x, value.y, 0f);
|
||
}
|
||
}
|
||
|
||
public Vector2 Head
|
||
{
|
||
get
|
||
{
|
||
if (unit != null) return ScenarioUi.Head(unit);
|
||
return Pos + new Vector2(0f, anim != null ? anim.TopHeight : 0.8f);
|
||
}
|
||
}
|
||
|
||
/// <summary>쓰러뜨릴 그림(유닛 = 아트 묶음 · 도형 유닛 = View · 연출 인물 = 그림).</summary>
|
||
public Transform Body
|
||
{
|
||
get
|
||
{
|
||
if (unit != null) return unit.View == null ? unit.transform : (unit.View.Anim != null ? unit.View.Anim.transform : unit.View.transform);
|
||
return anim != null ? anim.transform : extra.transform;
|
||
}
|
||
}
|
||
|
||
public GameObject Visual
|
||
{
|
||
get { return unit != null ? (unit.View != null ? unit.View.gameObject : unit.gameObject) : extra; }
|
||
}
|
||
|
||
/// <summary>연출 안 방향 = 앞모습(아래 좌·우)만 — 가로 성분으로 좌우만 바꾼다(위로 걸어도 뒷모습으로 돌지 않음 · 뒷모습 = face 명령 back · 2026-11-18 PD).</summary>
|
||
public void Face(Vector2 dir)
|
||
{
|
||
if (unit != null)
|
||
{
|
||
if (unit.View != null) unit.View.SetFacing(new Vector2(Mathf.Abs(dir.x) > 0.01f ? Mathf.Sign(dir.x) : 0f, -1f));
|
||
return;
|
||
}
|
||
if (anim != null && Mathf.Abs(dir.x) > 0.01f) anim.Renderer.flipX = (dir.x < 0f) != artLeft;
|
||
}
|
||
|
||
/// <summary>뒷모습(위 좌·우) — face 명령 s_arg back · back_left · back_right 만.</summary>
|
||
public void FaceBack(float x)
|
||
{
|
||
if (unit != null && unit.View != null) unit.View.SetFacing(new Vector2(x, 1f));
|
||
else if (anim != null && Mathf.Abs(x) > 0.01f) anim.Renderer.flipX = (x < 0f) != artLeft;
|
||
}
|
||
}
|
||
|
||
BattleManager battle;
|
||
CameraController cc;
|
||
BalanceConfig.StageDef stage;
|
||
string trigger;
|
||
Action onDone;
|
||
List<List<ScenarioData.EventRow>> groups;
|
||
readonly TalkState st = new TalkState();
|
||
readonly Dictionary<string, Actor> actors = new Dictionary<string, Actor>();
|
||
/// <summary>이 연출에서 hide 한 뒤 다시 show 하지 않은 판 유닛 — 시작 연출이 끝나도 숨긴 채(다음 연출의 show 가 보임 · 2026-11-19 PD 1막 「황건적 한명이 더 나타난」 지원 건달).</summary>
|
||
// 연출이 숨긴 판 유닛 = 아직 나타나지 않음(연출 사이에 이어짐 · show 가 풂) — 행동 · 표적 · 아군 턴 끝 판정에서 빠짐(BattleManager.CanAct · PrologueRules · 2026-11-19 PD 2막 「나중에 나타나는 기병 · 포위군 · 유비 · 장비」)
|
||
static readonly HashSet<Unit> keptHidden = new HashSet<Unit>();
|
||
|
||
/// <summary>연출이 숨겨 아직 나타나지 않은 유닛인가(행동 · 선택 · 적의 표적에서 빠짐).</summary>
|
||
public static bool Absent(Unit u)
|
||
{
|
||
return u != null && keptHidden.Contains(u);
|
||
}
|
||
|
||
/// <summary>새 판 = 숨김 기억 · 남겨 둔 연출 인물을 비움(BattleManager 판 준비).</summary>
|
||
public static void ClearAbsent()
|
||
{
|
||
keptHidden.Clear();
|
||
foreach (var a in keptExtras.Values)
|
||
if (a != null && a.extra != null) Destroy(a.extra);
|
||
keptExtras.Clear();
|
||
}
|
||
|
||
// keep 명령으로 남겨 둔 연출 인물 = 이 연출이 끝나도(전투 시작에도) 걸어 나가지 않고 다음 연출이 같은 이름으로 씀(2026-11-19 PD 2막 「마을 사람들이 관우에게 감사」 = 시작 연출의 마을 사람이 전투 시작에 사라져 감사 장면이 빠졌던 것)
|
||
static readonly Dictionary<string, Actor> keptExtras = new Dictionary<string, Actor>();
|
||
readonly Dictionary<string, Vector2> points = new Dictionary<string, Vector2>(); // line 명령이 정한 자리(line1 · line2 …) — move · show 의 s_arg at:이름
|
||
readonly Dictionary<Unit, Vector2> startPos = new Dictionary<Unit, Vector2>();
|
||
// 기절 상태 = 연출 사이에 이어짐(stage_start 의 keep 기절 → 그 판 전투 동안 유지 → win 연출의 wake 가 풂) · 유닛이 사라지면 키가 null
|
||
static readonly Dictionary<Transform, Quaternion> fainted = new Dictionary<Transform, Quaternion>();
|
||
static readonly Dictionary<SpriteRenderer, Color> faintTint = new Dictionary<SpriteRenderer, Color>();
|
||
static readonly HashSet<Transform> faintKeep = new HashSet<Transform>();
|
||
readonly List<GameObject> temp = new List<GameObject>();
|
||
readonly List<ScenarioData.EventRow> flat = new List<ScenarioData.EventRow>();
|
||
readonly HashSet<ScenarioData.EventRow> pulled = new HashSet<ScenarioData.EventRow>();
|
||
int cursor;
|
||
Vector3 camStart;
|
||
float viewStart;
|
||
|
||
RectTransform root, fx;
|
||
GameObject ambient;
|
||
|
||
/// <summary>장면 연출(벚꽃잎 등 · 로비와 같은 형식의 표) 만들기 — (부모, Resources 표 경로) → 만든 층. OutGame(LobbyAmbient)이 등록한다(Runtime 은 OutGame 을 모름 · 2026-11-19 PD 도원결의 벚꽃).</summary>
|
||
public static Func<RectTransform, string, GameObject> AmbientMaker;
|
||
|
||
/// <summary>move 의 s_arg dust = 걷는 동안 발밑 흙먼지 · skill_vfx.csv 의 이 키 depart 행(2026-11-19 PD 1장 3막 「흙먼지를 추가해서 이동이 자연스럽게」).</summary>
|
||
const string DustKey = "scenario_walk_dust";
|
||
Image fade;
|
||
Image captionBand;
|
||
Text captionText;
|
||
Button skipBtn;
|
||
|
||
static readonly Color AllyTag = new Color(0.16f, 0.36f, 0.72f);
|
||
static readonly Color EnemyTag = new Color(0.75f, 0.16f, 0.12f);
|
||
static readonly Color ExtraTag = new Color(0.47f, 0.33f, 0.18f);
|
||
|
||
static float C(string k)
|
||
{
|
||
return ScenarioData.EvCfg(k);
|
||
}
|
||
|
||
bool skip
|
||
{
|
||
get { return st.Skip; }
|
||
}
|
||
|
||
/// <summary>켜짐 규칙 = 학습 판과 같음(Auto = 메모리 세이브인 자동 테스트·검증 캡처에서는 꺼짐 · 1-1 을 일반 전투로 쓰는 기존 테스트 보호 · 연출 확인 = ForceOn).</summary>
|
||
public static TutorialMode Mode = TutorialMode.Auto;
|
||
|
||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||
static void ResetStatics()
|
||
{
|
||
Mode = TutorialMode.Auto;
|
||
current = null;
|
||
replayChapter = replayStage = 0;
|
||
keptHidden.Clear();
|
||
keptExtras.Clear();
|
||
fainted.Clear();
|
||
faintTint.Clear();
|
||
faintKeep.Clear();
|
||
}
|
||
|
||
public static bool Enabled
|
||
{
|
||
get { return Mode == TutorialMode.ForceOn || (Mode == TutorialMode.Auto && !SaveStore.MemoryOnly); }
|
||
}
|
||
|
||
/// <summary>이 판 · 이 발동에 틀 연출이 있는가(켜짐 · 표 행 있음 · 처음 깸 · 가상 실행·연무장 아님 · slot 배우가 있으면 학습 판 배치가 켜져 있을 때만).</summary>
|
||
static int replayChapter, replayStage;
|
||
|
||
/// <summary>
|
||
/// 다음에 이 판을 시작할 때 이미 깬 판이어도 연출을 다시 튼다(연의 전기 서장 「도원결의」 출전 = 이야기를 보러 들어옴 · 2026-11-18 PD 「결과물을 보고 피드백」).
|
||
/// 다른 판이 시작되면 풀린다.
|
||
/// </summary>
|
||
public static void AllowReplay(int chapter, int stage)
|
||
{
|
||
replayChapter = chapter;
|
||
replayStage = stage;
|
||
}
|
||
|
||
/// <summary>시나리오 표 열쇠 — 연의 모드 전투 = (편 id, 막) · 출정 = ("", 장, 판) · 그 밖 모드 = null(표 안 씀).</summary>
|
||
public static bool KeyOf(BattleManager bm, BalanceConfig.StageDef stage, out string battleId, out int chapter, out int st)
|
||
{
|
||
battleId = "";
|
||
chapter = stage != null ? stage.chapter : 0;
|
||
st = stage != null ? stage.stage : 0;
|
||
if (bm == null || stage == null) return false;
|
||
if (bm.Mode == null) return true;
|
||
var r = bm.Mode.rules;
|
||
if (r == null || string.IsNullOrEmpty(r.ScenarioBattleId)) return false;
|
||
battleId = r.ScenarioBattleId;
|
||
st = r.ScenarioAct;
|
||
return true;
|
||
}
|
||
|
||
static List<List<ScenarioData.EventRow>> GroupsFor(BattleManager bm, BalanceConfig.StageDef stage, string trigger, int turn)
|
||
{
|
||
string bid;
|
||
int ch, st;
|
||
if (!KeyOf(bm, stage, out bid, out ch, out st)) return new List<List<ScenarioData.EventRow>>();
|
||
return ScenarioData.Events(bid, ch, st, trigger, turn);
|
||
}
|
||
|
||
public static bool Wants(BattleManager bm, BalanceConfig.StageDef stage, string trigger, bool cleared, int turn = 0)
|
||
{
|
||
if (stage != null && trigger == "stage_start" && (stage.chapter != replayChapter || stage.stage != replayStage)) replayChapter = replayStage = 0;
|
||
if (cleared && stage != null && stage.chapter == replayChapter && stage.stage == replayStage) cleared = false;
|
||
if (!Enabled || Sim.Active || bm == null || stage == null || cleared) return false;
|
||
var g = GroupsFor(bm, stage, trigger, turn);
|
||
if (g.Count == 0) return false;
|
||
foreach (var list in g)
|
||
foreach (var e in list)
|
||
if ((e.actor.StartsWith("slot") || e.target.StartsWith("slot")) && bm.Tutorial == null && !(bm.Mode != null && bm.Mode.rules != null && bm.Mode.rules.EventSlots)) return false;
|
||
return true;
|
||
}
|
||
|
||
public static void Begin(BattleManager bm, BalanceConfig.StageDef stage, string trigger, Action onDone, int turn = 0)
|
||
{
|
||
Abort();
|
||
var cam = FindFirstObjectByType<CameraController>();
|
||
if (cam == null || cam.Cam == null)
|
||
{
|
||
onDone?.Invoke();
|
||
return;
|
||
}
|
||
var go = new GameObject("ScenarioEventUI");
|
||
var ev = go.AddComponent<ScenarioEvent>();
|
||
current = ev;
|
||
ev.battle = bm;
|
||
ev.RefreshViews(); // 연출 시작 = 행동을 마친 유닛도 밝게(UnitView.Refresh 의 ScenarioEvent.Running)
|
||
ev.cc = cam;
|
||
ev.stage = stage;
|
||
ev.trigger = trigger;
|
||
ev.onDone = onDone;
|
||
ev.groups = GroupsFor(bm, stage, trigger, turn);
|
||
ev.Build();
|
||
ev.StartCoroutine(ev.Run());
|
||
}
|
||
|
||
/// <summary>
|
||
/// 연의 전기 유닛 기본 방향 = 앞모습(아래)으로 판 가운데 쪽을 봄(가운데 왼쪽 = 오른쪽 아래 · 오른쪽 = 왼쪽 아래)
|
||
/// — 2026-11-18 PD 「연의 전기에서 유닛의 기본 방향은 좌/또는 우측 아래(윗 방향이면 뒷모습만 보여) · 뒷모습이 필요할 때만 위」.
|
||
/// 시나리오 이벤트 시작 · 연의 전기 전투 시작(ScenarioRules.OnBegin)에 부른다. 전투 중 이동 방향 규칙(PD #1082)은 그대로.
|
||
/// </summary>
|
||
public static void FaceFrontAll(BattleManager bm)
|
||
{
|
||
if (bm == null || Sim.Active) return;
|
||
foreach (var f in new[] { Faction.Player, Faction.Enemy })
|
||
foreach (var u in bm.AliveUnits(f))
|
||
{
|
||
if (u.View == null) continue;
|
||
// 가장 가까운 상대편 쪽(가로) — 없으면 판 가운데 쪽 · 2026-11-18 PD 「장비가 적들을 바라보지 않고 엉뚱한 방향」
|
||
Unit near = null;
|
||
float best = float.MaxValue;
|
||
foreach (var o in bm.AliveUnits(f == Faction.Player ? Faction.Enemy : Faction.Player))
|
||
{
|
||
float dd = (o.Position - u.Position).sqrMagnitude;
|
||
if (dd < best) { best = dd; near = o; }
|
||
}
|
||
float dx = near != null ? near.Position.x - u.Position.x : -u.Position.x;
|
||
u.View.SetFacing(new Vector2(Mathf.Abs(dx) > 0.05f ? Mathf.Sign(dx) : (u.View.FacingLeft ? -1f : 1f), -1f));
|
||
}
|
||
}
|
||
|
||
Actor lastSpeaker;
|
||
|
||
/// <summary>
|
||
/// 말할 때 = 화자와 상대가 서로 마주 봄(앞모습 · 가로만) — 상대 = say 의 s_target(말을 거는 상대 · 2026-11-18 PD 「첫 대사를 하는 황건적은 왼쪽 아래」) ·
|
||
/// 없으면 앞 화자 · 앞 화자도 없으면 가장 가까운 상대편 쪽.
|
||
/// </summary>
|
||
void FaceTalk(Actor a, Actor to)
|
||
{
|
||
if (a == null) return;
|
||
var other = to != null && to != a && to.Visual != null && to.Visual.activeInHierarchy ? to
|
||
: lastSpeaker != null && lastSpeaker != a && lastSpeaker.Visual != null && lastSpeaker.Visual.activeInHierarchy ? lastSpeaker : null;
|
||
if (other != null)
|
||
{
|
||
float dx = other.Pos.x - a.Pos.x;
|
||
if (Mathf.Abs(dx) > 0.05f)
|
||
{
|
||
a.Face(new Vector2(dx, 0f));
|
||
other.Face(new Vector2(-dx, 0f));
|
||
}
|
||
}
|
||
else if (a.unit != null)
|
||
{
|
||
Unit near = null;
|
||
float best = float.MaxValue;
|
||
foreach (var o in battle.AliveUnits(a.unit.Faction == Faction.Player ? Faction.Enemy : Faction.Player))
|
||
{
|
||
float dd = (o.Position - a.Pos).sqrMagnitude;
|
||
if (dd < best) { best = dd; near = o; }
|
||
}
|
||
if (near != null && Mathf.Abs(near.Position.x - a.Pos.x) > 0.05f) a.Face(new Vector2(near.Position.x - a.Pos.x, 0f));
|
||
}
|
||
lastSpeaker = a;
|
||
}
|
||
|
||
/// <summary>지금 실행 중인 줄(테스트·캡처 확인용 · 끝나면 int.MaxValue).</summary>
|
||
public static string CurrentId = "";
|
||
public static int CurrentOrder;
|
||
|
||
/// <summary>테스트·캡처: 화면 누름 1회.</summary>
|
||
public static void TapForTest()
|
||
{
|
||
if (current != null) current.st.Taps++;
|
||
}
|
||
|
||
/// <summary>테스트: 건너뛰기 버튼.</summary>
|
||
public static void SkipForTest()
|
||
{
|
||
if (current != null) current.st.Skip = true;
|
||
}
|
||
|
||
/// <summary>진행 중 연출을 바로 치움(전투 재시작 · 월드맵 복귀).</summary>
|
||
public static void Abort()
|
||
{
|
||
if (current == null) return;
|
||
current.Cleanup(false);
|
||
Destroy(current.gameObject);
|
||
current = null;
|
||
}
|
||
|
||
// ---------- 화면 ----------
|
||
|
||
void Build()
|
||
{
|
||
UiLayer.Root(gameObject, cc.Cam, 460, 0.38f, UiLayer.Reference, UiRate.Event);
|
||
root = (RectTransform)transform;
|
||
var catcher = Full("Tap", root, null, new Color(0f, 0f, 0f, 0f));
|
||
catcher.raycastTarget = true;
|
||
catcher.gameObject.AddComponent<Button>().onClick.AddListener(() => st.Taps++);
|
||
fx = UiLayer.Group("Fx", root, UiRate.Frame);
|
||
fade = Full("Fade", fx, null, new Color(0f, 0f, 0f, 0f));
|
||
// 위아래 검은 띠(연출 화면 · 재화 바·전투 HUD 를 가림 · 보스 등장과 같은 방식)
|
||
float bar = UiLayer.Reference.y * C("letterbox_ratio");
|
||
Img("BarTop", fx, null, Color.black, new Vector2(0f, 1f), new Vector2(1f, 1f), new Vector2(0.5f, 1f), Vector2.zero, new Vector2(0f, bar));
|
||
Img("BarBottom", fx, null, Color.black, new Vector2(0f, 0f), new Vector2(1f, 0f), new Vector2(0.5f, 0f), Vector2.zero, new Vector2(0f, bar));
|
||
float bandH = C("caption_band_height");
|
||
captionBand = Img("Caption", fx, null, new Color(0f, 0f, 0f, 0f), new Vector2(0f, 1f), new Vector2(1f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -C("caption_band_top")), new Vector2(0f, bandH));
|
||
captionText = Txt(captionBand.transform, "", Mathf.RoundToInt(C("caption_font_size")), new Color(1f, 0.95f, 0.85f, 0f), TextAnchor.MiddleCenter, Vector2.zero, new Vector2(UiLayer.Reference.x - 80f, bandH), UISkin.TitleFont);
|
||
var sb = Img("Skip", root, null, new Color(0f, 0f, 0f, 0.6f), new Vector2(1f, 1f), new Vector2(1f, 1f), new Vector2(1f, 1f), new Vector2(-40f, -60f), new Vector2(190f, 80f));
|
||
sb.raycastTarget = true;
|
||
skipBtn = sb.gameObject.AddComponent<Button>();
|
||
skipBtn.onClick.AddListener(() => st.Skip = true);
|
||
Txt(sb.transform, "건너뛰기 >>", 34, Color.white, TextAnchor.MiddleCenter, Vector2.zero, new Vector2(190f, 80f), UISkin.TitleFont);
|
||
sb.gameObject.SetActive(false);
|
||
}
|
||
|
||
// ---------- 흐름 ----------
|
||
|
||
readonly List<Canvas> hudHidden = new List<Canvas>();
|
||
|
||
/// <summary>연출 동안 전투 HUD(안내 줄 · 아래 패널 · 작은 지도)를 그리지 않음 — 끝나면 되돌림.</summary>
|
||
void HideHud(bool hide)
|
||
{
|
||
if (hide)
|
||
{
|
||
var hud = FindFirstObjectByType<BattleHUD>();
|
||
if (hud == null) return;
|
||
foreach (var c in hud.GetComponentsInChildren<Canvas>())
|
||
if (c.enabled)
|
||
{
|
||
c.enabled = false;
|
||
hudHidden.Add(c);
|
||
}
|
||
return;
|
||
}
|
||
foreach (var c in hudHidden)
|
||
if (c != null) c.enabled = true;
|
||
hudHidden.Clear();
|
||
}
|
||
|
||
IEnumerator Run()
|
||
{
|
||
camStart = cc.transform.position;
|
||
viewStart = cc.ViewHeight;
|
||
HideHud(true);
|
||
foreach (var u in battle.AliveUnits(Faction.Player)) startPos[u] = u.Position;
|
||
foreach (var u in battle.AliveUnits(Faction.Enemy)) startPos[u] = u.Position;
|
||
FaceFrontAll(battle);
|
||
StartCoroutine(SkipButtonLater());
|
||
flat.Clear();
|
||
foreach (var list in groups) flat.AddRange(list);
|
||
for (cursor = 0; cursor < flat.Count; cursor++)
|
||
{
|
||
var e = flat[cursor];
|
||
if (pulled.Contains(e)) continue; // 앞 move 가 미리 실행한 카메라 줄(focus)
|
||
CurrentId = e.id;
|
||
CurrentOrder = e.order;
|
||
yield return Do(e);
|
||
}
|
||
CurrentOrder = int.MaxValue;
|
||
yield return Return();
|
||
Cleanup(true);
|
||
var done = onDone;
|
||
onDone = null;
|
||
if (current == this) current = null;
|
||
RefreshViews(); // 연출이 끝남 = 행동을 마친 유닛을 다시 흐리게
|
||
Destroy(gameObject);
|
||
done?.Invoke();
|
||
}
|
||
|
||
IEnumerator SkipButtonLater()
|
||
{
|
||
float t = 0f, show = C("skip_show_after_sec");
|
||
while (t < show) { t += Time.unscaledDeltaTime; yield return null; }
|
||
if (skipBtn != null) skipBtn.gameObject.SetActive(true);
|
||
}
|
||
|
||
float Sec(ScenarioData.EventRow e, string key)
|
||
{
|
||
return float.IsNaN(e.sec) ? C(key) : Mathf.Max(0f, e.sec);
|
||
}
|
||
|
||
IEnumerator Do(ScenarioData.EventRow e)
|
||
{
|
||
switch (e.cmd)
|
||
{
|
||
case "fade": yield return Fade(e.arg == "out", Sec(e, "fade_sec")); break;
|
||
case "caption": yield return Caption(e.text, Sec(e, "caption_sec")); break;
|
||
case "bg":
|
||
if (battle.Board != null && battle.Board.SetEventArt(e.arg) && e.arg != ScenarioProps.StageBg)
|
||
{
|
||
ScenarioProps.Clear(); // 다른 장소로 바뀜 = 이 판 소품 치움(3막 → 복숭아 동산)
|
||
ScenarioProps.ApplyBg(battle, e.arg); // 그 장소 소품(scenario_props s_battle_id = bg:<바닥 그림> · 2026-11-19 PD 도원결의 벚나무)
|
||
}
|
||
break;
|
||
case "hide":
|
||
{
|
||
var h = Get(e.actor);
|
||
if (h != null && h.unit != null)
|
||
{
|
||
keptHidden.Add(h.unit);
|
||
SetBody(h.unit, false); // 숨은 동안 = 부딪히지 않음(보이지 않는 장애물 X)
|
||
}
|
||
yield return Show(h, false, e, Sec(e, "show_sec"));
|
||
break;
|
||
}
|
||
case "show":
|
||
{
|
||
var h = Get(e.actor);
|
||
if (h != null && h.unit != null)
|
||
{
|
||
keptHidden.Remove(h.unit);
|
||
SetBody(h.unit, true);
|
||
}
|
||
yield return Show(h, true, e, Sec(e, "show_sec"));
|
||
break;
|
||
}
|
||
case "extra": MakeExtra(e); break;
|
||
case "line": Line(e); break;
|
||
case "keep": // 연출 인물을 남겨 둠(전투 시작에 걸어 나가지 않음 · 다음 연출이 같은 이름으로 씀)
|
||
{
|
||
var a = Get(e.actor);
|
||
if (a != null && a.extra != null)
|
||
{
|
||
temp.Remove(a.extra);
|
||
keptExtras[a.key] = a;
|
||
}
|
||
break;
|
||
}
|
||
case "npc": // 판 아군을 조작 불가(NPC · 반격 없음 · 아군 턴 끝 판정에서 빠짐)로 · s_arg 0 = 다시 조작(2026-11-19 PD 2막 = 출혈로 지친 관우 · 유비 · 장비가 싸움)
|
||
{
|
||
var a = Get(e.actor);
|
||
if (a != null && a.unit != null)
|
||
{
|
||
a.unit.Npc = e.arg != "0";
|
||
if (a.unit.View != null) a.unit.View.Refresh();
|
||
}
|
||
break;
|
||
}
|
||
case "move":
|
||
// s_arg nowait = 기다리지 않고 다음 줄로(여럿이 함께 걸음 · 카메라 그대로 · 2026-11-19 PD 3막 「나란히 걷다」 · 「나타나 둘러쌈」) — 끝은 wait 줄이나 기다리는 move 로 맞춘다
|
||
if (System.Array.IndexOf((e.arg ?? "").Split(';'), "nowait") >= 0) StartCoroutine(Move(Get(e.actor), e));
|
||
else yield return Move(Get(e.actor), e);
|
||
break;
|
||
case "face":
|
||
{
|
||
var a = Get(e.actor);
|
||
if (a == null) break;
|
||
bool left = e.arg == "left" || e.arg == "back_left";
|
||
if (e.arg == "back" || e.arg == "back_left" || e.arg == "back_right") a.FaceBack(e.arg == "back" ? 0f : (left ? -1f : 1f));
|
||
else a.Face(new Vector2(left ? -1f : 1f, 0f));
|
||
break;
|
||
}
|
||
case "say":
|
||
{
|
||
var a = Get(e.actor);
|
||
// s_target = 말을 거는 상대(서로 마주 봄) · s_arg keepface = 아무도 돌리지 않음(앞 줄 face 그대로 · 뒷모습 등) · onlyme = 말하는 쪽만 상대를 봄(2026-11-19 PD 2막 「관우가 주민 안부를 물을 때 오른쪽 위」)
|
||
var sayTok = (e.arg ?? "").Split(';');
|
||
if (System.Array.IndexOf(sayTok, "keepface") >= 0) { }
|
||
else if (System.Array.IndexOf(sayTok, "onlyme") >= 0)
|
||
{
|
||
var to = string.IsNullOrEmpty(e.target) ? null : Get(e.target);
|
||
if (a != null && to != null && Mathf.Abs(to.Pos.x - a.Pos.x) > 0.05f) a.Face(new Vector2(to.Pos.x - a.Pos.x, 0f));
|
||
}
|
||
else FaceTalk(a, string.IsNullOrEmpty(e.target) ? null : Get(e.target));
|
||
if (a != null && !skip) yield return Say(fx, root, cc.Cam, () => a.Head, a.name, a.tag, e.text, st);
|
||
break;
|
||
}
|
||
case "emote":
|
||
{
|
||
// s_arg = 표시 이름[;nowait] — nowait = 기다리지 않고 다음 줄(여럿에게 한꺼번에 · 2026-11-19 PD 3막 「적이 등장할 때 모든 유닛에게 느낌표」)
|
||
var et = (e.arg ?? "").Split(';');
|
||
if (System.Array.IndexOf(et, "nowait") >= 0)
|
||
{
|
||
var g = skip ? null : Glyph(Get(e.actor), et[0].Trim(), false);
|
||
if (g != null) StartCoroutine(EmoteLife(g, C("emote_sec")));
|
||
}
|
||
else yield return EmoteAt(Get(e.actor), e.arg, false);
|
||
break;
|
||
}
|
||
case "focus": yield return Focus(e); break;
|
||
case "attack": yield return Attack(Get(e.actor), Get(e.target), Sec(e, "attack_sec")); break;
|
||
case "hit":
|
||
{
|
||
var a = Get(string.IsNullOrEmpty(e.target) ? e.actor : e.target);
|
||
if (a != null && !skip)
|
||
{
|
||
if (a.unit != null && a.unit.View != null) a.unit.View.OnHit();
|
||
yield return Wait(C("hit_sec"));
|
||
}
|
||
break;
|
||
}
|
||
case "faint": Faint(Get(e.actor), true, e.arg == "keep"); if (!skip) yield return Wait(C("faint_sec")); break;
|
||
case "wake": Faint(Get(e.actor), false, false); Unstun(Get(e.actor)); break;
|
||
case "stun": // 전투의 기절 상태(스턴 이펙트 · 행동불가 표 · 그 판 전투 동안 · wake 가 풂) — 건너뛰어도 건다(끝 상태)
|
||
{
|
||
var a = Get(e.actor);
|
||
if (a != null && a.unit != null && battle.Gimmicks != null && !SkillStatus.Stunned(a.unit))
|
||
{
|
||
battle.Gimmicks.Stun(a.unit, Mathf.Max(1, Mathf.RoundToInt(C("downed_stun_turns"))), skip ? "" : e.text);
|
||
if (a.unit.View != null) a.unit.View.Refresh(); // 기절한 구출 대상 = 이제부터 흐리게(기절 전 = 밝게 · 2026-11-19 PD)
|
||
}
|
||
if (!skip) yield return Wait(C("faint_sec"));
|
||
break;
|
||
}
|
||
case "shake":
|
||
if (!skip)
|
||
{
|
||
float k = string.IsNullOrEmpty(e.arg) ? 1f : Num(e.arg, 1f);
|
||
cc.Shake(Sec(e, "shake_sec"), C("shake_base") * k);
|
||
}
|
||
break;
|
||
case "wait": yield return Wait(Sec(e, "wait_sec")); break;
|
||
// ---- 2026-11-18 PD 1막 · 2막 학습 연출 ----
|
||
case "tip": yield return Tip(e.text); break; // 가운데 설명 카드(누르면 닫힘)
|
||
case "ambient": Ambient(e.arg); break; // 화면 장면 연출(s_arg = Resources 표 경로 · 로비 표 형식 · off = 치움 · 2026-11-19 PD 도원결의 벚꽃)
|
||
case "vfx": // 스킬 이펙트(s_arg = 키:시점 · 예 guanping_a:cast = 관평 호위)
|
||
{
|
||
var a = Get(e.actor);
|
||
if (a != null && a.unit != null && !skip)
|
||
{
|
||
var p = (e.arg ?? "").Split(':');
|
||
SkillVfx.PlayOn(a.unit, p[0], p.Length > 1 ? p[1] : "cast");
|
||
yield return Wait(Sec(e, "wait_sec"));
|
||
}
|
||
break;
|
||
}
|
||
case "bleed": // 출혈 상태(s_arg = 턴;비율)
|
||
{
|
||
var a = Get(e.actor);
|
||
var p = (e.arg ?? "").Split(';');
|
||
if (a != null && a.unit != null && battle.Skills != null && e.arg == "0") battle.Skills.ClearBleed(a.unit); // s_arg 0 = 출혈 멈춤(2026-11-19 PD 2막 「장비가 적을 물리치고 나면 관우의 출혈이 멈춰야」)
|
||
else if (a != null && a.unit != null && battle.Skills != null) battle.Skills.ApplyBleedStatus(a.unit, Mathf.Max(1, Mathf.RoundToInt(Num(p[0], 2f))), p.Length > 1 ? Num(p[1], 0.5f) : 0.5f);
|
||
break;
|
||
}
|
||
case "hp": // 체력을 최대의 s_arg 비율로 깎음(맞는 모습 · 끝 상태)
|
||
{
|
||
var a = Get(e.actor);
|
||
if (a != null && a.unit != null && a.unit.IsAlive)
|
||
{
|
||
int want = Mathf.Max(1, Mathf.RoundToInt(a.unit.MaxHp * Mathf.Clamp01(Num(e.arg, 1f))));
|
||
if (a.unit.Hp > want) a.unit.TakeDamage(a.unit.Hp - want);
|
||
}
|
||
if (!skip) yield return Wait(C("hit_sec"));
|
||
break;
|
||
}
|
||
case "kill": // 판 유닛 쓰러뜨림(연출 속 처치) · 연출 인물 = 사라짐
|
||
{
|
||
var a = Get(e.actor);
|
||
if (a != null && a.unit != null && a.unit.IsAlive) a.unit.TakeDamage(a.unit.MaxHp * 10 + a.unit.Hp);
|
||
else if (a != null && a.extra != null) yield return Show(a, false, e, skip ? 0f : C("show_sec") + 0.3f);
|
||
if (!skip) yield return Wait(C("faint_sec"));
|
||
break;
|
||
}
|
||
case "roll": yield return Roll(Get(e.actor), e); break; // 기믹(바위)을 연출로 굴림 — 2026-11-19 PD 2막 「관우가 바위를 밀쳐 적을 처치」
|
||
case "tap":
|
||
st.Taps = 0;
|
||
while (!skip && st.Taps == 0) yield return null;
|
||
st.Taps = 0;
|
||
break;
|
||
}
|
||
}
|
||
|
||
static float Num(string s, float def)
|
||
{
|
||
float v;
|
||
return float.TryParse(s, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out v) ? v : def;
|
||
}
|
||
|
||
// ---------- 배우 ----------
|
||
|
||
Actor Get(string key)
|
||
{
|
||
if (string.IsNullOrEmpty(key)) return null;
|
||
Actor a;
|
||
if (actors.TryGetValue(key, out a)) return a;
|
||
if (keptExtras.TryGetValue(key, out a) && a.extra != null) // 앞 연출이 남겨 둔 연출 인물(keep)
|
||
{
|
||
actors[key] = a;
|
||
return a;
|
||
}
|
||
Unit u = null;
|
||
if (key.StartsWith("slot"))
|
||
{
|
||
int slot;
|
||
if (int.TryParse(key.Substring(4), out slot))
|
||
{
|
||
if (battle.Tutorial != null) u = battle.Tutorial.UnitAt(slot);
|
||
else if (battle.Mode != null && battle.Mode.rules != null) u = battle.Mode.rules.UnitAtSlot(slot); // 연의 편 1~ = 배치 표 n_slot(이름 없는 일반 병사 · 2026-11-19 PD)
|
||
}
|
||
}
|
||
else
|
||
{
|
||
foreach (var f in new[] { Faction.Player, Faction.Enemy })
|
||
foreach (var x in battle.AliveUnits(f))
|
||
if (u == null && (x.HeroId == key || x.ArtId == key)) u = x;
|
||
}
|
||
if (u == null)
|
||
{
|
||
Debug.LogWarning("[TKS] 시나리오 이벤트: 배우 없음 " + key + " (" + stage.chapter + "-" + stage.stage + ")");
|
||
return null;
|
||
}
|
||
string nm = ScenarioData.ActorName(stage.chapter, stage.stage, key);
|
||
a = new Actor { key = key, unit = u, name = nm.Length > 0 ? nm : u.DisplayName, tag = u.Faction == Faction.Enemy ? EnemyTag : AllyTag };
|
||
actors[key] = a;
|
||
return a;
|
||
}
|
||
|
||
void MakeExtra(ScenarioData.EventRow e)
|
||
{
|
||
var go = new GameObject("Ev_" + e.actor);
|
||
temp.Add(go);
|
||
var pos = e.HasPos ? new Vector2(e.x, e.y) : Vector2.zero;
|
||
go.transform.position = new Vector3(pos.x, pos.y, 0f);
|
||
var a = new Actor { key = e.actor, extra = go, tag = ExtraTag };
|
||
string nm = ScenarioData.ActorName(stage.chapter, stage.stage, e.actor);
|
||
a.name = nm.Length > 0 ? nm : e.actor;
|
||
var art = UnitArt.Load(e.arg);
|
||
if (art != null)
|
||
{
|
||
var ago = new GameObject("Art");
|
||
ago.transform.SetParent(go.transform, false);
|
||
a.anim = ago.AddComponent<FrameAnimator>();
|
||
a.artLeft = art.Meta != null && art.Meta.faceLeft;
|
||
a.anim.Setup(art, battle.Config.unitArtHeight, 0, battle.Config.mountedArtMaxTop);
|
||
a.anim.SetIdle("front_idle");
|
||
a.anim.PlayIdle();
|
||
a.Face(Vector2.left); // 연출 인물 기본 방향 = 왼쪽 고정(그림이 그려진 방향과 무관 · 상황에 맞는 방향은 face · say 상대 · move 가 바꿈 · 2026-11-19 PD)
|
||
}
|
||
else
|
||
{
|
||
Debug.LogWarning("[TKS] 시나리오 이벤트: 그림 없음 " + e.arg + " → 도형");
|
||
a.shape = ProceduralSprites.NewSprite(go.transform, "Body", ProceduralSprites.Circle, ExtraTag, C("extra_shape_size"), 0);
|
||
}
|
||
actors[e.actor] = a;
|
||
}
|
||
|
||
IEnumerator Show(Actor a, bool on, ScenarioData.EventRow e, float dur)
|
||
{
|
||
if (a == null) yield break;
|
||
Vector2 at;
|
||
if (on && Where(e, out at)) a.Pos = at;
|
||
var vis = a.Visual;
|
||
if (vis == null) yield break;
|
||
var rends = vis.GetComponentsInChildren<SpriteRenderer>(true);
|
||
if (on) vis.SetActive(true);
|
||
if (dur > 0f && !skip)
|
||
{
|
||
var baseA = new float[rends.Length];
|
||
for (int i = 0; i < rends.Length; i++) baseA[i] = rends[i].color.a;
|
||
for (float t = 0f; t < dur && !skip; t += Time.unscaledDeltaTime)
|
||
{
|
||
float k = on ? t / dur : 1f - t / dur;
|
||
for (int i = 0; i < rends.Length; i++)
|
||
{
|
||
var c = rends[i].color;
|
||
rends[i].color = new Color(c.r, c.g, c.b, baseA[i] * k);
|
||
}
|
||
yield return null;
|
||
}
|
||
for (int i = 0; i < rends.Length; i++)
|
||
{
|
||
var c = rends[i].color;
|
||
rends[i].color = new Color(c.r, c.g, c.b, baseA[i]);
|
||
}
|
||
}
|
||
if (!on) vis.SetActive(false);
|
||
}
|
||
|
||
/// <summary>move · show 의 자리 — s_arg at:이름 = line 명령이 정한 자리 + f_x,f_y(빈칸 = 0 · 그 자리에서 얼마나 떨어져 나타날지) · 아니면 f_x,f_y.</summary>
|
||
bool Where(ScenarioData.EventRow e, out Vector2 p)
|
||
{
|
||
// s_arg 낱말(; 로 구분) — at:이름 = 그 자리 + f_x,f_y · atx:이름 = 그 자리의 x(+ f_x) · 높이는 표 f_y 그대로(맵 아래 끝에서 걸어 들어오기 · 2026-11-19 PD) · follow = move 카메라 따라감
|
||
foreach (var tok in (e.arg ?? "").Split(';'))
|
||
{
|
||
string t = tok.Trim();
|
||
if (t == "home") // 이 연출이 시작될 때 그 배우 자리 + f_x,f_y(stage_start = 배치 표 자리 · 배치 좌표를 이벤트 표에 다시 적지 않음 · 2026-11-19 PD 3막)
|
||
{
|
||
var h = Get(e.actor);
|
||
Vector2 hp;
|
||
if (h != null && h.unit != null && startPos.TryGetValue(h.unit, out hp))
|
||
{
|
||
p = hp + new Vector2(float.IsNaN(e.x) ? 0f : e.x, float.IsNaN(e.y) ? 0f : e.y);
|
||
return true;
|
||
}
|
||
Debug.LogWarning("[TKS] 시나리오 이벤트: home 자리 없음(판 유닛 아님) " + e.actor + " (" + e.id + " " + e.order + ")");
|
||
continue;
|
||
}
|
||
bool atx = t.StartsWith("atx:");
|
||
if (!atx && !t.StartsWith("at:")) continue;
|
||
Vector2 b;
|
||
if (points.TryGetValue(t.Substring(atx ? 4 : 3).Trim(), out b))
|
||
{
|
||
float ox = float.IsNaN(e.x) ? 0f : e.x;
|
||
p = atx ? new Vector2(b.x + ox, float.IsNaN(e.y) ? b.y : e.y) : b + new Vector2(ox, float.IsNaN(e.y) ? 0f : e.y);
|
||
return true;
|
||
}
|
||
Debug.LogWarning("[TKS] 시나리오 이벤트: 자리 없음 " + e.arg + " (앞에 line 명령이 없음 · " + e.id + " " + e.order + ")");
|
||
}
|
||
p = e.HasPos ? new Vector2(e.x, e.y) : Vector2.zero;
|
||
return e.HasPos;
|
||
}
|
||
|
||
/// <summary>
|
||
/// line — 쏘는 유닛(s_actor)이 제자리에서 한 번에 꿸 수 있게 줄 세울 자리를 정한다(2026-11-19 PD 「장비가 반격으로 적을 처치한 후 임의로 다른 장소로 이동하지 말고, 그 장소에서 그대로 적을 공격할 수 있게 적들의 움직임을 셋팅」).
|
||
/// s_target = 줄 세울 배우(앞 → 뒤 · ; 로 구분) · f_x,f_y = 맨 앞이 서고 싶은 자리 · s_arg = 간격(빈칸 = 표 line_gap) → 자리 line1 · line2 …(move · show 의 s_arg at:line1).
|
||
/// 맨 앞 자리를 그 근처(표 line_search_range · line_search_step)에서 고른다: 쏘는 유닛 → 맨 뒤 직선이 다른 유닛(유비 등) · 막히는 소품에서 표 line_clear 이상 떨어지고 ·
|
||
/// 맨 뒤가 쏘는 유닛 최대 거리 × line_reach_ratio 안 · 모든 자리가 전장 안 · 바라던 자리에 가장 가까운 곳. 맞는 곳이 없으면 거리 조건을 풀고 · 그래도 없으면 바라던 자리 그대로.
|
||
/// </summary>
|
||
void Line(ScenarioData.EventRow e)
|
||
{
|
||
var shooter = Get(e.actor);
|
||
if (shooter == null || shooter.unit == null) return;
|
||
var keys = new List<string>();
|
||
foreach (var k in (e.target ?? "").Split(';'))
|
||
if (k.Trim().Length > 0) keys.Add(k.Trim());
|
||
if (keys.Count == 0) return;
|
||
var members = new List<Actor>();
|
||
foreach (var k in keys) members.Add(Get(k));
|
||
var argParts = (e.arg ?? "").Split(';');
|
||
float gap = Num(argParts[0], C("line_gap"));
|
||
Vector2 from = shooter.Pos;
|
||
if (argParts.Length > 1 && argParts[1].Trim() == "fixed" && members[0] != null)
|
||
{
|
||
LineFixed(e, shooter, members, gap);
|
||
return;
|
||
}
|
||
Vector2 pref = e.HasPos ? new Vector2(e.x, e.y) : (members[0] != null ? members[0].Pos : from + Vector2.up * 5f);
|
||
float sr = shooter.unit.Radius;
|
||
float mr = members[0] != null && members[0].unit != null ? members[0].unit.Radius : sr;
|
||
float clear = C("line_clear");
|
||
// 비킬 것 = 쏘는 유닛 · 줄 세울 유닛을 뺀 살아 있는 유닛 + 막히는 소품
|
||
var obsC = new List<Vector2>();
|
||
var obsR = new List<float>();
|
||
foreach (var u in battle.Units)
|
||
{
|
||
if (u == null || !u.IsAlive || u == shooter.unit) continue;
|
||
bool member = false;
|
||
foreach (var m in members)
|
||
if (m != null && m.unit == u) member = true;
|
||
if (member) continue;
|
||
obsC.Add(u.Position);
|
||
obsR.Add(u.Radius);
|
||
}
|
||
foreach (var r in ScenarioProps.Blocking(battle, stage))
|
||
{
|
||
obsC.Add(new Vector2(r.x, r.y));
|
||
obsR.Add(r.blockR);
|
||
}
|
||
float reach = SkillMods.SlingMax(shooter.unit) * C("line_reach_ratio");
|
||
float range = Mathf.Max(0f, C("line_search_range")), step = Mathf.Max(0.05f, C("line_search_step"));
|
||
Vector2 best = pref;
|
||
bool found = false;
|
||
for (int pass = 0; pass < 2 && !found; pass++) // 0 = 거리 조건 지킴 · 1 = 거리 조건 풂
|
||
{
|
||
float bestCost = float.MaxValue;
|
||
for (float dx = -range; dx <= range + 1e-4f; dx += step)
|
||
for (float dy = -range; dy <= range + 1e-4f; dy += step)
|
||
{
|
||
Vector2 p1 = pref + new Vector2(dx, dy);
|
||
float cost = new Vector2(dx, dy).magnitude;
|
||
if (cost >= bestCost) continue;
|
||
Vector2 d = p1 - from;
|
||
float d1 = d.magnitude;
|
||
if (d1 < sr + mr + gap) continue; // 너무 가까움
|
||
Vector2 dir = d / d1;
|
||
Vector2 last = p1 + dir * gap * (keys.Count - 1);
|
||
if (pass == 0 && (last - from).magnitude > reach) continue;
|
||
bool ok = true;
|
||
for (int i = 0; i < keys.Count && ok; i++)
|
||
{
|
||
Vector2 pi = p1 + dir * gap * i;
|
||
if ((battle.Board.ClampInside(pi, mr) - pi).sqrMagnitude > 1e-4f) ok = false;
|
||
for (int j = 0; j < obsC.Count && ok; j++)
|
||
if ((pi - obsC[j]).magnitude < obsR[j] + mr + clear) ok = false;
|
||
}
|
||
Vector2 end = last + dir * (mr + sr);
|
||
for (int j = 0; j < obsC.Count && ok; j++)
|
||
if (SegDist(obsC[j], from, end) < obsR[j] + sr + clear) ok = false; // 돌진 길이 유비 · 소품에 닿지 않게
|
||
if (!ok) continue;
|
||
bestCost = cost;
|
||
best = p1;
|
||
found = true;
|
||
}
|
||
}
|
||
Vector2 dirB = (best - from).sqrMagnitude > 1e-6f ? (best - from).normalized : Vector2.up;
|
||
for (int i = 0; i < keys.Count; i++) points["line" + (i + 1)] = best + dirB * gap * i;
|
||
if (!found) Debug.LogWarning("[TKS] 시나리오 이벤트 line: 비킬 자리를 못 찾음 → 바라던 자리 그대로 (" + e.id + ")");
|
||
}
|
||
|
||
/// <summary>
|
||
/// line(s_arg 「간격;fixed」) — 맨 앞 배우는 지금 자리 그대로(움직이지 않음) · 쏘는 유닛 → 맨 앞 직선의 연장선에 나머지 자리(2026-11-19 PD 2막 「유비가 임의로 움직이지 않는 상태에서 관우가 유비로 공격」).
|
||
/// 간격은 s_arg 값부터 60 % 까지 0.2 씩 줄여 가며 전장 안 · 다른 유닛 · 막히는 소품과 떨어진 첫 값 · 자리 = line1(맨 앞) · line2 … + 각 자리와 앞 자리의 가운데 line2_near …(나타날 자리).
|
||
/// </summary>
|
||
void LineFixed(ScenarioData.EventRow e, Actor shooter, List<Actor> members, float gap)
|
||
{
|
||
Vector2 from = shooter.Pos, p1 = members[0].Pos;
|
||
Vector2 dir = (p1 - from).sqrMagnitude > 1e-4f ? (p1 - from).normalized : Vector2.up;
|
||
float mr = members.Count > 1 && members[1] != null && members[1].unit != null ? members[1].unit.Radius : 0.5f;
|
||
float clear = C("line_clear");
|
||
var obsC = new List<Vector2>();
|
||
var obsR = new List<float>();
|
||
foreach (var u in battle.Units)
|
||
{
|
||
if (u == null || !u.IsAlive || u == shooter.unit || ScenarioEvent.Absent(u)) continue;
|
||
bool member = false;
|
||
foreach (var m in members)
|
||
if (m != null && m.unit == u) member = true;
|
||
if (member) continue;
|
||
obsC.Add(u.Position);
|
||
obsR.Add(u.Radius);
|
||
}
|
||
foreach (var r in ScenarioProps.Blocking(battle, stage))
|
||
{
|
||
obsC.Add(new Vector2(r.x, r.y));
|
||
obsR.Add(r.blockR);
|
||
}
|
||
if (battle.Gimmicks != null) // 막는 기믹(굴린 바위 등)
|
||
foreach (var g in battle.Gimmicks.Items)
|
||
if (g != null && g.BlocksMove)
|
||
{
|
||
obsC.Add(g.Shape.Center);
|
||
obsR.Add(g.Shape.BoundingRadius);
|
||
}
|
||
float use = gap;
|
||
bool found = false;
|
||
for (float g = gap; g >= gap * 0.6f - 1e-4f && !found; g -= 0.2f)
|
||
{
|
||
bool ok = true;
|
||
for (int i = 1; i < members.Count && ok; i++)
|
||
{
|
||
Vector2 pi = p1 + dir * g * i;
|
||
if ((battle.Board.ClampInside(pi, mr) - pi).sqrMagnitude > 1e-4f) ok = false;
|
||
for (int j = 0; j < obsC.Count && ok; j++)
|
||
if ((pi - obsC[j]).magnitude < obsR[j] + mr + clear || SegDist(obsC[j], p1, pi) < obsR[j] + mr + clear) ok = false;
|
||
}
|
||
if (ok)
|
||
{
|
||
use = g;
|
||
found = true;
|
||
}
|
||
}
|
||
points["line1"] = p1;
|
||
for (int i = 1; i < members.Count; i++)
|
||
{
|
||
Vector2 pi = p1 + dir * use * i;
|
||
if (!found) pi = battle.Board.ClampInside(pi, mr);
|
||
points["line" + (i + 1)] = pi;
|
||
points["line" + (i + 1) + "_near"] = p1 + dir * use * (i - 0.5f);
|
||
}
|
||
if (!found) Debug.LogWarning("[TKS] 시나리오 이벤트 line fixed: 비킬 자리를 못 찾음 → 전장 안으로만 (" + e.id + ")");
|
||
}
|
||
|
||
static float SegDist(Vector2 p, Vector2 a, Vector2 b)
|
||
{
|
||
Vector2 ab = b - a;
|
||
float t = ab.sqrMagnitude > 1e-6f ? Mathf.Clamp01(Vector2.Dot(p - a, ab) / ab.sqrMagnitude) : 0f;
|
||
return (p - (a + ab * t)).magnitude;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 걷기 — 카메라가 move_cam_lead_sec(0.5초) 먼저 움직이고 유닛이 따라감(2026-11-18 PD 「카메라가 항상 늦게 이동 · 0.5초 먼저 이동하고 캐릭터가 따라가는 형태」).
|
||
/// 카메라 = 이 move 바로 뒤의 focus 줄(사이에 move · emote · face · show · hide · extra 만)을 앞당겨 실행 · 없으면 도착점이 화면 안쪽 여백 밖일 때만 그만큼 옮김 ·
|
||
/// 퇴장(다음 줄이 그 배우의 hide) = 카메라를 움직이지 않음.
|
||
/// </summary>
|
||
IEnumerator Move(Actor a, ScenarioData.EventRow e)
|
||
{
|
||
Vector2 p1;
|
||
if (a == null || !Where(e, out p1)) yield break;
|
||
Vector2 p0 = a.Pos;
|
||
var d = p1 - p0;
|
||
float dur = float.IsNaN(e.sec) ? d.magnitude / Mathf.Max(0.01f, C("move_speed")) : Mathf.Max(0f, e.sec);
|
||
if (System.Array.IndexOf((e.arg ?? "").Split(';'), "follow") >= 0) // 카메라가 그 배우를 화면 같은 자리에 둔 채 따라감(2026-11-19 PD 2막 「관우에게 카메라가 포커싱 된 상태로 마을 주민 쪽으로 이동」)
|
||
{
|
||
Vector2 off = (Vector2)cc.transform.position - p0;
|
||
if (d.sqrMagnitude > 0.0001f && System.Array.IndexOf((e.arg ?? "").Split(';'), "keepface") < 0) a.Face(d); // keepface = 앞 줄 face 그대로 걸음(뒷모습으로 걸어 올라감 · 2026-11-19 PD)
|
||
if (!skip && d.sqrMagnitude > 0.0001f && System.Array.IndexOf((e.arg ?? "").Split(';'), "dust") >= 0) StartCoroutine(Dust(a, dur));
|
||
for (float t = 0f; t < dur && !skip; t += Time.unscaledDeltaTime)
|
||
{
|
||
a.Pos = Vector2.Lerp(p0, p1, Ease(t / dur));
|
||
cc.SnapTo(a.Pos + off);
|
||
yield return null;
|
||
}
|
||
a.Pos = p1;
|
||
cc.SnapTo(p1 + off);
|
||
yield break;
|
||
}
|
||
bool camBusy = false;
|
||
bool noWait = System.Array.IndexOf((e.arg ?? "").Split(';'), "nowait") >= 0; // 함께 걷는 줄 = 카메라를 건드리지 않음
|
||
var fr = noWait ? null : PullFocus();
|
||
if (fr != null) // 늦게 따라오던 카메라 줄 = 먼저
|
||
{
|
||
camBusy = true;
|
||
StartCoroutine(Then(Focus(fr), () => camBusy = false));
|
||
}
|
||
else if (!noWait && !skip && !Exits(e.actor))
|
||
{
|
||
Vector2 shift = ShiftToShow(p1);
|
||
if (shift.sqrMagnitude > 0.0001f)
|
||
{
|
||
camBusy = true;
|
||
Vector2 c0 = cc.transform.position;
|
||
StartCoroutine(Then(Pan(c0, c0 + shift, Mathf.Max(dur, C("focus_sec"))), () => camBusy = false));
|
||
}
|
||
}
|
||
if (camBusy && !skip) yield return Wait(C("move_cam_lead_sec"));
|
||
if (d.sqrMagnitude > 0.0001f && System.Array.IndexOf((e.arg ?? "").Split(';'), "keepface") < 0) a.Face(d); // keepface = 앞 줄 face 그대로 걸음(뒷모습으로 걸어 올라감 · 2026-11-19 PD)
|
||
if (!skip && d.sqrMagnitude > 0.0001f && System.Array.IndexOf((e.arg ?? "").Split(';'), "dust") >= 0) StartCoroutine(Dust(a, dur)); // dust = 걷는 동안 발밑 흙먼지
|
||
for (float t = 0f; t < dur && !skip; t += Time.unscaledDeltaTime)
|
||
{
|
||
a.Pos = Vector2.Lerp(p0, p1, Ease(t / dur));
|
||
yield return null;
|
||
}
|
||
a.Pos = p1;
|
||
while (camBusy && !skip) yield return null;
|
||
}
|
||
|
||
static readonly string[] PassOver = { "move", "emote", "face", "show", "hide", "extra" };
|
||
|
||
/// <summary>지금 move 뒤에 오는 focus 줄(사이 = PassOver 명령만) — 있으면 앞당김 표시 후 반환.</summary>
|
||
ScenarioData.EventRow PullFocus()
|
||
{
|
||
for (int i = cursor + 1; i < flat.Count; i++)
|
||
{
|
||
var n = flat[i];
|
||
if (pulled.Contains(n)) continue;
|
||
if (n.cmd == "focus")
|
||
{
|
||
pulled.Add(n);
|
||
return n;
|
||
}
|
||
if (Array.IndexOf(PassOver, n.cmd) < 0) return null;
|
||
}
|
||
return null;
|
||
}
|
||
|
||
/// <summary>바로 다음 줄이 이 배우를 숨김 = 퇴장 걸음.</summary>
|
||
bool Exits(string actor)
|
||
{
|
||
int i = cursor + 1;
|
||
return i < flat.Count && flat[i].cmd == "hide" && flat[i].actor == actor;
|
||
}
|
||
|
||
/// <summary>점 p 가 화면 안쪽 여백(위아래 검은 띠 · move_cam_margin · 위 = move_cam_margin_top) 안에 들게 할 카메라 이동량(이미 안이면 0).</summary>
|
||
Vector2 ShiftToShow(Vector2 p)
|
||
{
|
||
var v = cc.ViewRect;
|
||
float bar = v.height * C("letterbox_ratio"), m = C("move_cam_margin"), mt = C("move_cam_margin_top");
|
||
float x0 = v.xMin + m, x1 = v.xMax - m, y0 = v.yMin + bar + m, y1 = v.yMax - bar - mt;
|
||
float dx = p.x < x0 ? p.x - x0 : (p.x > x1 ? p.x - x1 : 0f);
|
||
float dy = p.y < y0 ? p.y - y0 : (p.y > y1 ? p.y - y1 : 0f);
|
||
return new Vector2(dx, dy);
|
||
}
|
||
|
||
IEnumerator Pan(Vector2 from, Vector2 to, float dur)
|
||
{
|
||
for (float t = 0f; t < dur && !skip; t += Time.unscaledDeltaTime)
|
||
{
|
||
cc.SnapTo(Vector2.Lerp(from, to, Ease(t / dur)));
|
||
yield return null;
|
||
}
|
||
cc.SnapTo(to);
|
||
}
|
||
|
||
static IEnumerator Then(IEnumerator body, Action done)
|
||
{
|
||
yield return body;
|
||
done();
|
||
}
|
||
|
||
IEnumerator Attack(Actor a, Actor b, float dur)
|
||
{
|
||
if (a == null || b == null || skip) yield break;
|
||
Vector2 p0 = a.Pos;
|
||
var d = b.Pos - p0;
|
||
float reach = (a.unit != null ? a.unit.Radius : 0.4f) + (b.unit != null ? b.unit.Radius : 0.4f);
|
||
Vector2 hitAt = d.magnitude > reach ? b.Pos - d.normalized * reach * C("attack_reach_ratio") : p0;
|
||
a.Face(d);
|
||
if (a.unit != null && a.unit.View != null) a.unit.View.PlayAttack();
|
||
if (b.unit != null && b.unit.View != null && b.unit.IsAlive && !SkillStatus.Stunned(b.unit)) // 맞는 쪽도 짧게 공격 자세로 맞받음(2026-11-19 PD 「관우도 공격 포즈로 짧게 바뀌며 대응」)
|
||
{
|
||
b.Face(-d);
|
||
b.unit.View.PlayCounter();
|
||
}
|
||
float go = dur * C("attack_dash_ratio");
|
||
for (float t = 0f; t < go && !skip; t += Time.unscaledDeltaTime)
|
||
{
|
||
a.Pos = Vector2.Lerp(p0, hitAt, Ease(t / go));
|
||
yield return null;
|
||
}
|
||
a.Pos = hitAt;
|
||
yield return Wait(dur - go * 2f);
|
||
for (float t = 0f; t < go && !skip; t += Time.unscaledDeltaTime)
|
||
{
|
||
a.Pos = Vector2.Lerp(hitAt, p0, Ease(t / go));
|
||
yield return null;
|
||
}
|
||
a.Pos = p0;
|
||
}
|
||
|
||
/// <summary>
|
||
/// roll — 미는 배우(s_actor · 비면 없음)가 기믹에 부딪히듯 다가갔다 돌아오는 동안 기믹(s_arg = 기믹 id · 배우에게 가장 가까운 것)이 f_x,f_y 로 굴러감(f_sec · 빈칸 = roll_sec).
|
||
/// 판의 실제 기믹을 옮긴다(모양 · 콜라이더 · 그림) — 건너뛰어도 그 자리(끝 상태) · 시작 연출이 끝나도 되돌리지 않음(유닛만 시작 자리로).
|
||
/// </summary>
|
||
IEnumerator Roll(Actor a, ScenarioData.EventRow e)
|
||
{
|
||
if (!e.HasPos || battle.Gimmicks == null) yield break;
|
||
Vector2 near = a != null ? a.Pos : new Vector2(e.x, e.y);
|
||
GimmickInstance g = null;
|
||
float best = float.MaxValue;
|
||
foreach (var x in battle.Gimmicks.Items)
|
||
{
|
||
if (x == null || x.Removed || (!string.IsNullOrEmpty(e.arg) && x.Id != e.arg)) continue;
|
||
float dd = (x.Shape.Center - near).sqrMagnitude;
|
||
if (dd < best)
|
||
{
|
||
best = dd;
|
||
g = x;
|
||
}
|
||
}
|
||
if (g == null)
|
||
{
|
||
Debug.LogWarning("[TKS] 시나리오 이벤트: 굴릴 기믹 없음 " + e.arg + " (" + stage.chapter + "-" + stage.stage + ")");
|
||
yield break;
|
||
}
|
||
Vector2 g0 = g.Shape.Center, g1 = new Vector2(e.x, e.y);
|
||
if (a != null && !skip)
|
||
{
|
||
Vector2 p0 = a.Pos;
|
||
var d = g0 - p0;
|
||
float reach = (a.unit != null ? a.unit.Radius : 0.4f) + (g.Shape.Type == GimmickShapeType.Circle ? g.Shape.R : g.Shape.BoundingRadius);
|
||
Vector2 hitAt = d.magnitude > reach ? g0 - d.normalized * reach : p0;
|
||
a.Face(d);
|
||
if (a.unit != null && a.unit.View != null) a.unit.View.PlayAttack();
|
||
float go = C("attack_sec") * C("attack_dash_ratio");
|
||
for (float t = 0f; t < go && !skip; t += Time.unscaledDeltaTime)
|
||
{
|
||
a.Pos = Vector2.Lerp(p0, hitAt, Ease(t / go));
|
||
yield return null;
|
||
}
|
||
StartCoroutine(StepBack(a, hitAt, p0, go)); // 돌아가는 동안 기믹이 굴러감
|
||
}
|
||
float dur = Sec(e, "roll_sec");
|
||
for (float t = 0f; t < dur && !skip; t += Time.unscaledDeltaTime)
|
||
{
|
||
var p = Vector2.Lerp(g0, g1, Ease(t / dur));
|
||
if (g.Go != null) g.Go.transform.position = new Vector3(p.x, p.y, 0f);
|
||
yield return null;
|
||
}
|
||
g.MoveBy(g1 - g.Shape.Center);
|
||
Physics2D.SyncTransforms();
|
||
battle.NotifyChanged();
|
||
}
|
||
|
||
IEnumerator StepBack(Actor a, Vector2 from, Vector2 to, float dur)
|
||
{
|
||
for (float t = 0f; t < dur && !skip; t += Time.unscaledDeltaTime)
|
||
{
|
||
a.Pos = Vector2.Lerp(from, to, Ease(t / dur));
|
||
yield return null;
|
||
}
|
||
a.Pos = to;
|
||
}
|
||
|
||
void Faint(Actor a, bool on, bool keep)
|
||
{
|
||
if (a == null) return;
|
||
var body = a.Body;
|
||
if (on)
|
||
{
|
||
if (!fainted.ContainsKey(body)) fainted[body] = body.localRotation;
|
||
body.localRotation = Quaternion.Euler(0f, 0f, C("faint_angle"));
|
||
float dark = C("faint_dark");
|
||
foreach (var sr in body.GetComponentsInChildren<SpriteRenderer>())
|
||
{
|
||
if (faintTint.ContainsKey(sr)) continue;
|
||
faintTint[sr] = sr.color;
|
||
var c = sr.color;
|
||
sr.color = new Color(c.r * (1f - dark), c.g * (1f - dark), c.b * (1f - dark), c.a);
|
||
}
|
||
if (keep) faintKeep.Add(body);
|
||
var stars = Glyph(a, "dizzy", true);
|
||
if (stars != null)
|
||
{
|
||
stars.name = "FaintStars";
|
||
if (!keep) temp.Add(stars);
|
||
}
|
||
return;
|
||
}
|
||
Unfaint(body);
|
||
var holder = a.unit != null ? a.unit.transform : a.extra.transform;
|
||
var old = holder.Find("FaintStars");
|
||
if (old != null) Destroy(old.gameObject);
|
||
}
|
||
|
||
/// <summary>전투의 기절(stun 명령 · 연의 서장 기절한 구출 대상) 풀기 — wake.</summary>
|
||
void Unstun(Actor a)
|
||
{
|
||
if (a == null || a.unit == null) return;
|
||
if (battle.Gimmicks != null) battle.Gimmicks.ReleaseStun(a.unit);
|
||
a.unit.Downed = false;
|
||
if (a.unit.View != null) a.unit.View.Refresh();
|
||
}
|
||
|
||
static void Unfaint(Transform body)
|
||
{
|
||
Quaternion r;
|
||
if (fainted.TryGetValue(body, out r)) body.localRotation = r;
|
||
fainted.Remove(body);
|
||
faintKeep.Remove(body);
|
||
var keys = new List<SpriteRenderer>(faintTint.Keys);
|
||
foreach (var sr in keys)
|
||
{
|
||
if (sr == null)
|
||
{
|
||
faintTint.Remove(sr);
|
||
continue;
|
||
}
|
||
if (!sr.transform.IsChildOf(body)) continue;
|
||
sr.color = faintTint[sr];
|
||
faintTint.Remove(sr);
|
||
}
|
||
}
|
||
|
||
// ---------- 머리 위 표시 ----------
|
||
|
||
GameObject Glyph(Actor a, string id, bool persistent)
|
||
{
|
||
var em = ScenarioData.EmoteOf(id);
|
||
if (a == null || em == null) return null;
|
||
var parent = a.unit != null ? a.unit.transform : a.extra.transform;
|
||
var sp = string.IsNullOrEmpty(em.art) ? null : Resources.Load<Sprite>(ScenarioData.Root + "Emotes/" + em.art);
|
||
if (sp != null) // 말풍선 그림(머리 오른쪽 위 · 꼬리가 머리 쪽 · 높이 = emote_bubble_height)
|
||
{
|
||
var bg = new GameObject("Emote_" + em.art);
|
||
bg.transform.SetParent(parent, false);
|
||
var sr = bg.AddComponent<SpriteRenderer>();
|
||
sr.sprite = sp;
|
||
sr.sortingOrder = 6;
|
||
float s = C("emote_bubble_height") / Mathf.Max(0.01f, sp.bounds.size.y);
|
||
bg.transform.localScale = new Vector3(s, s, 1f);
|
||
bg.transform.position = (Vector3)(a.Head + new Vector2(C("emote_bubble_dx"), C("emote_bubble_offset")));
|
||
if (!persistent) temp.Add(bg);
|
||
return bg;
|
||
}
|
||
var tm = TextUtil.CreateWorldText(parent, em.glyph, C("emote_world_height"), em.color, 6);
|
||
tm.transform.position = (Vector3)(a.Head + new Vector2(0f, C("emote_offset"))) + new Vector3(0f, 0f, 0f);
|
||
if (!persistent) temp.Add(tm.gameObject);
|
||
return tm.gameObject;
|
||
}
|
||
|
||
IEnumerator EmoteAt(Actor a, string id, bool persistent)
|
||
{
|
||
if (a == null || skip) yield break;
|
||
var g = Glyph(a, id, persistent);
|
||
if (g == null) yield break;
|
||
StartCoroutine(EmoteLife(g, C("emote_sec")));
|
||
yield return Wait(C("emote_wait_sec"));
|
||
}
|
||
|
||
IEnumerator EmoteLife(GameObject g, float life)
|
||
{
|
||
var p0 = g.transform.localPosition;
|
||
float hop = C("emote_hop");
|
||
for (float t = 0f; t < life && g != null; t += Time.unscaledDeltaTime)
|
||
{
|
||
g.transform.localPosition = p0 + new Vector3(0f, hop * Mathf.Sin(Mathf.Clamp01(t / 0.25f) * Mathf.PI), 0f);
|
||
yield return null;
|
||
}
|
||
if (g != null) Destroy(g);
|
||
}
|
||
|
||
// ---------- 카메라 · 화면 ----------
|
||
|
||
IEnumerator Focus(ScenarioData.EventRow e)
|
||
{
|
||
Vector2 target;
|
||
var a = Get(e.actor);
|
||
if (a != null) target = a.Pos;
|
||
else if (e.HasPos) target = new Vector2(e.x, e.y);
|
||
else target = camStart;
|
||
float zoom = string.IsNullOrEmpty(e.arg) ? 1f : Mathf.Max(0.1f, Num(e.arg, 1f));
|
||
float h1 = viewStart / zoom;
|
||
float dur = Sec(e, "focus_sec");
|
||
Vector2 p0 = cc.transform.position;
|
||
float h0 = cc.ViewHeight;
|
||
for (float t = 0f; t < dur && !skip; t += Time.unscaledDeltaTime)
|
||
{
|
||
float k = Ease(t / dur);
|
||
cc.SetViewHeight(Mathf.Lerp(h0, h1, k));
|
||
cc.SnapTo(Vector2.Lerp(p0, target, k));
|
||
yield return null;
|
||
}
|
||
cc.SetViewHeight(h1);
|
||
cc.SnapTo(target);
|
||
}
|
||
|
||
IEnumerator Fade(bool toBlack, float dur)
|
||
{
|
||
float a0 = fade.color.a, a1 = toBlack ? 1f : 0f;
|
||
for (float t = 0f; t < dur && !skip; t += Time.unscaledDeltaTime)
|
||
{
|
||
fade.color = new Color(0f, 0f, 0f, Mathf.Lerp(a0, a1, t / dur));
|
||
yield return null;
|
||
}
|
||
fade.color = new Color(0f, 0f, 0f, skip ? 0f : a1);
|
||
}
|
||
|
||
IEnumerator Caption(string text, float hold)
|
||
{
|
||
if (skip) yield break;
|
||
captionText.text = text;
|
||
float fIn = C("caption_fade_sec"), bandA = C("caption_band_alpha");
|
||
for (float t = 0f; t < fIn && !skip; t += Time.unscaledDeltaTime)
|
||
{
|
||
SetCaption(bandA, t / fIn);
|
||
yield return null;
|
||
}
|
||
SetCaption(bandA, 1f);
|
||
st.Taps = 0;
|
||
for (float t = 0f; t < hold && !skip && st.Taps == 0; t += Time.unscaledDeltaTime) yield return null;
|
||
st.Taps = 0;
|
||
for (float t = 0f; t < fIn && !skip; t += Time.unscaledDeltaTime)
|
||
{
|
||
SetCaption(bandA, 1f - t / fIn);
|
||
yield return null;
|
||
}
|
||
SetCaption(bandA, 0f);
|
||
}
|
||
|
||
void SetCaption(float bandA, float k)
|
||
{
|
||
captionBand.color = new Color(0f, 0f, 0f, bandA * k);
|
||
var c = captionText.color;
|
||
captionText.color = new Color(c.r, c.g, c.b, k);
|
||
}
|
||
|
||
/// <summary>가운데 설명 카드(병종 · 조작 학습 · 2026-11-18 PD) — 어둡게 덮고 카드 · 누르면 닫힘 · 건너뛰기 = 안 보임. 값 = scenario_event_config tip_*.</summary>
|
||
IEnumerator Tip(string text)
|
||
{
|
||
if (skip || string.IsNullOrEmpty(text)) yield break;
|
||
var dim = Full("TipDim", fx, null, new Color(0f, 0f, 0f, C("tip_dim")));
|
||
var card = Img("Tip", fx, null, new Color(0.08f, 0.09f, 0.13f, C("tip_alpha")), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, C("tip_y")), new Vector2(C("tip_width"), C("tip_height")));
|
||
var edge = Img("TipEdge", card.transform, null, new Color(0.95f, 0.78f, 0.35f, 1f), new Vector2(0f, 1f), new Vector2(1f, 1f), new Vector2(0.5f, 1f), Vector2.zero, new Vector2(0f, 6f));
|
||
edge.raycastTarget = false;
|
||
dim.raycastTarget = card.raycastTarget = false; // 누름 = 연출 화면 누름 받이(Tap)
|
||
var t = Txt(card.transform, text, Mathf.RoundToInt(C("tip_font")), Color.white, TextAnchor.MiddleCenter, Vector2.zero, new Vector2(C("tip_width") - 80f, C("tip_height") - 40f), UISkin.TitleFont);
|
||
t.horizontalOverflow = HorizontalWrapMode.Wrap;
|
||
st.Taps = 0;
|
||
for (float w = 0f; w < C("tip_min_sec") && !skip; w += Time.unscaledDeltaTime) yield return null; // 바로 넘겨지지 않게
|
||
st.Taps = 0;
|
||
while (!skip && st.Taps == 0) yield return null;
|
||
st.Taps = 0;
|
||
Destroy(card.gameObject);
|
||
Destroy(dim.gameObject);
|
||
}
|
||
|
||
/// <summary>화면 장면 연출(로비와 같은 표 형식 · 꽃잎 등) — 검은 덮개 · 위아래 띠 아래 층(페이드 아웃이 함께 덮음) · 연출이 끝나면 치움. s_arg off = 지금 것만 치움.</summary>
|
||
void Ambient(string arg)
|
||
{
|
||
if (ambient != null)
|
||
{
|
||
temp.Remove(ambient);
|
||
Destroy(ambient);
|
||
ambient = null;
|
||
}
|
||
if (skip || string.IsNullOrEmpty(arg) || arg == "off") return;
|
||
if (AmbientMaker == null)
|
||
{
|
||
Debug.LogWarning("[TKS] 시나리오 이벤트: ambient 만들기 없음(OutGame 등록 전) " + arg);
|
||
return;
|
||
}
|
||
ambient = AmbientMaker(root, arg);
|
||
if (ambient == null) return;
|
||
ambient.transform.SetSiblingIndex(fx.GetSiblingIndex());
|
||
temp.Add(ambient);
|
||
}
|
||
|
||
/// <summary>걷는 동안 발밑 흙먼지(move s_arg dust) — walk_dust_sec 마다 1번 · 판 유닛 배우만(연출 인물은 skill_vfx 기준 유닛이 없음).</summary>
|
||
IEnumerator Dust(Actor a, float dur)
|
||
{
|
||
if (a == null || a.unit == null) yield break;
|
||
float gap = Mathf.Max(0.05f, C("walk_dust_sec"));
|
||
for (float t = 0f; t < dur && !skip; t += gap)
|
||
{
|
||
SkillVfx.PlayOn(a.unit, DustKey, SkillVfx.EventDepart);
|
||
yield return Wait(gap);
|
||
}
|
||
}
|
||
|
||
IEnumerator Wait(float sec)
|
||
{
|
||
for (float t = 0f; t < sec && !skip; t += Time.unscaledDeltaTime) yield return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 확대만 판 기본으로 · 검은 덮개 걷기 — 카메라 자리는 연출의 마지막 장면 그대로(2026-11-19 PD 2막 「바위를 이용해야겠다 뒤 카메라가 어색하게 흔들림 · 기병 등장 뒤 엉뚱한 장소」
|
||
/// = 그 전엔 연출 시작 전 자리로 되돌아갔다가 전투 · 안내 카메라가 다시 옮김). 다음 화면(아군 턴 · 안내 · 적 턴 추적)이 필요한 만큼만 옮긴다.
|
||
/// </summary>
|
||
IEnumerator Return()
|
||
{
|
||
float dur = skip ? 0f : C("return_sec");
|
||
float h0 = cc.ViewHeight, a0 = fade.color.a;
|
||
bool keepBlack = trigger == "win" && a0 > 0.5f; // 승리 연출이 검게 끝나면 결과 화면 전까지 검게
|
||
for (float t = 0f; t < dur; t += Time.unscaledDeltaTime)
|
||
{
|
||
float k = Ease(t / dur);
|
||
cc.SetViewHeight(Mathf.Lerp(h0, viewStart, k));
|
||
if (!keepBlack) fade.color = new Color(0f, 0f, 0f, a0 * (1f - k));
|
||
yield return null;
|
||
}
|
||
cc.SetViewHeight(viewStart);
|
||
}
|
||
|
||
/// <summary>연출이 남긴 것 치우기 — 연출 인물 · 표시 · (keep 아닌) 기절 · stage_start 면 판 유닛을 시작 자리·보임으로(요청서 약속 3).</summary>
|
||
void Cleanup(bool finished)
|
||
{
|
||
HideHud(false);
|
||
// 시작 연출 끝 = 전투 시작 → 남아 있는 연출 인물은 걸어 나가며 사라짐(바로 지우지 않음 · 2026-11-18 PD 「상인 NPC 들이 갑자기 사라지는데, 전투가 시작될 때 사라지도록」)
|
||
if (finished && trigger == "stage_start")
|
||
foreach (var a in actors.Values)
|
||
if (a.extra != null && a.extra.activeInHierarchy && temp.Remove(a.extra)) ExtraExit.Begin(a.extra, a.anim, C("extra_exit_sec"), C("extra_exit_dist"), a.artLeft);
|
||
foreach (var g in temp)
|
||
if (g != null) Destroy(g);
|
||
temp.Clear();
|
||
// keep 아닌 기절(또는 중단) = 되돌림 · keep = 그 판 전투 동안 유지(다음 연출의 wake 가 풂)
|
||
foreach (var body in new List<Transform>(fainted.Keys))
|
||
{
|
||
if (body == null)
|
||
{
|
||
fainted.Remove(body);
|
||
continue;
|
||
}
|
||
if (finished && faintKeep.Contains(body)) continue;
|
||
Unfaint(body);
|
||
}
|
||
faintKeep.RemoveWhere(b => b == null);
|
||
if (trigger == "stage_start")
|
||
foreach (var kv in startPos)
|
||
{
|
||
if (kv.Key == null) continue;
|
||
kv.Key.Position = kv.Value;
|
||
if (kv.Key.View != null && !keptHidden.Contains(kv.Key)) kv.Key.View.gameObject.SetActive(true); // 끝까지 숨긴 유닛 = 숨긴 채
|
||
}
|
||
}
|
||
|
||
void OnDestroy()
|
||
{
|
||
if (current == this) current = null;
|
||
}
|
||
|
||
/// <summary>판 유닛의 몸(충돌체) 켜기 · 끄기 — 연출이 숨긴 유닛은 보이지 않는 장애물이 되지 않게.</summary>
|
||
static void SetBody(Unit u, bool on)
|
||
{
|
||
if (u != null && u.Collider != null) u.Collider.enabled = on;
|
||
}
|
||
|
||
void RefreshViews()
|
||
{
|
||
if (battle == null || battle.Units == null) return;
|
||
foreach (var u in battle.Units)
|
||
if (u != null && u.View != null) u.View.Refresh();
|
||
}
|
||
|
||
/// <summary>연출 인물 퇴장 — 가까운 좌우 가장자리 쪽으로 dist 만큼 걸으며 dur 동안 흐려지고 사라짐(전투 시작 때 · 연출 객체와 따로 돎).</summary>
|
||
class ExtraExit : MonoBehaviour
|
||
{
|
||
float dur, t;
|
||
Vector3 from, to;
|
||
SpriteRenderer[] rends;
|
||
float[] baseA;
|
||
|
||
public static void Begin(GameObject go, FrameAnimator anim, float dur, float dist, bool artLeft = false)
|
||
{
|
||
if (go == null) return;
|
||
if (dur <= 0f)
|
||
{
|
||
Destroy(go);
|
||
return;
|
||
}
|
||
var x = go.AddComponent<ExtraExit>();
|
||
float dir = go.transform.position.x > 0.05f ? 1f : -1f;
|
||
if (anim != null) anim.Renderer.flipX = (dir < 0f) != artLeft; // 걸어 나가는 쪽을 봄(왼쪽을 보고 그린 그림 = 거꾸로)
|
||
x.dur = dur;
|
||
x.from = go.transform.position;
|
||
x.to = x.from + new Vector3(dir * dist, 0f, 0f);
|
||
x.rends = go.GetComponentsInChildren<SpriteRenderer>(true);
|
||
x.baseA = new float[x.rends.Length];
|
||
for (int i = 0; i < x.rends.Length; i++) x.baseA[i] = x.rends[i].color.a;
|
||
}
|
||
|
||
void Update()
|
||
{
|
||
t += Time.unscaledDeltaTime;
|
||
float k = Mathf.Clamp01(t / dur);
|
||
transform.position = Vector3.Lerp(from, to, k);
|
||
for (int i = 0; i < rends.Length; i++)
|
||
{
|
||
if (rends[i] == null) continue;
|
||
var c = rends[i].color;
|
||
rends[i].color = new Color(c.r, c.g, c.b, baseA[i] * (1f - k));
|
||
}
|
||
if (k >= 1f) Destroy(gameObject);
|
||
}
|
||
}
|
||
}
|
||
}
|