// Rinco in Caves

ON INIT {
 SET £friend "TWINS"
 INVENTORY ADDFROMSCENE "KEY_BASE_0064"
 SETNAME [description_shopkeeper]
 SET §weaponready 0	//returns weapon ready
 SET §enemy 0		//returns player is enemy
 ACCEPT
}

ON RELOAD {
  IF (#RINCO_DEAD > 1) {
    SENDEVENT CUSCION NOTE_0021 ""
    DESTROY SELF
    ACCEPT
  }
 ACCEPT
}

ON INITEND {
 TWEAK HEAD "human_villager_head3"
 TWEAK LEGS "human_villager_legs2"
 TWEAK TORSO "human_villager_chest2"
 SET_CONTROLLED_ZONE CUSHION
 PLAYANIM WAIT
 SETMAINEVENT MAIN_see
 INVENTORY ADDMULTI "JEWELRY\\GOLD_COIN\\GOLD_COIN" 57
 INVENTORY ADD "PROVISIONS\\BOTTLE_WINE\\BOTTLE_WINE"
 INVENTORY ADD "PROVISIONS\\LOCKPICKs\\LOCKPICKs"
 SETWEAPON DAGGER
 SENDEVENT -ir DURABILITY 100 "9"
 SENDEVENT -ir DURABILITY_ARMOR 100 "13"
 SET_NPC_STAT armor_class 12
 SET_NPC_STAT absorb 40
 SET_NPC_STAT damages 14
 SET_NPC_STAT tohit 70
 SET_NPC_STAT aimtime 1000
 SET_NPC_STAT life 60
 SET_XP_VALUE 140
 SET §cowardice 5
 SET §pain 4
 ACCEPT
}

ON MAIN_see {
 IF (§player_in_sight == 1) SENDEVENT PISIGHT NOTE_0021 "yes"
 IF (§player_in_sight == 0) SENDEVENT PISIGHT NOTE_0021 "no"
 ACCEPT
}

ON CONTROLLEDZONE_LEAVE {
  IF (§enemy == 1) ACCEPT
  IF (^$PARAM1 ISCLASS cuscion) {
    SENDEVENT CUSCION NOTE_0021 ""
    IF (§player_in_sight == 0) ACCEPT
    SPEAK [Rinco_cuscion_warning] nop
    ACCEPT
  }
  IF (^$PARAM1 == note_0021) {
>>READER
    IF (§player_in_sight == 0) ACCEPT
    UNSET_CONTROLLED_ZONE CUSHION
    SETMAINEVENT MAIN
    SENDEVENT ATTACK_PLAYER SELF "" 
    SPEAK [Rinco_note_touched] nop
    ACCEPT
  }
 ACCEPT
}
ON READ {
 GOTO READER
ACCEPT
}
ON CHAT {
  IF (§enemy == 1) ACCEPT
  IF(^speaking == 1 ) ACCEPT
  IF (§chatpos == 0) {
    GOSUB START_CHAT
    GOTO dialogue1_1
    ACCEPT
  }
  IF (§chatpos == 1) {
    GOSUB START_CHAT
    SPEAK [Rinco_busy] GOSUB END_CHAT
    TIMERpatrol 1 10 GOTO patrol1 
    ACCEPT
  }
 ACCEPT
}

ON REACHEDTARGET {
 IF (^target == MARKER_0167) {
  SETTARGET marker_0165
  ACCEPT
 }
 IF (^target == MARKER_0165) {
  BEHAVIOR FRIENDLY
  SETTARGET marker_0166
  TIMERpatrol 1 10 GOTO patrol2 
  ACCEPT
 }
 IF (^target == MARKER_0164) {
  PLAYANIM WAIT
  ACCEPT
 }
 ACCEPT
}

>>dialogue1_1
 SETNAME [description_Rinco]
 SPEAK [Rinco_welcome] GOTO dialogue1_2
 ACCEPT

>>dialogue1_2
 GOSUB END_CHAT
 SET §chatpos 1 
 ACCEPT

>>patrol1
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0167
 ACCEPT

>>patrol2
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0164
 ACCEPT

ON DIE {
 SET #RINCO_DEAD 1
 SET §dead 1
 UNSET_CONTROLLED_ZONE CUSHION
 SENDEVENT CUSCION NOTE_0021 ""
 ACCEPT
}

ON DEATH {
 IF (§dead == 1) ACCEPT
 TELEPORT MARKER_0716
 FORCEDEATH SELF
 FORCEANGLE 180
 ACCEPT
}

//#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 -----------------------------------------------------------
// ---------------------------------------------------------------------------------

//#

//#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 ------------------------------------------------------------
// ---------------------------------------------------------------------------------

//#