// Enoill Calpale in the Tavern
ON INIT {
 INVENTORY ADDMULTI "JEWELRY\\GOLD_COIN\\GOLD_COIN" 66
 INVENTORY ADD "PROVISIONS\\LOCKPICKS\\LOCKPICKS"
 SET £friend "TAVERN"
 SET §calpal_enemy 0		// Returns player has attacked Calpal
 SET #CALPALE_DEAD 0		// Indicates if Calpale is dead
 SET §need_beer 0			// Used to check if npc needs beer
 SET §drinking 0			// Used to know if npc is drinking and player cannot talk to him.
 SET §reflection_mode 0
 ACCEPT
}

ON INITEND {
 TWEAK TORSO "human_villager_chest1"
 TWEAK LEGS "human_villager_legs2"
 TWEAK SKIN "npc_human_base_hero_head" "npc_human_base_calpal_head"
 TWEAK SKIN "npc_human_villager_leg2a_chest2_a" "npc_human_clothes_c"
 LOADANIM ACTION2 "human_normal_sit_cycle"
 LOADANIM ACTION3 "human_normal_drink_cycle2"
 INVENTORY ADDMULTI "Jewelry\Gold_coin\Gold_coin" 125
 SETWEAPON DAGGER_ASSASSIN
 SENDEVENT -ir DURABILITY 100 "71"
 SET_CONTROLLED_ZONE "CALPAL_BEER"
 SET_NPC_STAT damages 18
 SET_NPC_STAT aimtime 300
 SET_NPC_STAT life 40
 SET_XP_VALUE 60
 PLAYANIM -l ACTION2
 SET §frozen 1
 PHYSICAL OFF
 ACCEPT
}

ON GAME_READY {
 LOADANIM -p ACTION1 "human_council_sit_cycle"
 ACCEPT
}

ON RELOAD {
  IF (#PLAYER_ON_QUEST > 5) {
    OBJECT_HIDE SELF OFF
    OBJECT_HIDE KEY_CALPALE_0003 OFF
    INVENTORY ADDFROMSCENE "key_calpale_0003"
    ACCEPT
  }
  IF (#PLAYER_ON_QUEST > 4) {
    OBJECT_HIDE SELF ON
    ACCEPT
  }
  IF (#PLAYER_ON_QUEST > 2) {
    IF (§chatpos == 4) ACCEPT
    IF (§chatpos != 0) ACCEPT
    SET §chatpos 3
    ACCEPT
  }
 ACCEPT
}

ON REACHEDTARGET {
  IF (^TARGET == MARKER_0197) {
    OBJECT_HIDE SELF ON
    TIMERdestroy 1 5 DESTROY ME
    ACCEPT
  }
  IF (^TARGET == MARKER_0205) {
    BEHAVIOR FRIENDLY
    SETTARGET MARKER_0558
    TIMERwc 1 10 GOTO GO_AWAY
    ACCEPT
  }
 ACCEPT
}

ON CHAT {
  SETNAME [description_enoill]
  IF (^SPEAKING == 1) ACCEPT
  IF (§calpal_enemy == 1) ACCEPT
  IF (§drinking == 1) ACCEPT
  IF (§chatpos == 0) GOTO DIALOGUE_FIRST
  IF (§chatpos == 3) GOTO DIALOGUE_FIRST_BIS
  IF (§chatpos == 1) {
    IF (#QUEEN_QUEST == 1) GOTO DIALOGUE_MURDER
    SPEAK [calpale_come_back_misc] NOP
    ACCEPT
  }
  IF (§chatpos == 4) {
    IF (#QUEEN_QUEST == 1) GOTO DIALOGUE_MURDER
    SPEAK [calpale_come_back_misc] NOP
    ACCEPT
  }  
  IF (§chatpos == 2) {
    SPEAK [calpale_pleaset_leave_misc] NOP
    ACCEPT
  }  
 ACCEPT
}

ON COMBINE {
  IF (§calpal_enemy == 1) ACCEPT
  IF (^SPEAKING == 1) {
    SPEAK -p [player_not_now] NOP
    ACCEPT
  }
  IF (^$PARAM1 == "BOOK_0026") GOTO DIALOGUE_DIARY
 ACCEPT
}

ON CONTROLLEDZONE_ENTER {
 IF (^$PARAM1 == "MUG_FULL2_0001") {
    IF (§need_beer == 0) ACCEPT
    IF (§need_beer == 2) ACCEPT
    UNSET_CONTROLLED_ZONE "CALPAL_BEER"
    SENDEVENT CUSTOM MUG_FULL2_0001 "HIDE"
    TIMERthirst OFF
    SET §need_beer 2
    OBJECT_HIDE MUG_FULL_0009 OFF
    ATTACH MUG_FULL_0009 "BEER_ATTACH" SELF "left_attach"
    SET £attached_object "MUG_FULL_0009"
    SENDEVENT CUSTOM HUMAN_BASE_0097 "DRINK"
    SET §drinking 1
    PLAY "drink"
    PLAYANIM -2e ACTION3 GOTO BEER_ON_TABLE02
    ACCEPT
  }
 ACCEPT
}
 
>>BEER_ON_TABLE02
 PLAYANIM -2 NONE
 PLAYANIM NONE
 SET §frozen 0
 SET §drinking 0
 DETACH MUG_FULL_0009 SELF
 SET £attached_object "NONE"
 DESTROY MUG_FULL_0009
 PHYSICAL ON
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0205
 SENDEVENT CUSTOM KEY_CALPALE_0001 "SHOW"
 DESTROY KEY_CALPALE_0003
 ACCEPT

ON DIE {
  SET #CALPALE_DEAD 1
  IF (§need_beer == 2) ACCEPT
  IF (#PLAYER_ON_QUEST < 4) {
    DESTROY KEY_CALPALE_0001
    DESTROY KEY_CALPALE_0003
    ACCEPT
  }
 DESTROY KEY_CALPALE_0001
 OBJECT_HIDE KEY_CALPALE_0003 OFF
 INVENTORY ADDFROMSCENE "key_calpale_0003"
 ACCEPT
}

ON OUCH {
 SET §calpal_enemy 1
 ACCEPT
}

//  First dialogue  //

>>DIALOGUE_FIRST
 SET_PLAYER_CONTROLS OFF
 PLAYER_INTERFACE -s HIDE
 CINEMASCOPE -s ON
 TELEPORT -p MARKER_0774
 TIMERlookat -m 1 10 PLAYERLOOKAT ME
 PLAYANIM -lp ACTION1
 SET #SHUT_UP 1
 SETNAME [description_enoill]
 SPEAK -c ZOOM 170 100 170 200 90 90 [calpale_greetings_player] GOTO DIALOGUE_FIRST02
 ACCEPT

>>DIALOGUE_FIRST02
 SPEAK -pc SIDE_L SELF 5 5 80 80 5 [player_calpale_well_actually] GOTO DIALOGUE_FIRST03
 ACCEPT

>>DIALOGUE_FIRST03
 SPEAK -c SIDE_R PLAYER 5 100 90 90 0 [calpale_i_cant] GOTO DIALOGUE_FIRST04
 ACCEPT

>>DIALOGUE_FIRST04
 SPEAK -pc ZOOM 180 350 180 350 150 150 [player_calpale_then_what] GOTO DIALOGUE_FIRST05
 ACCEPT

>>DIALOGUE_FIRST05
 SPEAK -c ZOOM 180 250 180 300 160 180 [calpale_ok_we] GOTO DIALOGUE_FIRST06
 ACCEPT

>>DIALOGUE_FIRST06
 SPEAK -pc SIDE_L SELF 5 5 80 80 5 [player_calpale_how_many] GOTO DIALOGUE_FIRST07
 ACCEPT

>>DIALOGUE_FIRST07
 SPEAK -c SIDE_R PLAYER 100 5 90 90 0 [calpale_i_dont_know] GOTO DIALOGUE_FIRST08
 ACCEPT

>>DIALOGUE_FIRST08
 IF (#QUEEN_QUEST == 1) GOTO DIALOGUE_MURDER01
 PLAYER_INTERFACE -s SHOW
 CINEMASCOPE -s OFF
 SET_PLAYER_CONTROLS ON
 TELEPORT -p MARKER_0515
 PLAYANIM -p WAIT
 SET #SHUT_UP 0
 SPEAK [calpale_come_back_misc] SET §chatpos 1
 ACCEPT

//  First dialogue if council //

>>DIALOGUE_FIRST_BIS
 SET_PLAYER_CONTROLS OFF
 PLAYER_INTERFACE -s HIDE
 CINEMASCOPE -s ON
 TELEPORT -p MARKER_0774
 TIMERlookat -m 1 10 PLAYERLOOKAT ME
 PLAYANIM -lp ACTION1
 SET #SHUT_UP 1
 SPEAK -c ZOOM 170 100 170 200 90 90 [calpale_greetings_player] GOTO DIALOGUE_FIRST_BIS02
 ACCEPT

>>DIALOGUE_FIRST_BIS02
 SPEAK -pc ZOOM 180 350 180 350 150 150 [player_calpale_then_what] GOTO DIALOGUE_FIRST_BIS03
 ACCEPT

>>DIALOGUE_FIRST_BIS03
 SPEAK -c ZOOM 180 250 180 300 160 180 [calpale_ok_we] GOTO DIALOGUE_FIRST_BIS04
 ACCEPT

>>DIALOGUE_FIRST_BIS04
 SPEAK -pc SIDE_L SELF 5 5 80 80 5 [player_calpale_how_many] GOTO DIALOGUE_FIRST_BIS05
 ACCEPT

>>DIALOGUE_FIRST_BIS05
 SPEAK -c SIDE_R PLAYER 100 5 90 90 0 [calpale_i_dont_know] GOTO DIALOGUE_FIRST_BIS06
 ACCEPT

>>DIALOGUE_FIRST_BIS06
 IF (#QUEEN_QUEST == 1) GOTO DIALOGUE_MURDER01
 SPEAK [calpale_come_back_misc] GOTO DIALOGUE_FIRST_BIS07
 ACCEPT

>>DIALOGUE_FIRST_BIS07
 PLAYER_INTERFACE -s SHOW
 CINEMASCOPE -s OFF
 SET_PLAYER_CONTROLS ON
 TELEPORT -p MARKER_0515
 PLAYANIM -p WAIT
 SET #SHUT_UP 0
 SET §chatpos 4
 ACCEPT

//  Player knows queen has been murdered  //

>>DIALOGUE_MURDER
 TELEPORT -p MARKER_0774
 PLAYANIM -p ACTION1
 TIMERlookat -m 1 10 PLAYERLOOKAT ME
 SET_PLAYER_CONTROLS OFF
 CINEMASCOPE -s ON
 PLAYER_INTERFACE -s HIDE
 GOTO DIALOGUE_MURDER01
 ACCEPT

>>DIALOGUE_MURDER01
 SPEAK -pc SIDE_R SELF 5 5 60 60 5 [player_calpale_about_woman] GOTO DIALOGUE_MURDER02
 ACCEPT

>>DIALOGUE_MURDER02
 SPEAK -c SIDE_L PLAYER 5 5 90 90 0 [calpale_what_do_you] GOTO DIALOGUE_MURDER03
 ACCEPT

>>DIALOGUE_MURDER03
 SPEAK -pc SIDE_R SELF 5 5 60 60 5 [player_calpale_seem_annoyed] GOTO DIALOGUE_MURDER04
 ACCEPT

>>DIALOGUE_MURDER04
 SPEAK -c SIDE_L PLAYER 5 5 90 90 0 [calpale_pleaset_leave_misc] GOTO DIALOGUE_MURDER05
 ACCEPT

>>DIALOGUE_MURDER05
 SET §chatpos 2
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 SET_PLAYER_CONTROLS ON
 TELEPORT -p MARKER_0515
 PLAYANIM -p WAIT
 GOTO DIALOGUE_MURDER06
 ACCEPT

>>DIALOGUE_MURDER06
 SET_CONTROLLED_ZONE CALPALE_BEER
 TIMERthirst -i 0 35 SPEAK [calpale_some_beer] NOP
 SPEAK [calpale_some_beer] SET §need_beer 1
 ACCEPT

//  Player shows calpale's journal  //

>>DIALOGUE_DIARY
 SPEAK -p [player_calpale_ring_bell] SPEAK [calpale_mister_detective] ADD_XP 1250
 ACCEPT

>>GO_AWAY
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0197
 ACCEPT