// Tizzy, the bartender
ON INIT {
 INVENTORY ADDMULTI "JEWELRY\\GOLD_COIN\\GOLD_COIN" 16
 INVENTORY ADD "JEWELRY\\GOLD_RING\\GOLD_RING"
 INVENTORY ADD "JEWELRY\\necklace\\necklace"
 INVENTORY ADD "JEWELRY\\bracelet\\bracelet"
 SET £friend "TAVERN"
 SET £type "human_female_base"
 SET §needpass 0
 SET §drink_beer 0		// Returns player has drink his beer
 SET §moving 0			// If = 1 player can't order beer
 SET §thief 0			// Used to chek if player is a thief
 IF (^DEMO == 1) {
  DESTROY KEY_BASE_0008
  ACCEPT
 }
 INVENTORY ADD_FROM_SCENE "KEY_BASE_0008"
 ACCEPT
}

ON INITEND {
 TWEAK LOWER "human_female_villager"
 TWEAK HEAD "human_female_villager_head2"
 TWEAK SKIN "npc_human_villager_female_body" "npc_human_tizzy"
 LOADANIM ACTION2 "human_work_barman"
 PLAYANIM -l ACTION2
 SET §frozen 1
 SET_CONTROLLED_ZONE "BAR"
 ATTACH MUG_0018 "BEER_ATTACH" SELF "primary_attach"
 SET £attached_object "MUG_0018"
 ACCEPT
}

ON LOAD {
 USEMESH "human_female_base\human_female_base.teo"
 ACCEPT
}

ON RELOAD {
 IF (#TROLL_QUEST == 2) TIMERmove 1 40 GOTO MOVE
 GOTO BACK
 ACCEPT
}

ON REACHEDTARGET {
  IF (^TARGET == MARKER_0290) {
    BEHAVIOR MOVE_TO
    SETTARGET MARKER_0291
    ACCEPT
  }
  IF (^TARGET == MARKER_0291) {
    BEHAVIOR MOVE_TO
    SETTARGET MARKER_0205
    ACCEPT
  }
  IF (^TARGET == MARKER_0205) {
    TIMERpatrol 1 10 GOTO BACK
    ACCEPT
  }
  IF (^TARGET == MARKER_0289) {
    FORCE_ANGLE 180
    BEHAVIOR NONE
    SETTARGET NONE
    SENDEVENT CUSTOM HUMAN_BASE_0025 "TALK"
    ACCEPT
  }
  IF (^TARGET == MARKER_0287) {
    FORCE_ANGLE 180
    BEHAVIOR NONE
    SETTARGET NONE
    PLAYANIM -l ACTION2
    ATTACH MUG_0018 "BEER_ATTACH" SELF "primary_attach"
    SET £attached_object "MUG_0018"
    SET §frozen 1
    SET §moving 0
    ACCEPT
  }
 ACCEPT
}

>>BACK
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0287
 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 (^SPEAKING == 1) ACCEPT
  IF (§enemy == 1) ACCEPT
  IF (§needpass == 1) {
    SET §needpass 2
	GOTO DIALOGUE_PASSWORD
    ACCEPT
  }
 GOSUB START_CHAT
 SPEAK [tizzy_friendly_misc] GOSUB END_CHAT
 ACCEPT
}

ON DIE {
 IF (#PLAYER_ON_QUEST < 3) SET #KINGDOM_ENEMY 1
 ACCEPT
}

ON COMBINE {
  IF (§enemy == 1) ACCEPT
  IF (^SPEAKING == 1) {
    SPEAK -p [player_not_now] NOP
    ACCEPT
  }
  IF (§moving == 1) {
    GOSUB START_CHAT
    SPEAK [tizzy_player_not_now] GOSUB END_CHAT
    ACCEPT
  }
  IF (^$PARAM1 == "GOLD_COIN") {
    IF (§drink_beer == 1) {
      SPEAK [tizzy_player_drink_your_beer] NOP
      ACCEPT
    }
   IF (^PLAYER_GOLD < 2) HEROSAY [system_not_enough_gold] ACCEPT
   SENDEVENT CUSTOM MUG_FULL2_0001 "SHOW"
   ADDGOLD -2
   SET §drink_beer 1
   ACCEPT
  }
 IF (^$PARAM1 ISCLASS "mug_empty") {
  DESTROY ^$PARAM1
    ADDGOLD 20
 RANDOM 30 {
  SPEAK -p [player_here_you_go] NOP
  ACCEPT
 }
 ACCEPT
}
 ACCEPT
}

>>THIEF
 SET §enemy 1
 SENDEVENT ATTACK_PLAYER SELF ""
 ACCEPT

ON COLLIDE_NPC {
 IF (§moving == 1) REFUSE
 ACCEPT
}

>>BOUGE
 SENDEVENT CUSTOM HUMAN_BASE_0025 "TALK02"
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0287
 ACCEPT

>>SUITE
 SENDEVENT CUSTOM GOBLIN_BASE_0034 "TALK_ON"
 GOTO DIALOGUE_INTRO
 ACCEPT

>>DIALOGUE_INTRO
 GOSUB START_CHAT
 SET #SHUT_UP 1
 TELEPORT -p MARKER_0174
 TIMERlookat -m 1 10 PLAYER_LOOKAT ME
 SET_PLAYER_CONTROLS OFF
 CINEMASCOPE -s ON
 PLAYER_INTERFACE -s HIDE
 SETNAME [description_tizzy]
 SPEAK -o [tizzy_welcome] GOTO DIALOGUE_GREETINGS
 ACCEPT

>>DIALOGUE_GREETINGS
 SPEAK -p [player_tizzy_greetings1] GOTO DIALOGUE_GREETINGS2
 ACCEPT

>>DIALOGUE_GREETINGS2
 SPEAK -c ZOOM 180 90 180 180 140 140 [tizzy_greetings1] GOTO DIALOGUE_GREETINGS3
 ACCEPT

>>DIALOGUE_GREETINGS3
  IF (§needpass == 1) {
    SET §needpass 2
	GOTO DIALOGUE_PASSWORD
    ACCEPT
  }
 SPEAK -pc ZOOM 170 150 170 150 100 100 [player_tizzy_greetings2] GOTO DIALOGUE_GREETINGS4
 ACCEPT

>>DIALOGUE_GREETINGS4
 SPEAK -c ZOOM 180 150 180 150 180 180 [tizzy_greetings2] GOTO DIALOGUE_GREETINGS5
 ACCEPT

>>DIALOGUE_GREETINGS5
 GOSUB END_CHAT
 SET_PLAYER_CONTROLS ON
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 SET §chatpos 1
 TIMERmove 1 10 GOTO PATROL
 SET #SHUT_UP 0
 ACCEPT

>>DIALOGUE_PASSWORD
 GOSUB START_CHAT
 SET #SHUT_UP 1
 TELEPORT -p MARKER_0174
 TIMERlookat -m 1 10 PLAYER_LOOKAT ME
 SET_PLAYER_CONTROLS OFF
 CINEMASCOPE -s ON
 PLAYER_INTERFACE -s HIDE
 SPEAK -p [player_wantpassword] GOTO DIALOGUE_PASSWORD2
 SENDEVENT CUSTOM HUMAN_BASE_0069 "GUESSING"
 ACCEPT

>>DIALOGUE_PASSWORD2
 SPEAK -o [tizzy_password1] GOTO DIALOGUE_PASSWORD3
 ACCEPT

>>DIALOGUE_PASSWORD3
 GOSUB END_CHAT
 SET_PLAYER_CONTROLS ON
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 SET §chatpos 1
 SET #SHUT_UP 0
 ACCEPT

>>PATROL
  IF (#SHUT_UP == 1) {
    TIMERagain 1 10 GOTO PATROL
    ACCEPT
  }
 SET §moving 1
 PLAYANIM NONE
 SET §frozen 0
 PLAYANIM NONE
 DETACH MUG_0018 SELF
 SET £attached_object "NONE"
 SENDEVENT CUSTOM MUG_0018 "TELEPORT"
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0289
 ACCEPT

>>MOVE
 SET §moving 2
 PLAYANIM NONE
 SET §frozen 0
 DETACH MUG_0018 SELF
 SET £attached_object "NONE"
 SENDEVENT CUSTOM MUG_0018 "TELEPORT"
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0290
 ACCEPT

ON CUSTOM {
  IF (§enemy == 1) ACCEPT
  IF (^$PARAM1 == "THIEF") {
    IF (§moving == 2) ACCEPT
    IF (§playerin == 0) ACCEPT
    IF (§thief == 1) GOTO THIEF
    SPEAK -0 [human_female_thief] INC §thief 1
    ACCEPT
  }
  IF (^$PARAM1 == "TALK") {
    IF (#SHUT_UP == 1) {
     GOTO BOUGE
     ACCEPT
    }
    SPEAK [tizzy_misc_customer] SENDEVENT CUSTOM HUMAN_BASE_0025 "TALK01"
    ACCEPT
  }
  IF (^$PARAM1 == "TALK01") {
    IF (#SHUT_UP == 1) {
     GOTO BOUGE
     ACCEPT
    }
    SPEAK [tizzy_misc_customer] GOTO BOUGE
    ACCEPT
  }
 IF (^$PARAM1 == "PLAYER_CURIOUS_ABOUT_DOOR") SET §needpass 1
 IF (^$PARAM1 == "DRINK") {
  IF (#PLAYER_ON_QUEST > 5) SET §moving 0
  SET §drink_beer 0
  ACCEPT
 }
 ACCEPT
}

ON CONTROLLEDZONE_ENTER {
  IF (§enemy == 1) ACCEPT
  IF (^$PARAM1 == PLAYER) {
    IF (^$PARAM2 == "BAR") {
      SENDEVENT CUSTOM GOBLIN_BASE_0034 "TALK_OFF"
      UNSET_CONTROLLED_ZONE "BAR"
      SET_CONTROLLED_ZONE "TIZZY_THIEF"
      GOTO SUITE
      ACCEPT
    }
    IF (^$PARAM2 == "TIZZY_THIEF") {
      IF (§moving == 2) ACCEPT
      TIMERmove OFF
      SET §playerin 1
      GOSUB START_CHAT
      SPEAK -o [female_disturbed] GOSUB END_CHAT
      ACCEPT
    }
   ACCEPT
  }
 ACCEPT
}

ON CONTROLLEDZONE_LEAVE {
  IF (§enemy == 1) ACCEPT
  IF (^$PARAM1 == PLAYER) {
    IF (^$PARAM2 == "TIZZY_THIEF") {
      IF (§moving == 2) ACCEPT
      TIMERmove OFF
      SET §playerin 0
      ACCEPT
    }
   ACCEPT
  }
 ACCEPT
} 