Advertisement
Guest User

Untitled

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