ON INIT {
 SET §short 0
 SET £friend "goblin_water"
 SET §walking 0
 SET §fishnumber 3
 SET §1starrival 0
 SET §reflection_mode 1
 SET §xpgiven 0
 IF (§revived == 1) ACCEPT
 IF (#air_clan_dead == 2) {
  IF (#water_clan_dead == 2) {
   SET §enemy 1
   SET §revived 1
   TWEAK SKIN "npc_Goblin_base_body" "npc_Goblin_grey_body"
   TWEAK SKIN "npc_Goblin_base_head" "npc_Goblin_grey_head"
   TELEPORT MARKER_0165
   BEHAVIOR MOVE_TO
   SETTARGET MARKER_0721
   ACCEPT
  }
  ACCEPT
 }
 ACCEPT
}

ON INITEND {
 SETWEAPON AXE
 SET §weaponready 0
 SET §dialogue 0
 SET §yourturn 0
 SET_SPEAK_PITCH 1.1
 SET §enemy 1
 IF (§revived == 1) ACCEPT
 SET §enemy 0
 INVENTORY ADD "PROVISIONS\\ROPE\\ROPE"
// SENDEVENT -ir DURABILITY 100 "11"
 INVENTORY ADDFROMSCENE "key_base_0038"
 RANDOM 50 {
    INVENTORY ADD "JEWELRY\\GOLD_COIN\\GOLD_COIN"
}
 RANDOM 30 {
    INVENTORY ADD "PROVISIONS\\BOTTLE_WINE\\BOTTLE_WINE"
}
 SET_CONTROLLED_ZONE FIRST_ENTER
 LOADANIM ACTION3 "goblin_normal_sit_in"
 LOADANIM ACTION2 "goblin_normal_sit_out"
 LOADANIM ACTION4 "goblin_normal_sit_cycle"
 LOADANIM WAIT2 "Goblin_misc_barbecue"
 LOADANIM ACTION5 "Goblin_misc_eatrat"
 ACCEPT
}

ON RELOAD {
 IF (§revived == 1) ACCEPT
  IF (#air_clan_dead == 2) {
   IF (#water_clan_dead == 2) {
    SENDEVENT ASSAULT CHEST_METAL_0085 ""
    REVIVE
    ACCEPT
   }
   ACCEPT
  }
 ACCEPT
}

ON REACHEDTARGET {
  IF (^target == marker_0456) {
   SET §reflection_mode 0
   SET §fishing 1
   SET §walking 0
   BEHAVIOR FRIENDLY
   SETTARGET MARKER_0457
   TIMERsit 1 2 PLAYANIM -l WAIT2
   SET §frozen 1
   IF (§infishzone == 1) {
    SPEAK [Goblin_misc_fish_scared] nop
    ACCEPT
   }
   ACCEPT
  }
   IF (^target == fish_spawn_0028) {
    SET §fishnumber 3
    GOTO TO_FIRECAMP
    ACCEPT
   }
   IF (^target == marker_0295) {
    SET §gofishing 0
    DETACH pole_0010 SELF 
    SET £attached_object "NONE"
    SENDEVENT HIDE pole_0010 ""
    SENDEVENT SHOW fishing_pole_0014 ""
    SET §walking 0
    BEHAVIOR FRIENDLY
    SETTARGET MARKER_0296 
    SET §reflection_mode 1
    SET §frozen 1
    SENDEVENT RESET food_fish_0012 ""
    SENDEVENT RESET food_fish_0013 ""
    SENDEVENT RESET food_fish_0014 ""
    TIMERbarb 1 2 GOTO BARBECUE
    ACCEPT
   }
IF (^target == marker_0721) {
    BEHAVIOR FRIENDLY
    SETTARGET GOBLIN_BASE_0031
    TIMERtrip 1 20 GOTO TRIP
    ACCEPT
   }
IF (^target == marker_0165) {
    BEHAVIOR FRIENDLY
    SETTARGET CHEST_METAL_0114
    TIMERtrip2 1 20 GOTO TRIP2
    ACCEPT
   }
  ACCEPT
}

>>TRIP
BEHAVIOR MOVE_TO
SETTARGET MARKER_0165
ACCEPT

>>TRIP2
BEHAVIOR MOVE_TO
SETTARGET MARKER_0721
ACCEPT

ON MAIN {
 ACCEPT
}

ON MAINpolite {
 IF (§yourturn == 1) GOTO dialogue2_1
 ACCEPT
}

ON CONTROLLEDZONE_ENTER {
  IF (§enemy == 1) ACCEPT
  IF (^$PARAM1 != PLAYER) ACCEPT
  IF (^$PARAM2 == FIRST_ENTER) {
    UNSET_CONTROLLED_ZONE FIRST_ENTER
    SET_CONTROLLED_ZONE FISH_DIALOGUE09
    GOTO dialogue1_1
    ACCEPT
  }
  IF (^$PARAM2 == FISH_DIALOGUE09) {
    UNSET_CONTROLLED_ZONE FISH_DIALOGUE09
    SET §playerinzone 1
    SET §reflection_mode 1
    SET_PLAYER_CONTROLS OFF
    PLAYER_INTERFACE -s HIDE
    CINEMASCOPE -s ON
    PLAYER_LOOKAT MARKER_0278
    SET_MAIN_EVENT MAINpolite
    ACCEPT
  }
 IF (^$PARAM2 == FISHING_ZONE2) {
  IF (§fishing == 0) {
   SET §infishzone 1
   ACCEPT
  }
  SET §infishzone 1 
  SPEAK [Goblin_misc_fish_scared] nop
  ACCEPT
 }
 ACCEPT
}

ON CONTROLLEDZONE_LEAVE {
 IF (§enemy == 1) ACCEPT 
 IF (^$param1 != PLAYER) ACCEPT
 IF (^$PARAM2 == AIR_CLAN_EXIT) {
  UNSET_CONTROLLED_ZONE AIR_CLAN_EXIT
  SENDEVENT CUSTOM Goblin_base_0028 "RETURN_FROM_AIR"
  SENDEVENT CUSTOM Goblin_base_0032 "RETURN_FROM_AIR"
  IF (§chatpos == 4) ACCEPT
  SET §chatpos 3 
  ACCEPT
 } 

 IF (^$PARAM2 == FISHING_ZONE2) {
  SET §infishzone 0 
  ACCEPT
 } 
 ACCEPT
} 

ON CHAT {
  IF (§enemy == 1) ACCEPT
  IF (^speaking == 1) ACCEPT
  GOSUB START_CHAT
  IF (§infishzone == 1) {
   SPEAK [Goblin_misc_fish_scared] GOSUB END_CHAT
   ACCEPT
  } 
  IF (#air_clan_dead == 2) GOTO AIR_CLAN_DEAD
  IF (§chatpos == 2) {
    SET §chatpos 3
    SPEAK [Goblin_water_repeat_mission] GOSUB END_CHAT
    ACCEPT
  }
  IF (§chatpos == 3) GOTO dialogue3_1 

>>AIR_CLAN_DEAD
  IF (§chatpos == 4) {
    SPEAK [Goblin_good_ally_misc] GOTO AMULET
    ACCEPT
  }
  GOTO dialogue3_1
 ACCEPT
}

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


>>dialogue2_1
// Début du dialogue avec le joueur
 SET #SHUT_UP 1 
 BEHAVIOR FRIENDLY
 SETTARGET PLAYER
 SENDEVENT CUSTOM Goblin_base_0028 "TURN"
 SPEAK -p [player_what_doing_here] SENDEVENT CUSTOM Goblin_base_0028 "TALK"
 SET_MAIN_EVENT MAIN
 ACCEPT

//Dialogue09 du Goblin 0028, du goblin 0027 et du player
ON CUSTOM {
  IF (^$PARAM1 == "XPGIVEN") SET §xpgiven 1
  IF (^$PARAM1 == "YOURTURN") {
   SET §reflection_mode 1 
   SET §yourturn 1 
   ACCEPT
  }
  IF (^$PARAM1 == "TALK") {
    IF (§dialogue == 0) {
      SETTARGET goblin_base_0028
      SPEAK -oa [goblin_not_bigger2] SENDEVENT CUSTOM Goblin_base_0028 "TALK"
   // Lance [Goblin_we_water_clan2]
      SET §dialogue 1
   //SET §dialogue 4   //RACCOURCI LA CINEMATIQUE
      ACCEPT
    }
    IF (§dialogue == 1) {
      SETTARGET PLAYER
      SENDEVENT CINEMATIC CAMERA_0063 ""
      SPEAK -p [player_why_dont_like] SENDEVENT CUSTOM Goblin_base_0028 "TALK"
   //Lance [goblin_eat_rats]
      SET §dialogue 2
      ACCEPT
    } 
    IF (§dialogue == 2) {
      SPEAK -o [goblin_eat_rats_other] SENDEVENT CUSTOM Goblin_base_0028 "TALK"
   //Lance [goblin_eat_rats2]
      SET §dialogue 3
      ACCEPT
    } 
    IF (§dialogue == 3) {
      SPEAK -o [goblin_eat_rats_other2] SENDEVENT CUSTOM Goblin_base_0028 "TALK"
   //Lance [goblin_eat_rats3]
      SET §dialogue 4
      ACCEPT
    }
    IF (§dialogue == 4) {
      SPEAK -o [goblin_eat_rats_other3] GOTO SUITE
   //Lance [player_well_see]
      SET §dialogue 5
      ACCEPT
    } 
    IF (§dialogue == 5) {
      >>SUITE
      SET §chatpos 2
      SENDEVENT CUSTOM Goblin_base_0028 "MISSION_RECEIVED"
      SENDEVENT CUSTOM Goblin_base_0032 "MISSION_RECEIVED"
      QUEST [system_Quest_water_clan] PLAY SYSTEM
      HEROSAY [system_questbook_updated]
      SET_CONTROLLED_ZONE AIR_CLAN_EXIT
      SET_CONTROLLED_ZONE FISHING_ZONE2
      IF (#air_clan_dead == 2) {
       SET §short 1 
       GOTO dialogue3_2
      }
      IF (#air_clan_dead == 0) SET #air_clan_dead 1
      SPEAK -p [player_well_see] NOP
      CINEMASCOPE -s OFF
      PLAYER_INTERFACE -s SHOW
      SET_PLAYER_CONTROLS ON
      SENDEVENT CUSTOM GOBLIN_BASE_0028 "MOVE"
      SET #SHUT_UP 0
>>TO_FIRECAMP
      SET §walking 1
      SET §reflection_mode 1  
      BEHAVIOR MOVE_TO
      SETTARGET MARKER_0295
      ACCEPT
     }
    ACCEPT
  } 
  IF (^$PARAM1 == "ALLY") {
   SET §amulet 1
   SET §chatpos 4
   ACCEPT
  }
 ACCEPT
}

>>dialogue1_1
 SET #SHUT_UP 1
 SPEAK [Goblin_big_fish] SENDEVENT CUSTOM Goblin_base_0028 "FISH_TALK"
 SET §chatpos 1
 ACCEPT

>>dialogue3_1
 CINEMASCOPE -s ON
 PLAYER_INTERFACE -s HIDE
 SET_PLAYER_CONTROLS OFF
 SET #SHUT_UP 1
 SPEAK [Goblin_misc_you_kill] GOTO dialogue3_2
 ACCEPT 

>>dialogue3_2
  IF (#air_clan_dead == 2) {
    SPEAK -p [player_yes] GOTO dialogue3_3
    ACCEPT
  }
 SPEAK -p [player_not_yet] GOTO ENDC
 ACCEPT

>>ENDC
 GOSUB END_CHAT
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 SET_PLAYER_CONTROLS ON
 SET #SHUT_UP 0
 ACCEPT

>>dialogue3_3
 IF (§amulet == 1) {
  GOSUB END_CHAT 
  CINEMASCOPE -s OFF
  PLAYER_INTERFACE -s SHOW
  SET_PLAYER_CONTROLS ON
  SET #SHUT_UP 0
  ACCEPT
 }
 SPEAK [Goblin_good_ally] GOTO dialogue3_4
 ACCEPT

>>dialogue3_4
  IF (§xpgiven == 0) {
    SET §xpgiven 1
    QUEST [system_Quest_water_clan_done]
    ADD_XP 1000
    SENDEVENT TADA PLAYER ""
  }
 SENDEVENT CUSTOM Goblin_base_0028 "ALLY"
 SENDEVENT CUSTOM Goblin_base_0032 "ALLY"
 SET §chatpos 4
 INVENTORY PLAYERADDFROMSCENE "necklace_0013"
 GOSUB END_CHAT
 CINEMASCOPE -s OFF
 PLAYER_INTERFACE -s SHOW
 SET_PLAYER_CONTROLS ON
 SET #SHUT_UP 0
 IF (§short ==  1) {
  SENDEVENT CUSTOM GOBLIN_BASE_0028 "MOVE"
  GOTO TO_FIRECAMP
  ACCEPT
 }
 ACCEPT 

>>dialogue4_1
 SET §fooled 1
 SENDEVENT FOOLED GOBLIN_BASE_0028 ""
 SPEAK -p [player_fooled] GOTO dialogue4_2
 ACCEPT 

>>dialogue4_2
 SPEAK [Goblin_you wrong] GOSUB END_CHAT 
 ACCEPT

ON DIE {
 SENDEVENT CUSTOM barrel_0004 "WATERDEAD"
 ACCEPT
}

>>BARBECUE
 IF (§1starrival == 0) {
  SET §1starrival 1
  PLAYANIM -e ACTION3 PLAYANIM -l WAIT2
 }
  SENDEVENT HIDE POLE_0001 ""
  ATTACH pole_with_fish_0001 "action point" SELF "primary_attach" 
  SET £attached_object "pole_with_fish_0001"
  IF (§fishnumber == 3) {
   SENDEVENT TAKEN food_fish_0014 ""
   TIMERsound1 1 5 PLAY "COOKING"
   TIMERcook 1 10 GOTO COOKED
   ACCEPT
  }
  IF (§fishnumber == 2) {
   SENDEVENT TAKEN food_fish_0013 ""
   TIMERsound2 1 5 PLAY "COOKING"
   TIMERcook2 1 10 GOTO COOKED
   ACCEPT
  }
  IF (§fishnumber == 1) {
   SENDEVENT TAKEN food_fish_0012 ""
   TIMERsound3 1 5 PLAY "COOKING"
   TIMERcook3 1 10 GOTO COOKED
   ACCEPT
  }
ACCEPT

>>COOKED
  DEC §fishnumber 1
  IF (§fishnumber == 2) {
    SENDEVENT COOKED food_fish_cooked_0007 ""
    TIMERbob1 1 10 GOTO BARBECUE 
    ACCEPT
  }
  IF (§fishnumber == 1) {
    SENDEVENT COOKED food_fish_cooked_0003 ""
    TIMERbob2 1 10 GOTO BARBECUE
    ACCEPT
  }
  IF (§fishnumber == 0) {
    SENDEVENT COOKED food_fish_cooked_0001 ""
    TIMERbob3 1 10 GOTO EAT 
    ACCEPT
  }
  ACCEPT
>>EAT
  SENDEVENT DONE POLE_0001 ""
  DETACH pole_with_fish_0001 SELF
  SET £attached_object "NONE"
  SENDEVENT HIDE pole_with_fish_0001 ""
  ATTACH food_fish_eaten_0001 "action point" SELF "primary_attach"
  SET £attached_object "food_fish_eaten_0001"
  SENDEVENT EATEN food_fish_cooked_0007 ""
  PLAYANIM -l ACTION5
  TIMERburp 1 20 GOTO EAT2
  ACCEPT
>>EAT2  
   SENDEVENT EATEN food_fish_cooked_0003 "" 
   PLAYANIM -l ACTION5
   TIMERburp2 1 20 GOTO EAT3
   ACCEPT
>>EAT3 
   SENDEVENT EATEN food_fish_cooked_0001 ""
   PLAYANIM -l ACTION5
   TIMERburp3 1 20 GOTO GETFISH
   ACCEPT
  
>>GETFISH 
 DETACH food_fish_eaten_0001 SELF 
 SET £attached_object "NONE"
 SENDEVENT HIDE food_fish_eaten_0001 ""  
 PLAYANIM -e ACTION2 GOTO GETFISH2
 ACCEPT
>>GETFISH2
 ATTACH pole_0010 "action point" SELF "primary_attach"
 SET £attached_object "pole_0010"
 SENDEVENT HIDE fishing_pole_0014 ""  
 SET §frozen 0
 SET §walking 1
 SET §reflection_mode 1
 SET §gofishing 1
 SET §1starrival 0
 SENDEVENT GOFISHING goblin_base_0028 ""
 PLAYANIM NONE
 BEHAVIOR MOVE_TO
 SETTARGET MARKER_0456
 ACCEPT

ON THIEF {
 SPEAK [goblin_thief] SENDEVENT -g £friend ATTACK_PLAYER ""
 ACCEPT
}

ON AGGRESSION {
 IF (§done == 1) ACCEPT
 SENDEVENT -g £friend COMBAT ""
>>COMBAT 
 SET §done 1
 DETACH food_fish_eaten_0001 SELF
 SET £attached_object "NONE"
 SENDEVENT HIDE food_fish_eaten_0001 ""
 DETACH pole_with_fish_0001 SELF
 SET £attached_object "NONE"
 SENDEVENT HIDE pole_with_fish_0001 ""
 IF (§gofishing >= 1) {
  DETACH pole_0010 SELF
  SET £attached_object "NONE"
  SENDEVENT HIDE pole_0010 ""
  INVENTORY ADDFROMSCENE "fishing_pole_0014"
  IF (§gofishing == 2) {
   INVENTORY ADD "Provisions\food_fish\food_fish"
   INVENTORY ADD "Provisions\food_fish\food_fish"
   INVENTORY ADD "Provisions\food_fish\food_fish"
   ACCEPT
  }
  ACCEPT
 }
 ACCEPT
}

ON COMBAT {
 GOTO COMBAT
 ACCEPT
}
ON SIMULATE { 
 TELEPORT marker_0171         /////A VIRER
 GOTO TO_FIRECAMP
 ACCEPT
}
ON GOCAMP {
 SET §fishing 0
 SET §fishnumber 3
 SET §gofishing 2
 PLAYANIM NONE GOTO TO_FIRECAMP ///A UPGRADER (PATHFINDER)
 ACCEPT
}

>>DETOUR
 SET §gofishing 2
 BEHAVIOR MOVE_TO
 SETTARGET FISH_SPAWN_0028
 ACCEPT

ON ATTACK_PLAYER {
 IF (§done == 1) ACCEPT
 SENDEVENT -g £friend COMBAT ""
 GOTO COMBAT
 ACCEPT
}
ON FOOLED {
 SET §fooled 1
 ACCEPT
}


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

ON DOUSED { 
 IF (§enemy == 1) ACCEPT
 IF (§revived == 1) ACCEPT
  TIMERignit -i 0 2 GOTO FIREPLEASE 
 ACCEPT
}

>>FIREPLEASE
 IF (§walking == 1) ACCEPT
 IF (§fishing == 1) ACCEPT
 SPELLCAST -msf 10 IGNIT FIRE_CAMP_0006
 TIMERignit OFF
 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 -----------------------------------------------------------
// ---------------------------------------------------------------------------------

//#