// Greu, the Artist

ON INIT {
 INVENTORY ADDFROMSCENE "amulet_troll_0001"
 INVENTORY ADDFROMSCENE "flute_0002"
 INVENTORY ADDFROMSCENE "mud_putty_0001"
 INVENTORY ADD "PROVISIONS\\FOOD_FISH_COOKED\\FOOD_FISH_COOKED"
 INVENTORY ADD "PROVISIONS\\FOOD_FISH\\FOOD_FISH"
 INVENTORY ADD "PROVISIONS\\FOOD_FISH\\FOOD_FISH"
 SET §reflection_mode 0
 SET §first 1
 SET §gift 0				// Used to check if book has been given
 ACCEPT
}

ON INITEND {
 LOADANIM TALK_HAPPY "Troll_walk_cycle_music_toponly"
 LOADANIM ACTION2 "Troll_greu_fish"
 TWEAK SKIN "npc_trollbase_body" "npc_trollbase_body_notatoo"
 TWEAK SKIN "npc_trollbase_head" "npc_trollbase_head_greu"
 ACCEPT
}

ON RELOAD {
  IF (§enemy == 1) ACCEPT
  IF (§first == 1) {
    SET §first 0
    ACCEPT
  }
  TIMERflute OFF
  TIMERbackhome OFF
  PLAYANIM NONE
  RANDOM 40 {
    GOTO FISHING
    ACCEPT
  }
  RANDOM 40 {
    GOTO MUSIC
    ACCEPT
  }
  TELEPORT -i
  IF (£attached_object != "NONE") {
    DETACH ~£attached_object~ SELF
    OBJECT_HIDE ~£attached_object~ YES
    SET £attached_object "NONE" 
  }
 BEHAVIOR WANDER_AROUND 200
 SETTARGET NONE
 ACCEPT
}

ON AGGRESSION {
 DETACH Pole_0014 SELF 
 SET £attached_object "NONE"
 SENDEVENT HIDE pole_0014 ""
 INVENTORY ADD "PROVISIONS\fishing_pole\fishing_pole"
 ACCEPT
}

>>FISHING
  IF (£attached_object != "NONE") {
    DETACH ~£attached_object~ SELF
    OBJECT_HIDE ~£attached_object~ YES
    SET £attached_object "NONE" 
  }
 BEHAVIOR FRIENDLY
 SETTARGET MARKER_0325
 FORCE_ANGLE 0
 TELEPORT MARKER_0325
 OBJECT_HIDE POLE_0014 OFF
 ATTACH POLE_0014 "action point" SELF "primary_attach"
 SET £attached_object "POLE_0014"
 PLAYANIM -l ACTION2
 SET §frozen 1
 ACCEPT

>>MUSIC
 SET §frozen 0
 IF (£attached_object != "NONE") {
  DETACH ~£attached_object~ SELF
  OBJECT_HIDE ~£attached_object~ YES
  SET £attached_object "NONE" 
 }
 TELEPORT MARKER_0492
 BEHAVIOR WANDER_AROUND 200
 SETTARGET NONE
 ATTACH FLUTE_0002 "attach_point" SELF "flute_attach"
 SET £attached_object "FLUTE_0002"
 TIMERflute -i 0 20 GOTO FLUTE
 TIMERbackhome -i 1 20 GOTO BACK_HOME
 ACCEPT

>>FLUTE
  IF (§main_behavior_stacked == 0) {
    SPEAK -h [flute1] NOP
  }
 ACCEPT

ON REACHEDTARGET {
  IF (^TARGET == MARKER_0493) {
    BEHAVIOR NONE
    SETTARGET NONE
    TIMERback -i 1 20 GOTO BACK_HOME02
    ACCEPT
  }
  IF (^TARGET == MARKER_0494) {
    BEHAVIOR WANDER_AROUND 200
    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 -----------------------------------------------------------
// ---------------------------------------------------------------------------------

//#

>>GIVE_MUD
 INVENTORY PLAYERADDFROMSCENE "MUD_PUTTY_0001"
 PLAY "system"
 HEROSAY [system_object_received]
 GOSUB END_CHAT
 ACCEPT

ON CHAT {
  IF (^SPEAKING == 1) ACCEPT
  IF (§enemy == 1) ACCEPT
  IF (#SEEN_BANK_KEY == 1) {
    SET #SEEN_BANK_KEY 2
    GOSUB START_CHAT
    SPEAK -p [player_greu_mauld] SPEAK [greu_mauld] GOTO GIVE_MUD
    ACCEPT
  }
  IF (§chatpos == 0) {
    GOTO DIALOGUE01
    ACCEPT
  }
  IF (§chatpos == 2) {
    GOSUB START_CHAT
    SPEAK [Greu_birthday3] GOSUB START_CHAT
    ACCEPT
  }
  IF (§chatpos == 3) {
    GOSUB START_CHAT
    SPEAK [Greu_happy] GOSUB END_CHAT
    ACCEPT
  }
 ACCEPT
}

ON COMBINE {
  IF (^SPEAKING == 1) {
    SPEAK -p [player_not_now] NOP
    ACCEPT
  }
  IF (§enemy == 1) ACCEPT
  IF (§chatpos < 2) ACCEPT
  IF (§gift == 1) ACCEPT
  IF (^$PARAM1 == "BOOKGREU_0001" ) {
    SET_PLAYER_CONTROLS OFF
    CINEMASCOPE -s ON
    PLAYER_INTERFACE -s HIDE
    INVENTORY ADDFROMSCENE "BOOKGREU_0001"
    SET §gift 1
    GOSUB START_CHAT
    SPEAK -p [player_greu_offer_gift] GOTO DIALOGUE09
    ACCEPT
  }
 GOSUB START_CHAT
 SPEAK -p [player_greu_offer_gift] SPEAK [greu_disapointed_by_gift] GOSUB END_CHAT
 ACCEPT
}

// DIALOGUES

>>DIALOGUE01
 GOSUB FREEZECONTROLS
 TIMERlookat -m 1 10 PLAYERLOOKAT ME
 GOSUB START_CHAT
 SETNAME [description_troll_Greu]
 SPEAK -o [Greu_introducing] GOTO DIALOGUE02
 ACCEPT

>>DIALOGUE02
 SPEAK -pc SIDE_R SELF 5 5 60 60 5 [player_Greu_surprised] GOTO DIALOGUE03
 ACCEPT

>>DIALOGUE03
 SPEAK -oc SIDE_L PLAYER 5 5 90 90 0 [Greu_introducing2] GOTO DIALOGUE04
 ACCEPT

>>DIALOGUE04
 SPEAK -o [Greu_birthday] GOTO DIALOGUE05
 ACCEPT

>>DIALOGUE05
 SPEAK -pc SIDE_R SELF 5 5 60 60 5 [player_Greu_friend] GOTO DIALOGUE06
 ACCEPT

>>DIALOGUE06
 SPEAK -oc SIDE_L PLAYER 5 100 90 90 0 [greu_birthday2] GOTO DIALOGUE07
 ACCEPT

>>DIALOGUE07
 SPEAK -pc SIDE_R SELF 5 5 60 60 5 [player_Greu_know_gift] GOTO DIALOGUE08
 ACCEPT

>>DIALOGUE08
 SET #talked2greu 1
 SET §chatpos 2
 QUEST [system_Quest_log_greu_gift]
 HEROSAY [system_questbook_updated]
 PLAY "system"
 GOSUB END_CHAT
 GOTO ACTIVATECONTROLS
 ACCEPT

>>DIALOGUE09
 SPEAK [greu_happy_with_gift] GOTO DIALOGUE10
 ACCEPT

>>DIALOGUE10
 SPEAK -p [player_thanks] GOTO DIALOGUE11
 ACCEPT

>>DIALOGUE11
 INVENTORY PLAYERADDFROMSCENE "amulet_troll_0001"
 HEROSAY [system_object_received]
 PLAY "system"
 ADD_XP 5000
 QUEST [system_Quest_log_greu_gift_done]
 HEROSAY [system_questbook_updated]
 SET #talked2greu 3
 SET §chatpos 3
 GOSUB END_CHAT
 GOTO ACTIVATECONTROLS
 ACCEPT

>>FREEZECONTROLS
 SET_PLAYER_CONTROLS OFF
 CINEMASCOPE -s ON
 PLAYER_INTERFACE -s HIDE
 PLAYER_LOOKAT SELF
 RETURN

>>ACTIVATECONTROLS
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 SET_PLAYER_CONTROLS ON
 ACCEPT

>>BACK_HOME
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0493
 ACCEPT

>>BACK_HOME02
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0494
 ACCEPT