using UnityEngine;

namespace Marro.PacManUdon
{
    public partial class GameManager
    {
        private void TimeSequenceStepIntermission2(int sequenceProgress)
        {
            var blinky = ghostManager.Ghosts[0];

            switch (sequenceProgress)
            {
                case 0:
                    PrepareForCutscene();
                    
                    // Show just level display
                    statusDisplay.SetLevelDisplayVisible(true);
                    break;
                case 1:
                    // Show pole
                    SetIntermissionScreenVisible(true);
                    intermission2Pole.SetActive(true);
                    intermission2Pole.Reset();
                    break;
                case 2:
                    // Start music
                    soundManager.SuppressSound(false);
                    soundManager.StartIntermissionSound();
                    break;
                case 3:
                    // Start animation, pacman running and blinky prepared to chase
                    pacMan.SetLevel(4);
                    pacMan.SetPowerPellet(false); // Update speed
                    pacMan.SetKinematic(true);
                    pacMan.SetActive(true);
                    pacMan.SetPosition(intermissionScreenElements[0].transform.localPosition);
                    pacMan.SetDirectionAndTargetDirection(Direction.Left);

                    ghostManager.SetLevel(5);
                    ghostManager.SetKinematic(true);
                    ghostManager.gameObject.SetActive(true);
                    blinky.SetElroy(2);
                    blinky.SetPosition(intermissionScreenElements[1].transform.localPosition);
                    blinky.SetDirectionAndTargetDirection(Direction.Left);
                    blinky.SetState(PacManGhostState.Normal);

                    SetFrozen(false);
                    break;
                case 4:
                    // Start blinky chasing
                    blinky.SetActive(true);
                    break;
                case 5:
                    // Blinky catches on pole
                    blinky.SetSpeed(1.25f);
                    break;
                case 6:
                    // Blinky cover about to tear
                    blinky.SetFrozen(true);
                    break;
                case 7:
                    // Blinky cover tears
                    intermission2Pole.SetStrechLevel(PoleStrechLevels.Separated);
                    break;
                case 8:
                    // Blinky sprite updates with broken cover
                    blinky.SetSpecialLook(true);
                    blinky.SetDirectionAndTargetDirection(Direction.Up);
                    blinky.SetPosition(blinky.GetPosition() + new Vector2(-0.250f, 0f));
                    break;
                case 9:
                    // Blinky looks at broken cover
                    blinky.SetDirectionAndTargetDirection(Direction.Down);
                    break;
                case 10:
                    // Cutscene starts to unload
                    blinky.SetDirectionAndTargetDirection(Direction.Zero);
                    break;
                case 11:
                    // End cutscene
                    SetFrozen(true);
                    break;
            }
        }

        private void TimeSequenceFinalizeIntermission2()
        {
            SetIntermissionScreenVisible(false);
            soundManager.StopAllSound();
        }

        private void TimeSequenceFinishedIntermission2()
        {
            StartTimeSequence(PacManTimeSequence.StartNewLevel);
        }
    }
}
