Advertisement
Guest User

Untitled

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