오늘 학습 키워드

최종 팀 프로젝트

오늘 학습 한 내용을 나만의 언어로 정리하기

DeadHard 스킬을 쓰고 패링을 하면 무적이 풀림

  • 패링하면 그냥 Invincible을 꺼버리는 바람에 생긴 일.
// PlayerCondition.cs
  
[Flags]  
public enum ePlayerBuff  
{  
    None = 0,  
    PowerUp = 1 << 1,  
    DeadHard = 1 << 2  
}
 
IEnumerator Invincible(float time, bool isBuff = false)  
{  
    if (isBuff)  
    {  
        controller.Condition.playerBuff |= ePlayerBuff.DeadHard;  
    }  
    Debug.Log("[플레이어] 플레이어 무적 시작");  
    isInvincible = true;  
    yield return new WaitForSecondsRealtime(time);  
    // 만약에 이 코루틴을 부른 이유가 버프가 아니고  
    // 지금 DeadHard가 켜져있는 상태면 무적을 끄면 안됨.  
    // ex) 데드하드 킨 채로 패링이면 무적 끄면 안됨  
    if (!isBuff && controller.Condition.playerBuff.HasFlag(ePlayerBuff.DeadHard))  
    {  
        yield break;  
    }  
    isInvincible = false;  
    invincibleCoroutine = null;  
    if (isBuff)  
    {  
        controller.Condition.playerBuff &= ~ePlayerBuff.DeadHard;  
    }  
    Debug.Log("[플레이어] 플레이어 무적 끝");  
}

저스트 섬단의 판정 문제

  • 이 상황에서는 저스트 섬단인지 아닌지 확실하지 않음. 그래서 차라리 데미지를 넣는 부분을 TriggerExit로 옮기기로 함
// AttackHitbox.cs
private async void OnTriggerEnter2D(Collider2D other)  
{  
    if (controller.Attack.isStartParry)  
    {  
        if (other.TryGetComponent(out ICountable countable))  
        {  
            Debug.Log("[플레이어] 플레이어 패링 시도");  
  
            if (other.TryGetComponent(out MonsterAttackController attackController))  
            {  
                if (attackController.GetIsCountable())  
                {  
                    controller.Attack.successParry = true;  
                    controller.Condition.SetInvincible(controller.Data.parryInvincibleTime);   
                    controller.Attack.JustSpecialAttack(other.gameObject.GetComponentInChildren<Animator>());  
                    Debug.Log("[플레이어] 플레이어 패링 성공");  
                    countable.CounterAttacked();  
                    // controller.Attack.successParry = false;  
                    await EffectManager.Instance.PlayEffectByIdAndTypeAsync(PlayerEffectID.SuccessParrying, EffectType.Sprite, controller.gameObject,   
                        /*(other.transform.position - controller.transform.position).normalized   
                        * Vector2.Distance(other.transform.position, controller.transform.position) * 0.5f*/  
                        (Vector3.right * 2f));  
                    return;  
                }  
            }  
        }  
    }  
  
    if (controller.Attack.isStartJustAttack)  
    {  
        if (other.TryGetComponent(out ICountable countable))  
        {  
            if (other.TryGetComponent(out MonsterAttackController attackController))  
            {  
                if (attackController.GetIsCountable())  
                {  
                    Debug.Log("[플레이어] 플레이어 저스트 어택!");  
                    controller.Attack.successJustAttack = true;  
                    controller.Condition.SetInvincible(0.5f + controller.Attack.justAttackStopTime);  
                      
                    controller.Attack.JustSpecialAttack(other.gameObject.GetComponentInChildren<Animator>());  
                    countable.CounterAttacked();  
                    controller.Condition.health.Add(3);  
                      
                    int stageId = StageManager.Instance.CurrentStageData.Stage_id;  
                    if (stageId != StageID.Village)  
                    {  
                        UGSManager.Instance.LogDoAction(stageId, PlayerEffectID.JustSpecialAttack);  
                    }  
                    EffectManager.Instance.PlayEffectsByIdAsync(PlayerEffectID.JustSpecialAttack, EffectOrder.Player, controller.gameObject,   
                        (Vector3.right * 2f)).Forget();  
                }   
            }  
            else  
            {  
                controller.Condition.SetInvincible(0.5f + controller.Attack.justAttackStopTime);  
                countable.CounterAttacked();  
            }  
            return;  
        }  
    }  
          
    if (other.TryGetComponent<IDamagable>(out var damagable))  
    {  
        // 패리랑 섬단은 데미지 판단 여기서 안함  
        if (controller.Attack.isStartParry || controller.Attack.isStartSpecialAttack) return;  
          
        ShakeCameraUsingState();  
        damagable?.TakeDamage(attack.AttackDamage + attack.AdditionalDamage);  
        Debug.Log($"[플레이어] 플레이어가 몬스터에게 {attack.AttackDamage + attack.AdditionalDamage} 만큼 데미지 줌");  
    }   
}  
  
private void OnTriggerExit2D(Collider2D other)  
{  
    // 섬단 데미지 판단 여기서 함  
    if (controller.Attack.isStartSpecialAttack)  
    {  
        if (other.TryGetComponent<IDamagable>(out var damagable))  
        {  
            CheckSpecialAttack(damagable);  
        }  
  
        try  
        {  
            var parentDamagable = other.GetComponentInParent<IDamagable>();  
            if (parentDamagable != null)  
            {  
                CheckSpecialAttack(parentDamagable);  
            }  
        }  
        catch (Exception e)  
        {  
            Debug.Log($"[플레이어] 몬스터의 Damagable을 찾을 수 없음. 사유 : {e}");  
        }  
    }  
}  
  
private void CheckSpecialAttack(IDamagable damagable)  
{  
    if (!specialAttackDamaged)  
    {  
        // 저섬 성공  
        if (controller.Attack.isStartSpecialAttack && controller.Attack.successJustAttack)  
        {  
            controller.Attack.SetDamage(controller.Data.justSpecialAttackDamage);  
            damagable?.TakeDamage(attack.AttackDamage + attack.AdditionalDamage);  
            Debug.Log($"[플레이어] 플레이어가 몬스터에게 저스트 섬단으로 {attack.AttackDamage + attack.AdditionalDamage} 만큼 데미지 줌");  
        }  
          
        // 저섬 실패  
        else if (controller.Attack.isStartSpecialAttack)  
        {  
            controller.Attack.SetDamage(controller.Data.specialAttackDamage);  
            damagable?.TakeDamage(attack.AttackDamage + attack.AdditionalDamage);  
            Debug.Log($"[플레이어] 플레이어가 몬스터에게 일반 섬단으로 {attack.AttackDamage + attack.AdditionalDamage} 만큼 데미지 줌");  
        }  
  
    }  
      
    specialAttackDamaged = true;  
  
}

플레이어가 피격 당했을 때 커서가 0,0으로 이동하던 문제

  • DamagedState에서 마우스 입력을 안받게 설정해놔서 그런 것이었다.
  • 마우스 입력을 받는 대신 좌우로 돌지 않게끔 할 것
// DamagedState.cs
controller.isLookLocked = true;  
controller.Inputs.Player.Move.Disable();  
controller.Inputs.Player.Jump.Disable();  
controller.Inputs.Player.NormalAttack.Disable();
  • 그리고 죽으면 인게임 커서가 사라지도록 변경함
// DieState.cs
public override void Enter(PlayerController controller)  
{  
    CursorManager.Instance.SetInGame(false);
    ...
}