// Mopak

ON INIT {
 SETNAME [description_shopkeeper]
 SET §weaponready 0
 SET §enemy 0
 SET §dead 0
 SET #shopkeeperalive 1
 SET £friend "TWINS"
 INVENTORY ADDFROMSCENE "KEY_BASE_0053"
 ACCEPT
}

ON PLAYER_ENEMY {
 GOTO NOSHOP
 ACCEPT
}

ON ATTACK_PLAYER {
 GOTO NOSHOP
 ACCEPT
}

ON INITEND {
 TWEAK HEAD "human_villager_head3"
 TWEAK LEGS "human_villager_legs1"
 TWEAK TORSO "human_villager_chest2"
 BEHAVIOR -a FRIENDLY
 SETTARGET PLAYER
 INVENTORY ADD "PROVISIONS\\TORCH\\TORCH"
 INVENTORY ADD "MAGIC\\Potion_purple\\Potion_purple"
 SETWEAPON AXE
 SENDEVENT -ir DURABILITY 100 "29"
 SENDEVENT -ir DURABILITY_ARMOR 100 "33"
 SET_NPC_STAT armor_class 18
 SET_NPC_STAT absorb 40
 SET_NPC_STAT damages 18
 SET_NPC_STAT tohit 70
 SET_NPC_STAT aimtime 1000
 SET_NPC_STAT life 80
 SET_XP_VALUE 160
 SET §cowardice 5
 SET §pain 4
 ACCEPT
}

ON RELOAD {
  IF (#RINCO_DEAD > 1) {
    SENDEVENT RINCODEAD CHEST_METAL_0099 ""
    SENDEVENT RINCODEAD CHEST_METAL_0100 ""
    DESTROY ME
    ACCEPT
  }
 ACCEPT
}

ON CHAT {
 IF (§enemy == 1) ACCEPT
 IF (^speaking == 1) ACCEPT
 IF (§chatpos == 0)GOTO dialogue1_1
 IF (§chatpos == 1) GOTO dialogue2_1
 ACCEPT
}

/////////////////////////////////////
// dialogue with player first time //
/////////////////////////////////////

>>dialogue1_1
 GOSUB START_CHAT
 SETNAME [description_mopak]
 SPEAK [mopak_introducing] GOTO dialogue1_4
 ACCEPT

>>dialogue1_4
 GOSUB END_CHAT
 SET §chatpos 1 
 ACCEPT

>>dialogue2_1
 GOSUB START_CHAT
 SPEAK [Rinco_busy] GOSUB END_CHAT
 ACCEPT

ON DIE {
>>NOSHOP
 IF (§dead == 1) ACCEPT
 SET §dead 1
 SENDEVENT RINCODEAD CHEST_METAL_0099 ""
 SENDEVENT RINCODEAD CHEST_METAL_0100 ""
 SET #RINCO_DEAD 1
 ACCEPT
}

ON DEATH {
 IF (#RINCO_DEAD >= 1) ACCEPT
 TELEPORT MARKER_0714
 FORCEDEATH SELF
 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 ------------------------------------------------------------
// ---------------------------------------------------------------------------------

//#