ON INIT {
 SET §chatpos 4
 SET £friend "goblin_castle"
 SETEVENT CHAT OFF
 SET £key_carried "Portcullis"
 ACCEPT
}

ON INITEND {
 LOADANIM ACTION3 "Goblin_normal_sit_cycle"
 LOADANIM ACTION4 "Goblin_normal_sit_in"
 LOADANIM ACTION5 "Goblin_normal_sit_out"
 SET §reflection_mode 0
 SET §frozen 1
 TWEAK HEAD "goblin_nohelm"
 SETWEAPON CLUB
 BEHAVIOR -a FRIENDLY
 SETTARGET GOBLIN_BASE_0023
 SET £flee_marker "FLEE_MARKER_0037"
 SET £helping_buddy "GOBLIN_BASE_0035"
 SENDEVENT -ir DURABILITY 100 "29"
 INVENTORY ADDMULTI "JEWELRY\\GOLD_COIN\\GOLD_COIN" 11
 PLAYANIM -L ACTION3 
 ACCEPT
}
ON COUNCIL {
 IF (^$PARAM1 == "2") {
 BEHAVIOR FRIENDLY
 SETTARGET PLAYER
 ACCEPT
}
 TIMER KILL_LOCAL
 SETEVENT CHAT OFF
 PLAYANIM NONE
 BEHAVIOR NONE
 SETTARGET NONE
 TELEPORT MARKER_0826
 TIMERlookat 1 2 BEHAVIOR FRIENDLY SETTARGET GOBLIN_BASE_0042
 ACCEPT
}

ON CHAT {
 IF (§enemy == 1) ACCEPT
 IF (^SPEAKING == 1) ACCEPT
 IF (§chatpos == 4) {
  GOSUB START_CHAT
  SPEAK [Goblin_generic] GOSUB END_CHAT
  ACCEPT
 }
 ACCEPT
}
ON CUSTOM {
 IF (^$PARAM1 == "HERE_HE_COMES" ) {
  IF (#SHUT_UP == 1) {
   SENDEVENT CUSTOM GOBLIN_BASE_0023 "STOP"
   ACCEPT
  }
  TIMERstop 1 2 SENDEVENT CUSTOM GOBLIN_BASE_0023 "STOP"
  SPEAK [goblin_chat]
  ACCEPT
 }
 IF (^$PARAM1 == "chiasse" ) {
  SETEVENT CHAT ON
  SENDEVENT CUSTOM GOBLIN_BASE_0023 "LAUGH"   // I send the event now so that the laugh is more immediate
  IF (#SHUT_UP == 1) {
   TIMERchange 1 5 GOTO SUITE
   ACCEPT
  } 
  SPEAK [Goblin_here_it_comes_again_laugh] TIMERchange 1 5 GOTO SUITE
  ACCEPT
 }
 IF (^$PARAM1 == "Epok") {
  SETEVENT CHAT ON
  PLAYANIM NONE
  TELEPORT MARKER_0431
  BEHAVIOR WANDER_AROUND 300
  SETTARGET NONE
  ACCEPT
 }
 ACCEPT
}
ON REACHEDTARGET {
 IF (^TARGET == Marker_0242) {
  TIMERwait 1 5 SETTARGET Marker_0252 
  ACCEPT
 }
 IF (^TARGET == Marker_0252) {
  BEHAVIOR FRIENDLY
  SETTARGET Marker_0242
  TIMERsit 1 2 GOTO PREWAND
  ACCEPT
 }
 ACCEPT
}
>>SUITE
  SET §reflection_mode 1
//  PLAYANIM -e ACTION5 GOTO SUITE2
  ACCEPT

>>SUITE2
  //TIMERgo 1 3
  SET §frozen 0
  BEHAVIOR MOVE_TO
  SETTARGET Marker_0242
  SETMOVEMODE WALK
  ACCEPT

>>PREWAND
  PLAYANIM -e ACTION4 PLAYANIM -L ACTION3
  SET §frozen 1
  TIMERwand 1 15 GOTO WAND
  ACCEPT

>>WAND
PLAYANIM -e ACTION5 GOTO WAND2
ACCEPT

>>WAND2
SET §frozen 0
BEHAVIOR Wander_around 200
SETTARGET NONE
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
    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 -----------------------------------------------------------
// ---------------------------------------------------------------------------------

//#