ON INIT {
 SET £friend "goblin_water"
 SET §fooled 0
 SET §walking 0
 SET £voice "_vb" 
 IF (§revived == 1) ACCEPT
 IF (#air_clan_dead == 2) {
  IF (#water_clan_dead == 2) {
   TELEPORT MARKER_0719
   SET §revived 1
//   TWEAK REMOVE
  // TWEAK SKIN "npc_Goblin_base_body" "npc_Goblin_grey_body"
  // TWEAK SKIN "npc_goblin_nohelm_head" "npc_Goblin_grey_head"
   ACCEPT
  }
  ACCEPT
 }
 ACCEPT
}

ON INITEND {
 SET §weaponready 0
 SET §dialogue 0
 SET §infishzone 0
 SET §fishing 0
 SET §enemy 1
 IF (§revived == 1) ACCEPT
 SET §enemy 0
 INVENTORY DESTROY
 INVENTORY CREATE
 INVENTORY ADDMULTI "JEWELRY\\GOLD_COIN\\GOLD_COIN" 17
// INVENTORY ADD "PROVISIONS\\BOTTLE_WINE\\BOTTLE_WINE"
 INVENTORY ADD "JEWELRY\\SILVER_RING\\SILVER_RING"
   INVENTORY ADD "PROVISIONS\\FOOD_FISH\\FOOD_FISH"
 RANDOM 50 {
    INVENTORY ADD "JEWELRY\\GOLD_COIN\\GOLD_COIN"
}
 RANDOM 30 {
    INVENTORY ADD "PROVISIONS\\BOTTLE_WINE\\BOTTLE_WINE"
}
 SENDEVENT -ir DURABILITY 100 "22"
 LOADANIM ACTION1 "Goblin_normal_lay_in"
 LOADANIM ACTION2 "Goblin_normal_lay_out"
 LOADANIM ACTION3 "Goblin_normal_lay_cycle"
 LOADANIM ACTION4 "Goblin_misc_eatrat"
 LOADANIM WAIT2 "Goblin_misc_fishing"
 TWEAK HEAD "goblin_nohelm"
 TWEAK SKIN "npc_goblin_base_head""npc_goblin_nohelm_head"
 SETWEAPON CLUB
 BEHAVIOR NONE
 SETTARGET NONE
 ACCEPT
}

ON RELOAD {
  IF (§revived == 1) ACCEPT
  IF (#air_clan_dead == 2) {
   IF (#water_clan_dead == 2) {
    REVIVE 
    SET §enemy 1
    ACCEPT
   }
   ACCEPT
  }
 ACCEPT
}


ON CONTROLLEDZONE_ENTER {
  IF (§enemy == 1) ACCEPT 
  IF (^$param1 != PLAYER) ACCEPT
  IF (^$param2 == AIR_CLAN_EXIT) {
   UNSET_CONTROLLED_ZONE AIR_CLAN_EXIT
   IF (§chatpos == 4) ACCEPT
   SET §chatpos 2
   ACCEPT
  }
  ACCEPT
}

ON CONTROLLEDZONE_LEAVE {
 IF (§enemy == 1) ACCEPT 
 IF (^$param1 != PLAYER) ACCEPT
 IF (^$param2 == FISHING_ZONE2) {
  SET §infishzone 0 
  ACCEPT
 }
 ACCEPT
}


ON REACHEDTARGET {
  IF (§enemy == 1) ACCEPT 
  IF (^target == marker_0171) {
   SET §reflection_mode 0
   SET §walking 0
   SET §frozen 1
   FORCE_ANGLE 5
   PLAYANIM -e ACTION1 PLAYANIM -l ACTION3
   SET §sleeping 1
   ACCEPT
  }
  IF (^target == marker_0170) {
   ATTACH pole_0009 "action point" SELF "primary_attach"
   SET £attached_object "pole_0009"
   SET §reflection_mode 0
   SET §fishing 1
   SET §walking 0
   BEHAVIOR FRIENDLY
   SETTARGET MARKER_0299
   TIMERsit 1 2 PLAYANIM -l WAIT2
   SET §frozen 1
   TIMERfishing 1 100 PLAYANIM NONE GOTO SLEEP
   IF (§infishzone == 1) {
    SPEAK [Goblin_misc_fish_scared] nop
    ACCEPT
   }
   ACCEPT
  }
 ACCEPT
}

ON CUSTOM {
  IF (^$PARAM1 == "FISH_TALK" ) {
   SPEAK -a [Goblin_not_bigger] SENDEVENT CUSTOM goblin_base_0027 "YOURTURN" 
   ACCEPT
  }
// Dialogue09 du Goblin 0028, du goblin 0027 et du player
  IF (^$PARAM1 == "TURN") {
    BEHAVIOR FRIENDLY
    SETTARGET PLAYER
    ACCEPT
  }
  IF (^$PARAM1 == "MOVE") {
    BEHAVIOR MOVE_TO
    SETTARGET MARKER_0171
    ACCEPT
  }
  IF (^$PARAM1 == "TALK") {
    IF (§dialogue == 0) {
      SET §reflection_mode 0
      SPEAK -o [Goblin_we_water_clan] SENDEVENT CUSTOM goblin_base_0027 "TALK"
     //Lance [goblin_not_bigger2]
      SET §dialogue 1
     //SET §dialogue 5 // //RACCOURCI LA CINEMATIQUE
      ACCEPT
    } 
    IF (§dialogue == 1) { 
      SPEAK -o [Goblin_we_water_clan2] SENDEVENT CUSTOM goblin_base_0027 "TALK"
     //Lance [player_why_dont_like]
      SET §dialogue 2
      ACCEPT
    } 
    IF (§dialogue == 2) { 
       SPEAK -o [Goblin_eat_rats] SENDEVENT CUSTOM goblin_base_0027 "TALK"
     //Lance [Goblin_eat_rats_other]
      SET §dialogue 3
      ACCEPT
    }    
    IF (§dialogue == 3) { 
     DESTROY CAMERA_0063
     SENDEVENT CINEMATIC CAMERA_0066 ""  
     SPEAK -o [Goblin_eat_rats2] SENDEVENT CUSTOM goblin_base_0027 "TALK"
     //Lance [Goblin_eat_rats_other2]
      SET §dialogue 4
      ACCEPT
    }
    IF (§dialogue == 4) { 
      DESTROY CAMERA_0066
      CAMERAACTIVATE NONE
      SPEAK -o [Goblin_eat_rats3] SENDEVENT CUSTOM goblin_base_0027 "TALK"
     //Lance [Goblin_eat_rats_other3]
      SET §dialogue 5
      ACCEPT
    } 
  //  IF (§dialogue == 5) { 
   //   SPEAK [player_well_see] SENDEVENT CUSTOM goblin_base_0027 "TALK"
    //  ACCEPT
   // }
   ACCEPT
  } 
  IF (^$PARAM1 == "MISSION_RECEIVED") {
    IF (§chatpos != 4) SET §chatpos 1
>>MOVIING
    BEHAVIOR MOVE_TO
    SETTARGET MARKER_0171
    ACCEPT
  }
  IF (^$PARAM1 == "RETURN_FROM_AIR") {
   IF (§chatpos == 4) ACCEPT
   SET §chatpos 2
   ACCEPT
  }
  IF (^$PARAM1 == "ALLY" ) {
   SET §chatpos 4
   SET §amulet 1
   ACCEPT
  }
 ACCEPT
}

ON CHAT {
  IF (§enemy == 1) ACCEPT
  IF (^speaking == 1) ACCEPT
  //IF (§walking == 1) ACCEPT
  GOSUB START_CHAT
  IF (#air_clan_dead == 2) GOTO AIR_CLAN_DEAD
  IF (§chatpos == 1) { 
   SET §chatpos 2
   SPEAK [goblin_water_repeat_mission_vb] GOSUB END_CHAT
   ACCEPT
  }
  IF (§chatpos == 2) GOTO dialogue1_1
>>AIR_CLAN_DEAD 
  IF (§chatpos == 4) {
   SPEAK [Goblin_good_ally_misc_vb] GOTO AMULET
   ACCEPT
  } 
  GOTO dialogue1_1
  ACCEPT
}

>>AMULET 
 IF (§fooled == 1) GOSUB END_CHAT ACCEPT
 IF (#amulet_identified == 1) GOTO dialogue4_1 
 GOSUB END_CHAT
 ACCEPT

>>dialogue1_1
 SPEAK [Goblin_misc_you_kill_vb] GOTO dialogue1_2
 ACCEPT 

>>dialogue1_2
 IF (#air_clan_dead == 2) {
   SPEAK -p [player_yes] GOTO dialogue1_3
   ACCEPT
 }
 SPEAK -p [player_not_yet] nop
 SET §chatpos 1
 SET_CONTROLLED_ZONE AIR_CLAN_EXIT
 GOSUB END_CHAT
 ACCEPT

>>dialogue1_3
 IF (§amulet == 1) GOSUB END_CHAT ACCEPT
 SPEAK [Goblin_good_ally] nop
 INVENTORY PLAYERADDFROMSCENE "necklace_0013"
 PLAY SYSTEM
 SENDEVENT CUSTOM Goblin_base_0027 "ALLY"
 SENDEVENT CUSTOM Goblin_base_0032 "ALLY"
 SET §chatpos 4
 GOSUB END_CHAT
 ACCEPT  

>>back_lake
 SET §sleeping 0
 PLAYANIM -e ACTION2 GOTO back_lake2

>>back_lake2
 SET §frozen 0
 TIMEReat OFF
 SET §walking 1
 SET §reflection_mode 1
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0170
 ACCEPT

>>SLEEP
 SET §walking 1
 SET §frozen 0
 SET §fishing 0
 TIMERfishing OFF
 SET §reflection_mode 1
 DETACH pole_0009 SELF
 SET £attached_object "NONE"
 SENDEVENT GOCAMP goblin_base_0027 ""
 SENDEVENT HIDE pole_0009 ""
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0171
 ACCEPT

>>dialogue4_1
 SPEAK -p [player_fooled_identified] GOTO dialogue4_2
 ACCEPT 

>>dialogue4_2
 SET §fooled 1
 SENDEVENT FOOLED GOBLIN_BASE_0027 ""
 SPEAK [Goblin_you_wrong_vb] GOSUB END_CHAT
 ACCEPT

ON DIE {
 SENDEVENT CUSTOM barrel_0004 "WATERDEAD"
 ACCEPT
}

ON AGGRESSION {
   IF (§done == 1) ACCEPT
   SENDEVENT -g £friend COMBAT ""
>>COMBAT
   SET §done 1
   DETACH pole_0009 SELF
   SET £attached_object "NONE"
   SENDEVENT HIDE pole_0009 ""
   INVENTORY ADD "Provisions\fishing_pole\fishing_pole"
ACCEPT
}

ON COMBAT {
// IF (^SENDER == SELF) ACCEPT 
 GOTO COMBAT
 ACCEPT
}

ON REFLEXION {
  SET §reflection_mode 1 
 ACCEPT
}
ON NOREFLEXION {
  SET §reflection_mode 0 
 ACCEPT
}
ON ATTACK_PLAYER {
 IF (§done == 1) ACCEPT
 SENDEVENT -g £friend COMBAT ""
 ACCEPT
}
ON GOFISHING {
 GOTO back_lake
 ACCEPT
}

ON FOOLED {
 SET §fooled 1
 ACCEPT
}

////////////////////////////A VIRER (simulate)
ON POUET { 
 GOTO SLEEP
 ACCEPT
}
///////////////////////////////////////////////

//#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 -----------------------------------------------------------
// ---------------------------------------------------------------------------------

//#