// Give me Badge and Autorization Goblin
ON INIT {
 SET £type "goblin_lord"
 SET £friend "lord_guard"
 SETWEAPON SHORT_SWORD
 SET §open 0
 SET §enemy 0
 SET §dead 0
 SET §openportcullis 0
 SET §reflection_mode 0
 SET £key_carried "KEY_BASE_0005portcullis"
// INVENTORY ADD "PROVISIONS\\BOTTLE_WINE\\BOTTLE_WINE"
 ACCEPT
}

ON INITEND {
 SET_CONTROLLED_ZONE GOBLIN_ENTER
 BEHAVIOR FRIENDLY
 SETTARGET PLAYER
 ACCEPT
}

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

ON CONTROLLEDZONE_ENTER {
  IF (^$PARAM2 == "ATTACK_ZONE") {
    IF (^$PARAM1 ISCLASS GOBLIN) {
      UNSET_CONTROLLED_ZONE "ATTACK_ZONE"
      SETEVENT CHAT OFF
      SETEVENT COMBINE OFF
      SET §openportcullis 1
      SENDEVENT ATTACK_PLAYER SELF ""
      SENDEVENT ATTACK_PLAYER GOBLIN_BASE_0015 ""
      SENDEVENT ATTACK_PLAYER GOBLIN_BASE_0039 ""
      SET #need_form 2
      ACCEPT 
    }  
    ACCEPT
  }
 IF (^$PARAM1 != PLAYER) ACCEPT
 SET #SHUT_UP 1
 SENDEVENT CINEMATIC CAMERA_0092 ""
 UNSET_CONTROLLED_ZONE GOBLIN_ENTER
 SET_PLAYER_CONTROLS OFF
 CINEMASCOPE -s ON
 PLAYER_INTERFACE -s HIDE
 SET §chatpos 1
 SET #need_form 1
 BEHAVIOR FRIENDLY
 SETTARGET PLAYER
 SPEAK -o [GoblinLord_who_goes] GOTO ENDINTRODUCE
 ACCEPT
}

ON REACHEDTARGET {
  IF (^TARGET == MARKER_0152) {
    SENDEVENT CUSTOM LEVER_0016 "ACTION"
    SENDEVENT CUSTOM PORTICULLIS_0018 "UNLOCK"
    BEHAVIOR FRIENDLY
    SETTARGET PLAYER
    SET #need_form 2
    SET §open 0
    ACCEPT
  }
 ACCEPT
}

ON CUSTOM {
  IF (§enemy == 1) ACCEPT
  IF (^$PARAM1 == "MISC") {
    SET §reflection_mode 1
    ACCEPT
  }
  IF (^$PARAM1 == "TELEPORTED") {
    IF (§dead == 1) {
      SENDEVENT CUSTOM LEVER_0016 "CLOSE"
      ACCEPT
    }
    TELEPORT MARKER_0750
    SET §chatpos 3
    ACCEPT
  }
 ACCEPT
}

ON _OMBINE { 
  IF (§enemy == 1) ACCEPT
  IF (§open == 2) {
    SPEAK [GoblinLord_human_wrong] NOP		// player give something else
    ACCEPT
  }
  IF (^SPEAKING == 1) {
    SPEAK -p [player_not_now] NOP 
    ACCEPT
  }
  IF (^$PARAM1 ISCLASS "GEM_DEALER_BADGE") {	// player gives gem dealer badge
    INC §open 1
    DESTROY ~^$PARAM1~
    OBJECT_HIDE GEM_DEALER_BADGE_0015 OFF
    INVENTORY ADDFROMSCENE "GEM_DEALER_BADGE_0015"
    SPEAK [Goblinlord_good] GOTO DIALOGUE1_1
    ACCEPT 
  }
  IF (^$PARAM1 ISCLASS "BLANK_FORM") {		// player gives blank form
    SPEAK [GoblinLord_not_signed] NOP
    ACCEPT
  }
  IF (^$PARAM1 ISCLASS "SIGNED_FORM") {		// player gives signed form
    INC §open 1
    DESTROY ~^$PARAM1~
    OBJECT_HIDE SIGNED_FORM_0001 OFF
    INVENTORY ADDFROMSCENE "SIGNED_FORM_0001" 
    SPEAK [Goblinlord_good] GOTO DIALOGUE1_1
    ACCEPT 
  }
  IF (^$PARAM1 == "GOLD_COIN") {			// player gives gold instead of signed form
    IF (§chatpos == 2) GOTO LA_SUITE
    IF (^PLAYER_GOLD < 300) {
      HEROSAY [system_not_enough_gold]
      SPEAK [GoblinLord_human_wrong] NOP
      ACCEPT
    }
   INC §open 1
   SPEAK [GoblinLord_gold_given] GOTO DIALOGUE1_1
   ADDGOLD -300
   ACCEPT
  }
>>LA_SUITE
 SPEAK [GoblinLord_human_wrong] NOP			// player give something else
 ACCEPT
}

ON AGGRESSION {
 IF (§openportcullis == 1) ACCEPT
 SENDEVENT CUSTOM Lever_0016 "ACTION"
 UNSET_CONTROLLED_ZONE "ATTACK_ZONE"
 SET §openportcullis 1
 SET #need_form 2
 ACCEPT
}

ON OUCH {
 IF (§openportcullis == 1) ACCEPT
 SENDEVENT CUSTOM Lever_0016 "ACTION"
 UNSET_CONTROLLED_ZONE "ATTACK_ZONE"
 SET §openportcullis 1
 SET #need_form 2
 ACCEPT
}

ON DIE {
 SET §dead 1
 SENDEVENT CUSTOM PORTICULLIS_0018 "ALWAYSOPEN"
 ACCEPT
}

ON CHAT { 
  IF (^SPEAKING == 1) ACCEPT 
  IF (§chatpos == 3) {
    BEHAVIOR MOVE_TO
    SETTARGET MARKER_0152
    SPEAK [GoblinLord_come_in] SET §chatpos 2
    ACCEPT
  }
  IF (§chatpos == 1) {
    BEHAVIOR FRIENDLY
    SETTARGET PLAYER
    SPEAK [GoblinLord_remember] NOP
    ACCEPT
  }
  IF (§chatpos == 2) {
    BEHAVIOR FRIENDLY
    SETTARGET PLAYER
    SPEAK [Goblinlord_warning] NOP
    ACCEPT
  }
 ACCEPT
}

>>DIALOGUE1_1
 IF (§open != 2) ACCEPT
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0152
 SPEAK [GoblinLord_come_in] GOTO DIALOGUE1_2
 ACCEPT

>>DIALOGUE1_2
 SET §chatpos 2
 QUEST [system_Quest_log_gob_authorization_done]
 HEROSAY [system_questbook_updated]
 DESTROY "GEM_DEALER_BADGE_0015"
 OBJECT_HIDE GEM_DEALER_BADGE_0015 OFF
 INVENTORY PLAYERADDFROMSCENE "GEM_DEALER_BADGE_0015"
 PLAY "system"
 ACCEPT

>>ENDINTRODUCE
 QUEST [system_Quest_log_gob_authorization]
 HEROSAY [system_questbook_updated]
 PLAY "system"
 SET_PLAYER_CONTROLS ON
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 SET #SHUT_UP 0
 PLAYER_LOOKAT ME
 CAMERAACTIVATE NONE
 SET_CONTROLLED_ZONE "ATTACK_ZONE"
 ACCEPT

ON COMBINE { 
  IF (§enemy == 1) ACCEPT
  IF (§open == 2) {
    SPEAK [GoblinLord_human_wrong] NOP		// player give something else
    ACCEPT
  }
  IF (^SPEAKING == 1) {
    SPEAK -p [player_not_now] NOP 
    ACCEPT
  }
  IF (^$PARAM1 ISCLASS "GEM_DEALER_BADGE") {	// player gives gem dealer badge
    INC §open 1
    DESTROY ~^$PARAM1~
    OBJECT_HIDE GEM_DEALER_BADGE_0015 OFF
    INVENTORY ADDFROMSCENE "GEM_DEALER_BADGE_0015"
    SPEAK [Goblinlord_good] GOTO DIALOGUE1_1
    ACCEPT 
  }
  IF (^$PARAM1 ISCLASS "BLANK_FORM") {		// player gives blank form
    SPEAK [GoblinLord_not_signed] NOP
    ACCEPT
  }
  IF (^$PARAM1 ISCLASS "SIGNED_FORM") {		// player gives signed form
    INC §open 1
    DESTROY ~^$PARAM1~
    OBJECT_HIDE SIGNED_FORM_0001 OFF
    INVENTORY ADDFROMSCENE "SIGNED_FORM_0001" 
    SPEAK [Goblinlord_good] GOTO DIALOGUE1_1
    ACCEPT 
  }
  IF (^$PARAM1 == "GOLD_COIN") {			// player gives gold instead of signed form
    IF (§chatpos == 2) GOTO LA_SUITE
    IF (^PLAYER_GOLD < 300) {
      HEROSAY [system_not_enough_gold]
      SPEAK [GoblinLord_human_wrong] NOP
      ACCEPT
    }
   INC §open 1
   SPEAK [GoblinLord_gold_given] GOTO DIALOGUE1_1
   ADDGOLD -300
   INVENTORY ADDMULTI "JEWELRY\\GOLD_COIN\\GOLD_COIN" 300
   ACCEPT
  }
>>LA_SUITE
 SPEAK [GoblinLord_human_wrong] NOP			// player give something else
 ACCEPT
}