// Anuk, the cook

ON COLLIDE_NPC {
 IF (§enemy == 0) {
  IF (§nocol == 1) REFUSE
  ACCEPT
 }
 ACCEPT
}

ON INIT {
 INVENTORY ADD "JEWELRY\\BRACELET\\BRACELET"
 SET §nocol 0
 SET §on_cook 0
 SET §wine_in_pasta 0
 SET §poison_in_pasta 0
 SET §king_ill 0
 SET §reflection_mode 1
 SET §return 0
 SET §state 0
 SET £friend "goblin_castle"
 SET £key_carried "Portcullis"
 SET £init_marker "MARKER_0084"
 ACCEPT
}
ON INITEND {
 SET £misc [anuk_lala]
 TWEAK HEAD "goblin_nohelm"
 TWEAK SKIN "npc_goblin_nohelm_head" "npc_goblin_atok"
 TWEAK SKIN "npc_Goblin_base_body" "npc_Goblin_cook"
 SETWEAPON NONE
 LOADANIM ACTION2 "Goblin_misc_work_cake"
 LOADANIM ACTION3 "Goblin_misc_carry_plateau"
 LOADANIM ACTION4 "Goblin_normal_scavenge"
 LOADANIM ACTION5 "human_work_herbalist"
 OBJECT_HIDE PLATE_CLEAN_0004 OFF
 ATTACH plate_clean_0004 "Action Point" SELF "primary_attach"
 SET £attached_object "plate_clean_0004"
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0084
 INVENTORY ADD "PROVISIONS\\BREAD_HALF\\BREAD_HALF"
// INVENTORY ADD "PROVISIONS\\BOTTLE_WINE\\BOTTLE_WINE"
 SET £flee_marker "FLEE_MARKER_0039"
 SET £helping_buddy "GOBLIN_BASE_0035"
 SENDEVENT -ir DURABILITY 100 "34"
 SET §recipe 0
 ACCEPT
}

ON RELOAD {
 GOTO DECISION
 ACCEPT
}

ON COMBINE {
 IF (^$PARAM1 == "BOOK_0048") {
  IF (§recipe == 1) ACCEPT
  INVENTORY ADDFROMSCENE "BOOK_0048"
  GOTO RECIPE
  ACCEPT
 } 
 IF (^$PARAM1 == "BOOK_0010") { 
  IF (§recipe == 1) ACCEPT
  INVENTORY ADDFROMSCENE "BOOK_0010"
>>RECIPE
  SET §recipe 1
  SENDEVENT TADA PLAYER ""
  ADD_XP 1000
  SPEAK [anuk_new_recipes] NOP
  IF (§king_ill > 0) {
   IF (^SPEAKING == 1) ACCEPT
   SPEAK [anuk_poor_king] NOP
   ACCEPT
  }
  ACCEPT
 }
 ACCEPT
}

ON REACHEDTARGET {
 IF (^TARGET == "NONE") ACCEPT
 //IF (^TARGET == MARKER_0286) {
 // IF (§return == 1) SETTARGET -a Marker_0084 ACCEPT
 // BEHAVIOR MOVE_TO
 // SETTARGET -a MARKER_0288
 // ACCEPT
 //}
 //IF (^TARGET == MARKER_0288) {
 //IF (§return == 1) SETTARGET -a Marker_0084 ACCEPT
 // SETTARGET -a MARKER_0268
 // ACCEPT
 //}
 IF (^TARGET == MARKER_0268) {
    SETTARGET -a MARKER_0084  
    SETEVENT CHAT OFF 
 //IF (§return == 1) SETTARGET -a Marker_0288 ACCEPT
 // SET §reflection_mode 0
 // SETTARGET -a MARKER_0285
  ACCEPT
 }
 IF (^TARGET == MARKER_0285) { 
  IF (§return == 1) SETTARGET -a Marker_0268 ACCEPT
  SET §reflection_mode 0
  SETTARGET -a MARKER_0090
  ACCEPT
 }
 IF (^TARGET == MARKER_0084) {
  SETEVENT CHAT ON
  IF (§king_ill == 1) {
   SET §chatpos 2
   SET §nocol 0
   SET §care_about_mice 1
   SET §state 1
   SET §king_ill 2
   PLAYANIM -2 NONE
   SET §frozen 0
   DETACH ~£attached_object~ SELF
   BEHAVIOR FRIENDLY
//   SETTARGET FLOUR_BIG_0001
   SETTARGET NONE
   SET §frozen 1
   FORCEANGLE 0
   PLAYANIM -e ACTION2 GOTO DECISION
   ACCEPT
  }
  IF (§king_ill == 2) {
   SET §state 1
   BEHAVIOR FRIENDLY
   SETTARGET FLOUR_BIG_0001
   SET §frozen 1
   FORCEANGLE 0
   PLAYANIM -e ACTION2 GOTO DECISION
   ACCEPT
  }    
  SET §nocol 1
  SET §reflection_mode 0
  SET §on_cook 1
  SET §return 0
  OBJECT_HIDE PLATE_CLEAN_0003 OFF
  DETACH plate_clean_0004 SELF
  SET £attached_object "NONE"
  OBJECT_HIDE PLATE_CLEAN_0004 YES
  PLAYANIM -2 NONE
  SET §frozen 1
  BEHAVIOR FRIENDLY
  SETTARGET NONE
  FORCEANGLE 0
  //SETTARGET -a FLOUR_BIG_0001
  PLAYANIM -e ACTION2 BEHAVIOR MOVE_TO SETTARGET -a MARKER_0085
  ACCEPT
 }
 IF (^TARGET == MARKER_0085) {
  BEHAVIOR FRIENDLY
  SETTARGET NONE
  FORCEANGLE 0
  //SETTARGET -a FLOUR_BIG_0001
  IF (#SHUT_UP != 1) {
   IF (§wine_in_pasta == 1) SPEAK [anuk_pasta_funny] NOP
   IF (§poison_in_pasta == 1) SPEAK [anuk_new_pasta] NOP
   IF (§wine_in_pasta == 0) {
    IF (§poison_in_pasta == 0) {
     SPEAK [anuk_lala] NOP
    }
   }
  }
  OBJECT_HIDE PLATE_CLEAN_0003 YES
  OBJECT_HIDE PLATE_GOBLIN_CAKES_RARE_0001 OFF
  PLAYANIM -e ACTION2 GOTO SUITE
  ACCEPT
 }
 IF (^TARGET == MARKER_0086) {
  SETTARGET -a MARKER_0118
  ACCEPT
 }
 IF (^TARGET == MARKER_0118) {
  IF (§king_ill == 3) {
   BEHAVIOR FRIENDLY
   SETTARGET MARKER_0667
   TIMERfico 1 2 SPELLCAST -SMF 1 IGNIT MARKER_0667 SENDEVENT CUSTOM MARKER_0667 "FIRE" 
   SET §king_ill 2
   TIMERmisc_reflection  -i 0 10 SENDEVENT MISC_REFLECTION SELF ""
   TIMERgodec 1 4 GOTO DECISION
   ACCEPT
  }
  IF (§king_ill == 2) {
   TIMERwait 1 5 GOTO DECISION
   ACCEPT
  }
  BEHAVIOR FRIENDLY
  SETTARGET -a PLATE_GOBLIN_CAKES_RARE_0003
  PLAYANIM -2 NONE
  SET §frozen 0
  SPELLCAST -SMF 1 IGNIT MARKER_0667 
  SENDEVENT CUSTOM MARKER_0667 "FIRE" 
  TIMERredo -m 1 1500 SPELLCAST -SMF 1 IGNIT MARKER_0667 SENDEVENT CUSTOM MARKER_0667 "FIRE"
  OBJECT_HIDE PLATE_GOBLIN_CAKES_RARE_0003 OFF
  DETACH plate_goblin_cakes_rare_0001 SELF
  SET £attached_object "NONE"
  OBJECT_HIDE PLATE_GOBLIN_CAKES_RARE_0001 YES
  PLAY Cooking
  SET §nocol 1
  TIMERcook 1 5 GOTO SUITE3
  ACCEPT
 }
 IF (^TARGET == MARKER_0090) {
  IF (§king_ill == 1) {
   BEHAVIOR MOVE_TO
   SETTARGET MARKER_0285
   SETMOVEMODE WALK
   ACCEPT
  } 
  SET §nocol 1
  SET §return 1
  BEHAVIOR FRIENDLY
  SETTARGET -a Goblin_base_0042
  DETACH plate_goblin_cakes_cooked_0002 SELF
  SET £attached_object "NONE"
  OBJECT_HIDE plate_goblin_cakes_cooked_0002 YES
  ATTACH plate_clean_0004 "Action Point" SELF "primary_attach"
  SET £attached_object "plate_clean_0004"
  IF (§wine_in_pasta == 2) {
   IF (#SHUT_UP == 0) SPEAK [Anuk_cook_give_cakes] SENDEVENT CUSTOM Goblin_base_0042 "EAT_THIS_FUCKER"
   IF (#SHUT_UP == 1) SENDEVENT CUSTOM Goblin_base_0042 "EAT_THIS_FUCKER"
   ACCEPT
  } 
  IF (#SHUT_UP == 0) SPEAK [Anuk_cook_give_cakes] SENDEVENT CUSTOM Goblin_base_0042 "EAT_THIS"
  IF (#SHUT_UP == 1) SENDEVENT CUSTOM Goblin_base_0042 "EAT_THIS"
  ACCEPT
 }
 IF (^TARGET == "Marker_0474") {
  SET §state 2
  BEHAVIOR FRIENDLY
  SETTARGET MARKER_0475
  SET §frozen 1
  PLAYANIM -e ACTION5 GOTO DECISION
  ACCEPT
 }
 IF (^TARGET == "MARKER_0917") {
  SET §state 3
  TIMERwait 1 3 GOTO NEXT
  ACCEPT
 }
 IF (^TARGET == "Marker_0476") {
  SET §state 4
  SET §frozen 1
  PLAYANIM -e ACTION4 GOTO DECISION
  ACCEPT
 }
 IF (^TARGET == "Marker_0477") {
  GOTO WANDER
  ACCEPT
 }
 ACCEPT
}

ON CHAT {
  IF (#troll_quest > 1) SET §chatpos 1
  IF (^SPEAKING == 1) ACCEPT
  IF (§chatpos == 1) ACCEPT
  IF (§chatpos == 0) {
   SETNAME [description_anuk]
   IF (§on_cook == 1) {
    SET §chatpos 1
    SPEAK [anuk_job] NOP
    ACCEPT
   }
//   GOSUB START_CHAT
   SET §chatpos 1
   SPEAK [anuk_job] GOSUB END_CHAT
   ACCEPT
  }
  IF (§chatpos == 2) {
   GOSUB START_CHAT
   SPEAK [anuk_poor_king] NOP//GOSUB END_CHAT
   SET §chatpos 3
   ACCEPT
  }
 ACCEPT
 }

ON _USTOM {
  IF (^$PARAM1 == "BRING_MORE" ) {
    SETEVENT CHAT ON
    SET §reflection_mode 1
    BEHAVIOR MOVE_TO
    SETTARGET -a MARKER_0285
    SET §nocol 0
    SETMOVEMODE WALK
    ACCEPT
  }
  IF (^$PARAM1 == "WINE" ) {
    SET §wine_in_pasta 1
    ACCEPT
  }
  IF (^$PARAM1 == "POISON" ) {
    SET £poison_pasta ^$PARAM1
    SET §poison_in_pasta 1
    ACCEPT
  }
  IF (^$PARAM1 == "GO_KITCHEN" ) {
   SET §king_ill 1
   SET §nocol 0
   SETEVENT CHAT ON
   SET §reflection_mode 1
   BEHAVIOR MOVE_TO
   SETTARGET -a MARKER_0285
   ACCEPT
  }
 IF (^$PARAM1 == "KING_ILL2") {
  SET §king_ill 1
  SET §return 1
  ACCEPT
 }
 IF (^$PARAM1 == "LIGHT_FIRE") {
  IF (§king_ill != 2) ACCEPT
  IF (§enemy == 1) ACCEPT
  SET §king_ill 3
  TIMER KILL_LOCAL 
  BEHAVIOR MOVE_TO
  SETTARGET MARKER_0118
  ACCEPT
 }
 ACCEPT
}

>>_UITE
 IF (§wine_in_pasta == 1) {
  SET §wine_in_pasta 2
 // IF (^SPEAKING != 1) {
 //  IF (#SHUT_UP != 1) SPEAK [anuk_pasta_funny] NOP
 // }
 }
 IF (§poison_in_pasta == 1) {
  SET §poison_in_pasta 0
  //IF (#shut_up !=1) SPEAK [anuk_new_pasta] SENDEVENT -r CUSTOM 200 "REPLACE_PASTA"
  //IF (#shut_up == 1)
  SENDEVENT -r CUSTOM 500 "REPLACE_PASTA"
  PLAYANIM ACTION2
 }
 //TIMERtest 1 4
 GOTO SUITE2 
 ACCEPT

>>SUITE2
SET §reflection_mode 1
ATTACH plate_goblin_cakes_rare_0001 "Action Point" SELF "Primary_attach"
SET £attached_object "plate_goblin_cakes_rare_0001"
OBJECT_HIDE PLATE_GOBLIN_CAKES_RARE_0001 YES
PLAYANIM -L2 ACTION3
SET §on_cook 0
SET §frozen 1
BEHAVIOR MOVE_TO
SETTARGET -a MARKER_0118
SET §nocol 0
ACCEPT

>>SUITE3
IF (§enemy == 1) ACCEPT
OBJECT_HIDE PLATE_GOBLIN_CAKES_COOKED_0002 OFF
OBJECT_HIDE PLATE_GOBLIN_CAKES_RARE_0003 YES
TIMERbringtoking 1 2 GOTO SUITE4
ACCEPT

>>SUITE4
//attach cakes cooked
ATTACH plate_goblin_cakes_cooked_0002 "Action Point" SELF "Primary_attach"
SET £attached_object "plate_goblin_cakes_cooked_0002"
OBJECT_HIDE PLATE_GOBLIN_CAKES_COOKED_0002 YES
PLAYANIM -L2 ACTION3
SET §frozen 1
BEHAVIOR MOVE_TO
//SETTARGET -a MARKER_0286
SETTARGET -a MARKER_0285
SET §nocol 0
ACCEPT

>>NEXT
IF ( §main_behavior_stacked != 0 ) {
 BEHAVIOR NONE
 SETTARGET NONE
 TIMERagain 1 5 GOTO NEXT
 ACCEPT
}
GOTO DECISION
ACCEPT



>>DECISION
SET §frozen 0
IF ( §main_behavior_stacked != 0 ) {
 BEHAVIOR NONE
 SETTARGET NONE
 TIMERdec 1 5 GOTO DECISION
 ACCEPT
}
RANDOM 20 {
 IF (§state == 2) GOTO DECISION
 BEHAVIOR MOVE_TO 
 SETTARGET Marker_0474
 ACCEPT
}  
RANDOM 20 {
 IF (§state == 3) GOTO DECISION
 BEHAVIOR MOVE_TO 
 SETTARGET MARKER_0917
 ACCEPT
}  
RANDOM 20 {
 IF (§state == 4) GOTO DECISION
 BEHAVIOR MOVE_TO 
 SETTARGET Marker_0476
 ACCEPT
}  
RANDOM 20 {
 IF (§state == 1) GOTO DECISION 
 BEHAVIOR MOVE_TO 
 SETTARGET Marker_0084
 ACCEPT
}  
RANDOM 20 {
 IF (§state == 5) GOTO DECISION 
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0477
 ACCEPT
}  
GOTO DECISION
ACCEPT


>>WANDER
TIMERwanderin 1 8 GOTO NEXT
SET §state 5
BEHAVIOR WANDER_AROUND 300
SETTARGET PLAYER
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
   SETNAME [description_anuk]
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 CUSTOM {
  IF (^$PARAM1 == "BRING_MORE" ) {
    SETEVENT CHAT ON
    SET §reflection_mode 1
    BEHAVIOR MOVE_TO
    SETTARGET -a MARKER_0285
    SET §nocol 0
    SETMOVEMODE WALK
    ACCEPT
  }
  IF (^$PARAM1 == "WINE" ) {
    SET §wine_in_pasta 1
    ACCEPT
  }
  IF (^$PARAM1 == "POISON" ) {
    SET £poison_pasta ^SENDER
    SET §poison_in_pasta 1
    ACCEPT
  }
  IF (^$PARAM1 == "GO_KITCHEN" ) {
   SET §king_ill 1
   SET §nocol 0
   SETEVENT CHAT ON
   SET §reflection_mode 1
   BEHAVIOR MOVE_TO
   SETTARGET -a MARKER_0285
   ACCEPT
  }
 IF (^$PARAM1 == "KING_ILL2") {
  SET §king_ill 1
  SET §return 1
  ACCEPT
 }
 IF (^$PARAM1 == "LIGHT_FIRE") {
  IF (§king_ill != 2) ACCEPT
  IF (§enemy == 1) ACCEPT
  SET §king_ill 3
  TIMER KILL_LOCAL 
  BEHAVIOR MOVE_TO
  SETTARGET MARKER_0118
  ACCEPT
 }
 ACCEPT
}

>>SUITE
 IF (§wine_in_pasta == 1) {
  SET §wine_in_pasta 2
 // IF (^SPEAKING != 1) {
 //  IF (#SHUT_UP != 1) SPEAK [anuk_pasta_funny] NOP
 // }
 }
 IF (§poison_in_pasta == 1) {
  SET §poison_in_pasta 0
  //IF (#shut_up !=1) SPEAK [anuk_new_pasta] SENDEVENT -r CUSTOM 200 "REPLACE_PASTA"
  //IF (#shut_up == 1)
  //SENDEVENT -r CUSTOM 500 "REPLACE_PASTA"
  SENDEVENT CUSTOM ~£poison_pasta~ "REPLACE_PASTA"
  PLAYANIM ACTION2
 }
 //TIMERtest 1 4
 GOTO SUITE2 
 ACCEPT
 