ON INIT {
 SET £type goblin_lord
 SET §chatpos 4
 SET £friend "goblin_castle"
 SETWEAPON Axe2handed_iron
 SET £key_carried "KEY_BASE_0036Portcullis"
 SET £init_marker "Marker_0274"
 INVENTORY ADDFROMSCENE "KEY_BASE_0036"
 SET_SPEAK_PITCH 0.9
 SET §fire_angry 0
 ACCEPT
}
ON LOAD {
 USE_MESH "Goblin_lord\\Goblin_lord.teo"
 ACCEPT
}
ON RELOAD {
 SET §fire_angry 0
 ACCEPT
}

ON INITEND {
>>ROND
 SET_NPC_STAT armor_class 16
 SET_NPC_STAT absorb 25
 SET_NPC_STAT damages 18
 SET_NPC_STAT tohit 50
 SET_NPC_STAT aimtime 1000
 SET_NPC_STAT life 40
 SET_XP_VALUE 120
 BEHAVIOR Move_to
 SETTARGET Marker_0274
 SET £flee_marker "FLEE_MARKER_0043"
 SET £helping_buddy "GOBLIN_BASE_0046"
 SENDEVENT -ir DURABILITY 100 "39"
 SENDEVENT -ir DURABILITY_ARMOR 100 "48"
 INVENTORY ADD "PROVISIONS\\TORCH\\TORCH"
 INVENTORY ADDMULTI "JEWELRY\\GOLD_COIN\\GOLD_COIN" 22
 ACCEPT
}
ON COUNCIL {
 IF (^$PARAM1 == "2") {
 BEHAVIOR FRIENDLY
 SETTARGET PLAYER
 ACCEPT
}
 TIMER KILL_LOCAL
 BEHAVIOR NONE
 SETTARGET NONE
 SETEVENT CHAT OFF
 TELEPORT MARKER_0829
 TIMERlookat 1 2 BEHAVIOR FRIENDLY SETTARGET MARKER_0825
 ACCEPT
}

ON REACHEDTARGET {
  IF (^TARGET == NONE) ACCEPT
  IF (^TARGET == MARKER_0440) {
   BEHAVIOR FRIENDLY
   SETTARGET RUBY_0001
  // SENDEVENT VIEWBLOCK LIGHT_DOOR_0031 ""
   TIMERback 1 4 GOTO BACK
   ACCEPT
  }
  IF (^TARGET == Marker_0273) {
    BEHAVIOR Friendly
    SETTARGET Marker_0766
    //BEHAVIOR -a FRIENDLY 
    //TIMERtar 1 1 SETTARGET PLAYER
    TIMERguar 1 5 GOTO NEXT1
    ACCEPT
  }
  IF (^TARGET == Marker_0274) { 
    TIMERguar2 1 8 GOTO NEXT2
    BEHAVIOR Friendly
    SETTARGET Marker_0440
    TIMERsen 1 1 SENDEVENT VIEWBLOCK LIGHT_DOOR_0031 ""
    ACCEPT
  }
 IF (^TARGET == MARKER_0657) {
  BEHAVIOR FRIENDLY
  SETTARGET PORTICULLIS_0068
  SPELLCAST -SMF 1 IGNIT MARKER_0657  
  TIMERgo 1 1 GOTO ROND
  ACCEPT
 }
 ACCEPT
}

ON CHAT {
 IF (§enemy == 1) ACCEPT
 IF (^SPEAKING == 1) ACCEPT
 GOSUB START_CHAT
 SPEAK [Goblinlord_warning] GOSUB END_CHAT
 ACCEPT
}

ON CUSTOM {
  IF (^$PARAM1 == "Attak_me") {
    BEHAVIOR STACK
    BEHAVIOR -f Move_to
    SETTARGET Goblin_base_0017
    ACCEPT
  }
  IF (^$PARAM1 == "Thief") {
   IF (§enemy == 1) ACCEPT
   HEROSAY -d "Did I see you do this?"
   IF (§player_in_sight == 0) ACCEPT
   HEROSAY -d "Oh Yes"
   SPEAK -a [Goblin_thief] NOP
   SENDEVENT ATTACK_PLAYER SELF ""
   SENDEVENT CUSTOM Light_door_0031 "UNSET"
   ACCEPT
  }
 IF (^$PARAM1 == "LIGHT_FIRE") GOTO LIGHT_FIRE
  ACCEPT
}

>>NEXT1
HEROSAY -d "NEXT1"
IF ( §main_behavior_stacked != 0 ) {
 BEHAVIOR NONE
 SETTARGET NONE
 TIMERtrc 1 5 GOTO NEXT1
 }
 ELSE {
  BEHAVIOR Move_to 
  SETTARGET Marker_0274
  ACCEPT
 }
ACCEPT

>>NEXT2
IF ( §main_behavior_stacked != 0 ) {
 BEHAVIOR NONE
 SETTARGET NONE
 TIMERtrc 1 5 GOTO NEXT2
 }
 ELSE {
  BEHAVIOR MOVE_TO
  SETTARGET MARKER_0440
  ACCEPT
 }
 ACCEPT

>>BACK 
IF ( §main_behavior_stacked != 0 ) {
 BEHAVIOR NONE
 SETTARGET NONE
 TIMERtrc 1 5 GOTO BACK
 }
 ELSE {
 SENDEVENT VIEWBLOCK LIGHT_DOOR_0031 ""
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0273
 ACCEPT
}
ACCEPT
 

>>LIGHT_FIRE
IF (§fire_angry == 2) {
 SPEAK [Goblinlord_warning] SENDEVENT ATTACK_PLAYER SELF ""
 ACCEPT
}
IF (§enemy == 1) ACCEPT
SPEAK [Goblinlord_warning] NOP
TIMERguar OFF
TIMERguar2 OFF
BEHAVIOR MOVE_TO
SETTARGET MARKER_0657
INC §fire_angry 1
ACCEPT



//#behavior

// ---------------------------------------------------------------------------------
// BEHAVIOR INCLUDE START ----------------------------------------------------------
// ---------------------------------------------------------------------------------
>>CLEAR_MICE_TARGET
 // if we care about mice : clear current mice target and listen to other mice
 IF ( §care_about_mice == 1 )
 {
  SET £targeted_mice "NOMOUSE"
  SETGROUP MICECARE // listen to other mice
 }
RETURN

>>SAVE_BEHAVIOR
 TIMERcolplayer OFF 
// to avoid TIMERcolplayer to restore the behavior 1 sec later
 IF (§main_behavior_stacked == 0) 
 {
  IF (§frozen == 1)
  { 
// frozen anim -> wake up !
    SET §frozen 0
    PLAYANIM NONE
    PLAYANIM -2 NONE
    PHYSICAL ON
    COLLISION ON
    BEHAVIOR FRIENDLY
    SETTARGET PLAYER
  }
  SET §main_behavior_stacked 1
  HEROSAY -d "STACK"
  BEHAVIOR STACK
 }
 ELSE
 { // behavior already saved : clear mice target if one
  GOSUB CLEAR_MICE_TARGET
 }
RETURN

>>RESTORE_BEHAVIOR
 IF (§main_behavior_stacked == 1) 
 {
  GOSUB CLEAR_MICE_TARGET
  HEROSAY -d "UNSTACK"
  BEHAVIOR UNSTACK
  SET §main_behavior_stacked 0
  RETURN
 }
IF (£init_marker != "NONE")
  { 
   BEHAVIOR MOVE_TO
   SETTARGET -a ~£init_marker~
   SETMOVEMODE WALK
   RETURN
  }
HEROSAY -d "go_home"
BEHAVIOR GO_HOME
SETTARGET PLAYER
RETURN

// ---------------------------------------------------------------------------------
// BEHAVIOR INCLUDE END ------------------------------------------------------------
// ---------------------------------------------------------------------------------

//#
//#LocalChat
// ---------------------------------------------------------------------------------
// LocalChat INCLUDE START ---------------------------------------------------------
// ---------------------------------------------------------------------------------
>>START_CHAT
 // save misc reflection mode
 SET §saved_reflection §reflection_mode
 // no more stupid reflections !
 SET §reflection_mode 0
 // fo not change behavior if frozen
 IF ( §frozen == 1 ) RETURN
 // save behavior (if not saved)
 GOSUB SAVE_BEHAVIOR
 // look at player
 BEHAVIOR FRIENDLY
 SETTARGET PLAYER
RETURN

>>END_CHAT
 SET_EVENT COLLIDE_NPC ON
 SET §collided_player 0
 // restor behavior only if not in fighting mode
 IF ( §fighting_mode == 0 )
 {
  // restore misc reflection mode
  SET §reflection_mode §saved_reflection
  // if frozen : don't restore behavior
  IF ( §frozen == 1 ) RETURN
  // restore behavior
  GOSUB RESTORE_BEHAVIOR
 }
RETURN
// ---------------------------------------------------------------------------------
// LocalChat INCLUDE END -----------------------------------------------------------
// ---------------------------------------------------------------------------------

//#

ON DIE {
 INVENTORY ADD "ARMOR\\HELMET_CHAIN\\HELMET_CHAIN"
  ACCEPT
 }