Advertisement
Guest User

Untitled

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