Advertisement
Guest User

Untitled

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