Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.rs.game.npc;
- import java.io.Serializable;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.concurrent.CopyOnWriteArrayList;
- import java.util.concurrent.TimeUnit;
- import com.rs.Settings;
- import com.rs.cache.loaders.ItemDefinitions;
- import com.rs.cache.loaders.NPCDefinitions;
- import com.rs.cores.CoresManager;
- import com.rs.game.Animation;
- import com.rs.game.Entity;
- import com.rs.game.Hit;
- import com.rs.game.Hit.HitLook;
- import com.rs.game.World;
- import com.rs.game.WorldTile;
- import com.rs.game.item.Item;
- import com.rs.game.minigames.wilderness.Wilderness;
- import com.rs.game.npc.combat.NPCCombat;
- import com.rs.game.npc.combat.NPCCombatDefinitions;
- import com.rs.game.npc.familiar.Familiar;
- import com.rs.game.player.Player;
- import com.rs.game.player.Skills;
- import com.rs.game.player.NPCDrops.CharmDrops;
- import com.rs.game.player.NPCDrops.CasketDrops;
- import com.rs.game.player.NPCDrops.CrystalKeyDrops;
- import com.rs.game.player.NPCDrops.RevenantDrops;
- import com.rs.game.tasks.WorldTask;
- import com.rs.game.tasks.WorldTasksManager;
- import com.rs.utils.Logger;
- import com.rs.utils.MapAreas;
- import com.rs.utils.NPCBonuses;
- import com.rs.utils.NPCCombatDefinitionsL;
- import com.rs.utils.NPCDrops;
- import com.rs.utils.Utils;
- import com.rs.game.SecondaryBar;
- import com.rs.game.route.RouteFinder;
- import com.rs.game.route.strategy.FixedTileStrategy;
- import com.rs.game.npc.NPC;
- import com.rs.game.npc.Drop;
- import com.rs.game.player.actions.HerbCleaning;
- import com.rs.game.player.content.Burying;
- import com.rs.game.player.content.FriendChatsManager;
- import com.rs.game.npc.Transformation;
- import com.rs.game.player.SlayerManager;
- public class NPC extends Entity implements Serializable {
- private static final long serialVersionUID = -4794678936277614443L;
- public static int NORMAL_WALK = 0x2, WATER_WALK = 0x4, FLY_WALK = 0x8;
- private int id;
- private WorldTile respawnTile;
- private int mapAreaNameHash;
- private boolean canBeAttackFromOutOfArea;
- private boolean randomwalk;
- private int[] bonuses;
- private boolean spawned;
- private transient NPCCombat combat;
- public WorldTile forceWalk;
- private int walkType;
- private transient double dropRateFactor;
- private long lastAttackedByTarget;
- private boolean cantInteract;
- private int capDamage;
- private int lureDelay;
- private boolean cantFollowUnderCombat;
- private boolean forceAgressive;
- private int forceTargetDistance;
- private boolean forceFollowClose;
- private boolean forceMultiAttacked;
- private boolean noDistanceCheck;
- private boolean intelligentRouteFinder;
- // npc masks
- private transient SecondaryBar nextSecondaryBar;
- private transient Transformation nextTransformation;
- // name changing masks
- private String name;
- private transient boolean changedName;
- private int combatLevel;
- private transient boolean changedCombatLevel;
- private transient boolean locked;
- private double charmDropPercentage;
- public NPC(int id, WorldTile tile, int mapAreaNameHash,
- boolean canBeAttackFromOutOfArea) {
- this(id, tile, mapAreaNameHash, canBeAttackFromOutOfArea, false);
- }
- public NPC(int id, WorldTile tile, int mapAreaNameHash,
- boolean canBeAttackFromOutOfArea, boolean spawned) {
- super(tile);
- this.id = id;
- this.respawnTile = new WorldTile(tile);
- this.mapAreaNameHash = mapAreaNameHash;
- this.canBeAttackFromOutOfArea = canBeAttackFromOutOfArea;
- this.spawned = spawned;
- this.charmDropPercentage = 0;
- combatLevel = -1;
- setHitpoints(getMaxHitpoints());
- setDirection(getRespawnDirection());
- setRandomWalk(getDefinitions().walkMask);
- setBonuses();
- combat = new NPCCombat(this);
- capDamage = -1;
- lureDelay = 12000;
- initEntity();
- World.addNPC(this);
- World.updateEntityRegion(this);
- loadMapRegions();
- checkMultiArea();
- }
- public void setBonuses() {
- bonuses = NPCBonuses.getBonuses(id);
- if (bonuses == null) {
- bonuses = new int[10];
- int level = getCombatLevel();
- for (int i = 0; i < bonuses.length; i++)
- bonuses[i] = level;
- }
- }
- @Override
- public boolean needMasksUpdate() {
- return super.needMasksUpdate() || nextSecondaryBar != null
- || nextTransformation != null || changedCombatLevel
- || changedName;
- }
- public void transformIntoNPC(int id) {
- setNPC(id);
- nextTransformation = new Transformation(id);
- }
- public void setNPC(int id) {
- this.id = id;
- bonuses = NPCBonuses.getBonuses(id);
- }
- @Override
- public void resetMasks() {
- super.resetMasks();
- nextTransformation = null;
- changedCombatLevel = false;
- changedName = false;
- nextSecondaryBar = null;
- }
- public int getMapAreaNameHash() {
- return mapAreaNameHash;
- }
- public void setCanBeAttackFromOutOfArea(boolean b) {
- canBeAttackFromOutOfArea = b;
- }
- public boolean canBeAttackFromOutOfArea() {
- return canBeAttackFromOutOfArea;
- }
- public NPCDefinitions getDefinitions() {
- return NPCDefinitions.getNPCDefinitions(id);
- }
- public NPCCombatDefinitions getCombatDefinitions() {
- return NPCCombatDefinitionsL.getNPCCombatDefinitions(id);
- }
- @Override
- public int getMaxHitpoints() {
- return getCombatDefinitions().getHitpoints();
- }
- public int getId() {
- return id;
- }
- public void processNPC() {
- if (isDead() || locked)
- return;
- if (id == 1512) {
- faceWorldTile(this, "east");
- setRandomWalk(0);
- setName("Account Manager");
- }
- if (id == 4290)
- setRandomWalk(0);
- if (id == 2593 && getX() == 3096 && getY() == 3491) {
- faceWorldTile(this, "west");
- }
- if (id == 2593 && getX() == 3097 && getY() == 3494) {
- faceWorldTile(this, "north");
- }
- if (id == 9711) {
- faceWorldTile(this, "west");
- }
- if (id == 14062) {
- setName("Pk Points Shop");
- faceWorldTile(this, "west");
- }
- if (id == 13463) {
- faceWorldTile(this, "south");
- setName("Experience Manager");
- }
- if (id == 534) {
- setName("Skilling Tools");
- }
- if (id == 804) {
- faceWorldTile(this, "south");
- setName("Hide Tanner");
- setRandomWalk(0);
- }
- if (id == 7950) {
- setName("Blacklist Manager");
- setRandomWalk(0);
- }
- if (id == 2676) {
- faceWorldTile(this, "east");
- setRandomWalk(0);
- setName("Appearence");
- }
- if (id == 2886) {
- for (Player player : World.getPlayers()) {
- if (player == null)
- continue;
- if (player.getAttackedByDelay() > Utils.currentTimeMillis()
- && !World.atMultiArea(player))
- return;
- if (withinDistance(player, 1)) {
- transformIntoNPC(2885);
- reset();
- setCantFollowUnderCombat(false);
- setRandomWalk(getDefinitions().walkMask);
- setForceAgressive(true);
- setNoDistanceCheck(false);
- setTarget(player);
- }
- }
- }
- if (id == 2453) {
- for (Player player : World.getPlayers()) {
- if (player == null)
- continue;
- if (player.getAttackedByDelay() > Utils.currentTimeMillis()
- && !World.atMultiArea(player))
- return;
- if (withinDistance(player, 1)) {
- transformIntoNPC(2452);
- reset();
- setCantFollowUnderCombat(false);
- setRandomWalk(getDefinitions().walkMask);
- setForceAgressive(true);
- setNoDistanceCheck(false);
- setTarget(player);
- }
- }
- }
- if (id == 1266) {
- for (Player player : World.getPlayers()) {
- if (player == null)
- continue;
- if (player.getAttackedByDelay() > Utils.currentTimeMillis()
- && !World.atMultiArea(player))
- return;
- if (withinDistance(player, 1)) {
- transformIntoNPC(1265);
- reset();
- setCantFollowUnderCombat(false);
- setRandomWalk(getDefinitions().walkMask);
- setForceAgressive(true);
- setNoDistanceCheck(false);
- setTarget(player);
- }
- }
- }
- if (id == 1268) {
- for (Player player : World.getPlayers()) {
- if (player == null)
- continue;
- if (player.getAttackedByDelay() > Utils.currentTimeMillis()
- && !World.atMultiArea(player))
- return;
- if (withinDistance(player, 1)) {
- transformIntoNPC(1267);
- reset();
- setCantFollowUnderCombat(false);
- setRandomWalk(getDefinitions().walkMask);
- setForceAgressive(true);
- setNoDistanceCheck(false);
- setTarget(player);
- }
- }
- }
- if (id == 2890) {
- for (Player player : World.getPlayers()) {
- if (player == null)
- continue;
- if (player.getAttackedByDelay() > Utils.currentTimeMillis()
- && !World.atMultiArea(player))
- return;
- if (withinDistance(player, 1)) {
- transformIntoNPC(2889);
- reset();
- setCantFollowUnderCombat(false);
- setRandomWalk(getDefinitions().walkMask);
- setForceAgressive(true);
- setNoDistanceCheck(false);
- setTarget(player);
- }
- }
- }
- if (!combat.process()) {
- if (!isForceWalking()) {
- if (!cantInteract) {
- if (!checkAgressivity()) {
- if (getFreezeDelay() < Utils.currentTimeMillis()) {
- if (!hasWalkSteps()
- && (walkType & NORMAL_WALK) != 0) {
- boolean can = false;
- for (int i = 0; i < 2; i++) {
- if (Math.random() * 1000.0 < 100.0) {
- can = true;
- break;
- }
- }
- if (can) {
- int moveX = (int) Math
- .round(Math.random() * 10.0 - 5.0);
- int moveY = (int) Math
- .round(Math.random() * 10.0 - 5.0);
- resetWalkSteps();
- if (getMapAreaNameHash() != -1) {
- if (!MapAreas.isAtArea(
- getMapAreaNameHash(), this)) {
- forceWalkRespawnTile();
- return;
- }
- addWalkSteps(getX() + moveX, getY()
- + moveY, 5,
- (walkType & FLY_WALK) == 0);
- } else
- addWalkSteps(
- respawnTile.getX() + moveX,
- respawnTile.getY() + moveY, 5,
- (walkType & FLY_WALK) == 0);
- }
- }
- }
- }
- }
- }
- }
- if (isForceWalking()) {
- if (getFreezeDelay() < Utils.currentTimeMillis()) {
- if (getX() != forceWalk.getX() || getY() != forceWalk.getY()) {
- if (!hasWalkSteps()) {
- int steps = RouteFinder.findRoute(
- RouteFinder.WALK_ROUTEFINDER, getX(), getY(),
- getPlane(), getSize(), new FixedTileStrategy(
- forceWalk.getX(), forceWalk.getY()),
- true);
- int[] bufferX = RouteFinder.getLastPathBufferX();
- int[] bufferY = RouteFinder.getLastPathBufferY();
- for (int i = steps - 1; i >= 0; i--) {
- if (!addWalkSteps(bufferX[i], bufferY[i], 25, true))
- break;
- }
- }
- if (!hasWalkSteps()) {
- setNextWorldTile(new WorldTile(forceWalk));
- forceWalk = null;
- }
- } else
- forceWalk = null;
- }
- }
- }
- @Override
- public void processEntity() {
- super.processEntity();
- processNPC();
- }
- public int getRespawnDirection() {
- NPCDefinitions definitions = getDefinitions();
- if (definitions.anInt853 << 32 != 0 && definitions.respawnDirection > 0
- && definitions.respawnDirection <= 8)
- return (4 + definitions.respawnDirection) << 11;
- return 0;
- }
- /*
- * forces npc to random walk even if cache says no, used because of fake
- * cache information
- */
- /*
- * private static boolean forceRandomWalk(int npcId) { switch (npcId) { case
- * 11226: return true; case 3341: case 3342: case 3343: return true;
- * default: return false; /* default: return
- * NPCDefinitions.getNPCDefinitions(npcId).name .equals("Icy Bones");
- */
- /*
- * } }
- */
- @Override
- public void handleIngoingHit(final Hit hit) {
- if (hit.getLook() != HitLook.MELEE_DAMAGE
- && hit.getLook() != HitLook.RANGE_DAMAGE
- && hit.getLook() != HitLook.MAGIC_DAMAGE)
- return;
- Entity source = hit.getSource();
- if (source == null)
- return;
- }
- @Override
- public void reset() {
- super.reset();
- setDirection(getRespawnDirection());
- combat.reset();
- setBonuses(); // back to real bonuses
- forceWalk = null;
- }
- @Override
- public void finish() {
- if (hasFinished())
- return;
- setFinished(true);
- World.updateEntityRegion(this);
- World.removeNPC(this);
- }
- public void setRespawnTask() {
- if (!hasFinished()) {
- reset();
- setLocation(respawnTile);
- finish();
- }
- CoresManager.slowExecutor.schedule(new Runnable() {
- @Override
- public void run() {
- try {
- spawn();
- } catch (Throwable e) {
- Logger.handle(e);
- }
- }
- }, getCombatDefinitions().getRespawnDelay() * 600,
- TimeUnit.MILLISECONDS);
- }
- public void deserialize() {
- if (combat == null)
- combat = new NPCCombat(this);
- spawn();
- }
- public void spawn() {
- setFinished(false);
- World.addNPC(this);
- setLastRegionId(0);
- World.updateEntityRegion(this);
- loadMapRegions();
- checkMultiArea();
- }
- public NPCCombat getCombat() {
- return combat;
- }
- @Override
- public void sendDeath(Entity source) {
- final NPCCombatDefinitions defs = getCombatDefinitions();
- resetWalkSteps();
- combat.removeTarget();
- source.setAttackedByDelay(defs.getDeathDelay());
- setNextAnimation(null);
- setNextAnimation(new Animation(defs.getDeathEmote()));
- WorldTasksManager.schedule(new WorldTask() {
- int loop;
- @Override
- public void run() {
- if (loop == 0) {
- } else if (loop >= defs.getDeathDelay()) {
- drop();
- reset();
- setLocation(respawnTile);
- finish();
- if (!isSpawned())
- setRespawnTask();
- stop();
- }
- loop++;
- }
- }, 0, 1);
- }
- private void addAvalonPoints(Player killer, NPC npc) {
- killer.setAvalonPoints(killer.getAvalonPoints()
- + (getCombatLevel() * 4));
- killer.getPackets().sendGameMessage(
- "You gain " + getCombatLevel() * 4
- + " avalon points for killing " + getName() + ".");
- }
- public void drop() {
- try {
- Drop[] drops = NPCDrops.getDrops(id);
- if (drops == null)
- return;
- Player killer = getMostDamageReceivedSourcePlayer();
- if (killer == null)
- return;
- if (getId() == 13478)
- RevenantDrops.sendRandomDrop(killer, this);
- CharmDrops.sendDrop(killer, this);
- CasketDrops.sendDrop(killer, this);
- CrystalKeyDrops.sendDrop(killer, this);
- if (getId() == 6260) {
- addAvalonPoints(killer, this);
- killer.bandosKilled++;
- killer.getPackets().sendGameMessage(
- "You have killed in total of " + killer.bandosKilled
- + " bandos bosses.");
- }
- if (getId() == 6222) {
- addAvalonPoints(killer, this);
- killer.armadylKilled++;
- killer.getPackets().sendGameMessage(
- "You have killed in total of " + killer.armadylKilled
- + " armadyl bosses.");
- }
- if (getId() == 6247) {
- addAvalonPoints(killer, this);
- killer.saradominKilled++;
- killer.getPackets().sendGameMessage(
- "You have killed in total of " + killer.saradominKilled
- + " saradomin bosses.");
- }
- if (getId() == 6203) {
- addAvalonPoints(killer, this);
- killer.zamorakKilled++;
- killer.getPackets().sendGameMessage(
- "You have killed in total of " + killer.zamorakKilled
- + " zamorak bosses.");
- }
- if (getId() == 8133) {
- addAvalonPoints(killer, this);
- killer.corpKilled++;
- killer.getPackets().sendGameMessage(
- "You have killed in total of " + killer.corpKilled
- + " corporeal beasts.");
- }
- if (killer.isAtWild()) {
- killer.setAvalonPoints(killer.getAvalonPoints()
- + (getCombatLevel() / 2 * Wilderness
- .getWildLevel(killer)) / 2);
- killer.getPackets().sendGameMessage(
- "You gain "
- + (getCombatLevel() / 2 * Wilderness
- .getWildLevel(killer)) / 2
- + " avalon points for killing " + getName()
- + " level " + getCombatLevel()
- + " in wildy level "
- + Wilderness.getWildLevel(killer) + ".");
- /*
- * killer.getPackets().sendGameMessage( "Combat level / 2 (" +
- * getCombatLevel() / 2 + ") * Wildy level (" +
- * Wilderness.getWildLevel(killer) + ") / 2 = " +
- * (getCombatLevel() / 2 * Wilderness .getWildLevel(killer)) / 2
- * + " avalon points.");
- */
- }
- Player otherPlayer = killer.getSlayerManager().getSocialPlayer();
- SlayerManager manager = killer.getSlayerManager();
- if (manager.isValidTask(getName()))
- manager.checkCompletedTask(getDamageReceived(killer),
- otherPlayer != null ? getDamageReceived(otherPlayer)
- : 0);
- Drop[] possibleDrops = new Drop[drops.length];
- int possibleDropsCount = 0;
- for (Drop drop : drops) {
- if (drop.getRate() == 100)
- sendDrop(killer, drop);
- else {
- if ((Utils.getRandomDouble(99) + 1) <= drop.getRate()) {
- possibleDrops[possibleDropsCount++] = drop;
- }
- }
- }
- if (possibleDropsCount > 0)
- sendDrop(killer,
- possibleDrops[Utils.getRandom(possibleDropsCount - 1)]);
- } catch (Exception e) {
- e.printStackTrace();
- } catch (Error e) {
- e.printStackTrace();
- }
- }
- public void sendDrop(Player player, Drop drop) {
- boolean sendDp = true;
- int size = getSize();
- String dropName = ItemDefinitions.getItemDefinitions(drop.getItemId())
- .getName().toLowerCase();
- Item item = ItemDefinitions.getItemDefinitions(drop.getItemId())
- .isStackable() ? new Item(drop.getItemId(),
- (drop.getMinAmount() * Settings.DROP_RATE)
- + Utils.getRandom(drop.getExtraAmount()
- * Settings.DROP_RATE)) : new Item(
- drop.getItemId(), (drop.getMinAmount() + Utils.getRandom(drop
- .getExtraAmount())));
- /* LootShare/CoinShare */
- FriendChatsManager fc = player.getCurrentFriendChat();
- if (player.isToogleLootShare()) {
- if (fc != null) {
- CopyOnWriteArrayList<Player> players = fc.getPlayers();
- CopyOnWriteArrayList<Player> playersWithLs = new CopyOnWriteArrayList<Player>();
- for (Player p : players) {
- if (p.isToogleLootShare()
- && p.getRegionId() == player.getRegionId())
- playersWithLs.add(p);
- }
- Player luckyPlayer = playersWithLs
- .get((int) (Math.random() * playersWithLs.size()));
- if (getId() == 13478)
- RevenantDrops.sendRandomDrop(luckyPlayer, this);
- CharmDrops.sendDrop(luckyPlayer, this);
- CasketDrops.sendDrop(luckyPlayer, this);
- CrystalKeyDrops.sendDrop(luckyPlayer, this);
- World.updateGroundItem(item, new WorldTile(getCoordFaceX(size),
- getCoordFaceY(size), getPlane()), luckyPlayer, 60, 0);
- luckyPlayer.sm(String.format(
- "<col=216902>You received: %s x %s. (" + getName()
- + ") </col>",
- Utils.getFormattedNumber(item.getAmount(), ','),
- dropName));
- for (Player p : playersWithLs) {
- if (!p.equals(luckyPlayer))
- p.sm(String.format(
- "%s received: %s x %s. (" + getName() + ") ",
- luckyPlayer.getDisplayName(),
- Utils.getFormattedNumber(item.getAmount(), ','),
- dropName));
- }
- }
- sendDp = false;
- }
- /* End of LootShare/CoinShare */
- if (player.getInventory().containsItem(18337, 1)// Bonecrusher
- && item.getDefinitions().getName().toLowerCase()
- .contains("bones")) {
- player.getSkills().addXp(Skills.PRAYER,
- Burying.Bone.forId(drop.getItemId()).getExperience());
- }
- if (player.getInventory().containsItem(19675, 1)// Herbicide
- && item.getDefinitions().getName().toLowerCase()
- .contains("grimy")) {
- if (player.getSkills().getLevelForXp(Skills.HERBLORE) >= HerbCleaning
- .getHerb(item.getId()).getLevel()) {
- player.getSkills()
- .addXp(Skills.HERBLORE,
- HerbCleaning.getHerb(drop.getItemId())
- .getExperience() * 2);
- }
- }
- if (sendDp)
- World.updateGroundItem(item, new WorldTile(getCoordFaceX(size),
- getCoordFaceY(size), getPlane()), player, 60, 0);
- if (dropName.contains("pernix") || dropName.contains("torva")
- || dropName.contains("virtus") || dropName.contains("bandos")
- || dropName.contains("hilt") || dropName.contains("steadfast")
- || dropName.contains("glaiven")
- || dropName.contains("saradomin sword")
- || dropName.contains("ragefire") || dropName.contains("visage")
- || dropName.contains("sigil") || dropName.contains("armadyl")
- || dropName.contains("zaryte")
- || dropName.contains("dragon claws"))
- World.sendWorldMessage(
- "<img=7><col=36648b>News: " + player.getDisplayName()
- + " has recieved " + dropName + " as a loot!",
- false);
- }
- public void setNextNPCTransformation(int id) {
- setNPC(id);
- nextTransformation = new Transformation(id);
- if (getCustomCombatLevel() != -1)
- changedCombatLevel = true;
- if (getCustomName() != null)
- changedName = true;
- }
- @Override
- public int getSize() {
- switch (id) {
- case 15202:
- return 2;
- case 15201:
- return 1;
- case 1459:
- return 2;
- case 6260:
- return 3;
- }
- return getDefinitions().size;
- }
- public int getMaxHit() {
- return getCombatDefinitions().getMaxHit();
- }
- public int[] getBonuses() {
- return bonuses;
- }
- @Override
- public double getMagePrayerMultiplier() {
- if (this instanceof Familiar)
- return 0.6;
- return 0;
- }
- @Override
- public double getRangePrayerMultiplier() {
- if (this instanceof Familiar)
- return 0.6;
- return 0;
- }
- @Override
- public double getMeleePrayerMultiplier() {
- if (this instanceof Familiar)
- return 0.6;
- return 0;
- }
- public WorldTile getRespawnTile() {
- return respawnTile;
- }
- public boolean isUnderCombat() {
- return combat.underCombat();
- }
- @Override
- public void setAttackedBy(Entity target) {
- super.setAttackedBy(target);
- if (target == combat.getTarget()
- && !(combat.getTarget() instanceof Familiar))
- lastAttackedByTarget = Utils.currentTimeMillis();
- }
- public boolean canBeAttackedByAutoRelatie() {
- return Utils.currentTimeMillis() - lastAttackedByTarget > lureDelay;
- }
- public boolean isForceWalking() {
- return forceWalk != null;
- }
- public void setTarget(Entity entity) {
- if (isForceWalking())
- return;
- combat.setTarget(entity);
- lastAttackedByTarget = Utils.currentTimeMillis();
- }
- public void removeTarget() {
- if (combat.getTarget() == null)
- return;
- combat.removeTarget();
- }
- public void forceWalkRespawnTile() {
- setForceWalk(respawnTile);
- }
- public void setForceWalk(WorldTile tile) {
- resetWalkSteps();
- forceWalk = tile;
- }
- public boolean hasForceWalk() {
- return forceWalk != null;
- }
- public ArrayList<Entity> getPossibleTargets(boolean checkNPCs,
- boolean checkPlayers) {
- int size = getSize();
- ArrayList<Entity> possibleTarget = new ArrayList<Entity>();
- for (int regionId : getMapRegionsIds()) {
- if (checkPlayers) {
- List<Integer> playerIndexes = World.getRegion(regionId)
- .getPlayerIndexes();
- if (playerIndexes != null) {
- for (int playerIndex : playerIndexes) {
- Player player = World.getPlayers().get(playerIndex);
- if (player == null
- || player.isDead()
- || player.hasFinished()
- || player.getUsername().equalsIgnoreCase(
- "ghost")
- || !player.isRunning()
- || player.getAppearence().isHidden()
- || !Utils
- .isOnRange(
- getX(),
- getY(),
- size,
- player.getX(),
- player.getY(),
- player.getSize(),
- forceTargetDistance > 0 ? forceTargetDistance
- : 16)
- || (!forceMultiAttacked
- && (!isAtMultiArea() || !player
- .isAtMultiArea()) && (player
- .getAttackedBy() != this && (player
- .getAttackedByDelay() > Utils
- .currentTimeMillis() || player
- .getFindTargetDelay() > Utils
- .currentTimeMillis())))
- || !clipedProjectile(player, false)
- || (!forceAgressive
- && !Wilderness.isAtWild(this) && player
- .getSkills()
- .getCombatLevelWithSummoning() >= getCombatLevel() * 2))
- continue;
- possibleTarget.add(player);
- }
- }
- }
- if (checkNPCs) {
- List<Integer> npcsIndexes = World.getRegion(regionId)
- .getNPCsIndexes();
- if (npcsIndexes != null) {
- for (int npcIndex : npcsIndexes) {
- NPC npc = World.getNPCs().get(npcIndex);
- if (npc == null
- || npc == this
- || npc.isDead()
- || npc.hasFinished()
- || !Utils
- .isOnRange(
- getX(),
- getY(),
- size,
- npc.getX(),
- npc.getY(),
- npc.getSize(),
- forceTargetDistance > 0 ? forceTargetDistance
- : 16)
- || !npc.getDefinitions().hasAttackOption()
- || ((!isAtMultiArea() || !npc.isAtMultiArea())
- && npc.getAttackedBy() != this && npc
- .getAttackedByDelay() > Utils
- .currentTimeMillis())
- || !clipedProjectile(npc, false))
- continue;
- possibleTarget.add(npc);
- }
- }
- }
- }
- return possibleTarget;
- }
- public ArrayList<Entity> getPossibleTargets() {
- return getPossibleTargets(false, true);
- }
- public boolean checkAgressivity() {
- if (!forceAgressive) {
- NPCCombatDefinitions defs = getCombatDefinitions();
- if (defs.getAgressivenessType() == NPCCombatDefinitions.PASSIVE)
- return false;
- }
- ArrayList<Entity> possibleTarget = getPossibleTargets();
- if (!possibleTarget.isEmpty()) {
- Entity target = possibleTarget.get(Utils.random(possibleTarget
- .size()));
- setTarget(target);
- target.setAttackedBy(target);
- target.setFindTargetDelay(Utils.currentTimeMillis() + 10000);
- return true;
- }
- return false;
- }
- public boolean isCantInteract() {
- return cantInteract;
- }
- public void setCantInteract(boolean cantInteract) {
- this.cantInteract = cantInteract;
- if (cantInteract)
- combat.reset();
- }
- public int getCapDamage() {
- return capDamage;
- }
- public void setCapDamage(int capDamage) {
- this.capDamage = capDamage;
- }
- public int getLureDelay() {
- return lureDelay;
- }
- public void setLureDelay(int lureDelay) {
- this.lureDelay = lureDelay;
- }
- public boolean isCantFollowUnderCombat() {
- return cantFollowUnderCombat;
- }
- public void setCantFollowUnderCombat(boolean canFollowUnderCombat) {
- this.cantFollowUnderCombat = canFollowUnderCombat;
- }
- public Transformation getNextTransformation() {
- return nextTransformation;
- }
- @Override
- public String toString() {
- return getDefinitions().name + " - " + id + " - " + getX() + " "
- + getY() + " " + getPlane();
- }
- public boolean isForceAgressive() {
- return forceAgressive;
- }
- public void setForceAgressive(boolean forceAgressive) {
- this.forceAgressive = forceAgressive;
- }
- public int getForceTargetDistance() {
- return forceTargetDistance;
- }
- public void setForceTargetDistance(int forceTargetDistance) {
- this.forceTargetDistance = forceTargetDistance;
- }
- public boolean isForceFollowClose() {
- return forceFollowClose;
- }
- public void setForceFollowClose(boolean forceFollowClose) {
- this.forceFollowClose = forceFollowClose;
- }
- public boolean isForceMultiAttacked() {
- return forceMultiAttacked;
- }
- public void setForceMultiAttacked(boolean forceMultiAttacked) {
- this.forceMultiAttacked = forceMultiAttacked;
- }
- public boolean hasRandomWalk() {
- return randomwalk;
- }
- public void setRandomWalk(int forceRandomWalk) {
- this.walkType = forceRandomWalk;
- }
- public String getCustomName() {
- return name;
- }
- public boolean isIntelligentRouteFinder() {
- return intelligentRouteFinder;
- }
- public void setIntelligentRouteFinder(boolean intelligentRouteFinder) {
- this.intelligentRouteFinder = intelligentRouteFinder;
- }
- public void setName(String string) {
- this.name = getDefinitions().name.equals(string) ? null : string;
- changedName = true;
- }
- public int getCustomCombatLevel() {
- return combatLevel;
- }
- public int getCombatLevel() {
- return combatLevel >= 0 ? combatLevel : getDefinitions().combatLevel;
- }
- public String getName() {
- return name != null ? name : getDefinitions().name;
- }
- public void setCombatLevel(int level) {
- combatLevel = getDefinitions().combatLevel == level ? -1 : level;
- changedCombatLevel = true;
- }
- public boolean hasChangedName() {
- return changedName;
- }
- public boolean hasChangedCombatLevel() {
- return changedCombatLevel;
- }
- public WorldTile getMiddleWorldTile() {
- int size = getSize();
- return new WorldTile(getCoordFaceX(size), getCoordFaceY(size),
- getPlane());
- }
- public boolean isSpawned() {
- return spawned;
- }
- public void setSpawned(boolean spawned) {
- this.spawned = spawned;
- }
- public boolean isNoDistanceCheck() {
- return noDistanceCheck;
- }
- public void setNoDistanceCheck(boolean noDistanceCheck) {
- this.noDistanceCheck = noDistanceCheck;
- }
- public boolean withinDistance(Player tile, int distance) {
- return super.withinDistance(tile, distance);
- }
- /**
- * Gets the locked.
- *
- * @return The locked.
- */
- public boolean isLocked() {
- return locked;
- }
- /**
- * Sets the locked.
- *
- * @param locked
- * The locked to set.
- */
- public void setLocked(boolean locked) {
- this.locked = locked;
- }
- public double getCharmDropPercentage() {
- return charmDropPercentage;
- }
- public void setCharmDropPercentage(double charmDropPercentage) {
- this.charmDropPercentage = charmDropPercentage;
- }
- public SecondaryBar getNextSecondaryBar() {
- return nextSecondaryBar;
- }
- public void setNextSecondaryBar(SecondaryBar secondaryBar) {
- this.nextSecondaryBar = secondaryBar;
- }
- public double getDropRateFactor() {
- return dropRateFactor;
- }
- public void setDropRateFactor(double dropRateFactor) {
- this.dropRateFactor = dropRateFactor;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement