// Maria, the shopkeeper
ON INIT {
 INVENTORY ADDMULTI "Jewelry\Gold_coin\Gold_coin" 120
 INVENTORY ADD "JEWELRY\\SILVER_RING\\SILVER_RING"
 INVENTORY ADD_FROM_SCENE "KEY_BASE_0030"
 INVENTORY ADD_FROM_SCENE "KEY_BASE_0072"
 SET £key_carried "key_base_0030key_base_0072"
 SET £friend "kingdom"
 SET £type "human_female_base"
 SET §noshany 0			// Used to check if Shany has disapeared
 SET #FORBIDEN_SHOP2 1		// Used to check if npc is in shop
 SET §reflection_mode 0
 SET §map 0				// Used to check if marker is already on the map
 SET §refuse 0			// Used to know if npc can collide with player
 ACCEPT
}

ON INITEND {
 TWEAK SKIN "npc_human_villager_female_body" "npc_human_villager_female_body3"
 SET_CONTROLLED_ZONE MARIA_SHOP
 BEHAVIOR MOVE_TO
 SETNAME [description_shopkeeper]
 SETTARGET MARKER_0029
 ACCEPT
}

ON LOAD {
 USE_MESH "HUMAN_FEMALE_BASE\TWEAKS\human_female_villager.TEO"
 ACCEPT
}

ON RELOAD {
  IF (#PLAYER_ON_QUEST == 6) {
    SET §reflection_mode 0
    TELEPORT MARKER_0029
    BEHAVIOR FRIENDLY
    SETTARGET MARKER_0426
    SET #FORBIDEN_SHOP2 1
    SENDEVENT CUSTOM CHEST_METAL_0027 "LOCK"
    SENDEVENT CUSTOM CHEST_METAL_0026 "LOCK"
    SENDEVENT CUSTOM CHEST_METAL_0028 "LOCK"
    SENDEVENT CUSTOM CHEST_METAL_0029 "LOCK"
    SENDEVENT CUSTOM CHEST_METAL_0080 "LOCK"
    SENDEVENT CUSTOM CHEST_METAL_0031 "LOCK"
    SENDEVENT CUSTOM CHEST_METAL_0032 "LOCK"
    ACCEPT
  }
  IF (#PLAYER_ON_QUEST == 7) {
    SET §reflection_mode 1
    TELEPORT MARKER_0029
    BEHAVIOR FRIENDLY
    SETTARGET MARKER_0426
    SET #FORBIDEN_SHOP2 1
    SENDEVENT CUSTOM CHEST_METAL_0027 "UNLOCK"
    SENDEVENT CUSTOM CHEST_METAL_0026 "UNLOCK"
    SENDEVENT CUSTOM CHEST_METAL_0028 "UNLOCK"
    SENDEVENT CUSTOM CHEST_METAL_0029 "UNLOCK"
    SENDEVENT CUSTOM CHEST_METAL_0080 "UNLOCK"
    SENDEVENT CUSTOM CHEST_METAL_0031 "UNLOCK"
    SENDEVENT CUSTOM CHEST_METAL_0032 "UNLOCK"
    ACCEPT
  }
  IF (#look_for_shany == 2) {
    TELEPORT MARKER_0029
    BEHAVIOR FRIENDLY
    SETTARGET PLAYER
    SET #FORBIDEN_SHOP2 1
    SENDEVENT CUSTOM CHEST_METAL_0027 "UNLOCK"
    SENDEVENT CUSTOM CHEST_METAL_0026 "UNLOCK"
    SENDEVENT CUSTOM CHEST_METAL_0028 "UNLOCK"
    SENDEVENT CUSTOM CHEST_METAL_0029 "UNLOCK"
    SENDEVENT CUSTOM CHEST_METAL_0080 "UNLOCK"
    SENDEVENT CUSTOM CHEST_METAL_0031 "UNLOCK"
    SENDEVENT CUSTOM CHEST_METAL_0032 "UNLOCK"
    SENDEVENT CUSTOM LIGHT_DOOR_0019 "UNLOCK"
    ACCEPT
  }
  IF (#carlo_rituals == 1) {
    IF (§noshany == 1) ACCEPT
    SET §noshany 1
    TELEPORT MARKER_0332
    BEHAVIOR FRIENDLY
    SETTARGET MARKER_0466
    SET §chatpos 2
    SET §refuse 1
    SET #FORBIDEN_SHOP2 0
    SENDEVENT CUSTOM LIGHT_DOOR_0019 "LOCK"
    ACCEPT
  }
 ACCEPT
}

ON AGGRESSION {
 SENDEVENT PLAYER_ENEMY HUMAN_BASE_0114 ""
 ACCEPT
}

ON PLAYER_IN_SHOP {
 IF (§player_in_sight == 0) ACCEPT
 IF (^PLAYER_ZONE != "FORBIDEN_SHOP2") ACCEPT
 SPEAK -a ~£thief~ NOP
 SENDEVENT ATTACK_PLAYER SELF ""
 ACCEPT
}

ON REACHEDTARGET {
  IF (^TARGET == MARKER_0029) {
    BEHAVIOR FRIENDLY
    SETTARGET PLAYER
    ACCEPT
  }
 ACCEPT
}

ON DIE {
 SENDEVENT CUSTOM CHEST_METAL_0026 "DEAD"
 SENDEVENT CUSTOM CHEST_METAL_0027 "DEAD"
 SENDEVENT CUSTOM CHEST_METAL_0028 "DEAD"
 SENDEVENT CUSTOM CHEST_METAL_0029 "DEAD"
 SENDEVENT CUSTOM CHEST_METAL_0080 "DEAD"
 SENDEVENT CUSTOM CHEST_METAL_0031 "DEAD"
 SENDEVENT CUSTOM CHEST_METAL_0032 "DEAD"
 ACCEPT
}

ON CUSTOM {
  IF (^$PARAM1 == "SHANY_BACK") {
    GOSUB START_CHAT
    SPEAK -oh [maria_oh_shany] GOTO END
    ACCEPT
  }
 ACCEPT
}

>>__D
 GOSUB END_CHAT
 SENDEVENT CUSTOM CAMERA_0094 "END"  
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 SET_PLAYER_CONTROLS ON
 SET §chatpos 1
 SET #look_for_shany 3
 ADD_XP 2500
 INVENTORY PLAYERADD "MAGIC\\POTION_LIFE\\POTION_LIFE"
 INVENTORY PLAYERADD "MAGIC\\POTION_MANA\\POTION_MANA" 
 HEROSAY [system_object_received]
 PLAY "system"
 HEROSAY [system_questbook_updated]
 QUEST [system_Quest_log_shanny_done]
 ACCEPT

ON CHAT {
  IF (^SPEAKING == 1) ACCEPT
  IF (§map == 0) {
    SET §map 1
    MAPMARKER 404 390 1 [description_maria]
  }
 PLAYANIM NONE
 IF (§chatpos == 1) GOTO DIALOGUE2_1
 IF (§chatpos == 2) GOTO DIALOGUE3_1
 IF (§chatpos == 3) GOTO DIALOGUE4_1
 GOTO DIALOGUE1_1
 ACCEPT
}

ON COLLIDE_NPC {
 IF (§refuse == 1) REFUSE
 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 -----------------------------------------------------------
// ---------------------------------------------------------------------------------

//#

////////////////////////////////
// First time in Maria's shop //
////////////////////////////////

>>DIALOGUE1_1
 GOSUB START_CHAT
 SET §chatpos 1
 SETNAME [description_maria]
 SPEAK [maria_name_maria] GOSUB END_CHAT
 ACCEPT

/////////////////////////////////////////////////////////
// Second time in Maria's shop and Carlo haven't spoke //
/////////////////////////////////////////////////////////

>>DIALOGUE2_1
 GOSUB START_CHAT
 SPEAK [female_shop_offer] GOSUB END_CHAT
 ACCEPT

/////////////////////////////////////////
// Carlo told the player about rituals //
/////////////////////////////////////////

>>DIALOGUE3_1
 GOSUB START_CHAT
 TELEPORT -p MARKER_0466
 SET_PLAYER_CONTROLS OFF
 CINEMASCOPE -s ON
 PLAYER_INTERFACE -s HIDE
 TIMERlookat -m 1 10 PLAYERLOOKAT SELF
 SPEAK -c ZOOM 180 170 180 220 150 150 [maria_sorry_not_sale] GOTO DIALOGUE3_2
 ACCEPT

>>DIALOGUE3_2
 SPEAK -pc ZOOM 180 180 180 180 150 150 [player_want_healer] GOTO DIALOGUE3_3
 ACCEPT

>>DIALOGUE3_3
 SPEAK -c ZOOM 180 80 180 120 130 130 [maria_not_ill] GOTO DIALOGUE3_4
 ACCEPT

>>DIALOGUE3_4
 SPEAK -pc ZOOM 180 180 180 180 150 150 [player_vanished] GOTO DIALOGUE3_5
 ACCEPT

>>DIALOGUE3_5
 SPEAK -c ZOOM 180 120 180 120 80 200 [maria_was_playing] GOTO DIALOGUE3_6
 ACCEPT

>>DIALOGUE3_6
 SPEAK -pc ZOOM 180 180 180 180 150 150 [player_figure_out] GOTO DIALOGUE3_7
 ACCEPT

>>DIALOGUE3_7
 SPEAK -c ZOOM 180 90 180 90 100 100 [maria_sent_by_god] GOTO DIALOGUE3_8
 ACCEPT

>>DIALOGUE3_8
 SET #FORBIDEN_SHOP2 1
 SENDEVENT CUSTOM LIGHT_DOOR_0019 "UNLOCK"
 SENDEVENT CUSTOM LIGHT_DOOR_0021 "UNLOCK"
 QUEST [system_Quest_log_shanny]
 PLAY "system"
 HEROSAY [system_questbook_updated]
 SET §chatpos 3
 SET #look_for_shany 1
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 SET_PLAYER_CONTROLS ON
 GOSUB END_CHAT
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0029
 SET §refuse 0
 ACCEPT

////////////////////////////////
// Player doesn't found Shany //
////////////////////////////////

>>DIALOGUE4_1
 GOSUB START_CHAT
 SPEAK [maria_did_find_shany_misc] GOSUB END_CHAT
 ACCEPT

//////////////////////////////////////////
// Player has found Shany - cinematic - //
//////////////////////////////////////////

>>DIALOGUE5_1
 GOSUB START_CHAT
 SET §chatpos 1
 SENDEVENT CUSTOM CHEST_METAL_0027 "UNLOCK"
 SENDEVENT CUSTOM CHEST_METAL_0026 "UNLOCK"
 SENDEVENT CUSTOM CHEST_METAL_0028 "UNLOCK"
 SENDEVENT CUSTOM CHEST_METAL_0029 "UNLOCK"
 SENDEVENT CUSTOM CHEST_METAL_0080 "UNLOCK"
 SENDEVENT CUSTOM CHEST_METAL_0031 "UNLOCK"
 SENDEVENT CUSTOM CHEST_METAL_0032 "UNLOCK"
 SET #look_for_shany 0
 SPEAK [maria_oh_shany] GOSUB END_CHAT 
 ACCEPT

>>END
 GOSUB END_CHAT
 SENDEVENT CUSTOM CAMERA_0094 "END"  
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 SET_PLAYER_CONTROLS ON
 SET §chatpos 1
 SET #look_for_shany 3
 ADD_XP 2500
 INVENTORY PLAYERADD "MAGIC\\POTION_LIFE\\POTION_LIFE"
 INVENTORY PLAYERADD "MAGIC\\POTION_MANA\\POTION_MANA" 
 PLAY "system"
 HEROSAY [system_questbook_updated]
 QUEST [system_Quest_log_shanny_done]
 HEROSAY [system_object_received]
 HEROSAY [description_lifepotion]
 HEROSAY [description_blu_potion]
 ACCEPT