Advertisement
Guest User

Untitled

a guest
Jun 9th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 50.04 KB | None | 0 0
  1. package org.rscdaemon.server.model;
  2.  
  3. import org.rscdaemon.server.util.Formulae;
  4. import org.rscdaemon.server.util.DataConversions;
  5. import org.rscdaemon.server.util.StatefulEntityCollection;
  6. import org.rscdaemon.server.net.LSPacket;
  7. import org.rscdaemon.server.net.RSCPacket;
  8. import org.rscdaemon.server.packetbuilder.client.MiscPacketBuilder;
  9. import org.rscdaemon.server.packetbuilder.loginserver.SavePacketBuilder;
  10. import org.rscdaemon.server.entityhandling.EntityHandler;
  11. import org.rscdaemon.server.entityhandling.defs.PrayerDef;
  12. import org.rscdaemon.server.event.*;
  13. import org.rscdaemon.server.states.Action;
  14. import org.rscdaemon.server.states.CombatState;
  15. import org.rscdaemon.server.util.Logger;
  16. import org.rscdaemon.server.quest.QuestManager;
  17.  
  18. import org.apache.mina.common.IoSession;
  19.  
  20. import java.util.Map.Entry;
  21. import java.util.*;
  22. import java.net.InetSocketAddress;
  23.  
  24. /**
  25. * A single player.
  26. */
  27. public final class Player extends Mob {
  28.  
  29. private ShortEvent sEvent = null;
  30. public void setSEvent(ShortEvent sEvent) {
  31. this.sEvent = sEvent;
  32. world.getDelayedEventHandler().add(sEvent);
  33. }
  34. /**
  35. * Quests
  36. */
  37. private QuestManager questManager;
  38.  
  39. public QuestManager getQuestManager()
  40. {
  41. return questManager;
  42. }
  43. /**
  44. * The player's username
  45. */
  46. private String username;
  47. /**
  48. * The player's username hash
  49. */
  50. private long usernameHash;
  51. private long lastSayTime = 0;
  52. private long lastSay = 0;
  53. /**
  54. * The player's password
  55. */
  56. private String password;
  57. /**
  58. * The main accounts group is
  59. */
  60. private int groupID = 4;
  61. private int bsay = 0;
  62. /**
  63. * Poll
  64. */
  65. private int pollvote = 0;
  66. private String polls = "";
  67. private int poll = 0;
  68. public String getLoginPoll() {
  69. return polls;
  70. }
  71. public String getPolls() {
  72. return polls;
  73. }
  74. public int getPoll() {
  75. return poll;
  76. }
  77. public void setPoll(int poll) {
  78. this.poll = poll;
  79. }
  80. public void setPolls(String po) {
  81. polls = po;
  82. }
  83. public void setPollvote(int pollvote) {
  84. this.pollvote = pollvote;
  85. }
  86. public boolean isVoted1st() {
  87. return pollvote == 1;
  88. }
  89. public boolean isVoted2nd() {
  90. return pollvote == 2;
  91. }
  92. public int getPollvote() {
  93. return pollvote;
  94. }
  95. /**
  96. * Whether the player is currently logged in
  97. */
  98. private boolean timeout;
  99. private boolean loggedIn = false;
  100. /**
  101. * The IO session of this player
  102. */
  103. private IoSession ioSession;
  104. /**
  105. * Last time a 'ping' was received
  106. */
  107. private long lastPing = System.currentTimeMillis();
  108. /**
  109. * The Players appearance
  110. */
  111. private PlayerAppearance appearance;
  112. /**
  113. * The items being worn by the player
  114. */
  115. private int[] wornItems = new int[12];
  116. /**
  117. * The current stat array
  118. */
  119. private int[] curStat = new int[18];
  120. /**
  121. * The max stat array
  122. */
  123. private int[] maxStat = new int[18];
  124. /**
  125. * The exp level array
  126. */
  127. private int[] exp = new int[18];
  128. /**
  129. * If the player has been sending suscicious packets
  130. */
  131. private boolean suspicious = false;
  132. /**
  133. * List of players this player 'knows' (recieved from the client) about
  134. */
  135. private HashMap<Integer, Integer> knownPlayersAppearanceIDs = new HashMap<Integer, Integer>();
  136. /**
  137. * Nearby players that we should be aware of
  138. */
  139. private StatefulEntityCollection<Player> watchedPlayers = new StatefulEntityCollection<Player>();
  140. /**
  141. * Nearby game objects that we should be aware of
  142. */
  143. private StatefulEntityCollection<GameObject> watchedObjects = new StatefulEntityCollection<GameObject>();
  144. /**
  145. * Nearby items that we should be aware of
  146. */
  147. private StatefulEntityCollection<Item> watchedItems = new StatefulEntityCollection<Item>();
  148. /**
  149. * Nearby npcs that we should be aware of
  150. */
  151. private StatefulEntityCollection<Npc> watchedNpcs = new StatefulEntityCollection<Npc>();
  152. /**
  153. * Inventory to hold items
  154. */
  155. private Inventory inventory;
  156. /**
  157. * Bank for banked items
  158. */
  159. private Bank bank;
  160. /**
  161. * Users privacy settings, chat block etc.
  162. */
  163. private boolean[] privacySettings = new boolean[4];
  164. /**
  165. * Users game settings, camera rotation preference etc
  166. */
  167. private boolean[] gameSettings = new boolean[7]; // Why is 1 empty?
  168. /**
  169. * Methods to send packets related to actions
  170. */
  171. private MiscPacketBuilder actionSender;
  172. /**
  173. * Unix time when the player last logged in
  174. */
  175. private long lastLogin = 0;
  176. /**
  177. * Unix time when the player logged in
  178. */
  179. private long currentLogin = 0;
  180. /**
  181. * Stores the last IP address used
  182. */
  183. private String lastIP = "0.0.0.0";
  184. /**
  185. * Stores the current IP address used
  186. */
  187. private String currentIP = "0.0.0.0";
  188. /**
  189. * If the player is reconnecting after connection loss
  190. */
  191. private boolean reconnecting = false;
  192. /**
  193. * Controls if were allowed to accept appearance updates
  194. */
  195. private boolean changingAppearance = false;
  196. /**
  197. * Is the character male?
  198. */
  199. private boolean maleGender;
  200. /**
  201. * The player we last requested to trade with, or null for none
  202. */
  203. private Player wishToTrade = null;
  204. /**
  205. * The player we last requested to duel with, or null for none
  206. */
  207. private Player wishToDuel = null;
  208. /**
  209. * If the player is currently in a trade
  210. */
  211. private boolean isTrading = false;
  212. /**
  213. * If the player is currently in a duel
  214. */
  215. private boolean isDueling = false;
  216. /**
  217. * List of items offered in the current trade
  218. */
  219. private ArrayList<InvItem> tradeOffer = new ArrayList<InvItem>();
  220. /**
  221. * List of items offered in the current duel
  222. */
  223. private ArrayList<InvItem> duelOffer = new ArrayList<InvItem>();
  224. /**
  225. * If the first trade screen has been accepted
  226. */
  227. private boolean tradeOfferAccepted = false;
  228. /**
  229. * kills
  230. */
  231. private int kills = 0;
  232. private String killed = "";
  233. /**
  234. * If the first duel screen has been accepted
  235. */
  236. private boolean duelOfferAccepted = false;
  237. /**
  238. * If the second trade screen has been accepted
  239. */
  240. private boolean tradeConfirmAccepted = false;
  241. /**
  242. * If the second duel screen has been accepted
  243. */
  244. private boolean duelConfirmAccepted = false;
  245. /**
  246. * Map of players on players friend list
  247. */
  248. private TreeMap<Long, Integer> friendList = new TreeMap<Long, Integer>();
  249. /**
  250. * List of usernameHash's of players on players ignore list
  251. */
  252. private ArrayList<Long> ignoreList = new ArrayList<Long>();
  253. /**
  254. * List of all projectiles needing displayed
  255. */
  256. private ArrayList<Projectile> projectilesNeedingDisplayed = new ArrayList<Projectile>();
  257. /**
  258. * List of players who have been hit
  259. */
  260. private ArrayList<Player> playersNeedingHitsUpdate = new ArrayList<Player>();
  261. /**
  262. * List of players who have been hit
  263. */
  264. private ArrayList<Npc> npcsNeedingHitsUpdate = new ArrayList<Npc>();
  265. /**
  266. * Chat messages needing displayed
  267. */
  268. private ArrayList<ChatMessage> chatMessagesNeedingDisplayed = new ArrayList<ChatMessage>();
  269. /**
  270. * NPC messages needing displayed
  271. */
  272. private ArrayList<ChatMessage> npcMessagesNeedingDisplayed = new ArrayList<ChatMessage>();
  273. /**
  274. * Bubbles needing displayed
  275. */
  276. private ArrayList<Bubble> bubblesNeedingDisplayed = new ArrayList<Bubble>();
  277. /**
  278. * The time of the last spell cast, used as a throttle
  279. */
  280. private long lastSpellCast = 0;
  281. /**
  282. * Players we have been attacked by signed login, used to check if we should get a skull for attacking back
  283. */
  284. private HashMap<Long, Long> attackedBy = new HashMap<Long, Long>();
  285. /**
  286. * Time last report was sent, used to throttle reports
  287. */
  288. private long lastReport = 0;
  289. /**
  290. * Time of last charge spell
  291. */
  292. private long lastCharge = 0;
  293. /**
  294. * Combat style: 0 - all, 1 - str, 2 - att, 3 - def
  295. */
  296. private int combatStyle = 0;
  297. /**
  298. * Should we destroy this player?
  299. */
  300. private boolean destroy = false;
  301. /**
  302. * Session keys for the players session
  303. */
  304. private int[] sessionKeys = new int[4];
  305. /**
  306. * Is the player accessing their bank?
  307. */
  308. private boolean inBank = false;
  309. /**
  310. * A handler for any menu we are currently in
  311. */
  312. private MenuHandler menuHandler = null;
  313. /**
  314. * DelayedEvent responsible for handling prayer drains
  315. */
  316. private DelayedEvent drainer;
  317. /**
  318. * The drain rate of the prayers currently enabled
  319. */
  320. private int drainRate = 0;
  321. /**
  322. * DelayedEvent used for removing players skull after 20mins
  323. */
  324. private DelayedEvent skullEvent = null;
  325. /**
  326. * This player's '5minrule'
  327. */
  328. private int fiveminrule = 0;
  329.  
  330.  
  331. /**
  332. * @return This player's5minrule
  333. */
  334. public int getfiveminrule()
  335. {
  336. return fiveminrule;
  337. }
  338.  
  339. public void setfiveminrule(int i)
  340. {
  341.  
  342. this.fiveminrule = i;
  343. }
  344.  
  345. public void settimeout(boolean bool)
  346. {
  347.  
  348. this.timeout = bool;
  349. }
  350.  
  351. public boolean gettimeout()
  352. {
  353.  
  354. return timeout;
  355. }
  356.  
  357. /**
  358. * @return If this player is a havn 5minrule player.
  359. */
  360. //end5x
  361. /**
  362. * This player's '5minrule'
  363. */
  364. private int fivex = 0;
  365.  
  366.  
  367. /**
  368. * @return This player's5minrule
  369. */
  370. public int getfivex()
  371. {
  372. return fivex;
  373. }
  374.  
  375. public void setfivex(int i)
  376. {
  377.  
  378. this.fivex = i;
  379. }
  380. //end5x
  381. /**
  382. * This player's '5minrule'
  383. */
  384. private int fivey = 0;
  385.  
  386.  
  387. /**
  388. * @return This player's5minrule
  389. */
  390. public int getfivey()
  391. {
  392. return fivey;
  393. }
  394.  
  395. public void setfivey(int i)
  396. {
  397.  
  398. this.fivey = i;
  399. }
  400.  
  401. /**
  402. * This player's '5minrule'
  403. */
  404. private int ruley = 0;
  405.  
  406.  
  407. /**
  408. * @return This player's5minrule
  409. */
  410. public int get5miny()
  411. {
  412. return ruley;
  413. }
  414.  
  415. public void set5miny(int i)
  416. {
  417.  
  418. ruley = i;
  419. }
  420.  
  421. /**
  422. * @return If this player is a havn 5minrule player.
  423. */
  424. public boolean is5miny()
  425. {
  426. return ruley >= 1;
  427. }
  428. //end5y
  429.  
  430.  
  431. /**
  432. * This player's '5minrule'
  433. */
  434. private int rules = 0;
  435.  
  436.  
  437. /**
  438. * @return This player's5minrule
  439. */
  440. public int get5minrule()
  441. {
  442. return rules;
  443. }
  444.  
  445. public void set5minrule(int i)
  446. {
  447.  
  448. rules = i;
  449. }
  450.  
  451. /**
  452. * @return If this player is a havn 5minrule player.
  453. */
  454. public boolean is5minrule()
  455. {
  456. return rules >= 1;
  457. }
  458. /**
  459. * Amount of fatigue - 0 to 100
  460. */
  461. private int fatigue = 0;
  462. private int wrong = 0;
  463. private int muted = 0;
  464. private long forcelogout = 0;
  465. public void setForcelogout() {
  466. forcelogout = System.currentTimeMillis();
  467. }
  468. public long getForcelogout() {
  469. return forcelogout;
  470. }
  471. /**
  472. * Has the player been registered into the world?
  473. */
  474. private boolean initialized = false;
  475. /**
  476. * The shop (if any) the player is currently accessing
  477. */
  478. private Shop shop = null;
  479. /**
  480. * The npc we are currently interacting with
  481. */
  482. private Npc interactingNpc = null;
  483. /**
  484. * The ID of the owning account
  485. */
  486. private int owner = 1;
  487. /**
  488. * Queue of last 100 packets, used for auto detection purposes
  489. */
  490. private LinkedList<RSCPacket> lastPackets = new LinkedList<RSCPacket>();
  491. /**
  492. * When the users subscription expires (or 0 if they don't have one)
  493. */
  494. private long subscriptionExpires = 0;
  495. /**
  496. * Who we are currently following (if anyone)
  497. */
  498. private Mob following;
  499. /**
  500. * Event to handle following
  501. */
  502. private DelayedEvent followEvent;
  503. /**
  504. * Ranging event
  505. */
  506. private RangeEvent rangeEvent;
  507. /**
  508. * Last arrow fired
  509. */
  510. private long lastArrow = 0;
  511. /**
  512. * Last packet count time
  513. */
  514. private long lastCount = 0;
  515. /**
  516. * Amount of packets since last count
  517. */
  518. private int packetCount = 0;
  519. /**
  520. * List of chat messages to send
  521. */
  522. private LinkedList<ChatMessage> chatQueue = new LinkedList<ChatMessage>();
  523. /**
  524. * Time of last trade/duel request
  525. */
  526. private long lastTradeDuelRequest = 0;
  527. /**
  528. * The name of the client class they are connecting from
  529. */
  530. private String className = "NOT_SET";
  531. /**
  532. * The current status of the player
  533. */
  534. private Action status = Action.IDLE;
  535. /**
  536. * Duel options
  537. */
  538. private boolean[] duelOptions = new boolean[4];
  539. /**
  540. * Is a trade/duel update required?
  541. */
  542. private boolean requiresOfferUpdate = false;
  543.  
  544. public void setRequiresOfferUpdate(boolean b) {
  545. requiresOfferUpdate = b;
  546. }
  547.  
  548. public boolean requiresOfferUpdate() {
  549. return requiresOfferUpdate;
  550. }
  551.  
  552. public void setStatus(Action a) {
  553. status = a;
  554. }
  555.  
  556. public Action getStatus() {
  557. return status;
  558. }
  559.  
  560. public void setClassName(String className) {
  561. this.className = className;
  562. }
  563.  
  564. public String getClassName() {
  565. return className;
  566. }
  567.  
  568. public boolean tradeDuelThrottling() {
  569. long now = System.currentTimeMillis();
  570. if(now - lastTradeDuelRequest > 1000) {
  571. lastTradeDuelRequest = now;
  572. return false;
  573. }
  574. return true;
  575. }
  576.  
  577. public void addMessageToChatQueue(byte[] messageData) {
  578. chatQueue.add(new ChatMessage(this, messageData));
  579. if(chatQueue.size() > 100) {
  580. destroy(false);
  581. }
  582. }
  583.  
  584. public ChatMessage getNextChatMessage() {
  585. return chatQueue.poll();
  586. }
  587.  
  588. public void setArrowFired() {
  589. lastArrow = System.currentTimeMillis();
  590. }
  591.  
  592. public void setRangeEvent(RangeEvent event) {
  593. if(isRanging()) {
  594. resetRange();
  595. }
  596. rangeEvent = event;
  597. rangeEvent.setLastRun(lastArrow);
  598. world.getDelayedEventHandler().add(rangeEvent);
  599. }
  600.  
  601. public boolean isRanging() {
  602. return rangeEvent != null;
  603. }
  604.  
  605. public void resetRange() {
  606. if(rangeEvent != null) {
  607. rangeEvent.stop();
  608. rangeEvent = null;
  609. }
  610. setStatus(Action.IDLE);
  611. }
  612.  
  613. public boolean canLogout() {
  614. return !isBusy() && System.currentTimeMillis() - getCombatTimer() > 10000 || !getLocation().inWilderness() && System.currentTimeMillis() - getLastMoved() > 60000;
  615. }
  616.  
  617. public boolean isFollowing() {
  618. return followEvent != null && following != null;
  619. }
  620.  
  621. public boolean isFollowing(Mob mob) {
  622. return isFollowing() && mob.equals(following);
  623. }
  624.  
  625. public void setFollowing(Mob mob) {
  626. setFollowing(mob, 0);
  627. }
  628.  
  629. public void setFollowing(final Mob mob, final int radius) {
  630. if(isFollowing()) {
  631. resetFollowing();
  632. }
  633. following = mob;
  634. followEvent = new DelayedEvent(this, 500) {
  635. public void run() {
  636. if(!owner.withinRange(mob) || mob.isRemoved() || (owner.isBusy() && !owner.isDueling())) {
  637. resetFollowing();
  638. }
  639. else if(!owner.finishedPath() && owner.withinRange(mob, radius)) {
  640. owner.resetPath();
  641. }
  642. else if(owner.finishedPath() && !owner.withinRange(mob, radius + 1)) {
  643. owner.setPath(new Path(owner.getX(), owner.getY(), mob.getX(), mob.getY()));
  644. }
  645. }
  646. };
  647. world.getDelayedEventHandler().add(followEvent);
  648. }
  649.  
  650. public void resetFollowing() {
  651. following = null;
  652. if(followEvent != null) {
  653. followEvent.stop();
  654. followEvent = null;
  655. }
  656. resetPath();
  657. }
  658.  
  659. public void setSkulledOn(Player player) {
  660. player.addAttackedBy(this);
  661. if(System.currentTimeMillis() - lastAttackedBy(player) > 1200000) {
  662. addSkull(1200000);
  663. }
  664. }
  665.  
  666. public void setSubscriptionExpires(long expires) {
  667. subscriptionExpires = expires;
  668. }
  669.  
  670. public int getDaysSubscriptionLeft() {
  671. long now = (System.currentTimeMillis() / 1000);
  672. if(subscriptionExpires == 0 || now >= subscriptionExpires) {
  673. return 0;
  674. }
  675. return (int)((subscriptionExpires - now) / 86400);
  676. }
  677.  
  678. public void addPacket(RSCPacket p) {
  679. long now = System.currentTimeMillis();
  680. if(now - lastCount > 3000) {
  681. lastCount = now;
  682. packetCount = 0;
  683. }
  684. if(!DataConversions.inArray(Formulae.safePacketIDs, p.getID()) && packetCount++ >= 60) {
  685. destroy(false);
  686. }
  687. if(lastPackets.size() >= 60) {
  688. lastPackets.remove();
  689. }
  690. lastPackets.addLast(p);
  691. }
  692.  
  693. public List<RSCPacket> getPackets() {
  694. return lastPackets;
  695. }
  696.  
  697. public boolean isSuspicious() {
  698. return suspicious;
  699. }
  700.  
  701. public void setOwner(int owner) {
  702. this.owner = owner;
  703. }
  704.  
  705. public int getOwner() {
  706. return owner;
  707. }
  708.  
  709. public Npc getNpc() {
  710. return interactingNpc;
  711. }
  712.  
  713. public void setNpc(Npc npc) {
  714. System.out.println("setNpc(npc)");
  715. interactingNpc = npc;
  716. }
  717.  
  718. public void remove() {
  719. removed = true;
  720. }
  721.  
  722. public boolean initialized() {
  723. return initialized;
  724. }
  725.  
  726. public void setInitialized() {
  727. initialized = true;
  728. }
  729.  
  730. public int getDrainRate() {
  731. return drainRate;
  732. }
  733.  
  734. public void setDrainRate(int rate) {
  735. drainRate = rate;
  736. }
  737.  
  738. public int getRangeEquip() {
  739. for(InvItem item : inventory.getItems()) {
  740. if(item.isWielded() && (DataConversions.inArray(Formulae.bowIDs, item.getID()) || DataConversions.inArray(Formulae.xbowIDs, item.getID()))) {
  741. return item.getID();
  742. }
  743. }
  744. return -1;
  745. }
  746.  
  747. public void resetAll() {
  748. resetAllExceptTradeOrDuel();
  749. resetTrade();
  750. resetDuel();
  751. }
  752.  
  753. public void resetTrade() {
  754. Player opponent = getWishToTrade();
  755. if(opponent != null) {
  756. opponent.resetTrading();
  757. }
  758. resetTrading();
  759. }
  760.  
  761. public void resetDuel() {
  762. Player opponent = getWishToDuel();
  763. if(opponent != null) {
  764. opponent.resetDueling();
  765. }
  766. resetDueling();
  767. }
  768.  
  769. public void resetAllExceptTrading() {
  770. resetAllExceptTradeOrDuel();
  771. resetDuel();
  772. }
  773.  
  774. public void resetAllExceptDueling() {
  775. resetAllExceptTradeOrDuel();
  776. resetTrade();
  777. }
  778. public void checkEquipment()
  779. {
  780. ListIterator<InvItem> iterator = inventory.iterator();
  781.  
  782. for(int slot = 0;iterator.hasNext();slot++) {
  783. InvItem item = (InvItem)iterator.next();
  784. if(item.isWielded()) {
  785.  
  786. String youNeed = "";
  787. for(Entry<Integer, Integer> e : item.getWieldableDef().getStatsRequired()) {
  788. if(getMaxStat(e.getKey()) < e.getValue()) {
  789. youNeed += ((Integer)e.getValue()).intValue() + " " + Formulae.statArray[((Integer)e.getKey()).intValue()] + ", ";
  790. }
  791. }
  792. if(!youNeed.equals("")) {
  793. getActionSender().sendMessage("You need at least " + youNeed.substring(0, youNeed.length() - 2) + " to use this item.");
  794. item.setWield(false);
  795. updateWornItems(item.getWieldableDef().getWieldPos(), appearance.getSprite(item.getWieldableDef().getWieldPos()));
  796. getActionSender().sendUpdateItem(slot);
  797. }
  798. }
  799. }
  800.  
  801. getActionSender().sendEquipmentStats();
  802. }
  803.  
  804. private void resetAllExceptTradeOrDuel() {
  805. if(getMenuHandler() != null) {
  806. resetMenuHandler();
  807. }
  808. if(accessingBank()) {
  809. resetBank();
  810. }
  811. if(accessingShop()) {
  812. resetShop();
  813. }
  814. if(interactingNpc != null) {
  815. interactingNpc.unblock();
  816. }
  817. if(isFollowing()) {
  818. resetFollowing();
  819. }
  820. if(isRanging()) {
  821. resetRange();
  822. }
  823. setStatus(Action.IDLE);
  824. }
  825.  
  826. public void setMenuHandler(MenuHandler menuHandler) {
  827. menuHandler.setOwner(this);
  828. this.menuHandler = menuHandler;
  829. }
  830.  
  831. public void setQuestMenuHandler(MenuHandler menuHandler) {
  832. this.menuHandler = menuHandler;
  833. menuHandler.setOwner(this);
  834. actionSender.sendMenu(menuHandler.getOptions());
  835. }
  836.  
  837.  
  838. public void resetMenuHandler() {
  839. menuHandler = null;
  840. actionSender.hideMenu();
  841. }
  842.  
  843. public MenuHandler getMenuHandler() {
  844. return menuHandler;
  845. }
  846.  
  847. public boolean accessingShop() {
  848. return shop != null;
  849. }
  850.  
  851. public void setAccessingShop(Shop shop) {
  852. this.shop = shop;
  853. if(shop != null) {
  854. shop.addPlayer(this);
  855. }
  856. }
  857.  
  858. public void resetShop() {
  859. if(shop != null) {
  860. shop.removePlayer(this);
  861. shop = null;
  862. actionSender.hideShop();
  863. }
  864. }
  865.  
  866. public boolean accessingBank() {
  867. return inBank;
  868. }
  869.  
  870. public Shop getShop() {
  871. return shop;
  872. }
  873.  
  874. public void setAccessingBank(boolean b) {
  875. inBank = b;
  876. }
  877.  
  878. public boolean canSay() {
  879. return System.currentTimeMillis() - lastSay > 10000;
  880. }
  881.  
  882. public void setLastSay() {
  883. lastSay = System.currentTimeMillis();
  884. }
  885.  
  886. public void resetBank() {
  887. setAccessingBank(false);
  888. actionSender.hideBank();
  889. }
  890.  
  891. public Player(IoSession ios) {
  892. ioSession = ios;
  893. currentIP = ((InetSocketAddress)ios.getRemoteAddress()).getAddress().getHostAddress();
  894. currentLogin = System.currentTimeMillis();
  895. actionSender = new MiscPacketBuilder(this);
  896. setBusy(true);
  897. questManager = new QuestManager(this);
  898. }
  899.  
  900. public void setServerKey(long key) {
  901. sessionKeys[2] = (int)(key >> 32);
  902. sessionKeys[3] = (int)key;
  903. }
  904.  
  905. public boolean setSessionKeys(int[] keys) {
  906. boolean valid = (sessionKeys[2] == keys[2] && sessionKeys[3] == keys[3]);
  907. sessionKeys = keys;
  908. return valid;
  909. }
  910.  
  911. public boolean destroyed() {
  912. return destroy;
  913. }
  914.  
  915. public void destroy(boolean force) {
  916. if(destroy) {
  917. return;
  918. }
  919. if(force || canLogout()) {
  920. destroy = true;
  921. actionSender.sendLogout();
  922. }
  923. else {
  924. final long startDestroy = System.currentTimeMillis();
  925. world.getDelayedEventHandler().add(new DelayedEvent(this, 60000) {
  926. public void run() {
  927. if(owner.canLogout() || (!(owner.inCombat() && owner.isDueling()) && System.currentTimeMillis() - startDestroy > 60000)) {
  928. // owner.setForcelogout();
  929. //if(System.currentTimeMillis() - owner.getForcelogout() >= 60000){
  930. owner.destroy(true);
  931. running = false;
  932. ///}
  933. }
  934. }
  935. });
  936. }
  937. }
  938.  
  939. public int getCombatStyle() {
  940. return combatStyle;
  941. }
  942.  
  943. public void setCombatStyle(int style) {
  944. combatStyle = style;
  945. }
  946.  
  947. public void load(String username, String password, int uid, boolean reconnecting) {
  948. setID(uid);
  949. this.password = password;
  950. this.reconnecting = reconnecting;
  951. usernameHash = DataConversions.usernameToHash(username);
  952. this.username = DataConversions.hashToUsername(usernameHash);
  953.  
  954. world.getServer().getLoginConnector().getActionSender().playerLogin(this);
  955.  
  956. world.getDelayedEventHandler().add(new DelayedEvent(this, 60000) {
  957. public void run() {
  958. for(int statIndex = 0;statIndex < 18;statIndex++) {
  959. if(statIndex == 5) {
  960. continue;
  961. }
  962. int curStat = getCurStat(statIndex);
  963. int maxStat = getMaxStat(statIndex);
  964. if(curStat > maxStat) {
  965. setCurStat(statIndex, curStat - 1);
  966. getActionSender().sendStat(statIndex);
  967. checkStat(statIndex);
  968. }
  969. else if(curStat < maxStat) {
  970. setCurStat(statIndex, curStat + 1);
  971. getActionSender().sendStat(statIndex);
  972. checkStat(statIndex);
  973. }
  974. }
  975. }
  976.  
  977. private void checkStat(int statIndex) {
  978. if(statIndex != 3 && owner.getCurStat(statIndex) == owner.getMaxStat(statIndex)) {
  979. owner.getActionSender().sendMessage("Your " + Formulae.statArray[statIndex] + " ability has returned to normal.");
  980. }
  981. }
  982. });
  983. drainer = new DelayedEvent(this, Integer.MAX_VALUE) {
  984. public void run() {
  985. int curPrayer = getCurStat(5);
  986. if(getDrainRate() > 0 && curPrayer > 0) {
  987. incCurStat(5, -1);
  988. getActionSender().sendStat(5);
  989. if(curPrayer <= 1) {
  990. for(int prayerID = 0;prayerID < 14;prayerID++) {
  991. setPrayer(prayerID, false);
  992. }
  993. setDrainRate(0);
  994. setDelay(Integer.MAX_VALUE);
  995. getActionSender().sendMessage("You have run out of prayer points. Return to a church to recharge");
  996. getActionSender().sendPrayers();
  997. }
  998. }
  999. }
  1000. };
  1001. world.getDelayedEventHandler().add(drainer);
  1002. }
  1003.  
  1004. public void resetTrading() {
  1005. if(isTrading()) {
  1006. actionSender.sendTradeWindowClose();
  1007. setStatus(Action.IDLE);
  1008. }
  1009. setWishToTrade(null);
  1010. setTrading(false);
  1011. setTradeOfferAccepted(false);
  1012. setTradeConfirmAccepted(false);
  1013. resetTradeOffer();
  1014. }
  1015.  
  1016. public void resetDueling() {
  1017. if(isDueling()) {
  1018. actionSender.sendDuelWindowClose();
  1019. setStatus(Action.IDLE);
  1020. }
  1021. setWishToDuel(null);
  1022. setDueling(false);
  1023. setDuelOfferAccepted(false);
  1024. setDuelConfirmAccepted(false);
  1025. resetDuelOffer();
  1026. clearDuelOptions();
  1027. }
  1028. public void checkDm() {
  1029. if(getLocation().inDm()) {
  1030. teleport(231, 440, false);
  1031. }
  1032. }
  1033.  
  1034.  
  1035. public void clearDuelOptions() {
  1036. for(int i = 0;i < 4;i++) {
  1037. duelOptions[i] = false;
  1038. } }
  1039.  
  1040. public void save() {
  1041. SavePacketBuilder builder = new SavePacketBuilder();
  1042. builder.setPlayer(this);
  1043. LSPacket temp = builder.getPacket();
  1044. if(temp != null) {
  1045. world.getServer().getLoginConnector().getSession().write(temp);
  1046. }
  1047. }
  1048.  
  1049. public void setCharged() {
  1050. lastCharge = System.currentTimeMillis();
  1051. }
  1052.  
  1053. public boolean isCharged() {
  1054. return System.currentTimeMillis() - lastCharge > 600000;
  1055. }
  1056.  
  1057. public boolean canReport() {
  1058. return System.currentTimeMillis() - lastReport > 60000;
  1059. }
  1060.  
  1061. public void setLastReport() {
  1062. lastReport = System.currentTimeMillis();
  1063. }
  1064. public void incKills() {
  1065. kills++;
  1066. }
  1067. public int getUniqueKills() {
  1068. if(killed.length() == 0)
  1069. return 0;
  1070.  
  1071. return killed.split("\\|").length;
  1072. }
  1073. public String getKilled()
  1074. {
  1075. if(killed.startsWith("|"))
  1076. killed = killed.substring(1);
  1077. if(killed.endsWith("|"))
  1078. killed = killed.substring(0, killed.length() - 1);
  1079.  
  1080. return killed.trim();
  1081. }
  1082. public void addKilled(Player p)
  1083. {
  1084. String hash = String.valueOf(p.getUsernameHash());
  1085.  
  1086. if(killed.indexOf(hash) > -1)
  1087. return;
  1088.  
  1089. killed = killed + "|" + hash;
  1090. }
  1091. public void setKilled(String s)
  1092. {
  1093. killed = s;
  1094. }
  1095. public void setKills(int i)
  1096. {
  1097. kills = i;
  1098. }
  1099. public int getKills()
  1100. {
  1101. return kills;
  1102. }
  1103. public void killedBy(Mob mob) {
  1104. killedBy(mob, false);
  1105. }
  1106.  
  1107. public void killedBy(Mob mob, boolean stake) {
  1108. if(!loggedIn) {
  1109. Logger.error(username + " not logged in, but killed!");
  1110. return;
  1111. }
  1112. if(mob instanceof Player) {
  1113. int exp = 1328;
  1114. int exp2 = 700;
  1115. Player player = (Player)mob;
  1116. player.getActionSender().sendMessage("You have defeated " + getUsername() + "!");
  1117. if(player.getLocation().inWilderness() || player.getLocation().inPurePk()) {
  1118. if(getCombatLevel() > player.getCombatLevel()){
  1119. player.incExp(7, exp + 1000, true);
  1120. player.getActionSender().sendStat(7);
  1121. } else if(getCombatLevel() < player.getCombatLevel()){
  1122. player.incExp(7, exp2, true);
  1123. player.getActionSender().sendStat(7);
  1124. } else {
  1125. player.incExp(7, exp, true);
  1126. player.getActionSender().sendStat(7);
  1127. }
  1128. for(Player p : world.getPlayers())
  1129. {
  1130. p.getActionSender().sendMessage("@red@[Server] @gre@" + player.getUsername() + " @whi@just Raped@red@ " + getUsername() + "@whi@!");
  1131. }
  1132. player.getActionSender().sendMessage("You just earned some Pking experience!");
  1133. }
  1134. player.getActionSender().sendSound("victory");
  1135. player.incKills();
  1136. player.addKilled(this);
  1137. world.getDelayedEventHandler().add(new MiniEvent(player) {
  1138. public void action() {
  1139. owner.getActionSender().sendScreenshot();
  1140. }
  1141. });
  1142. world.getServer().getLoginConnector().getActionSender().logKill(player.getUsernameHash(), usernameHash, stake);
  1143.  
  1144. }
  1145. Mob opponent = super.getOpponent();
  1146. if(opponent != null) {
  1147. opponent.resetCombat(CombatState.WON);
  1148. }
  1149. actionSender.sendDied();
  1150. for(int i = 0;i < 18;i++) {
  1151. curStat[i] = maxStat[i];
  1152. actionSender.sendStat(i);
  1153. }
  1154.  
  1155. Player player = mob instanceof Player ? (Player)mob : null;
  1156. if(stake) {
  1157. for(InvItem item : duelOffer) {
  1158. InvItem affectedItem = getInventory().get(item);
  1159. if(affectedItem == null) {
  1160. setSuspiciousPlayer(true);
  1161. Logger.error("Missing staked item [" + item.getID() + ", " + item.getAmount() + "] from = " + usernameHash + "; to = " + player.getUsernameHash() + ";");
  1162. continue;
  1163. }
  1164. if(affectedItem.isWielded()) {
  1165. affectedItem.setWield(false);
  1166. updateWornItems(affectedItem.getWieldableDef().getWieldPos(), getPlayerAppearance().getSprite(affectedItem.getWieldableDef().getWieldPos()));
  1167. }
  1168. getInventory().remove(item);
  1169. world.registerItem(new Item(item.getID(), getX(), getY(), item.getAmount(), player));
  1170.  
  1171. }
  1172. }
  1173.  
  1174. else {
  1175. inventory.sort();
  1176. ListIterator<InvItem> iterator = inventory.iterator();
  1177. if(!isSkulled()) {
  1178. for(int i = 0;i < 3 && iterator.hasNext();i++) {
  1179. if((iterator.next()).getDef().isStackable()) {
  1180. iterator.previous();
  1181. break;
  1182. }
  1183. }
  1184. }
  1185. if(activatedPrayers[8] && iterator.hasNext()) {
  1186. if(((InvItem)iterator.next()).getDef().isStackable()) {
  1187. iterator.previous();
  1188. }
  1189. }
  1190. for(int slot = 0;iterator.hasNext();slot++) {
  1191. InvItem item = (InvItem)iterator.next();
  1192. if(item.isWielded()) {
  1193. item.setWield(false);
  1194. updateWornItems(item.getWieldableDef().getWieldPos(), appearance.getSprite(item.getWieldableDef().getWieldPos()));
  1195. }
  1196. iterator.remove();
  1197. world.registerItem(new Item(item.getID(), getX(), getY(), item.getAmount(), player));
  1198.  
  1199. }
  1200. removeSkull();
  1201.  
  1202. }
  1203.  
  1204. world.registerItem(new Item(20, getX(), getY(), 1, player));
  1205.  
  1206.  
  1207. for(int x = 0;x < activatedPrayers.length;x++) {
  1208. if(activatedPrayers[x]) {
  1209. removePrayerDrain(x);
  1210. activatedPrayers[x] = false;
  1211. }
  1212. }
  1213. actionSender.sendPrayers();
  1214.  
  1215. setLocation(Point.location(233, 439), true);
  1216. Player affectedPlayer = world.getPlayer(usernameHash);
  1217. int xps = 664;
  1218. if(opponent instanceof Player)
  1219. {
  1220. if(player.getLocation().inWilderness()) {
  1221. incExp(7, -xps, true);
  1222. getActionSender().sendStat(7);
  1223. getActionSender().sendMessage("You lost 1000 Pking exp to: " + player.getUsername());
  1224. getActionSender().sendStat(7);
  1225. }
  1226. }
  1227. Collection<Player> allWatched = watchedPlayers.getAllEntities();
  1228. for (Player p : allWatched) {
  1229. p.removeWatchedPlayer(this);
  1230. }
  1231.  
  1232. resetPath();
  1233. resetCombat(CombatState.LOST);
  1234. actionSender.sendWorldInfo();
  1235. actionSender.sendEquipmentStats();
  1236. actionSender.sendInventory();
  1237. }
  1238.  
  1239. public void addAttackedBy(Player p) {
  1240. attackedBy.put(p.getUsernameHash(), System.currentTimeMillis());
  1241. }
  1242.  
  1243. public long lastAttackedBy(Player p) {
  1244. Long time = attackedBy.get(p.getUsernameHash());
  1245. if(time != null) {
  1246. return time;
  1247. }
  1248. return 0;
  1249. }
  1250.  
  1251. public void setCastTimer() {
  1252. lastSpellCast = System.currentTimeMillis();
  1253. }
  1254.  
  1255. public void setSpellFail() {
  1256. lastSpellCast = System.currentTimeMillis() + 20000;
  1257. }
  1258.  
  1259. public int getSpellWait() {
  1260. return DataConversions.roundUp((double)(1200 - (System.currentTimeMillis() - lastSpellCast)) / 1000D);
  1261. }
  1262.  
  1263. public long getCastTimer() {
  1264. return lastSpellCast;
  1265. }
  1266.  
  1267. public boolean castTimer() {
  1268. return System.currentTimeMillis() - lastSpellCast > 1200;
  1269. }
  1270.  
  1271. public boolean checkAttack(Mob mob, boolean missile) {
  1272. if(mob instanceof Player) {
  1273. Player victim = (Player)mob;
  1274. if((inCombat() && isDueling()) && (victim.inCombat() && victim.isDueling())) {
  1275. Player opponent = (Player)getOpponent();
  1276. if(opponent != null && victim.equals(opponent)) {
  1277. return true;
  1278. }
  1279. }
  1280. if(System.currentTimeMillis() - mob.getCombatTimer() < (mob.getCombatState() == CombatState.RUNNING || mob.getCombatState() == CombatState.WAITING ? 3300 : 625) && !mob.inCombat()) {
  1281. return false;
  1282. }
  1283. int myWildLvl = getLocation().wildernessLevel();
  1284. int victimWildLvl = victim.getLocation().wildernessLevel();
  1285. if(myWildLvl < 1 || victimWildLvl < 1) {
  1286. actionSender.sendMessage("You cannot attack other players outside of the wilderness!");
  1287. return false;
  1288. }
  1289. int combDiff = Math.abs(getCombatLevel() - victim.getCombatLevel());
  1290. if(combDiff > myWildLvl) {
  1291. actionSender.sendMessage("You must move to at least level " + combDiff + " wilderness to attack " + victim.getUsername() + "!");
  1292. return false;
  1293. }
  1294. if(combDiff > victimWildLvl) {
  1295. actionSender.sendMessage(victim.getUsername() + " is not in high enough wilderness for you to attack!");
  1296. return false;
  1297. }
  1298. return true;
  1299. }
  1300. else if(mob instanceof Npc) {
  1301. Npc victim = (Npc)mob;
  1302. if(!victim.getDef().isAttackable()) {
  1303. setSuspiciousPlayer(true);
  1304. return false;
  1305. }
  1306. return true;
  1307. }
  1308. return true;
  1309. }
  1310.  
  1311. public void informOfBubble(Bubble b) {
  1312. bubblesNeedingDisplayed.add(b);
  1313. }
  1314.  
  1315. public List<Bubble> getBubblesNeedingDisplayed() {
  1316. return bubblesNeedingDisplayed;
  1317. }
  1318.  
  1319. public void clearBubblesNeedingDisplayed() {
  1320. bubblesNeedingDisplayed.clear();
  1321. }
  1322.  
  1323. public void informOfChatMessage(ChatMessage cm) {
  1324. chatMessagesNeedingDisplayed.add(cm);
  1325. }
  1326.  
  1327. public void sayMessage(String msg, Mob to) {
  1328. ChatMessage cm = new ChatMessage(this, msg, to);
  1329. chatMessagesNeedingDisplayed.add(cm);
  1330. }
  1331.  
  1332. public void informOfNpcMessage(ChatMessage cm) {
  1333. npcMessagesNeedingDisplayed.add(cm);
  1334. }
  1335.  
  1336. public List<ChatMessage> getNpcMessagesNeedingDisplayed() {
  1337. return npcMessagesNeedingDisplayed;
  1338. }
  1339.  
  1340. public List<ChatMessage> getChatMessagesNeedingDisplayed() {
  1341. return chatMessagesNeedingDisplayed;
  1342. }
  1343.  
  1344. public void clearNpcMessagesNeedingDisplayed() {
  1345. npcMessagesNeedingDisplayed.clear();
  1346. }
  1347.  
  1348. public void clearChatMessagesNeedingDisplayed() {
  1349. chatMessagesNeedingDisplayed.clear();
  1350. }
  1351.  
  1352. public void informOfModifiedHits(Mob mob) {
  1353. if(mob instanceof Player) {
  1354. playersNeedingHitsUpdate.add((Player)mob);
  1355. }
  1356. else if(mob instanceof Npc) {
  1357. npcsNeedingHitsUpdate.add((Npc)mob);
  1358. }
  1359. }
  1360.  
  1361. public List<Player> getPlayersRequiringHitsUpdate() {
  1362. return playersNeedingHitsUpdate;
  1363. }
  1364.  
  1365. public List<Npc> getNpcsRequiringHitsUpdate() {
  1366. return npcsNeedingHitsUpdate;
  1367. }
  1368.  
  1369. public void clearPlayersNeedingHitsUpdate() {
  1370. playersNeedingHitsUpdate.clear();
  1371. }
  1372.  
  1373. public void clearNpcsNeedingHitsUpdate() {
  1374. npcsNeedingHitsUpdate.clear();
  1375. }
  1376.  
  1377. public void informOfProjectile(Projectile p) {
  1378. projectilesNeedingDisplayed.add(p);
  1379. }
  1380.  
  1381. public List<Projectile> getProjectilesNeedingDisplayed() {
  1382. return projectilesNeedingDisplayed;
  1383. }
  1384.  
  1385. public void clearProjectilesNeedingDisplayed() {
  1386. projectilesNeedingDisplayed.clear();
  1387. }
  1388.  
  1389. public void addPrayerDrain(int prayerID) {
  1390. PrayerDef prayer = EntityHandler.getPrayerDef(prayerID);
  1391. drainRate += prayer.getDrainRate();
  1392. drainer.setDelay((int)(240000 / drainRate));
  1393. }
  1394.  
  1395. public void removePrayerDrain(int prayerID) {
  1396. PrayerDef prayer = EntityHandler.getPrayerDef(prayerID);
  1397. drainRate -= prayer.getDrainRate();
  1398. if(drainRate <= 0) {
  1399. drainRate = 0;
  1400. drainer.setDelay(Integer.MAX_VALUE);
  1401. }
  1402. else {
  1403. drainer.setDelay((int)(240000 / drainRate));
  1404. }
  1405. }
  1406.  
  1407. public boolean isFriendsWith(long usernameHash) {
  1408. return friendList.containsKey(usernameHash);
  1409. }
  1410.  
  1411. public boolean isIgnoring(long usernameHash) {
  1412. return ignoreList.contains(usernameHash);
  1413. }
  1414.  
  1415. public Collection<Entry<Long, Integer>> getFriendList() {
  1416. return friendList.entrySet();
  1417. }
  1418.  
  1419. public ArrayList<Long> getIgnoreList() {
  1420. return ignoreList;
  1421. }
  1422.  
  1423. public void removeFriend(long id) {
  1424. friendList.remove(id);
  1425. }
  1426.  
  1427. public void removeIgnore(long id) {
  1428. ignoreList.remove(id);
  1429. }
  1430.  
  1431. public void addFriend(long id, int world) {
  1432. friendList.put(id, world);
  1433. }
  1434.  
  1435. public void addIgnore(long id) {
  1436. ignoreList.add(id);
  1437. }
  1438.  
  1439. public int friendCount() {
  1440. return friendList.size();
  1441. }
  1442.  
  1443. public int ignoreCount() {
  1444. return ignoreList.size();
  1445. }
  1446.  
  1447. public void setTradeConfirmAccepted(boolean b) {
  1448. tradeConfirmAccepted = b;
  1449. }
  1450.  
  1451. public void setDuelConfirmAccepted(boolean b) {
  1452. duelConfirmAccepted = b;
  1453. }
  1454.  
  1455. public boolean isTradeConfirmAccepted() {
  1456. return tradeConfirmAccepted;
  1457. }
  1458.  
  1459. public boolean isDuelConfirmAccepted() {
  1460. return duelConfirmAccepted;
  1461. }
  1462.  
  1463. public void setTradeOfferAccepted(boolean b) {
  1464. tradeOfferAccepted = b;
  1465. }
  1466.  
  1467. public void setDuelOfferAccepted(boolean b) {
  1468. duelOfferAccepted = b;
  1469. }
  1470.  
  1471. public boolean isTradeOfferAccepted() {
  1472. return tradeOfferAccepted;
  1473. }
  1474.  
  1475. public boolean isDuelOfferAccepted() {
  1476. return duelOfferAccepted;
  1477. }
  1478.  
  1479. public void resetTradeOffer() {
  1480. tradeOffer.clear();
  1481. }
  1482. public void resetDuelOffer() {
  1483. duelOffer.clear();
  1484. }
  1485.  
  1486. public void addToTradeOffer(InvItem item) {
  1487. tradeOffer.add(item);
  1488. }
  1489.  
  1490. public void addToDuelOffer(InvItem item) {
  1491. duelOffer.add(item);
  1492. }
  1493.  
  1494. public ArrayList<InvItem> getTradeOffer() {
  1495. return tradeOffer;
  1496. }
  1497.  
  1498. public ArrayList<InvItem> getDuelOffer() {
  1499. return duelOffer;
  1500. }
  1501.  
  1502. public void setTrading(boolean b) {
  1503. isTrading = b;
  1504. }
  1505.  
  1506. public void setDueling(boolean b) {
  1507. isDueling = b;
  1508. }
  1509.  
  1510. public boolean isTrading() {
  1511. return isTrading;
  1512. }
  1513.  
  1514. public boolean isDueling() {
  1515. return isDueling;
  1516. }
  1517.  
  1518. public void setWishToTrade(Player p) {
  1519. wishToTrade = p;
  1520. }
  1521.  
  1522. public void setWishToDuel(Player p) {
  1523. wishToDuel = p;
  1524. }
  1525.  
  1526. public Player getWishToTrade() {
  1527. return wishToTrade;
  1528. }
  1529.  
  1530. public Player getWishToDuel() {
  1531. return wishToDuel;
  1532. }
  1533.  
  1534. public void setDuelSetting(int i, boolean b) {
  1535. duelOptions[i] = b;
  1536. }
  1537.  
  1538. public long getLastSayTime() {
  1539. return lastSayTime;
  1540. }
  1541.  
  1542. public long setLastSayTime(long saytime) {
  1543. lastSayTime = saytime;
  1544. return lastSayTime;
  1545. }
  1546.  
  1547. public boolean getDuelSetting(int i) {
  1548. try {
  1549. for(InvItem item : duelOffer) {
  1550. if(DataConversions.inArray(Formulae.runeIDs, item.getID())) {
  1551. setDuelSetting(1, true);
  1552. break;
  1553. }
  1554. }
  1555. for(InvItem item : wishToDuel.getDuelOffer()) {
  1556. if(DataConversions.inArray(Formulae.runeIDs, item.getID())) {
  1557. setDuelSetting(1, true);
  1558. break;
  1559. }
  1560. }
  1561. }
  1562. catch(Exception e) { }
  1563. return duelOptions[i];
  1564. }
  1565.  
  1566. public void setMale(boolean male) {
  1567. maleGender = male;
  1568. }
  1569.  
  1570. public boolean isMale() {
  1571. return maleGender;
  1572. }
  1573.  
  1574. public void setChangingAppearance(boolean b) {
  1575. changingAppearance = b;
  1576. }
  1577.  
  1578. public boolean isChangingAppearance() {
  1579. return changingAppearance;
  1580. }
  1581.  
  1582. public boolean isReconnecting() {
  1583. return reconnecting;
  1584. }
  1585.  
  1586. public void setLastLogin(long l) {
  1587. lastLogin = l;
  1588. }
  1589.  
  1590. public long getLastLogin() {
  1591. return lastLogin;
  1592. }
  1593.  
  1594. public int getDaysSinceLastLogin() {
  1595. long now = Calendar.getInstance().getTimeInMillis() / 1000;
  1596. return (int)((now - lastLogin) / 86400);
  1597. }
  1598.  
  1599. public long getCurrentLogin() {
  1600. return currentLogin;
  1601. }
  1602.  
  1603. public void setLastIP(String ip) {
  1604. lastIP = ip;
  1605. }
  1606.  
  1607. public String getCurrentIP() {
  1608. return currentIP;
  1609. }
  1610.  
  1611. public String getLastIP() {
  1612. return lastIP;
  1613. }
  1614.  
  1615. public void setGroupID(int id) {
  1616. groupID = id;
  1617. }
  1618.  
  1619. public int getGroupID() {
  1620. return groupID;
  1621. }
  1622.  
  1623. public boolean isSubscriber() {
  1624. return groupID == 5 || isPMod() || isMod() || isAdmin();
  1625. }
  1626. public boolean isMuted() {
  1627. return muted == 1;
  1628. }
  1629.  
  1630. public boolean isPMod() {
  1631. return groupID == 6 || isMod() || isAdmin();
  1632. }
  1633.  
  1634. public boolean isMod() {
  1635. return groupID == 2 || isAdmin();
  1636. }
  1637.  
  1638. public boolean isAdmin() {
  1639. return groupID == 1;
  1640. }
  1641.  
  1642. public int getArmourPoints() {
  1643. int points = 1;
  1644. for(InvItem item : inventory.getItems()) {
  1645. if(item.isWielded()) {
  1646. points += item.getWieldableDef().getArmourPoints();
  1647. }
  1648. }
  1649. return points < 1 ? 1 : points;
  1650. }
  1651.  
  1652. public int getWeaponAimPoints() {
  1653. int points = 1;
  1654. for(InvItem item : inventory.getItems()) {
  1655. if(item.isWielded()) {
  1656. points += item.getWieldableDef().getWeaponAimPoints();
  1657. }
  1658. }
  1659. return points < 1 ? 1 : points;
  1660. }
  1661.  
  1662. public int getWeaponPowerPoints() {
  1663. int points = 1;
  1664. for(InvItem item : inventory.getItems()) {
  1665. if(item.isWielded()) {
  1666. points += item.getWieldableDef().getWeaponPowerPoints();
  1667. }
  1668. }
  1669. return points < 1 ? 1 : points;
  1670. }
  1671.  
  1672. public int getMagicPoints() {
  1673. int points = 1;
  1674. for(InvItem item : inventory.getItems()) {
  1675. if(item.isWielded()) {
  1676. points += item.getWieldableDef().getMagicPoints();
  1677. }
  1678. }
  1679. return points < 1 ? 1 : points;
  1680. }
  1681.  
  1682. public int getPrayerPoints() {
  1683. int points = 1;
  1684. for(InvItem item : inventory.getItems()) {
  1685. if(item.isWielded()) {
  1686. points += item.getWieldableDef().getPrayerPoints();
  1687. }
  1688. }
  1689. return points < 1 ? 1 : points;
  1690. }
  1691.  
  1692. public int getRangePoints() {
  1693. int points = 1;
  1694. for(InvItem item : inventory.getItems()) {
  1695. if(item.isWielded()) {
  1696. points += item.getWieldableDef().getRangePoints();
  1697. }
  1698. }
  1699. return points < 1 ? 1 : points;
  1700. }
  1701.  
  1702. public MiscPacketBuilder getActionSender() {
  1703. return actionSender;
  1704. }
  1705.  
  1706. public int[] getWornItems() {
  1707. return wornItems;
  1708. }
  1709.  
  1710. public void updateWornItems(int index, int id) {
  1711. wornItems[index] = id;
  1712. super.ourAppearanceChanged = true;
  1713. }
  1714.  
  1715. public void setWornItems(int[] worn) {
  1716. wornItems = worn;
  1717. super.ourAppearanceChanged = true;
  1718. }
  1719.  
  1720. public Inventory getInventory() {
  1721. return inventory;
  1722. }
  1723.  
  1724. public void setInventory(Inventory i) {
  1725. inventory = i;
  1726. }
  1727.  
  1728. public Bank getBank() {
  1729. return bank;
  1730. }
  1731.  
  1732. public void setBank(Bank b) {
  1733. bank = b;
  1734. }
  1735.  
  1736. public void setGameSetting(int i, boolean b) {
  1737. gameSettings[i] = b;
  1738. }
  1739.  
  1740. public boolean getGameSetting(int i) {
  1741. return gameSettings[i];
  1742. }
  1743.  
  1744. public void setPrivacySetting(int i, boolean b) {
  1745. privacySettings[i] = b;
  1746. }
  1747.  
  1748. public boolean getPrivacySetting(int i) {
  1749. return privacySettings[i];
  1750. }
  1751.  
  1752. public long getLastPing() {
  1753. return lastPing;
  1754. }
  1755.  
  1756. public IoSession getSession() {
  1757. return ioSession;
  1758. }
  1759.  
  1760. public boolean loggedIn() {
  1761. return loggedIn;
  1762. }
  1763.  
  1764. public void setLoggedIn(boolean loggedIn) {
  1765. if(loggedIn) {
  1766. currentLogin = System.currentTimeMillis();
  1767. }
  1768. this.loggedIn = loggedIn;
  1769. }
  1770.  
  1771. public String getUsername() {
  1772. return username;
  1773. }
  1774.  
  1775. public long getUsernameHash() {
  1776. return usernameHash;
  1777. }
  1778.  
  1779. public String getPassword() {
  1780. return password;
  1781. }
  1782.  
  1783. public void ping() {
  1784. lastPing = System.currentTimeMillis();
  1785. }
  1786.  
  1787. public boolean isSkulled() {
  1788. return skullEvent != null;
  1789. }
  1790.  
  1791. public PlayerAppearance getPlayerAppearance() {
  1792. return appearance;
  1793. }
  1794.  
  1795. public void setAppearance(PlayerAppearance appearance) {
  1796. this.appearance = appearance;
  1797. }
  1798.  
  1799. public int getSkullTime() {
  1800. if(isSkulled()) {
  1801. return skullEvent.timeTillNextRun();
  1802. }
  1803. return 0;
  1804. }
  1805.  
  1806. public void addSkull(long timeLeft) {
  1807. if(!isSkulled()) {
  1808. skullEvent = new DelayedEvent(this, 1200000) {
  1809. public void run() {
  1810. removeSkull();
  1811. }
  1812. };
  1813. world.getDelayedEventHandler().add(skullEvent);
  1814. super.setAppearnceChanged(true);
  1815. }
  1816. skullEvent.setLastRun(System.currentTimeMillis() - (1200000 - timeLeft));
  1817. }
  1818.  
  1819. public void removeSkull() {
  1820. if(!isSkulled()) {
  1821. return;
  1822. }
  1823. super.setAppearnceChanged(true);
  1824. skullEvent.stop();
  1825. skullEvent = null;
  1826. }
  1827.  
  1828. public void setSuspiciousPlayer(boolean suspicious) {
  1829. this.suspicious = suspicious;
  1830. }
  1831.  
  1832. public void addPlayersAppearanceIDs(int[] indicies, int[] appearanceIDs) {
  1833. for (int x = 0; x < indicies.length; x++) {
  1834. knownPlayersAppearanceIDs.put(indicies[x], appearanceIDs[x]);
  1835. }
  1836. }
  1837.  
  1838. public List<Player> getPlayersRequiringAppearanceUpdate() {
  1839. List<Player> needingUpdates = new ArrayList<Player>();
  1840. needingUpdates.addAll(watchedPlayers.getNewEntities());
  1841. if (super.ourAppearanceChanged) {
  1842. needingUpdates.add(this);
  1843. }
  1844. for (Player p : watchedPlayers.getKnownEntities()) {
  1845. if (needsAppearanceUpdateFor(p)) {
  1846. needingUpdates.add(p);
  1847. }
  1848. }
  1849. return needingUpdates;
  1850. }
  1851.  
  1852. private boolean needsAppearanceUpdateFor(Player p) {
  1853. int playerServerIndex = p.getIndex();
  1854. if (knownPlayersAppearanceIDs.containsKey(playerServerIndex)) {
  1855. int knownPlayerAppearanceID = knownPlayersAppearanceIDs.get(playerServerIndex);
  1856. if(knownPlayerAppearanceID != p.getAppearanceID()) {
  1857. return true;
  1858. }
  1859. }
  1860. else {
  1861. return true;
  1862. }
  1863. return false;
  1864. }
  1865.  
  1866. public void updateViewedPlayers() {
  1867. List<Player> playersInView = viewArea.getPlayersInView();
  1868. for (Player p : playersInView) {
  1869. if (p.getIndex() != getIndex() && p.loggedIn()) {
  1870. this.informOfPlayer(p);
  1871. p.informOfPlayer(this);
  1872. }
  1873. }
  1874. }
  1875.  
  1876. public void updateViewedObjects() {
  1877. List<GameObject> objectsInView = viewArea.getGameObjectsInView();
  1878. for (GameObject o : objectsInView) {
  1879. if (!watchedObjects.contains(o) && !o.isRemoved() && withinRange(o)) {
  1880. watchedObjects.add(o);
  1881. }
  1882. }
  1883. }
  1884.  
  1885. public void updateViewedItems() {
  1886. List<Item> itemsInView = viewArea.getItemsInView();
  1887. for (Item i : itemsInView) {
  1888. if (!watchedItems.contains(i) && !i.isRemoved() && withinRange(i) && i.visibleTo(this)) {
  1889. watchedItems.add(i);
  1890. }
  1891. }
  1892. }
  1893.  
  1894. public void updateViewedNpcs() {
  1895. List<Npc> npcsInView = viewArea.getNpcsInView();
  1896. for (Npc n : npcsInView) {
  1897. if ((!watchedNpcs.contains(n) || watchedNpcs.isRemoving(n)) && withinRange(n)) {
  1898. watchedNpcs.add(n);
  1899. }
  1900. }
  1901. }
  1902.  
  1903. public void teleport(int x, int y, boolean bubble) {
  1904. Mob opponent = super.getOpponent();
  1905. if(inCombat()) {
  1906. resetCombat(CombatState.ERROR);
  1907. }
  1908. if(opponent != null) {
  1909. opponent.resetCombat(CombatState.ERROR);
  1910. }
  1911. for (Object o : getWatchedPlayers().getAllEntities()) {
  1912. Player p = ((Player)o);
  1913. if(bubble) {
  1914. p.getActionSender().sendTeleBubble(getX(), getY(), false);
  1915. }
  1916. p.removeWatchedPlayer(this);
  1917. }
  1918. if(bubble) {
  1919. actionSender.sendTeleBubble(getX(), getY(), false);
  1920. }
  1921. setLocation(Point.location(x, y), true);
  1922. resetPath();
  1923. actionSender.sendWorldInfo();
  1924. }
  1925.  
  1926. /**
  1927. * This is a 'another player has tapped us on the shoulder' method.
  1928. *
  1929. * If we are in another players viewArea, they should in theory be in ours.
  1930. * So they will call this method to let the player know they should probably
  1931. * be informed of them.
  1932. */
  1933. public void informOfPlayer(Player p) {
  1934. if ((!watchedPlayers.contains(p) || watchedPlayers.isRemoving(p)) && withinRange(p)) {
  1935. watchedPlayers.add(p);
  1936. }
  1937. }
  1938.  
  1939. public StatefulEntityCollection<Player> getWatchedPlayers() {
  1940. return watchedPlayers;
  1941. }
  1942.  
  1943. public StatefulEntityCollection<GameObject> getWatchedObjects() {
  1944. return watchedObjects;
  1945. }
  1946.  
  1947. public StatefulEntityCollection<Item> getWatchedItems() {
  1948. return watchedItems;
  1949. }
  1950.  
  1951. public StatefulEntityCollection<Npc> getWatchedNpcs() {
  1952. return watchedNpcs;
  1953. }
  1954.  
  1955. public void removeWatchedNpc(Npc n) {
  1956. watchedNpcs.remove(n);
  1957. }
  1958.  
  1959. public void removeWatchedPlayer(Player p) {
  1960. watchedPlayers.remove(p);
  1961. }
  1962.  
  1963. public void revalidateWatchedPlayers() {
  1964. for (Player p : watchedPlayers.getKnownEntities()) {
  1965. if (!withinRange(p) || !p.loggedIn()) {
  1966. watchedPlayers.remove(p);
  1967. knownPlayersAppearanceIDs.remove(p.getIndex());
  1968. }
  1969. }
  1970. }
  1971.  
  1972. public void revalidateWatchedObjects() {
  1973. for (GameObject o : watchedObjects.getKnownEntities()) {
  1974. if (!withinRange(o) || o.isRemoved()) {
  1975. watchedObjects.remove(o);
  1976. }
  1977. }
  1978. }
  1979.  
  1980. public void revalidateWatchedItems() {
  1981. for (Item i : watchedItems.getKnownEntities()) {
  1982. if (!withinRange(i) || i.isRemoved() || !i.visibleTo(this)) {
  1983. watchedItems.remove(i);
  1984. }
  1985. }
  1986. }
  1987.  
  1988. public void revalidateWatchedNpcs() {
  1989. for (Npc n : watchedNpcs.getKnownEntities()) {
  1990. if (!withinRange(n) || n.isRemoved()) {
  1991. watchedNpcs.remove(n);
  1992. }
  1993. }
  1994. }
  1995.  
  1996. public boolean withinRange(Entity e) {
  1997. int xDiff = location.getX() - e.getLocation().getX();
  1998. int yDiff = location.getY() - e.getLocation().getY();
  1999. return xDiff <= 16 && xDiff >= -15 && yDiff <= 16 && yDiff >= -15;
  2000. }
  2001.  
  2002. public int[] getCurStats() {
  2003. return curStat;
  2004. }
  2005.  
  2006. public int getCurStat(int id) {
  2007. return curStat[id];
  2008. }
  2009.  
  2010. public int getHits() {
  2011. return getCurStat(3);
  2012. }
  2013.  
  2014. public int getAttack() {
  2015. return getCurStat(0);
  2016. }
  2017.  
  2018. public int getDefense() {
  2019. return getCurStat(1);
  2020. }
  2021.  
  2022. public int getStrength() {
  2023. return getCurStat(2);
  2024. }
  2025.  
  2026. public void setHits(int lvl) {
  2027. setCurStat(3, lvl);
  2028. }
  2029.  
  2030. public void setCurStat(int id, int lvl) {
  2031. if(lvl <= 0) {
  2032. lvl = 0;
  2033. }
  2034. curStat[id] = lvl;
  2035. }
  2036.  
  2037. public int getMaxStat(int id) {
  2038. return maxStat[id];
  2039. }
  2040.  
  2041. public void setMaxStat(int id, int lvl) {
  2042. if(lvl < 0) {
  2043. lvl = 0;
  2044. }
  2045. maxStat[id] = lvl;
  2046. }
  2047.  
  2048. public int[] getMaxStats() {
  2049. return maxStat;
  2050. }
  2051.  
  2052. public int getSkillTotal() {
  2053. int total = 0;
  2054. for(int stat : maxStat) {
  2055. total += stat;
  2056. }
  2057. return total;
  2058. }
  2059.  
  2060. public void incCurStat(int i, int amount) {
  2061. curStat[i] += amount;
  2062. if(curStat[i] < 0) {
  2063. curStat[i] = 0;
  2064. }
  2065. }
  2066.  
  2067. public void incMaxStat(int i, int amount) {
  2068. maxStat[i] += amount;
  2069. if(maxStat[i] < 0) {
  2070. maxStat[i] = 0;
  2071. }
  2072. }
  2073.  
  2074. public void setFatigue(int fatigue) {
  2075. this.fatigue = fatigue;
  2076. }
  2077. public void setWrong(int wrong) {
  2078. this.wrong = wrong;
  2079. }
  2080. public void setMuted(int muted) {
  2081. this.muted = muted;
  2082. }
  2083. public void setBsay(int bsay) {
  2084. this.bsay = bsay;
  2085. }
  2086. public int getBsay() {
  2087. return bsay;
  2088. }
  2089. public int getFatigue() {
  2090. return fatigue;
  2091. }
  2092. public int getWrong() {
  2093. return wrong;
  2094. }
  2095. public int getMuted() {
  2096. return muted;
  2097. }
  2098. public void incWrong() {
  2099. wrong++;
  2100. }
  2101.  
  2102. public void incExp(int i, int amount, boolean useFatigue) {
  2103. useFatigue = true;
  2104. if(useFatigue && i != 7) {
  2105. if(fatigue >= 100) {
  2106. actionSender.sendMessage("@gre@You are too tired to gain experience, get some rest!");
  2107. return;
  2108. }
  2109. if(fatigue >= 96) {
  2110. actionSender.sendMessage("@gre@You start to feel tired, maybe you should rest soon.");
  2111. }
  2112. fatigue++;
  2113. actionSender.sendFatigue();
  2114. }
  2115. if(isSubscriber()) {
  2116. amount *= 1.5D;
  2117. }
  2118. if(getLocation().inWilderness() && i != 9 && i != 11 && i != 16 && i != 8) {
  2119. amount *= 1.4D;
  2120. }
  2121. if(getLocation().inWilderness() && i != 9 && i != 11 && i != 16 && i != 8 && world.getDuel() > 0) {
  2122. amount *= 1.8D;
  2123. }
  2124.  
  2125. if(i == 5) {
  2126. amount *= 1.5D;
  2127. }
  2128.  
  2129. if(getLocation().inPurePk() && i != 7) {
  2130. return;
  2131. }
  2132.  
  2133. exp[i] += amount;
  2134. if(exp[i] < 0) {
  2135. exp[i] = 0;
  2136. }
  2137. int level = Formulae.experienceToLevel(exp[i]);
  2138. if(level != maxStat[i]) {
  2139. int advanced = level - maxStat[i];
  2140. incCurStat(i, advanced);
  2141. incMaxStat(i, advanced);
  2142. actionSender.sendStat(i);
  2143. actionSender.sendMessage("@gre@You just advanced " + advanced + " " + Formulae.statArray[i] + " level!");
  2144. world.getDelayedEventHandler().add(new MiniEvent(this) {
  2145. public void action() {
  2146. owner.getActionSender().sendScreenshot();
  2147. }
  2148. });
  2149. int comb = Formulae.getCombatlevel(maxStat);
  2150. if(comb != getCombatLevel()) {
  2151. setCombatLevel(comb);
  2152. }
  2153. }
  2154. }
  2155.  
  2156. public int[] getExps() {
  2157. return exp;
  2158. }
  2159.  
  2160. public int getExp(int id) {
  2161. return exp[id];
  2162. }
  2163.  
  2164. public void setExp(int id, int lvl) {
  2165. if(lvl < 0) {
  2166. lvl = 0;
  2167. }
  2168. exp[id] = lvl;
  2169. }
  2170.  
  2171. public void setExp(int[] lvls) {
  2172. exp = lvls;
  2173. }
  2174.  
  2175. public boolean equals(Object o) {
  2176. if (o instanceof Player) {
  2177. Player p = (Player)o;
  2178. return usernameHash == p.getUsernameHash();
  2179. }
  2180. return false;
  2181. }
  2182.  
  2183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement