2026-11-03 19:10:10 +00:00
using System ;
using System.Collections ;
using System.Collections.Generic ;
using UnityEngine ;
namespace TKS
{
public enum BattlePhase
{
Setup ,
PlayerTurn ,
Resolving ,
EnemyTurn ,
StageClear ,
Defeat
}
2026-11-05 12:11:10 +00:00
/// <summary>출전 1칸(아웃게임 편성 프리셋 · 2026-11-05 #1093). 배율 = 영웅 배율 × 성장 계수(기획서 §3-2) · slot = playerSpawnPoints 자리.</summary>
[Serializable]
public class LineupEntry
{
public int slot ;
public string id ;
public string name ;
public UnitType type ;
public string art ;
public float hpMult = 1f ;
public float atkMult = 1f ;
public float defMult = 1f ;
2026-11-05 14:31:27 +00:00
// 스킬(PD #1093 B · 편성 → SkillRules.FillLineup) — 병사 유닛 = 비어 있음
public string skillActive = "" ;
public string skillPassive = "" ;
public int activeLv = 1 ;
public int passiveLv = 1 ;
/// <summary>★5 패시브 배율(evolve.csv skill_unlock passive_x · 그 아래 ★ = 1).</summary>
public float passiveMult = 1f ;
/// <summary>무장(영웅) — 참장 대상.</summary>
public bool general ;
2026-11-05 12:11:10 +00:00
}
2026-11-05 15:22:54 +00:00
/// <summary>
/// 연무장 모드 전투(PD #1093 C · 탑 · 일일 던전 · 투기장 · 적장 토벌) — 스테이지 표 대신 이 적 편성(배율 반영)으로 시작한다.
/// 아군 = 출전 편성(LineupProvider) 그대로 · maxTurns 를 넘기면 전투 종료(패배 단계 · 적장 토벌 누적 피해) · 결과 탭 = onExit(월드맵 대신).
/// </summary>
public class BattleMode
{
public string kind = "" ;
public BalanceConfig . StageDef stage ;
/// <summary>0 = 제한 없음 · n = n 턴을 마치면 끝.</summary>
public int maxTurns ;
/// <summary>결과 화면 탭(연무장 복귀).</summary>
public Action onExit ;
2026-11-17 16:03:13 +00:00
/// <summary>컨텐츠 모드 전투 규칙(보급전 · 연의 전기 · 맹장 토벌전 · 투기장 · 2026-11-17) — null = 일반 연무장 전투.</summary>
public ModeBattleRules rules ;
2026-11-05 15:22:54 +00:00
}
2026-11-03 19:10:10 +00:00
/// <summary>턴 진행·유닛 관리·승패 판정. 아군은 모든 유닛이 행동하면 자동으로 적군 턴이 된다(버튼 없음).</summary>
public class BattleManager : MonoBehaviour
{
public static BattleManager Instance { get ; private set ; }
public BalanceConfig Config ;
public Board Board ;
public BattleHUD Hud ;
public SlingshotInput Sling ;
public BattlePhase Phase { get ; private set ; }
public int StageIndex { get ; private set ; }
public int TurnNumber { get ; private set ; }
public System . Random Rng { get ; private set ; }
public ActionResolver Resolver { get ; private set ; }
2026-11-05 14:31:27 +00:00
/// <summary>스킬 상태·시한 효과(PD #1093 B) · 수치 질의 = SkillMods.</summary>
public SkillSystem Skills { get ; private set ; }
2026-11-03 19:10:10 +00:00
public string LastMessage = "" ;
readonly List < Unit > units = new List < Unit > ( ) ;
2026-11-05 12:11:10 +00:00
readonly List < LineupEntry > deployed = new List < LineupEntry > ( ) ;
2026-11-03 19:10:10 +00:00
public IReadOnlyList < Unit > Units
{
get { return units ; }
}
2026-11-05 12:11:10 +00:00
/// <summary>출전 편성 공급자(GameBootstrap → 아웃게임 OutGameRoot 가 편성 프리셋으로 연결). null 이면 아군 없이 시작.</summary>
public Func < List < LineupEntry > > LineupProvider ;
2026-11-09 14:12:52 +00:00
/// <summary>스킬 테스트 씬(2026-11-09): true = 적 턴에 적이 행동하지 않는다(더미).</summary>
public bool EnemyHold ;
2026-11-17 07:27:22 +00:00
/// <summary>
/// 스킬 테스트 씬(2026-11-13 PD 「황개의 스킬은 행동 종료 후 다음 턴이 될때까지 이펙트 및 스킬 효과가 사라져서는 안돼」): 더미가 행동하지 않는 적 턴이 머무는 시간(초 · 0 = 바로 넘어감).
/// 시한 효과·상태 이상은 「다음 내 턴 시작」에 끝나는데 더미가 가만히 있으면 적 턴이 0.5초에 지나가 행동 직후 사라지는 것처럼 보였다(실측) — 규칙은 그대로 · 실제 게임(EnemyHold false)은 영향 없음.
/// </summary>
public float EnemyHoldSeconds ;
2026-11-09 14:12:52 +00:00
2026-11-05 12:11:10 +00:00
/// <summary>이번 전투에 출전한 칸(경험 지급 · 별 「전원 생존」 판정).</summary>
public IReadOnlyList < LineupEntry > Deployed
{
get { return deployed ; }
}
2026-11-03 19:10:10 +00:00
public BalanceConfig . StageDef Stage
{
2026-11-05 15:22:54 +00:00
get { return Mode ! = null & & Mode . stage ! = null ? Mode . stage : Config . stages [ Mathf . Clamp ( StageIndex , 0 , Config . stages . Length - 1 ) ] ; }
}
/// <summary>지금 전투가 연무장 모드면 그 정의(스테이지 전투 = null · PD #1093 C).</summary>
public BattleMode Mode { get ; private set ; }
2026-11-17 07:27:22 +00:00
/// <summary>지금 판의 1장 학습 판 계획(고정 편성 · 배치 표 · 구출 대상 · 턴 제한 — TutorialRules · 개발 요청서 C5 · 2026-11-12) · 일반 판·연무장 = null.</summary>
public TutorialPlan Tutorial { get ; private set ; }
/// <summary>이 전투의 턴 제한(0 = 없음) = 연무장 maxTurns 또는 학습 판 n_turn_limit — 그 턴의 적 턴까지 못 끝내면 패배.</summary>
public int TurnLimit
{
get { return Mode ! = null ? Mode . maxTurns : Tutorial ! = null ? Tutorial . TurnLimit : 0 ; }
}
2026-11-05 15:22:54 +00:00
/// <summary>진영 상시 효과 공급자(보물 crit·range·splash → SkillMods · 아웃게임이 연결) · 전투 시작마다 읽어 둔다.</summary>
public Func < Faction , List < SkillEffect > > SideEffectsProvider ;
readonly List < SkillEffect > [ ] sideEffects = new List < SkillEffect > [ 2 ] ;
public List < SkillEffect > SideEffects ( Faction f )
{
return sideEffects [ ( int ) f ] ;
2026-11-03 19:10:10 +00:00
}
2026-11-03 19:29:16 +00:00
/// <summary>상태가 바뀔 때(HUD 갱신용).</summary>
2026-11-03 19:10:10 +00:00
public event Action Changed ;
2026-11-03 19:29:16 +00:00
/// <summary>단계가 바뀔 때(카메라 연동용).</summary>
public event Action < BattlePhase > PhaseChanged ;
/// <summary>어떤 유닛이 행동을 시작할 때(카메라 추적용).</summary>
public event Action < Unit > UnitActing ;
/// <summary>스테이지 배치가 끝났을 때.</summary>
public event Action StageStarted ;
2026-11-03 19:10:10 +00:00
void Awake ( )
{
Instance = this ;
Rng = new System . Random ( Environment . TickCount ) ;
Fx . Runner = this ;
Phase = BattlePhase . Setup ;
2026-11-05 14:31:27 +00:00
Skills = new SkillSystem ( this ) ;
SkillSystem . Current = Skills ;
2026-11-03 19:10:10 +00:00
}
void OnDestroy ( )
{
if ( Instance = = this ) Instance = null ;
if ( Fx . Runner = = this ) Fx . Runner = null ;
2026-11-05 14:31:27 +00:00
if ( SkillSystem . Current = = Skills ) SkillSystem . Current = null ;
2026-11-03 19:10:10 +00:00
}
public void Configure ( BalanceConfig cfg , Board board )
{
Config = cfg ;
Board = board ;
Resolver = new ActionResolver ( cfg , this , Rng ) ;
2026-11-17 07:27:22 +00:00
Fx . Configure ( cfg ) ; // 이동 물리(등감속 · 부딪히는 힘) 수치
2026-11-03 19:10:10 +00:00
}
public void NotifyChanged ( )
{
2026-11-05 16:20:07 +00:00
if ( Sim . Active ) return ; // 가상 실행(적 AI 예측) 중 = HUD 갱신 없음
2026-11-03 19:10:10 +00:00
if ( Changed ! = null ) Changed ( ) ;
}
2026-11-05 16:20:07 +00:00
/// <summary>지형 기믹 레이어(PD #1097 · 전투마다 스테이지 배치로 다시 만든다).</summary>
public GimmickLayer Gimmicks
{
get { return GimmickLayer . Current ! = null & & GimmickLayer . Current . Battle = = this ? GimmickLayer . Current : null ; }
}
2026-11-03 19:29:16 +00:00
void SetPhase ( BattlePhase p )
{
if ( Phase = = p ) return ;
Phase = p ;
if ( PhaseChanged ! = null ) PhaseChanged ( p ) ;
NotifyChanged ( ) ;
}
2026-11-03 19:10:10 +00:00
// ---------- 유닛 ----------
public List < Unit > AliveUnits ( Faction f )
{
var list = new List < Unit > ( ) ;
for ( int i = 0 ; i < units . Count ; i + + )
{
var u = units [ i ] ;
if ( u ! = null & & u . IsAlive & & u . Faction = = f ) list . Add ( u ) ;
}
return list ;
}
public int AliveCount ( Faction f )
{
int n = 0 ;
for ( int i = 0 ; i < units . Count ; i + + )
{
var u = units [ i ] ;
if ( u ! = null & & u . IsAlive & & u . Faction = = f ) n + + ;
}
return n ;
}
public Unit UnitNear ( Vector2 p , Faction ? faction )
{
return Combat . UnitNear ( units , p , faction , 0.25f ) ;
}
2026-11-04 04:05:46 +00:00
public Unit SpawnUnit ( UnitType type , Faction faction , Vector2 pos , string name , float hpMult = 1f , float atkMult = 1f , bool boss = false , string art = null )
2026-11-03 19:10:10 +00:00
{
var go = new GameObject ( "Unit" ) ;
go . transform . position = new Vector3 ( pos . x , pos . y , 0f ) ;
var u = go . AddComponent < Unit > ( ) ;
2026-11-04 04:05:46 +00:00
u . Init ( Config , type , faction , name , hpMult , atkMult , boss , art ) ;
2026-11-03 19:10:10 +00:00
u . Position = Board . ClampInside ( pos , u . Radius ) ;
units . Add ( u ) ;
return u ;
}
public void ClearUnits ( )
{
for ( int i = 0 ; i < units . Count ; i + + )
{
if ( units [ i ] = = null ) continue ;
units [ i ] . gameObject . SetActive ( false ) ; // 콜라이더를 즉시 물리 월드에서 제거
Destroy ( units [ i ] . gameObject ) ;
}
units . Clear ( ) ;
2026-11-05 14:31:27 +00:00
if ( Skills ! = null ) Skills . Clear ( ) ;
2026-11-05 16:20:07 +00:00
if ( Gimmicks ! = null ) Gimmicks . Clear ( ) ;
2026-11-03 19:10:10 +00:00
}
// ---------- 스테이지 ----------
public void StartStage ( int index )
2026-11-05 15:22:54 +00:00
{
Mode = null ;
StageIndex = Mathf . Clamp ( index , 0 , Config . stages . Length - 1 ) ;
Begin ( Config . stages [ StageIndex ] ) ;
}
/// <summary>연무장 모드 전투 시작(적 편성 = mode.stage · PD #1093 C).</summary>
public void StartMode ( BattleMode mode )
{
if ( mode = = null | | mode . stage = = null ) return ;
Mode = mode ;
2026-11-17 16:03:13 +00:00
if ( mode . rules ! = null ) mode . rules . Bind ( this ) ;
2026-11-05 15:22:54 +00:00
Begin ( mode . stage ) ;
}
void Begin ( BalanceConfig . StageDef stage )
2026-11-03 19:10:10 +00:00
{
StopAllCoroutines ( ) ;
2026-11-12 14:41:13 +00:00
BossIntro . Abort ( ) ;
2026-11-03 19:10:10 +00:00
ClearUnits ( ) ;
2026-11-03 19:29:16 +00:00
Phase = BattlePhase . Setup ;
2026-11-05 15:22:54 +00:00
sideEffects [ 0 ] = SideEffectsProvider ! = null ? SideEffectsProvider ( Faction . Player ) : null ;
sideEffects [ 1 ] = SideEffectsProvider ! = null ? SideEffectsProvider ( Faction . Enemy ) : null ;
2026-11-03 19:10:10 +00:00
2026-11-05 12:11:10 +00:00
// 아군 = 편성 프리셋(자리 0~2 전열 · 3~4 후열 → playerSpawnPoints) · 방어 배율은 Unit.Init 에 없어 생성 뒤 적용
deployed . Clear ( ) ;
2026-11-05 14:31:27 +00:00
SkillCatalog . Invalidate ( ) ; // 임포트로 바뀐 스킬 표를 전투마다 다시 읽음
2026-11-09 14:12:52 +00:00
SkillVfx . Reload ( ) ; // 스킬 이펙트 표(skill_vfx.csv)도 전투마다 다시 읽음
2026-11-10 04:19:44 +00:00
HitFeel . Reload ( ) ; // 타격감 표(hit_feel.csv)
2026-11-17 07:27:22 +00:00
Tutorial = Mode = = null ? TutorialRules . For ( stage ) : null ; // 1장 학습 판(메모리 세이브 = 자동 테스트·검증 캡처에서는 꺼짐 · TutorialRules.Mode)
2026-11-05 12:11:10 +00:00
var lineup = LineupProvider ! = null ? LineupProvider ( ) : null ;
2026-11-17 07:27:22 +00:00
if ( Tutorial ! = null ) lineup = Tutorial . Lineup ( Config , lineup ) ; // 고정 편성 판 = 그 영웅들(보유 여부와 무관)
2026-11-17 16:03:13 +00:00
var rules = Mode ! = null ? Mode . rules : null ;
if ( rules ! = null )
{
var fixedLineup = rules . Lineup ( lineup ) ; // 연의 전기 고정 편성(보유 · 성장 무관)
if ( fixedLineup ! = null ) lineup = fixedLineup ;
}
if ( rules ! = null & & rules . MaxAllies > 0 & & lineup ! = null ) // 출전 칸 수 상한(병법 훈련 정예 = 4기)
{
lineup = new List < LineupEntry > ( lineup ) ;
lineup . Sort ( ( a , b ) = > a . slot . CompareTo ( b . slot ) ) ;
if ( lineup . Count > rules . MaxAllies ) lineup . RemoveRange ( rules . MaxAllies , lineup . Count - rules . MaxAllies ) ;
}
2026-11-05 12:11:10 +00:00
if ( lineup ! = null )
2026-11-03 19:10:10 +00:00
{
2026-11-17 16:03:13 +00:00
if ( rules ! = null )
{
lineup = new List < LineupEntry > ( lineup ) ;
lineup . Sort ( ( a , b ) = > ( a ! = null ? a . slot : 0 ) . CompareTo ( b ! = null ? b . slot : 0 ) ) ;
}
int ord = 0 ; // 컨텐츠 모드 출전 자리 = 칸 번호가 아니라 출전 순번(칸 0 · 2 · 4 편성도 자리 0 · 1 · 2 · Fable QA 8)
2026-11-05 12:11:10 +00:00
foreach ( var h in lineup )
{
if ( h = = null | | h . slot < 0 | | h . slot > = Config . playerSpawnPoints . Length ) continue ;
2026-11-17 07:27:22 +00:00
Vector2 at = Config . playerSpawnPoints [ h . slot ] ;
if ( Tutorial ! = null ) at = Tutorial . AllyPosition ( h , at ) ; // 배치 표의 시작 자리
2026-11-17 16:03:13 +00:00
if ( rules ! = null ) at = rules . AllyPosition ( ord + + , at ) ; // 컨텐츠 모드 배치 표의 출전 자리
2026-11-17 07:27:22 +00:00
var u = SpawnUnit ( h . type , Faction . Player , at , h . name , h . hpMult , h . atkMult , false , h . art ) ;
2026-11-05 12:11:10 +00:00
u . Def = Mathf . Max ( 0 , Mathf . RoundToInt ( Config . GetStats ( h . type ) . def * h . defMult ) ) ;
2026-11-10 04:19:44 +00:00
var hd = SkillCatalog . Hero ( h . id ) ;
2026-11-10 10:00:18 +00:00
u . Camp = hd ! = null & & hd . faction ! = null ? hd . faction : "" ; // 진영별 이펙트(skill_vfx.csv s_camp) · 스킬 진영 대상
u . Female = hd ! = null & & hd . Female ; // 스킬 조건 남성·여성(2026-11-10 #1112)
u . HeroId = h . id ? ? "" ;
2026-11-05 14:31:27 +00:00
Skills . AttachLineup ( u , h ) ; // 액티브·패시브(레벨 · ★5) · 산채 체력은 여기서 최대 HP 반영
2026-11-05 12:11:10 +00:00
deployed . Add ( h ) ;
2026-11-17 07:27:22 +00:00
if ( Tutorial ! = null ) Tutorial . BindAlly ( h , u ) ;
2026-11-05 12:11:10 +00:00
}
2026-11-03 19:10:10 +00:00
}
2026-11-17 07:27:22 +00:00
if ( Tutorial ! = null & & Tutorial . HasEnemies ) Tutorial . SpawnEnemies ( this , stage ) ; // 배치 표 좌표·배율(자동 진형 대신)
else
2026-11-03 19:10:10 +00:00
{
2026-11-17 07:27:22 +00:00
foreach ( var e in stage . enemies )
{
var u = SpawnUnit ( e . type , Faction . Enemy , e . position , e . name , e . hpMult , e . atkMult , e . isBoss , e . art ) ;
2026-11-18 03:23:53 +00:00
if ( e . defMult > 0f & & ! Mathf . Approximately ( e . defMult , 1f ) ) u . Def = Mathf . Max ( 0 , Mathf . RoundToInt ( Config . GetStats ( e . type ) . def * e . defMult ) ) ; // 스테이지 적 방어 배율(2026-11-18 레벨디자인)
2026-11-17 07:27:22 +00:00
Skills . AttachEnemy ( u , e , TacticalAI . BossUsesActive ( stage , e ) ) ; // 적 무장 = 패시브 · 1부 보스 = 액티브도(적 AI 가 예약해 씀 · PD #1098)
}
2026-11-03 19:10:10 +00:00
}
2026-11-17 07:27:22 +00:00
if ( Tutorial ! = null ) Tutorial . SpawnNpcs ( this ) ; // 구출 대상(조작 불가 · 반격 없음 · 적 AI 의 표적)
2026-11-17 16:03:13 +00:00
if ( Board ! = null ) Board . Restrict ( rules ! = null ? rules . BoardArea : null ) ; // 투기장 = 좁힌 전장(12× 18) · 그 밖 = 원래 크기
2026-11-05 16:20:07 +00:00
GimmickLayer . Ensure ( this ) . Build ( stage ) ; // 지형 기믹 레이어(배경 위 · 유닛 아래 · PD #1097)
2026-11-17 16:03:13 +00:00
if ( rules ! = null )
{
TurnNumber = 1 ; // 규칙의 시작 처리가 1턴 기준으로 예고 · 수레를 놓는다
rules . OnBegin ( ) ; // 배치 표의 기믹 · 허수아비 · 군량고(컨텐츠 모드 · 2026-11-17)
GimmickLayer . Current . ResolveOverlaps ( ) ;
}
2026-11-17 07:27:22 +00:00
TutorialDirector . Ensure ( this ) . BeginStage ( Tutorial ) ; // 학습 판 안내 · 남은 턴 · 함정 표시(유닛·기믹 배치 뒤 · 일반 판 = 비움)
2026-11-03 19:10:10 +00:00
TurnNumber = 1 ;
2026-11-17 16:03:13 +00:00
ambushOpening = false ;
2026-11-05 14:31:27 +00:00
Skills . BeginBattle ( ) ;
2026-11-03 19:10:10 +00:00
LastMessage = stage . title + " — 아군 차례" ;
2026-11-05 16:20:07 +00:00
string tip = GimmickTables . Table ! = null ? GimmickTables . Table . TipFor ( stage . chapter , stage . stage ) : "" ;
if ( tip . Length > 0 ) LastMessage + = " · " + tip ; // 1장 튜토리얼 문구(tutorial_tips.csv · PD #1098 §3)
2026-11-03 19:29:16 +00:00
if ( StageStarted ! = null ) StageStarted ( ) ;
2026-11-12 14:41:13 +00:00
// 보스 등장 연출(2026-11-12 시나리오 이벤트 C2 · boss_intro.csv) — 연출 동안 Setup(아군 조작 잠금) → 끝나면 아군 차례 · 연무장(Mode) 전투 제외
bool cleared = StageClearedProvider ! = null & & StageClearedProvider ( stage . chapter , stage . stage ) ;
if ( Mode = = null & & BossIntro . Wants ( stage , cleared ) ) BossIntro . Begin ( this , stage , cleared , ( ) = > SetPhase ( BattlePhase . PlayerTurn ) ) ;
2026-11-17 16:03:13 +00:00
else if ( rules ! = null & & rules . EnemyFirst ) // 선제(병법 훈련) — 적이 먼저 움직이고 그 적 턴은 턴 수를 세지 않는다
{
ambushOpening = true ;
SetPhase ( BattlePhase . Resolving ) ;
StartCoroutine ( EnemyTurnRoutine ( ) ) ;
}
2026-11-12 14:41:13 +00:00
else SetPhase ( BattlePhase . PlayerTurn ) ;
2026-11-03 19:10:10 +00:00
}
2026-11-17 16:03:13 +00:00
/// <summary>선제 판의 첫 적 턴(턴 수 · 제한 턴을 세지 않는다).</summary>
bool ambushOpening ;
2026-11-12 14:41:13 +00:00
/// <summary>이미 깬 스테이지인가(장, 번호) — 보스 등장 연출의 다시 출정 축약(replay_mode) 판정 · 아웃게임 세이브가 넣는다.</summary>
public Func < int , int , bool > StageClearedProvider ;
2026-11-04 18:38:47 +00:00
/// <summary>결과 화면 탭 처리기(true = 승리). 있으면 다음 전투로 넘기지 않고 이 처리기(월드맵 복귀)를 부른다.</summary>
public Action < bool > ResultHandler ;
/// <summary>전투 없음(월드맵 표시 중): 진행 중 루틴·유닛을 치우고 Setup 단계로.</summary>
public void GoIdle ( )
{
StopAllCoroutines ( ) ;
2026-11-12 14:41:13 +00:00
BossIntro . Abort ( ) ;
2026-11-04 18:38:47 +00:00
ClearUnits ( ) ;
SetPhase ( BattlePhase . Setup ) ;
}
2026-11-03 19:10:10 +00:00
public void ContinueAfterResult ( )
{
2026-11-05 15:22:54 +00:00
if ( Mode ! = null & & ( Phase = = BattlePhase . StageClear | | Phase = = BattlePhase . Defeat ) )
{
var exit = Mode . onExit ;
Mode = null ;
GoIdle ( ) ;
if ( exit ! = null ) exit ( ) ;
return ;
}
2026-11-04 18:38:47 +00:00
if ( ResultHandler ! = null & & ( Phase = = BattlePhase . StageClear | | Phase = = BattlePhase . Defeat ) )
{
ResultHandler ( Phase = = BattlePhase . StageClear ) ;
return ;
}
2026-11-03 19:10:10 +00:00
if ( Phase = = BattlePhase . StageClear )
{
StartStage ( ( StageIndex + 1 ) % Config . stages . Length ) ;
}
else if ( Phase = = BattlePhase . Defeat )
{
StartStage ( StageIndex ) ;
}
}
// ---------- 아군 행동 ----------
public bool CanAct ( Unit u )
{
return Phase = = BattlePhase . PlayerTurn & & u ! = null & & u . Faction = = Faction . Player & & u . IsAlive & & ! u . ActedThisTurn ;
}
2026-11-17 07:27:22 +00:00
/// <summary>궁병·책사 공격 가능 범위(사거리 · 가장자리 간격 기준) 안에 상대 유닛이 하나라도 있는가 — 도넛 색 표시용.</summary>
2026-11-04 04:05:46 +00:00
public bool AnyEnemyWithinArcherReach ( Unit u )
{
if ( u = = null ) return false ;
2026-11-17 07:27:22 +00:00
float reach = SkillMods . Range ( u ) ;
2026-11-04 04:05:46 +00:00
Faction other = u . Faction = = Faction . Player ? Faction . Enemy : Faction . Player ;
foreach ( var e in AliveUnits ( other ) )
{
float gap = Vector2 . Distance ( u . Position , e . Position ) - u . Radius * Combat . CastRadiusScale - e . Radius ;
if ( gap < = reach ) return true ;
}
return false ;
}
2026-11-17 07:27:22 +00:00
/// <summary>gaugeCrit = 조준 게이지 치명타 구간에서 놓았다 → 이 행동 동안 u 가 주는 공격은 반드시 치명타(PD 2026-11-16).</summary>
2026-11-18 03:23:53 +00:00
/// <summary>끌기 조준 · 원거리 병종이 판정 게이지 빈 칸에 놓음 = 이번 행동은 공격 없이 이동만(PD 2026-11-18 · 테스트) — PlayerActionRoutine 이 읽고 지운다.</summary>
bool forceMoveOnly ;
public bool RequestPlayerAction ( Unit u , Vector2 target , bool gaugeCrit = false , bool moveOnly = false )
2026-11-03 19:10:10 +00:00
{
if ( ! CanAct ( u ) ) return false ;
2026-11-18 03:23:53 +00:00
forceMoveOnly = moveOnly ;
2026-11-17 16:03:13 +00:00
if ( Mode ! = null & & Mode . rules ! = null ) target = Mode . rules . AdjustTarget ( u , target ) ; // 컨텐츠 모드(바람 턴 화살 휨)
2026-11-03 19:29:16 +00:00
SetPhase ( BattlePhase . Resolving ) ;
if ( UnitActing ! = null ) UnitActing ( u ) ;
2026-11-17 07:27:22 +00:00
StartCoroutine ( PlayerActionRoutine ( u , target , gaugeCrit ) ) ;
2026-11-03 19:10:10 +00:00
return true ;
}
2026-11-17 07:27:22 +00:00
IEnumerator PlayerActionRoutine ( Unit u , Vector2 target , bool gaugeCrit )
2026-11-03 19:10:10 +00:00
{
2026-11-05 14:31:27 +00:00
bool wasBonus = u . BonusMoveAvailable ;
2026-11-18 03:23:53 +00:00
bool moveOnly = ( wasBonus & & ! Skills . BonusCanAttack ( u ) ) | | forceMoveOnly ; // 호치·강동의 호랑이 = 추가 이동에서 공격 가능 · 끌기 조준 빈 칸 = 이동만
forceMoveOnly = false ;
2026-11-03 19:10:10 +00:00
var o = new ActionOutcome ( ) ;
2026-11-17 07:27:22 +00:00
u . GaugeCrit = gaugeCrit ;
2026-11-03 19:10:10 +00:00
yield return Resolver . Resolve ( u , target , moveOnly , o ) ;
2026-11-17 07:27:22 +00:00
u . GaugeCrit = false ;
2026-11-05 14:31:27 +00:00
yield return ApplyOverwatch ( u , o ) ;
2026-11-03 19:10:10 +00:00
2026-11-10 10:00:18 +00:00
// 추가 이동(보병 목표점 명중) → 끝나면 스킬 재행동(이도류·자오곡·백의도강·파로·군령 …) → 행동 끝
2026-11-05 14:31:27 +00:00
if ( u . IsAlive & & Skills . NextBonus ( u , wasBonus , o ) ) u . GrantBonusMove ( ) ;
2026-11-10 10:00:18 +00:00
else if ( u . IsAlive & & Skills . TakeReaction ( u ) )
{
Skills . ClearBonus ( u ) ;
u . GrantReAction ( ) ;
}
2026-11-05 14:31:27 +00:00
else
{
u . MarkActed ( ) ;
Skills . ClearBonus ( u ) ;
}
2026-11-03 19:10:10 +00:00
LastMessage = Describe ( u , o , moveOnly ) ;
2026-11-17 16:03:13 +00:00
if ( Mode ! = null & & Mode . rules ! = null ) Mode . rules . OnAction ( u , o ) ; // 컨텐츠 모드 집계(과제 · 허수아비 다시 솟음)
2026-11-03 19:10:10 +00:00
NotifyChanged ( ) ;
if ( CheckBattleEnd ( ) ) yield break ;
2026-11-17 16:03:13 +00:00
if ( Mode ! = null & & Mode . rules ! = null & & Mode . rules . Alternating )
{
yield return AlternateStep ( ) ; // 투기장 교대 조작
yield break ;
}
2026-11-03 19:10:10 +00:00
if ( AllPlayersActed ( ) )
{
yield return EnemyTurnRoutine ( ) ;
}
else
{
2026-11-03 19:29:16 +00:00
SetPhase ( BattlePhase . PlayerTurn ) ;
2026-11-03 19:10:10 +00:00
}
}
2026-11-17 16:03:13 +00:00
// ---------- 교대 조작(투기장 · arena_rules turn.* · 2026-11-18) ----------
bool AnyPlayerCanAct ( )
{
foreach ( var u in AliveUnits ( Faction . Player ) )
if ( ! u . ActedThisTurn & & ! u . Npc ) return true ;
return false ;
}
/// <summary>
/// 아군 1기가 움직인 뒤: 수비 1기(전술 AI · 아직 움직이지 않은 유닛 중 가치 판단) → 아군 차례 · 유닛 수가 다르면 남은 쪽이 이어서(tail) ·
/// 양쪽 모두 움직이면 라운드 끝(지속 피해 · 지대 · 스킬 라운드 = 라운드에 한 번) → 다음 라운드도 도전자 먼저 · 라운드 상한 = TurnLimit(OnTurnLimit 판정).
/// </summary>
IEnumerator AlternateStep ( )
{
while ( true )
{
if ( CheckBattleEnd ( ) ) yield break ;
foreach ( var e in AliveUnits ( Faction . Enemy ) ) // 행동 불가 = 자동으로 넘어감(행동 1회 소비)
if ( ! e . ActedThisTurn & & ( Skills . Suppressed ( e ) | | GimmickLayer . Skips ( e ) ) ) e . MarkActed ( ) ;
var pend = new List < Unit > ( ) ;
foreach ( var e in AliveUnits ( Faction . Enemy ) )
if ( ! e . ActedThisTurn ) pend . Add ( e ) ;
if ( pend . Count > 0 )
{
SetPhase ( BattlePhase . EnemyTurn ) ;
var plan = TacticalAI . Available ? TacticalAI . Next ( this , pend , Stage . aiAccuracy , float . MaxValue , Rng ) : null ;
Unit e = plan ! = null ? plan . Unit : pend [ 0 ] ;
Vector2 target ;
if ( plan ! = null ) target = plan . Target ;
else
{
var aim = EnemyAI . Decide ( e , AliveUnits ( Faction . Player ) , Stage . aiAccuracy , float . MaxValue , Rng , Board , Config ) ;
target = aim . HasValue ? aim . Value : e . Position ;
}
if ( UnitActing ! = null ) UnitActing ( e ) ;
yield return Fx . Wait ( 0.3f ) ;
if ( plan ! = null & & plan . UseSkill & & Skills . Of ( e ) ! = null ) Skills . Of ( e ) . Reserved = true ;
var o = new ActionOutcome ( ) ;
yield return Resolver . Resolve ( e , target , false , o ) ;
e . MarkActed ( ) ;
yield return ApplyOverwatch ( e , o ) ;
LastMessage = Describe ( e , o , false ) ;
if ( Mode ! = null & & Mode . rules ! = null ) Mode . rules . OnAction ( e , o ) ;
if ( e . IsAlive & & Skills . TakeReaction ( e ) ) e . GrantReAction ( ) ; // 수비 스킬 재행동(Fable QA 11)
NotifyChanged ( ) ;
if ( CheckBattleEnd ( ) ) yield break ;
yield return Fx . Wait ( 0.2f ) ;
if ( AnyPlayerCanAct ( ) )
{
SetPhase ( BattlePhase . PlayerTurn ) ;
yield break ;
}
continue ; // 아군이 다 움직였다 = 수비가 남은 유닛을 이어서
}
if ( AnyPlayerCanAct ( ) )
{
SetPhase ( BattlePhase . PlayerTurn ) ;
yield break ;
}
// 라운드 끝
if ( TurnLimit > 0 & & TurnNumber > = TurnLimit )
{
string msg ;
var end = Mode . rules . OnTurnLimit ( out msg ) ;
LastMessage = msg ;
SetPhase ( end ) ;
yield break ;
}
Skills . OnEnemyTurnStart ( ) ;
foreach ( var en in AliveUnits ( Faction . Enemy ) ) en . ResetForNewTurn ( ) ;
if ( Gimmicks ! = null ) yield return Gimmicks . TurnStart ( Faction . Enemy ) ;
yield return Skills . TurnBegin ( Faction . Enemy ) ;
if ( CheckBattleEnd ( ) ) yield break ;
foreach ( var u in AliveUnits ( Faction . Player ) ) u . ResetForNewTurn ( ) ;
Skills . OnPlayerTurnStart ( ) ;
TurnNumber + + ;
if ( Gimmicks ! = null ) yield return Gimmicks . TurnStart ( Faction . Player ) ;
yield return Skills . TurnBegin ( Faction . Player ) ;
if ( CheckBattleEnd ( ) ) yield break ;
LastMessage = TurnNumber + "라운드 — 도전자 먼저" ;
if ( AnyPlayerCanAct ( ) )
{
SetPhase ( BattlePhase . PlayerTurn ) ;
yield break ;
}
}
}
2026-11-03 19:10:10 +00:00
bool AllPlayersActed ( )
{
foreach ( var u in AliveUnits ( Faction . Player ) )
{
if ( ! u . ActedThisTurn ) return false ;
}
return true ;
}
public bool OnlyBonusMovesRemain ( )
{
bool any = false ;
foreach ( var u in AliveUnits ( Faction . Player ) )
{
if ( u . ActedThisTurn ) continue ;
if ( ! u . BonusMoveAvailable ) return false ;
any = true ;
}
return any ;
}
/// <summary>빈 곳 탭: 남은 행동이 추가 이동뿐이면 건너뛰고 적군 턴으로.</summary>
public void OnEmptyTap ( )
{
if ( Phase ! = BattlePhase . PlayerTurn ) return ;
if ( ! OnlyBonusMovesRemain ( ) ) return ;
foreach ( var u in AliveUnits ( Faction . Player ) )
{
2026-11-05 14:31:27 +00:00
if ( ! u . BonusMoveAvailable ) continue ;
u . MarkActed ( ) ;
Skills . ClearBonus ( u ) ;
2026-11-03 19:10:10 +00:00
}
2026-11-03 19:29:16 +00:00
SetPhase ( BattlePhase . Resolving ) ;
2026-11-17 16:03:13 +00:00
if ( Mode ! = null & & Mode . rules ! = null & & Mode . rules . Alternating ) StartCoroutine ( AlternateStep ( ) ) ; // 투기장 = 교대 조작(Fable QA 3)
else StartCoroutine ( EnemyTurnRoutine ( ) ) ;
2026-11-03 19:10:10 +00:00
}
2026-11-05 14:31:27 +00:00
/// <summary>즉시형 액티브 연출(장판 일갈 밀기 · 변진 이동 등) — 아군 턴에만 · 끝나면 다시 아군 턴(행동 소모 없음).</summary>
public bool RunSkillRoutine ( IEnumerator routine )
{
if ( Phase ! = BattlePhase . PlayerTurn | | routine = = null ) return false ;
SetPhase ( BattlePhase . Resolving ) ;
StartCoroutine ( SkillRoutine ( routine ) ) ;
return true ;
}
IEnumerator SkillRoutine ( IEnumerator routine )
{
yield return routine ;
NotifyChanged ( ) ;
if ( CheckBattleEnd ( ) ) yield break ;
SetPhase ( BattlePhase . PlayerTurn ) ;
}
2026-11-03 19:10:10 +00:00
// ---------- 적군 턴 ----------
public Coroutine RunEnemyTurn ( )
{
return StartCoroutine ( EnemyTurnRoutine ( ) ) ;
}
IEnumerator EnemyTurnRoutine ( )
{
2026-11-05 14:31:27 +00:00
Skills . OnEnemyTurnStart ( ) ; // 이번 아군 턴 효과(동남풍·고육계) · 쓰지 않은 예약 정리
2026-11-03 19:29:16 +00:00
SetPhase ( BattlePhase . EnemyTurn ) ;
2026-11-03 19:10:10 +00:00
LastMessage = "적군 차례" ;
NotifyChanged ( ) ;
foreach ( var e in AliveUnits ( Faction . Enemy ) ) e . ResetForNewTurn ( ) ;
2026-11-05 16:20:07 +00:00
if ( Gimmicks ! = null )
{
2026-11-10 10:00:18 +00:00
yield return Gimmicks . TurnStart ( Faction . Enemy ) ; // 군기 · 중독 · 불 · 행동 불가(PD #1097) · 스킬 기절
2026-11-05 16:20:07 +00:00
if ( CheckBattleEnd ( ) ) yield break ;
}
2026-11-10 10:00:18 +00:00
yield return Skills . TurnBegin ( Faction . Enemy ) ; // 스킬 라운드(아군 턴 끝 회복·정화 · 시한 효과 · 중독·화상 · 지대 · 2026-11-10 #1112)
if ( CheckBattleEnd ( ) ) yield break ;
2026-11-17 16:03:13 +00:00
var rules = Mode ! = null ? Mode . rules : null ;
if ( rules ! = null )
{
yield return rules . OnTurnStart ( Faction . Enemy ) ;
if ( CheckBattleEnd ( ) ) yield break ;
}
2026-11-03 19:29:16 +00:00
yield return Fx . Wait ( 0.4f ) ;
2026-11-03 19:10:10 +00:00
float accuracy = Stage . aiAccuracy ;
2026-11-05 14:31:27 +00:00
float aggro = Mathf . Max ( 0f , Stage . aiAggroRange + Skills . AggroAdd ( Faction . Enemy ) ) ; // 신산 = 적 교전 범위 −
2026-11-03 19:29:16 +00:00
int acted = 0 ;
2026-11-05 16:20:07 +00:00
// 예측 시뮬레이션 AI(PD #1098): 남은 적 전원 평가 → 서포터 → 돌격 → 사격 · 1기 실행마다 재평가 · 교전 범위 밖 = 대기
var pending = new List < Unit > ( ) ;
foreach ( var e in AliveUnits ( Faction . Enemy ) )
2026-11-03 19:10:10 +00:00
{
2026-11-05 14:31:27 +00:00
if ( Skills . Suppressed ( e ) ) continue ; // 장판 일갈·태평요술 = 이번 적 턴 교전 반응 없음
2026-11-05 16:20:07 +00:00
if ( GimmickLayer . Skips ( e ) ) continue ; // 함정·강 = 이번 턴 행동 불가
2026-11-17 16:03:13 +00:00
if ( rules ! = null & & ! rules . EnemyActs ( e ) ) continue ; // 컨텐츠 모드: 움직이지 않는 적(허수아비)
2026-11-05 16:20:07 +00:00
pending . Add ( e ) ;
}
2026-11-09 14:12:52 +00:00
if ( EnemyHold ) pending . Clear ( ) ; // 스킬 테스트 씬: 더미는 행동하지 않음(턴 · 쿨 · 시한 효과는 그대로 넘어감)
2026-11-17 07:27:22 +00:00
if ( EnemyHold & & EnemyHoldSeconds > 0f ) yield return Fx . Wait ( EnemyHoldSeconds ) ; // 가만히 있는 적 턴도 눈에 보이게 머묾(지속 효과·상태 이상 확인용)
2026-11-05 16:20:07 +00:00
bool tactical = TacticalAI . Available ;
while ( pending . Count > 0 )
{
pending . RemoveAll ( x = > x = = null | | ! x . IsAlive ) ;
2026-11-03 19:10:10 +00:00
var players = AliveUnits ( Faction . Player ) ;
2026-11-05 16:20:07 +00:00
if ( players . Count = = 0 | | pending . Count = = 0 ) break ;
2026-11-03 19:10:10 +00:00
2026-11-05 16:20:07 +00:00
Unit e ;
Vector2 target ;
bool useSkill = false ;
2026-11-17 16:03:13 +00:00
if ( rules ! = null ) // 컨텐츠 모드의 정해진 행동(맹장 기본 공격 · 수레 이동) — 슬링샷 AI 대신
{
Unit scripted = pending . Find ( p = > rules . ScriptsEnemy ( p ) ) ;
if ( scripted ! = null )
{
pending . Remove ( scripted ) ;
if ( UnitActing ! = null ) UnitActing ( scripted ) ;
yield return Fx . Wait ( 0.3f ) ;
yield return rules . RunEnemy ( scripted ) ;
scripted . MarkActed ( ) ;
NotifyChanged ( ) ;
acted + + ;
if ( scripted . IsAlive & & rules . ActAgain ( scripted ) ) pending . Add ( scripted ) ;
if ( CheckBattleEnd ( ) ) yield break ;
yield return Fx . Wait ( 0.25f ) ;
continue ;
}
}
Unit forced = null ;
if ( rules ! = null ) // 컨텐츠 모드가 표적을 정하는 적(삼형제 행동 · 복수) = 그 아군만 보고 조준
foreach ( var p in pending )
{
forced = rules . EnemyTarget ( p ) ;
if ( forced = = null ) continue ;
var aimF = EnemyAI . Decide ( p , new List < Unit > { forced } , 1f , float . MaxValue , Rng , Board , Config ) ;
e = p ;
target = aimF . HasValue ? aimF . Value : forced . Position ;
goto Act ;
}
2026-11-05 16:20:07 +00:00
if ( tactical )
{
var plan = TacticalAI . Next ( this , pending , accuracy , aggro , Rng ) ;
if ( plan = = null ) break ; // 남은 유닛 = 교전 범위 밖 → 자리 지킴
e = plan . Unit ;
target = plan . Target ;
useSkill = plan . UseSkill ;
LastAiPlan = plan ;
}
else
{
e = pending [ 0 ] ;
Vector2 ? aim = EnemyAI . Decide ( e , players , accuracy , aggro , Rng , Board , Config ) ; // 가중치 자산이 없으면 기존 조준
if ( ! aim . HasValue )
{
pending . RemoveAt ( 0 ) ;
continue ;
}
target = aim . Value ;
}
2026-11-17 16:03:13 +00:00
Act :
2026-11-05 16:20:07 +00:00
pending . Remove ( e ) ;
2026-11-03 19:29:16 +00:00
if ( UnitActing ! = null ) UnitActing ( e ) ;
yield return Fx . Wait ( 0.3f ) ; // 카메라가 따라올 시간
2026-11-05 16:20:07 +00:00
if ( useSkill & & Skills . Of ( e ) ! = null ) Skills . Of ( e ) . Reserved = true ; // 적 보스 액티브(다음 행동형 · 1부 보스만)
2026-11-03 19:10:10 +00:00
var o = new ActionOutcome ( ) ;
2026-11-05 16:20:07 +00:00
yield return Resolver . Resolve ( e , target , false , o ) ;
2026-11-17 07:27:22 +00:00
e . MarkActed ( ) ; // 이번 적 턴 행동을 마침 — 턴 지속 효과 소멸 규칙이 「이미 행동을 마친 대상」을 가려냄(PD 2026-11-13 · 아군은 RequestPlayerAction 이 표시)
2026-11-05 14:31:27 +00:00
yield return ApplyOverwatch ( e , o ) ;
2026-11-03 19:10:10 +00:00
LastMessage = Describe ( e , o , false ) ;
2026-11-17 16:03:13 +00:00
if ( rules ! = null ) rules . OnAction ( e , o ) ;
2026-11-03 19:10:10 +00:00
NotifyChanged ( ) ;
2026-11-03 19:29:16 +00:00
acted + + ;
2026-11-17 07:27:22 +00:00
if ( e . IsAlive & & Skills . TakeReaction ( e ) ) // 적 스킬 재행동
{
pending . Add ( e ) ;
e . GrantReAction ( ) ;
}
2026-11-03 19:10:10 +00:00
if ( CheckBattleEnd ( ) ) yield break ;
yield return Fx . Wait ( 0.25f ) ;
}
2026-11-03 19:29:16 +00:00
if ( acted = = 0 ) yield return Fx . Wait ( 0.3f ) ;
2026-11-03 19:10:10 +00:00
2026-11-17 16:03:13 +00:00
bool opening = ambushOpening ;
ambushOpening = false ;
if ( ! opening & & TurnLimit > 0 & & TurnNumber > = TurnLimit ) // 제한 턴(연무장 적장 토벌 · 학습 판 n_turn_limit) = 전투 끝
2026-11-05 15:22:54 +00:00
{
2026-11-17 16:03:13 +00:00
string msg = TurnLimit + "턴 종료" ;
var end = rules ! = null ? rules . OnTurnLimit ( out msg ) : BattlePhase . Defeat ; // 컨텐츠 모드 집계형 던전 = 판정이 있으면 승리
LastMessage = msg ;
if ( end = = BattlePhase . StageClear )
foreach ( var p in AliveUnits ( Faction . Player ) )
if ( p . View ! = null ) p . View . PlayVictory ( ) ;
SetPhase ( end ) ;
2026-11-05 15:22:54 +00:00
yield break ;
}
2026-11-03 19:10:10 +00:00
foreach ( var u in AliveUnits ( Faction . Player ) ) u . ResetForNewTurn ( ) ;
2026-11-05 14:31:27 +00:00
Skills . OnPlayerTurnStart ( ) ; // 이번 적 턴 효과(호위·철벽·간웅·일갈·안개) · 견제 강화 정리
2026-11-17 16:03:13 +00:00
if ( ! opening ) TurnNumber + + ; // 선제 판의 첫 적 턴은 턴 수를 세지 않는다
2026-11-05 16:20:07 +00:00
if ( Gimmicks ! = null )
{
2026-11-10 10:00:18 +00:00
yield return Gimmicks . TurnStart ( Faction . Player ) ; // 군기 · 불 지속 · 중독 · 불 · 행동 불가(PD #1097) · 스킬 기절
2026-11-05 16:20:07 +00:00
if ( CheckBattleEnd ( ) ) yield break ;
}
2026-11-10 10:00:18 +00:00
yield return Skills . TurnBegin ( Faction . Player ) ; // 스킬 라운드(적 턴 끝 처리 · 시한 효과 · 중독·화상 · 회복 · 지대 · 망령 소멸)
if ( CheckBattleEnd ( ) ) yield break ;
2026-11-17 16:03:13 +00:00
if ( rules ! = null )
{
yield return rules . OnTurnStart ( Faction . Player ) ;
if ( CheckBattleEnd ( ) ) yield break ;
}
2026-11-03 19:29:16 +00:00
LastMessage = TurnNumber + "번째 턴 — 아군 차례" + ( acted = = 0 ? " (적은 교전 범위 밖에서 대기)" : "" ) ;
2026-11-05 16:20:07 +00:00
if ( AliveCount ( Faction . Player ) > 0 & & AllPlayersActed ( ) )
{
LastMessage = TurnNumber + "번째 턴 — 아군 전원 행동 불가" ;
yield return Fx . Wait ( 0.4f ) ;
yield return EnemyTurnRoutine ( ) ; // 함정·강으로 아군 전원이 쉬는 턴
yield break ;
}
2026-11-03 19:29:16 +00:00
SetPhase ( BattlePhase . PlayerTurn ) ;
2026-11-03 19:10:10 +00:00
}
2026-11-05 16:20:07 +00:00
/// <summary>마지막 적 AI 결정(디버그 · 테스트 · 캡처).</summary>
public AiPlan LastAiPlan ;
2026-11-03 19:10:10 +00:00
/// <summary>창병 대기: 상대 유닛이 지나간 경로가 대기 중인 창병 반경을 스치면 피해(창병마다 1회).</summary>
public IEnumerator ApplyOverwatch ( Unit mover , List < Vector2 > path )
{
2026-11-05 14:31:27 +00:00
var o = new ActionOutcome ( ) ;
if ( path ! = null ) o . Path . AddRange ( path ) ;
yield return ApplyOverwatch ( mover , o ) ;
}
/// <summary>
/// 창병 대기 견제(스킬 반영 · PD #1093 B): 반경 = SkillMods.OverwatchRadius(후계·백마의 창·청룡언월) · 지나간 적 1기당 1회(기본) × 견제 횟수(삼대 노신 = n 회 타격) ·
/// 「견제 무제한」(청룡언월) = 행동 유닛 경로가 반경을 스친 구간마다 + 그 행동으로 밀리거나 넉백된 상대 유닛도 타격 · 피해 × 교변 · 쓰러뜨리면 하북 명장 회복.
/// </summary>
public IEnumerator ApplyOverwatch ( Unit mover , ActionOutcome o )
{
if ( mover = = null | | o = = null ) yield break ;
var path = o . Path ;
2026-11-03 19:10:10 +00:00
Faction other = mover . Faction = = Faction . Player ? Faction . Enemy : Faction . Player ;
foreach ( var spear in AliveUnits ( other ) )
{
if ( spear . Type ! = UnitType . Spear | | ! spear . Overwatch ) continue ;
2026-11-05 14:31:27 +00:00
if ( ! mover . IsAlive & & o . Displaced . Count = = 0 ) yield break ;
2026-11-10 10:00:18 +00:00
float radius = spear . AttackRange ; // 옛 견제(대기 유닛 없음 · 스킬 확장 제거 2026-11-10 #1112)
bool unlimited = false ;
2026-11-05 14:31:27 +00:00
var victims = new List < Unit > ( ) ;
int passes = 0 ;
for ( int i = 0 ; path ! = null & & i < path . Count - 1 ; i + + )
2026-11-03 19:10:10 +00:00
{
Vector2 a = path [ i ] ;
Vector2 b = path [ i + 1 ] ;
if ( Vector2 . Distance ( a , b ) < 0.05f ) continue ;
2026-11-05 14:31:27 +00:00
if ( Combat . SegmentPointDistance ( a , b , spear . Position ) > radius + mover . Radius ) continue ;
passes + + ;
if ( ! unlimited ) break ;
}
for ( int i = 0 ; i < passes ; i + + ) victims . Add ( mover ) ;
if ( unlimited )
{
foreach ( var d in o . Displaced )
2026-11-03 19:10:10 +00:00
{
2026-11-05 14:31:27 +00:00
if ( d . Unit = = null | | d . Unit = = mover | | d . Unit . Faction = = spear . Faction ) continue ;
if ( Vector2 . Distance ( d . From , d . To ) < 0.05f ) continue ;
if ( Combat . SegmentPointDistance ( d . From , d . To , spear . Position ) < = radius + d . Unit . Radius ) victims . Add ( d . Unit ) ;
}
}
if ( victims . Count = = 0 ) continue ;
2026-11-10 10:00:18 +00:00
const int strikes = 1 ;
2026-11-05 14:31:27 +00:00
foreach ( var v in victims )
{
for ( int k = 0 ; k < strikes ; k + + )
{
if ( ! v . IsAlive | | ! spear . IsAlive ) break ;
int dmg = Combat . OverwatchDamage ( Config , spear , v , Rng ) ;
if ( spear . View ! = null ) spear . View . PlayAttack ( ) ;
yield return Fx . Lunge ( spear , v . Position ) ;
2026-11-10 10:00:18 +00:00
dmg = SkillSystem . Deal ( v , dmg , spear , HitKind . Attack ) ;
2026-11-05 14:31:27 +00:00
Fx . Popup ( v . Position , dmg + " 견제" , new Color ( 0.6f , 0.85f , 1f ) ) ;
NotifyChanged ( ) ;
yield return Fx . Wait ( 0.2f ) ;
2026-11-03 19:10:10 +00:00
}
}
}
}
2026-11-10 10:00:18 +00:00
// ---------- 승패 ----------
/// <summary>스킬 소환(장로 망령)을 뺀 생존 수 — 승패 판정용.</summary>
int RealAlive ( Faction f )
2026-11-05 14:31:27 +00:00
{
2026-11-10 10:00:18 +00:00
int n = 0 ;
foreach ( var u in units )
2026-11-17 16:03:13 +00:00
if ( u ! = null & & u . IsAlive & & u . Faction = = f & & ! u . Npc & & ! SkillSystem . IsSummon ( u ) & & ( Mode = = null | | Mode . rules = = null | | Mode . rules . CountsForVictory ( u ) ) ) n + + ; // 구출 대상(학습 판) · 허수아비(컨텐츠 모드)는 세지 않는다
2026-11-10 10:00:18 +00:00
return n ;
2026-11-05 14:31:27 +00:00
}
2026-11-10 10:00:18 +00:00
/// <summary>유닛 제거(소환 소멸 · 콜라이더 즉시 제거).</summary>
public void RemoveUnit ( Unit u )
{
if ( u = = null ) return ;
units . Remove ( u ) ;
u . gameObject . SetActive ( false ) ;
Destroy ( u . gameObject ) ;
}
2026-11-03 19:10:10 +00:00
public bool CheckBattleEnd ( )
{
2026-11-17 16:03:13 +00:00
var rules = Mode ! = null ? Mode . rules : null ;
if ( rules ! = null & & ! Sim . Active )
{
BattlePhase ph ;
string msg ;
if ( rules . CheckEnd ( out ph , out msg ) ) // 컨텐츠 모드 판정(군량고 전부 · 맹세 · 구출 …)
{
LastMessage = msg ? ? "" ;
if ( ph = = BattlePhase . StageClear )
foreach ( var p in AliveUnits ( Faction . Player ) )
if ( p . View ! = null ) p . View . PlayVictory ( ) ;
SetPhase ( ph ) ;
return true ;
}
}
if ( RealAlive ( Faction . Enemy ) = = 0 & & ( rules = = null | | rules . EliminationVictory ) )
2026-11-03 19:10:10 +00:00
{
LastMessage = "승리 — 전장의 적을 모두 처치했습니다" ;
2026-11-04 04:05:46 +00:00
foreach ( var p in AliveUnits ( Faction . Player ) )
{
if ( p . View ! = null ) p . View . PlayVictory ( ) ;
}
2026-11-03 19:29:16 +00:00
SetPhase ( BattlePhase . StageClear ) ;
2026-11-03 19:10:10 +00:00
return true ;
}
2026-11-17 07:27:22 +00:00
if ( Tutorial ! = null & & ! Sim . Active & & Tutorial . NpcLost ) // 학습 판: 구출 대상이 쓰러지면 실패
{
LastMessage = "패배 — 구출 대상이 쓰러졌습니다" ;
SetPhase ( BattlePhase . Defeat ) ;
return true ;
}
2026-11-10 10:00:18 +00:00
if ( RealAlive ( Faction . Player ) = = 0 )
2026-11-03 19:10:10 +00:00
{
LastMessage = "패배 — 아군이 전멸했습니다" ;
2026-11-03 19:29:16 +00:00
SetPhase ( BattlePhase . Defeat ) ;
2026-11-03 19:10:10 +00:00
return true ;
}
return false ;
}
2026-11-17 16:03:13 +00:00
/// <summary>연전(연의 전기 오관참육장)의 다음 판 — 아군 행동을 새로 하고 턴 수 +1(체력 · 스킬 대기는 그대로).</summary>
public void NextActTurn ( )
{
TurnNumber + + ;
foreach ( var u in AliveUnits ( Faction . Player ) ) u . ResetForNewTurn ( ) ;
if ( Mode ! = null & & Mode . rules ! = null ) StartCoroutine ( Mode . rules . OnTurnStart ( Faction . Player ) ) ;
SetPhase ( BattlePhase . PlayerTurn ) ;
NotifyChanged ( ) ;
}
2026-11-03 19:10:10 +00:00
// ---------- 테스트·자동 플레이용 ----------
public IEnumerator ResolveForTest ( Unit u , Vector2 target , bool moveOnly , ActionOutcome o )
{
yield return Resolver . Resolve ( u , target , moveOnly , o ) ;
}
public void ForcePhase ( BattlePhase p )
{
2026-11-03 19:29:16 +00:00
SetPhase ( p ) ;
2026-11-03 19:10:10 +00:00
NotifyChanged ( ) ;
}
2026-11-05 14:31:27 +00:00
/// <summary>테스트·캡처: 턴 번호 지정(스킬 쿨·선봉 1턴 확인).</summary>
public void SetTurnForTest ( int turn )
{
TurnNumber = Mathf . Max ( 1 , turn ) ;
}
2026-11-03 19:10:10 +00:00
static string Describe ( Unit u , ActionOutcome o , bool moveOnly )
{
2026-11-05 14:31:27 +00:00
string who = u . DisplayName + "(" + UnitTypeInfo . Korean ( u . Type ) + ")" + ( o . SkillUsed ! = null ? " 「" + o . SkillUsed . NameKo + "」" : "" ) ;
2026-11-04 06:56:02 +00:00
string s ;
2026-11-03 19:10:10 +00:00
if ( o . Attacked . Count = = 0 )
{
2026-11-05 04:06:32 +00:00
s = who + ( o . Fired ? " 사격" : moveOnly ? " 추가 이동" : " 이동" ) ;
2026-11-03 19:10:10 +00:00
}
2026-11-04 06:56:02 +00:00
else
2026-11-03 19:10:10 +00:00
{
2026-11-04 06:56:02 +00:00
var names = new List < string > ( ) ;
foreach ( var a in o . Attacked )
{
if ( ! names . Contains ( a . DisplayName ) ) names . Add ( a . DisplayName ) ;
}
s = who + " → " + string . Join ( ", " , names . ToArray ( ) ) + " 공격 " + o . DamageDealt ;
if ( o . Crit ) s + = " 크리티컬!" ;
if ( o . CounterTaken > 0 ) s + = " · 반격 " + o . CounterTaken ;
}
if ( o . Pushed . Count > 0 )
{
var pushed = new List < string > ( ) ;
foreach ( var p in o . Pushed )
{
if ( ! pushed . Contains ( p . DisplayName ) ) pushed . Add ( p . DisplayName ) ;
}
s + = " · " + string . Join ( ", " , pushed . ToArray ( ) ) + " 밀어냄" ;
2026-11-03 19:10:10 +00:00
}
2026-11-05 04:06:32 +00:00
if ( o . FriendlyHit . Count > 0 )
{
var hurt = new List < string > ( ) ;
foreach ( var f in o . FriendlyHit )
{
if ( ! hurt . Contains ( f . DisplayName ) ) hurt . Add ( f . DisplayName ) ;
}
s + = " · 아군 오사 " + string . Join ( ", " , hurt . ToArray ( ) ) + " " + o . FriendlyDamage ; // PD 2026-11-05 #1087 ⑤⑥
}
2026-11-04 06:56:02 +00:00
foreach ( var n in o . Notes ) s + = " · " + n ;
2026-11-03 19:10:10 +00:00
if ( o . BonusMove ) s + = " · 추가 이동!" ;
return s ;
}
}
}