DEG-151 [FEAT] 공격 방식 변경
This commit is contained in:
parent
f666ea85ac
commit
0f84310d90
@ -8,16 +8,6 @@ public class AnimatorEventRelay : MonoBehaviour
|
||||
{
|
||||
_playerController = GetComponentInParent<PlayerController>();
|
||||
}
|
||||
|
||||
public void SetAttackComboTrue()
|
||||
{
|
||||
_playerController?.SetAttackComboTrue();
|
||||
}
|
||||
|
||||
public void SetAttackComboFalse()
|
||||
{
|
||||
_playerController?.SetAttackComboFalse();
|
||||
}
|
||||
|
||||
public void PlayAttackEffect()
|
||||
{
|
||||
|
@ -2,72 +2,79 @@
|
||||
|
||||
public class PlayerActionAttack : IPlayerAction {
|
||||
private static readonly int ComboStep = Animator.StringToHash("ComboStep");
|
||||
|
||||
private PlayerController player;
|
||||
private int comboStep = 1;
|
||||
private bool comboQueued = false;
|
||||
private bool canReceiveCombo = false;
|
||||
|
||||
public int CurrentComboStep => comboStep;
|
||||
private float comboTimer = 0f;
|
||||
|
||||
[SerializeField] private float comboDuration = 0.7f;
|
||||
private int maxComboStep = 4;
|
||||
|
||||
public bool IsActive { get; private set; }
|
||||
public int CurrentComboStep => comboStep;
|
||||
|
||||
public void StartAction(PlayerController player) {
|
||||
this.player = player;
|
||||
IsActive = true;
|
||||
|
||||
comboStep = 1;
|
||||
comboQueued = false;
|
||||
PlayComboAnimation(comboStep);
|
||||
canReceiveCombo = true;
|
||||
comboTimer = 0f;
|
||||
|
||||
player.SafeSetBool("Attack", true);
|
||||
PlayComboAnimation(comboStep);
|
||||
}
|
||||
|
||||
public void UpdateAction() {
|
||||
if (Input.GetKeyDown(KeyCode.X) && canReceiveCombo) {
|
||||
comboTimer += Time.deltaTime;
|
||||
|
||||
if (canReceiveCombo && Input.GetKeyDown(KeyCode.X)) {
|
||||
comboQueued = true;
|
||||
}
|
||||
|
||||
if (comboTimer >= comboDuration) {
|
||||
ProceedComboOrEnd();
|
||||
}
|
||||
}
|
||||
|
||||
private void ProceedComboOrEnd() {
|
||||
canReceiveCombo = false;
|
||||
|
||||
if (comboQueued && comboStep < maxComboStep) {
|
||||
comboStep++;
|
||||
comboQueued = false;
|
||||
comboTimer = 0f;
|
||||
canReceiveCombo = true;
|
||||
PlayComboAnimation(comboStep);
|
||||
} else {
|
||||
EndAction();
|
||||
}
|
||||
}
|
||||
|
||||
public void EndAction() {
|
||||
if (player == null) return;
|
||||
|
||||
player.SafeSetBool("Attack", false);
|
||||
IsActive = false;
|
||||
player.OnActionEnded(this); // player 에서도 action 초기화
|
||||
player.OnActionEnded(this);
|
||||
player = null;
|
||||
}
|
||||
|
||||
public void EnableCombo() {
|
||||
canReceiveCombo = true;
|
||||
}
|
||||
private void PlayComboAnimation(int step) {
|
||||
if (player?.PlayerAnimator == null) return;
|
||||
|
||||
public void DisableCombo() {
|
||||
canReceiveCombo = false;
|
||||
player.PlayerAnimator.SetInteger(ComboStep, step);
|
||||
|
||||
if (comboQueued && comboStep < 4) {
|
||||
comboStep++;
|
||||
PlayComboAnimation(comboStep);
|
||||
comboQueued = false;
|
||||
} else {
|
||||
EndAction(); // 행동 종료
|
||||
}
|
||||
}
|
||||
|
||||
private void PlayComboAnimation(int step)
|
||||
{
|
||||
if (player.PlayerAnimator == null) return;
|
||||
|
||||
// 안전하게 파라미터 체크
|
||||
foreach (var param in player.PlayerAnimator.parameters)
|
||||
{
|
||||
if (param.nameHash == ComboStep && param.type == AnimatorControllerParameterType.Int)
|
||||
{
|
||||
player.PlayerAnimator.SetInteger(ComboStep, step);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 무기에 콤보 단계 전달
|
||||
var weapon = player.GetComponentInChildren<WeaponController>();
|
||||
if (weapon != null)
|
||||
{
|
||||
weapon.SetComboStep(step);
|
||||
weapon?.SetComboStep(step);
|
||||
}
|
||||
|
||||
public void OnComboInput() {
|
||||
if (canReceiveCombo) {
|
||||
comboQueued = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -291,27 +291,7 @@ public class PlayerController : CharacterBase, IObserver<GameObject>
|
||||
// 무기도 전투모드에만
|
||||
weapon.SetActive(_isBattle);
|
||||
}
|
||||
|
||||
// Animation Event에서 호출될 메서드
|
||||
public void SetAttackComboTrue()
|
||||
{
|
||||
if (_weaponController.IsAttacking) return; // 이미 공격 중이면 실행 안함
|
||||
|
||||
if (_currentAction == _attackAction) {
|
||||
_attackAction.EnableCombo();
|
||||
_weaponController.AttackStart();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetAttackComboFalse()
|
||||
{
|
||||
if (_currentAction == _attackAction) {
|
||||
// 이벤트 중복 호출? 공격 종료 시 SetAttackComboFalse가 아니라 ~True로 끝나서 오류 발생. (공격 안하는 상태여도 공격으로 판정됨)
|
||||
_attackAction.DisableCombo();
|
||||
_weaponController.AttackEnd(); // IsAttacking = false로 변경
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayAttackEffect()
|
||||
{
|
||||
if (_attackAction == null) return;
|
||||
@ -350,6 +330,10 @@ public class PlayerController : CharacterBase, IObserver<GameObject>
|
||||
GameManager.Instance.PlayPlayerAttackSound();
|
||||
StartAttackAction();
|
||||
}
|
||||
else if (_currentAction is PlayerActionAttack attackAction)
|
||||
{
|
||||
attackAction.OnComboInput();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
Loading…
x
Reference in New Issue
Block a user