Guest User

Untitled

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