// Zuk, the Warden
ON INIT {
   IF (§dead == 2) {
     SET £type "goblin_lord"
     SET £key_carried "KEY_BASE_0005portcullis" 
     SET §reflection_mode 1 
     SET §hitten 1
     SET §enemy 1
     TELEPORT MARKER_0173
     ACCEPT
   }
 SET £type "goblin_lord"
 SET_SPEAK_PITCH 1.4
 SET £key_carried "KEY_BASE_0005portcullis"
 SET §little_gob_dead 0				// Used to check if little gob is dead
 SET §reflection_mode 0
 SET §hitten 0
 SET §enemy 0
 ACCEPT
}

ON INITEND {
 INVENTORY DESTROY
 INVENTORY CREATE
 INVENTORY ADD "PROVISIONS\\FOOD_FISH_COOKED\\FOOD_FISH_COOKED"
 INVENTORY ADD "PROVISIONS\\BOTTLE_WATER\\BOTTLE_WATER"
 RANDOM 50 {
    INVENTORY ADD "JEWELRY\\GOLD_COIN\\GOLD_COIN"
}
 RANDOM 30 {
    INVENTORY ADD "PROVISIONS\\BREAD_HALF\\BREAD_HALF"
}
  SET_NPC_STAT life 20
  SET_NPC_STAT damages 8
  IF (§dead == 2) {
    SET_NPC_STAT life 25
    SET_NPC_STAT damages 10
    SET_NPC_STAT damages 18
    SET_NPC_STAT aimtime 800
    SETWEAPON SHORT_SWORD
    SENDEVENT -ir DURABILITY 100 "28"
    BEHAVIOR WANDER_AROUND 300
    SETTARGET NONE
    ACCEPT
  }
 SET £youmad []
 SETWEAPON NONE
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0148
 ACCEPT
}

ON GAME_READY {
 SET_NPC_STAT armor_class 10
 SET_NPC_STAT absorb 15
 ACCEPT
} 

ON LOAD {
 USE_MESH "goblin_lord\goblin_lord.teo"
 ACCEPT
}

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

ON DETECTPLAYER {
 SENDEVENT CUSTOM Goblin_base_0009 "STOP_BUSTING_BALLS"
 ACCEPT
}

ON REACHEDTARGET {
  IF (^TARGET == MARKER_0148) {
    BEHAVIOR FRIENDLY
    SETTARGET MARKER_0147
    TIMERpatrol01 1 2 GOTO NEXT_STEP
    ACCEPT
  }
  IF (^TARGET == MARKER_0147) {
    BEHAVIOR FRIENDLY
    SETTARGET MARKER_0148
    TIMERpatrol02 1 2 GOTO NEXT_STEP01
    ACCEPT
  }
 ACCEPT
}

>>NEXT_STEP
  IF (§main_behavior_stacked != 0) {
    TIMERpatrol01 1 2 GOTO NEXT_STEP
  }
  ELSE {
    BEHAVIOR MOVE_TO
    SETTARGET MARKER_0147
  }
 ACCEPT

>>NEXT_STEP01
  IF (§main_behavior_stacked != 0) {
    TIMERpatrol02 1 2 GOTO NEXT_STEP01
  }
  ELSE {
    BEHAVIOR MOVE_TO
    SETTARGET MARKER_0148
  }
 ACCEPT

ON DIE {
 IF (§dead == 2) ACCEPT
 SENDEVENT CUSTOM Goblin_base_0009 "ZUK_DEAD"
 SENDEVENT CUSTOM Goblin_base_0050 "ZUK_DEAD"
 SET §dead 1
 IF (#BOSS_ZUK == 1) ADD_XP 70
 ACCEPT
}

ON AGGRESSION {
 IF (§hitten == 1) ACCEPT
 SENDEVENT CUSTOM Goblin_base_0009 "STOP_BUSTING_BALLS"
 SET §hitten 1
 ACCEPT
}

ON OUCH {
 SENDEVENT CUSTOM Goblin_base_0009 "HIT"			//Polsius encourage player
 ACCEPT
}

ON CUSTOM {
  IF (§fighting_mode != 0) ACCEPT
  IF (§looking_for != 0) ACCEPT
  IF (^$PARAM1 == "TALK" ) {
    SPEAK [Zuk_nasty_to_polsius] NOP			//Polsius asked food
    ACCEPT
  }
  IF (^$PARAM1 == "LISTEN" ) {
    TIMER KILL_LOCAL
    BEHAVIOR FRIENDLY
    SETTARGET GOBLIN_BASE_0050
    SENDEVENT CUSTOM Goblin_base_0009 "STOP_BUSTING_BALLS"
    ACCEPT
  }
  IF (^$PARAM1 == "ACCUSED" ) {
    SET_XP_VALUE 0
	SETNAME [description_zuk]
	SPEAK [Zuk_insult] GOTO CHECK_IF_ALIVE 
    ACCEPT
  }
  IF (^$PARAM1 == "LORD_ATTACK" ) {
    SETGROUP -r goblin
    SET £friend "NONE"
    BEHAVIOR -f MOVE_TO
    SETTARGET GOBLIN_BASE_0050
    ACCEPT
  }
  IF (^$PARAM1 == "LITTLE_GOB_DEAD") {
    SET §little_gob_dead 1
    ACCEPT
  }
 ACCEPT
}

>>CHECK_IF_ALIVE
  IF (§little_gob_dead == 1) {
    SENDEVENT CUSTOM GOBLIN_BASE_0050 "BOSS_ATTACK"
    ACCEPT
  }
 SENDEVENT CUSTOM Goblin_base_0010 "ZUK_ANSWERED"
 ACCEPT

//********************************

ON TARGET_DEATH {
  IF (^$PARAM1 != PLAYER) { 
    BEHAVIOR MOVE_TO
    SETTARGET MARKER_0147
    SET £friend "goblin"
    SETGROUP £friend
    ACCEPT
  }
 ACCEPT
}