//The different states:
//0: Guard\Combat
//1: Turned to ice
//Note: This is a specific boss script!

//------------------------------------------------------------------------------
//Combat/Guard
IfSpawned
  tmpargument = passage
  ClosePassage

//------------------------------------------------------------------------------
//Combat/Guard
IfStateIs0
  IfAtLastWaypoint	//Choose next move
    tmpturn = rand	//Randomly...
    tmpx = selfspawnx
    tmpy = selfspawny
    tmpdistance = 200	//up to 200 distance from spawn point
    Compass
    ClearWaypoints
    AddWaypoint
  IfBumped		//How to react if bumped
    SetTargetToWhoeverBumped
    IfTargetIsOnHatedTeam	//Enemy?
      IfFacingTarget		//Attack?
        // Battle cry
        tmpargument = 3
        tmpdistance = rand & 2047 + 6000
        PlaySound

        //Attack natural weapon
        tmpargument = LATCHRIGHT
        PressLatchButton
      Else		//Not looking at enemy, move towards him
        tmpx = targetx
        tmpy = targety
        ClearWaypoints
        AddWaypoint
    Else		//Move out of way of friendlies
      tmpx = rand & 511 - 256 + selfx
      tmpy = rand & 511 - 256 + selfy
      tmpdistance = 100
      tmpturn = targetturnto + 32768
      Compass
      ClearWaypoints
      AddWaypoint
      SetTargetToOldTarget
  IfTimeOut			//Check out for enemies
    SetTargetToWideEnemy
      IfFacingTarget
        tmpx = targetdistance
        tmpy = 20
        IfXIsLessThanY		//Close enough?
          // Decide which leg to kick
          tmpargument = LATCHRIGHT
          PressLatchButton
      Else			//Get in combat position
        tmpx = targetx
        tmpy = targety
        tmpturn = targetturnto
        tmpdistance = 200
        Compass
        ClearWaypoints
        AddWaypoint
    tmpargument = 20		//Set time for next round
    SetTime

//------------------------------------------------------------------------------
//Handle death by sending a message and other stuff
IfKilled
  tmpargument = 1		//Sound number
  tmpdistance = 11025		//Frequency stuff
  PlaySound

  //Messaging
  tmpargument = MESSAGEDEATH
  IfTargetIsOnSameTeam
    tmpargument = MESSAGEFRAG
    IfTargetIsSelf
      tmpargument = MESSAGEACCIDENT
  SendMessageNear


  // Drop goodies
  tmpargument = 65535		//All of it
  DropMoney


  //Destroyed ice cloud...
  SpawnPoof

  //Open the boss door
  tmpargument = passage
  OpenPassage

//------------------------------------------------------------------------------
//Handle being attacked by blocking or countering or running away
IfAttacked
  // Turn to ice if life is less than 6 blocks
  IfStateIs0
    tmpx = selflife
    tmpy = 2560
    IfXIsLessThanY
      // Remove poison
      SetTargetToSelf
      tmpargument = 4
      HealTarget
      BlackTarget		//!!Remove?!!
      SetTargetToOldTarget
      tmpargument = 1		//Ice form
      SetState
      tmpargument = 1		//Look like ice
      ChangeArmor
      tmpargument = ACTIONMK	//Ice mode
      DoActionOverride
      KeepAction
      tmpargument = 5		//Ice sound
      tmpdistance = 11025
      PlaySound

   //Fire Bonus damage
    Else
      GetDamageType
      tmpx = tmpargument
      tmpy = DAMAGEFIRE
      IfXIsEqualToY
        // Permanent life loss from fire
        SetOldTarget
        SetTargetToSelf
        tmpargument = 0 - 1024		//Lose 4 permanent life
        GiveLifeToTarget
        SetTargetToOldTarget
        tmpargument = 5
        SendMessageNear

      //Ouch sound
      tmpargument = 2
      tmpdistance = rand & 2047 + 6000
      PlaySound

  //Hit while ice form, spawn a ice dust cloud
  Else
    tmpargument = 4
    tmpdistance = rand & 2047 + 10000
    PlaySound
    DisaffirmCharacter

//------------------------------------------------------------------------------
//What to do if frozen
IfStateIs1
  tmpx = selflife
  tmpy = 5120
  IfXIsMoreThanY	//Keep regeneration in ice form
    tmpargument = 0	//until you gain 20 life again
    ChangeArmor
    tmpargument = 0
    SetState
    tmpargument = ACTIONMJ
    DoActionOverride
    UnkeepAction


//------------------------------------------------------------------------------
End
//------------------------------------------------------------------------------
