Guest User

Untitled

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