// Izak, da foreman
ON INIT {
 SET §wander 0
 SET §begin 0
 SET §wait 0
 SET §return 0
 SET £friend "goblin_castle"
 SET §notnow 0
 IF (#debug == 1) SET #troll_quest 1
 ACCEPT
}
ON GAME_READY {
 IF (§wander == 0) ACCEPT
 IF (§enemy == 1) ACCEPT
 TELEPORT MARKER_0561
 BEHAVIOR Wander_Around 200
 SETTARGET NONE
 ACCEPT
}
ON INITEND {
 TWEAK HEAD "goblin_nohelm"
 TWEAK SKIN "npc_goblin_nohelm_head" "npc_goblin_isak"
 TWEAK SKIN "npc_Goblin_base_body" "npc_Goblin_leather"
 SETWEAPON Dagger_iron
 LOADANIM ACTION3 "Goblin_normal_sit_cycle"
 SET £key_carried "Portcullis"
 BEHAVIOR -a FRIENDLY
 SETTARGET PLAYER
 SET £flee_marker "FLEE_MARKER_0040"
 SET £helping_buddy "GOBLIN_BASE_0035"
// INVENTORY ADD "ARMOR\\CHEST_LEATHER\\CHEST_LEATHER"
   INVENTORY ADD "PROVISIONS\\ROPE\\ROPE"
 SENDEVENT -ir DURABILITY 100 "37"
 SENDEVENT -ir DURABILITY_ARMOR 100 "41"
 SET £misc [Izak_strike_misc]
 IF (#debug == 1) GOTO SIMU /////XXXXXXXX
// IF (#debug == 1) GOTO SIT /////XXXXXXXX
// IF (#debug == 1) GOTO SIMU2 /////XXXXXXXX
 ACCEPT
}
ON RELOAD {
 IF (#PLAYER_ON_QUEST == 1) {
  IF (#TROLL_QUEST == 0) {
>>SIMU
   IF (§troll_enemy == 1) ACCEPT
   TELEPORT Marker_0279
   ACCEPT
  }
  ACCEPT
 }
 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_0824
 TIMERlookat 1 2 BEHAVIOR FRIENDLY SETTARGET GOBLIN_BASE_0042
 ACCEPT
}
ON REACHEDTARGET {
  IF (^TARGET == NONE) ACCEPT
  IF (^TARGET == MARKER_0113) {
    SETTARGET -a MARKER_0080
    ACCEPT
  }
  IF (^TARGET == MARKER_0080 ) {
    SETTARGET -a MARKER_0081
    ACCEPT
  }
  IF (^TARGET == MARKER_0081) {
    SETTARGET -a MARKER_0082
    ACCEPT
  }
  IF (^TARGET == MARKER_0082) {
   SETTARGET -a Marker_0083
   ACCEPT
  }
  IF (^TARGET == Marker_0083) {
    SET §reflection_mode 0
    BEHAVIOR FRIENDLY
    SETTARGET PLAYER
    SET §wait 1
    SET §chatpos 5
    SENDEVENT CUSTOM Goblin_base_0014 "HERE"
    TIMERwait 0 1 GOTO WAIT_TO_OPEN
    ACCEPT
  }
 ACCEPT
 }
ON CUSTOM {
 IF (^$PARAM1 == "TROLL_ENEMY") {
  SET §troll_enemy 1
  ACCEPT
 }
 IF (^$PARAM1 == "Appear") {
>>SIT
  SET §wander 0
  IF (§enemy == 1) ACCEPT
  SENDEVENT CUSTOM Mug_0010 "Appear" 
  SENDEVENT CUSTOM L2_Gobel_Chair_02_0001 "RESET"
  TELEPORT -i
  FORCEANGLE 310
  PLAYANIM -L ACTION3
  SET §frozen 1
  PHYSICAL OFF
  TIMERtalk -mi 0 400 GOTO TALK
  ACCEPT
 }
 IF (^$PARAM1 == "Teleport") {
>>SIMU2
  SET §wander 0
  TIMERtalk OFF
  PLAYANIM NONE
  Teleport Marker_0264
  SET £misc [Izak_reward]
  FORCEANGLE 90
  PLAYANIM -L ACTION3
  SET §frozen 1
  PHYSICAL OFF
  ACCEPT
 }
 IF (^$PARAM1 == "Go_on") GOTO WAITING1
 IF (^$PARAM1 == "Notnow") SET §notnow 1
 ACCEPT
}
ON CHAT {
  IF (§enemy == 1) ACCEPT
  IF (^SPEAKING == 1) ACCEPT
  IF (#troll_quest > 1) {
   IF (§return == 0) {
    SET §reflection_mode 0
    SPEAK -p [player_goblins_strikeover] SPEAK [Izak_reward] SET §return 1  SET §reflection_mode 1 BEHAVIOR UNSTACK
    ACCEPT
   }
   IF (§return ==1) {
    SPEAK [Izak_reward] NOP 
    ACCEPT
   }
   ACCEPT
  }
  IF (§chatpos == 0) {
   SETNAME [description_izak]
   SET §reflection_mode 0
   GOSUB START_CHAT 
   CINEMASCOPE -s ON
   SET_PLAYER_CONTROLS OFF
   PLAYERINTERFACE HIDE
   PLAYERLOOKAT ME
   SET #SHUT_UP 1
   SPEAK -p [player_to_Izak_01] GOTO Introduce
   ACCEPT
  }
  IF (§chatpos == 3) {
    IF (#troll_quest == 0) GOTO MISC
    GOSUB START_CHAT
    PLAYERLOOKAT ME
    SET #SHUT_UP 1
    CINEMASCOPE -s ON
    PLAYERINTERFACE HIDE
    SET_PLAYER_CONTROLS OFF
    SPEAK -p [player_to_Izak_03] SPEAK [Izak_followme] GOSUB END_CHAT SET #SHUT_UP 0 CINEMASCOPE -s OFF PLAYERINTERFACE SHOW SET_PLAYER_CONTROLS ON SET §chatpos 4 GOTO Follow_me 
    ACCEPT
  }
  IF (§chatpos == 5) {
   CINEMASCOPE -s ON
   PLAYERINTERFACE HIDE
   SET_PLAYER_CONTROLS OFF
   SET #SHUT_UP 1
   GOTO WAITING1
  ACCEPT
 }
  IF (§chatpos == 6) {
    GOSUB START_CHAT
    SPEAK [Izak_hurryup] GOSUB END_CHAT 
    ACCEPT
  }
 ACCEPT
}

>>Introduce
SPEAK -c ZOOM 250 200 200 165 200 150 [Izak_introduce] GOTO Introduce02
ACCEPT

>>Introduce02 
SPEAK -pc SIDE Goblin_base_0041 0 90 70 70 0 [player_to_Izak_02] GOTO Introduce03
ACCEPT

>>Introduce03
IF (#troll_quest == 1) {
 SPEAK -c KEEP [Izak_explaintrolls] GOTO 2in1
 ACCEPT
} 
SPEAK -c KEEP [Izak_explaintrolls] GOTO Introduce04
ACCEPT

>>Introduce04
CINEMASCOPE -s OFF
SET #SHUT_UP 0
SET_PLAYER_CONTROLS ON
PLAYERINTERFACE SHOW
SET §chatpos 3
GOSUB END_CHAT
ACCEPT

>>Follow_me
BEHAVIOR MOVE_TO
SETTARGET MARKER_0113
SET §begin 1
SETMOVEMODE WALK
ACCEPT

>>WAIT_TO_OPEN
 IF (§enemy == 1) ACCEPT
 IF (^SPEAKING == 1) ACCEPT
 IF (§WAIT == 0) ACCEPT
 IF (§wait == 2) ACCEPT
 IF (^DIST_PLAYER < 600) {
  IF (§notnow == 1) SET §wait 2 ACCEPT
  TIMERwait OFF
  CINEMASCOPE -s ON
  SET #SHUT_UP 1
  PLAYERINTERFACE HIDE
  SET_PLAYER_CONTROLS OFF
  GOTO WAITING1
 ACCEPT



>>WAITING1
TELEPORT -p MARKER_0561
GOSUB START_CHAT
SET §wait 2
TIMERlookat -m 1 10 PLAYERLOOKAT ME
TIMERsop -m 1 30 SPEAK -c ZOOM 180 120 180 120 110 110 [Izak_helpus] GOTO Open2
ACCEPT

>>Open2
SENDEVENT CINEMATIC CAMERA_0141 ""
SPEAK -p [player_to_Izak_04] GOTO Open3
//SPEAK -cp ZOOM 0 350 0 350 150 150 [player_to_Izak_04] GOTO Open3
ACCEPT

>>Open3
BEHAVIOR FRIENDLY
TIMERlook 1 10 SETTARGET GOBLIN_BASE_0014
TIMERcam 1 9 SENDEVENT CINEMATIC CAMERA_0141 ""
CAMERAACTIVATE NONE
SPEAK -c ZOOM 180 120 180 120 110 110 [Izak_opendoor] GOTO op3
//SPEAK -c ZOOM 50 20 50 20 70 100 [Izak_opendoor] GOTO op3
ACCEPT

>>op3
TIMERcam OFF
sendevent OFF camera_0141 ""
SENDEVENT CUSTOM GOBLIN_BASE_0014 "PORTCULLIS_OPEN"
GOTO Open4
ACCEPT

>>Open4
//SENDEVENT CUSTOM Troll_base_0016 "Teleport"
SET §chatpos 6
GOSUB END_CHAT
CINEMASCOPE -s OFF
SET #SHUT_UP 0
PLAYERINTERFACE -s SHOW
SET_PLAYER_CONTROLS ON
SET §wander 0
SET §reflection_mode 1
BEHAVIOR FRIENDLY
//SETTARGET GOBLIN_BASE_0014
SETTARGET PLAYER
BEHAVIOR -a FRIENDLY
SETTARGET PLAYER
//BEHAVIOR Wander_Around 200
//SETTARGET NONE
ACCEPT

>>MISC
GOSUB START_CHAT
SPEAK [Izak_strike_misc] GOSUB END_CHAT
ACCEPT

>>2in1
//SPEAK -cp ZOOM 20 510 20 510 60 60 [player_to_Izak_03] SPEAK -c ZOOM 0 40 0 40 70 70 [Izak_followme] GOTO 2in2
SPEAK -cp SIDE Goblin_base_0041 20 20 45 45 0 [player_to_Izak_03] SPEAK -c ZOOM 0 40 0 40 70 70 [Izak_followme] GOTO 2in2
ACCEPT

>>2in2
CINEMASCOPE -s OFF
SET #SHUT_UP 0
PLAYERINTERFACE SHOW
SET_PLAYER_CONTROLS ON 
SET §chatpos 4 
GOSUB END_CHAT
GOTO Follow_me
ACCEPT

>>TALK
IF (§enemy == 1) ACCEPT
IF (^DIST_PLAYER > 1100) ACCEPT
TIMERtalk OFF
SPEAK [Izak_Misc] NOP
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 -----------------------------------------------------------
// ---------------------------------------------------------------------------------

//#