ON INIT {
 SET_SPEAK_PITCH 0.9
 SET £friend "goblin_water"
 SET §reflection_mode 0
 IF (§revived == 1) ACCEPT
 IF (#air_clan_dead == 2) {
   IF (#water_clan_dead == 2) {
    INVENTORY ADDMULTI "JEWELRY\\GOLD_COIN\\GOLD_COIN" 4
    TWEAK SKIN "npc_Goblin_base_body" "npc_Goblin_grey_body"
    TWEAK SKIN "npc_Goblin_base_head" "npc_Goblin_grey_head"
    TELEPORT MARKER_0720
    SET §revived 1
    SET §enemy 1
   ACCEPT
   }
  ACCEPT
 }
 ACCEPT
}
ON INITEND {
 SET_SPEAK_PITCH 0.9
 IF (§revived == 1) ACCEPT
// INVENTORY ADD "ARMOR\\CHEST_LEATHER\\CHEST_LEATHER"
 LOADANIM WAIT2 "Goblin_misc_fishing"
 ATTACH pole_0008 "action point" SELF "primary_attach"
 SET £attached_object "pole_0008"
 SET_CONTROLLED_ZONE FISHING_ZONE
 PLAYANIM -l WAIT2
 SENDEVENT -ir DURABILITY 100 "19"
 SENDEVENT -ir DURABILITY_ARMOR 100 "26"
 SET §frozen 1
 SET §infishzone 0 
 ACCEPT
}

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


ON CONTROLLEDZONE_ENTER {
 IF (§enemy == 1) ACCEPT 
 IF (^$param1 != PLAYER) ACCEPT
 SET §infishzone 1
 SPEAK [Goblin_misc_fish_scared] nop  
 ACCEPT
}

ON CONTROLLEDZONE_LEAVE {
 IF (§enemy == 1) ACCEPT 
 IF (^$param1 != PLAYER) ACCEPT
 SET §infishzone 0 
 ACCEPT
} 
 
ON CUSTOM {
 IF (^$PARAM1 == "MISSION_RECEIVED"){
  IF (§chatpos == 4) ACCEPT
  SET §chatpos 1
  ACCEPT
 }
 IF (^$PARAM1 == "RETURN_FROM_AIR") {
  IF (§chatpos == 4) ACCEPT
  SET §chatpos 2
  ACCEPT
 }
 IF (^$PARAM1 == "ALLY") SET §chatpos 4
 ACCEPT
}

ON CHAT {
  IF (§enemy == 1) ACCEPT
  IF (§infishzone == 1) {
   SPEAK [Goblin_misc_fish_scared] nop 
   ACCEPT
  } 
  IF (#air_clan_dead == 2) GOTO AIR_CLAN_DEAD
  IF (^speaking == 1) ACCEPT
  IF (§chatpos == 1) {
     SPEAK [goblin_water_repeat_mission] nop
    ACCEPT
  }
  IF (§chatpos == 2) {
     SPEAK [goblin_water_repeat_mission] nop
    ACCEPT
  }

>>AIR_CLAN_DEAD
  IF (§chatpos == 4) {
   SPEAK [Goblin_good_ally_misc] nop
   ACCEPT
  }
   SPEAK [goblin_water_repeat_mission] nop
  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_0008 SELF 
 SET £attached_object "NONE"
 SENDEVENT HIDE pole_0008 ""
 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 ATTACK_PLAYER {
 IF (§done == 1) ACCEPT
 SENDEVENT -g £friend COMBAT ""
 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 -----------------------------------------------------------
// ---------------------------------------------------------------------------------

//#