// Pog, king of the trolls
ON INIT {
 SET §nonote 1
 TWEAK SKIN "npc_trollbase_body" "npc_trollking_body"
 TWEAK SKIN "npc_trollbase_head" "npc_trollking_head"
 LOADANIM ACTION4 "Troll_note_read"
 SET §finance 0
 SET §gone 0
 SET §do 0
 ACCEPT
}
ON INITEND {
 INVENTORY ADD "JEWELRY\\GOLD_RING\\GOLD_RING"
 INVENTORY ADDMULTI "JEWELRY\\necklace\\necklace" 2
 INVENTORY ADDMULTI "JEWELRY\\GOLD_COIN\\GOLD_COIN" 61
 BEHAVIOR FRIENDLY
 SETTARGET MARKER_0511
 SET_NPC_STAT RESISTMAGIC 1
 SET_NPC_STAT RESISTPOISON 10
 SET_NPC_STAT RESISTFIRE 1
 PHYSICAL RADIUS 40
 PHYSICAL HEIGHT 200
 SET_NPC_STAT armor_class 20
 SET_NPC_STAT absorb 35 
 SET_NPC_STAT damages 25
 SET_NPC_STAT tohit 30
 SET_NPC_STAT aimtime 2000
 SET_NPC_STAT life 60
 SET_XP_VALUE 180
 ACCEPT
}

ON RELOAD {
 IF (§enemy == 1) ACCEPT
 IF (#player_on_quest == 1) {
  IF (#TROLL_QUEST == 0) {
    IF (§do == 0) {
     SET §do 1
     INVENTORY ADDFROMSCENE KEY_BASE_0042
   }
  }
 }
 IF (§gone == 1) {
  SET §gone 0
  TELEPORT MARKER_0261
  BEHAVIOR Wander_Around 200
  SETTARGET NONE
 }
 IF (§finance == 1) {
  SET §finance 2
  SET §chatpos 12
  SENDEVENT CUSTOM chest_metal_0046 "SELLING"
  SENDEVENT CUSTOM Goblin_base_0042 "SELL_END"
  SENDEVENT COUNCIL GOBLIN_BASE_0042 "" 
  INVENTORY ADDFROMSCENE "KEY_BASE_0066"
  ACCEPT
 }
 IF (#TROLLPOG_IDed == 1) SETNAME [description_troll_king]
 ACCEPT
}
ON DIE {
 IF (#troll_quest < 2) ADD_XP 500
 SENDEVENT CUSTOM chest_metal_0046 "DEAD"
 IF (#PLAYER_ON_QUEST == 0) SENDEVENT CUSTOM TROLL_BASE_0019 "POG_IS_DEAD"
 ACCEPT
}
ON PLAYER_ENEMY {
 IF (#troll_quest == 0) SENDEVENT CUSTOM TROLL_BASE_0019 "POG_IS_DEAD"
 SENDEVENT CUSTOM chest_metal_0046 "DEAD"
 SENDEVENT CUSTOM Light_door_0111 "ENEMY"
 SENDEVENT CUSTOM Troll_base_0014 "ENEMY"
 ACCEPT
} 

ON CHAT {
  IF (§enemy == 1) ACCEPT
  IF (^SPEAKING == 1) ACCEPT
  IF (§chatpos == 0) GOTO dialogue1_1
  IF (§chatpos == 1) GOTO dialogue1_2
  IF (§chatpos == 9) GOTO dialogue6_1
  IF (§chatpos == 10) GOTO dialogue7_1
  IF (§chatpos == 11) GOTO dialogue6_2
  IF (§chatpos == 12) GOTO dialogue9_1
  IF (§chatpos == 13) {
   GOSUB START_CHAT
   SPEAK [Troll_greetings] GOSUB END_CHAT
   ACCEPT
  }
  IF (§chatpos == 6) {
   GOSUB START_CHAT
   SPEAK [Pog_giveme_idol] GOSUB END_CHAT
   ACCEPT
  } 
  IF (§chatpos == 14) {
   GOSUB START_CHAT
   SPEAK [Pog_friend] GOSUB END_CHAT
   ACCEPT
  }
  ACCEPT
}

ON _OMBINE {
  IF (§enemy == 1) ACCEPT
  IF (^SPEAKING == 1) {
   SPEAK -p [player_not_now] NOP 
   ACCEPT
  }
  IF (^$PARAM1 ISCLASS "TROLL_IDOL" ) {
   >>IDOL
    SETNAME [description_troll_king]
    INVENTORY ADDFROMSCENE "TROLL_IDOL_0005"
    SET #troll_quest 2
    SENDEVENT CUSTOM Light_door_0111 "unlock"
    SENDEVENT CUSTOM Pick_axe_0012 "STRIKE_OVER"
    SENDEVENT CUSTOM Pick_axe_0013 "STRIKE_OVER"
    SENDEVENT CUSTOM Pick_axe_0014 "STRIKE_OVER"
    SENDEVENT CUSTOM Light_door_0111 "STOP"
    SENDEVENT CUSTOM Troll_base_0001 "STRIKE_OVER"
    SENDEVENT CUSTOM Troll_base_0006 "STRIKE_OVER"
    SENDEVENT CUSTOM Troll_base_0007 "STRIKE_OVER"
    SENDEVENT CUSTOM MARKER_0012 "CONTROL"
    SENDEVENT CUSTOM MARKER_0395 "CONTROL"
    GOTO dialogue5_1
    ACCEPT
  }
  IF (^$PARAM1 == "NOTE_0015" ) GOTO FAKE 
  IF (^$PARAM1 == "NOTE_0020" ) {
   >>FAKE
   IF (#troll_quest > 1) GOTO SHORTCUT2
   SET §nonote 0
   SET £attached_object "Note2_0003"
   ATTACH Note2_0003 "Action Point" SELF "primary_attach"
   INVENTORY ADDFROMSCENE "NOTE_0020"
   GOTO dialogue2_1
   ACCEPT
  }
  IF (^$PARAM1 == "BOOK_0046") {
   IF (§finance > 0) ACCEPT
   SET §finance 1
   INVENTORY ADDFROMSCENE BOOK_0046
   GOTO FINANCE
   ACCEPT
  }
  IF (^$PARAM1 == "BOOK_0007" ) {
    IF (§finance > 0) ACCEPT
    INVENTORY ADDFROMSCENE BOOK_0007
    //SENDEVENT CUSTOM ^$PARAM1 "DESTROY"
    >>FINANCE
    SENDEVENT CUSTOM Goblin_base_0042 "SELL_END"
    SET §finance 1
    SET #FINANCE 1
    SET §chatpos 14
    //SET #goblin_enemy 1
    GOTO dialogue8_1
    ACCEPT
  }
 ACCEPT
 }

ON ALOTAR_IS_DEAD {
 IF (§finance == 1) ACCEPT
  SET §alotar_dead 1
  IF (#troll_quest > 1) SET §chatpos 10
  ACCEPT
 }

ON CUSTOM {
  IF (^$PARAM1 == "ALOTAR_IS_DEAD") {
   IF (§finance == 1) ACCEPT
   SET §alotar_dead 1
   SET §chatpos 10
   ACCEPT
  }
  IF (^$PARAM1 == "Teleport") {
 //  TELEPORT Marker_0261
 //  BEHAVIOR Wander_Around 200
 //  SETTARGET NONE
   ACCEPT
  }
 ACCEPT
}


////////////

>>ISPLAYERNICE
  IF (§alotar_dead == 1) {
    GOSUB END_CHAT
    ADD_XP 500
    PLAY system_MissionComplete
    IF (§nonote == 1) {
     SET §chatpos 10
     GOTO AD
     //GOTO ENDC
     ACCEPT
    }
    QUEST [system_Quest_log_troll_idol_done]
    HEROSAY [system_questbook_updated]
    SET §chatpos 10
    SET §gone 1
    GOTO AD
    //GOTO ENDC
    ACCEPT
  }
 GOSUB END_CHAT
 ADDXP 500
 SET §chatpos 9
 SET #TROLLHERO 1
 //ENDQUEST [system_Quest_log_fallen_rocks]
 //ENDQUEST [system_Quest_log_troll_idol]
 IF (§nonote == 1) {
  SET §chatpos 9
  GOTO ENDC
  ACCEPT
 }
 QUEST [system_Quest_log_troll_idol_done]
 HEROSAY [system_questbook_updated]
 PLAY system_MissionComplete
 SET §gone 1
 GOTO ENDC
 ACCEPT

////////////

>>dialogue1_1
 SET #SHUT_UP 1
 SETNAME [description_troll_king]
 GOSUB START_CHAT 
 PLAYERLOOKAT ME
 CINEMASCOPE -s ON 
 SET_PLAYER_CONTROLS OFF
 PLAYERINTERFACE HIDE
 SPEAK -op [player_to_Pog01] GOTO dialogue1_2
 ACCEPT

>>dialogue1_2
 SPEAK -o [Pog_asknote] GOSUB END_CHAT SET §chatpos 1 GOTO ENDC 
 ACCEPT

////////////

>>dialogue2_1
 SET #SHUT_UP 1
 SETNAME [description_troll_king] //In cas the player show the note without talking first
 TELEPORT -p MARKER_0511
 GOSUB START_CHAT
 TIMERlookat -m 1 10 PLAYERLOOKAT ME
 PLAYANIM ACTION4 
 //TIMERdetach 1 2 DETACH Note2_0002 SELF
 CINEMASCOPE -s ON
 SET_PLAYER_CONTROLS OFF
 PLAYERINTERFACE HIDE
 SPEAK -co ZOOM 150 80 150 90 150 120 [pog_readnote] GOTO dialogue3_1
 ACCEPT

////////////

>>dialogue3_1
 DETACH ~£attached_object~ SELF
 DESTROY ~£attached_object~
 SET £attached_object "NONE"
 SPEAK -cop ZOOM 150 250 150 250 200 200 [player_to_Pog03] GOTO dialogue3_2
 ACCEPT

>>dialogue3_2
 SENDEVENT CUSTOM Troll_base_0004 "Teleport"
 SENDEVENT CUSTOM Greu_art1_0003 "Appear"
 SET #troll_quest 1
 SPEAK -co ZOOM 150 80 150 250 150 150 [Pog_briefing] GOTO dialogue4_1
 ACCEPT

////////////

>>dialogue4_1
 SPEAK -cop ZOOM 150 80 150 80 100 100  [player_to_Pog04] GOTO dialogue4_2
 ACCEPT

>>dialogue4_2
 SPEAK -aco SIDE PLAYER 0 30 200 200 0 [Pog_explain] GOTO dialogue4_3
 ACCEPT

>>dialogue4_3
 SPEAK -cop KEEP [player_to_Pog05] GOTO dialend
 ACCEPT

>>dialend
SET §chatpos 6
HEROSAY [system_questbook_updated] 
PLAY SYSTEM
QUEST [system_Quest_log_troll_idol]
GOSUB END_CHAT
SET #SHUT_UP 0
CINEMASCOPE -s OFF
PLAYERINTERFACE -s SHOW
SET_PLAYER_CONTROLS ON 
ACCEPT

////////////

>>dialogue5_1
 GOSUB START_CHAT
 SENDEVENT CUSTOM Skull_0024 "Appear"
 SENDEVENT CUSTOM Rubbish_0006 "Appear"
 SENDEVENT CUSTOM Bone_bassin_0004 "Appear"
 SENDEVENT CUSTOM Troll_base_0005 "Teleport"
 SENDEVENT CUSTOM Troll_base_0001 "Wander"
 SENDEVENT CUSTOM Goblin_base_0041 "Teleport"
 SET #SHUT_UP 1
 TELEPORT -p MARKER_0511
 TIMERlookat -m 1 10 PLAYERLOOKAT ME
 CINEMASCOPE -s ON
 SETPLAYERCONTROLS OFF
 PLAYERINTERFACE -s HIDE
 IF (§nonote == 1) {
  SPEAK [pog_thanks] GOTO ISPLAYERNICE
  ACCEPT
 }
 SPEAK -oc SIDE PLAYER 0 30 200 200 0 [pog_thanks] GOTO dialogue5_2
 ACCEPT

>>dialogue5_2
 SPEAK -cop KEEP [player_to_Pog07] GOTO dialogue5_3
 ACCEPT

>>dialogue5_3
 SENDEVENT CUSTOM TROLL_BASE_0002 "HELP_HUMANS"
 SENDEVENT CUSTOM TROLL_BASE_0003 "HELP_HUMANS"
 SPEAK -co ZOOM 30 340 30 340 100 100 [Pog_helpyou] GOTO ISPLAYERNICE
 ACCEPT

////////////

>>dialogue6_1
 GOSUB START_CHAT 
 PLAYERLOOKAT ME
 SET #SHUT_UP 1 
 CINEMASCOPE -s ON
 SET_PLAYER_CONTROLS OFF
 PLAYERINTERFACE -s HIDE
 SET §chatpos 11
 SPEAK -po [player_to_Pog08] GOTO dialogue6_2
 ACCEPT

>>dialogue6_2
 SPEAK -o [Pog_notclever] SET §chatpos 14 GOSUB END_CHAT GOTO ENDC
 ACCEPT

////////////

>>dialogue7_1
 GOSUB START_CHAT 
 PLAYERLOOKAT ME
 SET #SHUT_UP 1
 CINEMASCOPE -s ON
 SET_PLAYER_CONTROLS OFF
 PLAYERINTERFACE HIDE
>>AD
 SPEAK -o [Pog_nasty] GOTO dialogue7_2
 ACCEPT

>>dialogue7_2
 SPEAK -op [player_to_Pog09] SET §chatpos 13 GOSUB END_CHAT GOTO ENDC
 ACCEPT

////////////

>>dialogue8_1
 GOSUB START_CHAT 
 PLAYERLOOKAT ME
 SET #SHUT_UP 1
 CINEMASCOPE -s ON
 SET_PLAYER_CONTROLS OFF
 PLAYERINTERFACE HIDE
 SPEAK -o [Pog_finance] GOTO dialogue8_2
 ACCEPT

>>dialogue8_2
 SET §finance 1
 SPEAK -op [player_to_Pog10] GOTO SHOP2
 ACCEPT

>>SHOP2
GOSUB END_CHAT 
SET #SHUT_UP 0
CINEMASCOPE -s OFF
SETPLAYERCONTROLS ON
PLAYERINTERFACE -s SHOW
ADD_XP 2000
PLAY system_MissionComplete
ACCEPT

>>dialogue9_1
 GOSUB START_CHAT
 SPEAK [Pog_dealgems] GOSUB END_CHAT
 ACCEPT

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

>>SHORTCUT2
GOSUB START_CHAT
SET #SHUT_UP 1
CINEMASCOPE -s ON
SET_PLAYER_CONTROLS OFF
PLAYERINTERFACE -s HIDE
SPEAK -p [player_to_Pog07] GOTO SHORTCUT3
ACCEPT

>>SHORTCUT3
SPEAK [Pog_helpyou] GOTO HELP
ACCEPT

>>HELP
SENDEVENT CUSTOM Skull_0024 "Appear"
SENDEVENT CUSTOM Rubbish_0006 "Appear"
SENDEVENT CUSTOM Bone_bassin_0004 "Appear"
SENDEVENT CUSTOM Troll_base_0005 "Teleport"
SENDEVENT CUSTOM Troll_base_0001 "Wander"
SENDEVENT CUSTOM Goblin_base_0041 "Teleport"
SENDEVENT CUSTOM TROLL_BASE_0002 "HELP_HUMANS"
SENDEVENT CUSTOM TROLL_BASE_0003 "HELP_HUMANS"
GOSUB END_CHAT
ADD_XP 500
PLAY system_MissionComplete
QUEST [system_Quest_log_troll_idol_done]
HEROSAY [system_questbook_updated]
SET §gone 1
GOTO ENDC
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 COMBINE {
  IF (§enemy == 1) ACCEPT
  IF (^$PARAM1 ISCLASS "TROLL_IDOL" ) {
   >>IDOL
    IF (§given == 1) {
     SENDEVENT STEAL SELF ""
     ACCEPT
    }
    SET §given 1
    SETNAME [description_troll_king]
    INVENTORY ADDFROMSCENE "TROLL_IDOL_0005"
    SET #troll_quest 2
    SENDEVENT CUSTOM Light_door_0111 "unlock"
    SENDEVENT CUSTOM Pick_axe_0012 "STRIKE_OVER"
    SENDEVENT CUSTOM Pick_axe_0013 "STRIKE_OVER"
    SENDEVENT CUSTOM Pick_axe_0014 "STRIKE_OVER"
    SENDEVENT CUSTOM Light_door_0111 "STOP"
    SENDEVENT CUSTOM Troll_base_0001 "STRIKE_OVER"
    SENDEVENT CUSTOM Troll_base_0006 "STRIKE_OVER"
    SENDEVENT CUSTOM Troll_base_0007 "STRIKE_OVER"
    SENDEVENT CUSTOM MARKER_0012 "CONTROL"
    SENDEVENT CUSTOM MARKER_0395 "CONTROL"
    GOTO dialogue5_1
    ACCEPT
  }
  IF (^$PARAM1 == "NOTE_0015" ) GOTO FAKE 
  IF (^$PARAM1 == "NOTE_0020" ) {
   >>FAKE
   IF (#troll_quest > 1) GOTO SHORTCUT2
   SET §nonote 0
   SET £attached_object "Note2_0003"
   ATTACH Note2_0003 "Action Point" SELF "primary_attach"
   INVENTORY ADDFROMSCENE "NOTE_0020"
   GOTO dialogue2_1
   ACCEPT
  }
  IF (^$PARAM1 == "BOOK_0046") {
   IF (§finance > 0) ACCEPT
   SET §finance 1
   INVENTORY ADDFROMSCENE BOOK_0046
   GOTO FINANCE
   ACCEPT
  }
  IF (^$PARAM1 == "BOOK_0007" ) {
    IF (§finance > 0) ACCEPT
    INVENTORY ADDFROMSCENE BOOK_0007
    //SENDEVENT CUSTOM ^$PARAM1 "DESTROY"
    >>FINANCE
    SENDEVENT CUSTOM Goblin_base_0042 "SELL_END"
    SET §finance 1
    SET #FINANCE 1
    SET §chatpos 14
    //SET #goblin_enemy 1
    GOTO dialogue8_1
    ACCEPT
  }
 ACCEPT
 } 