protected override StateMachineTransition <CharacterChoiceStates> Transition(Entity entity, CharacterChoiceStateMachineComponent stateMachine) { var input = entity.getComponent <PlayerInputComponent>(); var state = stateMachine.State; if (state.StateEnum == CharacterChoiceStates.Idle && Math.Abs(input.MovementStick.X) > CharacterChoiceState.MOVEMENT_THRESHOLD) { if (input.MovementStick.X > 0) { Console.WriteLine($"rotating right!"); return(StateMachineTransition <CharacterChoiceStates> .Replace(CharacterChoiceStates.RotatingRight)); } else { Console.WriteLine($"rotating left!"); return(StateMachineTransition <CharacterChoiceStates> .Replace(CharacterChoiceStates.RotatingLeft)); } } else if (state.StateEnum == CharacterChoiceStates.RotatingLeft || state.StateEnum == CharacterChoiceStates.RotatingRight) { if (Time.time - state.LastRotatedTime > CharacterChoiceState.ROTATION_TIME) { Console.WriteLine($"done rotating!! back to idle"); return(StateMachineTransition <CharacterChoiceStates> .Replace(CharacterChoiceStates.Idle)); // back into idle } } return(StateMachineTransition <CharacterChoiceStates> .None()); }
protected override StateMachineTransition <GameStates> Transition(Entity entity, GameStateComponent stateMachine) { var state = stateMachine.State; var gameStateTimer = entity.getComponent <TimerComponent>(); switch (state.StateEnum) { case GameStates.Ready: return(StateMachineTransition <GameStates> .Replace(GameStates.Service)); case GameStates.Service: var ballVelocity = state.Ball.getComponent <VelocityComponent>(); var ballState = state.Ball.getComponent <BallStateComponent>(); if (!ballVelocity.Freeze) { ballVelocity.Velocity = ballVelocity.Velocity / ballState.HitBoost; ballState.HitBoost = 1.0f; return(StateMachineTransition <GameStates> .Replace(GameStates.Play)); } break; case GameStates.Play: var knockedOutTeam = isOneTeamKnockedOut(state.Players); switch (knockedOutTeam) { case Gameplay.Side.LEFT: return(StateMachineTransition <GameStates> .Replace(GameStates.PointScoredRight)); case Gameplay.Side.RIGHT: return(StateMachineTransition <GameStates> .Replace(GameStates.PointScoredLeft)); case Gameplay.Side.NONE: break; default: throw new ArgumentOutOfRangeException(); } break; case GameStates.PointScoredRight: case GameStates.PointScoredLeft: if (gameStateTimer.Finished) { return(StateMachineTransition <GameStates> .Replace(GameStates.Service)); } break; default: throw new ArgumentOutOfRangeException(); } return(StateMachineTransition <GameStates> .None()); }
protected override StateMachineTransition <WizardStates> Transition(Entity entity, WizardStateMachineComponent stateMachine) { var input = entity.getComponent <PlayerInputComponent>(); var events = entity.getComponent <EventComponent>(); var wizardState = stateMachine.State; var playerState = entity.getComponent <PlayerStateComponent>(); if (wizardState.StateEnum != WizardStates.KO && wizardState.StateEnum != WizardStates.Eliminated && playerState.IsKilled) { return(StateMachineTransition <WizardStates> .Replace(WizardStates.KO)); } switch (wizardState.StateEnum) { case WizardStates.Idle: if (input.AttackPressed) { return(StateMachineTransition <WizardStates> .Replace(WizardStates.Charge)); } else if (input.HeavyAttackPressed) { return(StateMachineTransition <WizardStates> .Replace(WizardStates.ChargeHeavy)); } else if (input.DashPressed && wizardState.GlideCooldown >= WizardState.GLIDE_COOLDOWN) { return(StateMachineTransition <WizardStates> .Replace(WizardStates.PreGlide)); } else if (input.MovementStick.LengthSquared() > PlayerStateComponent.DEAD_ZONE) { return(StateMachineTransition <WizardStates> .Replace(WizardStates.Walk)); } break; case WizardStates.Walk: if (input.AttackPressed) { return(StateMachineTransition <WizardStates> .Replace(WizardStates.Charge)); } else if (input.HeavyAttackPressed) { return(StateMachineTransition <WizardStates> .Replace(WizardStates.ChargeHeavy)); } else if (input.DashPressed && wizardState.GlideCooldown >= WizardState.GLIDE_COOLDOWN) { return(StateMachineTransition <WizardStates> .Replace(WizardStates.PreGlide)); } else if (input.MovementStick.LengthSquared() < PlayerStateComponent.DEAD_ZONE) { return(StateMachineTransition <WizardStates> .Replace(WizardStates.Idle)); } break; case WizardStates.Charge: if (!input.AttackPressed) { return(StateMachineTransition <WizardStates> .Replace(WizardStates.Attack)); } break; case WizardStates.ChargeHeavy: if (!input.HeavyAttackPressed) { return(StateMachineTransition <WizardStates> .Replace(WizardStates.AttackHeavy)); } break; case WizardStates.AttackHeavy: case WizardStates.Attack: playerState.SwingFinished = events.ConsumeEventAndReturnIfPresent(PlayerEvents.PLAYER_SWING_END); if (playerState.SwingFinished) { return(StateMachineTransition <WizardStates> .Replace(WizardStates.Idle)); } if (events.ConsumeEventAndReturnIfPresent(PlayerEvents.PLAYER_HIT_START)) { playerState.HitActive = true; } if (events.ConsumeEventAndReturnIfPresent(PlayerEvents.PLAYER_HIT_END)) { playerState.HitActive = false; } break; case WizardStates.PreGlide: if (wizardState.GlideTime >= WizardState.GLIDE_DELAY) { return(StateMachineTransition <WizardStates> .Replace(WizardStates.Glide)); } break; case WizardStates.Glide: if (input.AttackPressed) { wizardState.GlideTime = 10000; // kill the glide so it pops back to glide -> instantly to ilde return(StateMachineTransition <WizardStates> .Replace(WizardStates.Charge)); } else if (input.HeavyAttackPressed) { wizardState.LastGlideTime = wizardState.GlideTime; return(StateMachineTransition <WizardStates> .Replace(WizardStates.ChargeHeavy)); } else if (wizardState.GlideTime >= WizardState.MAX_GLIDE_TIME) { return(StateMachineTransition <WizardStates> .Replace(WizardStates.Idle)); } break; case WizardStates.KO: if (events.ConsumeEventAndReturnIfPresent(PlayerEvents.KO_END)) { return(StateMachineTransition <WizardStates> .Replace(WizardStates.Eliminated)); } break; case WizardStates.Eliminated: if (!playerState.IsKilled) { return(StateMachineTransition <WizardStates> .Replace(WizardStates.Idle)); } break; default: throw new ArgumentOutOfRangeException(); } return(StateMachineTransition <WizardStates> .None()); }
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()); }