Advertisement
Guest User

Untitled

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