@Override protected boolean thinkActive() { NpcInstance actor = getActor(); Player player; // follow the player double distance; if (targetPlayers != null && targetPlayers.size() > 0 && followTargetIndex > 0) { player = targetPlayers.get(followTargetIndex - 1); // in case the player set to follow is null, fall back to the first player in the list if (player == null) player = targetPlayers.get(0); distance = (int) actor.getDistance(player); if (distance > maxFollowDistance) { if (GeoEngine.canSeeTarget(actor, player, false)) { // in case the NPC can see the player actor.setRunning(); Location loc = new Location( player.getX() + Rnd.get(-60, 60), player.getY() + Rnd.get(-60, 60), player.getZ()); actor.followToCharacter(loc, player, minFollowDistance, false); } else { // in case the NPC cannot see the player, then teleport straight to him actor.teleToLocation(player.getLoc().getRandomLoc(100)); } return true; } } return startAttack(); }
@Override protected boolean thinkActive() { NpcInstance actor = getActor(); Creature target = actor.getFollowTarget(); if (target == null || !(target instanceof Player)) { if (actor != null) actor.deleteMe(); return false; } int npcId = actor.getNpcId(); int[][] coords; NpcString string; NpcString end_String; // Select coords switch (npcId) { case SEARCHING_MYST_POWER_SOLDIER: coords = SMP_COORDS; string = SEARCHING_MYST_POWER_STRING; end_String = NpcString.S1_THAT_MAN_IN_FRONT_IS_IBANE; break; case BACKUP_SEEKERS_ASSASSIN: coords = BS_COORDS; string = BACKUP_SEEKERS_STRING; end_String = NpcString.TALK_TO_THAT_APPRENTICE_AND_GET_ON_KOOKARU; break; case GOING_INTO_REAL_WAR_SOLDIER: double distLeft = target.getDistance(GRW_COORDS_LEFT[0][0], GRW_COORDS_LEFT[0][1], GRW_COORDS_LEFT[0][2]); double distRight = target.getDistance( GRW_COORDS_RIGHT[0][0], GRW_COORDS_RIGHT[0][1], GRW_COORDS_RIGHT[0][2]); if (distLeft <= distRight) coords = GRW_COORDS_LEFT; else coords = GRW_COORDS_RIGHT; string = GOING_INTO_REAL_WAR_STRING; end_String = NpcString.S1_THAT_MAN_IN_FRONT_IS_HOLDEN; break; default: return false; } // Нужно всё это переписать. // This NPC is running actor.setRunning(); if (actor.getDistance(target) < 100 || currentState == 0 || currentState >= coords.length) { if (currentState < coords.length) { actor.moveToLocation( coords[currentState][0], coords[currentState][1], coords[currentState][2], Rnd.get(0, 50), true); if (actor.getDestination() == null) { ++currentState; } } else { Functions.npcSay(actor, end_String, target.getName()); actor.deleteMe(); } } else if (lastSayTime + SAY_INTERVAL < System.currentTimeMillis() && actor.getDestination() == null) { int heading = actor.calcHeading(target.getX(), target.getY()); actor.setHeading(heading); actor.broadcastPacket(new ExRotation(actor.getObjectId(), heading)); lastSayTime = System.currentTimeMillis(); Functions.npcSay(actor, string, target.getName()); } return true; }