Advertisement
Guest User

Untitled

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