2026-01-29 06:58:38 +00:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
public class EquippableItem : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
[SerializeField] private WeaponConfig config;
|
|
|
|
|
|
public WeaponConfig Config => config;
|
|
|
|
|
|
|
|
|
|
|
|
[Header("--- 데미지 밸런스 ---")]
|
|
|
|
|
|
[SerializeField] private float lv1Mult = 1.0f;
|
|
|
|
|
|
[SerializeField] private float lv2Mult = 1.5f;
|
|
|
|
|
|
[SerializeField] private float lv3Mult = 2.5f;
|
2026-02-08 14:20:23 +00:00
|
|
|
|
// [제거] strengthBonusFactor 변수 삭제
|
2026-01-29 06:58:38 +00:00
|
|
|
|
|
|
|
|
|
|
private Rigidbody _rb;
|
|
|
|
|
|
private Collider _col;
|
|
|
|
|
|
private bool _isThrown;
|
|
|
|
|
|
private int _chargeLevel;
|
2026-02-08 14:20:23 +00:00
|
|
|
|
private Stats _thrower;
|
2026-01-29 06:58:38 +00:00
|
|
|
|
private Vector3 _originalWorldScale;
|
|
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
|
{
|
|
|
|
|
|
_rb = GetComponent<Rigidbody>();
|
|
|
|
|
|
_col = GetComponent<Collider>();
|
|
|
|
|
|
_originalWorldScale = transform.lossyScale;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnPickedUp(Transform hand)
|
|
|
|
|
|
{
|
|
|
|
|
|
_isThrown = false;
|
|
|
|
|
|
transform.SetParent(hand);
|
|
|
|
|
|
transform.localScale = new Vector3(
|
|
|
|
|
|
_originalWorldScale.x / hand.lossyScale.x,
|
|
|
|
|
|
_originalWorldScale.y / hand.lossyScale.y,
|
|
|
|
|
|
_originalWorldScale.z / hand.lossyScale.z
|
|
|
|
|
|
);
|
|
|
|
|
|
transform.localPosition = Vector3.zero;
|
|
|
|
|
|
transform.localRotation = Quaternion.identity;
|
|
|
|
|
|
if (_rb) _rb.isKinematic = true;
|
|
|
|
|
|
if (_col) _col.enabled = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnDropped(Vector3 throwDir)
|
|
|
|
|
|
{
|
|
|
|
|
|
_isThrown = false;
|
|
|
|
|
|
transform.SetParent(null);
|
|
|
|
|
|
transform.localScale = _originalWorldScale;
|
|
|
|
|
|
if (_rb)
|
|
|
|
|
|
{
|
|
|
|
|
|
_rb.isKinematic = false;
|
|
|
|
|
|
Vector3 force = (throwDir + Vector3.up * 0.5f).normalized * 5f;
|
|
|
|
|
|
_rb.AddForce(force, ForceMode.Impulse);
|
|
|
|
|
|
_rb.AddTorque(Random.insideUnitSphere * 3f, ForceMode.Impulse);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (_col) _col.enabled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnThrown(Vector3 dir, float force, int lv, Stats s)
|
|
|
|
|
|
{
|
|
|
|
|
|
_isThrown = true;
|
|
|
|
|
|
_chargeLevel = lv;
|
2026-02-08 14:20:23 +00:00
|
|
|
|
_thrower = s;
|
2026-01-29 06:58:38 +00:00
|
|
|
|
transform.SetParent(null);
|
|
|
|
|
|
transform.localScale = _originalWorldScale;
|
|
|
|
|
|
if (_rb)
|
|
|
|
|
|
{
|
|
|
|
|
|
_rb.isKinematic = false;
|
|
|
|
|
|
_rb.AddForce(dir * force, ForceMode.Impulse);
|
|
|
|
|
|
_rb.AddTorque(transform.right * 10f, ForceMode.Impulse);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (_col) _col.enabled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnCollisionEnter(Collision collision)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!_isThrown) return;
|
2026-02-08 14:20:23 +00:00
|
|
|
|
if (_thrower != null && collision.gameObject == _thrower.gameObject) return;
|
2026-01-29 06:58:38 +00:00
|
|
|
|
|
|
|
|
|
|
if (collision.gameObject.TryGetComponent<IDamageable>(out var target))
|
|
|
|
|
|
{
|
|
|
|
|
|
float mult = _chargeLevel == 3 ? lv3Mult : (_chargeLevel == 2 ? lv2Mult : lv1Mult);
|
2026-02-08 14:20:23 +00:00
|
|
|
|
|
|
|
|
|
|
// ✨ [수정] 힘 보너스 로직 제거. (플레이어 기본 공격력 + 무기 대미지) * 차지 배율
|
|
|
|
|
|
float finalDamage = (_thrower.BaseAttackDamage + config.BaseDamage) * mult;
|
2026-01-29 06:58:38 +00:00
|
|
|
|
|
|
|
|
|
|
target.TakeDamage(finalDamage);
|
|
|
|
|
|
Debug.Log($"<color=orange>[투척 적중]</color> {collision.gameObject.name}에게 {finalDamage:F1} 데미지!");
|
|
|
|
|
|
_isThrown = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-08 14:20:23 +00:00
|
|
|
|
if (collision.gameObject.layer != LayerMask.NameToLayer("Player")) _isThrown = false;
|
2026-01-29 06:58:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|