ON INIT {
 SET £type goblin_lord
 SET §chatpos 4
 INVENTORY ADD_FROM_SCENE "KEY_BASE_0020"
 SET £key_carried "KEY_BASE_0020KEY_BASE_0035PortcullisKEY_BASE_0036"
 SET £friend "goblin_castle"
 SETWEAPON Sword2handed_iron
 SET £init_marker "Marker_0271"
 SET_SPEAK_PITCH 1.1
 SET §barrel 0
 SET §fire_angry 0
 ACCEPT
}

ON INITEND {
>>ROND
 BEHAVIOR Move_to
 SETTARGET Marker_0271
 SET £flee_marker "FLEE_MARKER_0042"
 SET £helping_buddy "GOBLIN_BASE_0046"
 SENDEVENT -ir DURABILITY 100 "44"
 SENDEVENT -ir DURABILITY_ARMOR 100 "31"
 INVENTORY ADDMULTI "JEWELRY\\GOLD_COIN\\GOLD_COIN" 27
 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
 ACCEPT
}

ON LOAD {
 USE_MESH "Goblin_lord\\Goblin_lord.teo"
 ACCEPT
}
ON RELOAD {
 SET §fire_angry 0
 ACCEPT
}

ON REACHEDTARGET {
 IF (^TARGET == Marker_0271) {
  TIMERguard 1 15 GOTO NEXT1
  BEHAVIOR Friendly
  SETTARGET Marker_0276
  ACCEPT
 }
 IF (^TARGET == BARREL_0005) {
  SET §barrel 1
  BEHAVIOR FRIENDLY
  SETTARGET BARREL_0005
  BEHAVIOR MOVE_TO
  TIMERret 1 2 GOTO NEXT2
  ACCEPT
 }
 IF (^TARGET == Marker_0272) { 
  RANDOM 20 {
   BEHAVIOR MOVE_TO
   SETTARGET BARREL_0005
   ACCEPT
  }
  TIMERguard2 1 15 GOTO NEXT2
  BEHAVIOR Friendly
  SETTARGET Marker_0277
  ACCEPT
 }
 IF (^TARGET == MARKER_0658) {
  BEHAVIOR FRIENDLY
  SETTARGET MARKER_0508
  SPELLCAST -SMF 1 IGNIT MARKER_0658 
  TIMERgo 1 1 GOTO ROND
  ACCEPT
 }
 ACCEPT
}
ON COUNCIL {
 IF (^$PARAM1 == "2") {
 BEHAVIOR FRIENDLY
 SETTARGET PLAYER
 ACCEPT
}
 TIMER KILL_LOCAL
 BEHAVIOR NONE
 SETTARGET NONE
 SETEVENT CHAT OFF
 TELEPORT MARKER_0828
 TIMERlookat 1 2 BEHAVIOR FRIENDLY SETTARGET MARKER_0826
 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 == "Control") {
//  SET_CONTROLLED_ZONE GUARD_ZONE
  ACCEPT
 }
IF (^$PARAM1 == "Attak_me") {
  BEHAVIOR STACK
  SETEVENT CHAT OFF
  BEHAVIOR -f Move_to
  SETTARGET Goblin_base_0017
  ACCEPT
 }
 IF (^$PARAM1 == "Stop_attak") {
  BEHAVIOR UNSTACK
  SETEVENT CHAT OFF
  ACCEPT
 }
 IF (^$PARAM1 == "DISTURB") {
  IF (^SPEAKING == 1) ACCEPT
  SPEAK [Goblinlord_warning] NOP
  ACCEPT
 }
 IF (^$PARAM1 == "LIGHT_FIRE") GOTO LIGHT_FIRE
 ACCEPT
}
ON CONTROLLEDZONE_ENTER {
 IF (^$PARAM1 != PLAYER) ACCEPT
 IF (§player_in_sight == 1) {
  SPEAK [Goblinlord_thief] NOP
  SENDEVENT ATTACK_PLAYER SELF ""
  UNSET_CONTROLLED_ZONE GUARD_ZONE
  ACCEPT
 }
 ACCEPT
}

ON CONTROLLEDZONE_LEAVE {
 IF (^$PARAM1 != PLAYER) ACCEPT
 IF (§player_in_sight == 1) {
  SPEAK [Goblinlord_thief] NOP
  SENDEVENT ATTACK_PLAYER SELF ""
  UNSET_CONTROLLED_ZONE GUARD_ZONE
  ACCEPT
 }
 ACCEPT
}

>>NEXT1
IF ( §main_behavior_stacked != 0 ) {
 BEHAVIOR NONE
 SETTARGET NONE
 TIMERtru 1 5 GOTO NEXT1
 }
 ELSE {
  BEHAVIOR Move_to  
  SETTARGET Marker_0272
  ACCEPT
 }
ACCEPT

>>NEXT2
IF ( §main_behavior_stacked != 0 ) {
 BEHAVIOR NONE
 SETTARGET NONE
 TIMERtru 1 5 GOTO NEXT2
 }
 ELSE {
  SET §barrel 0
  BEHAVIOR Move_to 
  SETTARGET Marker_0271
  ACCEPT
 }
ACCEPT

>>LIGHT_FIRE
 IF (§fire_angry == 2) {
  SPEAK [Goblinlord_warning] SENDEVENT ATTACK_PLAYER SELF ""
  ACCEPT
 }
 IF (§enemy == 1) ACCEPT
 SPEAK [Goblinlord_warning] NOP
 TIMERguard OFF
 TIMERguard2 OFF
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0658
 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
 }