// BURWAKA

ON INIT {
 TELEPORT MARKER_0805
 BEHAVIOR Wander_around 200
 LOADANIM ACTION1 "Troll_work_pick"
 SETTARGET NONE
 INVENTORY ADD "PROVISIONS\\CHEESE\\CHEESE"
 INVENTORY ADD "PROVISIONS\\BREAD_HALF\\BREAD_HALF"
 SET §strike 1
 SET §speaking 1
 IF (#debug == 1) GOTO STRIKE
 ACCEPT
}

ON INITEND {
 TWEAK SKIN "npc_trollbase_head" "npc_trollbase_head_burwaka"
 ACCEPT
}

ON PLAYER_ENEMY {
 (IF #TROLL_QUEST == 2) DETACH pick_axe_0014 SELF
 ACCEPT
}

ON CHAT {
 IF (§enemy == 1) ACCEPT
 IF (^SPEAKING == 1) ACCEPT
// IF (§work == 1) {
//  SPEAK -p [player_not_now] NOP
//  ACCEPT
// }
 SET §speaking 1
 PLAYANIM NONE
 IF (§chatpos == 0) {
  SETNAME [description_troll_Burwaka]
  SET §chatpos 1
  IF (#talked2greu == 1) {
   //GOSUB START_CHAT
   BEHAVIOR FRIENDLY
   SETTARGET PLAYER
   PLAYERLOOKAT ME
   SET #SHUT_UP 1
   CINEMASCOPE -s ON
   PLAYERINTERFACE HIDE
   SET_PLAYER_CONTROLS OFF
   SPEAK -o [burwaka_introducing] GOTO CONTINUE
   ACCEPT
  }
//  GOSUB START_CHAT
  BEHAVIOR FRIENDLY
  SETTARGET PLAYER
  SPEAK [burwaka_introducing] GOTO CONTINUESTOP
  ACCEPT
 }
 IF (§chatpos == 1) {
  IF (#talked2greu == 1) {
   BEHAVIOR FRIENDLY
   SETTARGET PLAYER
//   GOSUB START_CHAT
   SET #SHUT_UP 1
   PLAYERLOOKAT ME
   CINEMASCOPE -s ON
   PLAYERINTERFACE HIDE
   SETPLAYERCONTROLS OFF
   >>CONTINUE
   SET #talked2greu 2
   SET §chatpos 2
   SPEAK -o [burwaka_explain_greu] GOTO CONTINUE2
   ACCEPT
  }
  BEHAVIOR FRIENDLY
  SETTARGET PLAYER
//  GOSUB START_CHAT
  SPEAK [Troll_greetings] GOSUB ENDTALK //GOSUB END_CHAT 
  ACCEPT
 }
 IF (#talked2greu == 2) {
   BEHAVIOR FRIENDLY
   SETTARGET PLAYER
//  GOSUB START_CHAT
  SPEAK [Troll_greetings_friend] GOSUB ENDTALK //GOSUB END_CHAT
  ACCEPT
 } 
 IF (#talked2greu == 3) {
  IF (§chatpos == 2) {
   BEHAVIOR FRIENDLY
   SETTARGET PLAYER
//   GOSUB START_CHAT
   SET #SHUT_UP 1
   CINEMASCOPE -s ON
   PLAYERINTERFACE HIDE
   SET_PLAYER_CONTROLS OFF 
   SET §chatpos 3
   SPEAK -p [player_burwaka_jobdone] GOTO TWELVE
   ACCEPT
  }
   BEHAVIOR FRIENDLY
   SETTARGET PLAYER
//  GOSUB START_CHAT
  SPEAK [burwaka_friend] GOSUB ENDTALK //GOSUB END_CHAT
  ACCEPT
 }
 ACCEPT
}
ON CUSTOM {
 IF (^$PARAM1 == "STRIKE_OVER") {
 >>STRIKE
  SET §strike 0
  ATTACH pick_axe_0014 "Attach" SELF "primary_attach" 
  SET §attached_object "pick_axe_0014"
  TELEPORT -i
  BEHAVIOR MOVE_TO
  SETTARGET MARKER_0340
  ACCEPT
 }
 IF (^$PARAM1 == "Thief") {
  IF (§strike == 0) ACCEPT
  SPEAK [Troll_thief] SENDEVENT ATTACK_PLAYER SELF ""
  ACCEPT
 }
 ACCEPT
}
ON REACHEDTARGET {
 IF (^TARGET == Marker_0340) {
  SET §work 1
  FORCEANGLE 90
  PLAYANIM -l ACTION1
  SET §frozen 1
  TIMERchange 1 8 GOTO CHANGE1
  ACCEPT
 }
 IF (^TARGET == Marker_0341) {
  SET §work 1
  FORCEANGLE 0
  PLAYANIM -l ACTION1
  SET §frozen 1
  TIMERchange 1 3 GOTO CHANGE2
  ACCEPT
 }
 IF (^TARGET == Marker_0342) {
  SET §work 1
  FORCEANGLE 270
  PLAYANIM -l ACTION1
  SET §frozen 1
  TIMERchange 1 8 GOTO CHANGE3
  ACCEPT
 }
 ACCEPT
}

>>CONTINUESTOP
BEHAVIOR FRIENDLY
SETTARGET PLAYER
SPEAK [burwaka_explain_greu] GOSUB ENDTALK //GOSUB END_CHAT
ACCEPT

>>CONTINUE2
SPEAK -p [player_burwaka_greu] GOTO CONTINUE3
ACCEPT

>>CONTINUE3
SPEAK -o [burwaka_greu_gift] GOTO CONTINUE4
ACCEPT

>>CONTINUE4
SPEAK -p [player_burwaka_sayhello] GOSUB ENDTALK GOTO ENDC
ACCEPT

>>TWELVE
SPEAK [burwaka_friend] GOSUB ENDTALK GOTO ENDC //GOSUB END_CHAT  
ACCEPT
>>CHANGE1
IF (§speaking == 1) GOTO SHORT
IF (^SPEAKING == 1) GOTO SHORT
IF (§enemy == 1) ACCEPT
IF ( §main_behavior_stacked != 0 ) {
>>SHORT
 BEHAVIOR NONE
 SETTARGET NONE
 TIMERtc 1 5 GOTO CHANGE1
 ACCEPT
}
SET §work 0
PLAYANIM NONE
SET §frozen 0
BEHAVIOR MOVE_TO
SETTARGET MARKER_0341
ACCEPT

>>CHANGE2
IF (§speaking == 1) GOTO SHORT
IF (§enemy == 1) ACCEPT
IF (^SPEAKING == 1) GOTO SHORT2
IF ( §main_behavior_stacked != 0 ) {
>>SHORT2
 BEHAVIOR NONE
 SETTARGET NONE
 TIMERtc 1 5 GOTO CHANGE2
 ACCEPT
}
SET §work 0
PLAYANIM NONE
SET §frozen 0
BEHAVIOR MOVE_TO
SETTARGET MARKER_0342
ACCEPT

>>CHANGE3
IF (^SPEAKING == 1) GOTO SHORT3
IF (§enemy == 1) ACCEPT
IF ( §main_behavior_stacked != 0 ) {
>>SHORT3
 BEHAVIOR NONE
 SETTARGET NONE
 TIMERtc 1 5 GOTO CHANGE3
 ACCEPT
}
SET §work 0
PLAYANIM NONE
SET §frozen 0
BEHAVIOR MOVE_TO
SETTARGET MARKER_0340
ACCEPT


>>ENDC
SET §speaking 0
SET #SHUT_UP 0
CINEMASCOPE -s OFF
SET_PLAYER_CONTROLS ON
PLAYERINTERFACE SHOW
ACCEPT

>>ENDTALK
 CINEMASCOPE -s OFF
 PLAYERINTERFACE SHOW
 SETPLAYERCONTROLS ON
 SET §speaking 0
 IF (§strike == 1) {
  BEHAVIOR Wander_around 200
  SETTARGET NONE
  ACCEPT
 }
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0342
 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 -----------------------------------------------------------
// ---------------------------------------------------------------------------------

//#