Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.45 KB | None | 0 0
  1. package com.rs.game.npc;
  2.  
  3. import java.io.Serializable;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import java.util.concurrent.CopyOnWriteArrayList;
  7. import java.util.concurrent.TimeUnit;
  8.  
  9. import com.rs.Settings;
  10. import com.rs.cache.loaders.ItemDefinitions;
  11. import com.rs.cache.loaders.NPCDefinitions;
  12. import com.rs.cores.CoresManager;
  13. import com.rs.game.Animation;
  14. import com.rs.game.Entity;
  15. import com.rs.game.Hit;
  16. import com.rs.game.Hit.HitLook;
  17. import com.rs.game.World;
  18. import com.rs.game.WorldTile;
  19. import com.rs.game.item.Item;
  20. import com.rs.game.minigames.wilderness.Wilderness;
  21. import com.rs.game.npc.combat.NPCCombat;
  22. import com.rs.game.npc.combat.NPCCombatDefinitions;
  23. import com.rs.game.npc.familiar.Familiar;
  24. import com.rs.game.player.Player;
  25. import com.rs.game.player.Skills;
  26. import com.rs.game.player.NPCDrops.CharmDrops;
  27. import com.rs.game.player.NPCDrops.CasketDrops;
  28. import com.rs.game.player.NPCDrops.CrystalKeyDrops;
  29. import com.rs.game.player.NPCDrops.RevenantDrops;
  30. import com.rs.game.tasks.WorldTask;
  31. import com.rs.game.tasks.WorldTasksManager;
  32. import com.rs.utils.Logger;
  33. import com.rs.utils.MapAreas;
  34. import com.rs.utils.NPCBonuses;
  35. import com.rs.utils.NPCCombatDefinitionsL;
  36. import com.rs.utils.NPCDrops;
  37. import com.rs.utils.Utils;
  38. import com.rs.game.SecondaryBar;
  39. import com.rs.game.route.RouteFinder;
  40. import com.rs.game.route.strategy.FixedTileStrategy;
  41. import com.rs.game.npc.NPC;
  42. import com.rs.game.npc.Drop;
  43. import com.rs.game.player.actions.HerbCleaning;
  44. import com.rs.game.player.content.Burying;
  45. import com.rs.game.player.content.FriendChatsManager;
  46. import com.rs.game.npc.Transformation;
  47. import com.rs.game.player.SlayerManager;
  48.  
  49. public class NPC extends Entity implements Serializable {
  50.  
  51. private static final long serialVersionUID = -4794678936277614443L;
  52.  
  53. public static int NORMAL_WALK = 0x2, WATER_WALK = 0x4, FLY_WALK = 0x8;
  54.  
  55. private int id;
  56. private WorldTile respawnTile;
  57. private int mapAreaNameHash;
  58. private boolean canBeAttackFromOutOfArea;
  59. private boolean randomwalk;
  60. private int[] bonuses;
  61. private boolean spawned;
  62. private transient NPCCombat combat;
  63. public WorldTile forceWalk;
  64. private int walkType;
  65.  
  66. private transient double dropRateFactor;
  67.  
  68. private long lastAttackedByTarget;
  69. private boolean cantInteract;
  70. private int capDamage;
  71. private int lureDelay;
  72. private boolean cantFollowUnderCombat;
  73. private boolean forceAgressive;
  74. private int forceTargetDistance;
  75. private boolean forceFollowClose;
  76. private boolean forceMultiAttacked;
  77. private boolean noDistanceCheck;
  78. private boolean intelligentRouteFinder;
  79.  
  80. // npc masks
  81. private transient SecondaryBar nextSecondaryBar;
  82. private transient Transformation nextTransformation;
  83. // name changing masks
  84. private String name;
  85. private transient boolean changedName;
  86. private int combatLevel;
  87. private transient boolean changedCombatLevel;
  88. private transient boolean locked;
  89.  
  90. private double charmDropPercentage;
  91.  
  92. public NPC(int id, WorldTile tile, int mapAreaNameHash,
  93. boolean canBeAttackFromOutOfArea) {
  94. this(id, tile, mapAreaNameHash, canBeAttackFromOutOfArea, false);
  95. }
  96.  
  97. public NPC(int id, WorldTile tile, int mapAreaNameHash,
  98. boolean canBeAttackFromOutOfArea, boolean spawned) {
  99. super(tile);
  100. this.id = id;
  101. this.respawnTile = new WorldTile(tile);
  102. this.mapAreaNameHash = mapAreaNameHash;
  103. this.canBeAttackFromOutOfArea = canBeAttackFromOutOfArea;
  104. this.spawned = spawned;
  105. this.charmDropPercentage = 0;
  106. combatLevel = -1;
  107. setHitpoints(getMaxHitpoints());
  108. setDirection(getRespawnDirection());
  109. setRandomWalk(getDefinitions().walkMask);
  110. setBonuses();
  111. combat = new NPCCombat(this);
  112. capDamage = -1;
  113. lureDelay = 12000;
  114. initEntity();
  115. World.addNPC(this);
  116. World.updateEntityRegion(this);
  117. loadMapRegions();
  118. checkMultiArea();
  119. }
  120.  
  121. public void setBonuses() {
  122. bonuses = NPCBonuses.getBonuses(id);
  123. if (bonuses == null) {
  124. bonuses = new int[10];
  125. int level = getCombatLevel();
  126. for (int i = 0; i < bonuses.length; i++)
  127. bonuses[i] = level;
  128. }
  129. }
  130.  
  131. @Override
  132. public boolean needMasksUpdate() {
  133. return super.needMasksUpdate() || nextSecondaryBar != null
  134. || nextTransformation != null || changedCombatLevel
  135. || changedName;
  136. }
  137.  
  138. public void transformIntoNPC(int id) {
  139. setNPC(id);
  140. nextTransformation = new Transformation(id);
  141. }
  142.  
  143. public void setNPC(int id) {
  144. this.id = id;
  145. bonuses = NPCBonuses.getBonuses(id);
  146. }
  147.  
  148. @Override
  149. public void resetMasks() {
  150. super.resetMasks();
  151. nextTransformation = null;
  152. changedCombatLevel = false;
  153. changedName = false;
  154. nextSecondaryBar = null;
  155. }
  156.  
  157. public int getMapAreaNameHash() {
  158. return mapAreaNameHash;
  159. }
  160.  
  161. public void setCanBeAttackFromOutOfArea(boolean b) {
  162. canBeAttackFromOutOfArea = b;
  163. }
  164.  
  165. public boolean canBeAttackFromOutOfArea() {
  166. return canBeAttackFromOutOfArea;
  167. }
  168.  
  169. public NPCDefinitions getDefinitions() {
  170. return NPCDefinitions.getNPCDefinitions(id);
  171. }
  172.  
  173. public NPCCombatDefinitions getCombatDefinitions() {
  174. return NPCCombatDefinitionsL.getNPCCombatDefinitions(id);
  175. }
  176.  
  177. @Override
  178. public int getMaxHitpoints() {
  179. return getCombatDefinitions().getHitpoints();
  180. }
  181.  
  182. public int getId() {
  183. return id;
  184. }
  185.  
  186. public void processNPC() {
  187. if (isDead() || locked)
  188. return;
  189. if (id == 1512) {
  190. faceWorldTile(this, "east");
  191. setRandomWalk(0);
  192. setName("Account Manager");
  193. }
  194. if (id == 4290)
  195. setRandomWalk(0);
  196. if (id == 2593 && getX() == 3096 && getY() == 3491) {
  197. faceWorldTile(this, "west");
  198. }
  199. if (id == 2593 && getX() == 3097 && getY() == 3494) {
  200. faceWorldTile(this, "north");
  201. }
  202. if (id == 9711) {
  203. faceWorldTile(this, "west");
  204. }
  205. if (id == 14062) {
  206. setName("Pk Points Shop");
  207. faceWorldTile(this, "west");
  208. }
  209. if (id == 13463) {
  210. faceWorldTile(this, "south");
  211. setName("Experience Manager");
  212. }
  213. if (id == 534) {
  214. setName("Skilling Tools");
  215. }
  216. if (id == 804) {
  217. faceWorldTile(this, "south");
  218. setName("Hide Tanner");
  219. setRandomWalk(0);
  220. }
  221. if (id == 7950) {
  222. setName("Blacklist Manager");
  223. setRandomWalk(0);
  224. }
  225. if (id == 2676) {
  226. faceWorldTile(this, "east");
  227. setRandomWalk(0);
  228. setName("Appearence");
  229. }
  230.  
  231. if (id == 2886) {
  232. for (Player player : World.getPlayers()) {
  233. if (player == null)
  234. continue;
  235. if (player.getAttackedByDelay() > Utils.currentTimeMillis()
  236. && !World.atMultiArea(player))
  237. return;
  238. if (withinDistance(player, 1)) {
  239. transformIntoNPC(2885);
  240. reset();
  241. setCantFollowUnderCombat(false);
  242. setRandomWalk(getDefinitions().walkMask);
  243. setForceAgressive(true);
  244. setNoDistanceCheck(false);
  245. setTarget(player);
  246. }
  247. }
  248. }
  249.  
  250. if (id == 2453) {
  251. for (Player player : World.getPlayers()) {
  252. if (player == null)
  253. continue;
  254. if (player.getAttackedByDelay() > Utils.currentTimeMillis()
  255. && !World.atMultiArea(player))
  256. return;
  257. if (withinDistance(player, 1)) {
  258. transformIntoNPC(2452);
  259. reset();
  260. setCantFollowUnderCombat(false);
  261. setRandomWalk(getDefinitions().walkMask);
  262. setForceAgressive(true);
  263. setNoDistanceCheck(false);
  264. setTarget(player);
  265. }
  266. }
  267. }
  268.  
  269. if (id == 1266) {
  270. for (Player player : World.getPlayers()) {
  271. if (player == null)
  272. continue;
  273. if (player.getAttackedByDelay() > Utils.currentTimeMillis()
  274. && !World.atMultiArea(player))
  275. return;
  276. if (withinDistance(player, 1)) {
  277. transformIntoNPC(1265);
  278. reset();
  279. setCantFollowUnderCombat(false);
  280. setRandomWalk(getDefinitions().walkMask);
  281. setForceAgressive(true);
  282. setNoDistanceCheck(false);
  283. setTarget(player);
  284. }
  285. }
  286. }
  287. if (id == 1268) {
  288. for (Player player : World.getPlayers()) {
  289. if (player == null)
  290. continue;
  291. if (player.getAttackedByDelay() > Utils.currentTimeMillis()
  292. && !World.atMultiArea(player))
  293. return;
  294. if (withinDistance(player, 1)) {
  295. transformIntoNPC(1267);
  296. reset();
  297. setCantFollowUnderCombat(false);
  298. setRandomWalk(getDefinitions().walkMask);
  299. setForceAgressive(true);
  300. setNoDistanceCheck(false);
  301. setTarget(player);
  302. }
  303. }
  304. }
  305. if (id == 2890) {
  306. for (Player player : World.getPlayers()) {
  307. if (player == null)
  308. continue;
  309. if (player.getAttackedByDelay() > Utils.currentTimeMillis()
  310. && !World.atMultiArea(player))
  311. return;
  312. if (withinDistance(player, 1)) {
  313. transformIntoNPC(2889);
  314. reset();
  315. setCantFollowUnderCombat(false);
  316. setRandomWalk(getDefinitions().walkMask);
  317. setForceAgressive(true);
  318. setNoDistanceCheck(false);
  319. setTarget(player);
  320. }
  321. }
  322. }
  323. if (!combat.process()) {
  324. if (!isForceWalking()) {
  325. if (!cantInteract) {
  326. if (!checkAgressivity()) {
  327. if (getFreezeDelay() < Utils.currentTimeMillis()) {
  328. if (!hasWalkSteps()
  329. && (walkType & NORMAL_WALK) != 0) {
  330. boolean can = false;
  331. for (int i = 0; i < 2; i++) {
  332. if (Math.random() * 1000.0 < 100.0) {
  333. can = true;
  334. break;
  335. }
  336. }
  337.  
  338. if (can) {
  339. int moveX = (int) Math
  340. .round(Math.random() * 10.0 - 5.0);
  341. int moveY = (int) Math
  342. .round(Math.random() * 10.0 - 5.0);
  343. resetWalkSteps();
  344. if (getMapAreaNameHash() != -1) {
  345. if (!MapAreas.isAtArea(
  346. getMapAreaNameHash(), this)) {
  347. forceWalkRespawnTile();
  348. return;
  349. }
  350. addWalkSteps(getX() + moveX, getY()
  351. + moveY, 5,
  352. (walkType & FLY_WALK) == 0);
  353. } else
  354. addWalkSteps(
  355. respawnTile.getX() + moveX,
  356. respawnTile.getY() + moveY, 5,
  357. (walkType & FLY_WALK) == 0);
  358. }
  359.  
  360. }
  361. }
  362. }
  363. }
  364. }
  365. }
  366. if (isForceWalking()) {
  367. if (getFreezeDelay() < Utils.currentTimeMillis()) {
  368. if (getX() != forceWalk.getX() || getY() != forceWalk.getY()) {
  369. if (!hasWalkSteps()) {
  370. int steps = RouteFinder.findRoute(
  371. RouteFinder.WALK_ROUTEFINDER, getX(), getY(),
  372. getPlane(), getSize(), new FixedTileStrategy(
  373. forceWalk.getX(), forceWalk.getY()),
  374. true);
  375. int[] bufferX = RouteFinder.getLastPathBufferX();
  376. int[] bufferY = RouteFinder.getLastPathBufferY();
  377. for (int i = steps - 1; i >= 0; i--) {
  378. if (!addWalkSteps(bufferX[i], bufferY[i], 25, true))
  379. break;
  380. }
  381. }
  382. if (!hasWalkSteps()) {
  383. setNextWorldTile(new WorldTile(forceWalk));
  384. forceWalk = null;
  385. }
  386. } else
  387. forceWalk = null;
  388. }
  389. }
  390. }
  391.  
  392. @Override
  393. public void processEntity() {
  394. super.processEntity();
  395. processNPC();
  396. }
  397.  
  398. public int getRespawnDirection() {
  399. NPCDefinitions definitions = getDefinitions();
  400. if (definitions.anInt853 << 32 != 0 && definitions.respawnDirection > 0
  401. && definitions.respawnDirection <= 8)
  402. return (4 + definitions.respawnDirection) << 11;
  403. return 0;
  404. }
  405.  
  406. /*
  407. * forces npc to random walk even if cache says no, used because of fake
  408. * cache information
  409. */
  410. /*
  411. * private static boolean forceRandomWalk(int npcId) { switch (npcId) { case
  412. * 11226: return true; case 3341: case 3342: case 3343: return true;
  413. * default: return false; /* default: return
  414. * NPCDefinitions.getNPCDefinitions(npcId).name .equals("Icy Bones");
  415. */
  416. /*
  417. * } }
  418. */
  419.  
  420. @Override
  421. public void handleIngoingHit(final Hit hit) {
  422. if (hit.getLook() != HitLook.MELEE_DAMAGE
  423. && hit.getLook() != HitLook.RANGE_DAMAGE
  424. && hit.getLook() != HitLook.MAGIC_DAMAGE)
  425. return;
  426. Entity source = hit.getSource();
  427. if (source == null)
  428. return;
  429. }
  430.  
  431. @Override
  432. public void reset() {
  433. super.reset();
  434. setDirection(getRespawnDirection());
  435. combat.reset();
  436. setBonuses(); // back to real bonuses
  437. forceWalk = null;
  438. }
  439.  
  440. @Override
  441. public void finish() {
  442. if (hasFinished())
  443. return;
  444. setFinished(true);
  445. World.updateEntityRegion(this);
  446. World.removeNPC(this);
  447. }
  448.  
  449. public void setRespawnTask() {
  450. if (!hasFinished()) {
  451. reset();
  452. setLocation(respawnTile);
  453. finish();
  454. }
  455. CoresManager.slowExecutor.schedule(new Runnable() {
  456. @Override
  457. public void run() {
  458. try {
  459. spawn();
  460. } catch (Throwable e) {
  461. Logger.handle(e);
  462. }
  463. }
  464. }, getCombatDefinitions().getRespawnDelay() * 600,
  465. TimeUnit.MILLISECONDS);
  466. }
  467.  
  468. public void deserialize() {
  469. if (combat == null)
  470. combat = new NPCCombat(this);
  471. spawn();
  472. }
  473.  
  474. public void spawn() {
  475. setFinished(false);
  476. World.addNPC(this);
  477. setLastRegionId(0);
  478. World.updateEntityRegion(this);
  479. loadMapRegions();
  480. checkMultiArea();
  481. }
  482.  
  483. public NPCCombat getCombat() {
  484. return combat;
  485. }
  486.  
  487. @Override
  488. public void sendDeath(Entity source) {
  489. final NPCCombatDefinitions defs = getCombatDefinitions();
  490. resetWalkSteps();
  491. combat.removeTarget();
  492. source.setAttackedByDelay(defs.getDeathDelay());
  493. setNextAnimation(null);
  494. setNextAnimation(new Animation(defs.getDeathEmote()));
  495. WorldTasksManager.schedule(new WorldTask() {
  496. int loop;
  497.  
  498. @Override
  499. public void run() {
  500. if (loop == 0) {
  501. } else if (loop >= defs.getDeathDelay()) {
  502. drop();
  503. reset();
  504. setLocation(respawnTile);
  505. finish();
  506. if (!isSpawned())
  507. setRespawnTask();
  508. stop();
  509. }
  510. loop++;
  511. }
  512. }, 0, 1);
  513. }
  514.  
  515. private void addAvalonPoints(Player killer, NPC npc) {
  516. killer.setAvalonPoints(killer.getAvalonPoints()
  517. + (getCombatLevel() * 4));
  518. killer.getPackets().sendGameMessage(
  519. "You gain " + getCombatLevel() * 4
  520. + " avalon points for killing " + getName() + ".");
  521. }
  522.  
  523. public void drop() {
  524. try {
  525. Drop[] drops = NPCDrops.getDrops(id);
  526. if (drops == null)
  527. return;
  528. Player killer = getMostDamageReceivedSourcePlayer();
  529. if (killer == null)
  530. return;
  531. if (getId() == 13478)
  532. RevenantDrops.sendRandomDrop(killer, this);
  533. CharmDrops.sendDrop(killer, this);
  534. CasketDrops.sendDrop(killer, this);
  535. CrystalKeyDrops.sendDrop(killer, this);
  536. if (getId() == 6260) {
  537. addAvalonPoints(killer, this);
  538. killer.bandosKilled++;
  539. killer.getPackets().sendGameMessage(
  540. "You have killed in total of " + killer.bandosKilled
  541. + " bandos bosses.");
  542. }
  543. if (getId() == 6222) {
  544. addAvalonPoints(killer, this);
  545. killer.armadylKilled++;
  546. killer.getPackets().sendGameMessage(
  547. "You have killed in total of " + killer.armadylKilled
  548. + " armadyl bosses.");
  549. }
  550. if (getId() == 6247) {
  551. addAvalonPoints(killer, this);
  552. killer.saradominKilled++;
  553. killer.getPackets().sendGameMessage(
  554. "You have killed in total of " + killer.saradominKilled
  555. + " saradomin bosses.");
  556. }
  557. if (getId() == 6203) {
  558. addAvalonPoints(killer, this);
  559. killer.zamorakKilled++;
  560. killer.getPackets().sendGameMessage(
  561. "You have killed in total of " + killer.zamorakKilled
  562. + " zamorak bosses.");
  563. }
  564. if (getId() == 8133) {
  565. addAvalonPoints(killer, this);
  566. killer.corpKilled++;
  567. killer.getPackets().sendGameMessage(
  568. "You have killed in total of " + killer.corpKilled
  569. + " corporeal beasts.");
  570. }
  571. if (killer.isAtWild()) {
  572. killer.setAvalonPoints(killer.getAvalonPoints()
  573. + (getCombatLevel() / 2 * Wilderness
  574. .getWildLevel(killer)) / 2);
  575. killer.getPackets().sendGameMessage(
  576. "You gain "
  577. + (getCombatLevel() / 2 * Wilderness
  578. .getWildLevel(killer)) / 2
  579. + " avalon points for killing " + getName()
  580. + " level " + getCombatLevel()
  581. + " in wildy level "
  582. + Wilderness.getWildLevel(killer) + ".");
  583. /*
  584. * killer.getPackets().sendGameMessage( "Combat level / 2 (" +
  585. * getCombatLevel() / 2 + ") * Wildy level (" +
  586. * Wilderness.getWildLevel(killer) + ") / 2 = " +
  587. * (getCombatLevel() / 2 * Wilderness .getWildLevel(killer)) / 2
  588. * + " avalon points.");
  589. */
  590. }
  591. Player otherPlayer = killer.getSlayerManager().getSocialPlayer();
  592. SlayerManager manager = killer.getSlayerManager();
  593. if (manager.isValidTask(getName()))
  594. manager.checkCompletedTask(getDamageReceived(killer),
  595. otherPlayer != null ? getDamageReceived(otherPlayer)
  596. : 0);
  597. Drop[] possibleDrops = new Drop[drops.length];
  598. int possibleDropsCount = 0;
  599. for (Drop drop : drops) {
  600. if (drop.getRate() == 100)
  601. sendDrop(killer, drop);
  602. else {
  603. if ((Utils.getRandomDouble(99) + 1) <= drop.getRate()) {
  604. possibleDrops[possibleDropsCount++] = drop;
  605. }
  606. }
  607. }
  608. if (possibleDropsCount > 0)
  609. sendDrop(killer,
  610. possibleDrops[Utils.getRandom(possibleDropsCount - 1)]);
  611. } catch (Exception e) {
  612. e.printStackTrace();
  613. } catch (Error e) {
  614. e.printStackTrace();
  615. }
  616. }
  617.  
  618. public void sendDrop(Player player, Drop drop) {
  619. boolean sendDp = true;
  620. int size = getSize();
  621. String dropName = ItemDefinitions.getItemDefinitions(drop.getItemId())
  622. .getName().toLowerCase();
  623. Item item = ItemDefinitions.getItemDefinitions(drop.getItemId())
  624. .isStackable() ? new Item(drop.getItemId(),
  625. (drop.getMinAmount() * Settings.DROP_RATE)
  626. + Utils.getRandom(drop.getExtraAmount()
  627. * Settings.DROP_RATE)) : new Item(
  628. drop.getItemId(), (drop.getMinAmount() + Utils.getRandom(drop
  629. .getExtraAmount())));
  630.  
  631. /* LootShare/CoinShare */
  632. FriendChatsManager fc = player.getCurrentFriendChat();
  633. if (player.isToogleLootShare()) {
  634. if (fc != null) {
  635. CopyOnWriteArrayList<Player> players = fc.getPlayers();
  636. CopyOnWriteArrayList<Player> playersWithLs = new CopyOnWriteArrayList<Player>();
  637. for (Player p : players) {
  638. if (p.isToogleLootShare()
  639. && p.getRegionId() == player.getRegionId())
  640. playersWithLs.add(p);
  641. }
  642. Player luckyPlayer = playersWithLs
  643. .get((int) (Math.random() * playersWithLs.size()));
  644. if (getId() == 13478)
  645. RevenantDrops.sendRandomDrop(luckyPlayer, this);
  646. CharmDrops.sendDrop(luckyPlayer, this);
  647. CasketDrops.sendDrop(luckyPlayer, this);
  648. CrystalKeyDrops.sendDrop(luckyPlayer, this);
  649. World.updateGroundItem(item, new WorldTile(getCoordFaceX(size),
  650. getCoordFaceY(size), getPlane()), luckyPlayer, 60, 0);
  651. luckyPlayer.sm(String.format(
  652. "<col=216902>You received: %s x %s. (" + getName()
  653. + ") </col>",
  654. Utils.getFormattedNumber(item.getAmount(), ','),
  655. dropName));
  656. for (Player p : playersWithLs) {
  657. if (!p.equals(luckyPlayer))
  658. p.sm(String.format(
  659. "%s received: %s x %s. (" + getName() + ") ",
  660. luckyPlayer.getDisplayName(),
  661. Utils.getFormattedNumber(item.getAmount(), ','),
  662. dropName));
  663. }
  664. }
  665. sendDp = false;
  666. }
  667. /* End of LootShare/CoinShare */
  668.  
  669. if (player.getInventory().containsItem(18337, 1)// Bonecrusher
  670. && item.getDefinitions().getName().toLowerCase()
  671. .contains("bones")) {
  672. player.getSkills().addXp(Skills.PRAYER,
  673. Burying.Bone.forId(drop.getItemId()).getExperience());
  674. }
  675.  
  676. if (player.getInventory().containsItem(19675, 1)// Herbicide
  677. && item.getDefinitions().getName().toLowerCase()
  678. .contains("grimy")) {
  679. if (player.getSkills().getLevelForXp(Skills.HERBLORE) >= HerbCleaning
  680. .getHerb(item.getId()).getLevel()) {
  681. player.getSkills()
  682. .addXp(Skills.HERBLORE,
  683. HerbCleaning.getHerb(drop.getItemId())
  684. .getExperience() * 2);
  685. }
  686. }
  687.  
  688. if (sendDp)
  689. World.updateGroundItem(item, new WorldTile(getCoordFaceX(size),
  690. getCoordFaceY(size), getPlane()), player, 60, 0);
  691. if (dropName.contains("pernix") || dropName.contains("torva")
  692. || dropName.contains("virtus") || dropName.contains("bandos")
  693. || dropName.contains("hilt") || dropName.contains("steadfast")
  694. || dropName.contains("glaiven")
  695. || dropName.contains("saradomin sword")
  696. || dropName.contains("ragefire") || dropName.contains("visage")
  697. || dropName.contains("sigil") || dropName.contains("armadyl")
  698. || dropName.contains("zaryte")
  699. || dropName.contains("dragon claws"))
  700. World.sendWorldMessage(
  701. "<img=7><col=36648b>News: " + player.getDisplayName()
  702. + " has recieved " + dropName + " as a loot!",
  703. false);
  704. }
  705.  
  706. public void setNextNPCTransformation(int id) {
  707. setNPC(id);
  708. nextTransformation = new Transformation(id);
  709. if (getCustomCombatLevel() != -1)
  710. changedCombatLevel = true;
  711. if (getCustomName() != null)
  712. changedName = true;
  713. }
  714.  
  715. @Override
  716. public int getSize() {
  717. switch (id) {
  718. case 15202:
  719. return 2;
  720. case 15201:
  721. return 1;
  722. case 1459:
  723. return 2;
  724. case 6260:
  725. return 3;
  726. }
  727. return getDefinitions().size;
  728. }
  729.  
  730. public int getMaxHit() {
  731. return getCombatDefinitions().getMaxHit();
  732. }
  733.  
  734. public int[] getBonuses() {
  735. return bonuses;
  736. }
  737.  
  738. @Override
  739. public double getMagePrayerMultiplier() {
  740. if (this instanceof Familiar)
  741. return 0.6;
  742. return 0;
  743. }
  744.  
  745. @Override
  746. public double getRangePrayerMultiplier() {
  747. if (this instanceof Familiar)
  748. return 0.6;
  749. return 0;
  750. }
  751.  
  752. @Override
  753. public double getMeleePrayerMultiplier() {
  754. if (this instanceof Familiar)
  755. return 0.6;
  756. return 0;
  757. }
  758.  
  759. public WorldTile getRespawnTile() {
  760. return respawnTile;
  761. }
  762.  
  763. public boolean isUnderCombat() {
  764. return combat.underCombat();
  765. }
  766.  
  767. @Override
  768. public void setAttackedBy(Entity target) {
  769. super.setAttackedBy(target);
  770. if (target == combat.getTarget()
  771. && !(combat.getTarget() instanceof Familiar))
  772. lastAttackedByTarget = Utils.currentTimeMillis();
  773. }
  774.  
  775. public boolean canBeAttackedByAutoRelatie() {
  776. return Utils.currentTimeMillis() - lastAttackedByTarget > lureDelay;
  777. }
  778.  
  779. public boolean isForceWalking() {
  780. return forceWalk != null;
  781. }
  782.  
  783. public void setTarget(Entity entity) {
  784. if (isForceWalking())
  785. return;
  786. combat.setTarget(entity);
  787. lastAttackedByTarget = Utils.currentTimeMillis();
  788. }
  789.  
  790. public void removeTarget() {
  791. if (combat.getTarget() == null)
  792. return;
  793. combat.removeTarget();
  794. }
  795.  
  796. public void forceWalkRespawnTile() {
  797. setForceWalk(respawnTile);
  798. }
  799.  
  800. public void setForceWalk(WorldTile tile) {
  801. resetWalkSteps();
  802. forceWalk = tile;
  803. }
  804.  
  805. public boolean hasForceWalk() {
  806. return forceWalk != null;
  807. }
  808.  
  809. public ArrayList<Entity> getPossibleTargets(boolean checkNPCs,
  810. boolean checkPlayers) {
  811. int size = getSize();
  812. ArrayList<Entity> possibleTarget = new ArrayList<Entity>();
  813. for (int regionId : getMapRegionsIds()) {
  814. if (checkPlayers) {
  815. List<Integer> playerIndexes = World.getRegion(regionId)
  816. .getPlayerIndexes();
  817. if (playerIndexes != null) {
  818. for (int playerIndex : playerIndexes) {
  819. Player player = World.getPlayers().get(playerIndex);
  820. if (player == null
  821. || player.isDead()
  822. || player.hasFinished()
  823. || player.getUsername().equalsIgnoreCase(
  824. "ghost")
  825. || !player.isRunning()
  826. || player.getAppearence().isHidden()
  827. || !Utils
  828. .isOnRange(
  829. getX(),
  830. getY(),
  831. size,
  832. player.getX(),
  833. player.getY(),
  834. player.getSize(),
  835. forceTargetDistance > 0 ? forceTargetDistance
  836. : 16)
  837. || (!forceMultiAttacked
  838. && (!isAtMultiArea() || !player
  839. .isAtMultiArea()) && (player
  840. .getAttackedBy() != this && (player
  841. .getAttackedByDelay() > Utils
  842. .currentTimeMillis() || player
  843. .getFindTargetDelay() > Utils
  844. .currentTimeMillis())))
  845. || !clipedProjectile(player, false)
  846. || (!forceAgressive
  847. && !Wilderness.isAtWild(this) && player
  848. .getSkills()
  849. .getCombatLevelWithSummoning() >= getCombatLevel() * 2))
  850. continue;
  851. possibleTarget.add(player);
  852. }
  853. }
  854. }
  855. if (checkNPCs) {
  856. List<Integer> npcsIndexes = World.getRegion(regionId)
  857. .getNPCsIndexes();
  858. if (npcsIndexes != null) {
  859. for (int npcIndex : npcsIndexes) {
  860. NPC npc = World.getNPCs().get(npcIndex);
  861. if (npc == null
  862. || npc == this
  863. || npc.isDead()
  864. || npc.hasFinished()
  865. || !Utils
  866. .isOnRange(
  867. getX(),
  868. getY(),
  869. size,
  870. npc.getX(),
  871. npc.getY(),
  872. npc.getSize(),
  873. forceTargetDistance > 0 ? forceTargetDistance
  874. : 16)
  875. || !npc.getDefinitions().hasAttackOption()
  876. || ((!isAtMultiArea() || !npc.isAtMultiArea())
  877. && npc.getAttackedBy() != this && npc
  878. .getAttackedByDelay() > Utils
  879. .currentTimeMillis())
  880. || !clipedProjectile(npc, false))
  881. continue;
  882. possibleTarget.add(npc);
  883. }
  884. }
  885. }
  886. }
  887. return possibleTarget;
  888. }
  889.  
  890. public ArrayList<Entity> getPossibleTargets() {
  891. return getPossibleTargets(false, true);
  892. }
  893.  
  894. public boolean checkAgressivity() {
  895. if (!forceAgressive) {
  896. NPCCombatDefinitions defs = getCombatDefinitions();
  897. if (defs.getAgressivenessType() == NPCCombatDefinitions.PASSIVE)
  898. return false;
  899. }
  900. ArrayList<Entity> possibleTarget = getPossibleTargets();
  901. if (!possibleTarget.isEmpty()) {
  902. Entity target = possibleTarget.get(Utils.random(possibleTarget
  903. .size()));
  904. setTarget(target);
  905. target.setAttackedBy(target);
  906. target.setFindTargetDelay(Utils.currentTimeMillis() + 10000);
  907. return true;
  908. }
  909. return false;
  910. }
  911.  
  912. public boolean isCantInteract() {
  913. return cantInteract;
  914. }
  915.  
  916. public void setCantInteract(boolean cantInteract) {
  917. this.cantInteract = cantInteract;
  918. if (cantInteract)
  919. combat.reset();
  920. }
  921.  
  922. public int getCapDamage() {
  923. return capDamage;
  924. }
  925.  
  926. public void setCapDamage(int capDamage) {
  927. this.capDamage = capDamage;
  928. }
  929.  
  930. public int getLureDelay() {
  931. return lureDelay;
  932. }
  933.  
  934. public void setLureDelay(int lureDelay) {
  935. this.lureDelay = lureDelay;
  936. }
  937.  
  938. public boolean isCantFollowUnderCombat() {
  939. return cantFollowUnderCombat;
  940. }
  941.  
  942. public void setCantFollowUnderCombat(boolean canFollowUnderCombat) {
  943. this.cantFollowUnderCombat = canFollowUnderCombat;
  944. }
  945.  
  946. public Transformation getNextTransformation() {
  947. return nextTransformation;
  948. }
  949.  
  950. @Override
  951. public String toString() {
  952. return getDefinitions().name + " - " + id + " - " + getX() + " "
  953. + getY() + " " + getPlane();
  954. }
  955.  
  956. public boolean isForceAgressive() {
  957. return forceAgressive;
  958. }
  959.  
  960. public void setForceAgressive(boolean forceAgressive) {
  961. this.forceAgressive = forceAgressive;
  962. }
  963.  
  964. public int getForceTargetDistance() {
  965. return forceTargetDistance;
  966. }
  967.  
  968. public void setForceTargetDistance(int forceTargetDistance) {
  969. this.forceTargetDistance = forceTargetDistance;
  970. }
  971.  
  972. public boolean isForceFollowClose() {
  973. return forceFollowClose;
  974. }
  975.  
  976. public void setForceFollowClose(boolean forceFollowClose) {
  977. this.forceFollowClose = forceFollowClose;
  978. }
  979.  
  980. public boolean isForceMultiAttacked() {
  981. return forceMultiAttacked;
  982. }
  983.  
  984. public void setForceMultiAttacked(boolean forceMultiAttacked) {
  985. this.forceMultiAttacked = forceMultiAttacked;
  986. }
  987.  
  988. public boolean hasRandomWalk() {
  989. return randomwalk;
  990. }
  991.  
  992. public void setRandomWalk(int forceRandomWalk) {
  993. this.walkType = forceRandomWalk;
  994. }
  995.  
  996. public String getCustomName() {
  997. return name;
  998. }
  999.  
  1000. public boolean isIntelligentRouteFinder() {
  1001. return intelligentRouteFinder;
  1002. }
  1003.  
  1004. public void setIntelligentRouteFinder(boolean intelligentRouteFinder) {
  1005. this.intelligentRouteFinder = intelligentRouteFinder;
  1006. }
  1007.  
  1008. public void setName(String string) {
  1009. this.name = getDefinitions().name.equals(string) ? null : string;
  1010. changedName = true;
  1011. }
  1012.  
  1013. public int getCustomCombatLevel() {
  1014. return combatLevel;
  1015. }
  1016.  
  1017. public int getCombatLevel() {
  1018. return combatLevel >= 0 ? combatLevel : getDefinitions().combatLevel;
  1019. }
  1020.  
  1021. public String getName() {
  1022. return name != null ? name : getDefinitions().name;
  1023. }
  1024.  
  1025. public void setCombatLevel(int level) {
  1026. combatLevel = getDefinitions().combatLevel == level ? -1 : level;
  1027. changedCombatLevel = true;
  1028. }
  1029.  
  1030. public boolean hasChangedName() {
  1031. return changedName;
  1032. }
  1033.  
  1034. public boolean hasChangedCombatLevel() {
  1035. return changedCombatLevel;
  1036. }
  1037.  
  1038. public WorldTile getMiddleWorldTile() {
  1039. int size = getSize();
  1040. return new WorldTile(getCoordFaceX(size), getCoordFaceY(size),
  1041. getPlane());
  1042. }
  1043.  
  1044. public boolean isSpawned() {
  1045. return spawned;
  1046. }
  1047.  
  1048. public void setSpawned(boolean spawned) {
  1049. this.spawned = spawned;
  1050. }
  1051.  
  1052. public boolean isNoDistanceCheck() {
  1053. return noDistanceCheck;
  1054. }
  1055.  
  1056. public void setNoDistanceCheck(boolean noDistanceCheck) {
  1057. this.noDistanceCheck = noDistanceCheck;
  1058. }
  1059.  
  1060. public boolean withinDistance(Player tile, int distance) {
  1061. return super.withinDistance(tile, distance);
  1062. }
  1063.  
  1064. /**
  1065. * Gets the locked.
  1066. *
  1067. * @return The locked.
  1068. */
  1069. public boolean isLocked() {
  1070. return locked;
  1071. }
  1072.  
  1073. /**
  1074. * Sets the locked.
  1075. *
  1076. * @param locked
  1077. * The locked to set.
  1078. */
  1079. public void setLocked(boolean locked) {
  1080. this.locked = locked;
  1081. }
  1082.  
  1083. public double getCharmDropPercentage() {
  1084. return charmDropPercentage;
  1085. }
  1086.  
  1087. public void setCharmDropPercentage(double charmDropPercentage) {
  1088. this.charmDropPercentage = charmDropPercentage;
  1089. }
  1090.  
  1091. public SecondaryBar getNextSecondaryBar() {
  1092. return nextSecondaryBar;
  1093. }
  1094.  
  1095. public void setNextSecondaryBar(SecondaryBar secondaryBar) {
  1096. this.nextSecondaryBar = secondaryBar;
  1097. }
  1098.  
  1099. public double getDropRateFactor() {
  1100. return dropRateFactor;
  1101. }
  1102.  
  1103. public void setDropRateFactor(double dropRateFactor) {
  1104. this.dropRateFactor = dropRateFactor;
  1105. }
  1106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement