示例#1
0
        protected override StateMachineTransition <SpacemanStates> Transition(Entity entity, SpacemanStateMachineComponent stateMachine)
        {
            var input         = entity.getComponent <PlayerInputComponent>();
            var events        = entity.getComponent <EventComponent>();
            var playerState   = entity.getComponent <PlayerStateComponent>();
            var spacemanState = stateMachine.State;

            if (spacemanState.StateEnum != SpacemanStates.KO && spacemanState.StateEnum != SpacemanStates.Eliminated && playerState.IsKilled)
            {
                return(StateMachineTransition <SpacemanStates> .Replace(SpacemanStates.KO));
            }

            switch (spacemanState.StateEnum)
            {
            case SpacemanStates.Idle:
                if (input.AttackPressed)
                {
                    return(StateMachineTransition <SpacemanStates> .Push(SpacemanStates.Attack));
                }
                else if (input.HeavyAttackPressed && spacemanState.ShieldCooldown >= SpacemanState.SHIELD_COOLDOWN)
                {
                    return(StateMachineTransition <SpacemanStates> .Push(SpacemanStates.Shield));
                }
                else if (input.MovementStick.LengthSquared() > PlayerStateComponent.DEAD_ZONE)
                {
                    return(StateMachineTransition <SpacemanStates> .Replace(SpacemanStates.Walk));
                }
                break;

            case SpacemanStates.Walk:
                if (input.AttackPressed)
                {
                    return(StateMachineTransition <SpacemanStates> .Push(SpacemanStates.Attack));
                }
                else if (input.HeavyAttackPressed && spacemanState.ShieldCooldown >= SpacemanState.SHIELD_COOLDOWN)
                {
                    return(StateMachineTransition <SpacemanStates> .Push(SpacemanStates.Shield));
                }
                else if (input.MovementStick.LengthSquared() < PlayerStateComponent.DEAD_ZONE)
                {
                    return(StateMachineTransition <SpacemanStates> .Replace(SpacemanStates.Idle));
                }
                break;

            case SpacemanStates.Attack:
                playerState.SwingFinished = events.ConsumeEventAndReturnIfPresent(PlayerEvents.PLAYER_SWING_END);
                if (playerState.SwingFinished)
                {
                    return(StateMachineTransition <SpacemanStates> .Pop());
                }
                if (events.ConsumeEventAndReturnIfPresent(PlayerEvents.PLAYER_HIT_START))
                {
                    playerState.HitActive = true;
                }
                if (events.ConsumeEventAndReturnIfPresent(PlayerEvents.PLAYER_HIT_END))
                {
                    playerState.HitActive = false;
                }
                break;

            case SpacemanStates.KO:
                if (events.ConsumeEventAndReturnIfPresent(PlayerEvents.KO_END) || Time.time - spacemanState.KoTime > SpacemanState.KO_ANIM_PLACEHOLDER_LENGTH)
                {
                    return(StateMachineTransition <SpacemanStates> .Replace(SpacemanStates.Eliminated));
                }
                break;

            case SpacemanStates.Eliminated:
                if (!playerState.IsKilled)
                {
                    return(StateMachineTransition <SpacemanStates> .Replace(SpacemanStates.Idle));
                }
                break;

            case SpacemanStates.Shield:
                if (events.ConsumeEventAndReturnIfPresent(PlayerEvents.BLOCK_END))
                {
                    return(StateMachineTransition <SpacemanStates> .Replace(SpacemanStates.Idle));
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(StateMachineTransition <SpacemanStates> .None());
        }
        protected override StateMachineTransition <KnightStates> Transition(Entity entity, KnightStateMachineComponent stateMachine)
        {
            var input       = entity.getComponent <PlayerInputComponent>();
            var events      = entity.getComponent <EventComponent>();
            var playerState = entity.getComponent <PlayerStateComponent>();
            var knightState = stateMachine.State;

            if (knightState.StateEnum != KnightStates.KO && knightState.StateEnum != KnightStates.Eliminated && playerState.IsKilled)
            {
                return(StateMachineTransition <KnightStates> .Replace(KnightStates.KO));
            }

            switch (knightState.StateEnum)
            {
            case KnightStates.Idle:
                if (input.AttackPressed)
                {
                    return(StateMachineTransition <KnightStates> .Push(KnightStates.Charge));
                }
                else if (input.HeavyAttackPressed)
                {
                    return(StateMachineTransition <KnightStates> .Push(KnightStates.ChargeHeavy));
                }
                else if (input.DashPressed && knightState.SprintRemaining >= KnightState.MIN_START_SPRINT)
                {
                    return(StateMachineTransition <KnightStates> .Push(KnightStates.Dash));
                }
                else if (input.MovementStick.LengthSquared() > PlayerStateComponent.DEAD_ZONE)
                {
                    return(StateMachineTransition <KnightStates> .Replace(KnightStates.Walk));
                }
                break;

            case KnightStates.Walk:
                if (input.AttackPressed)
                {
                    return(StateMachineTransition <KnightStates> .Push(KnightStates.Charge));
                }
                else if (input.HeavyAttackPressed)
                {
                    return(StateMachineTransition <KnightStates> .Push(KnightStates.ChargeHeavy));
                }
                else if (input.DashPressed && input.DashPressed && knightState.SprintRemaining >= KnightState.MIN_START_SPRINT)
                {
                    return(StateMachineTransition <KnightStates> .Push(KnightStates.Dash));
                }
                else if (input.MovementStick.LengthSquared() < PlayerStateComponent.DEAD_ZONE)
                {
                    return(StateMachineTransition <KnightStates> .Replace(KnightStates.Idle));
                }
                break;

            case KnightStates.Dash:
                if (!input.DashPressed || knightState.SprintRemaining <= 0.01)
                {
                    return(StateMachineTransition <KnightStates> .Pop());
                }
                else if (input.AttackPressed)
                {
                    return(StateMachineTransition <KnightStates> .Push(KnightStates.Charge));
                }
                else if (input.HeavyAttackPressed)
                {
                    return(StateMachineTransition <KnightStates> .Push(KnightStates.ChargeHeavy));
                }
                else if (playerState.DashFinished)
                {
                    return(StateMachineTransition <KnightStates> .Pop());
                }
                break;

            case KnightStates.Charge:
                if (!input.AttackPressed)
                {
                    return(StateMachineTransition <KnightStates> .Replace(KnightStates.Swing));
                }
                break;

            case KnightStates.Swing:
                playerState.SwingFinished = events.ConsumeEventAndReturnIfPresent(PlayerEvents.PLAYER_SWING_END);
                if (playerState.SwingFinished)
                {
                    return(StateMachineTransition <KnightStates> .Pop());
                }
                if (events.ConsumeEventAndReturnIfPresent(PlayerEvents.PLAYER_HIT_START))
                {
                    playerState.HitActive = true;
                }
                if (events.ConsumeEventAndReturnIfPresent(PlayerEvents.PLAYER_HIT_END))
                {
                    playerState.HitActive = false;
                }
                break;

            case KnightStates.KO:
                if (events.ConsumeEventAndReturnIfPresent(PlayerEvents.KO_END))
                {
                    return(StateMachineTransition <KnightStates> .Replace(KnightStates.Eliminated));
                }
                break;

            case KnightStates.Eliminated:
                if (!playerState.IsKilled)
                {
                    return(StateMachineTransition <KnightStates> .Replace(KnightStates.Idle));
                }
                break;

            case KnightStates.ChargeHeavy:
                if (!input.HeavyAttackPressed)
                {
                    return(StateMachineTransition <KnightStates> .Replace(KnightStates.SwingHeavy));
                }
                break;

            case KnightStates.SwingHeavy:
                playerState.SwingFinished = events.ConsumeEventAndReturnIfPresent(PlayerEvents.PLAYER_SWING_END);
                if (playerState.SwingFinished)
                {
                    return(StateMachineTransition <KnightStates> .Pop());
                }
                if (events.ConsumeEventAndReturnIfPresent(PlayerEvents.PLAYER_HIT_START))
                {
                    playerState.HitActive = true;
                }
                if (events.ConsumeEventAndReturnIfPresent(PlayerEvents.PLAYER_HIT_END))
                {
                    playerState.HitActive = false;
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(StateMachineTransition <KnightStates> .None());
        }