Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 44.79 KB | None | 0 0
  1. package com.rs2.model.player;
  2.  
  3. import com.rs2.Constants;
  4. import com.rs2.GameEngine;
  5. import com.rs2.content.ForceWalker;
  6. import com.rs2.content.JailSystem;
  7. import com.rs2.content.controllers.Damage;
  8. import com.rs2.content.minigames.FightPits;
  9. import com.rs2.model.Item;
  10. import com.rs2.model.Entity;
  11. import com.rs2.model.npc.NPC;
  12. import com.rs2.net.Stream;
  13. import com.rs2.tiles.FollowEngine;
  14. import com.rs2.util.Misc;
  15. import com.rs2.world.NPCManager;
  16. import com.rs2.world.PlayerManager;
  17.  
  18. public abstract class Player extends Entity {
  19.    
  20.     public String teleOther;
  21.  
  22.     public int teleToSpell;
  23.    
  24.     public boolean inMiniGame() {
  25.         if (FightPits.inFightPits((Client)this) || FightPits.inFightArea((Client)this)) {
  26.             return true;
  27.         }
  28.         if (FightPits.inWaitingRoom((Client)this) || FightPits.inWaitingArea((Client)this)) {
  29.             return true;
  30.         }
  31.         return false;
  32.     }
  33.    
  34.     public int clickedNPCID = 0, destX = 0, destY = 0, npcSize = 0, npcTask = 0, npcSlot = 0;
  35.    
  36.     public NPC npc = null;
  37.     public boolean[] teleport = new boolean[6];
  38.     public int teleportConfig = -1;
  39.     public int projectileDelay;
  40.    
  41.     /**
  42.      * poisoning
  43.      */
  44.     public boolean poisonHit = false;
  45.     public int[] poisonHits = new int[3];
  46.     public int poisonDamage;
  47.     public int poisonDelay;
  48.    
  49.     /** mining **/
  50.     public int objectID = 0, objectX = 0, objectY = 0, objectSize = 0, setPlayerX = 0, setPlayerY = 0;
  51.    
  52.     public int[] objectStorage = new int[6];
  53.  
  54.     public int chargeTimer;
  55.     public int runConfig;
  56.     public int retaliate;
  57.     public int ID;
  58.     /**
  59.      * @return the ID
  60.      */
  61.     public int getID() {
  62.         return ID;
  63.     }
  64.    
  65.     /**
  66.      * Duelling features.
  67.      */
  68.     public boolean[] duelRule = new boolean[22];
  69.     public boolean[] duelAccepted = new boolean[2]; //1 being first screen, etc.
  70.     public Client duelRequest = null;
  71.     public int duelOption = 0;
  72.     public int duelSpaceReq = 0;
  73.     public int duelSlot = 0;
  74.     public int[] DUEL_RULE_ID = {
  75.         1, 2, 16, 32, 64, 128, 256, 512,
  76.         1024, 4096, 8192, 16384, 32768,
  77.         65536, 131072, 262144, 524288,
  78.         2097152, 8388608, 16777216,
  79.         67108864, 134217728
  80.     };
  81.    
  82.     public int[][] array;
  83.     public int gem = 0;
  84.     public int crafting = 0;
  85.     public int craftingItem = 0;
  86.     public int craftingType = 0;
  87.     public int craftingAmount = 0;
  88.     public int craftingThreadCount = 0;
  89.    
  90.     /**
  91.      * smelting
  92.      */
  93.     public int oreId = 0;
  94.     public int smeltAmount = 0;
  95.    
  96.     public int jewleryId = 0;
  97.     public int lastMeleeMode = -1;
  98.     public int lastRangeMode = -1;
  99.     public int lastMagicMode = -1;
  100.     public boolean forceMove;
  101.     public int[] forceMovement = new int[3];
  102.    
  103.     public int foodDelay;
  104.     public int potionDelay;
  105.     public Client skulledOn;
  106.     public long potionTimer;
  107.     public int[] pickup = new int[3];
  108.     public int starter;
  109.     public Client whoKilledYa;
  110.     public String[] lastKilled = {"", "", ""};
  111.     public String MBTC = "", MBBC = "",  MBHT = "", MBID = "";
  112.     public boolean wildSignWarning = false, SplitChat;
  113.     public int testnum = 0;
  114.     public int combatMode = 0; //default - attack.
  115.     public boolean usingMagicDefence = false;
  116.     public boolean turnOffSpell = false;
  117.     public int spellId = 0;
  118.     public boolean autoRetaliate = false;
  119.    
  120.     public void println_debug(String s) {
  121.         if (GameEngine.isDebugEnabled())
  122.             System.out.println("[Client] " + getUsername() + " - " + s);
  123.     }
  124.     public String[] multiList = new String[9];
  125.     public long actionTimer;
  126.     public long yellTimer;
  127.     public String[] getMulti() {
  128.         return multiList;
  129.     }
  130.     public void setMulti(String name, int slot) {
  131.         this.multiList[slot] = name;
  132.     }
  133.     public int tanningInterfaceID;
  134.    
  135.     public int getTanningInterfaceID() {
  136.         return tanningInterfaceID;
  137.     }
  138.     public void setTanningInterfaceID(int newInterface) {
  139.         this.tanningInterfaceID = newInterface;
  140.     }
  141.    
  142.     public int wildernessLevel;
  143.    
  144.     public int getWildernessLevel() {
  145.         return wildernessLevel;
  146.     }
  147.     public void setWildernessLevel(int level) {
  148.         this.wildernessLevel = level;
  149.     }
  150.    
  151.     public int autoCastId;
  152.    
  153.     public int getAutoCastId() {
  154.         return autoCastId;
  155.     }
  156.     public void setAutoCastId(int id) {
  157.         this.autoCastId = id;
  158.     }
  159.    
  160.     public boolean autoCasting;
  161.    
  162.     public boolean isAutoCasting() {
  163.         return autoCasting;
  164.     }
  165.     public void setAutoCasting(boolean type) {
  166.         this.autoCasting = type;
  167.     }
  168.    
  169.     public boolean isDeadWaiting;
  170.    
  171.     public boolean isDeadWaiting() {
  172.         return isDeadWaiting;
  173.     }
  174.     public void setDeadWaiting(boolean type) {
  175.         this.isDeadWaiting = type;
  176.     }
  177.    
  178.     public int deadTimer;
  179.    
  180.     public int getDeadTimer() {
  181.         return deadTimer;
  182.     }
  183.     public void setDeadTimer(int time) {
  184.         this.deadTimer = time;
  185.     }
  186.     public void deductDeadTimer() {
  187.         this.deadTimer--;
  188.     }
  189.    
  190.     public int stunnedTimer;
  191.    
  192.     public int getStunnedTimer() {
  193.         return stunnedTimer;
  194.     }
  195.     public void setStunnedTimer(int time) {
  196.         this.stunnedTimer = time;
  197.     }
  198.     public void deductStunnedTimer() {
  199.         this.stunnedTimer--;
  200.     }
  201.    
  202.     public int recoil;
  203.     public int getRecoilCount() {
  204.         return recoil;
  205.     }
  206.     public void setRecoilCount(int count) {
  207.         this.recoil = count;
  208.     }
  209.     /*
  210.      * spellbook 0 = reg, 1 = anc, 2 = lunar
  211.      */
  212.     public int dharokDamage = 0;
  213.     public int spellBook = 0;
  214.     public String username = "";
  215.     public String password = "";
  216.     public String connectedFrom = "";
  217.     public int privileges = 0;
  218.     public int userID = -1;
  219.     public boolean appearanceSet = false;
  220.  
  221.     /**
  222.      * @return the username
  223.      */
  224.     public String getUsername() {
  225.         return username;
  226.     }
  227.  
  228.     /**
  229.      * @param username
  230.      *            the username to be set
  231.      */
  232.    
  233.     public void setUsername(String username) {
  234.         this.username = username;
  235.     }
  236.     private long lastAction;
  237.  
  238.     public long getLastAction() {
  239.         return lastAction;
  240.     }
  241.  
  242.     public void setLastAction(long currentTimeMillis) {
  243.         this.lastAction = currentTimeMillis;
  244.        
  245.     }
  246.    
  247.     /**
  248.      * lunar
  249.      */
  250.     private boolean vengenceCasted;
  251.    
  252.     public boolean isVengOn() {
  253.         return vengenceCasted;
  254.     }
  255.     public void setVeng(boolean type) {
  256.         this.vengenceCasted = type;
  257.     }
  258.     public void moveClient() {
  259.         this.forceMove = true;
  260.         int random = Misc.random(1);
  261.         int opposite = random == 1 ? 0 : 1;
  262.         this.forceMovement[0] = this.getAbsX() + random;
  263.         this.forceMovement[1] = this.getAbsY() + opposite;
  264.         this.forceMovement[2] = this.getHeightLevel();
  265.     }
  266.  
  267.     /**
  268.      * @return the password
  269.      */
  270.     public String getPassword() {
  271.         return password;
  272.     }
  273.  
  274.     /**
  275.      * @param password
  276.      *            the password to be set
  277.      */
  278.     public void setPassword(String password) {
  279.         this.password = password;
  280.     }
  281.  
  282.     /**
  283.      * @return the connectedFrom
  284.      */
  285.     public String getConnectedFrom() {
  286.         return connectedFrom;
  287.     }
  288.  
  289.     /**
  290.      * @param connectedFrom
  291.      *            the connectedFrom to be set
  292.      */
  293.     public void setConnectedFrom(String connectedFrom) {
  294.         this.connectedFrom = connectedFrom;
  295.     }
  296.  
  297.     /**
  298.      * @return the privileges
  299.      */
  300.     public int getPrivileges() {
  301.         return privileges;
  302.     }
  303.  
  304.     /**
  305.      * @param privileges
  306.      *            the privileges to be set
  307.      */
  308.     public void setPrivileges(int privileges) {
  309.         this.privileges = privileges;
  310.     }
  311.  
  312.     /**
  313.      * @return the userID
  314.      */
  315.     public int getUserID() {
  316.         return userID;
  317.     }
  318.  
  319.     /**
  320.      * @param userID
  321.      *            the userID to be set
  322.      */
  323.     public void setUserID(int userID) {
  324.         this.userID = userID;
  325.     }
  326.  
  327.     private long[] friends = new long[200];
  328.     private long[] ignores = new long[100];
  329.     private int friendsSize;
  330.     private int ignoresSize;
  331.  
  332.     /**
  333.      * @param friends
  334.      *            the friends to set
  335.      */
  336.     public void setFriends(long[] friends) {
  337.         this.friends = friends;
  338.     }
  339.  
  340.     /**
  341.      * @return the friends
  342.      */
  343.     public long[] getFriends() {
  344.         return friends;
  345.     }
  346.  
  347.     public int getSpellBook() {
  348.         return spellBook;
  349.     }
  350.    
  351.     public void setSpellBook(int book) {
  352.         this.spellBook = book;
  353.     }
  354.    
  355.     public int getDharokDamage() {
  356.         return dharokDamage;
  357.     }
  358.    
  359.     public void resetDharokDamage() {
  360.         this.dharokDamage = 0;
  361.     }
  362.    
  363.     public void setDharokDamage(int damage) {
  364.         this.dharokDamage = damage;
  365.     }
  366.     /**
  367.      * @param ignoresSize
  368.      *            the ignoresSize to set
  369.      */
  370.     public void setIgnoresSize(int ignoresSize) {
  371.         this.ignoresSize = ignoresSize;
  372.     }
  373.  
  374.     /**
  375.      * @return the ignoresSize
  376.      */
  377.     public int getIgnoresSize() {
  378.         return ignoresSize;
  379.     }
  380.  
  381.     /**
  382.      * @param friendsSize
  383.      *            the friendsSize to set
  384.      */
  385.     public void setFriendsSize(int friendsSize) {
  386.         this.friendsSize = friendsSize;
  387.     }
  388.  
  389.     /**
  390.      * @return the friendsSize
  391.      */
  392.     public int getFriendsSize() {
  393.         return friendsSize;
  394.     }
  395.  
  396.     /**
  397.      * @param ignores
  398.      *            the ignores to set
  399.      */
  400.     public void setIgnores(long[] ignores) {
  401.         this.ignores = ignores;
  402.     }
  403.  
  404.     /**
  405.      * @return the ignores
  406.      */
  407.     public long[] getIgnores() {
  408.         return ignores;
  409.     }
  410.  
  411.     public boolean isBusy = false;
  412.  
  413.     /**
  414.      * @return the player's status
  415.      */
  416.     public boolean isBusy() {
  417.         return isBusy;
  418.     }
  419.  
  420.     /**
  421.      * @param isBusy
  422.      *            the status to be set
  423.      */
  424.     public void setBusy(boolean isBusy) {
  425.         this.isBusy = isBusy;
  426.     }
  427.  
  428.     public boolean canWalk = true;
  429.  
  430.     /*
  431.      * @return if the player can walk
  432.      */
  433.     public boolean canWalk() {
  434.         return canWalk;
  435.     }
  436.  
  437.     /**
  438.      * @param canWalk
  439.      *            set the player walking
  440.      */
  441.     public void setCanWalk(boolean canWalk) {
  442.         this.canWalk = canWalk;
  443.     }
  444.  
  445.     public int specialAmount = 100;
  446.  
  447.     /**
  448.      * @param specialAmount
  449.      *            the specialAmount to set
  450.      */
  451.     public void setSpecialAmount(int specialAmount) {
  452.         this.specialAmount = specialAmount;
  453.     }
  454.  
  455.     /**
  456.      * @return the specialAmount
  457.      */
  458.     public int getSpecialAmount() {
  459.         return specialAmount;
  460.     }
  461.  
  462.     public int lastHit;
  463.  
  464.     public int skullTimer = 0;
  465.  
  466.     /**
  467.      * @return the skullTimer
  468.      */
  469.     public int getSkullTimer() {
  470.         return skullTimer;
  471.     }
  472.  
  473.     /**
  474.      * @param skullTimer
  475.      *            the skullTimer to be set
  476.      */
  477.     public void setSkullTimer(int skullTimer) {
  478.         this.skullTimer = skullTimer;
  479.     }
  480.  
  481.     public boolean ancients;
  482.  
  483.     /**
  484.      * @return ancients;
  485.      */
  486.     public boolean isUsingAncients() {
  487.         return ancients;
  488.     }
  489.  
  490.     public int pkPoints;
  491.  
  492.     /**
  493.      * @return the pk points;
  494.      */
  495.     public int getPkPoints() {
  496.         return pkPoints;
  497.     }
  498.  
  499.     public int logoutDelay = 0;
  500.  
  501.     public boolean playerIsMember = false;
  502.  
  503.     /**
  504.      * @return playerIsMember
  505.      */
  506.     public boolean isPlayerMember() {
  507.         return playerIsMember;
  508.     }
  509.  
  510.     public int[] killedBy = new int[Constants.MAX_PLAYERS];
  511.  
  512.     public boolean alreadyInList(Client client) {
  513.         for (int i = 0; i < lastKilled.length; i++) {
  514.             if (lastKilled[i].equalsIgnoreCase(client.getUsername())) {
  515.                 return true;
  516.             }
  517.         }
  518.         return false;
  519.     }
  520.    
  521.    
  522.     public void addNewKiller(Client client) {
  523.         if(lastKilled[0] == null) {
  524.             lastKilled[0] = client.getUsername();
  525.         } else if (lastKilled[1] == null) {
  526.             lastKilled[1] = lastKilled[0];
  527.             lastKilled[0] = client.getUsername();
  528.         } else {
  529.             lastKilled[2] = lastKilled[1];
  530.             lastKilled[1] = lastKilled[0];
  531.             lastKilled[0] = client.getUsername();
  532.         }
  533.     }
  534.  
  535.    
  536.     public void removeKiller(Client client) {
  537.         for (int i = 0; i < lastKilled.length; i++) {
  538.             if (lastKilled[i] == client.getUsername()) {
  539.                 lastKilled[i] = null;
  540.             }
  541.         }
  542.     }
  543.     public String[] getLastKilled() {
  544.         return lastKilled;
  545.     }
  546.    
  547.     public int getPlayerKiller() {
  548.         int killerID;
  549.         int killerHits;
  550.         retry: {
  551.             killerID = 0;
  552.             killerHits = 0;
  553.             int l = 1;
  554.             do {
  555.                 if (l >= Constants.MAX_PLAYERS)
  556.                     break retry;
  557.                 if (killerID == 0) {
  558.                     killerID = l;
  559.                     killerHits = 1;
  560.                 } else if (killedBy[l] > killedBy[killerID]) {
  561.                     killerID = l;
  562.                     killerHits = 1;
  563.                 } else if (killedBy[l] == killedBy[killerID])
  564.                     killerHits++;
  565.                 l++;
  566.             } while (true);
  567.         }
  568.         if (killerHits > 1)
  569.             killerID = userID;
  570.         return killerID;
  571.     }
  572.  
  573.     public Player(int userID) {
  574.         super();
  575.  
  576.         setUserID(userID);
  577.  
  578.         for (int i = 0; i < playerItems.length; i++) {
  579.             playerItems[i] = 0;
  580.         }
  581.         for (int i = 0; i < playerItemsN.length; i++) {
  582.             playerItemsN[i] = 0;
  583.         }
  584.  
  585.         for (int i = 0; i < PlayerConstants.MAX_SKILLS; i++) {
  586.             if (i == 3) {
  587.                 playerLevel[i] = 10;
  588.             } else {
  589.                 playerLevel[i] = 1;
  590.             }
  591.         }
  592.  
  593.         for (int i = 0; i < PlayerConstants.MAX_SKILLS; i++) {
  594.             if (i == 3) {
  595.                 playerXP[i] = 1155;
  596.             } else {
  597.                 playerXP[i] = 0;
  598.             }
  599.         }
  600.  
  601.         for (int i = 0; i < playerBankSize; i++) {
  602.             bankItems[i] = 0;
  603.         }
  604.         for (int i = 0; i < playerBankSize; i++) {
  605.             bankItemsN[i] = 0;
  606.         }
  607.  
  608.         for (int j1 = 0; j1 < killedBy.length; j1++)
  609.             killedBy[j1] = 0;
  610.  
  611.         for (int i = 0; i < friends.length; i++) {
  612.             friends[i] = 0;
  613.         }
  614.         for (int i = 0; i < ignores.length; i++) {
  615.             ignores[i] = 0;
  616.         }
  617.  
  618.         playerEquipment[PlayerConstants.HELM] = -1;
  619.         playerEquipment[PlayerConstants.CAPE] = -1;
  620.         playerEquipment[PlayerConstants.AMULET] = -1;
  621.         playerEquipment[PlayerConstants.CHEST] = -1;
  622.         playerEquipment[PlayerConstants.SHIELD] = -1;
  623.         playerEquipment[PlayerConstants.BOTTOMS] = -1;
  624.         playerEquipment[PlayerConstants.GLOVES] = -1;
  625.         playerEquipment[PlayerConstants.BOOTS] = -1;
  626.         playerEquipment[PlayerConstants.RING] = -1;
  627.         playerEquipment[PlayerConstants.ARROWS] = -1;
  628.         playerEquipment[PlayerConstants.WEAPON] = -1;
  629.  
  630.         playerLook[PlayerConstants.HEAD] = 0;
  631.         playerLook[PlayerConstants.BODY] = 18;
  632.         playerLook[PlayerConstants.ARMS] = 26;
  633.         playerLook[PlayerConstants.HANDS] = 33;
  634.         playerLook[PlayerConstants.LEGS] = 36;
  635.         playerLook[PlayerConstants.FEET] = 42;
  636.         playerLook[PlayerConstants.BEARD] = 10;
  637.  
  638.         setHeightLevel(0);
  639.         teleportToX = 3251 + (Misc.random(2) - 1);
  640.         teleportToY = 3422 + (Misc.random(2) - 1);
  641.  
  642.         setAbsX(-1);
  643.         setAbsY(-1);
  644.         mapRegionX = mapRegionY = -1;
  645.         currentX = currentY = 0;
  646.         resetWalkingQueue();
  647.  
  648.     }
  649.  
  650.     public void destruct() {
  651.         playerListSize = 0;
  652.         for (int i = 0; i < Constants.MAX_PLAYERS; i++)
  653.             playerList[i] = null;
  654.  
  655.         npcListSize = 0;
  656.         for (int i = 0; i < NPCManager.MAXIMUM_NPCS; i++)
  657.             npcList[i] = null;
  658.  
  659.         setAbsX(-1);
  660.         setAbsY(-1);
  661.         mapRegionX = mapRegionY = -1;
  662.         currentX = currentY = 0;
  663.         resetWalkingQueue();
  664.     }
  665.  
  666.     public PlayerManager manager = null;
  667.  
  668.     public boolean initialized = false;
  669.     public boolean disconnected = false;
  670.     public boolean isActive = false;
  671.  
  672.     public abstract void initialize();
  673.  
  674.     public abstract void update();
  675.  
  676.     public abstract void process();
  677.  
  678.     protected static Stream playerProps;
  679.  
  680.     static {
  681.         playerProps = new Stream(new byte[PlayerConstants.PROPS_SIZE]);
  682.     }
  683.    
  684.  
  685.     public int getPoisonDelay() {
  686.         return poisonDelay;
  687.     }
  688.     public int[] playerLook = new int[13];
  689.  
  690.     public int runEmote = 0x338;
  691.     public int standEmote = 0x328;
  692.     public int walkEmote = 0x333;
  693.     public int headIcon = -1;
  694.     public int prayerId = -1;
  695.     public int bountyIcon = -1;
  696.     public int skullIcon = -1;
  697.     public int modHeadIcon = -1;
  698.     public int hintIcon = -1;
  699.  
  700.  
  701.     public int npcID = 0;
  702.     public boolean isNPC = false;
  703.  
  704.     public int[] playerEquipment = new int[14];
  705.     public int[] playerEquipmentN = new int[14];
  706.  
  707.     public int[] playerLevel = new int[PlayerConstants.MAX_SKILLS];
  708.     public int[] playerXP = new int[PlayerConstants.MAX_SKILLS];
  709.  
  710.     public int getXPForLevel(int level) {
  711.         int points = 0;
  712.         int output = 0;
  713.  
  714.         for (int lvl = 1; lvl <= level; lvl++) {
  715.             points += Math.floor(lvl + 300.0 * Math.pow(2.0, lvl / 7.0));
  716.             if (lvl >= level) {
  717.                 return output;
  718.             }
  719.             output = (int) Math.floor(points / 4);
  720.         }
  721.         return 0;
  722.     }
  723.  
  724.     public int getLevelForXP(int exp) {
  725.         int points = 0;
  726.         int output = 0;
  727.  
  728.         for (int lvl = 1; lvl <= 99; lvl++) {
  729.             points += Math.floor(lvl + 300.0 * Math.pow(2.0, lvl / 7.0));
  730.             output = (int) Math.floor(points / 4);
  731.             if (output >= exp)
  732.                 return lvl;
  733.         }
  734.         return 99;
  735.     }
  736.  
  737.     public int[] playerItems = new int[28];
  738.     public int[] playerItemsN = new int[28];
  739.  
  740.     private int playerBankSize;
  741.     public int[] bankItems = new int[800];
  742.     public int[] bankItemsN = new int[800];
  743.  
  744.     private int bankXremoveID = 0;
  745.     private int bankXinterfaceID = 0;
  746.     private int bankXremoveSlot = 0;
  747.  
  748.     public boolean takeAsNote = false;
  749.  
  750.     /**
  751.      * @param bankXinterfaceID
  752.      *            the bankXinterfaceID to set
  753.      */
  754.     public void setBankXinterfaceID(int bankXinterfaceID) {
  755.         this.bankXinterfaceID = bankXinterfaceID;
  756.     }
  757.  
  758.     /**
  759.      * @return the bankXinterfaceID
  760.      */
  761.     public int getBankXinterfaceID() {
  762.         return bankXinterfaceID;
  763.     }
  764.  
  765.     /**
  766.      * @param bankXremoveSlot
  767.      *            the bankXremoveSlot to set
  768.      */
  769.     public void setBankXremoveSlot(int bankXremoveSlot) {
  770.         this.bankXremoveSlot = bankXremoveSlot;
  771.     }
  772.  
  773.     /**
  774.      * @return the bankXremoveSlot
  775.      */
  776.     public int getBankXremoveSlot() {
  777.         return bankXremoveSlot;
  778.     }
  779.  
  780.     /**
  781.      * @param bankXremoveID
  782.      *            the bankXremoveID to set
  783.      */
  784.     public void setBankXremoveID(int bankXremoveID) {
  785.         this.bankXremoveID = bankXremoveID;
  786.     }
  787.  
  788.     /**
  789.      * @return the bankXremoveID
  790.      */
  791.     public int getBankXremoveID() {
  792.         return bankXremoveID;
  793.     }
  794.  
  795.     /**
  796.      * @return the playerBankSize
  797.      */
  798.     public int getPlayerBankSize() {
  799.         return playerBankSize;
  800.     }
  801.  
  802.     /**
  803.      * @param playerBankSize
  804.      *            the playerBankSize to set
  805.      */
  806.     public void setPlayerBankSize(int playerBankSize) {
  807.         this.playerBankSize = playerBankSize;
  808.     }
  809.     public void appendPlayerAppearance(Stream str) {
  810.         playerProps.currentOffset = 0;
  811.         playerProps.writeByte(playerLook[PlayerConstants.SEX]);
  812.         playerProps.writeByte(headIcon);
  813.         playerProps.writeByte(skullIcon);
  814.         playerProps.writeByte(modHeadIcon);
  815.         //playerProps.writeByte(hintIcon);
  816.        
  817.         if (!isNPC && playerEquipment[PlayerConstants.RING] != 6583 || getTarget() != null) {
  818.             if (playerEquipment[PlayerConstants.HELM] > 1) {
  819.                 playerProps
  820.                         .writeWord(0x200 + playerEquipment[PlayerConstants.HELM]);
  821.             } else {
  822.                 playerProps.writeByte(0);
  823.             }
  824.             if (playerEquipment[PlayerConstants.CAPE] > 1) {
  825.                 playerProps
  826.                         .writeWord(0x200 + playerEquipment[PlayerConstants.CAPE]);
  827.             } else {
  828.                 playerProps.writeByte(0);
  829.             }
  830.             if (playerEquipment[PlayerConstants.AMULET] > 1) {
  831.                 playerProps
  832.                         .writeWord(0x200 + playerEquipment[PlayerConstants.AMULET]);
  833.             } else {
  834.                 playerProps.writeByte(0);
  835.             }
  836.             if (playerEquipment[PlayerConstants.WEAPON] > 1) {
  837.                 playerProps
  838.                         .writeWord(0x200 + playerEquipment[PlayerConstants.WEAPON]);
  839.             } else {
  840.                 playerProps.writeByte(0);
  841.             }
  842.             if (playerEquipment[PlayerConstants.CHEST] > 1) {
  843.                 playerProps
  844.                         .writeWord(0x200 + playerEquipment[PlayerConstants.CHEST]);
  845.             } else {
  846.                 playerProps.writeWord(0x100 + playerLook[PlayerConstants.BODY]);
  847.             }
  848.             if (playerEquipment[PlayerConstants.SHIELD] > 1) {
  849.                 playerProps
  850.                         .writeWord(0x200 + playerEquipment[PlayerConstants.SHIELD]);
  851.             } else {
  852.                 playerProps.writeByte(0);
  853.             }
  854.             if (!Item.isPlate(playerEquipment[PlayerConstants.CHEST])) {
  855.                 playerProps.writeWord(0x100 + playerLook[PlayerConstants.ARMS]);
  856.             } else {
  857.                 playerProps.writeByte(0);
  858.             }
  859.             if (playerEquipment[PlayerConstants.BOTTOMS] > 1) {
  860.                 playerProps
  861.                         .writeWord(0x200 + playerEquipment[PlayerConstants.BOTTOMS]);
  862.             } else {
  863.                 playerProps.writeWord(0x100 + playerLook[PlayerConstants.LEGS]);
  864.             }
  865.             if (!Item.isFullHelm(playerEquipment[PlayerConstants.HELM])
  866.                     && !Item.isFullMask(playerEquipment[PlayerConstants.HELM])) {
  867.                 playerProps.writeWord(0x100 + playerLook[PlayerConstants.HEAD]);
  868.             } else {
  869.                 playerProps.writeByte(0);
  870.             }
  871.             if (playerEquipment[PlayerConstants.GLOVES] > 1) {
  872.                 playerProps
  873.                         .writeWord(0x200 + playerEquipment[PlayerConstants.GLOVES]);
  874.             } else {
  875.                 playerProps
  876.                         .writeWord(0x100 + playerLook[PlayerConstants.HANDS]);
  877.             }
  878.             if (playerEquipment[PlayerConstants.BOOTS] > 1) {
  879.                 playerProps
  880.                         .writeWord(0x200 + playerEquipment[PlayerConstants.BOOTS]);
  881.             } else {
  882.                 playerProps.writeWord(0x100 + playerLook[PlayerConstants.FEET]);
  883.             }
  884.             if (!Item.isFullMask(playerEquipment[PlayerConstants.HELM])
  885.                     && (playerLook[PlayerConstants.SEX] != 1)) {
  886.                 playerProps
  887.                         .writeWord(0x100 + playerLook[PlayerConstants.BEARD]);
  888.             } else {
  889.                 playerProps.writeByte(0);
  890.             }
  891.         } else {
  892.             if (playerEquipment[PlayerConstants.RING] == 6583 && getTarget() == null) {
  893.                 npcID = 2626;
  894.             } else if  (npcID == 2626 && playerEquipment[PlayerConstants.RING] != 6583) {
  895.                 npcID = -1;
  896.             }
  897.             playerProps.writeWord(-1);
  898.             playerProps.writeWord(npcID);
  899.         }
  900.  
  901.         playerProps.writeByte(playerLook[PlayerConstants.HAIR_COLOUR]);
  902.         playerProps.writeByte(playerLook[PlayerConstants.BODY_COLOUR]);
  903.         playerProps.writeByte(playerLook[PlayerConstants.LEG_COLOUR]);
  904.         playerProps.writeByte(playerLook[PlayerConstants.FEET_COLOUR]);
  905.         playerProps.writeByte(playerLook[PlayerConstants.SKIN_COLOUR]);
  906.         playerProps.writeWord(standEmote);
  907.         playerProps.writeWord(0x337);
  908.         playerProps.writeWord(walkEmote);
  909.         playerProps.writeWord(0x334);
  910.         playerProps.writeWord(0x335);
  911.         playerProps.writeWord(0x336);
  912.         playerProps.writeWord(runEmote);
  913.         playerProps.writeQWord(Misc.playerNameToInt64(getUsername()));
  914.         int combatLevel = getCombatLevel();
  915.         playerProps.writeByte(combatLevel);
  916.         playerProps.writeWord(0);
  917.         str.writeByteC(playerProps.currentOffset);
  918.         str.writeBytes(playerProps.buffer, playerProps.currentOffset, 0);
  919.     }
  920.  
  921.     public int combatLevel = 3;
  922.  
  923.     public int getCombatLevel() {
  924.  
  925.         final int attack = getLevelForXP(playerXP[0]);
  926.         final int defence = getLevelForXP(playerXP[1]);
  927.         final int strength = getLevelForXP(playerXP[2]);
  928.         final int hp = getLevelForXP(playerXP[3]);
  929.         final int prayer = getLevelForXP(playerXP[5]);
  930.         final int ranged = getLevelForXP(playerXP[4]);
  931.         final int magic = getLevelForXP(playerXP[6]);
  932.         int combatLevel = 3;   
  933.         combatLevel = (int) ((defence + hp + Math.floor(prayer / 2)) * 0.2535) + 1;
  934.         final double melee = (attack + strength) * 0.325;
  935.         final double ranger = Math.floor(ranged * 1.5) * 0.325;
  936.         final double mage = Math.floor(magic * 1.5) * 0.325;
  937.         if (melee >= ranger && melee >= mage) {
  938.             combatLevel += melee;
  939.         } else if (ranger >= melee && ranger >= mage) {
  940.             combatLevel += ranger;
  941.         } else if (mage >= melee && mage >= ranger) {
  942.             combatLevel += mage;
  943.         }
  944.         if(combatLevel <= 126) {
  945.             return combatLevel;
  946.         } else {
  947.             return 126;
  948.         }
  949.     }
  950.  
  951.  
  952.     public boolean appearanceUpdateRequired = true;
  953.     public boolean updateRequired = true;
  954.  
  955.     public byte chatText[] = new byte[4096];
  956.     public byte chatTextSize = 0;
  957.     public int chatTextEffects = 0;
  958.     public int chatTextColor = 0;
  959.     public boolean chatTextUpdateRequired = false;
  960.  
  961.     public void appendplayerChatOptionsText(Stream str) {
  962.         str.writeWordBigEndian(((chatTextColor & 0xFF) << 8)
  963.                 + (chatTextEffects & 0xFF));
  964.         str.writeByte(getPrivileges());
  965.         str.writeByteC(chatTextSize);
  966.         str.writeBytes_reverse(chatText, chatTextSize, 0);
  967.     }
  968.  
  969.     public int gfxID = 0;
  970.     public int gfxDelay = 0;
  971.     public boolean graphicsUpdateRequired = false;
  972.  
  973.     public void appendGraphicsUpdate(Stream str) {
  974.         str.writeWordBigEndian(gfxID);
  975.         str.writeDWord(gfxDelay);
  976.     }
  977.  
  978.     public int animationRequest = -1, animationWaitCycles = 0;
  979.     protected boolean animationUpdateRequired = false;
  980.  
  981.     public void appendAnimationRequest(Stream str) {
  982.         str.writeWordBigEndian((animationRequest == -1) ? 65535
  983.                 : animationRequest);
  984.         str.writeByte(animationWaitCycles);
  985.     }
  986.  
  987.     public String forcedText = "";
  988.     public boolean forcedTextUpdateRequired = false;
  989.  
  990.     public void appendForcedText(Stream str) {
  991.         str.writeString(forcedText);
  992.     }
  993.  
  994.     public int turnPlayerTo = -1;
  995.     public boolean turnPlayerToUpdateRequired = false;
  996.  
  997.     public void appendTurnPlayerToUpdate(Stream str) {
  998.         str.writeWordBigEndian(turnPlayerTo);
  999.     }
  1000.  
  1001.     public void resetFaceDirection() {
  1002.         turnPlayerTo = 65535;
  1003.         updateRequired = true;
  1004.         turnPlayerToUpdateRequired = true;
  1005.     }
  1006.  
  1007.     public int viewToX = -1;
  1008.     public int viewToY = -1;
  1009.  
  1010.     public boolean faceUpdateRequired = false;
  1011.  
  1012.     public void appendFaceUpdate(Stream str) {
  1013.         str.writeWordBigEndianA(viewToX);
  1014.         str.writeWordBigEndian(viewToY);
  1015.     }
  1016.  
  1017.     public int hitpoints = 10;
  1018.     public boolean dead = false;
  1019.  
  1020.     public boolean isDead() {
  1021.         return dead;
  1022.     }
  1023.  
  1024.     public void setDead(boolean dead) {
  1025.         this.dead = dead;
  1026.     }
  1027.    
  1028.     public Damage damage;
  1029.  
  1030.     public int hitDiff = 0;
  1031.     int hitType1 = 0;
  1032.     public boolean hitUpdateRequired = false;
  1033.     public void hits() {
  1034.     if (hitDiff > 0 && hitDiff < 10) {
  1035.     if(damage.getAttacker().getCombatType() == CombatType.DRAGONBREATH) {
  1036.         hitType1 = 13;
  1037.     } else {
  1038.         hitType1 = 1;  
  1039.         }
  1040.     } else if(hitDiff > 9 && hitDiff < 100) {
  1041.         if(damage.getAttacker().getCombatType() == CombatType.DRAGONBREATH) {
  1042.         hitType1 = 14;
  1043.     } else {
  1044.         hitType1 = 5;
  1045.         }
  1046.     } else if(hitDiff <= 0) {
  1047.         if (damage.getAttacker().getCombatType() == CombatType.DRAGONBREATH) {
  1048.         hitType1 = 12;
  1049.     } else {
  1050.         hitType1 = 0;
  1051.         }
  1052.     }
  1053. }
  1054.  
  1055.     protected void appendHitUpdate(Stream str) {
  1056.         if (hitpoints < 0) {
  1057.             hitpoints = 0;
  1058.         }
  1059.         str.writeByte(hitDiff);
  1060.         str.writeByteC(hitpoints);
  1061.         str.writeByteA(hitType1);
  1062.         str.writeByte(getLevelForXP(playerXP[3]));
  1063.         if (hitpoints <= 0) {
  1064.             setDead(true);
  1065.             hitpoints = 0;
  1066.             }
  1067.         }
  1068.  
  1069.     public int hitDiff2 = 0, hitType2 = 0;
  1070.     public boolean hitUpdateRequired2 = false; 
  1071.     public void hits2() {
  1072.         if (hitDiff2 > 0 && hitDiff2 < 10) {
  1073.         if(damage.getAttacker().getCombatType() == CombatType.DRAGONBREATH) {
  1074.             hitType2 = 13;
  1075.         } else {
  1076.             hitType2 = 1;  
  1077.             }
  1078.         } else if(hitDiff2 > 9 && hitDiff2 < 100) {
  1079.             if(damage.getAttacker().getCombatType() == CombatType.DRAGONBREATH) {
  1080.             hitType2 = 14;
  1081.         } else {
  1082.             hitType2 = 5;
  1083.             }
  1084.         } else if(hitDiff2 <= 0) {
  1085.             if (damage.getAttacker().getCombatType() == CombatType.DRAGONBREATH) {
  1086.             hitType2 = 12;
  1087.         } else {
  1088.             hitType2 = 0;
  1089.             }
  1090.         }
  1091.     }
  1092.  
  1093.     public void appendHitUpdate2(Stream str) {
  1094.         if (hitpoints < 0) {
  1095.             hitpoints = 0;
  1096.         }
  1097.         str.writeByte(hitDiff2);
  1098.         if (!poisonHit) {
  1099.             str.writeByteS(hitType2);
  1100.         } else {
  1101.             str.writeByteS(2);
  1102.         }
  1103.         str.writeByte(hitpoints);
  1104.         str.writeByteC(getLevelForXP(playerXP[3]));
  1105.         if (hitpoints <= 0) {
  1106.             setDead(true);
  1107.             hitpoints = 0;
  1108.         }
  1109.     }
  1110.  
  1111.     public void appendPlayerUpdateBlock(Stream str) {
  1112.         if (!updateRequired && !chatTextUpdateRequired)
  1113.             return;
  1114.         int updateMask = 0;
  1115.  
  1116.         if (graphicsUpdateRequired)
  1117.             updateMask |= 0x100;   
  1118.         if (animationRequest != -1)
  1119.             updateMask |= 8;
  1120.         if (forcedTextUpdateRequired)
  1121.             updateMask |= 4;
  1122.         if (chatTextUpdateRequired)
  1123.             updateMask |= 0x80;
  1124.         if (turnPlayerToUpdateRequired)
  1125.             updateMask |= 1;
  1126.         if (appearanceUpdateRequired)
  1127.             updateMask |= 0x10;
  1128.         if (faceUpdateRequired)
  1129.             updateMask |= 2;
  1130.         if (hitUpdateRequired)
  1131.             updateMask |= 0x20;
  1132.         if (hitUpdateRequired2)
  1133.             updateMask |= 0x200;
  1134.  
  1135.         if (updateMask >= 0x100) {
  1136.             updateMask |= 0x40;
  1137.             str.writeByte(updateMask & 0xFF);
  1138.             str.writeByte(updateMask >> 8);
  1139.         } else {
  1140.             str.writeByte(updateMask);
  1141.         }
  1142.         if (graphicsUpdateRequired)
  1143.             appendGraphicsUpdate(str);
  1144.         if (animationRequest != -1)
  1145.             appendAnimationRequest(str);
  1146.         if (forcedTextUpdateRequired)
  1147.             appendForcedText(str);
  1148.         if (chatTextUpdateRequired)
  1149.             appendplayerChatOptionsText(str);
  1150.         if (turnPlayerToUpdateRequired)
  1151.             appendTurnPlayerToUpdate(str);
  1152.         if (appearanceUpdateRequired)
  1153.             appendPlayerAppearance(str);
  1154.         if (faceUpdateRequired)
  1155.             appendFaceUpdate(str);
  1156.         if (hitUpdateRequired)
  1157.             appendHitUpdate(str);
  1158.         if (hitUpdateRequired2)
  1159.             appendHitUpdate2(str);
  1160.     }
  1161.  
  1162.     public void clearUpdateFlags() {
  1163.         updateRequired = false;
  1164.         graphicsUpdateRequired = false;
  1165.         animationRequest = -1;
  1166.         forcedText = null;
  1167.         forcedTextUpdateRequired = false;
  1168.         chatTextUpdateRequired = false;
  1169.         turnPlayerTo = 65535;
  1170.         turnPlayerToUpdateRequired = false;
  1171.         appearanceUpdateRequired = false;
  1172.         faceUpdateRequired = false;
  1173.         hitUpdateRequired = false;
  1174.         hitUpdateRequired2 = false;
  1175.         poisonHit = false;
  1176.     }
  1177.  
  1178.     public int walkingQueueX[] = new int[PlayerConstants.WALKING_QUEUE_SIZE],
  1179.             walkingQueueY[] = new int[PlayerConstants.WALKING_QUEUE_SIZE];
  1180.  
  1181.     public int directionCount = 0;
  1182.     public int dir1 = -1, dir2 = -1;
  1183.     public int currentX, currentY = 0;
  1184.     public int mapRegionX, mapRegionY = 0;
  1185.     public int wQueueReadPtr = 0;
  1186.     public int wQueueWritePtr = 0;
  1187.  
  1188.     public int energy = 100;
  1189.  
  1190.     /**
  1191.      * @return the energy
  1192.      */
  1193.     public int getEnergy() {
  1194.         return energy;
  1195.     }
  1196.  
  1197.     public boolean didTeleport = false;
  1198.     public boolean isRunning = false;
  1199.     public boolean isRunning2 = false;
  1200.     public boolean mapRegionDidChange = false;
  1201.  
  1202.     public boolean wi1ldArea() {
  1203.         return getAbsX() >= 2940 && getAbsX() <= 3395 && getAbsY() >= 3520
  1204.                 && getAbsY() <= 4000;
  1205.     }
  1206.  
  1207.     public void setRunning(boolean b) {
  1208.         isRunning = b;
  1209.         isRunning2 = b;
  1210.     }
  1211.  
  1212.     public int teleportToX = -1, teleportToY = -1, teleportToZ = -1;
  1213.  
  1214.     public int newWalkCmdX[] = new int[PlayerConstants.WALKING_QUEUE_SIZE];
  1215.     public int newWalkCmdY[] = new int[PlayerConstants.WALKING_QUEUE_SIZE];
  1216.  
  1217.     public int newWalkCmdSteps = 0;
  1218.     public boolean newWalkCmdIsRunning = false;
  1219.     public int travelBackX[] = new int[PlayerConstants.WALKING_QUEUE_SIZE];
  1220.     public int travelBackY[] = new int[PlayerConstants.WALKING_QUEUE_SIZE];
  1221.     public int numTravelBackSteps = 0;
  1222.  
  1223.     public void resetWalkingQueue() {
  1224.         wQueueReadPtr = wQueueWritePtr = 0;
  1225.         for (int i = 0; i < PlayerConstants.WALKING_QUEUE_SIZE; i++) {
  1226.             walkingQueueX[i] = currentX;
  1227.             walkingQueueY[i] = currentY;
  1228.         }
  1229.     }
  1230.  
  1231.     public void addToWalkingQueue(int x, int y) {
  1232.         int next = (wQueueWritePtr + 1) % PlayerConstants.WALKING_QUEUE_SIZE;
  1233.         if (next == wQueueWritePtr) {
  1234.             return;
  1235.         }
  1236.         walkingQueueX[wQueueWritePtr] = x;
  1237.         walkingQueueY[wQueueWritePtr] = y;
  1238.         wQueueWritePtr = next;
  1239.     }
  1240.  
  1241.     protected boolean zoneRequired = true;
  1242.  
  1243.     public int getNextWalkingDirection() {
  1244.        
  1245.         if (wQueueReadPtr == wQueueWritePtr)
  1246.             return -1;
  1247.         int dir;
  1248.         do {
  1249.             dir = Misc.direction(currentX, currentY,
  1250.                     walkingQueueX[wQueueReadPtr], walkingQueueY[wQueueReadPtr]);
  1251.             if (dir == -1)
  1252.                 wQueueReadPtr = (wQueueReadPtr + 1)
  1253.                         % PlayerConstants.WALKING_QUEUE_SIZE;
  1254.             else if ((dir & 1) != 0) {
  1255.                 println_debug("Invalid waypoint in walking queue!");
  1256.                 resetWalkingQueue();
  1257.                 return -1;
  1258.             }
  1259.         } while (dir == -1 && wQueueReadPtr != wQueueWritePtr);
  1260.         if (dir == -1)
  1261.             return -1;
  1262.        
  1263.        
  1264.         dir >>= 1;
  1265.         currentX += Misc.directionDeltaX[dir];
  1266.         currentY += Misc.directionDeltaY[dir];
  1267.         setAbsX(getAbsX() + Misc.directionDeltaX[dir]);
  1268.         setAbsY(getAbsY() + Misc.directionDeltaY[dir]);
  1269.         return dir;
  1270.     }
  1271.    
  1272.    
  1273.     public void stopMovement() {
  1274.         if (teleportToX <= 0 && teleportToY <= 0) {
  1275.             teleportToX = getAbsX();
  1276.             teleportToY = getAbsY();
  1277.         }
  1278.         newWalkCmdSteps = 0;
  1279.         newWalkCmdX[0] = newWalkCmdY[0] = travelBackX[0] = travelBackY[0] = 0;
  1280.         getNextPlayerMovement();
  1281.     }
  1282.  
  1283.     public void updatePlayerMovement(Stream str) {
  1284.         if (dir1 == -1) {
  1285.             if (updateRequired || chatTextUpdateRequired) {
  1286.                 str.writeBits(1, 1);
  1287.                 str.writeBits(2, 0);
  1288.             } else
  1289.                 str.writeBits(1, 0);
  1290.         } else if (dir2 == -1) {
  1291.             str.writeBits(1, 1);
  1292.             str.writeBits(2, 1);
  1293.             str.writeBits(3, Misc.xlateDirectionToClient[dir1]);
  1294.             str.writeBits(1, (updateRequired || chatTextUpdateRequired) ? 1 : 0);
  1295.         } else {
  1296.             str.writeBits(1, 1);
  1297.             str.writeBits(2, 2);
  1298.             str.writeBits(3, Misc.xlateDirectionToClient[dir1]);
  1299.             str.writeBits(3, Misc.xlateDirectionToClient[dir2]);
  1300.             str.writeBits(1, (updateRequired || chatTextUpdateRequired) ? 1 : 0);
  1301.         }
  1302.     }
  1303.    
  1304.     public Client getFollowPlayer() {
  1305.         return followPlayer;
  1306.     }
  1307.     public Client setFollowPlayer(Client follow) {
  1308.         return this.followPlayer = follow;
  1309.     }
  1310.     public void getNextPlayerMovement() {
  1311.        
  1312.  
  1313.         mapRegionDidChange = false;
  1314.         boolean heightLevelDidChange = false;
  1315.         didTeleport = false;
  1316.         dir1 = dir2 = -1;
  1317.  
  1318.         if (teleportToZ != -1) {
  1319.             setHeightLevel(teleportToZ);
  1320.             teleportToZ = -1;
  1321.             if (teleportToX == -1) {
  1322.                 teleportToX = getAbsX();
  1323.             }
  1324.             if (teleportToY == -1) {
  1325.                 teleportToY = getAbsY();
  1326.             }
  1327.             heightLevelDidChange = true;
  1328.         }
  1329.         if (teleportToX != -1 && teleportToY != -1) {
  1330.             mapRegionDidChange = true;
  1331.             if (mapRegionX != -1 && mapRegionY != -1) {
  1332.                 int relX = teleportToX - mapRegionX * 8, relY = teleportToY
  1333.                         - mapRegionY * 8;
  1334.                 if (relX >= 2 * 8 && relX < 11 * 8 && relY >= 2 * 8
  1335.                         && relY < 11 * 8)
  1336.                     mapRegionDidChange = false;
  1337.             }
  1338.             if (mapRegionDidChange) {
  1339.                 mapRegionX = (teleportToX >> 3) - 6;
  1340.                 mapRegionY = (teleportToY >> 3) - 6;
  1341.  
  1342.             }
  1343.            
  1344.             currentX = teleportToX - 8 * mapRegionX;
  1345.             currentY = teleportToY - 8 * mapRegionY;
  1346.             setAbsX(teleportToX);
  1347.             setAbsY(teleportToY);
  1348.             resetWalkingQueue();
  1349.            
  1350.             teleportToX = teleportToY = -1;
  1351.             didTeleport = true;
  1352.  
  1353.         } else  {
  1354.             if (((Client)this).getFreezeDelay() > 0) {
  1355.                 return;
  1356.             }
  1357.             if (following != null){
  1358.                 if (followPlayerIdle) {
  1359.                     followPlayerIdle = false;
  1360.                     return;
  1361.                 }
  1362.                 if (pauseFollow || JailSystem.inJail((Client)this))
  1363.                     return;
  1364.                
  1365.                 dir1 = FollowEngine.getNextFollowingDirection((Client) this, following);
  1366.                
  1367.                 if (dir1 == -1) {
  1368.                     followPlayerIdle = true;
  1369.                 }
  1370.             } else   
  1371.            
  1372.                 dir1 = getNextWalkingDirection();
  1373.        
  1374.             if (forceMove) //overwrite old walking path.
  1375.                 dir1 = ForceWalker.getForceMovement((Client)this, forceMovement);
  1376.            
  1377.             if (dir1 == -1 || JailSystem.inJail((Client)this))
  1378.                 return;
  1379.  
  1380.             if (isRunning && following != null)
  1381.             {
  1382.                 if(following != null)
  1383.                     dir2 = FollowEngine.getNextFollowingDirection((Client) this, following);
  1384.                 else
  1385.                     dir2 = getNextWalkingDirection();
  1386.                
  1387.  
  1388.             } else if (isRunning) {
  1389.                 dir2 = getNextWalkingDirection();
  1390.             } else {
  1391.                 setRunning(false);
  1392.             }  
  1393.             int deltaX = 0, deltaY = 0;
  1394.             if (currentX < 2 * 8) {
  1395.                 deltaX = 4 * 8;
  1396.                 mapRegionX -= 4;
  1397.                 mapRegionDidChange = true;
  1398.             } else if (currentX >= 11 * 8) {
  1399.                 deltaX = -4 * 8;
  1400.                 mapRegionX += 4;
  1401.                 mapRegionDidChange = true;
  1402.             }
  1403.             if (currentY < 2 * 8) {
  1404.                 deltaY = 4 * 8;
  1405.                 mapRegionY -= 4;
  1406.                 mapRegionDidChange = true;
  1407.             } else if (currentY >= 11 * 8) {
  1408.                 deltaY = -4 * 8;
  1409.                 mapRegionY += 4;
  1410.                 mapRegionDidChange = true;
  1411.             }
  1412.  
  1413.             if (mapRegionDidChange) {
  1414.                 currentX += deltaX;
  1415.                 currentY += deltaY;
  1416.                 for (int i = 0; i < PlayerConstants.WALKING_QUEUE_SIZE; i++) {
  1417.                     walkingQueueX[i] += deltaX;
  1418.                     walkingQueueY[i] += deltaY;
  1419.                 }
  1420.             }
  1421.         }
  1422.         if (mapRegionDidChange || heightLevelDidChange) {
  1423.             zoneRequired = true;
  1424.         }
  1425.     }
  1426.     public boolean pauseFollow = false, followPlayerIdle = false;
  1427.     public Client followPlayer = null;
  1428.  
  1429.     public void updateThisPlayerMovement(Stream str) {
  1430.         if (mapRegionDidChange) {
  1431.             str.createFrame(73);
  1432.             str.writeWordA(mapRegionX + 6);
  1433.             str.writeWord(mapRegionY + 6);
  1434.         }
  1435.         if (didTeleport) {
  1436.             str.createFrameVarSizeWord(81);
  1437.             str.initBitAccess();
  1438.             str.writeBits(1, 1);
  1439.             str.writeBits(2, 3);
  1440.             str.writeBits(2, getHeightLevel());
  1441.             str.writeBits(1, 1);
  1442.             str.writeBits(1, (updateRequired) ? 1 : 0);
  1443.             str.writeBits(7, currentY);
  1444.             str.writeBits(7, currentX);
  1445.             return;
  1446.         }
  1447.         if (dir1 == -1) {
  1448.             str.createFrameVarSizeWord(81);
  1449.             str.initBitAccess();
  1450.             if (updateRequired) {
  1451.                 str.writeBits(1, 1);
  1452.                 str.writeBits(2, 0);
  1453.             } else {
  1454.                 str.writeBits(1, 0);
  1455.             }
  1456.             if (directionCount < PlayerConstants.WALKING_QUEUE_SIZE) {
  1457.                 directionCount++;
  1458.             }
  1459.         } else {
  1460.             directionCount = 0;
  1461.             str.createFrameVarSizeWord(81);
  1462.             str.initBitAccess();
  1463.             str.writeBits(1, 1);
  1464.  
  1465.             if (dir2 == -1) {
  1466.                 str.writeBits(2, 1);
  1467.                 str.writeBits(3, Misc.xlateDirectionToClient[dir1]);
  1468.                 if (updateRequired) {
  1469.                     str.writeBits(1, 1);
  1470.                 } else {
  1471.                     str.writeBits(1, 0);
  1472.                 }
  1473.             } else {
  1474.                 str.writeBits(2, 2);
  1475.                 str.writeBits(3, Misc.xlateDirectionToClient[dir1]);
  1476.                 str.writeBits(3, Misc.xlateDirectionToClient[dir2]);
  1477.                 if (updateRequired) {
  1478.                     str.writeBits(1, 1);
  1479.                 } else {
  1480.                     str.writeBits(1, 0);
  1481.                 }
  1482.             }
  1483.         }
  1484.     }
  1485.  
  1486.     public void updateEnergy() {
  1487.         Client client = (Client) this;
  1488.         client.getActionSender().sendQuest(energy + "%", 149);
  1489.     }
  1490.  
  1491.     public void postProcessing() {
  1492.         if (newWalkCmdSteps > 0) {
  1493.             int firstX = newWalkCmdX[0], firstY = newWalkCmdY[0];
  1494.             int lastDir = 0;
  1495.             boolean found = false;
  1496.             numTravelBackSteps = 0;
  1497.             int ptr = wQueueReadPtr;
  1498.             int dir = Misc.direction(currentX, currentY, firstX, firstY);
  1499.             if (dir != -1 && (dir & 1) != 0) {
  1500.  
  1501.                 do {
  1502.                     lastDir = dir;
  1503.                     if (--ptr < 0)
  1504.                         ptr = PlayerConstants.WALKING_QUEUE_SIZE - 1;
  1505.                    
  1506.                     travelBackX[numTravelBackSteps] = walkingQueueX[ptr];
  1507.                     travelBackY[numTravelBackSteps++] = walkingQueueY[ptr];
  1508.                    
  1509.                     dir = Misc.direction(walkingQueueX[ptr],
  1510.                             walkingQueueY[ptr], firstX, firstY);
  1511.                     if (lastDir != dir) {
  1512.                         found = true;
  1513.                         break;
  1514.                     }
  1515.  
  1516.                 } while (ptr != wQueueWritePtr);
  1517.             } else
  1518.                 found = true;
  1519.  
  1520.             if (!found)
  1521.                 println_debug("Fatal: couldn't find connection vertex! Dropping packet.");
  1522.             else {
  1523.                 wQueueWritePtr = wQueueReadPtr;
  1524.  
  1525.                 addToWalkingQueue(currentX, currentY);
  1526.  
  1527.                 if (dir != -1 && (dir & 1) != 0) {
  1528.  
  1529.                     for (int i = 0; i < numTravelBackSteps - 1; i++) {
  1530.                         addToWalkingQueue(travelBackX[i], travelBackY[i]);
  1531.                     }
  1532.                     int wayPointX2 = travelBackX[numTravelBackSteps - 1], wayPointY2 = travelBackY[numTravelBackSteps - 1];
  1533.                     int wayPointX1, wayPointY1;
  1534.                     if (numTravelBackSteps == 1) {
  1535.                         wayPointX1 = currentX;
  1536.                         wayPointY1 = currentY;
  1537.                     } else {
  1538.                         wayPointX1 = travelBackX[numTravelBackSteps - 2];
  1539.                         wayPointY1 = travelBackY[numTravelBackSteps - 2];
  1540.                     }
  1541.  
  1542.                     dir = Misc.direction(wayPointX1, wayPointY1, wayPointX2,
  1543.                             wayPointY2);
  1544.                     if (dir == -1 || (dir & 1) != 0) {
  1545.                         println_debug("Fatal: The walking queue is corrupt! wp1=("
  1546.                                 + wayPointX1
  1547.                                 + ", "
  1548.                                 + wayPointY1
  1549.                                 + "), "
  1550.                                 + "wp2=("
  1551.                                 + wayPointX2
  1552.                                 + ", "
  1553.                                 + wayPointY2
  1554.                                 + ")");
  1555.                     } else {
  1556.                         dir >>= 1;
  1557.                         found = false;
  1558.                         int x = wayPointX1, y = wayPointY1;
  1559.                         perviousStepX = currentX;
  1560.                         perviousStepY = currentY;
  1561.                         while (x != wayPointX2 || y != wayPointY2) {
  1562.                             x += Misc.directionDeltaX[dir];
  1563.                             y += Misc.directionDeltaY[dir];
  1564.                             if ((Misc.direction(x, y, firstX, firstY) & 1) == 0) {
  1565.                                 found = true;
  1566.                                 break;
  1567.                             }
  1568.                         }
  1569.                         if (!found) {
  1570.                             println_debug("Fatal: Internal error: unable to determine connection vertex!"
  1571.                                     + "  wp1=("
  1572.                                     + wayPointX1
  1573.                                     + ", "
  1574.                                     + wayPointY1
  1575.                                     + "), wp2=("
  1576.                                     + wayPointX2
  1577.                                     + ", "
  1578.                                     + wayPointY2
  1579.                                     + "), "
  1580.                                     + "first=("
  1581.                                     + firstX + ", " + firstY + ")");
  1582.                         } else
  1583.                             addToWalkingQueue(wayPointX1, wayPointY1);
  1584.                     }
  1585.                 } else {
  1586.                     for (int i = 0; i < numTravelBackSteps; i++) {
  1587.                         addToWalkingQueue(travelBackX[i], travelBackY[i]);
  1588.                     }
  1589.                 }
  1590.  
  1591.                 for (int i = 0; i < newWalkCmdSteps; i++) {
  1592.                     addToWalkingQueue(newWalkCmdX[i], newWalkCmdY[i]);
  1593.                 }
  1594.  
  1595.             }
  1596.             isRunning = newWalkCmdIsRunning || isRunning2;
  1597.         }
  1598.         preProcessing();
  1599.     }
  1600.     public int perviousStepX = 0, perviousStepY = 0;
  1601.     public void preProcessing() {
  1602.         newWalkCmdSteps = 0;
  1603.     }
  1604.  
  1605.     public Player playerList[] = new Player[Constants.MAX_PLAYERS];
  1606.     public int playerListSize = 0;
  1607.     public byte playerInListBitmap[] = new byte[(Constants.MAX_PLAYERS + 7) >> 3];
  1608.  
  1609.     public void addNewPlayer(Player plr, Stream str, Stream updateBlock) {
  1610.         int id = plr.getUserID();
  1611.         playerInListBitmap[id >> 3] |= 1 << (id & 7);
  1612.         playerList[playerListSize++] = plr;
  1613.  
  1614.         str.writeBits(11, id);
  1615.  
  1616.         str.writeBits(1, 1);
  1617.         boolean savedFlag = plr.appearanceUpdateRequired;
  1618.         boolean savedUpdateRequired = plr.updateRequired;
  1619.         plr.appearanceUpdateRequired = true;
  1620.         plr.updateRequired = true;
  1621.         plr.appendPlayerUpdateBlock(updateBlock);
  1622.         plr.appearanceUpdateRequired = savedFlag;
  1623.         plr.updateRequired = savedUpdateRequired;
  1624.  
  1625.         str.writeBits(1, 1);
  1626.  
  1627.         int z = plr.getAbsY() - getAbsY();
  1628.         if (z < 0)
  1629.             z += 32;
  1630.         str.writeBits(5, z);
  1631.         z = plr.getAbsX() - getAbsX();
  1632.         if (z < 0)
  1633.             z += 32;
  1634.         str.writeBits(5, z);
  1635.     }
  1636.  
  1637.     public boolean withinDistance(int targetX, int targetY, int distance) {
  1638.         for (int i = 0; i <= distance; i++) {
  1639.             for (int j = 0; j <= distance; j++) {
  1640.                 if ((targetX + i) == getAbsX()
  1641.                         && ((targetY + j) == getAbsY()
  1642.                                 || (targetY - j) == getAbsY() || targetY == getAbsY())) {
  1643.                     return true;
  1644.                 } else if ((targetX - i) == getAbsX()
  1645.                         && ((targetY + j) == getAbsY()
  1646.                                 || (targetY - j) == getAbsY() || targetY == getAbsY())) {
  1647.                     return true;
  1648.                 } else if (targetX == getAbsX()
  1649.                         && ((targetY + j) == getAbsY()
  1650.                                 || (targetY - j) == getAbsY() || targetY == getAbsY())) {
  1651.                     return true;
  1652.                 }
  1653.             }
  1654.         }
  1655.         return false;
  1656.     }
  1657.  
  1658.     public boolean withinDistance(Player otherPlr) {
  1659.         if (getHeightLevel() != otherPlr.getHeightLevel()) {
  1660.             return false;
  1661.         }
  1662.         int deltaX = otherPlr.getAbsX() - getAbsX(), deltaY = otherPlr
  1663.                 .getAbsY()
  1664.                 - getAbsY();
  1665.         return deltaX <= 15 && deltaX >= -16 && deltaY <= 15 && deltaY >= -16;
  1666.     }
  1667.  
  1668.     public boolean withinInteractionDistance(Client otherClient) {
  1669.         return withinInteractionDistance(otherClient.getAbsX(), otherClient
  1670.                 .getAbsY(), otherClient.getHeightLevel());
  1671.     }
  1672.  
  1673.     public boolean withinInteractionDistance(int x, int y, int z) {
  1674.         if (getHeightLevel() != z)
  1675.             return false;
  1676.         int deltaX = x - getAbsX(), deltaY = y - getAbsY();
  1677.         return deltaX <= 2 && deltaX >= -2 && deltaY <= 2 && deltaY >= -2;
  1678.     }
  1679.  
  1680.     public boolean withinDistance(NPC npc) {
  1681.         if (getHeightLevel() != npc.getHeightLevel())
  1682.             return false;
  1683.         int deltaX = npc.getAbsX() - getAbsX(), deltaY = npc.getAbsY()
  1684.                 - getAbsY();
  1685.         return deltaX <= 15 && deltaX >= -16 && deltaY <= 15 && deltaY >= -16;
  1686.     }
  1687.  
  1688.     public static final int maxNPCListSize = NPCManager.MAXIMUM_NPCS;
  1689.     public NPC[] npcList = new NPC[maxNPCListSize];
  1690.     public int npcListSize = 0;
  1691.  
  1692.     public byte[] npcInListBitmap = new byte[(NPCManager.MAXIMUM_NPCS + 7) >> 3];
  1693.     public boolean rebuildNPCList = false;
  1694.  
  1695.     public void addNewNPC(NPC npc, Stream str, Stream updateBlock) {
  1696.  
  1697.         int slot = npc.getNpcId();
  1698.         npcInListBitmap[slot >> 3] |= 1 << (slot & 7);
  1699.         npcList[npcListSize++] = npc;
  1700.  
  1701.         str.writeBits(14, slot); //14
  1702.  
  1703.         int z = npc.getAbsY() - getAbsY();
  1704.         if (z < 0)
  1705.             z += 32;
  1706.         str.writeBits(5, z);
  1707.         z = npc.getAbsX() - getAbsX();
  1708.         if (z < 0)
  1709.             z += 32;
  1710.         str.writeBits(5, z);
  1711.  
  1712.         str.writeBits(1, 0);
  1713.         str.writeBits(14, npc.getDefinition().getType()); // 12
  1714.  
  1715.         boolean savedUpdateRequired = npc.isUpdateRequired();
  1716.         npc.setUpdateRequired(true);
  1717.         npc.appendNPCUpdateBlock(updateBlock);
  1718.         npc.setUpdateRequired(savedUpdateRequired);
  1719.         str.writeBits(1, 1);
  1720.     }
  1721.  
  1722.     public boolean isKicked = false;
  1723.  
  1724.     public void kick() {
  1725.         Client client = (Client) this;
  1726.         client.getActionSender().sendLogout();
  1727.         isKicked = true;
  1728.     }
  1729.     /**
  1730.      * Smithing
  1731.      */
  1732.    
  1733.     public int smithxp;
  1734.     public int smithremove;
  1735.     public int smithmaketimes, smithremoveamount, amountToMakeBars, smithitem;
  1736.     public boolean hasfailed2123;
  1737.    
  1738.     public int smeltBarId;
  1739.     public int[] smelt_bars = { 2349, 2351, 2355, 2353, 2357, 2359, 2361, 2363 };
  1740.     public int[] smelt_frame = { 2405, 2406, 2407, 2409, 2410, 2411, 2412, 2413 };
  1741.    
  1742.     public int itemToAdd, barID, toremove, barsRemoved, timestomake, NOTUSED, NOTUSED2, xp = 0;
  1743.    
  1744.     public int item = -1;
  1745.     public int remove = -1;
  1746.     public int remove2 = -1;
  1747.     public int removeam = -1;
  1748.     public int removeam2 = -1;
  1749.     /**
  1750.      * Fletching
  1751.      */
  1752.     public int amountLeft = 0;
  1753.     public int log2 = 0;
  1754.     public int unstrungBow = 0;
  1755.     public String length = "";
  1756.  
  1757.     /**
  1758.      * Fletching
  1759.      */
  1760.    
  1761.     public int[] LOGS = { 1511, 1521, 1519, 1517, 1515, 1513 };
  1762.     public int[] UNSTRUNG_BOWS = { 50, 48, 54, 56, 58, 60, 62, 64,66, 68, 70, 72 };
  1763.     public int[] STRUNG_BOWS = { 841, 839, 843, 845, 847, 849,851, 853, 855, 857, 859, 861 };
  1764.     public int[] FLETCHING_LEVELS = { 5, 10, 25, 20, 40, 35, 55,50, 70, 65, 85, 80 };
  1765.     public int[] EXPERIENCE = { 5, 10, 15, 20, 70, 50, 110, 90, 155, 135, 200, 175 };
  1766.     public int[] ARROWSX = { 882, 884, 886, 888, 890, 892 };
  1767.     public int[] ARROW_HEADS = { 39, 40, 41, 42, 43, 44 };
  1768.     public int[] ARROW_LEVELS = { 1, 15, 30, 45, 60, 75 };
  1769.     public int[] ARROW_EXPERIENCE = { 15, 20, 22, 25, 30, 40 };
  1770.     public int[] DARTS = { 806, 807, 808, 809, 810, 811 };
  1771.     public int[] DART_TIPS = { 819, 820, 821, 822, 823, 824 };
  1772.     public int[] DART_LEVELS = { 1, 22, 37, 52, 67, 81 };
  1773.     public int[] DART_EXPERIENCE = { 12, 14, 16, 18, 20, 25 };
  1774.     public int[] LEFT_ITEM = { 50, 54, 60, 64, 68, 72 };
  1775.     public int[] RIGHT_ITEM = { 48, 56, 58, 62, 66, 70 };
  1776.     public String[] LEFT_ITEM_NAME = { "Longbow(u)", "Oak Longbow(u)","Willow Longbow(u)", "Maple Longbow(u)", "Yew Longbow(u)","Magic Longbow(u)" };
  1777.     public String[] RIGHT_ITEM_NAME = { "Shortbow(u)","Oak Shortbow(u)", "Willow Shortbow(u)", "Maple Shortbow(u)","Yew Shortbow(u)", "Magic Shortbow(u)" };
  1778.     public int FLETCHING_DELAY = 4;
  1779.     /**
  1780.      * cooking
  1781.      */
  1782.    
  1783.     public int cooking;
  1784.     public int cookingAmount;
  1785.     public int cookingAnimation;
  1786.    
  1787.     /**
  1788.      * Fishing
  1789.      */
  1790.     public int fishing;
  1791.     public int fishingX;
  1792.     public int fishingY;
  1793.    
  1794.     public int destroyItem;
  1795.    
  1796.     public boolean slothSettings[] = new boolean[4];
  1797.  
  1798. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement