//The different states
//0: Watch mode
//1: Combat mode
//3: Backstabbed

//SPECIAL Abyss Module stuff
IfOrdered
  tmpx = selforder
  tmpy = [UNDO]
  IfXIsEqualToY
    SetTargetToSelf
    KillTarget

//---------------------------------------------------------------------------------
//What to do if warned
IfCalledForHelp
  SetTargetToWideEnemy
    tmpargument = 3
    IfStateIsNot		//Dont if backstabbed
      tmpargument = 1
      SetState
  Else
    SetTargetToOldTarget
    tmpargument = 0
    SetState

//---------------------------------------------------------------------------------
//New round
IfTimeOut
  tmpargument = rand & 15 + 30
  SetTime
			 
  //WATCH MODE
  IfStateIs0
    Sneak
    SetTargetToWideEnemy		//Enemy nearby?
      IfFacingTarget			//See the enemy
        tmpx = targetz
        tmpy = 300
        IfXIsLessThanY			//Target not flying or jumping out of sight?
          tmpargument = 1		//Enter combat mode
          SetState
    Else
      SetTurnModeToSpin			//Spin around
    tmpx = selfx
    tmpy = selfy

  //COMBAT MODE
  IfStateIs1
    SetTurnModeToVelocity
    Run
    SetTargetToWideEnemy		//Enemy nearby?
      CallForHelp
      //SHOOT EYE RAY
      IfFacingTarget
        tmpargument = rand & 25 + 25	//Time between shots
        SetTime
        tmpargument = rand % 3 + 1	//Randomize ray
        tmpx = selfx
        tmpy = selfy
        tmpdistance = selfz + 50
        SpawnExactParticle
//        tmpargument = 256		//1 ray costs 1 mana
//        SetTargetToSelf
//        CostTargetMana
      tmpx = targetx
      tmpy = targety			//Move towards him or her

    Else				//Enemy ran away
      tmpargument = 0
      SetState
  ClearWaypoints			  //
  AddWaypoint				  //	

//---------------------------------------------------------------------------------
//Change skin
IfStateIs0		//When watching
  tmpargument = 0
  tmpx = selfspawnx	//Return to start
  tmpy = selfspawny
  ClearWaypoints
  AddWaypoint
IfStateIs1		//Or in combat
  tmpargument = 1
SetTargetToSelf
IfTargetIsAlive		//and when killed
  GetState		//DoNothing
Else		
  tmpargument = 2
SetTargetToOldTarget
ChangeArmor		//Do it

//---------------------------------------------------------------------------------
//Return to watch mode
IfStateIs1				//Only if already in combat
  IfTargetKilled				
    SetTargetToNearestEnemy
      tmpargument = 1
      SetState			//Combat
    Else
      tmpargument = 0			//Watch mode
      SetState				 


//---------------------------------------------------------------------------------
//How to react if bumped
IfBumped				// Attack whoever it bumped
  SetTargetToWhoeverBumped		  
  IfTargetIsOnHatedTeam			  // Make sure it's an enemy
    tmpargument = 3
    IfStateIsNot			  //Dont if backstabbed
      tmpargument = 1			  //Enter combat mode
      SetState
      CallForHelp		//Warn others (Only if not backstabbed)
      tmpx = targetx		//Move away from melee
      tmpy = targety
      tmpdistance = 400
      tmpturn = targetturnto + 36000
      Compass
      ClearWaypoints
      AddWaypoint
  Else					    //Move out of the way of friendlies
    tmpx = rand & 255 + targetx - 128	    
    tmpy = rand & 255 + targety - 128	    
    ClearWaypoints			    
    AddWaypoint				    
    SetTargetToOldTarget		    

//---------------------------------------------------------------------------------
//How to react if attacked
IfAttacked
  SetTargetToWhoeverAttacked

  //Backstab?
  IfStateIs0				//Hasn't seen a enemy yet
    IfHitFromBehind
      tmpargument = [DISA]		//Is it a rouge?
      IfTargetHasSkillID		
        SetTargetToSelf
        KillTarget			//Yep, instant kill
        SetTargetToWhoeverAttacked
        tmpargument = 25
        tmpdistance = EXPMURDER
        GiveExperienceToTarget		//Give some bonus xp
        tmpargument = 3
        SetState			//Backstabs are undetected
        SetContent			//For death message
        tmpargument = 1
        SendMessageNear		      

  IfTargetIsOnHatedTeam
    tmpargument = 3			//Backstabbed?
    IfStateIsNot		    
      tmpargument = 1			//Nope, enter combat mode
      SetState		
      CallForHelp		//Warn others (Only if not backstabbed)		      
  Else				    
    SetTargetToOldTarget

  tmpargument = rand % 3		  //Play damaged sound
  tmpdistance = rand & 4095 + 8000	  
  PlaySound


//---------------------------------------------------------------------------------
//What to do if killed
IfKilled	
  //Messaging	
  tmpargument = 3	//Backstabbed?
  IfContentIs
    tmpargument = 1
  Else
    tmpargument = 0	//Normal death

  SendMessageNear			    

  //Make the body
  tmpargument = 33			  
  SetBumpSize	  		  
  tmpargument = 50  
  SetBumpHeight				  			  

  tmpargument = 7
  SetShadowSize

  //Drop stash
  tmpargument = 65535			  
  DropMoney	
  DropKeys

  //Death sound
  tmpargument = 1			  
  tmpdistance = rand & 2047 + 10000	  
  PlaySound

  //Death stuff
  tmpargument = 0
  SetFlyHeight
  tmpargument = 10
  SetShadowSize
  KeepAction


//---------------------------------------------------------------------------------
End					// Finished with this character
//---------------------------------------------------------------------------------