// Alotar, King of the Goblins

ON INIT {
 SET §no 0
 SET £key_carried "KEY_BASE_0020KEY_BASE_0035Portcullis"
 SETNAME [description_goblin]
 SET §go_supply 0
 SET §target 0
 SET £type "goblin_king"
 SET £friend "goblin_castle"
 ACCEPT
}

ON INITEND {
 SET §reflection_mode 0
 LOADANIM ACTION4 "Goblin_king_normal_sit_in"
 LOADANIM ACTION5 "Goblin_king_normal_sit_cycle"
 LOADANIM ACTION6 "Goblin_king_normal_sit_out"
 LOADANIM ACTION7 "Goblin_misc_here"
 SET §frozen 1
 PHYSICAL OFF
 SETWEAPON Dagger_iron
 BEHAVIOR -a FRIENDLY
 SETTARGET PLAYER
 SET £flee_marker "FLEE_MARKER_0044"
 SET £helping_buddy "GOBLIN_BASE_0046"
 SENDEVENT -ir DURABILITY 100 "36"
 INVENTORY ADD "MAGIC\\Potion_Life\\Potion_life"
 INVENTORY ADD "JEWELRY\\gold_ring\\gold_ring"
 INVENTORY ADDMULTI "JEWELRY\\gold_coin\\gold_coin" 96
 INVENTORY ADD_FROM_SCENE "KEY_GOB_TREASURE_0001"
 INVENTORY ADD_FROM_SCENE "Key_base_0011"
 INVENTORY ADD_FROM_SCENE "KEY_BASE_0035"
 PLAYANIM -l ACTION5
 ACCEPT
}

ON LOAD {
 USE_MESH "Goblin_king\\Goblin_king.teo"
 ACCEPT
}
ON COLLIDE_NPC {
 IF (§enemy == 1) ACCEPT
 IF (§no == 1) REFUSE
 ACCEPT
}

ON _IE {
 SET #alotar_dead 1
 IF (§chatpos < 3) ADD_XP 500
 SENDEVENT CUSTOM TROLL_base_0016 "ALOTAR_IS_DEAD" // in order to warn the Troll King
 SENDEVENT CUSTOM CHEST_METAL_0047 "DEAD"
 ACCEPT
}
ON THIEF {
 IF (§enemy == 1) ACCEPT
 IF (§target == 0) ACCEPT
 SPEAK [Goblin_thief] SENDEVENT ATTACK_PLAYER SELF ""
 ACCEPT
}
ON _OUNCIL {
>>COUNCIL
 IF (§enemy == 1) ACCEPT
 SENDEVENT CUSTOM Metal_chest_0047 "SELL_END"
 TELEPORT MARKER_0823
 PLAYANIM NONE
 BEHAVIOR FRIENDLY
 SETTARGET NONE
 SETEVENT CHAT OFF
 SETCONTROLLEDZONE NOMOREWELCOMED
 SENDEVENT -gr ~£friend~  COUNCIL 9999 ""
 TIMERLookat 1 2 SETTARGET MARKER_0824
 ACCEPT
}
ON CONTROLLEDZONE_ENTER {
 IF (§enemy == 1) ACCEPT
 IF (^$PARAM1 != PLAYER) ACCEPT
 BEHAVIOR FRIENDLY
 SETTARGET PLAYER 
 PLAYANIM ACTION7 
 TIMERattak 1 2 SENDEVENT ATTACK_PLAYER SELF ""
 SENDEVENT -gr ~£friend~ COUNCIL 9999 "2"
 ACCEPT
}
ON CUSTOM {
  IF (^$PARAM1 == "PIE") { 
   SPEAK [alotar_thanks_anuk] NOP
   ACCEPT
  }
  IF (^$PARAM1 == "EAT_THIS" ) {
    IF (§chatpos == 1) SENDEVENT CUSTOM goblin_base_0013 "GO_KITCHEN" ACCEPT
    IF (#SHUT_UP == 1) SENDEVENT CUSTOM goblin_base_0013 "BRING_MORE" ACCEPT
    IF (^SPEAKING == 1) SENDEVENT CUSTOM goblin_base_0013 "BRING_MORE" ACCEPT
    SPEAK [alotar_thanks_anuk] SENDEVENT CUSTOM goblin_base_0013 "BRING_MORE"
    ACCEPT
  }
  IF (^$PARAM1 == "EAT_THIS_FUCKER" ) {
    IF (§chatpos == 1) SENDEVENT CUSTOM goblin_base_0013 "GO_KITCHEN" ACCEPT
    SETEVENT CHAT OFF
    TIMERx 1 8 GOTO pain
    IF (#SHUT_UP == 1) SENDEVENT CUSTOM goblin_base_0013 "GO_KITCHEN" ACCEPT
    IF (^SPEAKING == 1) SENDEVENT CUSTOM goblin_base_0013 "GO_KITCHEN" ACCEPT
    SPEAK [alotar_thanks_anuk] SENDEVENT CUSTOM goblin_base_0013 "GO_KITCHEN"
    ACCEPT
  }
  IF (^$PARAM1 == "DISTURBED" ) {
    IF (^SPEAKING == 1) ACCEPT
    IF (#SHUT_UP == 0) SPEAK -o [alotar_irritated] NOP
    ACCEPT
  }
  IF (^$PARAM1 == "PLAYER_KNOWS" ) {
    SET §go_supply 1
    ACCEPT
  }
  IF (^$PARAM1 == "Gone") {
   HEROSAY -d "Go"
   SET £MISC [Goblin_gni]
   SET §reflection_mode 1
   PLAYANIM -e ACTION6 GOTO WC
   ACCEPT
  }
 IF (^$PARAM1 == "Return") {
  SENDEVENT OPEN Light_door_0032 ""
  SET £MISC [Alotar_atok]
  SET §reflection_mode 1
  BEHAVIOR FRIENDLY 
  PLAYANIM NONE
  TELEPORT MARKER_0090
  SETTARGET -a MARKER_0243
  TIMERtel 1 3 GOTO INI
  ACCEPT
 }
 IF (^$PARAM1 == "SELL_END") {
  //SET §chatpos 1
  //SET §go_supply 0
  //SENDEVENT CUSTOM Metal_chest_0047 "SELL_END"
  ACCEPT
 }
 ACCEPT
}
ON CHAT {
 IF (§enemy == 1) ACCEPT
 IF (^SPEAKING == 1) ACCEPT
 IF (#troll_quest > 1) {
  IF (§chatpos == 6) {
   SPEAK [Alotar_sellgems] NOP
   ACCEPT
  }
  SET #SHUT_UP 1
  CINEMASCOPE -s ON
  PLAYERLOOKAT ME
  SET_PLAYER_CONTROLS OFF
  PLAYERINTERFACE HIDE 
  SET §chatpos 6
  SENDEVENT CUSTOM Chest_metal_0047 "SHOP"
  SPEAK -p [player_goblins_strikeover] SPEAK [Alotar_izak] SPEAK [Alotar_sellgems] GOTO ENDC 
  ACCEPT
 }
 IF (§chatpos == 0) {
  SET §chatpos 1
  SENDEVENT CUSTOM Goblin_base_0013 "KING_ILL2"
  SETNAME [Description_goblin_king]
  IF (§go_supply == 1) {
   IF (§target == 0) TELEPORT -p MARKER_0508
   IF (§target == 1) {
    TELEPORT -p MARKER_0266 
    SET §reflection_mode 0
   }
   SET #SHUT_UP 1
   TIMERlookat -m 1 10 PLAYERLOOKAT ME
   CINEMASCOPE -s ON
   SET_PLAYER_CONTROLS OFF
   PLAYERINTERFACE HIDE 
   SET §chatpos 1
   SENDEVENT CUSTOM Goblin_base_0016 "Sleep"
   SENDEVENT CUSTOM Goblin_base_0023 "Epok"
   SENDEVENT CUSTOM Goblin_base_0024 "Epok"
   SPEAK -p [player_to_alotar01] SPEAK [Alotar_greetings] GOTO SUPPLY
   ACCEPT
  }
  SENDEVENT CUSTOM Goblin_base_0013 "KING_ILL2"
  SENDEVENT CUSTOM Goblin_base_0016 "Sleep"
  SENDEVENT CUSTOM Goblin_base_0023 "Epok"
  SENDEVENT CUSTOM Goblin_base_0024 "Epok"
  PLAYERLOOKAT ME
  CINEMASCOPE -s ON
  SET #SHUT_UP 1
  SET_PLAYER_CONTROLS OFF
  PLAYERINTERFACE HIDE 
  SET §chatpos 1
  SPEAK -p [player_to_alotar01] SPEAK [Alotar_greetings] GOTO ENDC
  ACCEPT
 }
 IF (§chatpos == 1) {
  IF (§go_supply == 0) SPEAK -a [Alotar_irritated] NOP
  IF (§go_supply == 1) {
   IF (§target == 0) TELEPORT -p MARKER_0508
   IF (§target == 1) {
    TELEPORT -p MARKER_0266 
    SET §reflection_mode 0 
   }
   TIMERlookat -m 1 10 PLAYERLOOKAT ME
   CINEMASCOPE -s ON  
   SET_PLAYER_CONTROLS OFF
   PLAYERINTERFACE HIDE
   SPEAK -p [player_to_alotar02] SPEAK [Alotar_favour] GOTO Chat2
   ACCEPT
  }
  ACCEPT
 }
 IF (§chatpos == 3) {
  SPEAK -p [player_to_alotar05] SPEAK [Alotar_knows] SET §chatpos 5
  ACCEPT
 }
 IF (§chatpos == 5) {
  SPEAK [alotar_irritated] NOP
  ACCEPT
 }
 ACCEPT
}

ON COMBINE {
  IF (§enemy == 1) ACCEPT
  IF (^SPEAKING == 1) SPEAK -p [player_not_now] NOP ACCEPT
  IF (^$PARAM1 ISCLASS "TROLL_IDOL" ) {
   SPEAK [Alotar_atok] NOP
   ACCEPT
  }
 ACCEPT
}

ON REACHEDTARGET {
 IF (^TARGET == "NONE") ACCEPT
 IF (^TARGET == "Marker_0243") {
  HEROSAY -d "243"
  SETTARGET -a Marker_0245
  ACCEPT
 }
 IF (^TARGET == "Marker_0245") {
  //SETTARGET -a Marker_0250
  SETTARGET -a MARKER_0267
  ACCEPT
 }
 IF (^TARGET == "Marker_0250") {
  SETTARGET -a Marker_0265
  ACCEPT
 }
 IF (^TARGET == "Marker_0265") {
  SETTARGET -a Marker_0266
  ACCEPT
 }
 IF (^TARGET == "Marker_0266") {
  SET §target 1
  SETTARGET -a Marker_0267
  ACCEPT
 }
 IF (^TARGET == "Marker_0267") {
  SET §no 1
  BEHAVIOR FRIENDLY
  SETTARGET -a Marker_0266
  TIMERs 1 2 GOTO SIT
  ACCEPT
 }
 ACCEPT
}

>>pain
 IF (#SHUT_UP == 1) {
  SENDEVENT CUSTOM Light_door_0032 "KING_POISONED"
  ACCEPT
 }
 SPEAK [alotar_pain] SENDEVENT CUSTOM Light_door_0032 "KING_POISONED"
 ACCEPT

ON PLAYER_ENEMY {
 SENDEVENT CUSTOM CHEST_METAL_0047 "DEAD"
 ACCEPT
}

>>ENDC
IF (§target == 1) SET §reflection_mode 1
SET #SHUT_UP 0
CINEMASCOPE -S OFF
PLAYERINTERFACE SHOW
SET_PLAYER_CONTROLS ON
ACCEPT

>>WC
Herosay -d "wc"
SET §frozen 0
PHYSICAL ON
BEHAVIOR Move_to
SETTARGET -a Marker_0243
SETMOVEMODE RUN
ACCEPT

>>INI
TELEPORT -i
PLAYANIM -l ACTION5
SET §frozen 1
PHYSICAL OFF
SET §target 0
SENDEVENT OPEN LIGHT_DOOR_0032 ""
ACCEPT

>>SIT
PLAYANIM -e ACTION4 PLAYANIM -l ACTION5
SET §frozen 1
PHYSICAL OFF
SET §target 1
SETEVENT CHAT ON
ACCEPT

>>SUPPLY
SPEAK -cp SIDE goblin_base_0042 0 95 80 80 0 [player_to_alotar02] SPEAK -c KEEP [Alotar_favour] GOTO Chat2
ACCEPT


>>Chat2
 SET §chatpos 3
 SENDEVENT CUSTOM Goblin_base_0041 "Appear"
 SENDEVENT CUSTOM GOBLIN_BASE_0045 "KING_OPEN"
 SENDEVENT CUSTOM Greu_art3_0003 "Appear"
 SPEAK -cp ZOOM 200 220 200 270 50 80 [player_to_alotar03] SPEAK -c ZOOM 100 50 100 50 100 100 [Alotar_clever] GOTO INTER
 ACCEPT

>>INTER
 ADD_XP 500
 GOTO ENDC
 ACCEPT
}
ON COUNCIL {
>>COUNCIL
 IF (§enemy == 1) ACCEPT
 SENDEVENT CUSTOM Metal_chest_0047 "SELL_END"
 TELEPORT MARKER_0823
 PLAYANIM NONE
 SET §council 1
 BEHAVIOR FRIENDLY
 SETTARGET NONE
 SETEVENT CHAT OFF
 SETCONTROLLEDZONE NOMOREWELCOMED
 SENDEVENT -gr ~£friend~  COUNCIL 9999 ""
 TIMERLookat 1 2 SETTARGET MARKER_0824
 ACCEPT
}

ON DIE {
 INVENTORY ADD "JEWELRY\\necklace\\necklace"
 IF (§council == 1) {
  SENDEVENT CUSTOM CHEST_METAL_0047 "DEAD"
  ACCEPT
 }
 SET #alotar_dead 1
 IF (§chatpos < 3) ADD_XP 500
 SENDEVENT CUSTOM TROLL_base_0016 "ALOTAR_IS_DEAD" // in order to warn the Troll King
 SENDEVENT CUSTOM CHEST_METAL_0047 "DEAD"
 ACCEPT
}