Advertisement
Guest User

Untitled

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