몬스터 공격 시 캐릭터 방어력 값 참조 추가 및 리워드 코드 추가
This commit is contained in:
@@ -10,7 +10,7 @@ namespace TON
|
||||
[SerializeField] private GameObject _target; // 몬스터의 타겟
|
||||
[SerializeField] private Collider2D _collider; // 몬스터의 콜라이더
|
||||
[SerializeField] private SpriteRenderer _spriteRenderer; // 몬스터의 스프라이트 렌더러
|
||||
[SerializeField] private TextMeshProUGUI _textState;
|
||||
// [SerializeField] private TextMeshProUGUI _textState;
|
||||
[SerializeField] public int id; // 몬스터의 ID
|
||||
public float defencePower;
|
||||
public float defenceIntention = 30; // 몬스터 방어력 변수
|
||||
@@ -20,10 +20,12 @@ namespace TON
|
||||
public float currentHP { get; private set; } // 몬스터 현재 체력
|
||||
private float hpMaxWidth;
|
||||
|
||||
private PlayerData _playerData;
|
||||
private MonsterData _monsterData;
|
||||
private Animator _animator; // 몬스터 애니메이터
|
||||
private string currentAnimationState; // 현재 애니메이션 상태
|
||||
|
||||
private float moveSpeed = 2f;
|
||||
|
||||
StateMachine _stateMachine;
|
||||
private SkillPattern _skillPattern;
|
||||
|
||||
@@ -33,6 +35,10 @@ namespace TON
|
||||
public bool IsFinishAttack { get; set; } // 몬스터 공격 모션이 끝났는지 여부
|
||||
public bool IsSkillAttackable => _skillPattern.IsAttackable;
|
||||
|
||||
public int Gold = 0;
|
||||
public int Exp = 0;
|
||||
public int Score = 0;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_animator = GetComponent<Animator>(); // 애니메이터 컴포넌트 초기화
|
||||
@@ -45,8 +51,6 @@ namespace TON
|
||||
|
||||
_skillPattern = new Monster1SkillPattern(_monsterData, this);
|
||||
|
||||
id = _monsterData.id;
|
||||
|
||||
_direction = new Vector3(1, 0, 0); // 초기 이동 방향 (x 축 양의 방향)
|
||||
|
||||
_spriteRenderer.flipX = !(_direction.x > 0); // 이동 방향에 따라 스프라이트 플립
|
||||
@@ -62,8 +66,11 @@ namespace TON
|
||||
{
|
||||
currentHP = _monsterData.hp;
|
||||
defencePower = _monsterData.defencePower;
|
||||
Gold = _monsterData.Gold;
|
||||
Exp = _monsterData.Exp;
|
||||
Score = _monsterData.Score;
|
||||
|
||||
Debug.Log($"몬스터 {_monsterData.name} 데이터 로드 완료");
|
||||
// Debug.Log($"몬스터 {_monsterData.name} 데이터 로드 완료");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -71,6 +78,11 @@ namespace TON
|
||||
}
|
||||
}
|
||||
|
||||
public void RewardData()
|
||||
{
|
||||
StageManager.Singleton.SetRewardData(Gold, Exp, Score);
|
||||
}
|
||||
|
||||
public void ChangeAnimationState(string newState)
|
||||
{
|
||||
if (currentAnimationState == newState) return; // 현재 상태와 동일한 상태일 경우, 애니메이션을 변경하지 않음
|
||||
@@ -94,7 +106,7 @@ namespace TON
|
||||
float prevHP = currentHP; // 몬스터의 체력을 감소시키고, 죽었을 경우 파괴 처리
|
||||
currentHP -= damage;
|
||||
|
||||
UpdateHPBar();
|
||||
UpdateHPBar(currentHP);
|
||||
|
||||
if (prevHP > 0 && currentHP <= 0)
|
||||
{
|
||||
@@ -107,7 +119,7 @@ namespace TON
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateHPBar()
|
||||
private void UpdateHPBar(float currentHP)
|
||||
{
|
||||
if (_hpBarImage != null)
|
||||
{
|
||||
@@ -118,15 +130,14 @@ namespace TON
|
||||
}
|
||||
}
|
||||
|
||||
public void Attack(GameObject player)
|
||||
public void Attack()
|
||||
{
|
||||
// 데미지 계산 (현재 임시 값)
|
||||
DamageCalculator damageCalculator = new DamageCalculator();
|
||||
|
||||
float baseAttack = _monsterData.attackPower; // 기본 공격력
|
||||
float equipmentAttack = 0; // 장비 공격력
|
||||
// float defense = _monsterData.defencePower; // 방어력 비율
|
||||
float defense = PlayerDataManager.Singleton.defensiveIntention; // 캐릭터 방어력
|
||||
float defense = PlayerDataManager.Singleton.player.defensivePower / (PlayerDataManager.Singleton.player.defensivePower + PlayerDataManager.Singleton.defensiveIntention); // 캐릭터 방어력
|
||||
|
||||
// 기본 데미지 계산 (치명타 없음)
|
||||
float damage = damageCalculator.CalculateBaseDamage(baseAttack, equipmentAttack, defense);
|
||||
@@ -134,12 +145,6 @@ namespace TON
|
||||
Debug.Log($" 몬스터 공격! 최종 데미지: {damage}"); // 데미지 출력
|
||||
}
|
||||
|
||||
public void PlayerAttack()
|
||||
{
|
||||
var target = GameObject.FindGameObjectWithTag("Player");
|
||||
Attack(target);
|
||||
}
|
||||
|
||||
public void SetOppositionDirection()
|
||||
{
|
||||
_direction *= -1; // 이동 방향 반전
|
||||
@@ -148,7 +153,7 @@ namespace TON
|
||||
|
||||
public void Move()
|
||||
{
|
||||
transform.Translate(_direction * _monsterData.moveSpeed * Time.deltaTime); // 몬스터를 이동시킴
|
||||
transform.Translate(_direction * moveSpeed * Time.deltaTime); // 몬스터를 이동시킴
|
||||
}
|
||||
|
||||
public void Chasing()
|
||||
@@ -157,17 +162,21 @@ namespace TON
|
||||
UnityEngine.Vector2 direction = target.transform.position - transform.position; // 타겟과의 방향 계산
|
||||
_spriteRenderer.flipX = target.transform.position.x < transform.position.x; // 타겟이 왼쪽에 있으면 스프라이트를 왼쪽으로, 오른쪽에 있으면 오른쪽으로 바라보도록 설정
|
||||
|
||||
transform.Translate(direction.normalized * _monsterData.moveSpeed * Time.deltaTime); // 타겟 방향으로 이동
|
||||
transform.Translate(direction.normalized * moveSpeed * Time.deltaTime); // 타겟 방향으로 이동
|
||||
}
|
||||
|
||||
public void MonsterSkillLaunch()
|
||||
{
|
||||
var target = GameObject.FindGameObjectWithTag("Player");
|
||||
_skillPattern.Attack(target);
|
||||
if (_monsterData.monsterSkillID != 0)
|
||||
{
|
||||
var target = GameObject.FindGameObjectWithTag("Player");
|
||||
_skillPattern.Attack(target);
|
||||
}
|
||||
}
|
||||
|
||||
public void DestroyMonster()
|
||||
{
|
||||
RewardData();
|
||||
Destroy(gameObject); // 몬스터 파괴
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user