//This spawns the portal in the beginning and starts the music
IfSpawned
  tmpx = selfx
  tmpy = selfy
  tmpdistance = selfz
  tmpargument = 0
  SpawnExactParticle

  tmpargument = 18
  tmpdistance = 0
  PlayMusic

  tmpargument = 100
  SetTime

  //Make pittraps work
  tmpx = 8640
  tmpy = 13888          //Coordinates on where to drop the player
  tmpdistance = 1200
  PitsFall

  //Ready the boss music
  tmpargument = 36		//Boss music theme
  tmpdistance = 16
  SetMusicPassage

  //This keeps track of the number of seals left
  tmpargument = 0
  tmpx = 0          //Number destroyed
  tmpy = 4          //Total number of seals in map
  SetXY

//This happens when a deamon lord dies
IfOrdered
  tmpx = selforder
  tmpy = [LKIL]
  IfXIsEqualToY
    GetContent
    tmpargument = tmpargument - 1
    SetContent

IfTimeOut
  tmpargument = 1
  SetTargetToWhoeverIsInPassage
    IfTargetIsAPlayer
      IfStateIs1			//Still not broken...
        tmpargument = [KEYL]
        CostTargetItemID
          tmpargument = 150
          SetTime
          tmpargument = 5
          SendMessage
          tmpargument = 4
          PlayFullSound

          //This keeps track of the number of crowns
          tmpargument = 0
          GetXY
          tmpx = tmpx + 1
          tmpy = 4
          SetXY
          IfXIsEqualToY       //all done!
            tmpargument = 2
            SetState
        Else
          tmpargument = 3   //Need more seals... blah blah
          SendMessage
          tmpargument = 2
          PlayFullSound
          tmpargument = 350
          SetTime

      IfStateIs2                        //Broken!
        tmpargument = 4
        SendMessage
        tmpargument = 3
        PlayFullSound

        //Row 1
        tmpx = 6650
        tmpy = 6560
        GetTileXY
        tmpargument = tmpargument + 4
        SetTileXY

        tmpx = tmpx + 125
        GetTileXY
        tmpargument = tmpargument + 4
        SetTileXY

        tmpx = tmpx + 125
        GetTileXY
        tmpargument = tmpargument + 4
        SetTileXY

        tmpx = tmpx + 125
        GetTileXY
        tmpargument = tmpargument + 4
        SetTileXY

        //Row 2
        tmpx = 6650
        tmpy = 6460
        GetTileXY
        tmpargument = tmpargument + 4
        SetTileXY

        tmpx = tmpx + 125
        GetTileXY
        tmpargument = tmpargument + 4
        SetTileXY

        tmpx = tmpx + 125
        GetTileXY
        tmpargument = tmpargument + 4
        SetTileXY

        tmpx = tmpx + 125
        GetTileXY
        tmpargument = tmpargument + 4
        SetTileXY

        //Row 3
        tmpx = 6650
        tmpy = 6360
        GetTileXY
        tmpargument = tmpargument + 4
        SetTileXY

        tmpx = tmpx + 125
        GetTileXY
        tmpargument = tmpargument + 4
        SetTileXY

        tmpx = tmpx + 125
        GetTileXY
        tmpargument = tmpargument + 4
        SetTileXY

        tmpx = tmpx + 125
        GetTileXY
        tmpargument = tmpargument + 4
        SetTileXY

        //Row 4
        tmpx = 6650
        tmpy = 6260
        GetTileXY
        tmpargument = tmpargument + 4
        SetTileXY

        tmpx = tmpx + 125
        GetTileXY
        tmpargument = tmpargument + 4
        SetTileXY

        tmpx = tmpx + 125
        GetTileXY
        tmpargument = tmpargument + 4
        SetTileXY

        tmpx = tmpx + 125
        GetTileXY
        tmpargument = tmpargument + 4
        SetTileXY

        //Dont forget to actually open the boss door =)
        tmpargument = 34
        OpenPassage

      IfStateIs0			//First time introductions (check last)
        tmpargument = 1
        PlayFullSound
        tmpargument = 0
        SendMessage
        tmpargument = 1
        SendMessage
        tmpargument = 2
        SendMessage
        tmpargument = 1
        SetState
        tmpargument = 800
        SetTime

  //Open up for the deamon lord battle
  tmpargument = 6
  SetTargetToWhoeverIsInPassage
    IfTargetIsAMount
      SetTargetToRider
    IfTargetIsAPlayer
      tmpargument = 7
      OpenPassage

  //This starts the Deamon Lord battle
  GetContent
  tmpx = tmpargument
  tmpy = 0                              //At least one alive
  IfXIsMoreThanY
    tmpargument = 8
    SetTargetToWhoeverIsInPassage
      IfTargetIsAPlayer
        tmpargument = 7
        ClosePassage
        tmpargument = 9
        ClosePassage
        tmpargument = 15
        tmpdistance = 0
        PlayMusic
  //This ends the Deamon Lord battle
  Else
    tmpargument = 7	//Entrance
    OpenPassage
    tmpargument = 9	//First gate
    OpenPassage
    tmpargument = 24	//Second gate
    OpenPassage
    tmpargument = 18
    tmpdistance = 0
    PlayMusic

//This opens up the door to the magma yeti
tmpargument = 38
SetTargetToWhoeverIsInPassage
  IfTargetCanOpenStuff
    tmpargument = 37
    OpenPassage

End					// All done

