//This object is a tool controlled by setting its content value to a specified number.
//(Set in spawn.txt). Object is module specified and must be modified to be used
//elsewhere...
//Content commands:
//0 = play music and handle puzzle door
//1 = spawn confusing smiley
//2 = handle lava tiles
//3 = free hostage zone
//Module Setting: Cobol Empror

//------------------------------------------------------------------------------------
// CONTENT 0 - This plays music and handles the puzzle    
tmpargument = 0
IfContentIs
  IfOrdered
    tmpx = selforder
    tmpy = [OPEN]
    IfXIsEqualToY
      tmpargument = selfstate +1
      SetState
    tmpx = selforder
    tmpy = [CLOS]
    IfXIsEqualToY
      tmpargument = selfstate -1
      SetState  

   //Play music
  IfSpawned
    tmpargument = 11
    tmpdistance = 0
    PlayMusic
    
  //Setup the boss music
  IfSpawned
    tmpargument = 68
    tmpdistance = 25
    SetMusicPassage

  //Check to open or close puzzle door
  IfTimeOut
    tmpargument = 10
    SetTime

    //Open and close gate for brazier puzzle
    IfStateIs4
      tmpargument = passage    //Gate
      OpenPassage
    Else
      tmpargument = passage + 1    //Detect (allow to open from other side)
      SetTargetToWhoeverIsInPassage
        tmpargument = passage
        IfTargetCanOpenStuff
          OpenPassage
        Else
          ClosePassage
      Else
        tmpargument = passage
        ClosePassage

//------------------------------------------------------------------------------------
//CONTENT 1 - spawn confusing smiley
tmpargument = 1
IfContentIs
  IfSpawned
    tmpargument = 0
    tmpx = selfx
    tmpy = selfy
    tmpdistance = selfz
    SpawnExactParticle

    //All done!
    GoPoof

//------------------------------------------------------------------------------------
// CONTENT 2 - This causes tiles to break away    
tmpargument = 2
IfContentIs
  IfTimeOut
    tmpargument = 2
    SetTime
    
    // Decrement the break sound counter
    tmpargument = 0
    IfStateIsNot
      tmpargument = selfstate - 1
      SetState

    tmpturn = 200                          // The starting tile
    tmpdistance = 7                        // Number of frames
    tmpargument = passage                  // The passage
    tmpx = 208                             // The tile to become when animated
    tmpy = FXDAMAGE + FXANIM + FXWATER     // Water so weather spawns correctly
    BreakPassage
    
      // Play the break sound?
      IfStateIs0
        tmpargument = passage
        SetTargetToWhoeverIsInPassage
          tmpx = targetx
          tmpy = targety                //Play the sound where the tile breaks
          Teleport
        tmpargument = 1
        PlaySound
        tmpargument = 10      //cooldown
        SetState

//------------------------------------------------------------------------------------
// CONTENT 3 - This frees hostages in the exit zone (selfcontent is number of hostages freed)
tmpargument = 3
IfContentIs
  IfTimeOut
    tmpargument = 10
    SetTime
    tmpargument = passage
    SetTargetToWhoeverIsInPassage
      tmpargument = [TOUR]
      IfTargetHasID
        IfTargetIsAPlayer
          DoNothing             //Don't save Tourist players
        Else
          PoofTarget
          
            //Tell them what happened
            tmpargument = 2
            PlayFullSound
            tmpargument = 0
            SendMessage
            
            //Award some xp
            tmpargument = 75
            tmpdistance = EXPQUEST
            GiveExperienceToGoodTeam
            
            //Remember how many
            tmpargument = selfstate + 1
            SetState
              
            //This is one way of beating the level
            BeatModule
            EnableExport
            tmpargument = [TOUR]
            tmpdistance = selfstate     //Set quest level to the number of hostages saved
            AddQuestAllPlayers
            tmpargument = [BEAT]
            AddIDSZ
            
            //End text
            ClearEndMessage
            tmpargument = 2
            AddEndMessage
            tmpargument = 3
            AddEndMessage
            
            
            //Award some extra xp for saving all three!
            IfStateIs3
              tmpargument = 200
              tmpdistance = EXPQUEST
              GiveExperienceToGoodTeam
              tmpargument = 1
              SendMessage
              
              //Unlock the tourist starter
              tmpargument = [TOUR]
              AddIDSZ
              
              //No longer needed
              GoPoof
        
//------------------------------------------------------------------------------------
End					// All done
//------------------------------------------------------------------------------------
