// Lordboi guarding access in level 0

//#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 INITEND {
 SENDEVENT -ir DURABILITY 100 "52"
 INVENTORY ADDMULTI "JEWELRY\\GOLD_COIN\\GOLD_COIN" 3
 RANDOM 50 { INVENTORY ADD "JEWELRY\\GOLD_COIN\\GOLD_COIN" }
 OBJECT_HIDE SELF ON
 SET §reflection_mode 0
 TWEAK SKIN "npc_Goblin_base_body" "npc_Goblin_lordboi"
 ACCEPT
}

ON CONTROLLEDZONE_ENTER {
  IF (^$PARAM1 != PLAYER) ACCEPT
  IF (§enemy == 1) ACCEPT
  IF (^$PARAM2 == "GOB_WAIT") {
    UNSET_CONTROLLED_ZONE GOB_WAIT
    SET_CONTROLLED_ZONE NO_BADGE
    SET §chatpos 1
    BEHAVIOR FRIENDLY
    SETTARGET PLAYER
    SPEAK [Goblin_only_gem_dealer_shall_pass] NOP
    ACCEPT
  }
  IF (^PARAM2 == "NO_BADGE") {
    UNSET_CONTROLLED_ZONE NO_BADGE
    SENDEVENT ATTACK_PLAYER SELF ""
    SET #NOBADGE 1
    ACCEPT
  }
 ACCEPT
}

ON CUSTOM {
  IF (^$PARAM1 == "SHOW") {
    OBJECT_HIDE SELF OFF
    BEHAVIOR FRIENDLY
    SETTARGET MARKER_0096
    SET_CONTROLLED_ZONE GOB_WAIT
    ACCEPT
  }
 ACCEPT
}

ON CHAT {
  IF (§enemy == 1) ACCEPT
  IF (^SPEAKING == 1) ACCEPT
  IF (§chatpos == 1) {
   GOSUB START_CHAT
   SPEAK [Goblin_generic] GOSUB END_CHAT
   ACCEPT
  }
 ACCEPT
}

ON REACHEDTARGET {
  IF (^TARGET == MARKER_0122) {
    SET §reflection_mode 1
    BEHAVIOR WANDER_AROUND 200
    SETTARGET NONE
    ACCEPT
  }
 ACCEPT
}

ON COMBINE {
  IF (§enemy == 1) ACCEPT
  IF (^SPEAKING == 1) {
    SPEAK -p [player_not_now] NOP
    ACCEPT
  }
  IF (^$PARAM1 ISCLASS GEM_DEALER_BADGE) {
    UNSET_CONTROLLED_ZONE NO_BADGE
    GOSUB START_CHAT
    SPEAK -p [player_Im_gem_dealer] GOTO SUITE
    ACCEPT
  }
 ACCEPT
}

>>SUITE
 SPEAK [Goblin_you_can_pass] GOTO PATROL
 ACCEPT

>>PATROL
 GOSUB END_CHAT
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0122
 ACCEPT