// Joker warden

ON INIT {
  IF (§dead == 2) {
    INVENTORY ADDMULTI "JEWELRY\\GOLD_COIN\\GOLD_COIN" 3
    SET §reflection_mode 1
    SET §enemy 1
    SET £key_carried "KEY_BASE_0005portcullis"
    ACCEPT
  }
 INVENTORY ADDMULTI "JEWELRY\\GOLD_COIN\\GOLD_COIN" 6
 SET §reflection_mode 0
 SET §no_time_for_joke 0
 SET §alert 0
 SET §dead 0
 SET £key_carried "KEY_BASE_0005portcullis"
 ACCEPT
}

ON INITEND {
 SET_NPC_STAT life 11
 SET_NPC_STAT damages 4
 SENDEVENT -ir DURABILITY 100 "43"
  IF (§dead == 2) {
    BEHAVIOR WANDER_AROUND 200
    SETTARGET NONE
    ACCEPT
  }
 SET_CONTROLLED_ZONE JOKE_ZONE
 ACCEPT
}

ON RELOAD {
  IF (#PLAYER_ON_QUEST > 3) {
    IF (§dead == 1) {
      SET §dead 2
      REVIVE -i
      ACCEPT
    }
   ACCEPT
  }
 SET §enemy 1
 SETEVENT HEAR ON
 ACCEPT
}

ON DETECTPLAYER {
 IF (§enemy == 0) ACCEPT
 IF (§alert == 1) ACCEPT
 SET §no_time_for_joke 1
 SENDEVENT CUSTOM Goblin_base_0007 "ALERT"
 SET §alert 1
 ACCEPT
}

ON CUSTOM {
 IF (§no_time_for_joke == 1) ACCEPT
 IF (^$PARAM1 == "ALERT" ) {
  SET §no_time_for_joke 1
  SPEAK [] NOP
  TIMER kill_local
  ACCEPT
 }
 IF (§fighting_mode != 0) ACCEPT
 IF (^$PARAM1 == "TALK" ) {
   IF ( §chatpos == 0) {
     SPEAK [Goblin_here_joke] SENDEVENT CUSTOM Goblin_base_0007 "TALK"
     SET §chatpos 1
     ACCEPT
   }
   IF ( §chatpos == 1) {
     SPEAK [Goblin_grey_gob] SENDEVENT CUSTOM Goblin_base_0007 "TALK"
     SET §chatpos 2
     ACCEPT
   }
   IF ( §chatpos == 2) {
     SPEAK [Goblin_free_oxygen] SENDEVENT CUSTOM Goblin_base_0007 "TALK"
     SET §chatpos 3
     ACCEPT
   }
   IF ( §chatpos == 3) {
     SPEAK [Goblin_sorry] SENDEVENT CUSTOM Goblin_base_0007 "TALK" 
     SET §chatpos 4
     TIMERwander 1 5 GOTO WANDER
     ACCEPT
   }
  ACCEPT
 }
ACCEPT
}

ON CONTROLLEDZONE_ENTER {
  IF (^$PARAM1 == PLAYER) {
    UNSET_CONTROLLED_ZONE JOKE_ZONE
    HEROSAY [tutorial_stealth]
    QUEST [tutorial_stealth]
    IF (§fighting_mode != 0) ACCEPT
    IF (§no_time_for_joke == 1) ACCEPT
    BEHAVIOR FRIENDLY
    SETTARGET GOBLIN_BASE_0007
    SPEAK [Goblin_you_lost] SENDEVENT CUSTOM Goblin_base_0007 "TALK"
    ACCEPT
  }
 ACCEPT
}

ON DIE {
 IF (§dead == 2) ACCEPT
 SET §dead 1
 ACCEPT
}

>>WANDER
 BEHAVIOR WANDER_AROUND 200
 SETTARGET NONE
 SET §care_about_mice 1
 ACCEPT