ThreeKingdomsSlingshot/Assets/Scripts/Runtime/Unit.cs

137 lines
5.0 KiB
C#
Raw Normal View History

using UnityEngine;
namespace TKS
{
/// <summary>전장의 유닛 1기. 능력치·상태·콜라이더를 가진다. 시각은 UnitView 가 담당.</summary>
[RequireComponent(typeof(CircleCollider2D))]
public class Unit : MonoBehaviour
{
public string DisplayName;
public UnitType Type;
public Faction Faction;
public bool IsBoss;
public int MaxHp;
public int Hp;
public int Atk;
public int Def;
public float Radius;
public float SlingMaxDistance;
/// <summary>궁병·책사 = 사거리 = 슬링샷 최대 거리(적 가장자리까지의 간격 기준 · 제자리 사격) · 창병 = 대기(견제) 반경.</summary>
public float AttackRange;
/// <summary>궁병·책사가 사거리 밖(~ 사거리 × (1 + archerRangeRatio))의 적에게 다가갈 수 있는 최대 거리. 다른 병종 = 0.</summary>
전투 로직 #1080 — 알까기 충돌(보병) · 관통·아군 직전 정지(기병) · 밀며 함께 전진(창병) · 밀린 아군 공격 기회 · 궁병 제자리 사격(사거리 = 슬링샷)+접근 20 % · 궁수 근접 피해 50 %/피격 +50 % · 원화 1차·2차 반영(전장 배경 + 황건적 5 + 동탁군 4) · 테스트 22/22 - ActionResolver 전면 재작성: InfantryRoutine(접촉점 정지 · Push 접촉 방향 × collisionPushRatio · 적이면 공격+반격 뒤 밀림) · SpearRoutine(앞 유닛과 같은 속도로 함께 전진 · 접촉 간격 유지) · CavalryRoutine(벽만 막음 · StopBeforeUnclearedAllies) · ArcherRoutine(AttackRange = 슬링 · ArcherMoveAllow = 슬링 × archerRangeRatio) · PushedAllyAttack(규칙 ⑤ · ActionOutcome.Pushed/Notes) - Combat: Damage(melee) 궁병 근접 배율(근접 유닛 상대만) · FirstUnitOnPath · TouchingOpponent · FreeTravel ignore - BalanceConfig/Defaults: archerMeleeDealtRatio 0.5 · archerMeleeTakenRatio 1.5 · collisionPushRatio 1 · boardArt battlefield_01 (자산 재시드) - Board: Resources/Board/<boardArt> 원화 배경(격자·진영 띠 생략) · UnitArtImporter Board 규칙 · GameBootstrap - Resources/Units: hgj_infantry·spear·cavalry·archer·boss_zhangjiao · dz_infantry·spear·cavalry·archer (원화 세션 납품 정지 그림 · rig_frames_export static) · Resources/Board/battlefield_01.png - BattleManager Describe 「밀어냄 · 밀린 B → 적 공격」 · BattleHUD 궁병 줄 · 테스트 22종(신규·개정 7 + 원화 확인) · CLAUDE.md · README Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-04 06:56:02 +00:00
public float ArcherMoveAllow;
/// <summary>Resources/Units/&lt;ArtId&gt;/ 아트 폴더 · 비면 도형.</summary>
public string ArtId = "";
/// <summary>아트 세로 크기(월드) = unitArtHeight × 반지름 배율.</summary>
public float ArtHeight;
/// <summary>이번 아군 턴에 행동을 마쳤는가.</summary>
public bool ActedThisTurn;
/// <summary>보병이 최종 목표점 명중으로 얻은 추가 이동(이동만 가능).</summary>
public bool BonusMoveAvailable;
/// <summary>창병 대기(견제) 상태 — 적군 턴에 반경 안에서 움직이는 적에게 피해.</summary>
public bool Overwatch;
public CircleCollider2D Collider { get; private set; }
public UnitView View { get; private set; }
public bool IsAlive
{
get { return Hp > 0; }
}
public Vector2 Position
{
get { return transform.position; }
set { transform.position = new Vector3(value.x, value.y, 0f); }
}
public void Init(BalanceConfig cfg, UnitType type, Faction faction, string displayName, float hpMult, float atkMult, bool boss, string artId = null)
{
var s = cfg.GetStats(type);
Type = type;
Faction = faction;
DisplayName = displayName;
IsBoss = boss;
ArtId = artId ?? "";
MaxHp = Mathf.Max(1, Mathf.RoundToInt(s.maxHp * hpMult * (boss ? cfg.bossHpMult : 1f)));
Hp = MaxHp;
Atk = Mathf.Max(1, Mathf.RoundToInt(s.atk * atkMult));
Def = s.def;
float radiusMult = boss ? cfg.bossRadiusMult : 1f;
Radius = s.radius * radiusMult;
ArtHeight = cfg.unitArtHeight * radiusMult;
SlingMaxDistance = s.slingMaxDistance;
전투 로직 #1080 — 알까기 충돌(보병) · 관통·아군 직전 정지(기병) · 밀며 함께 전진(창병) · 밀린 아군 공격 기회 · 궁병 제자리 사격(사거리 = 슬링샷)+접근 20 % · 궁수 근접 피해 50 %/피격 +50 % · 원화 1차·2차 반영(전장 배경 + 황건적 5 + 동탁군 4) · 테스트 22/22 - ActionResolver 전면 재작성: InfantryRoutine(접촉점 정지 · Push 접촉 방향 × collisionPushRatio · 적이면 공격+반격 뒤 밀림) · SpearRoutine(앞 유닛과 같은 속도로 함께 전진 · 접촉 간격 유지) · CavalryRoutine(벽만 막음 · StopBeforeUnclearedAllies) · ArcherRoutine(AttackRange = 슬링 · ArcherMoveAllow = 슬링 × archerRangeRatio) · PushedAllyAttack(규칙 ⑤ · ActionOutcome.Pushed/Notes) - Combat: Damage(melee) 궁병 근접 배율(근접 유닛 상대만) · FirstUnitOnPath · TouchingOpponent · FreeTravel ignore - BalanceConfig/Defaults: archerMeleeDealtRatio 0.5 · archerMeleeTakenRatio 1.5 · collisionPushRatio 1 · boardArt battlefield_01 (자산 재시드) - Board: Resources/Board/<boardArt> 원화 배경(격자·진영 띠 생략) · UnitArtImporter Board 규칙 · GameBootstrap - Resources/Units: hgj_infantry·spear·cavalry·archer·boss_zhangjiao · dz_infantry·spear·cavalry·archer (원화 세션 납품 정지 그림 · rig_frames_export static) · Resources/Board/battlefield_01.png - BattleManager Describe 「밀어냄 · 밀린 B → 적 공격」 · BattleHUD 궁병 줄 · 테스트 22종(신규·개정 7 + 원화 확인) · CLAUDE.md · README Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-04 06:56:02 +00:00
// PD 2026-11-04 #1080: 궁병 사거리 = 슬링샷 범위(제자리 사격) · 그 밖 +비율 안의 적은 들어올 만큼만 다가가 사격 · 창병은 자산의 대기 반경
// 책사(PD 2026-11-05 #1087 ⑤) = 궁병과 같은 사거리 규칙
bool ranged = UnitTypeInfo.IsRanged(type);
AttackRange = ranged ? s.slingMaxDistance : s.attackRange;
ArcherMoveAllow = ranged ? s.slingMaxDistance * cfg.archerRangeRatio : 0f;
gameObject.name = (faction == Faction.Player ? "P_" : "E_") + displayName;
Collider = GetComponent<CircleCollider2D>();
Collider.radius = Radius;
Collider.isTrigger = false;
Collider.enabled = true;
View = GetComponentInChildren<UnitView>();
if (View == null)
{
var vgo = new GameObject("View");
vgo.transform.SetParent(transform, false);
View = vgo.AddComponent<UnitView>();
}
View.Build(this);
}
public void TakeDamage(int dmg)
{
if (!IsAlive) return;
Hp = Mathf.Max(0, Hp - dmg);
if (View != null)
{
View.OnHit();
View.Refresh();
}
if (!IsAlive) Die();
}
void Die()
{
Overwatch = false;
BonusMoveAvailable = false;
Collider.enabled = false;
if (View != null) View.PlayDeath();
}
public void SetOverwatch(bool on)
{
Overwatch = on && IsAlive;
if (View != null) View.Refresh();
}
public void ResetForNewTurn()
{
ActedThisTurn = false;
BonusMoveAvailable = false;
Overwatch = false;
if (View != null) View.Refresh();
}
public void MarkActed()
{
ActedThisTurn = true;
BonusMoveAvailable = false;
if (View != null) View.Refresh();
}
public void GrantBonusMove()
{
ActedThisTurn = false;
BonusMoveAvailable = true;
if (View != null) View.Refresh();
}
}
}