// Felnor, the Alchemist

ON INIT {
 SET £friend "kingdom"
 SET £type "felnor"
 INVENTORY ADD_FROM_SCENE "note_0019"
 INVENTORY ADD_FROM_SCENE "key_base_0019"
 INVENTORY ADD_FROM_SCENE "KEY_BASE_0027"
 INVENTORY ADD_FROM_SCENE "KEY_BASE_0028"
 INVENTORY ADD_FROM_SCENE "KEY_BASE_0076"
 INVENTORY ADD_FROM_SCENE "KEY_BASE_0077"
 INVENTORY ADD "JEWELRY\\GOLD_RING\\GOLD_RING"
 INVENTORY ADD "MAGIC\\Potion2bewhite\\Potion2bewhite"
 INVENTORY ADD "MAGIC\\Ring_water_point\\Ring_water_point"
 SET £key_carried "KEY_BASE_0028key_base_0019KEY_BASE_0027KEY_BASE_0076"
 SET §reflection_mode 0
 SET §book 0   // Used to check if npc takes falan'sbook
 SET §targ 0   // Used to check cinematic position
 ACCEPT
}

ON INITEND {
 SETWEAPON Dagger_jeweld
 SETGROUP CINE1
 SETGROUP STATUE_TOUCHED  // Felnor, King and Carlo
 TWEAK HEAD "human_priest_naked_head"
 TWEAK SKIN "npc_human_priest_akbaa_body" "npc_Human_priest_felnor_body"
 TWEAK SKIN "npc_Human_priest_akbaa_head" "npc_Human_priest_felnor_head"
 LOADANIM ACTION2 "HUMAN_WORK_HERBALIST"
 BEHAVIOR FRIENDLY
 SETTARGET PLAYER
 ACCEPT
}

ON LOAD {
 USE_MESH "HUMAN_PRIEST\HUMAN_PRIEST.TEO"
 ACCEPT
}

ON RELOAD {
 IF (§book == 1) {
  INVENTORY ADD_FROM_SCENE "BOOK_0011"
  SET §book 2
  ACCEPT
 }
 ACCEPT
}

ON CHANGESTATUS {
  IF (^$PARAM1 == "2") {
    SET §frozen 0
    PLAYANIM WAIT
    TELEPORT MARKER_0310
    BEHAVIOR FRIENDLY
    SETTARGET HUMAN_BASE_0082 //king
    ACCEPT
  }
  IF (^$PARAM1 == "2end") {
    TELEPORT MARKER_0383
    BEHAVIOR MOVE_TO
    SETTARGET MARKER_0115 // dans son labo
    ACCEPT
  }
  IF (^$PARAM1 == "3") {
    SET §chatpos 3
    SETNAME [description_felnor]
    SETTARGET NONE // dans son labo
    ACCEPT
  }
  IF (^$PARAM1 == "5") {
    SET §frozen 0
    PLAYANIM WAIT
    TELEPORT MARKER_0182
    BEHAVIOR FRIENDLY
    SETTARGET HUMAN_BASE_0082 //king
    SET §chatpos 4
    ACCEPT
  }
  IF (^$PARAM1 == "7") {
    SET §frozen 0
    PLAYANIM WAIT
    SET §chatpos 5
    TELEPORT MARKER_0310
    BEHAVIOR FRIENDLY
    SETTARGET HUMAN_BASE_0082 //king
    ACCEPT
  }
 ACCEPT
}

ON CUSTOM {
  IF (^$PARAM1 == "thief") {
    IF (§player_in_sight == 0) ACCEPT
    SPEAK -o [human_male_thief] SENDEVENT ATTACK_PLAYER SELF ""
    ACCEPT
  }
  IF (^$PARAM1 == "BOOK") {
    SET §book 1
    ACCEPT
  }
  IF (^$PARAM1 == "TALK") {
    PLAYER_LOOKAT SELF
    SENDEVENT -g STATUE_TOUCHED LOOKME ""
    IF (§targ == 0) GOTO DIALOGUE1_0
    IF (§targ == 1) GOTO DIALOGUE1_1
    IF (§targ == 2) GOTO ZOHARK1
    IF (§targ == 3) GOTO DIALOGUE3_1
    ACCEPT
  }
  IF (^$PARAM1 == "STATUE_TALK") {
    SPEAK -c ZOOM 170 0 170 0 100 50 [felnor_statue_have_figured] GOTO NEXT_DIALOGUE
    ACCEPT
  }
 IF (^$PARAM1 == "TALK5") GOTO DIALOGUE4_1
 IF (^$PARAM1 == "TALK_QUAKE1") GOTO CINEMATIC_QUAKE_1
 ACCEPT
}
>>NEXT_DIALOGUE
 SETTARGET PLAYER
 SENDEVENT CUSTOM HUMAN_BASE_0082 "LOOK_PLAYER"
 SPEAK -pc SIDE SELF 0 0 50 50 0 [player_statue_why_iserbius] SENDEVENT CUSTOM HUMAN_BASE_0082 "TALK_STATUE04"
 ACCEPT
ON REACHEDTARGET {
  IF (^TARGET == MARKER_0115) {
    FORCE_ANGLE 135
    SET §frozen 1
    PLAYANIM -L ACTION2
    ACCEPT
  }
  IF (^TARGET == MARKER_0116) {
    BEHAVIOR WANDER_AROUND 300
    SETTARGET NONE
    ACCEPT
  }
 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 CHAT {
  IF (§enemy == 1) ACCEPT
  IF (^SPEAKING == 1) ACCEPT
  PLAYANIM NONE
  SET §frozen 0
  IF (§chatpos == 0) GOTO DIALOGUE_GREETINGS
  IF (§chatpos == 1) {
    IF (#PLAYER_ON_QUEST == 2) GOTO DIALOGUE2_1
    ACCEPT
  }
  IF (§chatpos == 3) {
    GOSUB START_CHAT
    SPEAK [felnor_council_noden_with_you] GOSUB END_CHAT
    ACCEPT
  }
  IF (§chatpos == 4) {
    GOSUB START_CHAT
    SPEAK [felnor_statue_now_go_save_misc] GOSUB END_CHAT
    ACCEPT
  }
  IF (§chatpos == 5) {
    IF (#superweapon == 0) { //this means the player has the weapon already
      GOSUB START_CHAT
      SPEAK [Felnor_keep_looking_weapon] GOSUB END_CHAT
      ACCEPT
    }
   GOSUB START_CHAT
   SPEAK [felnor_council_noden_with_you] GOSUB END_CHAT
   ACCEPT
  }
 GOSUB START_CHAT
 SPEAK [Felnor_laboratory_generic] GOSUB END_CHAT
 ACCEPT
}
//  dialogues  //
>>DIALOGUE_GREETINGS
 SENDEVENT CLOSE LIGHT_DOOR_0027 ""
 SETNAME [description_felnor]
 SET §chatpos 1
 TELEPORT MARKER_0383
 BEHAVIOR FRIENDLY
 SETTARGET PLAYER
 TELEPORT -p MARKER_0116
 SET_PLAYER_CONTROLS OFF
 TIMERlookat -m 1 10 PLAYERLOOKAT SELF
 CINEMASCOPE -s ON
 PLAYER_INTERFACE -s HIDE
 SPEAK -c ZOOM 180 10 170 10 130 110 [Felnor_greetings] GOTO DIALOGUE_GREETINGS_2
 ACCEPT
>>DIALOGUE_GREETINGS_2
 SPEAK -pc ZOOM 180 200 180 200 230 230 [player_felnor_falan] GOTO DIALOGUE_GREETINGS_3
 ACCEPT
>>DIALOGUE_GREETINGS_3
 SPEAK -c ZOOM 190 360 190 60 180 180 [Felnor_greetings2] GOTO DIALOGUE_GREETINGS_4
 ACCEPT
>>DIALOGUE_GREETINGS_4
 SENDEVENT CUSTOM CHEST_METAL_0078 "UNLOCK"
 SENDEVENT CUSTOM CHEST_METAL_0079 "UNLOCK"
 IF (#PLAYER_ON_QUEST == 2) GOTO DIALOGUE2_1b
 GOTO DIALOGUE_GREETINGS_5
 ACCEPT
>>DIALOGUE_GREETINGS_5
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 SET_PLAYER_CONTROLS ON 
 ACCEPT
//  Dialogue if Carlo has talked about rituals.  //
>>DIALOGUE2_1
 SENDEVENT CLOSE LIGHT_DOOR_0027 ""
 TELEPORT MARKER_0383
 BEHAVIOR FRIENDLY
 SETTARGET PLAYER
 TELEPORT -p MARKER_0116
 SET_PLAYER_CONTROLS OFF
 CINEMASCOPE -s ON
 PLAYER_INTERFACE -s HIDE
 CINEMASCOPE -s ON
 TIMERlookat -m 1 10 GOTO DIALOGUE2_1b
 ACCEPT
>>DIALOGUE2_1b
 PLAYERLOOKAT SELF
 SPEAK -pc ZOOM 180 220 180 220 100 100 [player_felnor_falan2] GOTO DIALOGUE2_2
 ACCEPT
>>DIALOGUE2_2
 SPEAK -c ZOOM 180 360 180 120 180 180 [Felnor_falan] GOTO DIALOGUE2_3
 ACCEPT
>>DIALOGUE2_3
 SET #FALAN_KEY 1
 SET §chatpos 2
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 SET_PLAYER_CONTROLS ON 
 INVENTORY PLAYERADDFROMSCENE "note_0019"
 INVENTORY PLAYERADDFROMSCENE "KEY_BASE_0076"
 HEROSAY [system_object_received]
 PLAY "system"
 MAPMARKER 237 62 1 [addmarker_falan_room]
 HEROSAY [system_map_updated]
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0115
 ACCEPT
// about finding krahoz and Zohark
>>DIALOGUE1_0
 SET §targ 1
 SENDEVENT -g STATUE_TOUCHED LOOKME ""
 SPEAK -c ZOOM 180 80 180 130 150 150 [felnor_statue_mhh] SENDEVENT CUSTOM HUMAN_BASE_0082 "TALK1"
 ACCEPT
>>DIALOGUE1_1
 SET §targ 2
 SENDEVENT -g STATUE_TOUCHED LOOKME ""
 SPEAK -c ZOOM 180 110 180 110 150 150 [felnor_statue_not_best_man] GOTO DIALOGUE1_2
 ACCEPT
>>DIALOGUE1_2
 SETTARGET PLAYER
 SENDEVENT CUSTOM HUMAN_BASE_0082 "LOOK_PLAYER"
 SPEAK -pc ZOOM 200 90 200 90 150 150 [player_statue_apreciate_explanation] GOTO DIALOGUE1_3
 ACCEPT
>>DIALOGUE1_3
 PLAYER_LOOKAT SELF
 SENDEVENT -g STATUE_TOUCHED LOOKME ""
 SETTARGET PLAYER
 SPEAK -c ZOOM 180 80 180 130 160 160 [felnor_statue_your_only_chance] GOTO DIALOGUE1_4
 ACCEPT
>>DIALOGUE1_4
 SETTARGET PLAYER
 SENDEVENT CUSTOM HUMAN_BASE_0082 "LOOK_PLAYER"
 SPEAK -pc ZOOM 200 90 200 90 150 150 [player_statue_where_the_problem] GOTO DIALOGUE1_5
 ACCEPT
>>DIALOGUE1_5
 PLAYERLOOKAT SELF
 SENDEVENT -g STATUE_TOUCHED LOOKME ""
 SETTARGET PLAYER
 SPEAK -c ZOOM 180 80 180 130 150 150 [felnor_statue_more_complicated] GOTO DIALOGUE1_6
 ACCEPT
>>DIALOGUE1_6
 SETTARGET PLAYER
 SENDEVENT CUSTOM HUMAN_BASE_0082 "LOOK_PLAYER"
 SPEAK -pc ZOOM 200 90 200 90 150 150 [player_statue_fair_enough] SENDEVENT CUSTOM HUMAN_BASE_0082 "TALK2"
 ACCEPT
>>ZOHARK1
 SENDEVENT -g STATUE_TOUCHED LOOKME ""
 SPEAK -c ZOOM 180 110 180 110 150 150 [felnor_statue_steal_krahoz] GOTO ZOHARK2
 ACCEPT
>>ZOHARK2
 SET §targ 3
 SETTARGET PLAYER  
 SENDEVENT CUSTOM HUMAN_BASE_0082 "LOOK_PLAYER"
 SPEAK -pc ZOOM 200 40 200 90 150 150 [player_statue_good_news] GOTO ZOHARK3
 ACCEPT
>>ZOHARK3
 SENDEVENT CUSTOM HUMAN_BASE_0082 "TALK3"
 BEHAVIOR WANDER_AROUND 300
 SETTARGET NONE
 ACCEPT
>>DIALOGUE3_1
 SPEAK -c ZOOM 180 80 180 130 150 150 [felnor_statue_have_figured] GOTO DIALOGUE3_2
 ACCEPT
>>DIALOGUE3_2
 SENDEVENT -g STATUE_TOUCHED LOOKME ""
 SPEAK -pc ZOOM 200 40 200 90 150 150 [player_statue_why_iserbius] GOTO DIALOGU3_3
 ACCEPT

>>DIALOGUE3_3
 BEHAVIOR WANDER_AROUND 300
 SETTARGET NONE
 SENDEVENT CUSTOM HUMAN_BASE_0082 "TALK6"
 ACCEPT
// after INVASION
>>DIALOGUE4_1
 TIMERlookatb -m 1 10 PLAYER_LOOKAT SELF
 SENDEVENT -g STATUE_TOUCHED LOOKME ""
 SPEAK -c ZOOM 180 220 180 180 180 180 [felnor_after_attack_afraid] GOTO DIALOGUE4_2
 ACCEPT
>>DIALOGUE4_2
 SPEAK -pc ZOOM 190 180 190 170 150 150 [player_after_attack_for_nothing] GOTO DIALOGUE4_3
 ACCEPT
>>DIALOGUE4_3
 PLAYER_LOOKAT SELF
 SENDEVENT -g STATUE_TOUCHED LOOKME ""
 SPEAK -c ZOOM 180 300 180 300 180 120 [felnor_after_attack_usefull] GOTO DIALOGUE4_4
 ACCEPT
>>DIALOGUE4_4
 SPEAK -pc ZOOM 190 160 190 160 150 150 [player_after_attack_stop_process] GOTO DIALOGUE4_5
 ACCEPT
>>DIALOGUE4_5
 PLAYER_LOOKAT SELF
 SENDEVENT -g STATUE_TOUCHED LOOKME ""
 SPEAK -c ZOOM 180 220 180 180 180 180 [felnor_after_attack_kill_entity] GOTO DIALOGUE4_6
 ACCEPT
>>DIALOGUE4_6
 SPEAK -pc ZOOM 190 160 190 160 150 150 [player_after_attack_where_weapon] GOTO DIALOGUE4_7
 ACCEPT
>>DIALOGUE4_7
 PLAYER_LOOKAT SELF
 SENDEVENT -g STATUE_TOUCHED LOOKME ""
 SPEAK -c ZOOM 160 300 160 300 180 120 [felnor_after_attack_not_exist] GOTO DIALOGUE4_8
 ACCEPT
>>DIALOGUE4_8
  IF (#superweapon < 2) {
    SENDEVENT CUSTOM HUMAN_BASE_0082 "TALK7"
    ACCEPT
  }
 SENDEVENT CUSTOM HUMAN_BASE_0082 "TALK8"
 ACCEPT
//*****************CINEMATICS
>>CINEMATIC_QUAKE_1
 CAMERA_ACTIVATE NONE
 SENDEVENT -g CINE1 LOOKME ""
 SPEAK -c ZOOM 170 280 170 240 130 130 [felnor_warmeet2] SENDEVENT CUSTOM human_base_0082 "TALK_QUAKE2"
 ACCEPT