Advertisement
Guest User

Untitled

a guest
May 28th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 67.61 KB | None | 0 0
  1. package org.rscdaemon.server.model;
  2.  
  3. import org.rscdaemon.server.GUI;
  4. import org.rscdaemon.server.GameVars;
  5. import org.rscdaemon.server.util.Config;
  6. import org.rscdaemon.server.util.Formulae;
  7. import org.rscdaemon.server.util.DataConversions;
  8. import org.rscdaemon.server.util.StatefulEntityCollection;
  9. import org.rscdaemon.server.net.RSCPacket;
  10. import org.rscdaemon.server.packetbuilder.RSCPacketBuilder;
  11. import org.rscdaemon.server.packetbuilder.client.MiscPacketBuilder;
  12. import org.rscdaemon.server.entityhandling.EntityHandler;
  13. import org.rscdaemon.server.entityhandling.defs.PrayerDef;
  14. import org.rscdaemon.server.event.*;
  15. import org.rscdaemon.server.states.Action;
  16. import org.rscdaemon.server.states.CombatState;
  17. import org.rscdaemon.server.util.Logger;
  18. import org.rscdaemon.server.model.World;
  19. import org.rscdaemon.server.model.Point;
  20. import org.rscdaemon.server.*;
  21.  
  22. import org.apache.mina.common.IoSession;
  23.  
  24. import java.util.*;
  25. import java.io.File;
  26. import java.io.IOException;
  27. import java.io.FileInputStream;
  28. import java.io.FileOutputStream;
  29. import java.net.InetSocketAddress;
  30.  
  31. /**
  32. * A single player.
  33. */
  34. public final class Player extends Mob {
  35.  
  36. public void setSEvent(ShortEvent sEvent) {
  37. world.getDelayedEventHandler().add(sEvent);
  38. }
  39.  
  40. private String clanName;
  41. private long clanNameHash;
  42.  
  43. private Clan myClan;
  44. private long lastCreatedClan;
  45. private ClanInvite clanInvite;
  46.  
  47. public void resetClan() {
  48. myClan = null;
  49. clanName = "NULL";
  50. clanNameHash = DataConversions.usernameToHash(clanName);
  51. super.ourAppearanceChanged = true;
  52. }
  53.  
  54. public void setLastCreatedClan() {
  55. lastCreatedClan = System.currentTimeMillis();
  56. }
  57.  
  58. public long getClanNameHash() {
  59. return clanNameHash;
  60. }
  61.  
  62. public void setClanNameHash(long l) {
  63. this.clanNameHash = l;
  64. }
  65. public void setLastCreatedClan(long l) {
  66. this.lastCreatedClan = l;
  67. }
  68.  
  69. public boolean canCreateClan() {
  70. return System.currentTimeMillis() - lastCreatedClan >= 7200000L;
  71. }
  72.  
  73. public void setClanInvite(ClanInvite ci) {
  74. //System.out.println("setClanInvite, ");
  75. this.getActionSender().sendMessage("You have been invited to join clan:[@cya@"+ci.getClan().getName()+"@whi@], Type ::clanaccept to join.");
  76. this.clanInvite = ci;
  77. }
  78.  
  79. public boolean declineClanInvite() {
  80. if(clanInvite == null) {
  81. return false;
  82. }
  83. clanInvite = null;
  84. return true;
  85. }
  86.  
  87. public boolean hasClan() {
  88. return myClan != null;
  89. }
  90.  
  91. public boolean isClanLeader() {
  92. if(!hasClan()) {
  93. return false;
  94. }
  95. return myClan.getOwner().equals(this);
  96. }
  97.  
  98. public void setClan(Clan c) {
  99. this.myClan = c;
  100. this.clanName = c.getName();
  101. this.clanNameHash = DataConversions.usernameToHash(this.clanName);
  102. super.ourAppearanceChanged = true;
  103. }
  104.  
  105. public Clan getClan() {
  106. return myClan;
  107. }
  108.  
  109. public boolean acceptClanInvite() {
  110. if(clanInvite == null || !clanName.equals("NULL")) {
  111. return false;
  112. }
  113. myClan = clanInvite.getClan();
  114. clanName = clanInvite.getClan().getName();
  115. clanNameHash = DataConversions.usernameToHash(clanName);
  116. clanInvite.getClan().add(this, " has joined the clan.");
  117. clanInvite = null;
  118. getActionSender().sendMessage("You have joined "+clanName);
  119. super.ourAppearanceChanged = true;
  120. return true;
  121. }
  122.  
  123. /**
  124. * The player's username
  125. */
  126.  
  127. /**
  128. * clan
  129. */
  130.  
  131. private String username;
  132. /**
  133. * The player's username hash
  134. */
  135. private long usernameHash;
  136. /**
  137. * The player's password
  138. */
  139.  
  140. /**
  141. * Subscription System
  142. * --------------------------------------------------------------------------------
  143. **/
  144.  
  145. /**
  146. * Checks if the user is a subscriber
  147. * @param username of the investigated player
  148. * @return is rank equal to 1?
  149. */
  150. public static boolean isSub(String user) {
  151. int rank = Integer.valueOf(GUI.readValue(user, "rank"));
  152. return rank == 1;
  153. }
  154.  
  155. /**
  156. * Sets a user as subscriber for 30 days
  157. *
  158. * NOTE- If affected user is online, they need to logout inorder for
  159. * the sub to take affect. You can make it so the user gets
  160. * kicked from the server as soon as they get the sub by removing
  161. * the "//" from "world.kickPlayer(user);"
  162. *
  163. * @param username of the player that gets subscription
  164. */
  165. public static void setSub(String user) {
  166. if (GUI.isOnline(user)) {
  167. Player p = world.getPlayer(DataConversions.usernameToHash(user));
  168. p.rank = 1;
  169. //world.kickPlayer(user);
  170. } else {
  171. GUI.writeValue(user, "rank", "1");
  172. }
  173. java.util.Calendar cal = java.util.Calendar.getInstance();
  174.  
  175. cal.add(Calendar.DATE, 30);
  176. GUI.writeValue(user, "sube", Long.toString(cal.getTime().getTime()));
  177. }
  178.  
  179. /**
  180. * Sets a user as subscriber for 'length' amount of time in days
  181. *
  182. * NOTE- If affected user is online, they need to logout inorder for
  183. * the sub to take affect. You can make it so the user gets
  184. * kicked from the server as soon as they get the sub by removing
  185. * the "//" from "world.kickPlayer(user);"
  186. *
  187. * @param 'user' - Username of the player that gets subscription
  188. * 'length' - Number of days you want the user subbed
  189. */
  190. public static void setSub(String user, int length) {
  191. if (GUI.isOnline(user)) {
  192. Player p = world.getPlayer(DataConversions.usernameToHash(user));
  193. p.rank = 1;
  194. //world.kickPlayer(user);
  195. } else {
  196. GUI.writeValue(user, "rank", "1");
  197. }
  198. java.util.Calendar cal = java.util.Calendar.getInstance();
  199.  
  200. cal.add(Calendar.DATE, length);
  201. GUI.writeValue(user, "sube", Long.toString(cal.getTime().getTime()));
  202. }
  203.  
  204. /**
  205. * Unsub the users subscription
  206. *
  207. * NOTE- If affected user is online, they need to logout inorder for
  208. * the sub to take affect. You can make it so the user gets
  209. * kicked from the server as soon as they get the sub by removing
  210. * the "//" from "world.kickPlayer(user);"
  211. *
  212. * @param 'user' - Username of the player that gets UN-subscribed
  213. */
  214. public static void unSetSub(String user) {
  215. if (GUI.isOnline(user)) {
  216. Player p = world.getPlayer(DataConversions.usernameToHash(user));
  217. p.rank = 0;
  218. //world.kickPlayer(user);
  219. } else {
  220. GUI.writeValue(user, "rank", "0");
  221. }
  222.  
  223. GUI.writeValue(user, "sube", "");
  224. }
  225. /**
  226. * Gets when the subscription of the user ends
  227. * @param username of the investigated player
  228. * @return subscription end
  229. */
  230. public static long getSubEnd(String user) {
  231. if (!isSub(user)) {
  232. return 0; // Shouldn't really happen
  233. }
  234. long getsube = Long.parseLong(GUI.readValue(user, "sube"));
  235. return getsube;
  236. }
  237. /**
  238. * Gets the remaining subscription of the user
  239. * @param username of the investigated player
  240. * @return number of days remaining
  241. */
  242. public static int getRemSub(String user) {
  243. long sube = Long.parseLong(GUI.readValue(user, "sube"));
  244. java.util.Calendar cal = java.util.Calendar.getInstance();
  245. long subs = cal.getTime().getTime();
  246. if((sube - subs) < 0) {
  247. return 0;
  248. }
  249. return ((int)((sube - subs) / 86400000));
  250. }
  251. /**
  252. *End Sub System
  253. * --------------------------------------------------------------------------------
  254. **/
  255.  
  256. /**
  257. * Hidden Ground Items
  258. */
  259. private boolean hiddenItems = true;
  260.  
  261. public boolean getHiddenItem() {
  262. return hiddenItems;
  263. }
  264.  
  265. public void setHiddenItem(boolean hiddenitem) {
  266. hiddenItems = hiddenitem;
  267. }
  268.  
  269.  
  270. private String password;
  271. /**
  272. * Whether the player is currently logged in
  273. */
  274. private boolean loggedIn = false;
  275. /**
  276. * The IO session of this player
  277. */
  278. private IoSession ioSession;
  279. /**
  280. * Last time a 'ping' was received
  281. */
  282. private long lastPing = System.currentTimeMillis();
  283. public int rank;
  284. /**
  285. * The Players appearance
  286. */
  287. private PlayerAppearance appearance;
  288. /**
  289. * The items being worn by the player
  290. */
  291. private int[] wornItems = new int[12];
  292. /**
  293. * The current stat array
  294. */
  295. private int[] curStat = new int[18];
  296. /**
  297. * The max stat array
  298. */
  299. private int[] maxStat = new int[18];
  300. /**
  301. * The exp level array
  302. */
  303. private int[] exp = new int[18];
  304. /**
  305. * If the player has been sending suscicious packets
  306. */
  307. private boolean suspicious = false;
  308. /**
  309. * List of players this player 'knows' (recieved from the client) about
  310. */
  311. private HashMap<Integer, Integer> knownPlayersAppearanceIDs = new HashMap<Integer, Integer>();
  312. /**
  313. * Nearby players that we should be aware of
  314. */
  315. private StatefulEntityCollection<Player> watchedPlayers = new StatefulEntityCollection<Player>();
  316. /**
  317. * Nearby game objects that we should be aware of
  318. */
  319. private StatefulEntityCollection<GameObject> watchedObjects = new StatefulEntityCollection<GameObject>();
  320. /**
  321. * Nearby items that we should be aware of
  322. */
  323. private StatefulEntityCollection<Item> watchedItems = new StatefulEntityCollection<Item>();
  324. /**
  325. * Nearby npcs that we should be aware of
  326. */
  327. private StatefulEntityCollection<Npc> watchedNpcs = new StatefulEntityCollection<Npc>();
  328. /**
  329. * Inventory to hold items
  330. */
  331. private Inventory inventory;
  332. /**
  333. * Bank for banked items
  334. */
  335. private Bank bank;
  336. /**
  337. * Users privacy settings, chat block etc.
  338. */
  339. private boolean[] privacySettings = new boolean[4];
  340. /**
  341. * Users game settings, camera rotation preference etc
  342. */
  343. private boolean[] gameSettings = new boolean[7]; // Why is 1 empty?
  344. /**
  345. * Methods to send packets related to actions
  346. */
  347. private MiscPacketBuilder actionSender;
  348. /**
  349. * Unix time when the player last logged in
  350. */
  351. private long lastLogin = 0;
  352.  
  353. public boolean bad_login = false;
  354. /**
  355. * Unix time when the player logged in
  356. */
  357. private long currentLogin = 0;
  358. /**
  359. * Stores the last IP address used
  360. */
  361. private String lastIP = "0.0.0.0";
  362. /**
  363. * Stores the current IP address used
  364. */
  365. private String currentIP = "0.0.0.0";
  366. /**
  367. * If the player is reconnecting after connection loss
  368. */
  369. private boolean reconnecting = false;
  370. /**
  371. * Controls if were allowed to accept appearance updates
  372. */
  373. private boolean changingAppearance = false;
  374. /**
  375. * Is the character male?
  376. */
  377. private boolean maleGender;
  378. /**
  379. * The player we last requested to trade with, or null for none
  380. */
  381. private Player wishToTrade = null;
  382. /**
  383. * The player we last requested to duel with, or null for none
  384. */
  385. private Player wishToDuel = null;
  386. /**
  387. * If the player is currently in a trade
  388. */
  389. private boolean isTrading = false;
  390. /**
  391. * If the player is currently in a duel
  392. */
  393. private boolean isDueling = false;
  394. /**
  395. * List of items offered in the current trade
  396. */
  397. private ArrayList<InvItem> tradeOffer = new ArrayList<InvItem>();
  398. /**
  399. * List of items offered in the current duel
  400. */
  401. private ArrayList<InvItem> duelOffer = new ArrayList<InvItem>();
  402. /**
  403. * If the first trade screen has been accepted
  404. */
  405. private boolean tradeOfferAccepted = false;
  406. /**
  407. * If the first duel screen has been accepted
  408. */
  409. private boolean duelOfferAccepted = false;
  410. /**
  411. * If the second trade screen has been accepted
  412. */
  413. private boolean tradeConfirmAccepted = false;
  414. /**
  415. * If the second duel screen has been accepted
  416. */
  417. private boolean duelConfirmAccepted = false;
  418. /**
  419. * Map of players on players friend list
  420. */
  421. private ArrayList<String> friendList = new ArrayList<String>();
  422. /**
  423. * List of usernameHash's of players on players ignore list
  424. */
  425. private HashSet<String> ignoreList = new HashSet<String>();
  426. /**
  427. * List of all projectiles needing displayed
  428. */
  429. private ArrayList<Projectile> projectilesNeedingDisplayed = new ArrayList<Projectile>();
  430. /**
  431. * List of players who have been hit
  432. */
  433. private ArrayList<Player> playersNeedingHitsUpdate = new ArrayList<Player>();
  434. /**
  435. * List of players who have been hit
  436. */
  437. private ArrayList<Npc> npcsNeedingHitsUpdate = new ArrayList<Npc>();
  438. /**
  439. * Chat messages needing displayed
  440. */
  441. private ArrayList<ChatMessage> chatMessagesNeedingDisplayed = new ArrayList<ChatMessage>();
  442. /**
  443. * NPC messages needing displayed
  444. */
  445. private ArrayList<ChatMessage> npcMessagesNeedingDisplayed = new ArrayList<ChatMessage>();
  446. /**
  447. * Bubbles needing displayed
  448. */
  449. private ArrayList<Bubble> bubblesNeedingDisplayed = new ArrayList<Bubble>();
  450. /**
  451. * The time of the last spell cast, used as a throttle
  452. */
  453. private long lastSpellCast = 0;
  454. /**
  455. * Players we have been attacked by signed login, used to check if we should get a skull for attacking back
  456. */
  457. private HashMap<Long, Long> attackedBy = new HashMap<Long, Long>();
  458. /**
  459. * Time last report was sent, used to throttle reports
  460. */
  461. private long lastReport = 0;
  462. /**
  463. * Time of last charge spell
  464. */
  465. private long lastCharge = 0;
  466. /**
  467. * Combat style: 0 - all, 1 - str, 2 - att, 3 - def
  468. */
  469. private int combatStyle = 0;
  470. /**
  471. * Should we destroy this player?
  472. */
  473. private boolean destroy = false;
  474. /**
  475. * Session keys for the players session
  476. */
  477. private int[] sessionKeys = new int[4];
  478. /**
  479. * Is the player accessing their bank?
  480. */
  481. private boolean inBank = false;
  482. /**
  483. * A handler for any menu we are currently in
  484. */
  485. private MenuHandler menuHandler = null;
  486. /**
  487. * DelayedEvent responsible for handling prayer drains
  488. */
  489. private DelayedEvent drainer;
  490. /**
  491. * The drain rate of the prayers currently enabled
  492. */
  493. private int drainRate = 0;
  494. /**
  495. * DelayedEvent used for removing players skull after 20mins
  496. */
  497. private DelayedEvent skullEvent = null;
  498. /**
  499. * Death Match System
  500. */
  501. public boolean inDeathMatchArena;
  502. public ArrayList<String> invitedPlayer = new ArrayList<String>();
  503. public String lastDeathMatchInvite;
  504. /**
  505. * Killing Spree Ranks
  506. */
  507. private String killingSpreeRank[] = {"No Rank", "Noob", "Pker", "Hitman", "Assassin", "Legend"};
  508. /**
  509. * Clan System
  510. */
  511. public boolean inParty;
  512. public ArrayList<String> myParty = new ArrayList<String>();
  513. public ArrayList<String> invitedPlayers = new ArrayList<String>();
  514. public String lastPartyInvite;
  515. public String summonLeader = null;
  516. private long summonTime = 0;
  517. private Player summoner = null;
  518.  
  519. public void clearMyParty()
  520. {
  521. myParty.clear();
  522. inParty = false;
  523. }
  524.  
  525. public void setSummoner(Player summoner) { this.summoner = summoner; }
  526. public Player getSummoner() { return summoner; }
  527. public void setSummonTime(long newTime) { summonTime = newTime; }
  528. public long getSummonTime() { return summonTime; }
  529.  
  530. public void updateRemovedPlayer()
  531. {
  532. Player leader = world.getPlayer(myParty.get(0));
  533. myParty = leader.myParty;
  534. }
  535. /**
  536. * Amount of fatigue - 0 to 100
  537. */
  538. private int fatigue = 0;
  539. /**
  540. * Has the player been registered into the world?
  541. */
  542. private boolean initialized = false;
  543. /**
  544. * The shop (if any) the player is currently accessing
  545. */
  546. private Shop shop = null;
  547. /**
  548. * The npc we are currently interacting with
  549. */
  550. private Npc interactingNpc = null;
  551. /**
  552. * The ID of the owning account
  553. */
  554. private int owner = 1;
  555. /**
  556. * Queue of last 100 packets, used for auto detection purposes
  557. */
  558. private LinkedList<RSCPacket> lastPackets = new LinkedList<RSCPacket>();
  559. /**
  560. * When the users subscription expires (or 0 if they don't have one)
  561. */
  562. private long subscriptionExpires = 0;
  563. /**
  564. * Who we are currently following (if anyone)
  565. */
  566. private Mob following;
  567. /**
  568. * Event to handle following
  569. */
  570. private DelayedEvent followEvent;
  571. /**
  572. * Ranging event
  573. */
  574. private RangeEvent rangeEvent;
  575. /**
  576. * Last arrow fired
  577. */
  578. private long lastArrow = 0;
  579. /**
  580. * Last packet count time
  581. */
  582. private long lastCount = 0;
  583. /**
  584. * Amount of packets since last count
  585. */
  586. private int packetCount = 0;
  587. /**
  588. * List of chat messages to send
  589. */
  590. private LinkedList<ChatMessage> chatQueue = new LinkedList<ChatMessage>();
  591. /**
  592. * Time of last trade/duel request
  593. */
  594. private long lastTradeDuelRequest = 0;
  595. /**
  596. * The name of the client class they are connecting from
  597. */
  598. private String className = "NOT_SET";
  599. /**
  600. * The current status of the player
  601. */
  602. private Action status = Action.IDLE;
  603. /**
  604. * Duel options
  605. */
  606. private boolean[] duelOptions = new boolean[4];
  607. /**
  608. * Is a trade/duel update required?
  609. */
  610.  
  611. private boolean requiresOfferUpdate = false;
  612.  
  613. /**
  614. * Mute System
  615. */
  616. public int mute = 0;
  617.  
  618. public int getMute()
  619. {
  620. return mute;
  621. }
  622.  
  623. public void setMute(int i)
  624. {
  625. mute = i;
  626. }
  627.  
  628. public void incMute()
  629. {
  630. mute++;
  631. }
  632.  
  633. public boolean isMuted() {
  634. if (mute == 0) {
  635. return false; }
  636. else return true;
  637. }
  638.  
  639. /**
  640. * Invisibility @author Yong Min
  641. */
  642. private boolean isInvisible = false;
  643.  
  644. public void goInvisible() {
  645. isInvisible = !isInvisible;
  646. if(!isInvisible) {
  647. loggedIn = true; }
  648. else loggedIn = false;
  649. }
  650.  
  651. public void setInvisible(boolean invisible) {
  652. isInvisible = invisible;
  653. }
  654.  
  655. public boolean isInvisible() {
  656. return isInvisible;
  657. }
  658.  
  659. /**
  660. * Quest Points @author Yong Min
  661. */
  662. private int questpoints = 0;
  663.  
  664. public void setQuestPoints(int i){
  665. questpoints = i;
  666. actionSender.sendQuestPoints();
  667. }
  668.  
  669. public int getQuestPoints() {
  670. return questpoints;
  671. }
  672.  
  673. /**
  674. * Kills and Deaths @author Yong Min
  675. */
  676. private int kills = 0;
  677. private int deaths = 0;
  678.  
  679. public int getKills() {
  680. return kills;
  681. }
  682.  
  683. public int getDeaths() {
  684. return deaths;
  685. }
  686.  
  687. public void setKills(int i) {
  688. kills = i;
  689. }
  690.  
  691. public void setDeaths(int i) {
  692. deaths = i;
  693. }
  694.  
  695. public void incKills() {
  696. kills++;
  697. }
  698.  
  699. public void incDeaths() {
  700. deaths++;
  701. }
  702.  
  703. /**
  704. * Killing Spree @author Yong Min
  705. */
  706. private int killingspree = 0;
  707.  
  708. public int getKillingSpree() {
  709. return killingspree;
  710. }
  711.  
  712. public void setKillingSpree(int i) {
  713. killingspree = i;
  714. }
  715.  
  716. public void incKillingSpree() {
  717. killingspree++;
  718. }
  719.  
  720. public void setRequiresOfferUpdate(boolean b) {
  721. requiresOfferUpdate = b;
  722. }
  723.  
  724. public boolean requiresOfferUpdate() {
  725. return requiresOfferUpdate;
  726. }
  727.  
  728. public void setStatus(Action a) {
  729. status = a;
  730. }
  731.  
  732. public Action getStatus() {
  733. return status;
  734. }
  735.  
  736. public void setClassName(String className) {
  737. this.className = className;
  738. }
  739.  
  740. public String getClassName() {
  741. return className;
  742. }
  743.  
  744. public boolean [] npcThief = {false, false, false, false, false, false}; // Baker, Silver, Spices, Gem.
  745. private boolean packetSpam = false;
  746. public void setSpam(boolean spam) { packetSpam = spam; }
  747. public boolean getSpam() { return packetSpam; }
  748.  
  749. public boolean tradeDuelThrottling() {
  750. long now = System.currentTimeMillis();
  751. if(now - lastTradeDuelRequest > 1000) {
  752. lastTradeDuelRequest = now;
  753. return false;
  754. }
  755. return true;
  756. }
  757.  
  758. public void addMessageToChatQueue(byte[] messageData) {
  759. chatQueue.add(new ChatMessage(this, messageData));
  760. if(chatQueue.size() > 2) {
  761. destroy(false);
  762. }
  763. }
  764.  
  765. public ChatMessage getNextChatMessage() {
  766. return chatQueue.poll();
  767. }
  768.  
  769. public void setArrowFired() {
  770. lastArrow = System.currentTimeMillis();
  771. }
  772.  
  773.  
  774.  
  775. public void setRangeEvent(RangeEvent event) {
  776. if(isRanging()) {
  777. resetRange();
  778. }
  779. rangeEvent = event;
  780. rangeEvent.setLastRun(lastArrow);
  781. world.getDelayedEventHandler().add(rangeEvent);
  782. }
  783.  
  784. public boolean isRanging() {
  785. return rangeEvent != null;
  786. }
  787.  
  788. public void resetRange() {
  789. if(rangeEvent != null) {
  790. rangeEvent.stop();
  791. rangeEvent = null;
  792. }
  793. setStatus(Action.IDLE);
  794. }
  795.  
  796. public boolean canLogout() {
  797. return !isBusy() && System.currentTimeMillis() - getCombatTimer() > 10000;
  798. }
  799.  
  800. public boolean isFollowing() {
  801. return followEvent != null && following != null;
  802. }
  803.  
  804. public boolean isFollowing(Mob mob) {
  805. return isFollowing() && mob.equals(following);
  806. }
  807.  
  808. public void setFollowing(Mob mob) {
  809. setFollowing(mob, 0);
  810. }
  811.  
  812. public void setFollowing(final Mob mob, final int radius) {
  813. if(isFollowing()) {
  814. resetFollowing();
  815. }
  816. following = mob;
  817. followEvent = new DelayedEvent(this, 500) {
  818. public void run() {
  819. if(!owner.withinRange(mob) || mob.isRemoved() || (owner.isBusy() && !owner.isDueling())) {
  820. resetFollowing();
  821. }
  822. else if(!owner.finishedPath() && owner.withinRange(mob, radius)) {
  823. owner.resetPath();
  824. }
  825. else if(owner.finishedPath() && !owner.withinRange(mob, radius + 1)) {
  826. owner.setPath(new Path(owner.getX(), owner.getY(), mob.getX(), mob.getY()));
  827. }
  828. }
  829. };
  830. world.getDelayedEventHandler().add(followEvent);
  831. }
  832.  
  833. public void resetFollowing() {
  834. following = null;
  835. if(followEvent != null) {
  836. followEvent.stop();
  837. followEvent = null;
  838. }
  839. resetPath();
  840. }
  841.  
  842. public void setSkulledOn(Player player) {
  843. player.addAttackedBy(this);
  844. if(System.currentTimeMillis() - lastAttackedBy(player) > 1200000) {
  845. addSkull(1200000);
  846. }
  847. }
  848.  
  849. public void setSubscriptionExpires(long expires) {
  850. subscriptionExpires = expires;
  851. }
  852.  
  853. public int getDaysSubscriptionLeft() {
  854. long now = (System.currentTimeMillis() / 1000);
  855. if(subscriptionExpires == 0 || now >= subscriptionExpires) {
  856. return 0;
  857. }
  858. return (int)((subscriptionExpires - now) / 86400);
  859. }
  860.  
  861. public void addPacket(RSCPacket p) {
  862. long now = System.currentTimeMillis();
  863. if(now - lastCount > 3000) {
  864. lastCount = now;
  865. packetCount = 0;
  866. }
  867. if(!DataConversions.inArray(Formulae.safePacketIDs, p.getID()) && packetCount++ >= 60) {
  868. destroy(false);
  869. }
  870. if(lastPackets.size() >= 60) {
  871. lastPackets.remove();
  872. }
  873. lastPackets.addLast(p);
  874. }
  875.  
  876. public List<RSCPacket> getPackets() {
  877. return lastPackets;
  878. }
  879.  
  880. public boolean isSuspicious() {
  881. return suspicious;
  882. }
  883.  
  884. public void setOwner(int owner) {
  885. this.owner = owner;
  886. }
  887.  
  888. public int getOwner() {
  889. return owner;
  890. }
  891.  
  892. public Npc getNpc() {
  893. return interactingNpc;
  894. }
  895.  
  896. public void setNpc(Npc npc) {//System.out.println
  897. interactingNpc = npc;
  898. }
  899.  
  900. public void remove() {
  901. removed = true;
  902. }
  903.  
  904. public boolean initialized() {
  905. return initialized;
  906. }
  907.  
  908. public void setInitialized() {
  909. initialized = true;
  910. }
  911.  
  912. public int getDrainRate() {
  913. return drainRate;
  914. }
  915.  
  916. public void setDrainRate(int rate) {
  917. drainRate = rate;
  918. }
  919.  
  920. public int getRangeEquip() {
  921. for(InvItem item : inventory.getItems()) {
  922. if(item.isWielded() && (DataConversions.inArray(Formulae.bowIDs, item.getID()) || DataConversions.inArray(Formulae.xbowIDs, item.getID()))) {
  923. return item.getID();
  924. }
  925. }
  926. return -1;
  927. }
  928.  
  929. public void resetAll() {
  930. resetAllExceptTradeOrDuel();
  931. resetTrade();
  932. resetDuel();
  933. }
  934.  
  935. public void resetTrade() {
  936. Player opponent = getWishToTrade();
  937. if(opponent != null) {
  938. opponent.resetTrading();
  939. }
  940. resetTrading();
  941. }
  942.  
  943. public void resetDuel() {
  944. Player opponent = getWishToDuel();
  945. if(opponent != null) {
  946. opponent.resetDueling();
  947. }
  948. resetDueling();
  949. }
  950.  
  951. public void resetAllExceptTrading() {
  952. resetAllExceptTradeOrDuel();
  953. resetDuel();
  954. }
  955.  
  956. public void resetAllExceptDueling() {
  957. resetAllExceptTradeOrDuel();
  958. resetTrade();
  959. }
  960.  
  961. private void resetAllExceptTradeOrDuel() {
  962. if(getMenuHandler() != null) {
  963. resetMenuHandler();
  964. }
  965. if(accessingBank()) {
  966. resetBank();
  967. }
  968. if(accessingShop()) {
  969. resetShop();
  970. }
  971. if(interactingNpc != null) {
  972. interactingNpc.unblock();
  973. }
  974. if(isFollowing()) {
  975. resetFollowing();
  976. }
  977. if(isRanging()) {
  978. resetRange();
  979. }
  980. setStatus(Action.IDLE);
  981. }
  982.  
  983. public void setMenuHandler(MenuHandler menuHandler) {
  984. menuHandler.setOwner(this);
  985. this.menuHandler = menuHandler;
  986. }
  987.  
  988. public void setQuestMenuHandler(MenuHandler menuHandler) {
  989. this.menuHandler = menuHandler;
  990. menuHandler.setOwner(this);
  991. actionSender.sendMenu(menuHandler.getOptions());
  992. }
  993.  
  994. public void resetMenuHandler() {
  995. menuHandler = null;
  996. actionSender.hideMenu();
  997. }
  998.  
  999. public MenuHandler getMenuHandler() {
  1000. return menuHandler;
  1001. }
  1002.  
  1003. public boolean accessingShop() {
  1004. return shop != null;
  1005. }
  1006.  
  1007. public void setAccessingShop(Shop shop) {
  1008. this.shop = shop;
  1009. if(shop != null) {
  1010. shop.addPlayer(this);
  1011. }
  1012. }
  1013.  
  1014. public void resetShop() {
  1015. if(shop != null) {
  1016. shop.removePlayer(this);
  1017. shop = null;
  1018. actionSender.hideShop();
  1019. }
  1020. }
  1021.  
  1022. public boolean accessingBank() {
  1023. return inBank;
  1024. }
  1025.  
  1026. public Shop getShop() {
  1027. return shop;
  1028. }
  1029.  
  1030. public void setAccessingBank(boolean b) {
  1031. inBank = b;
  1032. }
  1033.  
  1034. public void resetBank() {
  1035. setAccessingBank(false);
  1036. actionSender.hideBank();
  1037. }
  1038.  
  1039. public Player(IoSession ios) {
  1040.  
  1041. ioSession = ios;
  1042. currentIP = ((InetSocketAddress)ios.getRemoteAddress()).getAddress().getHostAddress();
  1043. currentLogin = System.currentTimeMillis();
  1044. actionSender = new MiscPacketBuilder(this);
  1045. setBusy(true);
  1046. }
  1047.  
  1048. public void setServerKey(long key) {
  1049. sessionKeys[2] = (int)(key >> 32);
  1050. sessionKeys[3] = (int)key;
  1051. }
  1052.  
  1053. public boolean setSessionKeys(int[] keys) {
  1054. boolean valid = (sessionKeys[2] == keys[2] && sessionKeys[3] == keys[3]);
  1055. sessionKeys = keys;
  1056. return valid;
  1057. }
  1058. // save
  1059. public boolean destroyed() {
  1060. return destroy;
  1061. }
  1062.  
  1063. public void destroy(boolean force) {
  1064. if(destroy) {
  1065. return;
  1066. }
  1067. String user = this.getUsername();
  1068. if(force || canLogout()) {
  1069. if(user == null) {
  1070. destroy = true;
  1071. actionSender.sendLogout();
  1072. return;
  1073. }
  1074. destroy = true;
  1075. actionSender.sendLogout();
  1076. GUI.writeValue(user, "loggedin", "false");
  1077. if(this.isAdmin())
  1078. GameVars.adminsOnline--;
  1079. else if(this.rank == 3 || this.rank == 2)
  1080. GameVars.modsOnline--;
  1081. }
  1082. else {
  1083. final long startDestroy = System.currentTimeMillis();
  1084. world.getDelayedEventHandler().add(new DelayedEvent(this, 3000) {
  1085. public void run() {
  1086. if(owner.canLogout() || (!(owner.inCombat() && owner.isDueling()) && System.currentTimeMillis() - startDestroy > 60000)) {
  1087. owner.destroy(true);
  1088. running = false;
  1089. }
  1090. }
  1091. });
  1092. }
  1093. }
  1094.  
  1095. public int getCombatStyle() {
  1096. return combatStyle;
  1097. }
  1098.  
  1099. public void setCombatStyle(int style) {
  1100. combatStyle = style;
  1101. }
  1102.  
  1103. public boolean muted;
  1104.  
  1105. public void load(String username, String password, int uid, boolean reconnecting) {
  1106. try {
  1107. //String user = username.replaceAll("_");
  1108. File f = new File("players/" + username + ".cfg");
  1109. if(!f.exists()) {
  1110. this.destroy(true);
  1111. return;
  1112. }
  1113. setID(uid);
  1114. this.password = password;
  1115. this.reconnecting = reconnecting;
  1116. usernameHash = DataConversions.usernameToHash(username);
  1117. this.username = DataConversions.hashToUsername(usernameHash);
  1118. //TODO
  1119. //world.getServer().getLoginConnector().getActionSender().playerLogin(this);
  1120.  
  1121. world.getDelayedEventHandler().add(new DelayedEvent(this, 60000) {
  1122. public void run() {
  1123. for(int statIndex = 0;statIndex < 18;statIndex++) {
  1124. if(statIndex == 5) {
  1125. continue;
  1126. }
  1127. int curStat = getCurStat(statIndex);
  1128. int maxStat = getMaxStat(statIndex);
  1129. if(curStat > maxStat) {
  1130. setCurStat(statIndex, curStat - 1);
  1131. getActionSender().sendStat(statIndex);
  1132. checkStat(statIndex);
  1133. }
  1134. else if(curStat < maxStat) {
  1135. setCurStat(statIndex, curStat + 1);
  1136. getActionSender().sendStat(statIndex);
  1137. checkStat(statIndex);
  1138. }
  1139. }
  1140. }
  1141.  
  1142.  
  1143. private void checkStat(int statIndex) {
  1144. if(statIndex != 3 && owner.getCurStat(statIndex) == owner.getMaxStat(statIndex)) {
  1145. owner.getActionSender().sendMessage("Your " + Formulae.statArray[statIndex] + " ability has returned to normal.");
  1146. }
  1147. }
  1148. });
  1149. drainer = new DelayedEvent(this, Integer.MAX_VALUE) {
  1150. public void run() {
  1151. int curPrayer = getCurStat(5);
  1152. if(getDrainRate() > 0 && curPrayer > 0) {
  1153. incCurStat(5, -1);
  1154. getActionSender().sendStat(5);
  1155. if(curPrayer <= 1) {
  1156. for(int prayerID = 0;prayerID < 14;prayerID++) { //Prayer was < 14
  1157. setPrayer(prayerID, false);
  1158. }
  1159. setDrainRate(0);
  1160. setDelay(Integer.MAX_VALUE);
  1161. getActionSender().sendMessage("You have run out of prayer points. Return to a church to recharge");
  1162. getActionSender().sendPrayers();
  1163. }
  1164. }
  1165. }
  1166. };
  1167. world.getDelayedEventHandler().add(drainer);
  1168. //setOwner(p.readInt()); SQL/PunBB Integration "Owner ID" Which i won't be needing.
  1169. //player.setGroupID(p.readInt()); <-- Same.
  1170. Properties props = new Properties();
  1171.  
  1172.  
  1173. FileInputStream fis = new FileInputStream(f);
  1174. props.load(fis);
  1175.  
  1176.  
  1177.  
  1178. setSubscriptionExpires(0); // No sub atm.
  1179. setLastIP(props.getProperty("ip"));
  1180. setLastLogin(Long.parseLong(props.getProperty("ll"))); // Temporary.
  1181.  
  1182. rank = Integer.parseInt(props.getProperty("rank"));
  1183. if(this.isAdmin())
  1184. GameVars.adminsOnline++;
  1185. else if(this.rank == 3 || this.rank == 2)
  1186. GameVars.modsOnline++;
  1187. setLocation(Point.location(Integer.parseInt(props.getProperty("x")), Integer.parseInt(props.getProperty("y"))), true);
  1188. setFatigue(Integer.parseInt(props.getProperty("fat")));
  1189. setKillingSpree(Integer.parseInt(props.getProperty("killingspree")));
  1190. setMute(Integer.parseInt(props.getProperty("mute")));
  1191. setKills(Integer.parseInt(props.getProperty("kills")));
  1192. setDeaths(Integer.parseInt(props.getProperty("deaths")));
  1193. setQuestPoints(Integer.parseInt(props.getProperty("questpoints")));
  1194. setCombatStyle(Integer.parseInt(props.getProperty("cs")));
  1195. setPrivacySetting(0, Integer.parseInt(props.getProperty("ps0")) == 1);
  1196. setPrivacySetting(1, Integer.parseInt(props.getProperty("ps1")) == 1);
  1197. setPrivacySetting(2, Integer.parseInt(props.getProperty("ps2")) == 1);
  1198. setPrivacySetting(3, Integer.parseInt(props.getProperty("ps3")) == 1);
  1199.  
  1200.  
  1201. setGameSetting(0, Integer.parseInt(props.getProperty("gs0")) == 1);
  1202. setGameSetting(2, Integer.parseInt(props.getProperty("gs2")) == 1);
  1203. setGameSetting(3, Integer.parseInt(props.getProperty("gs3")) == 1);
  1204. setGameSetting(4, Integer.parseInt(props.getProperty("gs4")) == 1);
  1205. setGameSetting(5, Integer.parseInt(props.getProperty("gs5")) == 1);
  1206. setGameSetting(6, Integer.parseInt(props.getProperty("gs6")) == 1);
  1207.  
  1208. PlayerAppearance appearance = new PlayerAppearance(
  1209. Integer.parseInt(props.getProperty("a1")),
  1210. Integer.parseInt(props.getProperty("a2")),
  1211. Integer.parseInt(props.getProperty("a3")),
  1212. Integer.parseInt(props.getProperty("a4")),
  1213. Integer.parseInt(props.getProperty("a5")),
  1214. Integer.parseInt(props.getProperty("a6")));
  1215.  
  1216. if(!appearance.isValid()) {
  1217. destroy(true);
  1218. getSession().close();
  1219. }
  1220. setAppearance(appearance);
  1221. setWornItems(getPlayerAppearance().getSprites());
  1222.  
  1223. setMale(Integer.parseInt(props.getProperty("male")) == 1);
  1224.  
  1225. long skull = Long.parseLong(props.getProperty("skull"));
  1226. if(skull > 0) {
  1227. addSkull(skull);
  1228. }
  1229.  
  1230. for(int i = 0;i < 18;i++) {
  1231. int exp = Integer.parseInt(props.getProperty("e" + (i + 1)));
  1232. setExp(i, exp);
  1233. setMaxStat(i, Formulae.experienceToLevel(exp));
  1234. setCurStat(i, Integer.parseInt(props.getProperty("c" + (i + 1))));
  1235. }
  1236. setCombatLevel(Formulae.getCombatlevel(getMaxStats()));
  1237.  
  1238. int count = Integer.parseInt(props.getProperty("fcount"));
  1239. for(int i=0; i < count; i++) {
  1240. this.getFriendList().add(props.getProperty("f" + i));
  1241. }
  1242. Inventory inventory = new Inventory(this);
  1243. int invCount = Integer.parseInt(props.getProperty("icount"));
  1244. for(int i = 0;i < invCount;i++) {
  1245. int id = Integer.parseInt(props.getProperty("i" + i));
  1246. int amount = Integer.parseInt(props.getProperty("ia" + i));
  1247. int wear = Integer.parseInt(props.getProperty("iw" + i));
  1248. if(id != 7000) {
  1249. InvItem item = new InvItem(id, amount);
  1250. if(wear == 1 && item.isWieldable()) {
  1251. item.setWield(true);
  1252. updateWornItems(item.getWieldableDef().getWieldPos(), item.getWieldableDef().getSprite());
  1253. }
  1254. inventory.add(item);
  1255.  
  1256. }
  1257. }
  1258. setInventory(inventory);
  1259.  
  1260. Bank bank = new Bank();
  1261. int bnkCount = Integer.parseInt(props.getProperty("bcount"));
  1262. for(int i = 0;i < bnkCount;i++) {
  1263. int id = Integer.parseInt(props.getProperty("b" + i));
  1264. int amount = Integer.parseInt(props.getProperty("ba" + i));
  1265. if(id != 7000)
  1266. bank.add(new InvItem(id, amount));
  1267. }
  1268. setBank(bank);
  1269. if(!this.bad_login) {
  1270. fis.close();
  1271. FileOutputStream fos = new FileOutputStream(f);
  1272. props.setProperty("loggedin", "true");
  1273. props.store(fos, "Character Data.");
  1274. fos.close();
  1275. }
  1276.  
  1277.  
  1278. /* End of loading methods */
  1279.  
  1280. world.registerPlayer(this);
  1281.  
  1282. updateViewedPlayers();
  1283. updateViewedObjects();
  1284.  
  1285. org.rscdaemon.server.packetbuilder.client.MiscPacketBuilder sender = getActionSender();
  1286. sender.sendServerInfo();
  1287. sender.sendFatigue();
  1288. sender.sendKillingSpree();
  1289. sender.sendMute();
  1290. sender.sendQuestPoints();
  1291. sender.sendKills();
  1292. sender.sendDeaths();
  1293. sender.sendWorldInfo();
  1294. sender.sendInventory();
  1295. sender.sendEquipmentStats();
  1296. sender.sendStats();
  1297. sender.sendPrivacySettings();
  1298. sender.sendGameSettings();
  1299. sender.sendFriendList();
  1300. sender.sendIgnoreList();
  1301. sender.sendCombatStyle();
  1302.  
  1303.  
  1304.  
  1305. GUI.populateWorldList();
  1306. for(Player p : world.getPlayers()) {
  1307. if(p.isFriendsWith(this.getUsername())) {
  1308. p.getActionSender().sendFriendUpdate(this.getUsernameHash(), org.rscdaemon.server.util.Config.SERVER_NUM);
  1309. }
  1310. }
  1311. for(String player : getFriendList()) {
  1312. Player p = world.getPlayer(DataConversions.usernameToHash(player));
  1313. if(p != null) {
  1314. sender.sendFriendUpdate(p.getUsernameHash(), Config.SERVER_NUM);
  1315. } else {
  1316. sender.sendFriendUpdate(DataConversions.usernameToHash(player), 0);
  1317. }
  1318. }
  1319.  
  1320. sender.sendMessage(" "); // ROFL at this, its to stop the stupid friends list saying xx logged out when someone logs in, ill fix it up later
  1321. sender.sendMessage(" ");
  1322. sender.sendMessage(" ");
  1323. sender.sendMessage("@yel@Welcome to @whi@" + GameVars.serverName);
  1324. sender.sendMessage("@yel@Powered by: @whi@" + "EasyRSC Emulator v" + (double)GameVars.projectVersion);
  1325. sender.sendMessage("@yel@Online Players: @whi@" + (GameVars.usersOnline + 1) + " @yel@Peak: @whi@" + (GameVars.userPeak + 1));
  1326. int timeTillShutdown = world.getServer().timeTillShutdown();
  1327. if(timeTillShutdown > -1) {
  1328. sender.startShutdown((int)(timeTillShutdown / 1000));
  1329. }
  1330.  
  1331. if(getLastLogin() == 0) {
  1332. setChangingAppearance(true);
  1333. sender.sendAppearanceScreen();
  1334. }
  1335. setLastLogin(System.currentTimeMillis());
  1336. sender.sendLoginBox();
  1337.  
  1338. setLoggedIn(true);
  1339. setBusy(false);
  1340. RSCPacketBuilder pb = new RSCPacketBuilder();
  1341. pb.setBare(true);
  1342. pb.addByte((byte)0);
  1343. getSession().write(pb.toPacket());
  1344. } catch (Exception e) {
  1345. e.printStackTrace();
  1346. Logger.print(e.toString(), 1);
  1347. }
  1348.  
  1349. }
  1350.  
  1351.  
  1352.  
  1353. public void resetTrading() {
  1354. if(isTrading()) {
  1355. actionSender.sendTradeWindowClose();
  1356. setStatus(Action.IDLE);
  1357. }
  1358. setWishToTrade(null);
  1359. setTrading(false);
  1360. setTradeOfferAccepted(false);
  1361. setTradeConfirmAccepted(false);
  1362. resetTradeOffer();
  1363. }
  1364.  
  1365. public void resetDueling() {
  1366. if(isDueling()) {
  1367. actionSender.sendDuelWindowClose();
  1368. setStatus(Action.IDLE);
  1369. }
  1370. inDuel = false;
  1371. setWishToDuel(null);
  1372. setDueling(false);
  1373. setDuelOfferAccepted(false);
  1374. setDuelConfirmAccepted(false);
  1375. resetDuelOffer();
  1376. clearDuelOptions();
  1377. }
  1378. //mute
  1379. public void clearDuelOptions() {
  1380. for(int i = 0;i < 4;i++) {
  1381. duelOptions[i] = false;
  1382. } }
  1383.  
  1384. public void save() {
  1385. try {
  1386.  
  1387. if(!this.bad_login) {
  1388. String username = this.getUsername().replaceAll(" ", "_");
  1389. File f = new File("players/" + username.toLowerCase() + ".cfg");
  1390. //System.out.println("test test 1");
  1391. Properties pr = new Properties();
  1392.  
  1393. FileInputStream fis = new FileInputStream(f);
  1394. pr.load(fis);
  1395. fis.close();
  1396.  
  1397.  
  1398. pr.setProperty("rank", "" + this.rank);
  1399. pr.setProperty("x", "" + this.getLocation().getX());
  1400. pr.setProperty("y", "" + this.getLocation().getY());
  1401. pr.setProperty("fat", "" + this.getFatigue());
  1402. pr.setProperty("killingspree", "" + this.getKillingSpree());
  1403. pr.setProperty("mute", "" + this.getMute());
  1404. pr.setProperty("kills", "" + this.getKills());
  1405. pr.setProperty("deaths", "" + this.getDeaths());
  1406. pr.setProperty("questpoints", "" + this.getQuestPoints());
  1407. pr.setProperty("ip", "" + this.getLastIP());
  1408. pr.setProperty("ll", "" + this.getLastLogin());
  1409. pr.setProperty("cs", "" + this.getCombatStyle());
  1410. pr.setProperty("ps0", "" + (this.getPrivacySetting(0) ? 1 : 0));
  1411. pr.setProperty("ps1", "" + (this.getPrivacySetting(1) ? 1 : 0));
  1412. pr.setProperty("ps2", "" + (this.getPrivacySetting(2) ? 1 : 0));
  1413. pr.setProperty("ps3", "" + (this.getPrivacySetting(3) ? 1 : 0));
  1414. pr.setProperty("gs0", "" + (this.getGameSetting(0) ? 1 : 0));
  1415. pr.setProperty("gs2", "" + (this.getGameSetting(2) ? 1 : 0));
  1416. pr.setProperty("gs3", "" + (this.getGameSetting(3) ? 1 : 0));
  1417. pr.setProperty("gs4", "" + (this.getGameSetting(4) ? 1 : 0));
  1418.  
  1419. pr.setProperty("gs5", "" + (this.getGameSetting(5) ? 1 : 0));
  1420. pr.setProperty("gs6", "" + (this.getGameSetting(6) ? 1 : 0));
  1421. pr.setProperty("a1", "" + this.appearance.getHairColour());
  1422. pr.setProperty("a2", "" + this.appearance.getTopColour());
  1423. pr.setProperty("a3", "" + this.appearance.getTrouserColour());
  1424. pr.setProperty("a4", "" + this.appearance.getSkinColour());
  1425. pr.setProperty("a5", "" + this.appearance.head);
  1426. pr.setProperty("a6", "" + this.appearance.body);
  1427. pr.setProperty("male", "" + (this.isMale() ? 1 : 0));
  1428. pr.setProperty("skull", "" + (this.getSkullTime() > 0 ? this.getSkullTime() : 0));
  1429.  
  1430. for(int i=0; i < 18; i++) {
  1431. pr.setProperty("c" + (i + 1), "" + this.getCurStat(i));
  1432. pr.setProperty("e" + (i + 1), "" + this.getExp(i));
  1433. }
  1434.  
  1435.  
  1436.  
  1437. int count = this.getInventory().size();
  1438. pr.setProperty("icount", "" + count);
  1439. for(int i=0; i < count; i++) {
  1440. InvItem item = this.getInventory().get(i);
  1441. pr.setProperty("i" + i, "" + item.getID());
  1442. pr.setProperty("ia" + i, "" + item.getAmount());
  1443. pr.setProperty("iw" + i, "" + (item.isWielded() ? 1 : 0));
  1444. }
  1445.  
  1446. count = this.getFriendList().size();
  1447. pr.setProperty("fcount", "" + count);
  1448. for(int i=0; i < count; i++) {
  1449. pr.setProperty("f" + i, "" + this.getFriendList().get(i));
  1450. }
  1451.  
  1452. count = this.getBank().size();
  1453. pr.setProperty("bcount", "" + count);
  1454. for(int i=0; i < count; i++) {
  1455. InvItem item = this.getBank().get(i);
  1456. pr.setProperty("b" + i, "" + item.getID());
  1457. pr.setProperty("ba" + i, "" + item.getAmount());
  1458. }
  1459.  
  1460. FileOutputStream fos = new FileOutputStream(f);
  1461. pr.store(fos, "Character Data.");
  1462. fos.close();
  1463.  
  1464. }
  1465. } catch (IOException e) {
  1466.  
  1467. System.out.println(e);
  1468. }
  1469. }
  1470.  
  1471. public void setCharged() {
  1472. lastCharge = System.currentTimeMillis();
  1473. }
  1474.  
  1475. public boolean isCharged() {
  1476. return System.currentTimeMillis() - lastCharge > 600000;
  1477. }
  1478.  
  1479. public boolean wielding(int id) {
  1480. ListIterator iterator = getInventory().iterator();
  1481. for(int slot = 0; iterator.hasNext(); slot++) {
  1482. InvItem item = (InvItem)iterator.next();
  1483. if(item.isWielded() && item.getID() == id) {
  1484. return true;
  1485. }
  1486. }
  1487. return false;
  1488. }
  1489.  
  1490. public boolean canReport() {
  1491. return System.currentTimeMillis() - lastReport > 60000;
  1492. }
  1493.  
  1494. public void setLastReport() {
  1495. lastReport = System.currentTimeMillis();
  1496. }
  1497.  
  1498. public void killedBy(Mob mob) {
  1499. killedBy(mob, false);
  1500. }
  1501.  
  1502. public void killedBy(Mob mob, boolean stake) {
  1503. boolean drop = true;
  1504. if(!loggedIn) {
  1505. Logger.error(username + " not logged in, but killed!");
  1506. return;
  1507. }
  1508. if(mob instanceof Player) {
  1509. Player player = (Player)mob;
  1510. player.getActionSender().sendMessage("You have defeated " + getUsername() + "!");
  1511. player.incKills();
  1512. actionSender.sendKills();
  1513. player.incKillingSpree();
  1514. actionSender.sendKillingSpree();
  1515. player.getActionSender().sendSound("victory");
  1516.  
  1517. ArrayList<Player> playersToSend = new ArrayList<Player>();
  1518.  
  1519. for(Player p : world.getPlayers())
  1520. playersToSend.add(p);
  1521.  
  1522. for(Player pl : playersToSend)
  1523. if(player.getKillingSpree() == 1) {
  1524. pl.getActionSender().sendMessage("[@red@RSCShadow@whi@] @or1@" + player.getUsername() + "@whi@ has just gained the " + killingSpreeRank[1] + " killing spree rank!");
  1525. }
  1526. else if(player.getKillingSpree() == 5) {
  1527. pl.getActionSender().sendMessage("[@red@RSCShadow@whi@] @or1@" + player.getUsername() + "@whi@ now has a killing spree of: @or1@" + player.getKillingSpree());
  1528. pl.getActionSender().sendMessage("[@red@RSCShadow@whi@] @or1@" + player.getUsername() + "@whi@ has just gained the " + killingSpreeRank[2] + " killing spree rank!");
  1529. }
  1530. else if(player.getKillingSpree() == 10) {
  1531. pl.getActionSender().sendMessage("[@red@RSCShadow@whi@] @or1@" + player.getUsername() + "@whi@ now has a killing spree of: @or1@" + player.getKillingSpree());
  1532. pl.getActionSender().sendMessage("[@red@RSCShadow@whi@] @or1@" + player.getUsername() + "@whi@ has just gained the " + killingSpreeRank[3] + " killing spree rank!");
  1533. }
  1534. else if(player.getKillingSpree() == 15) {
  1535. pl.getActionSender().sendMessage("[@red@RSCShadow@whi@] @or1@" + player.getUsername() + "@whi@ now has a killing spree of: @or1@" + player.getKillingSpree());
  1536. pl.getActionSender().sendMessage("[@red@RSCShadow@whi@] @or1@" + player.getUsername() + "@whi@ has just gained the " + killingSpreeRank[4] + " killing spree rank!");
  1537. }
  1538. else if(player.getKillingSpree() == 20) {
  1539. pl.getActionSender().sendMessage("[@red@RSCShadow@whi@] @or1@" + player.getUsername() + "@whi@ now has a killing spree of: @or1@" + player.getKillingSpree());
  1540. pl.getActionSender().sendMessage("[@red@RSCShadow@whi@] @or1@" + player.getUsername() + "@whi@ has just gained the " + killingSpreeRank[5] + " killing spree rank!");
  1541. } else {
  1542. pl.getActionSender().sendMessage("@or1@" + player.getUsername() + "@whi@ has just @red@owned @or1@" + getUsername() + "@whi@ !");
  1543. pl.getActionSender().sendMessage("@or1@" + getUsername() + "@whi@'s killing spree of " + getKillingSpree() + " has now ended.");
  1544. }
  1545. world.getDelayedEventHandler().add(new MiniEvent(player) {
  1546. public void action() {
  1547. owner.getActionSender().sendScreenshot();
  1548. owner.actionSender.sendKills();
  1549. owner.actionSender.sendKillingSpree();
  1550. }
  1551. });//setNpc
  1552. //world.getServer().getLoginConnector().getActionSender().logKill(player.getUsernameHash(), usernameHash, stake);
  1553. if(world.getServer().pvpIsRunning() && world.getPvpSize() == 2 && world.getPvpEntry(this)) {
  1554. world.setWinner(player);
  1555. world.removePvpEntry(player);
  1556. world.removePvpEntry(this);
  1557. player.getInventory().add(new InvItem(10, world.getJackPot()));
  1558. player.getActionSender().sendInventory();
  1559. world.getServer().stopDuel();
  1560. world.clearJackPot();
  1561. player.teleport(220, 445, false);
  1562. drop=false;
  1563. }
  1564. else if(world.getServer().pvpIsRunning()){
  1565. world.removePvpEntry(this);
  1566. drop=false;
  1567. }
  1568. }
  1569. Mob opponent = super.getOpponent();
  1570. if(opponent != null) {
  1571. opponent.resetCombat(CombatState.WON);
  1572. }
  1573. actionSender.sendDied();
  1574. for(int i = 0;i < 18;i++) {
  1575. curStat[i] = maxStat[i];
  1576. actionSender.sendStat(i);
  1577. }
  1578.  
  1579. Player player = mob instanceof Player ? (Player)mob : null;
  1580. if(stake) {
  1581. for(InvItem item : duelOffer) {
  1582. InvItem affectedItem = getInventory().get(item);
  1583. if(affectedItem == null) {
  1584. setSuspiciousPlayer(true);
  1585. Logger.error("Missing staked item [" + item.getID() + ", " + item.getAmount() + "] from = " + usernameHash + "; to = " + player.getUsernameHash() + ";");
  1586. continue;
  1587. }
  1588. if(affectedItem.isWielded()) {
  1589. affectedItem.setWield(false);
  1590. updateWornItems(affectedItem.getWieldableDef().getWieldPos(), getPlayerAppearance().getSprite(affectedItem.getWieldableDef().getWieldPos()));
  1591. }
  1592. getInventory().remove(item);
  1593. world.registerItem(new Item(item.getID(), getX(), getY(), item.getAmount(), player));
  1594. }
  1595. }
  1596. else {
  1597. inventory.sort();
  1598. ListIterator<InvItem> iterator = inventory.iterator();
  1599. if(!isSkulled()) {
  1600. for(int i = 0;i < 3 && iterator.hasNext();i++) {
  1601. if((iterator.next()).getDef().isStackable()) {
  1602. iterator.previous();
  1603. break;
  1604. }
  1605. }
  1606. }
  1607. if(activatedPrayers[8] && iterator.hasNext()) {
  1608. if(((InvItem)iterator.next()).getDef().isStackable()) {
  1609. iterator.previous();
  1610. }
  1611. }
  1612. for(int slot = 0;iterator.hasNext();slot++) {
  1613. InvItem item = (InvItem)iterator.next();
  1614. if(item.isWielded()) {
  1615. item.setWield(false);
  1616. updateWornItems(item.getWieldableDef().getWieldPos(), appearance.getSprite(item.getWieldableDef().getWieldPos()));
  1617. }
  1618. iterator.remove();
  1619. world.registerItem(new Item(item.getID(), getX(), getY(), item.getAmount(), player));
  1620. }
  1621. removeSkull();
  1622. }
  1623. world.registerItem(new Item(20, getX(), getY(), 1, player));
  1624.  
  1625. for(int x = 0;x < activatedPrayers.length;x++) {
  1626. if(activatedPrayers[x]) {
  1627. removePrayerDrain(x);
  1628. activatedPrayers[x] = false;
  1629. }
  1630. }
  1631. actionSender.sendPrayers();
  1632.  
  1633. setLocation(Point.location(213, 442), true);
  1634. Player affectedPlayer = world.getPlayer(usernameHash);
  1635. Collection<Player> allWatched = watchedPlayers.getAllEntities();
  1636. for (Player p : allWatched) {
  1637. p.removeWatchedPlayer(this);
  1638. }
  1639.  
  1640. resetPath();
  1641. resetCombat(CombatState.LOST);
  1642. actionSender.sendWorldInfo();
  1643. actionSender.sendEquipmentStats();
  1644. actionSender.sendInventory();
  1645. affectedPlayer.incDeaths();
  1646. affectedPlayer.actionSender.sendDeaths();
  1647. affectedPlayer.setKillingSpree(affectedPlayer.getKillingSpree() - affectedPlayer.getKillingSpree());
  1648. affectedPlayer.actionSender.sendKillingSpree();
  1649. }
  1650.  
  1651. public void addAttackedBy(Player p) {
  1652. attackedBy.put(p.getUsernameHash(), System.currentTimeMillis());
  1653. }
  1654.  
  1655. public long lastAttackedBy(Player p) {
  1656. Long time = attackedBy.get(p.getUsernameHash());
  1657. if(time != null) {
  1658. return time;
  1659. }
  1660. return 0;
  1661. }
  1662.  
  1663. public void setCastTimer() {
  1664. lastSpellCast = System.currentTimeMillis();
  1665. }
  1666.  
  1667. public void setSpellFail() {
  1668. lastSpellCast = System.currentTimeMillis() + 20000;
  1669. }
  1670.  
  1671. public int getSpellWait() {
  1672. return DataConversions.roundUp((double)(1200 - (System.currentTimeMillis() - lastSpellCast)) / 1000D);
  1673. }
  1674.  
  1675. public long getCastTimer() {
  1676. return lastSpellCast;
  1677. }
  1678.  
  1679. public boolean castTimer() {
  1680. return System.currentTimeMillis() - lastSpellCast > 1200;
  1681. }
  1682. //destroy
  1683. public boolean checkAttack(Mob mob, boolean missile) {
  1684. if(mob instanceof Player) {
  1685. Player victim = (Player)mob;
  1686. if((inCombat() && isDueling()) && (victim.inCombat() && victim.isDueling())) {
  1687. Player opponent = (Player)getOpponent();
  1688. if(opponent != null && victim.equals(opponent)) {
  1689. return true;
  1690. }
  1691. }
  1692. if(System.currentTimeMillis() - mob.getCombatTimer() < (mob.getCombatState() == CombatState.RUNNING || mob.getCombatState() == CombatState.WAITING ? 3000 : 500) && !mob.inCombat()) {
  1693. return false;
  1694. }
  1695. int myWildLvl = getLocation().wildernessLevel();
  1696. int victimWildLvl = victim.getLocation().wildernessLevel();
  1697. if(myWildLvl < 1 || victimWildLvl < 1) {
  1698. actionSender.sendMessage("You cannot attack other players outside of the wilderness!");
  1699. return false;
  1700. }
  1701. if(getLocation().inDeathMatchArena()) {
  1702. return true;
  1703. }
  1704. if((victim.isAdmin()) || (victim.isMod()) || (victim.isPMod()) || (victim.isEvent())) {
  1705. actionSender.sendMessage("You can't attack staff members!");
  1706. resetFollowing();
  1707. return false;
  1708. }
  1709. int combDiff = Math.abs(getCombatLevel() - victim.getCombatLevel());
  1710. if(combDiff > myWildLvl) {
  1711. actionSender.sendMessage("You must move to at least level " + combDiff + " wilderness to attack " + victim.getUsername() + "!");
  1712. return false;
  1713. }
  1714. if(combDiff > victimWildLvl) {
  1715. actionSender.sendMessage(victim.getUsername() + " is not in high enough wilderness for you to attack!");
  1716. return false;
  1717. }
  1718. return true;
  1719. }
  1720. else if(mob instanceof Npc) {
  1721. Npc victim = (Npc)mob;
  1722. if(!victim.getDef().isAttackable()) {
  1723. setSuspiciousPlayer(true);
  1724. return false;
  1725. }
  1726. return true;
  1727. }
  1728. return true;
  1729. }
  1730.  
  1731. public void informOfBubble(Bubble b) {
  1732. bubblesNeedingDisplayed.add(b);
  1733. }
  1734.  
  1735. public List<Bubble> getBubblesNeedingDisplayed() {
  1736. return bubblesNeedingDisplayed;
  1737. }
  1738.  
  1739. public void clearBubblesNeedingDisplayed() {
  1740. bubblesNeedingDisplayed.clear();
  1741. }
  1742.  
  1743. public void informOfChatMessage(ChatMessage cm) {
  1744. chatMessagesNeedingDisplayed.add(cm);
  1745. }
  1746.  
  1747. public void sayMessage(String msg, Mob to) {
  1748. ChatMessage cm = new ChatMessage(this, msg, to);
  1749. chatMessagesNeedingDisplayed.add(cm);
  1750. }
  1751.  
  1752. public void informOfNpcMessage(ChatMessage cm) {
  1753. npcMessagesNeedingDisplayed.add(cm);
  1754. }
  1755.  
  1756. public List<ChatMessage> getNpcMessagesNeedingDisplayed() {
  1757. return npcMessagesNeedingDisplayed;
  1758. }
  1759.  
  1760. public List<ChatMessage> getChatMessagesNeedingDisplayed() {
  1761. return chatMessagesNeedingDisplayed;
  1762. }
  1763.  
  1764. public void clearNpcMessagesNeedingDisplayed() {
  1765. npcMessagesNeedingDisplayed.clear();
  1766. }
  1767.  
  1768. public void clearChatMessagesNeedingDisplayed() {
  1769. chatMessagesNeedingDisplayed.clear();
  1770. }
  1771.  
  1772. public void informOfModifiedHits(Mob mob) {
  1773. if(mob instanceof Player) {
  1774. playersNeedingHitsUpdate.add((Player)mob);
  1775. }
  1776. else if(mob instanceof Npc) {
  1777. npcsNeedingHitsUpdate.add((Npc)mob);
  1778. }
  1779. }
  1780.  
  1781. public List<Player> getPlayersRequiringHitsUpdate() {
  1782. return playersNeedingHitsUpdate;
  1783. }
  1784.  
  1785. public List<Npc> getNpcsRequiringHitsUpdate() {
  1786. return npcsNeedingHitsUpdate;
  1787. }
  1788.  
  1789. public void clearPlayersNeedingHitsUpdate() {
  1790. playersNeedingHitsUpdate.clear();
  1791. }
  1792.  
  1793. public void clearNpcsNeedingHitsUpdate() {
  1794. npcsNeedingHitsUpdate.clear();
  1795. }
  1796.  
  1797. public void informOfProjectile(Projectile p) {
  1798. projectilesNeedingDisplayed.add(p);
  1799. }
  1800.  
  1801. public List<Projectile> getProjectilesNeedingDisplayed() {
  1802. return projectilesNeedingDisplayed;
  1803. }
  1804.  
  1805. public void clearProjectilesNeedingDisplayed() {
  1806. projectilesNeedingDisplayed.clear();
  1807. }
  1808.  
  1809. public void addPrayerDrain(int prayerID) {
  1810. PrayerDef prayer = EntityHandler.getPrayerDef(prayerID);
  1811. drainRate += prayer.getDrainRate();
  1812. drainer.setDelay((int)(240000 / drainRate));
  1813. }
  1814.  
  1815. public void removePrayerDrain(int prayerID) {
  1816. PrayerDef prayer = EntityHandler.getPrayerDef(prayerID);
  1817. drainRate -= prayer.getDrainRate();
  1818. if(drainRate <= 0) {
  1819. drainRate = 0;
  1820. drainer.setDelay(Integer.MAX_VALUE);
  1821. }
  1822. else {
  1823. drainer.setDelay((int)(240000 / drainRate));
  1824. }
  1825. }
  1826.  
  1827. public boolean isFriendsWith(String username) {
  1828. return friendList.contains(username);
  1829. }
  1830.  
  1831. public boolean isIgnoring(String user) {
  1832. return ignoreList.contains(user);
  1833. }
  1834.  
  1835. public List<String> getFriendList() {
  1836. return friendList;
  1837. }
  1838.  
  1839. public HashSet<String> getIgnoreList() {
  1840. return ignoreList;
  1841. }
  1842.  
  1843. public void removeFriend(String user) {
  1844. friendList.remove(user);
  1845. }
  1846.  
  1847. public void removeIgnore(String user) {
  1848. ignoreList.remove(user);
  1849. }
  1850.  
  1851. public void addFriend(String name) {
  1852. if(friendList.size() >= 50)
  1853. getActionSender().sendMessage("Sorry your friends list is Full.");
  1854. else
  1855. friendList.add(name);
  1856. }
  1857.  
  1858. public void addIgnore(String user) {
  1859. ignoreList.add(user);
  1860. }
  1861.  
  1862. public int friendCount() {
  1863. return friendList.size();
  1864. }
  1865.  
  1866. public int ignoreCount() {
  1867. return ignoreList.size();
  1868. }
  1869.  
  1870. public void setTradeConfirmAccepted(boolean b) {
  1871. tradeConfirmAccepted = b;
  1872. }
  1873.  
  1874. public void setDuelConfirmAccepted(boolean b) {
  1875. duelConfirmAccepted = b;
  1876. }
  1877.  
  1878. public boolean isTradeConfirmAccepted() {
  1879. return tradeConfirmAccepted;
  1880. }
  1881.  
  1882. public boolean isDuelConfirmAccepted() {
  1883. return duelConfirmAccepted;
  1884. }
  1885.  
  1886. public void setTradeOfferAccepted(boolean b) {
  1887. tradeOfferAccepted = b;
  1888. }
  1889.  
  1890. public void setDuelOfferAccepted(boolean b) {
  1891. duelOfferAccepted = b;
  1892. }
  1893.  
  1894. public boolean isTradeOfferAccepted() {
  1895. return tradeOfferAccepted;
  1896. }
  1897.  
  1898. public boolean isDuelOfferAccepted() {
  1899. return duelOfferAccepted;
  1900. }
  1901.  
  1902. public void resetTradeOffer() {
  1903. tradeOffer.clear();
  1904. }
  1905. public void resetDuelOffer() {
  1906. duelOffer.clear();
  1907. }
  1908.  
  1909. public void addToTradeOffer(InvItem item) {
  1910. tradeOffer.add(item);
  1911. }
  1912.  
  1913. public void addToDuelOffer(InvItem item) {
  1914. duelOffer.add(item);
  1915. }
  1916.  
  1917. public ArrayList<InvItem> getTradeOffer() {
  1918. return tradeOffer;
  1919. }
  1920.  
  1921. public ArrayList<InvItem> getDuelOffer() {
  1922. return duelOffer;
  1923. }
  1924.  
  1925. public void setTrading(boolean b) {
  1926. isTrading = b;
  1927. }
  1928.  
  1929. public void setDueling(boolean b) {
  1930. isDueling = b;
  1931. }
  1932.  
  1933. public boolean isTrading() {
  1934. return isTrading;
  1935. }
  1936.  
  1937. public boolean isDueling() {
  1938. return isDueling;
  1939. }
  1940.  
  1941. public void setWishToTrade(Player p) {
  1942. wishToTrade = p;
  1943. }
  1944.  
  1945. public void setWishToDuel(Player p) {
  1946. wishToDuel = p;
  1947. }
  1948.  
  1949. public Player getWishToTrade() {
  1950. return wishToTrade;
  1951. }
  1952.  
  1953. public Player getWishToDuel() {
  1954. return wishToDuel;
  1955. }
  1956. // IoSession
  1957. public void setDuelSetting(int i, boolean b) {
  1958. duelOptions[i] = b;
  1959. }
  1960.  
  1961. public boolean getDuelSetting(int i) {
  1962. try {
  1963. for(InvItem item : duelOffer) {
  1964. if(DataConversions.inArray(Formulae.runeIDs, item.getID())) {
  1965. setDuelSetting(1, true);
  1966. break;
  1967. }
  1968. }
  1969. for(InvItem item : wishToDuel.getDuelOffer()) {
  1970. if(DataConversions.inArray(Formulae.runeIDs, item.getID())) {
  1971. setDuelSetting(1, true);
  1972. break;
  1973. }
  1974. }
  1975. }
  1976. catch(Exception e) { }
  1977. return duelOptions[i];
  1978. }
  1979.  
  1980. public void setMale(boolean male) {
  1981. maleGender = male;
  1982. }
  1983.  
  1984. public boolean isMale() {
  1985. return maleGender;
  1986. }
  1987.  
  1988. public void setChangingAppearance(boolean b) {
  1989. changingAppearance = b;
  1990. }
  1991.  
  1992. public boolean isChangingAppearance() {
  1993. return changingAppearance;
  1994. }
  1995.  
  1996. public boolean isReconnecting() {
  1997. return reconnecting;
  1998. }
  1999.  
  2000. public void setLastLogin(long l) {
  2001. lastLogin = l;
  2002. }
  2003.  
  2004. public long getLastLogin() {
  2005. return lastLogin;
  2006. }
  2007.  
  2008. public int getDaysSinceLastLogin() {
  2009. long now = Calendar.getInstance().getTimeInMillis() / 1000;
  2010. return (int)((now - lastLogin) / 86400);
  2011. }
  2012.  
  2013. public long getCurrentLogin() {
  2014. return currentLogin;
  2015. }
  2016.  
  2017. public void setLastIP(String ip) {
  2018. lastIP = ip;
  2019. }
  2020.  
  2021. public String getCurrentIP() {
  2022. return currentIP;
  2023. }
  2024.  
  2025. public String getLastIP() {
  2026. return lastIP;
  2027. }
  2028.  
  2029. public void setGroupID(int id) {
  2030. rank = id;
  2031. }
  2032.  
  2033. public int getGroupID() {
  2034. return rank;
  2035. }
  2036.  
  2037. public boolean isSubscriber() {
  2038. return rank == 1 || isEvent() || isPMod() || isMod() || isAdmin();
  2039. }
  2040.  
  2041. public boolean isEvent() {
  2042. return rank == 7 || isPMod() || isMod() || isAdmin();
  2043. }
  2044.  
  2045. public boolean isPMod() {
  2046. return rank == 2 || isMod() || isAdmin();
  2047. }
  2048.  
  2049. public boolean isMod() {
  2050. return rank == 3 || isAdmin();
  2051. }
  2052.  
  2053. public boolean isAdmin() {
  2054. return rank == 4;
  2055. }
  2056.  
  2057. public int getArmourPoints() {
  2058. int points = 1;
  2059. for(InvItem item : inventory.getItems()) {
  2060. if(item.isWielded()) {
  2061. points += item.getWieldableDef().getArmourPoints();
  2062. }
  2063. }
  2064. return points < 1 ? 1 : points;
  2065. }
  2066.  
  2067. public int getWeaponAimPoints() {
  2068. int points = 1;
  2069. for(InvItem item : inventory.getItems()) {
  2070. if(item.isWielded()) {
  2071. points += item.getWieldableDef().getWeaponAimPoints();
  2072. }
  2073. }
  2074. return points < 1 ? 1 : points;
  2075. }
  2076.  
  2077. public int getWeaponPowerPoints() {
  2078. int points = 1;
  2079. for(InvItem item : inventory.getItems()) {
  2080. if(item.isWielded()) {
  2081. points += item.getWieldableDef().getWeaponPowerPoints();
  2082. }
  2083. }
  2084. return points < 1 ? 1 : points;
  2085. }
  2086.  
  2087. public int getMagicPoints() {
  2088. int points = 1;
  2089. for(InvItem item : inventory.getItems()) {
  2090. if(item.isWielded()) {
  2091. points += item.getWieldableDef().getMagicPoints();
  2092. }
  2093. }
  2094. return points < 1 ? 1 : points;
  2095. }
  2096.  
  2097. public int getPrayerPoints() {
  2098. int points = 1;
  2099. for(InvItem item : inventory.getItems()) {
  2100. if(item.isWielded()) {
  2101. points += item.getWieldableDef().getPrayerPoints();
  2102. }
  2103. }
  2104. return points < 1 ? 1 : points;
  2105. }
  2106.  
  2107. public int getRangePoints() {
  2108. int points = 1;
  2109. for(InvItem item : inventory.getItems()) {
  2110. if(item.isWielded()) {
  2111. points += item.getWieldableDef().getRangePoints();
  2112. }
  2113. }
  2114. return points < 1 ? 1 : points;
  2115. }
  2116.  
  2117. public MiscPacketBuilder getActionSender() {
  2118. return actionSender;
  2119. }
  2120.  
  2121. public int[] getWornItems() {
  2122. return wornItems;
  2123. }
  2124.  
  2125. public void updateWornItems(int index, int id) {
  2126. wornItems[index] = id;
  2127. super.ourAppearanceChanged = true;
  2128. }
  2129.  
  2130. public void setWornItems(int[] worn) {
  2131. wornItems = worn;
  2132. super.ourAppearanceChanged = true;
  2133. }
  2134.  
  2135. public Inventory getInventory() {
  2136. return inventory;
  2137. }
  2138.  
  2139. public void setInventory(Inventory i) {
  2140. inventory = i;
  2141. }
  2142.  
  2143. public Bank getBank() {
  2144. return bank;
  2145. }
  2146.  
  2147. public void setBank(Bank b) {
  2148. bank = b;
  2149. }
  2150.  
  2151. public void setGameSetting(int i, boolean b) {
  2152. gameSettings[i] = b;
  2153. }
  2154.  
  2155. public boolean getGameSetting(int i) {
  2156. return gameSettings[i];
  2157. }
  2158.  
  2159. public void setPrivacySetting(int i, boolean b) {
  2160. privacySettings[i] = b;
  2161. }
  2162.  
  2163. public boolean getPrivacySetting(int i) {
  2164. return privacySettings[i];
  2165. }
  2166.  
  2167. public long getLastPing() {
  2168. return lastPing;
  2169. }
  2170.  
  2171. public IoSession getSession() {
  2172. return ioSession;
  2173. }
  2174.  
  2175. public boolean loggedIn() {
  2176. return loggedIn;
  2177. }
  2178.  
  2179. public void setLoggedIn(boolean loggedIn) {
  2180. if(loggedIn) {
  2181. currentLogin = System.currentTimeMillis();
  2182. }
  2183. this.loggedIn = loggedIn;
  2184. }
  2185.  
  2186. public String getUsername() {
  2187. return username;
  2188. }
  2189.  
  2190. public long getUsernameHash() {
  2191. return usernameHash;
  2192. }
  2193.  
  2194. public String getPassword() {
  2195. return password;
  2196. }
  2197.  
  2198. public void ping() {
  2199. lastPing = System.currentTimeMillis();
  2200. }
  2201.  
  2202. public boolean isSkulled() {
  2203. return skullEvent != null;
  2204. }
  2205.  
  2206. public PlayerAppearance getPlayerAppearance() {
  2207. return appearance;
  2208. }
  2209.  
  2210.  
  2211. public void setAppearance(PlayerAppearance appearance) {
  2212. this.appearance = appearance;
  2213. }
  2214.  
  2215. public int getSkullTime() {
  2216. if(isSkulled()) {
  2217. return skullEvent.timeTillNextRun();
  2218. }
  2219. return 0;
  2220. }
  2221. // destroy
  2222. public void addSkull(long timeLeft) {
  2223. if(!isSkulled()) {
  2224. skullEvent = new DelayedEvent(this, 1200000) {
  2225. public void run() {
  2226. removeSkull();
  2227. }
  2228. };
  2229. world.getDelayedEventHandler().add(skullEvent);
  2230. super.setAppearnceChanged(true);
  2231. }
  2232. skullEvent.setLastRun(System.currentTimeMillis() - (1200000 - timeLeft));
  2233. }
  2234.  
  2235. public void removeSkull() {
  2236. if(!isSkulled()) {
  2237. return;
  2238. }
  2239. super.setAppearnceChanged(true);
  2240. skullEvent.stop();
  2241. skullEvent = null;
  2242. }
  2243.  
  2244. public void setSuspiciousPlayer(boolean suspicious) {
  2245. this.suspicious = suspicious;
  2246. }
  2247.  
  2248. public void addPlayersAppearanceIDs(int[] indicies, int[] appearanceIDs) {
  2249. for (int x = 0; x < indicies.length; x++) {
  2250. knownPlayersAppearanceIDs.put(indicies[x], appearanceIDs[x]);
  2251. }
  2252. }
  2253.  
  2254. public List<Player> getPlayersRequiringAppearanceUpdate() {
  2255. List<Player> needingUpdates = new ArrayList<Player>();
  2256. needingUpdates.addAll(watchedPlayers.getNewEntities());
  2257. if (super.ourAppearanceChanged) {
  2258. needingUpdates.add(this);
  2259. }
  2260. for (Player p : watchedPlayers.getKnownEntities()) {
  2261. if (needsAppearanceUpdateFor(p)) {
  2262. needingUpdates.add(p);
  2263. }
  2264. }
  2265. return needingUpdates;
  2266. }
  2267.  
  2268. private boolean needsAppearanceUpdateFor(Player p) {
  2269. int playerServerIndex = p.getIndex();
  2270. if (knownPlayersAppearanceIDs.containsKey(playerServerIndex)) {
  2271. int knownPlayerAppearanceID = knownPlayersAppearanceIDs.get(playerServerIndex);
  2272. if(knownPlayerAppearanceID != p.getAppearanceID()) {
  2273. return true;
  2274. }
  2275. }
  2276. else {
  2277. return true;
  2278. }
  2279. return false;
  2280. }
  2281.  
  2282. public void updateViewedPlayers() {
  2283. List<Player> playersInView = viewArea.getPlayersInView();
  2284. for (Player p : playersInView) {
  2285. if (p.getIndex() != getIndex() && p.loggedIn()) {
  2286. this.informOfPlayer(p);
  2287. }
  2288. if (p.isInvisible()) {
  2289. p.informOfPlayer(this);
  2290. }
  2291. }
  2292. }
  2293.  
  2294. public void updateViewedObjects() {
  2295. List<GameObject> objectsInView = viewArea.getGameObjectsInView();
  2296. for (GameObject o : objectsInView) {
  2297. if (!watchedObjects.contains(o) && !o.isRemoved() && withinRange(o)) {
  2298. watchedObjects.add(o);
  2299. }
  2300. }
  2301. }
  2302.  
  2303. public void updateViewedItems() {
  2304. List<Item> itemsInView = viewArea.getItemsInView();
  2305. for (Item i : itemsInView) {
  2306. if ((!(watchedItems.contains(i))) && (!(i.isRemoved())) && (withinRange(i)) && (i.visibleTo(this)) && (hiddenItems == true)) {
  2307. watchedItems.add(i);
  2308. }
  2309. }
  2310. }
  2311.  
  2312. public void updateViewedNpcs() {
  2313. List<Npc> npcsInView = viewArea.getNpcsInView();
  2314. for (Npc n : npcsInView) {
  2315. if ((!watchedNpcs.contains(n) || watchedNpcs.isRemoving(n)) && withinRange(n)) {
  2316. watchedNpcs.add(n);
  2317. }
  2318. }
  2319. }
  2320.  
  2321. public void teleport(int x, int y, boolean bubble) {
  2322. Mob opponent = super.getOpponent();
  2323. if(inCombat()) {
  2324. resetCombat(CombatState.ERROR);
  2325. }
  2326. if(opponent != null) {
  2327. opponent.resetCombat(CombatState.ERROR);
  2328. }
  2329. for (Object o : getWatchedPlayers().getAllEntities()) {
  2330. Player p = ((Player)o);
  2331. if(bubble) {
  2332. p.getActionSender().sendTeleBubble(getX(), getY(), false);
  2333. }
  2334. p.removeWatchedPlayer(this);
  2335. }
  2336. if(bubble) {
  2337. actionSender.sendTeleBubble(getX(), getY(), false);
  2338. }
  2339. setLocation(Point.location(x, y), true);
  2340. resetPath();
  2341. actionSender.sendWorldInfo();
  2342. }
  2343. //destroy
  2344. /**
  2345. * This is a 'another player has tapped us on the shoulder' method.
  2346. *
  2347. * If we are in another players viewArea, they should in theory be in ours.
  2348. * So they will call this method to let the player know they should probably
  2349. * be informed of them.
  2350. */
  2351. public void informOfPlayer(Player p) {
  2352. if ((!watchedPlayers.contains(p) || watchedPlayers.isRemoving(p)) && withinRange(p)) {
  2353. watchedPlayers.add(p);
  2354. }
  2355. }
  2356.  
  2357. public StatefulEntityCollection<Player> getWatchedPlayers() {
  2358. return watchedPlayers;
  2359. }
  2360.  
  2361. public StatefulEntityCollection<GameObject> getWatchedObjects() {
  2362. return watchedObjects;
  2363. }
  2364.  
  2365. public StatefulEntityCollection<Item> getWatchedItems() {
  2366. return watchedItems;
  2367. }
  2368.  
  2369. public StatefulEntityCollection<Npc> getWatchedNpcs() {
  2370. return watchedNpcs;
  2371. }
  2372.  
  2373. public void removeWatchedNpc(Npc n) {
  2374. watchedNpcs.remove(n);
  2375. }
  2376.  
  2377. public void removeWatchedPlayer(Player p) {
  2378. watchedPlayers.remove(p);
  2379. }
  2380.  
  2381. public void revalidateWatchedPlayers() {
  2382. for (Player p : watchedPlayers.getKnownEntities()) {
  2383. if (!withinRange(p) || !p.loggedIn()) {
  2384. watchedPlayers.remove(p);
  2385. knownPlayersAppearanceIDs.remove(p.getIndex());
  2386. }
  2387. }
  2388. }
  2389.  
  2390. public void revalidateWatchedObjects() {
  2391. for (GameObject o : watchedObjects.getKnownEntities()) {
  2392. if (!withinRange(o) || o.isRemoved()) {
  2393. watchedObjects.remove(o);
  2394. }
  2395. }
  2396. }
  2397.  
  2398. public void revalidateWatchedItems() {
  2399. for (Item i : watchedItems.getKnownEntities()) {
  2400. if (!withinRange(i) || i.isRemoved() || !i.visibleTo(this)) {
  2401. watchedItems.remove(i);
  2402. }
  2403. }
  2404. }
  2405.  
  2406. public void revalidateWatchedNpcs() {
  2407. for (Npc n : watchedNpcs.getKnownEntities()) {
  2408. if (!withinRange(n) || n.isRemoved()) {
  2409. watchedNpcs.remove(n);
  2410. }
  2411. }
  2412. }
  2413.  
  2414. public boolean withinRange(Entity e) {
  2415. int xDiff = location.getX() - e.getLocation().getX();
  2416. int yDiff = location.getY() - e.getLocation().getY();
  2417. return xDiff <= 16 && xDiff >= -15 && yDiff <= 16 && yDiff >= -15;
  2418. }
  2419.  
  2420. public int[] getCurStats() {
  2421. return curStat;
  2422. }
  2423.  
  2424. public int getCurStat(int id) {
  2425. return curStat[id];
  2426. }
  2427.  
  2428. public int getHits() {
  2429. return getCurStat(3);
  2430. }
  2431.  
  2432. public int getAttack() {
  2433. return getCurStat(0);
  2434. }
  2435.  
  2436. public int getDefense() {
  2437. return getCurStat(1);
  2438. }
  2439.  
  2440. public int getStrength() {
  2441. return getCurStat(2);
  2442. }
  2443.  
  2444. public void setHits(int lvl) {
  2445. setCurStat(3, lvl);
  2446. }
  2447.  
  2448. public void setAttack(int lvl) {
  2449. setCurStat(0, lvl);
  2450. }
  2451.  
  2452. public void setDefense(int lvl) {
  2453. setCurStat(1, lvl);
  2454. }
  2455.  
  2456. public void setStrength(int lvl) {
  2457. setCurStat(2, lvl);
  2458. }
  2459.  
  2460. public void setCurStat(int id, int lvl) {
  2461. if(lvl <= 0) {
  2462. lvl = 0;
  2463. }
  2464. curStat[id] = lvl;
  2465. }
  2466.  
  2467. public int getMaxStat(int id) {
  2468. return maxStat[id];
  2469. }
  2470.  
  2471. public void setMaxStat(int id, int lvl) {
  2472. if(lvl < 0) {
  2473. lvl = 0;
  2474. }
  2475. maxStat[id] = lvl;
  2476. }
  2477.  
  2478. public int[] getMaxStats() {
  2479. return maxStat;
  2480. }
  2481.  
  2482. public int getSkillTotal() {
  2483. int total = 0;
  2484. for(int stat : maxStat) {
  2485. total += stat;
  2486. }
  2487. return total;
  2488. }
  2489.  
  2490. public void incCurStat(int i, int amount) {
  2491. curStat[i] += amount;
  2492. if(curStat[i] < 0) {
  2493. curStat[i] = 0;
  2494. }
  2495. }
  2496.  
  2497. public void incMaxStat(int i, int amount) {
  2498. maxStat[i] += amount;
  2499. if(maxStat[i] < 0) {
  2500. maxStat[i] = 0;
  2501. }
  2502. }
  2503.  
  2504. public void setFatigue(int fatigue) {
  2505. this.fatigue = fatigue;
  2506. }
  2507.  
  2508. public int getFatigue() {
  2509. return fatigue;
  2510. }
  2511.  
  2512. public void incExp(int i, int amount, boolean useFatigue, boolean multiplied) {
  2513. if(GameVars.useFatigue) {
  2514. if(useFatigue) {
  2515. if(fatigue >= 100) {
  2516. actionSender.sendMessage("@gre@You are too tired to gain experience, get some rest!");
  2517. return;
  2518. }
  2519. if(fatigue >= 96) {
  2520. actionSender.sendMessage("@gre@You start to feel tired, maybe you should rest soon.");
  2521. }
  2522. fatigue++;
  2523. actionSender.sendFatigue();
  2524. }
  2525. }
  2526. if(multiplied)
  2527. amount*=GameVars.expMultiplier;
  2528. if(isSub(getUsername()))
  2529. amount*=GameVars.SubExpMultiplier;
  2530. exp[i] += amount;
  2531. if(exp[i] < 0) {
  2532. exp[i] = 0;
  2533. }
  2534. int level = Formulae.experienceToLevel(exp[i]);
  2535. if(level != maxStat[i]) {
  2536. int advanced = level - maxStat[i];
  2537. incCurStat(i, advanced);
  2538. incMaxStat(i, advanced);
  2539. actionSender.sendStat(i);
  2540. actionSender.sendMessage("@gre@You just advanced " + advanced + " " + Formulae.statArray[i] + " level!");
  2541. actionSender.sendSound("advance");
  2542. world.getDelayedEventHandler().add(new MiniEvent(this) {
  2543. public void action() {
  2544. owner.getActionSender().sendScreenshot();
  2545. }
  2546. });
  2547. int comb = Formulae.getCombatlevel(maxStat);
  2548. if(comb != getCombatLevel()) {
  2549. actionSender.sendMessage("@gre@Your combat level is now:@whi@ " + comb + "!");
  2550. actionSender.sendSound("advance");
  2551. setCombatLevel(comb);
  2552. }
  2553. }
  2554. }
  2555. //destroy
  2556. public int[] getExps() {
  2557. return exp;
  2558. }
  2559.  
  2560. public int getExp(int id) {
  2561. return exp[id];
  2562. }
  2563.  
  2564. public void setExp(int id, int lvl) {
  2565. if(lvl < 0) {
  2566. lvl = 0;
  2567. }
  2568. exp[id] = lvl;
  2569. }
  2570.  
  2571. public void setExp(int[] lvls) {
  2572. exp = lvls;
  2573. }
  2574.  
  2575. public boolean equals(Object o) {
  2576. if (o instanceof Player) {
  2577. Player p = (Player)o;
  2578. return usernameHash == p.getUsernameHash();
  2579. }
  2580. return false;
  2581. }
  2582.  
  2583. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement