Beispiel #1
0
        private void HandleReceivedInput(InputEventArg <PlayerInputCommand> input)
        {
            var     pInput          = _input as PlayerInput;
            Vector2 aimingDirection = pInput.GetAimingDirection();

            switch (input._command)
            {
            // Normal jump. If player is on ground, jump away without holding the jump button
            case PlayerInputCommand.JumpBegin:
                if (!_groundDetector.IsOnGround)
                {
                    break;
                }
                CancelAnimation();
                _mover.Jump();
                _animator.SetToggle(PlayerFSMData.Stat.Jump, true);
                break;

            // Extra jump only happens here, normal jump could happen too if player is on ground.
            case PlayerInputCommand.Jump:
                if (!_groundDetector.IsOnGround &&
                    !_extraJump)
                {
                    break;
                }

                CancelAnimation();
                if (_extraJump)
                {
                    _mover.ExtraJump(input._additionalValue);
                    _extraJump = false;
                }
                else
                {
                    _mover.Jump();
                }

                TriggerBulletTimeIfPossible();
                _animator.SetToggle(PlayerFSMData.Stat.Jump, true);
                break;

            // Dash. Both ground and air dash.
            case PlayerInputCommand.Dash:
                if (!_dashCooldownTimer.IsReachedTime())
                {
                    return;
                }

                // Determine the dashing direction
                var dashingDirection = _input.GetMovingDirection();
                if (dashingDirection == Vector2.zero)
                {
                    dashingDirection = _state._facingRight ? Vector2.right : Vector2.left;
                }
                else
                {
                    dashingDirection = DirectionalHelper.NormalizeOctadDirection(dashingDirection);
                }

                UpdateFacingDirection(dashingDirection);

                var airDash = !_groundDetector.IsOnGround || dashingDirection.y > 0;

                // Break if this dash cannot happen
                if (airDash && _state._stamina <= 0)
                {
                    break;
                }

                _airDashGhost.enabled    = airDash;
                _groundDashGhost.enabled = !airDash;

                CancelAnimation();
                _mover.Dash(dashingDirection);

                if (airDash)
                {
                    _state._stamina  -= 1;
                    _currentAirAttack = 0;
                    TriggerBulletTimeIfPossible();

                    _extraJump       = true;
                    _bulletTimeReady = true;
                    _btManager.StartDashBTWindow();
                }
                else
                {
                    _dashCooldownTimer.Start(_dashCooldown);
                }

                _animator.SetToggle(PlayerFSMData.Stat.DashBegin, true);
                _animator.SetFloat(PlayerFSMData.Stat.XSpeed, dashingDirection.x);
                _animator.SetFloat(PlayerFSMData.Stat.YSpeed, dashingDirection.y);
                SetBlockInput(true);
                SetFrozen(true);

                _animator.UpdateAnimationState();
                break;

            //case PlayerInputCommand.MeleeBegin:
            //    if (!_groundDetector.IsOnGround && _currentAirAttack >= _maxAirAttack)
            //        break;
            //    CancelAnimation();
            //    break;

            // Both air melee and ground melee
            case PlayerInputCommand.MeleeAttack:
                if (!_groundDetector.IsOnGround && _currentAirAttack >= _maxAirAttack)
                {
                    break;
                }

                // Counting air attack
                if (!_groundDetector.IsOnGround)
                {
                    _currentAirAttack++;
                }

                _animator.SetToggle(PlayerFSMData.Stat.MeleeAttack, true);
                _mover.AirAttacking = !_groundDetector.IsOnGround;
                SetDelayInput(true);
                SetFrozen(true);

                TriggerBulletTimeIfPossible();
                break;

            //case PlayerInputCommand.MeleeChargeBegin:
            //    CancelAnimation();
            //    _animator.SetBool(PlayerFSMData.Stat.Charge, true);
            //    SetFrozen(true);

            //    TriggerBulletTimeIfPossible();
            //    break;

            //case PlayerInputCommand.MeleeChargeBreak:
            //    CancelAnimation();
            //    _animator.SetBool(PlayerFSMData.Stat.Charge, false);
            //    break;

            //case PlayerInputCommand.MeleeChargeAttack:
            //    _weaponSystem.ChargedMeleeAttack(input._additionalValue);
            //    _animator.SetToggle(PlayerFSMData.Stat.MeleeAttack, true);
            //    SetDelayInput(true);
            //    SetFrozen(true);
            //    break;

            case PlayerInputCommand.RangeBegin:
                _weaponSystem.StartRangeCharge(input._actionChargedPercent);
                _aimAssistant.StartAimingAssistant();
                break;

            case PlayerInputCommand.RangeAttack:
                if (!pInput.IsUsingController)
                {
                    _weaponSystem.RangeAttack(aimingDirection);
                    break;
                }

                if (aimingDirection.sqrMagnitude <= 0.025f)
                {
                    aimingDirection = _aimAssistant.ToNearestTarget(_state._facingRight);
                }
                else
                {
                    aimingDirection = _aimAssistant.ExcuteAimingAssistantance(aimingDirection);
                }
                _weaponSystem.RangeAttack(aimingDirection);
                break;

            case PlayerInputCommand.RangeChargeBreak:
                _weaponSystem.StopCharging();
                break;

            case PlayerInputCommand.RangeChargeAttack:
                if (!pInput.IsUsingController)
                {
                    _weaponSystem.ChargedRangeAttack(aimingDirection);
                    break;
                }

                if (aimingDirection.sqrMagnitude <= 0.025f)
                {
                    aimingDirection = _aimAssistant.ToNearestTarget(_state._facingRight);
                }
                else
                {
                    aimingDirection = _aimAssistant.ExcuteAimingAssistantance(aimingDirection);
                }
                _weaponSystem.ChargedRangeAttack(aimingDirection);
                break;

            case PlayerInputCommand.WithdrawAll:
                TriggerBulletTimeIfPossible();
                _weaponSystem.WithdrawAll();
                break;

            case PlayerInputCommand.WithdrawOne:
                TriggerBulletTimeIfPossible();
                _weaponSystem.WithdrawOne();
                break;

            case PlayerInputCommand.Regenerate:
                if (_state._stamina < _healingStaminaCost)
                {
                    break;
                }
                _animator.SetToggle(PlayerFSMData.Stat.Healing, true);
                SetBlockInput(true);
                SetFrozen(true);
                break;
            }
        }