ThreeKingdomsSlingshot/Assets/Scripts/Runtime/Gimmicks/GimmickInstance.cs

97 lines
3.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections.Generic;
using UnityEngine;
namespace TKS
{
/// <summary>전장에 놓인 기믹 1개(정의 + 배치 + 전투 중 상태). 시각 = GimmickView · 콜라이더 = 장애물만.</summary>
public class GimmickInstance
{
public GimmickDef Def;
public GimmickPlacement Src;
public GimmickShape Shape;
public int Hp;
public int MaxHp;
/// <summary>내구 0 = 잔해(통과 가능 · art_broken).</summary>
public bool Broken;
/// <summary>제거됨(책사 광역 덤불 · 발동한 함정).</summary>
public bool Removed;
/// <summary>함정이 드러났다(발동).</summary>
public bool Revealed;
/// <summary>불 지대 남은 라운드(−1 = 영구) · 0 이 되면 Out.</summary>
public int BurnLeft = -1;
/// <summary>불이 꺼짐(잔해만 남음 · 효과 없음).</summary>
public bool Out;
/// <summary>군기 점령 진영(−1 = 중립 · 0 = 아군 · 1 = 적군).</summary>
public int Owner = -1;
/// <summary>전투 중 생긴 기믹(폭발·광역 불).</summary>
public bool Spawned;
/// <summary>배치만 있고 지대는 만들지 않는 생성 규칙(불 spawn_on_splash).</summary>
public bool Template;
public GameObject Go;
public readonly List<Collider2D> Colliders = new List<Collider2D>();
public GimmickView View;
public string Id
{
get { return Def != null ? Def.id : ""; }
}
public GimmickZone Zone
{
get { return Def.zone; }
}
public bool IsBlock
{
get { return Def.kind == GimmickKind.Block; }
}
/// <summary>이동을 막는다(장애물 · 부서지거나 제거되지 않음).</summary>
public bool BlocksMove
{
get { return IsBlock && !Broken && !Removed; }
}
/// <summary>지대 효과가 살아 있다.</summary>
public bool ZoneActive
{
get { return Def.kind == GimmickKind.Zone && !Removed && !Out && !Template; }
}
public bool Rolls
{
get { return Def.id == GimmickIds.Boulder; }
}
public bool IsBridge
{
get { return Def.id == GimmickIds.Bridge; }
}
/// <summary>정의 p(i) · 배치 params 가 있으면 그 값 · 둘 다 비면 fallback.</summary>
public float P(int i, float fallback = 0f)
{
float o = i == 1 ? Src.pOver1 : (i == 2 ? Src.pOver2 : Src.pOver3);
if (!float.IsNaN(o)) return o;
float d = i == 1 ? Def.p1 : (i == 2 ? Def.p2 : Def.p3);
return float.IsNaN(d) ? fallback : d;
}
public void SetCollidersEnabled(bool on)
{
foreach (var c in Colliders)
{
if (c != null) c.enabled = on;
}
}
/// <summary>모양·표시·콜라이더를 d 만큼 옮긴다(목책 밀기 · 바위 굴림).</summary>
public void MoveBy(Vector2 d)
{
Shape = Shape.Translated(d);
if (Go != null) Go.transform.position = new Vector3(Shape.Center.x, Shape.Center.y, 0f);
}
}
}