Advertisement
Guest User

Untitled

a guest
Aug 21st, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 120.48 KB | None | 0 0
  1.    
  2.  
  3.     package server.model.players;
  4.      
  5.     import java.util.ArrayList;
  6.      
  7.     import server.Config;
  8.     import server.model.items.Item;
  9.     import server.model.npcs.NPC;
  10.     import server.model.npcs.NPCHandler;
  11.     import server.util.ISAACRandomGen;
  12.     import server.util.Misc;
  13.     import server.util.Stream;
  14.     import server.world.Clan;
  15.      
  16.     import java.util.HashMap;
  17.     import java.util.Map;
  18.      
  19.     public abstract class Player {
  20.      
  21.             public boolean updateRequired = true;
  22.             public boolean appearanceUpdateRequired = true;
  23.             public boolean isNpc = false;
  24.             public int npcId2 = 0;
  25.             public int removedTasks[] = { -1, -1, -1, -1 };
  26.             public long buySlayerTimer;
  27.             public boolean needsNewTask = false;
  28.             public boolean isUsingSpecial;
  29.             public int slayerPoints = 0;
  30.             public int ag1, ag2, ag3, ag4, ag5, ag6;
  31.             public int Arma;
  32.             public int Sara;
  33.             public int Zammy;
  34.             public int Band;
  35.      
  36.             public ArrayList<String> killedPlayers = new ArrayList<String>();
  37.             public ArrayList<Integer> attackedPlayers = new ArrayList<Integer>();
  38.             public ArrayList<String> lastKilledPlayers = new ArrayList<String>();
  39.             public ArrayList<String> lastConnectedFrom = new ArrayList<String>();
  40.             public boolean isShopping = false;
  41.             public boolean isBanking = false;
  42.             public boolean inTrade = false;
  43.             public boolean openDuel = false;
  44.             public String UUID = "";
  45.             /*
  46.              * Earning Potential
  47.              */
  48.             public int earningPotential = 0;
  49.             public int epTimer = 0;
  50.            
  51.      
  52.             /**
  53.              * System to optimize sendFrame126 performance.
  54.              * @author MikeRSPS
  55.              * UltimateScape
  56.              * http://ultimatescape2.com
  57.              */
  58.             private Map<Integer, TinterfaceText> interfaceText = new HashMap<Integer, TinterfaceText>();
  59.            
  60.             public boolean playerIsBusy() {
  61.             if(isShopping || inTrade || openDuel || isBanking || duelStatus == 1)
  62.                 return true;
  63.             return false;
  64.         }
  65.             public class TinterfaceText {
  66.                     public int id;
  67.                     public String currentState;
  68.                    
  69.                     public TinterfaceText(String s, int id) {
  70.                             this.currentState = s;
  71.                             this.id = id;
  72.                     }
  73.                    
  74.             }
  75.      
  76.             public boolean checkPacket126Update(String text, int id) {
  77.                     if(!interfaceText.containsKey(id)) {
  78.                             interfaceText.put(id, new TinterfaceText(text, id));
  79.                     } else {
  80.                             TinterfaceText t = interfaceText.get(id);
  81.                             if(text.equals(t.currentState)) {
  82.                                     return false;
  83.                             }
  84.                             t.currentState = text;
  85.                     }
  86.                     return true;
  87.             }
  88.      
  89.             /**
  90.              * Clan Chat Variables
  91.              */
  92.             public Clan clan;
  93.             public String clanName, properName;
  94.             public String lastClanChat = "";
  95.            
  96.                     /**
  97.              * Title Variables
  98.              */
  99.             public String playerTitle = "";
  100.             public int titleColor = 0;
  101.             public int nameColor = 0;
  102.            
  103.             /**
  104.              * Event Variables
  105.              */
  106.             public boolean hasEvent;
  107.            
  108.             /**
  109.              * Achievement Variables
  110.              */
  111.             public int achievementsCompleted;
  112.             public int achievementPoints;
  113.             public int fireslit;
  114.             public int crabsKilled;
  115.             public int treesCut;
  116.      
  117.             public boolean expLock = false;
  118.             public boolean claimedReward = false;
  119.             public boolean buyingX;
  120.             public boolean leverClicked = false;
  121.             public double crossbowDamage;
  122.      
  123.             public int pkp, KC, DC;
  124.             public int bounty = 0;
  125.             public int killStreak = 0;
  126.            
  127.             public boolean[] clanWarRule = new boolean[10];
  128.             public int follow2 = 0;
  129.             public int antiqueSelect = 0;
  130.             public boolean usingLamp = false;
  131.             public boolean normalLamp = false;
  132.             public boolean antiqueLamp = false;
  133.             public boolean usingAltar = false;
  134.             public boolean usingShit = false;
  135.             public int altarItemId = 0;
  136.             public int[][] playerSkillProp = new int[20][15];
  137.             public boolean[] playerSkilling = new boolean[20];
  138.             public boolean setPin = false;
  139.             public String bankPin = "";
  140.             public boolean teleporting;
  141.      
  142.             public long muteEnd;
  143.             public long lastReport = 0;
  144.             public int level1 = 0, level2 = 0, level3 = 0;
  145.             public String lastReported = "";
  146.             public long lastButton;
  147.             public int leatherType = -1;
  148.             public boolean isWc;
  149.             public int homeTele = 0;
  150.             public int playerPrestige = 0;
  151.             //public int prestigePoints = 0;
  152.             public int homeTeleDelay = 0;
  153.      
  154.             public boolean wcing;
  155.             public int treeX, treeY;
  156.             public long miscTimer;
  157.             public boolean canWalk;
  158.             public long lastFlower;
  159.             public long waitTime;
  160.             public boolean usingROD = false;
  161.             public int DELAY = 1250;
  162.             public long saveButton = 0;
  163.             public int attempts = 3;
  164.             public boolean isOperate;
  165.             public int itemUsing;
  166.      
  167.             public boolean isFullBody = false;
  168.             public boolean isFullHelm = false;
  169.             public boolean isFullMask = false;
  170.      
  171.             public long lastCast;
  172.             public boolean hasBankPin, enterdBankpin, firstPinEnter, requestPinDelete,
  173.                             secondPinEnter, thirdPinEnter, fourthPinEnter, hasBankpin;
  174.             public int lastLoginDate, playerBankPin, recoveryDelay = 3,
  175.                             attemptsRemaining = 3, lastPinSettings = -1, setPinDate = -1,
  176.                             changePinDate = -1, deletePinDate = -1, firstPin, secondPin,
  177.                             thirdPin, fourthPin, bankPin1, bankPin2, bankPin3, bankPin4,
  178.                             pinDeleteDateRequested;
  179.      
  180.             public boolean isCooking = false, initialized = false,
  181.                             disconnected = false, ruleAgreeButton = false,
  182.                             RebuildNPCList = false, isActive = false, isKicked = false,
  183.                             isSkulled = false, friendUpdate = false, newPlayer = false,
  184.                             hasMultiSign = false, saveCharacter = false, mouseButton = false,
  185.                             splitChat = false, chatEffects = true, acceptAid = false,
  186.                             nextDialogue = false, autocasting = false, usedSpecial = false,
  187.                             mageFollow = false, dbowSpec = false, craftingLeather = false,
  188.                             properLogout = false, secDbow = false, maxNextHit = false,
  189.                             ssSpec = false, vengOn = false, addStarter = false,
  190.                             startPack = false, accountFlagged = false, msbSpec = false,
  191.      
  192.                             dtOption = false, dtOption2 = false, doricOption = false,
  193.                             doricOption2 = false, caOption2 = false, caOption2a = false,
  194.                             caOption4a = false, caOption4b = false, caOption4c = false,
  195.                             caPlayerTalk1 = false, horrorOption = false, rfdOption = false,
  196.                             inDt = false, inHfd = false, disableAttEvt = false,
  197.                             AttackEventRunning = false, npcindex, spawned = false;
  198.      
  199.             public int
  200.      
  201.             saveDelay, height = 0, playerKilled, pkPoints, totalPlayerDamageDealt,
  202.                             killedBy, lastChatId = 1, privateChat, friendSlot = 0, dialogueId, gloryValue,
  203.                             randomCoffin, newLocation, specEffect, specBarId, attackLevelReq,
  204.                             defenceLevelReq, strengthLevelReq, rangeLevelReq, magicLevelReq,
  205.                             followId, skullTimer, votingPoints, nextChat = 0, talkingNpc = -1,
  206.                             dialogueAction = 0, autocastId, followDistance, followId2,
  207.                             barrageCount = 0, delayedDamage = 0, delayedDamage2 = 0,
  208.                             pcPoints = 0, prestigePoints = 0, donPoints = 0, returnDon = 0, ecoPro = 0, totalDon = 0, playerKills = 0, playerVotes = 0, magePoints = 0, lastArrowUsed = -1,
  209.                             clanId = -1, autoRet = 0, pcDamage = 0, xInterfaceId = 0,
  210.                             xRemoveId = 0, xRemoveSlot = 0, tzhaarToKill = 0, tzhaarKilled = 0,
  211.                             waveId, frozenBy = 0, poisonDamage = 0, teleAction = 0,
  212.                             newPlayerAct = 0, bonusAttack = 0, lastNpcAttacked = 0,
  213.                             killCount = 0, tzKekSpawn = 0, tzKekTimer = 0,
  214.      
  215.                             actionTimer, rfdRound = 0, roundNpc = 0, desertTreasure = 0,
  216.                             horrorFromDeep = 0, QuestPoints = 0, doricQuest = 0;
  217.      
  218.             public int[] voidStatus = new int[5];
  219.             public int[] itemKeptId = new int[4];
  220.             public int[] pouches = new int[4];
  221.             public final int[] POUCH_SIZE = { 3, 6, 9, 12 };
  222.             public boolean[] invSlot = new boolean[28], equipSlot = new boolean[14];
  223.             public long friends[] = new long[200];
  224.             public double specAmount = 0;
  225.             public double specAccuracy = 1;
  226.             public double specDamage = 1;
  227.             public double prayerPoint = 1.0;
  228.             public boolean storing = false;
  229.             public int teleGrabItem, teleGrabX, teleGrabY, duelCount, underAttackBy,
  230.                             underAttackBy2, wildLevel, teleTimer, respawnTimer, saveTimer = 0,
  231.                             teleBlockLength, poisonDelay;
  232.             public long lastPlayerMove, lastPoison, lastPoisonSip, poisonImmune,
  233.                             lastSpear, lastProtItem, dfsDelay, lastVeng, lastYell,
  234.                             teleGrabDelay, protMageDelay, protMeleeDelay, protRangeDelay,
  235.                             lastAction, lastThieve, lastLockPick, alchDelay, specCom,
  236.                             specDelay = System.currentTimeMillis(), duelDelay, teleBlockDelay,
  237.                             godSpellDelay, singleCombatDelay, singleCombatDelay2, reduceStat,
  238.                             restoreStatsDelay, logoutDelay, buryDelay, cleanDelay, diceDelay,
  239.                             foodDelay, wcDelay, potDelay, klikDelay;
  240.             public boolean canChangeAppearance = false;
  241.             public boolean mageAllowed;
  242.             public byte poisonMask = 0;
  243.             public int focusPointX = -1, focusPointY = -1;
  244.             public int questPoints = 0;
  245.             public int cooksA;
  246.             public int lastDtKill = 0;
  247.             public int dtHp = 0, dtMax = 0, dtAtk = 0, dtDef = 0;
  248.             public int desertT;
  249.             public long lastChat, lastRandom, lastCaught = 0, lastAttacked,
  250.                             homeTeleTime, lastDagChange = -1, reportDelay, lastPlant,
  251.                             objectTimer, npcTimer, lastEss, lastClanMessage;
  252.             public int DirectionCount = 0;
  253.     //      public boolean appearanceUpdateRequired = true;
  254.             public int hitDiff2;
  255.             public int hitDiff = 0;
  256.             public boolean hitUpdateRequired2;
  257.             public boolean hitUpdateRequired = false;
  258.             public boolean isDead = false;
  259.             public boolean randomEvent = false;
  260.             public boolean FirstClickRunning = false;
  261.             public boolean WildernessWarning = false;
  262.      
  263.             /*
  264.              * End*
  265.              */
  266.      
  267.             public void faceNPC(int index) {
  268.                     faceNPC = index;
  269.                     faceNPCupdate = true;
  270.                     updateRequired = true;
  271.             }
  272.      
  273.             protected boolean faceNPCupdate = false;
  274.             public int faceNPC = -1;
  275.      
  276.             public void appendFaceNPCUpdate(Stream str) {
  277.                     str.writeWordBigEndian(faceNPC);
  278.             }
  279.      
  280.             public int[] keepItems = new int[4];
  281.             public int[] keepItemsN = new int[4];
  282.             public int WillKeepAmt1, WillKeepAmt2, WillKeepAmt3, WillKeepAmt4,
  283.                             WillKeepItem1, WillKeepItem2, WillKeepItem3, WillKeepItem4,
  284.                             WillKeepItem1Slot, WillKeepItem2Slot, WillKeepItem3Slot,
  285.                             WillKeepItem4Slot, EquipStatus;
  286.      
  287.             public void ResetKeepItems() {
  288.                     WillKeepAmt1 = -1;
  289.                     WillKeepItem1 = -1;
  290.                     WillKeepAmt2 = -1;
  291.                     WillKeepItem2 = -1;
  292.                     WillKeepAmt3 = -1;
  293.                     WillKeepItem3 = -1;
  294.                     WillKeepAmt4 = -1;
  295.                     WillKeepItem4 = -1;
  296.             }
  297.      
  298.             public void StartBestItemScan(Client c) {
  299.                     if (c.isSkulled && !c.prayerActive[10]) {
  300.                             ItemKeptInfo(c, 0);
  301.                             return;
  302.                     }
  303.                     FindItemKeptInfo(c);
  304.                     ResetKeepItems();
  305.                     BestItem1(c);
  306.             }
  307.      
  308.             public void FindItemKeptInfo(Client c) {
  309.                     if (isSkulled && c.prayerActive[10])
  310.                             ItemKeptInfo(c, 1);
  311.                     else if (!isSkulled && !c.prayerActive[10])
  312.                             ItemKeptInfo(c, 3);
  313.                     else if (!isSkulled && c.prayerActive[10])
  314.                             ItemKeptInfo(c, 4);
  315.             }
  316.      
  317.             public void ItemKeptInfo(Client c, int Lose) {
  318.                     for (int i = 17109; i < 17131; i++) {
  319.                             c.getPA().sendFrame126("", i);
  320.                     }
  321.                     c.getPA().sendFrame126("Items you will keep on death:", 17104);
  322.                     c.getPA().sendFrame126("Items you will lose on death:", 17105);
  323.                     c.getPA().sendFrame126("Player Information", 17106);
  324.                     c.getPA().sendFrame126("Max items kept on death:", 17107);
  325.                     c.getPA().sendFrame126("~ " + Lose + " ~", 17108);
  326.                     c.getPA().sendFrame126("The normal amount of", 17111);
  327.                     c.getPA().sendFrame126("items kept is three.", 17112);
  328.                     switch (Lose) {
  329.                     case 0:
  330.                     default:
  331.                             c.getPA().sendFrame126("Items you will keep on death:", 17104);
  332.                             c.getPA().sendFrame126("Items you will lose on death:", 17105);
  333.                             c.getPA().sendFrame126("You're marked with a", 17111);
  334.                             c.getPA().sendFrame126("@red@skull. @lre@This reduces the", 17112);
  335.                             c.getPA().sendFrame126("items you keep from", 17113);
  336.                             c.getPA().sendFrame126("three to zero!", 17114);
  337.                             break;
  338.                     case 1:
  339.                             c.getPA().sendFrame126("Items you will keep on death:", 17104);
  340.                             c.getPA().sendFrame126("Items you will lose on death:", 17105);
  341.                             c.getPA().sendFrame126("You're marked with a", 17111);
  342.                             c.getPA().sendFrame126("@red@skull. @lre@This reduces the", 17112);
  343.                             c.getPA().sendFrame126("items you keep from", 17113);
  344.                             c.getPA().sendFrame126("three to zero!", 17114);
  345.                             c.getPA().sendFrame126("However, you also have", 17115);
  346.                             c.getPA().sendFrame126("the @red@Protect @lre@Items prayer", 17116);
  347.                             c.getPA().sendFrame126("active, which saves you", 17117);
  348.                             c.getPA().sendFrame126("one extra item!", 17118);
  349.                             break;
  350.                     case 3:
  351.                             c.getPA().sendFrame126(
  352.                                             "Items you will keep on death(if not skulled):", 17104);
  353.                             c.getPA().sendFrame126(
  354.                                             "Items you will lose on death(if not skulled):", 17105);
  355.                             c.getPA().sendFrame126("You have no factors", 17111);
  356.                             c.getPA().sendFrame126("affecting the items you", 17112);
  357.                             c.getPA().sendFrame126("keep.", 17113);
  358.                             break;
  359.                     case 4:
  360.                             c.getPA().sendFrame126(
  361.                                             "Items you will keep on death(if not skulled):", 17104);
  362.                             c.getPA().sendFrame126(
  363.                                             "Items you will lose on death(if not skulled):", 17105);
  364.                             c.getPA().sendFrame126("You have the @red@Protect", 17111);
  365.                             c.getPA().sendFrame126("@red@Item @lre@prayer active,", 17112);
  366.                             c.getPA().sendFrame126("which saves you one", 17113);
  367.                             c.getPA().sendFrame126("extra item!", 17114);
  368.                             break;
  369.                     }
  370.             }
  371.      
  372.             public void BestItem1(Client c) {
  373.                     int BestValue = 0;
  374.                     int NextValue = 0;
  375.                     int ItemsContained = 0;
  376.                     WillKeepItem1 = 0;
  377.                     WillKeepItem1Slot = 0;
  378.                     for (int ITEM = 0; ITEM < 28; ITEM++) {
  379.                             if (playerItems[ITEM] > 0) {
  380.                                     ItemsContained += 1;
  381.                                     NextValue = (int) Math.floor(c.getShops().getItemShopValue(
  382.                                                     playerItems[ITEM] - 1));
  383.                                     if (NextValue > BestValue) {
  384.                                             BestValue = NextValue;
  385.                                             WillKeepItem1 = playerItems[ITEM] - 1;
  386.                                             WillKeepItem1Slot = ITEM;
  387.                                             if (playerItemsN[ITEM] > 2 && !c.prayerActive[10]) {
  388.                                                     WillKeepAmt1 = 3;
  389.                                             } else if (playerItemsN[ITEM] > 3 && c.prayerActive[10]) {
  390.                                                     WillKeepAmt1 = 4;
  391.                                             } else {
  392.                                                     WillKeepAmt1 = playerItemsN[ITEM];
  393.                                             }
  394.                                     }
  395.                             }
  396.                     }
  397.                     for (int EQUIP = 0; EQUIP < 14; EQUIP++) {
  398.                             if (playerEquipment[EQUIP] > 0) {
  399.                                     ItemsContained += 1;
  400.                                     NextValue = (int) Math.floor(c.getShops().getItemShopValue(
  401.                                                     playerEquipment[EQUIP]));
  402.                                     if (NextValue > BestValue) {
  403.                                             BestValue = NextValue;
  404.                                             WillKeepItem1 = playerEquipment[EQUIP];
  405.                                             WillKeepItem1Slot = EQUIP + 28;
  406.                                             if (playerEquipmentN[EQUIP] > 2 && !c.prayerActive[10]) {
  407.                                                     WillKeepAmt1 = 3;
  408.                                             } else if (playerEquipmentN[EQUIP] > 3
  409.                                                             && c.prayerActive[10]) {
  410.                                                     WillKeepAmt1 = 4;
  411.                                             } else {
  412.                                                     WillKeepAmt1 = playerEquipmentN[EQUIP];
  413.                                             }
  414.                                     }
  415.                             }
  416.                     }
  417.                     if (!isSkulled
  418.                                     && ItemsContained > 1
  419.                                     && (WillKeepAmt1 < 3 || (c.prayerActive[10] && WillKeepAmt1 < 4))) {
  420.                             BestItem2(c, ItemsContained);
  421.                     }
  422.             }
  423.      
  424.             public void BestItem2(Client c, int ItemsContained) {
  425.                     int BestValue = 0;
  426.                     int NextValue = 0;
  427.                     WillKeepItem2 = 0;
  428.                     WillKeepItem2Slot = 0;
  429.                     for (int ITEM = 0; ITEM < 28; ITEM++) {
  430.                             if (playerItems[ITEM] > 0) {
  431.                                     NextValue = (int) Math.floor(c.getShops().getItemShopValue(
  432.                                                     playerItems[ITEM] - 1));
  433.                                     if (NextValue > BestValue
  434.                                                     && !(ITEM == WillKeepItem1Slot && playerItems[ITEM] - 1 == WillKeepItem1)) {
  435.                                             BestValue = NextValue;
  436.                                             WillKeepItem2 = playerItems[ITEM] - 1;
  437.                                             WillKeepItem2Slot = ITEM;
  438.                                             if (playerItemsN[ITEM] > 2 - WillKeepAmt1
  439.                                                             && !c.prayerActive[10]) {
  440.                                                     WillKeepAmt2 = 3 - WillKeepAmt1;
  441.                                             } else if (playerItemsN[ITEM] > 3 - WillKeepAmt1
  442.                                                             && c.prayerActive[10]) {
  443.                                                     WillKeepAmt2 = 4 - WillKeepAmt1;
  444.                                             } else {
  445.                                                     WillKeepAmt2 = playerItemsN[ITEM];
  446.                                             }
  447.                                     }
  448.                             }
  449.                     }
  450.                     for (int EQUIP = 0; EQUIP < 14; EQUIP++) {
  451.                             if (playerEquipment[EQUIP] > 0) {
  452.                                     NextValue = (int) Math.floor(c.getShops().getItemShopValue(
  453.                                                     playerEquipment[EQUIP]));
  454.                                     if (NextValue > BestValue
  455.                                                     && !(EQUIP + 28 == WillKeepItem1Slot && playerEquipment[EQUIP] == WillKeepItem1)) {
  456.                                             BestValue = NextValue;
  457.                                             WillKeepItem2 = playerEquipment[EQUIP];
  458.                                             WillKeepItem2Slot = EQUIP + 28;
  459.                                             if (playerEquipmentN[EQUIP] > 2 - WillKeepAmt1
  460.                                                             && !c.prayerActive[10]) {
  461.                                                     WillKeepAmt2 = 3 - WillKeepAmt1;
  462.                                             } else if (playerEquipmentN[EQUIP] > 3 - WillKeepAmt1
  463.                                                             && c.prayerActive[10]) {
  464.                                                     WillKeepAmt2 = 4 - WillKeepAmt1;
  465.                                             } else {
  466.                                                     WillKeepAmt2 = playerEquipmentN[EQUIP];
  467.                                             }
  468.                                     }
  469.                             }
  470.                     }
  471.                     if (!isSkulled
  472.                                     && ItemsContained > 2
  473.                                     && (WillKeepAmt1 + WillKeepAmt2 < 3 || (c.prayerActive[10] && WillKeepAmt1
  474.                                                     + WillKeepAmt2 < 4))) {
  475.                             BestItem3(c, ItemsContained);
  476.                     }
  477.             }
  478.      
  479.             public void BestItem3(Client c, int ItemsContained) {
  480.                     int BestValue = 0;
  481.                     int NextValue = 0;
  482.                     WillKeepItem3 = 0;
  483.                     WillKeepItem3Slot = 0;
  484.                     for (int ITEM = 0; ITEM < 28; ITEM++) {
  485.                             if (playerItems[ITEM] > 0) {
  486.                                     NextValue = (int) Math.floor(c.getShops().getItemShopValue(
  487.                                                     playerItems[ITEM] - 1));
  488.                                     if (NextValue > BestValue
  489.                                                     && !(ITEM == WillKeepItem1Slot && playerItems[ITEM] - 1 == WillKeepItem1)
  490.                                                     && !(ITEM == WillKeepItem2Slot && playerItems[ITEM] - 1 == WillKeepItem2)) {
  491.                                             BestValue = NextValue;
  492.                                             WillKeepItem3 = playerItems[ITEM] - 1;
  493.                                             WillKeepItem3Slot = ITEM;
  494.                                             if (playerItemsN[ITEM] > 2 - (WillKeepAmt1 + WillKeepAmt2)
  495.                                                             && !c.prayerActive[10]) {
  496.                                                     WillKeepAmt3 = 3 - (WillKeepAmt1 + WillKeepAmt2);
  497.                                             } else if (playerItemsN[ITEM] > 3 - (WillKeepAmt1 + WillKeepAmt2)
  498.                                                             && c.prayerActive[10]) {
  499.                                                     WillKeepAmt3 = 4 - (WillKeepAmt1 + WillKeepAmt2);
  500.                                             } else {
  501.                                                     WillKeepAmt3 = playerItemsN[ITEM];
  502.                                             }
  503.                                     }
  504.                             }
  505.                     }
  506.                     for (int EQUIP = 0; EQUIP < 14; EQUIP++) {
  507.                             if (playerEquipment[EQUIP] > 0) {
  508.                                     NextValue = (int) Math.floor(c.getShops().getItemShopValue(
  509.                                                     playerEquipment[EQUIP]));
  510.                                     if (NextValue > BestValue
  511.                                                     && !(EQUIP + 28 == WillKeepItem1Slot && playerEquipment[EQUIP] == WillKeepItem1)
  512.                                                     && !(EQUIP + 28 == WillKeepItem2Slot && playerEquipment[EQUIP] == WillKeepItem2)) {
  513.                                             BestValue = NextValue;
  514.                                             WillKeepItem3 = playerEquipment[EQUIP];
  515.                                             WillKeepItem3Slot = EQUIP + 28;
  516.                                             if (playerEquipmentN[EQUIP] > 2 - (WillKeepAmt1 + WillKeepAmt2)
  517.                                                             && !c.prayerActive[10]) {
  518.                                                     WillKeepAmt3 = 3 - (WillKeepAmt1 + WillKeepAmt2);
  519.                                             } else if (playerEquipmentN[EQUIP] > 3 - WillKeepAmt1
  520.                                                             && c.prayerActive[10]) {
  521.                                                     WillKeepAmt3 = 4 - (WillKeepAmt1 + WillKeepAmt2);
  522.                                             } else {
  523.                                                     WillKeepAmt3 = playerEquipmentN[EQUIP];
  524.                                             }
  525.                                     }
  526.                             }
  527.                     }
  528.                     if (!isSkulled && ItemsContained > 3 && c.prayerActive[10]
  529.                                     && ((WillKeepAmt1 + WillKeepAmt2 + WillKeepAmt3) < 4)) {
  530.                             BestItem4(c);
  531.                     }
  532.             }
  533.      
  534.             public void BestItem4(Client c) {
  535.                     int BestValue = 0;
  536.                     int NextValue = 0;
  537.                     WillKeepItem4 = 0;
  538.                     WillKeepItem4Slot = 0;
  539.                     for (int ITEM = 0; ITEM < 28; ITEM++) {
  540.                             if (playerItems[ITEM] > 0) {
  541.                                     NextValue = (int) Math.floor(c.getShops().getItemShopValue(
  542.                                                     playerItems[ITEM] - 1));
  543.                                     if (NextValue > BestValue
  544.                                                     && !(ITEM == WillKeepItem1Slot && playerItems[ITEM] - 1 == WillKeepItem1)
  545.                                                     && !(ITEM == WillKeepItem2Slot && playerItems[ITEM] - 1 == WillKeepItem2)
  546.                                                     && !(ITEM == WillKeepItem3Slot && playerItems[ITEM] - 1 == WillKeepItem3)) {
  547.                                             BestValue = NextValue;
  548.                                             WillKeepItem4 = playerItems[ITEM] - 1;
  549.                                             WillKeepItem4Slot = ITEM;
  550.                                     }
  551.                             }
  552.                     }
  553.                     for (int EQUIP = 0; EQUIP < 14; EQUIP++) {
  554.                             if (playerEquipment[EQUIP] > 0) {
  555.                                     NextValue = (int) Math.floor(c.getShops().getItemShopValue(
  556.                                                     playerEquipment[EQUIP]));
  557.                                     if (NextValue > BestValue
  558.                                                     && !(EQUIP + 28 == WillKeepItem1Slot && playerEquipment[EQUIP] == WillKeepItem1)
  559.                                                     && !(EQUIP + 28 == WillKeepItem2Slot && playerEquipment[EQUIP] == WillKeepItem2)
  560.                                                     && !(EQUIP + 28 == WillKeepItem3Slot && playerEquipment[EQUIP] == WillKeepItem3)) {
  561.                                             BestValue = NextValue;
  562.                                             WillKeepItem4 = playerEquipment[EQUIP];
  563.                                             WillKeepItem4Slot = EQUIP + 28;
  564.                                     }
  565.                             }
  566.                     }
  567.             }
  568.      
  569.             public final int[] BOWS = { 9185, 839, 845, 847, 851, 855, 859, 841, 843,
  570.                             849, 853, 857, 861, 4212, 4214, 4215, 11235, 4216, 4217, 4218,
  571.                             4219, 4220, 4221, 4222, 4223, 6724, 4734, 4934, 4935, 4936, 4937 };
  572.             public final int[] ARROWS = { 882, 884, 886, 888, 890, 892, 4740, 11212,
  573.                             9140, 9141, 4142, 9143, 9144, 9240, 9241, 9242, 9243, 9244, 9245 };
  574.             public final int[] NO_ARROW_DROP = { 4212, 4214, 4215, 4216, 4217, 4218,
  575.                             4219, 4220, 4221, 4222, 4223, 4734, 4934, 4935, 4936, 4937 };
  576.             public final int[] OTHER_RANGE_WEAPONS = { 863, 864, 865, 866, 867, 868,
  577.                             869, 806, 807, 808, 809, 810, 811, 825, 826, 827, 828, 829, 830,
  578.                             800, 801, 802, 803, 804, 805, 6522 };
  579.      
  580.             public final int[][] MAGIC_SPELLS = {
  581.                             // example {magicId, level req, animation, startGFX, projectile Id,
  582.                             // endGFX, maxhit, exp gained, rune 1, rune 1 amount, rune 2, rune 2
  583.                             // amount, rune 3, rune 3 amount, rune 4, rune 4 amount}
  584.      
  585.                             // Modern Spells
  586.                             { 1152, 1, 711, 90, 91, 92, 2, 5, 556, 1, 558, 1, 0, 0, 0, 0 }, // wind
  587.                                                                                                                                                             // strike
  588.                             { 1154, 5, 711, 93, 94, 95, 4, 7, 555, 1, 556, 1, 558, 1, 0, 0 }, // water
  589.                                                                                                                                                                     // strike
  590.                             { 1156, 9, 711, 96, 97, 98, 6, 9, 557, 2, 556, 1, 558, 1, 0, 0 },// earth
  591.                                                                                                                                                                     // strike
  592.                             { 1158, 13, 711, 99, 100, 101, 8, 11, 554, 3, 556, 2, 558, 1, 0, 0 }, // fire
  593.                                                                                                                                                                             // strike
  594.                             { 1160, 17, 711, 117, 118, 119, 9, 13, 556, 2, 562, 1, 0, 0, 0, 0 }, // wind
  595.                                                                                                                                                                             // bolt
  596.                             { 1163, 23, 711, 120, 121, 122, 10, 16, 556, 2, 555, 2, 562, 1, 0,
  597.                                             0 }, // water bolt
  598.                             { 1166, 29, 711, 123, 124, 125, 11, 20, 556, 2, 557, 3, 562, 1, 0,
  599.                                             0 }, // earth bolt
  600.                             { 1169, 35, 711, 126, 127, 128, 12, 22, 556, 3, 554, 4, 562, 1, 0,
  601.                                             0 }, // fire bolt
  602.                             { 1172, 41, 711, 132, 133, 134, 13, 25, 556, 3, 560, 1, 0, 0, 0, 0 }, // wind
  603.                                                                                                                                                                             // blast
  604.                             { 1175, 47, 711, 135, 136, 137, 14, 28, 556, 3, 555, 3, 560, 1, 0,
  605.                                             0 }, // water blast
  606.                             { 1177, 53, 711, 138, 139, 140, 15, 31, 556, 3, 557, 4, 560, 1, 0,
  607.                                             0 }, // earth blast
  608.                             { 1181, 59, 711, 129, 130, 131, 16, 35, 556, 4, 554, 5, 560, 1, 0,
  609.                                             0 }, // fire blast
  610.                             { 1183, 62, 711, 158, 159, 160, 17, 36, 556, 5, 565, 1, 0, 0, 0, 0 }, // wind
  611.                                                                                                                                                                             // wave
  612.                             { 1185, 65, 711, 161, 162, 163, 18, 37, 556, 5, 555, 7, 565, 1, 0,
  613.                                             0 }, // water wave
  614.                             { 1188, 70, 711, 164, 165, 166, 19, 40, 556, 5, 557, 7, 565, 1, 0,
  615.                                             0 }, // earth wave
  616.                             { 1189, 75, 711, 155, 156, 157, 20, 42, 556, 5, 554, 7, 565, 1, 0,
  617.                                             0 }, // fire wave
  618.                             { 1153, 3, 716, 102, 103, 104, 0, 13, 555, 3, 557, 2, 559, 1, 0, 0 }, // confuse
  619.                             { 1157, 11, 716, 105, 106, 107, 0, 20, 555, 3, 557, 2, 559, 1, 0, 0 }, // weaken
  620.                             { 1161, 19, 716, 108, 109, 110, 0, 29, 555, 2, 557, 3, 559, 1, 0, 0 }, // curse
  621.                             { 1542, 66, 729, 167, 168, 169, 0, 76, 557, 5, 555, 5, 566, 1, 0, 0 }, // vulnerability
  622.                             { 1543, 73, 729, 170, 171, 172, 0, 83, 557, 8, 555, 8, 566, 1, 0, 0 }, // enfeeble
  623.                             { 1562, 80, 729, 173, 174, 107, 0, 90, 557, 12, 555, 12, 556, 1, 0,
  624.                                             0 }, // stun
  625.                             { 1572, 20, 711, 177, 178, 181, 0, 30, 557, 3, 555, 3, 561, 2, 0, 0 }, // bind
  626.                             { 1582, 50, 711, 177, 178, 180, 2, 60, 557, 4, 555, 4, 561, 3, 0, 0 }, // snare
  627.                             { 1592, 79, 711, 177, 178, 179, 4, 90, 557, 5, 555, 5, 561, 4, 0, 0 }, // entangle
  628.                             { 1171, 39, 724, 145, 146, 147, 15, 25, 556, 2, 557, 2, 562, 1, 0,
  629.                                             0 }, // crumble undead
  630.                             { 1539, 50, 708, 87, 88, 89, 25, 42, 554, 5, 560, 1, 0, 0, 0, 0 }, // iban
  631.                                                                                                                                                                     // blast
  632.                             { 12037, 50, 1576, 327, 328, 329, 19, 30, 560, 1, 558, 4, 0, 0, 0,
  633.                                             0 }, // magic dart
  634.                             { 1190, 60, 811, 0, 0, 76, 20, 60, 554, 2, 565, 2, 556, 4, 0, 0 }, // sara
  635.                                                                                                                                                                     // strike
  636.                             { 1191, 60, 811, 0, 0, 77, 20, 60, 554, 1, 565, 2, 556, 4, 0, 0 }, // cause
  637.                                                                                                                                                                     // of
  638.                                                                                                                                                                     // guthix
  639.                             { 1192, 60, 811, 0, 0, 78, 20, 60, 554, 4, 565, 2, 556, 1, 0, 0 }, // flames
  640.                                                                                                                                                                     // of
  641.                                                                                                                                                                     // zammy
  642.                             { 12445, 85, 1819, 0, 344, 345, 0, 65, 563, 1, 562, 1, 560, 1, 0, 0 }, // teleblock
  643.      
  644.                             // Ancient Spells
  645.                             { 12939, 50, 1978, 0, 384, 385, 13, 30, 560, 2, 562, 2, 554, 1,
  646.                                             556, 1 }, // smoke rush
  647.                             { 12987, 52, 1978, 0, 378, 379, 14, 31, 560, 2, 562, 2, 566, 1,
  648.                                             556, 1 }, // shadow rush
  649.                             { 12901, 56, 1978, 0, 0, 373, 15, 33, 560, 2, 562, 2, 565, 1, 0, 0 }, // blood
  650.                                                                                                                                                                             // rush
  651.                             { 12861, 58, 1978, 0, 360, 361, 16, 34, 560, 2, 562, 2, 555, 2, 0,
  652.                                             0 }, // ice rush
  653.                             { 12963, 62, 1979, 0, 0, 389, 19, 36, 560, 2, 562, 4, 556, 2, 554,
  654.                                             2 }, // smoke burst
  655.                             { 13011, 64, 1979, 0, 0, 382, 20, 37, 560, 2, 562, 4, 556, 2, 566,
  656.                                             2 }, // shadow burst
  657.                             { 12919, 68, 1979, 0, 0, 376, 21, 39, 560, 2, 562, 4, 565, 2, 0, 0 }, // blood
  658.                                                                                                                                                                             // burst
  659.                             { 12881, 70, 1979, 0, 0, 363, 22, 40, 560, 2, 562, 4, 555, 4, 0, 0 }, // ice
  660.                                                                                                                                                                             // burst
  661.                             { 12951, 74, 1978, 0, 386, 387, 23, 42, 560, 2, 554, 2, 565, 2,
  662.                                             556, 2 }, // smoke blitz
  663.                             { 12999, 76, 1978, 0, 380, 381, 24, 43, 560, 2, 565, 2, 556, 2,
  664.                                             566, 2 }, // shadow blitz
  665.                             { 12911, 80, 1978, 0, 374, 375, 25, 45, 560, 2, 565, 4, 0, 0, 0, 0 }, // blood
  666.                                                                                                                                                                             // blitz
  667.                             { 12871, 82, 1978, 366, 0, 367, 26, 46, 560, 2, 565, 2, 555, 3, 0,
  668.                                             0 }, // ice blitz
  669.                             { 12975, 86, 1979, 0, 0, 391, 27, 48, 560, 4, 565, 2, 556, 4, 554,
  670.                                             4 }, // smoke barrage
  671.                             { 13023, 88, 1979, 0, 0, 383, 28, 49, 560, 4, 565, 2, 556, 4, 566,
  672.                                             3 }, // shadow barrage
  673.                             { 12929, 92, 1979, 0, 0, 377, 29, 51, 560, 4, 565, 4, 566, 1, 0, 0 }, // blood
  674.                                                                                                                                                                             // barrage
  675.                             { 12891, 94, 1979, 0, 0, 369, 30, 52, 560, 4, 565, 2, 555, 6, 0, 0 }, // ice
  676.                                                                                                                                                                             // barrage
  677.      
  678.                             { -1, 80, 811, 301, 0, 0, 0, 0, 554, 3, 565, 3, 556, 3, 0, 0 }, // charge
  679.                             { -1, 21, 712, 112, 0, 0, 0, 10, 554, 3, 561, 1, 0, 0, 0, 0 }, // low
  680.                                                                                                                                                             // alch
  681.                             { -1, 55, 713, 113, 0, 0, 0, 20, 554, 5, 561, 1, 0, 0, 0, 0 }, // high
  682.                                                                                                                                                             // alch
  683.                             { -1, 33, 728, 142, 143, 144, 0, 35, 556, 1, 563, 1, 0, 0, 0, 0 } // telegrab
  684.      
  685.             };
  686.      
  687.             public boolean isAutoButton(int button) {
  688.                     for (int j = 0; j < autocastIds.length; j += 2) {
  689.                             if (autocastIds[j] == button)
  690.                                     return true;
  691.                     }
  692.                     return false;
  693.             }
  694.      
  695.             /* Start of combat variables */
  696.      
  697.             public boolean multiAttacking, rangeEndGFXHeight, playerFletch,
  698.                             playerIsFletching, playerIsMining, playerIsFiremaking,
  699.                             playerIsFishing, playerIsCooking;
  700.             public boolean below459 = true, defaultWealthTransfer, updateInventory,
  701.                             oldSpec, stopPlayerSkill, playerStun, stopPlayerPacket, usingClaws;
  702.             public boolean playerBFishing, finishedBarbarianTraining, ignoreDefence,
  703.                             secondFormAutocast, usingArrows, usingOtherRangeWeapons,
  704.                             usingCross, magicDef, spellSwap, recoverysSet;
  705.             public int rangeEndGFX, boltDamage, teleotherType, playerTradeWealth,
  706.                             doAmount, woodcuttingTree, stageT, dfsCount, recoilHits,
  707.                             playerDialogue, clawDelay, previousDamage;
  708.             public boolean protectItem = false;
  709.      
  710.             /* End of combat variables */
  711.      
  712.             public int[] autocastIds = { 51133, 32, 51185, 33, 51091, 34, 24018, 35,
  713.                             51159, 36, 51211, 37, 51111, 38, 51069, 39, 51146, 40, 51198, 41,
  714.                             51102, 42, 51058, 43, 51172, 44, 51224, 45, 51122, 46, 51080, 47,
  715.                             7038, 0, 7039, 1, 7040, 2, 7041, 3, 7042, 4, 7043, 5, 7044, 6,
  716.                             7045, 7, 7046, 8, 7047, 9, 7048, 10, 7049, 11, 7050, 12, 7051, 13,
  717.                             7052, 14, 7053, 15, 47019, 27, 47020, 25, 47021, 12, 47022, 13,
  718.                             47023, 14, 47024, 15 };
  719.      
  720.             // public String spellName = "Select Spell";
  721.             public void assignAutocast(int button) {
  722.                     for (int j = 0; j < autocastIds.length; j++) {
  723.                             if (autocastIds[j] == button) {
  724.                                     Client c = (Client) PlayerHandler.players[this.playerId];
  725.                                     autocasting = true;
  726.                                     autocastId = autocastIds[j + 1];
  727.                                     c.getPA().sendFrame36(108, 1);
  728.                                     c.setSidebarInterface(0, 328);
  729.                                     // spellName = getSpellName(autocastId);
  730.                                     // spellName = spellName;
  731.                                     // c.getPA().sendFrame126(spellName, 354);
  732.                                     c = null;
  733.                                     break;
  734.                             }
  735.                     }
  736.             }
  737.      
  738.             public int getLocalX() {
  739.                     return getX() - 8 * getMapRegionX();
  740.             }
  741.      
  742.             public int getLocalY() {
  743.                     return getY() - 8 * getMapRegionY();
  744.             }
  745.      
  746.             public String getSpellName(int id) {
  747.                     switch (id) {
  748.                     case 0:
  749.                             return "Air Strike";
  750.                     case 1:
  751.                             return "Water Strike";
  752.                     case 2:
  753.                             return "Earth Strike";
  754.                     case 3:
  755.                             return "Fire Strike";
  756.                     case 4:
  757.                             return "Air Bolt";
  758.                     case 5:
  759.                             return "Water Bolt";
  760.                     case 6:
  761.                             return "Earth Bolt";
  762.                     case 7:
  763.                             return "Fire Bolt";
  764.                     case 8:
  765.                             return "Air Blast";
  766.                     case 9:
  767.                             return "Water Blast";
  768.                     case 10:
  769.                             return "Earth Blast";
  770.                     case 11:
  771.                             return "Fire Blast";
  772.                     case 12:
  773.                             return "Air Wave";
  774.                     case 13:
  775.                             return "Water Wave";
  776.                     case 14:
  777.                             return "Earth Wave";
  778.                     case 15:
  779.                             return "Fire Wave";
  780.                     case 32:
  781.                             return "Shadow Rush";
  782.                     case 33:
  783.                             return "Smoke Rush";
  784.                     case 34:
  785.                             return "Blood Rush";
  786.                     case 35:
  787.                             return "Ice Rush";
  788.                     case 36:
  789.                             return "Shadow Burst";
  790.                     case 37:
  791.                             return "Smoke Burst";
  792.                     case 38:
  793.                             return "Blood Burst";
  794.                     case 39:
  795.                             return "Ice Burst";
  796.                     case 40:
  797.                             return "Shadow Blitz";
  798.                     case 41:
  799.                             return "Smoke Blitz";
  800.                     case 42:
  801.                             return "Blood Blitz";
  802.                     case 43:
  803.                             return "Ice Blitz";
  804.                     case 44:
  805.                             return "Shadow Barrage";
  806.                     case 45:
  807.                             return "Smoke Barrage";
  808.                     case 46:
  809.                             return "Blood Barrage";
  810.                     case 47:
  811.                             return "Ice Barrage";
  812.                     default:
  813.                             return "Select Spell";
  814.                     }
  815.             }
  816.      
  817.             public boolean fullVoidRange() {
  818.                     return playerEquipment[playerHat] == 11664
  819.                                     && playerEquipment[playerLegs] == 8840
  820.                                     && playerEquipment[playerChest] == 8839
  821.                                     && playerEquipment[playerHands] == 8842;
  822.             }
  823.      
  824.             public boolean fullVoidMage() {
  825.                     return playerEquipment[playerHat] == 11663
  826.                                     && playerEquipment[playerLegs] == 8840
  827.                                     && playerEquipment[playerChest] == 8839
  828.                                     && playerEquipment[playerHands] == 8842;
  829.             }
  830.      
  831.             public boolean fullVoidMelee() {
  832.                     return playerEquipment[playerHat] == 11665
  833.                                     && playerEquipment[playerLegs] == 8840
  834.                                     && playerEquipment[playerChest] == 8839
  835.                                     && playerEquipment[playerHands] == 8842;
  836.             }
  837.      
  838.             public int[][] barrowsNpcs = { { 2030, 0 }, // verac
  839.                             { 2029, 0 }, // toarg
  840.                             { 2028, 0 }, // karil
  841.                             { 2027, 0 }, // guthan
  842.                             { 2026, 0 }, // dharok
  843.                             { 2025, 0 } // ahrim
  844.             };
  845.             public int barrowsKillCount;
  846.      
  847.             public int reduceSpellId;
  848.             public final int[] REDUCE_SPELL_TIME = { 250000, 250000, 250000, 500000,
  849.                             500000, 500000 }; // how long does the other player stay immune to
  850.                                                                     // the spell
  851.             public long[] reduceSpellDelay = new long[6];
  852.             public final int[] REDUCE_SPELLS = { 1153, 1157, 1161, 1542, 1543, 1562 };
  853.             public boolean[] canUseReducingSpell = { true, true, true, true, true, true };
  854.      
  855.             public int slayerTask, taskAmount;
  856.      
  857.             public int prayerId = -1;
  858.             public int headIcon = -1;
  859.             public int bountyIcon = 0;
  860.             public long stopPrayerDelay, prayerDelay;
  861.             public boolean usingPrayer;
  862.             public final int[] PRAYER_DRAIN_RATE = { 500, 500, 500, 500, 500, 500, 500,
  863.                             500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500,
  864.                             500, 500, 500, 500, 500, 500 };
  865.             public final int[] PRAYER_LEVEL_REQUIRED = { 1, 4, 7, 8, 9, 10, 13, 16, 19,
  866.                             22, 25, 26, 27, 28, 31, 34, 37, 40, 43, 44, 45, 46, 49, 52, 60, 70 };
  867.             public final int[] PRAYER = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
  868.                             14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 };
  869.             public final String[] PRAYER_NAME = { "Thick Skin", "Burst of Strength",
  870.                             "Clarity of Thought", "Sharp Eye", "Mystic Will", "Rock Skin",
  871.                             "Superhuman Strength", "Improved Reflexes", "Rapid Restore",
  872.                             "Rapid Heal", "Protect Item", "Hawk Eye", "Mystic Lore",
  873.                             "Steel Skin", "Ultimate Strength", "Incredible Reflexes",
  874.                             "Protect from Magic", "Protect from Missiles",
  875.                             "Protect from Melee", "Eagle Eye", "Mystic Might", "Retribution",
  876.                             "Redemption", "Smite", "Chivalry", "Piety" };
  877.             public final int[] PRAYER_GLOW = { 83, 84, 85, 601, 602, 86, 87, 88, 89,
  878.                             90, 91, 603, 604, 92, 93, 94, 95, 96, 97, 605, 606, 98, 99, 100,
  879.                             607, 608 };
  880.             public final int[] PRAYER_HEAD_ICONS = { -1, -1, -1, -1, -1, -1, -1, -1,
  881.                             -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 0, -1, -1, 3, 5, 4, -1, -1 };
  882.             // {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,3,2,1,4,6,5};
  883.      
  884.             public boolean[] prayerActive = { false, false, false, false, false, false,
  885.                             false, false, false, false, false, false, false, false, false,
  886.                             false, false, false, false, false, false, false, false, false,
  887.                             false, false };
  888.      
  889.             public int duelTimer, duelTeleX, duelTeleY, duelSlot, duelSpaceReq,
  890.                             duelOption, duelingWith, duelStatus;
  891.             public int headIconPk = -1, headIconHints;
  892.             public boolean duelRequested;
  893.             public boolean[] duelRule = new boolean[22];
  894.             public final int[] DUEL_RULE_ID = { 1, 2, 16, 32, 64, 128, 256, 512, 1024,
  895.                             4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 2097152,
  896.                             8388608, 16777216, 67108864, 134217728 };
  897.      
  898.             public boolean doubleHit, usingSpecial, npcDroppingItems, usingRangeWeapon,
  899.                             usingBow, usingMagic, castingMagic;
  900.             public int specMaxHitIncrease, freezeDelay, freezeTimer = -6, killerId,
  901.                             playerIndex, oldPlayerIndex, lastWeaponUsed, projectileStage,
  902.                             crystalBowArrowCount, playerMagicBook, teleGfx, teleEndAnimation,
  903.                             teleHeight, teleX, teleY, rangeItemUsed, killingNpcIndex,
  904.                             totalDamageDealt, oldNpcIndex, fightMode, attackTimer, npcIndex,
  905.                             npcClickIndex, npcType, castingSpellId, oldSpellId, spellId,
  906.                             hitDelay;
  907.             public boolean magicFailed, oldMagicFailed;
  908.             public int bowSpecShot, clickNpcType, clickObjectType, objectId, objectX,
  909.                             objectY, objectXOffset, objectYOffset, objectDistance;
  910.             public int pItemX, pItemY, pItemId;
  911.             public boolean isMoving, walkingToItem;
  912.             public boolean updateShop;
  913.             public int myShopId;
  914.             public int tradeStatus, tradeWith;
  915.             public boolean forcedChatUpdateRequired, inDuel, tradeAccepted, goodTrade,
  916.                             tradeRequested, tradeResetNeeded, tradeConfirmed,
  917.                             tradeConfirmed2, canOffer, acceptTrade, acceptedTrade;
  918.             public int attackAnim, animationRequest = -1, animationWaitCycles;
  919.             public int[] playerBonus = new int[12];
  920.             public boolean isRunning2 = true;
  921.             public boolean takeAsNote;
  922.             public int combatLevel;
  923.             public boolean saveFile = false;
  924.             public int playerAppearance[] = new int[13];
  925.             public int apset;
  926.             public int actionID;
  927.             public int wearItemTimer, wearId, wearSlot, interfaceId;
  928.             public int XremoveSlot, XinterfaceID, XremoveID, Xamount;
  929.      
  930.             public int tutorial = 15;
  931.             public boolean usingGlory = false;
  932.             // public int[] woodcut = new int [3];
  933.             public int[] woodcut = new int[7];
  934.             public int wcTimer = 0;
  935.             public int[] mining = new int[3];
  936.             public int miningTimer = 0;
  937.             public boolean fishing = false;
  938.             public int fishTimer = 0;
  939.             public int smeltType; // 1 = bronze, 2 = iron, 3 = steel, 4 = gold, 5 =
  940.                                                             // mith, 6 = addy, 7 = rune
  941.             public int smeltAmount;
  942.             public int smeltTimer = 0;
  943.             public boolean smeltInterface;
  944.             public boolean patchCleared;
  945.             public int[] farm = new int[2];
  946.      
  947.             public boolean antiFirePot = false;
  948.      
  949.             /**
  950.              * Castle Wars
  951.              */
  952.             public int castleWarsTeam;
  953.             public boolean inCwGame;
  954.             public boolean inCwWait;
  955.      
  956.             /**
  957.              * Fight Pits
  958.              */
  959.             public boolean inPits = false;
  960.             public int pitsStatus = 0;
  961.      
  962.             /**
  963.              * SouthWest, NorthEast, SouthWest, NorthEast
  964.              */
  965.      
  966.             public boolean isInTut() {
  967.                     if (absX >= 2625 && absX <= 2687 && absY >= 4670 && absY <= 4735) {
  968.                             return true;
  969.                     }
  970.                     return false;
  971.             }
  972.      
  973.             public boolean inBarrows() {
  974.                     if (absX > 3520 && absX < 3598 && absY > 9653 && absY < 9750) {
  975.                             return true;
  976.                     }
  977.                     return false;
  978.             }
  979.            
  980.             public boolean gwdCoords() {
  981.             if (heightLevel == 2 || heightLevel == 0 || heightLevel == 1) {
  982.             if (absX >= 2800 && absX <= 2950 && absY >= 5200 && absY <= 5400) {
  983.                             return true;
  984.                     }
  985.             }
  986.             return false;
  987.     }
  988.      
  989.             public boolean inArea(int x, int y, int x1, int y1) {
  990.                     if (absX > x && absX < x1 && absY < y && absY > y1) {
  991.                             return true;
  992.                     }
  993.                     return false;
  994.             }
  995.      
  996.             public boolean Area(final int x1, final int x2, final int y1, final int y2) {
  997.                     return (absX >= x1 && absX <= x2 && absY >= y1 && absY <= y2);
  998.             }
  999.      
  1000.             public boolean inBank() {
  1001.                     return Area(3090, 3099, 3487, 3500) || Area(3089, 3090, 3492, 3498)
  1002.                                     || Area(3248, 3258, 3413, 3428) || Area(3179, 3191, 3432, 3448)
  1003.                                     || Area(2944, 2948, 3365, 3374) || Area(2942, 2948, 3367, 3374)
  1004.                                     || Area(2944, 2950, 3365, 3370) || Area(3008, 3019, 3352, 3359)
  1005.                                     || Area(3017, 3022, 3352, 3357) || Area(3203, 3213, 3200, 3237)
  1006.                                     || Area(3212, 3215, 3200, 3235) || Area(3215, 3220, 3202, 3235)
  1007.                                     || Area(3220, 3227, 3202, 3229) || Area(3227, 3230, 3208, 3226)
  1008.                                     || Area(3226, 3228, 3230, 3211) || Area(3227, 3229, 3208, 3226);
  1009.             }
  1010.      
  1011.             public boolean isInJail() {
  1012.                     if (absX >= 2065 && absX <= 2111 && absY >= 4415 && absY <= 4455) {
  1013.                             return true;
  1014.                     }
  1015.                     return false;
  1016.             }
  1017.            
  1018.             public boolean safeAreas(int x, int y, int x1, int y1) {
  1019.                     return (absX >= x && absX <= x1 && absY >= y && absY <= y1);
  1020.             }
  1021.      
  1022.             public boolean inWild() {
  1023.                     if (absX > 2941 && absX < 3392 && absY > 3518 && absY < 3966
  1024.                                     || absX > 2941 && absX < 3392 && absY > 9918 && absY < 10366) {
  1025.                             return true;
  1026.                     }
  1027.                     return false;
  1028.             }
  1029.      
  1030.             public boolean arenas() {
  1031.                     if (absX > 3331 && absX < 3391 && absY > 3242 && absY < 3260) {
  1032.                             return true;
  1033.                     }
  1034.                     return false;
  1035.             }
  1036.      
  1037.             public boolean inDuelArena() {
  1038.                     if ((absX > 3322 && absX < 3394 && absY > 3195 && absY < 3291)
  1039.                                     || (absX > 3311 && absX < 3323 && absY > 3223 && absY < 3248)) {
  1040.                             return true;
  1041.                     }
  1042.                     return false;
  1043.             }
  1044.      
  1045.             public boolean inMulti() {
  1046.                     if ((absX >= 3136 && absX <= 3327 && absY >= 3519 && absY <= 3607)
  1047.                                     || (absX >= 3190 && absX <= 3327 && absY >= 3648 && absY <= 3839)
  1048.                                     || (absX >= 3200 && absX <= 3390 && absY >= 3840 && absY <= 3967)
  1049.                                     || (absX >= 2992 && absX <= 3007 && absY >= 3912 && absY <= 3967)
  1050.                                     || (absX >= 2946 && absX <= 2959 && absY >= 3816 && absY <= 3831)
  1051.                                     || (absX >= 3008 && absX <= 3199 && absY >= 3856 && absY <= 3903)
  1052.                                     || (absX >= 2824 && absX <= 2944 && absY >= 5258 && absY <= 5369)
  1053.                                     || (absX >= 3008 && absX <= 3071 && absY >= 3600 && absY <= 3711)
  1054.                                     || (absX >= 3072 && absX <= 3327 && absY >= 3608 && absY <= 3647)
  1055.                                     || (absX >= 2624 && absX <= 2690 && absY >= 2550 && absY <= 2619)
  1056.                                     || (absX >= 2371 && absX <= 2422 && absY >= 5062 && absY <= 5117)
  1057.                                     || (absX >= 2896 && absX <= 2927 && absY >= 3595 && absY <= 3630)
  1058.                                     || (absX >= 2892 && absX <= 2932 && absY >= 4435 && absY <= 4464)
  1059.                                     || (absX >= 2256 && absX <= 2287 && absY >= 4680 && absY <= 4711)) {
  1060.                             return true;
  1061.                     }
  1062.                     return false;
  1063.             }
  1064.      
  1065.             public boolean inFightCaves() {
  1066.                     return absX >= 2360 && absX <= 2445 && absY >= 5045 && absY <= 5125;
  1067.             }
  1068.      
  1069.             public boolean inPirateHouse() {
  1070.                     return absX >= 3038 && absX <= 3044 && absY >= 3949 && absY <= 3959;
  1071.             }
  1072.      
  1073.             public String connectedFrom = "";
  1074.             // public static String addr = ((InetSocketAddress)
  1075.             // c.getSession().getRemoteAddress()).getAddress().getHostAddress();
  1076.             public String globalMessage = "";
  1077.      
  1078.             public abstract void initialize();
  1079.      
  1080.             public abstract void update();
  1081.      
  1082.             public int playerId = -1;
  1083.             public String playerName = null;
  1084.             public String playerName2 = null;
  1085.             public String playerPass = null;
  1086.             public int playerRights;
  1087.             public PlayerHandler handler = null;
  1088.             public int playerItems[] = new int[28];
  1089.             public int playerItemsN[] = new int[28];
  1090.             public int bankItems[] = new int[Config.BANK_SIZE];
  1091.             public int bankItemsN[] = new int[Config.BANK_SIZE];
  1092.             public boolean bankNotes = false;
  1093.             public boolean gdegradeNow = false;
  1094.      
  1095.             public int playerStandIndex = 0x328;
  1096.             public int playerTurnIndex = 0x337;
  1097.             public int playerWalkIndex = 0x333;
  1098.             public int playerTurn180Index = 0x334;
  1099.             public int playerTurn90CWIndex = 0x335;
  1100.             public int playerTurn90CCWIndex = 0x336;
  1101.             public int playerRunIndex = 0x338;
  1102.      
  1103.             public int playerHat = 0;
  1104.             public int playerCape = 1;
  1105.             public int playerAmulet = 2;
  1106.             public int playerWeapon = 3;
  1107.             public int playerChest = 4;
  1108.             public int playerShield = 5;
  1109.             public int playerLegs = 7;
  1110.             public int playerHands = 9;
  1111.             public int playerFeet = 10;
  1112.             public int playerRing = 12;
  1113.             public int playerArrows = 13;
  1114.      
  1115.             public int playerAttack = 0;
  1116.             public int playerDefence = 1;
  1117.             public int playerStrength = 2;
  1118.             public int playerHitpoints = 3;
  1119.             public int playerRanged = 4;
  1120.             public int playerPrayer = 5;
  1121.             public int playerMagic = 6;
  1122.             public int playerCooking = 7;
  1123.             public int playerWoodcutting = 8;
  1124.             public int playerFletching = 9;
  1125.             public int playerFishing = 10;
  1126.             public int playerFiremaking = 11;
  1127.             public int playerCrafting = 12;
  1128.             public int playerSmithing = 13;
  1129.             public int playerMining = 14;
  1130.             public int playerHerblore = 15;
  1131.             public int playerAgility = 16;
  1132.             public int playerThieving = 17;
  1133.             public int playerSlayer = 18;
  1134.             public int playerFarming = 19;
  1135.             public int playerRunecrafting = 20;
  1136.      
  1137.             public int[] playerEquipment = new int[14];
  1138.             public int[] playerEquipmentN = new int[14];
  1139.             public int[] playerLevel = new int[25];
  1140.             public int[] playerXP = new int[25];
  1141.      
  1142.             public void updateshop(int i) {
  1143.                     Client p = (Client) PlayerHandler.players[playerId];
  1144.                     p.getShops().resetShop(i);
  1145.             }
  1146.      
  1147.             public void println_debug(String str) {
  1148.                     System.out.println("[player-" + playerId + "]: " + str);
  1149.             }
  1150.      
  1151.             public void println(String str) {
  1152.                     System.out.println("[player-" + playerId + "]: " + str);
  1153.             }
  1154.      
  1155.             public Player(int _playerId) {
  1156.                     playerId = _playerId;
  1157.                     playerRights = 0;
  1158.      
  1159.                     for (int i = 0; i < playerItems.length; i++) {
  1160.                             playerItems[i] = 0;
  1161.                     }
  1162.                     for (int i = 0; i < playerItemsN.length; i++) {
  1163.                             playerItemsN[i] = 0;
  1164.                     }
  1165.      
  1166.                     for (int i = 0; i < playerLevel.length; i++) {
  1167.                             if (i == 3) {
  1168.                                     playerLevel[i] = 10;
  1169.                             } else {
  1170.                                     playerLevel[i] = 1;
  1171.                             }
  1172.                     }
  1173.      
  1174.                     for (int i = 0; i < playerXP.length; i++) {
  1175.                             if (i == 3) {
  1176.                                     playerXP[i] = 1300;
  1177.                             } else {
  1178.                                     playerXP[i] = 0;
  1179.                             }
  1180.                     }
  1181.                     for (int i = 0; i < Config.BANK_SIZE; i++) {
  1182.                             bankItems[i] = 0;
  1183.                     }
  1184.      
  1185.                     for (int i = 0; i < Config.BANK_SIZE; i++) {
  1186.                             bankItemsN[i] = 0;
  1187.                     }
  1188.      
  1189.                     playerAppearance[0] = 0; // gender
  1190.                     playerAppearance[1] = 0; // head
  1191.                     playerAppearance[2] = 18;// Torso
  1192.                     playerAppearance[3] = 26; // arms
  1193.                     playerAppearance[4] = 33; // hands
  1194.                     playerAppearance[5] = 36; // legs
  1195.                     playerAppearance[6] = 42; // feet
  1196.                     playerAppearance[7] = 10; // beard
  1197.                     playerAppearance[8] = 0; // hair colour
  1198.                     playerAppearance[9] = 0; // torso colour
  1199.                     playerAppearance[10] = 0; // legs colour
  1200.                     playerAppearance[11] = 0; // feet colour
  1201.                     playerAppearance[12] = 0; // skin colour
  1202.      
  1203.                     apset = 0;
  1204.                     actionID = 0;
  1205.      
  1206.                     playerEquipment[playerHat] = -1;
  1207.                     playerEquipment[playerCape] = -1;
  1208.                     playerEquipment[playerAmulet] = -1;
  1209.                     playerEquipment[playerChest] = -1;
  1210.                     playerEquipment[playerShield] = -1;
  1211.                     playerEquipment[playerLegs] = -1;
  1212.                     playerEquipment[playerHands] = -1;
  1213.                     playerEquipment[playerFeet] = -1;
  1214.                     playerEquipment[playerRing] = -1;
  1215.                     playerEquipment[playerArrows] = -1;
  1216.                     playerEquipment[playerWeapon] = -1;
  1217.      
  1218.                     heightLevel = 0;
  1219.      
  1220.                     teleportToX = Config.START_LOCATION_X;
  1221.                     teleportToY = Config.START_LOCATION_Y;
  1222.      
  1223.                     absX = absY = -1;
  1224.                     mapRegionX = mapRegionY = -1;
  1225.                     currentX = currentY = 0;
  1226.                     resetWalkingQueue();
  1227.             }
  1228.      
  1229.             void destruct() {
  1230.                     playerListSize = 0;
  1231.                     for (int i = 0; i < maxPlayerListSize; i++)
  1232.                             playerList[i] = null;
  1233.                     absX = absY = -1;
  1234.                     mapRegionX = mapRegionY = -1;
  1235.                     currentX = currentY = 0;
  1236.                     resetWalkingQueue();
  1237.             }
  1238.      
  1239.             public static final int maxPlayerListSize = Config.MAX_PLAYERS;
  1240.             public Player playerList[] = new Player[maxPlayerListSize];
  1241.             public int playerListSize = 0;
  1242.      
  1243.             public byte playerInListBitmap[] = new byte[(Config.MAX_PLAYERS + 7) >> 3];
  1244.      
  1245.             public static final int maxNPCListSize = NPCHandler.maxNPCs;
  1246.             public NPC npcList[] = new NPC[maxNPCListSize];
  1247.             public int npcListSize = 0;
  1248.      
  1249.             public byte npcInListBitmap[] = new byte[(NPCHandler.maxNPCs + 7) >> 3];
  1250.      
  1251.             public boolean WithinDistance(int objectX, int objectY, int playerX,
  1252.                             int playerY, int distance) {
  1253.                     for (int i = 0; i <= distance; i++) {
  1254.                             for (int j = 0; j <= distance; j++) {
  1255.                                     if ((objectX + i) == playerX
  1256.                                                     && ((objectY + j) == playerY
  1257.                                                                     || (objectY - j) == playerY || objectY == playerY)) {
  1258.                                             return true;
  1259.                                     } else if ((objectX - i) == playerX
  1260.                                                     && ((objectY + j) == playerY
  1261.                                                                     || (objectY - j) == playerY || objectY == playerY)) {
  1262.                                             return true;
  1263.                                     } else if (objectX == playerX
  1264.                                                     && ((objectY + j) == playerY
  1265.                                                                     || (objectY - j) == playerY || objectY == playerY)) {
  1266.                                             return true;
  1267.                                     }
  1268.                             }
  1269.                     }
  1270.                     return false;
  1271.             }      
  1272.            
  1273.             public boolean withinDistance(Player otherPlr) {
  1274.                     if (heightLevel != otherPlr.heightLevel)
  1275.                             return false;
  1276.                     int deltaX = otherPlr.absX - absX, deltaY = otherPlr.absY - absY;
  1277.                     return deltaX <= 15 && deltaX >= -16 && deltaY <= 15 && deltaY >= -16;
  1278.             }
  1279.      
  1280.             public boolean withinDistance(NPC npc) {
  1281.                     if (heightLevel != npc.heightLevel)
  1282.                             return false;
  1283.                     if (npc.needRespawn == true)
  1284.                             return false;
  1285.                     int deltaX = npc.absX - absX, deltaY = npc.absY - absY;
  1286.                     return deltaX <= 15 && deltaX >= -16 && deltaY <= 15 && deltaY >= -16;
  1287.             }
  1288.      
  1289.             public boolean withinDistance(int absX, int getY, int getHeightLevel) {
  1290.                     if (this.getHeightLevel() != getHeightLevel)
  1291.                             return false;
  1292.                     int deltaX = this.getX() - absX, deltaY = this.getY() - getY;
  1293.                     return deltaX <= 15 && deltaX >= -16 && deltaY <= 15 && deltaY >= -16;
  1294.             }
  1295.      
  1296.             public int getHeightLevel;
  1297.      
  1298.             public int getHeightLevel() {
  1299.                     return getHeightLevel;
  1300.             }
  1301.      
  1302.             public int distanceToPoint(int pointX, int pointY) {
  1303.                     return (int) Math.sqrt(Math.pow(absX - pointX, 2)
  1304.                                     + Math.pow(absY - pointY, 2));
  1305.             }
  1306.      
  1307.             public int mapRegionX, mapRegionY;
  1308.             public int absX, absY;
  1309.             public int currentX, currentY;
  1310.      
  1311.             public int heightLevel;
  1312.             public int playerSE = 0x328;
  1313.             public int playerSEW = 0x333;
  1314.             public int playerSER = 0x334;
  1315.      
  1316.             //public boolean updateRequired = true;
  1317.      
  1318.             public final int walkingQueueSize = 50;
  1319.             public int walkingQueueX[] = new int[walkingQueueSize],
  1320.                             walkingQueueY[] = new int[walkingQueueSize];
  1321.             public int wQueueReadPtr = 0;
  1322.             public int wQueueWritePtr = 0;
  1323.             public boolean isRunning = true;
  1324.             public int teleportToX = -1, teleportToY = -1;
  1325.      
  1326.             public void resetWalkingQueue() {
  1327.                     wQueueReadPtr = wQueueWritePtr = 0;
  1328.      
  1329.                     for (int i = 0; i < walkingQueueSize; i++) {
  1330.                             walkingQueueX[i] = currentX;
  1331.                             walkingQueueY[i] = currentY;
  1332.                     }
  1333.             }
  1334.      
  1335.             public void addToWalkingQueue(int x, int y) {
  1336.                     // if (VirtualWorld.I(heightLevel, absX, absY, x, y, 0)) {
  1337.                     int next = (wQueueWritePtr + 1) % walkingQueueSize;
  1338.                     if (next == wQueueWritePtr)
  1339.                             return;
  1340.                     walkingQueueX[wQueueWritePtr] = x;
  1341.                     walkingQueueY[wQueueWritePtr] = y;
  1342.                     wQueueWritePtr = next;
  1343.                     // }
  1344.             }
  1345.      
  1346.             public boolean goodDistance(int objectX, int objectY, int playerX,
  1347.                             int playerY, int distance) {
  1348.                     for (int i = 0; i <= distance; i++) {
  1349.                             for (int j = 0; j <= distance; j++) {
  1350.                                     if ((objectX + i) == playerX
  1351.                                                     && ((objectY + j) == playerY
  1352.                                                                     || (objectY - j) == playerY || objectY == playerY)) {
  1353.                                             return true;
  1354.                                     } else if ((objectX - i) == playerX
  1355.                                                     && ((objectY + j) == playerY
  1356.                                                                     || (objectY - j) == playerY || objectY == playerY)) {
  1357.                                             return true;
  1358.                                     } else if (objectX == playerX
  1359.                                                     && ((objectY + j) == playerY
  1360.                                                                     || (objectY - j) == playerY || objectY == playerY)) {
  1361.                                             return true;
  1362.                                     }
  1363.                             }
  1364.                     }
  1365.                     return false;
  1366.             }
  1367.      
  1368.             public int getNextWalkingDirection() {
  1369.                     if (wQueueReadPtr == wQueueWritePtr)
  1370.                             return -1;
  1371.                     int dir;
  1372.                     do {
  1373.                             dir = Misc.direction(currentX, currentY,
  1374.                                             walkingQueueX[wQueueReadPtr], walkingQueueY[wQueueReadPtr]);
  1375.                             if (dir == -1) {
  1376.                                     wQueueReadPtr = (wQueueReadPtr + 1) % walkingQueueSize;
  1377.                             } else if ((dir & 1) != 0) {
  1378.                                     println_debug("Invalid waypoint in walking queue!");
  1379.                                     resetWalkingQueue();
  1380.                                     return -1;
  1381.                             }
  1382.                     } while ((dir == -1) && (wQueueReadPtr != wQueueWritePtr));
  1383.                     if (dir == -1)
  1384.                             return -1;
  1385.                     dir >>= 1;
  1386.                     currentX += Misc.directionDeltaX[dir];
  1387.                     currentY += Misc.directionDeltaY[dir];
  1388.                     absX += Misc.directionDeltaX[dir];
  1389.                     absY += Misc.directionDeltaY[dir];
  1390.                     if (isRunning()) {
  1391.                             Client c = (Client) this;
  1392.                             if (runEnergy > 0) {
  1393.                                     runEnergy--;
  1394.                                     c.getPA().sendFrame126(runEnergy + "%", 149);
  1395.                             } else {
  1396.                                     isRunning2 = false;
  1397.                                     c.getPA().setConfig(173, 0);
  1398.                             }
  1399.                     }
  1400.                     return dir;
  1401.             }
  1402.      
  1403.             public int runEnergy = 100;
  1404.             public long lastRunRecovery;
  1405.      
  1406.             public boolean isRunning() {
  1407.                     return isNewWalkCmdIsRunning() || (isRunning2 && isMoving);
  1408.             }
  1409.      
  1410.             public boolean didTeleport = false;
  1411.             public boolean mapRegionDidChange = false;
  1412.             public int dir1 = -1, dir2 = -1;
  1413.             public boolean createItems = false;
  1414.             public int poimiX = 0, poimiY = 0;
  1415.      
  1416.             public synchronized void getNextPlayerMovement() {
  1417.                     mapRegionDidChange = false;
  1418.                     didTeleport = false;
  1419.                     dir1 = dir2 = -1;
  1420.      
  1421.                     if (teleportToX != -1 && teleportToY != -1) {
  1422.                             mapRegionDidChange = true;
  1423.                             if (mapRegionX != -1 && mapRegionY != -1) {
  1424.                                     int relX = teleportToX - mapRegionX * 8, relY = teleportToY
  1425.                                                     - mapRegionY * 8;
  1426.                                     if (relX >= 2 * 8 && relX < 11 * 8 && relY >= 2 * 8
  1427.                                                     && relY < 11 * 8)
  1428.                                             mapRegionDidChange = false;
  1429.                             }
  1430.                             if (mapRegionDidChange) {
  1431.                                     mapRegionX = (teleportToX >> 3) - 6;
  1432.                                     mapRegionY = (teleportToY >> 3) - 6;
  1433.                             }
  1434.                             currentX = teleportToX - 8 * mapRegionX;
  1435.                             currentY = teleportToY - 8 * mapRegionY;
  1436.                             absX = teleportToX;
  1437.                             absY = teleportToY;
  1438.                             resetWalkingQueue();
  1439.      
  1440.                             teleportToX = teleportToY = -1;
  1441.                             didTeleport = true;
  1442.                     } else {
  1443.                             dir1 = getNextWalkingDirection();
  1444.                             if (dir1 == -1)
  1445.                                     return;
  1446.                             if (isRunning) {
  1447.                                     dir2 = getNextWalkingDirection();
  1448.                             }
  1449.                             Client c = (Client) this;
  1450.                             // c.sendMessage("Cycle Ended");
  1451.                             int deltaX = 0, deltaY = 0;
  1452.                             if (currentX < 2 * 8) {
  1453.                                     deltaX = 4 * 8;
  1454.                                     mapRegionX -= 4;
  1455.                                     mapRegionDidChange = true;
  1456.                             } else if (currentX >= 11 * 8) {
  1457.                                     deltaX = -4 * 8;
  1458.                                     mapRegionX += 4;
  1459.                                     mapRegionDidChange = true;
  1460.                             }
  1461.                             if (currentY < 2 * 8) {
  1462.                                     deltaY = 4 * 8;
  1463.                                     mapRegionY -= 4;
  1464.                                     mapRegionDidChange = true;
  1465.                             } else if (currentY >= 11 * 8) {
  1466.                                     deltaY = -4 * 8;
  1467.                                     mapRegionY += 4;
  1468.                                     mapRegionDidChange = true;
  1469.                             }
  1470.      
  1471.                             if (mapRegionDidChange/*
  1472.                                                                      * && VirtualWorld.I(heightLevel, currentX,
  1473.                                                                      * currentY, currentX + deltaX, currentY +
  1474.                                                                      * deltaY, 0)
  1475.                                                                      */) {
  1476.                                     currentX += deltaX;
  1477.                                     currentY += deltaY;
  1478.                                     for (int i = 0; i < walkingQueueSize; i++) {
  1479.                                             walkingQueueX[i] += deltaX;
  1480.                                             walkingQueueY[i] += deltaY;
  1481.                                     }
  1482.                             }
  1483.                             // CoordAssistant.processCoords(this);
  1484.      
  1485.                     }
  1486.             }
  1487.      
  1488.             public void updateThisPlayerMovement(Stream str) {
  1489.                     // synchronized(this) {
  1490.                     if (mapRegionDidChange) {
  1491.                             str.createFrame(73);
  1492.                             str.writeWordA(mapRegionX + 6);
  1493.                             str.writeWord(mapRegionY + 6);
  1494.                     }
  1495.      
  1496.                     if (didTeleport) {
  1497.                             str.createFrameVarSizeWord(81);
  1498.                             str.initBitAccess();
  1499.                             str.writeBits(1, 1);
  1500.                             str.writeBits(2, 3);
  1501.                             str.writeBits(2, heightLevel);
  1502.                             str.writeBits(1, 1);
  1503.                             str.writeBits(1, (updateRequired) ? 1 : 0);
  1504.                             str.writeBits(7, currentY);
  1505.                             str.writeBits(7, currentX);
  1506.                             return;
  1507.                     }
  1508.      
  1509.                     if (dir1 == -1) {
  1510.                             // don't have to update the character position, because we're just
  1511.                             // standing
  1512.                             str.createFrameVarSizeWord(81);
  1513.                             str.initBitAccess();
  1514.                             isMoving = false;
  1515.                             if (updateRequired) {
  1516.                                     // tell client there's an update block appended at the end
  1517.                                     str.writeBits(1, 1);
  1518.                                     str.writeBits(2, 0);
  1519.                             } else {
  1520.                                     str.writeBits(1, 0);
  1521.                             }
  1522.                             if (DirectionCount < 50) {
  1523.                                     DirectionCount++;
  1524.                             }
  1525.                     } else {
  1526.                             DirectionCount = 0;
  1527.                             str.createFrameVarSizeWord(81);
  1528.                             str.initBitAccess();
  1529.                             str.writeBits(1, 1);
  1530.      
  1531.                             if (dir2 == -1) {
  1532.                                     isMoving = true;
  1533.                                     str.writeBits(2, 1);
  1534.                                     str.writeBits(3, Misc.xlateDirectionToClient[dir1]);
  1535.                                     if (updateRequired)
  1536.                                             str.writeBits(1, 1);
  1537.                                     else
  1538.                                             str.writeBits(1, 0);
  1539.                             } else {
  1540.                                     isMoving = true;
  1541.                                     str.writeBits(2, 2);
  1542.                                     str.writeBits(3, Misc.xlateDirectionToClient[dir1]);
  1543.                                     str.writeBits(3, Misc.xlateDirectionToClient[dir2]);
  1544.                                     if (updateRequired)
  1545.                                             str.writeBits(1, 1);
  1546.                                     else
  1547.                                             str.writeBits(1, 0);
  1548.                             }
  1549.                     }
  1550.      
  1551.             }
  1552.      
  1553.             public void updatePlayerMovement(Stream str) {
  1554.                     // synchronized(this) {
  1555.                     if (dir1 == -1) {
  1556.                             if (updateRequired || isChatTextUpdateRequired()) {
  1557.      
  1558.                                     str.writeBits(1, 1);
  1559.                                     str.writeBits(2, 0);
  1560.                             } else
  1561.                                     str.writeBits(1, 0);
  1562.                     } else if (dir2 == -1) {
  1563.      
  1564.                             str.writeBits(1, 1);
  1565.                             str.writeBits(2, 1);
  1566.                             str.writeBits(3, Misc.xlateDirectionToClient[dir1]);
  1567.                             str.writeBits(1, (updateRequired || isChatTextUpdateRequired()) ? 1
  1568.                                             : 0);
  1569.                     } else {
  1570.      
  1571.                             str.writeBits(1, 1);
  1572.                             str.writeBits(2, 2);
  1573.                             str.writeBits(3, Misc.xlateDirectionToClient[dir1]);
  1574.                             str.writeBits(3, Misc.xlateDirectionToClient[dir2]);
  1575.                             str.writeBits(1, (updateRequired || isChatTextUpdateRequired()) ? 1
  1576.                                             : 0);
  1577.                     }
  1578.      
  1579.             }
  1580.      
  1581.             public byte cachedPropertiesBitmap[] = new byte[(Config.MAX_PLAYERS + 7) >> 3];
  1582.      
  1583.             public void addNewNPC(NPC npc, Stream str, Stream updateBlock) {
  1584.                     // synchronized(this) {
  1585.                     int id = npc.npcId;
  1586.                     npcInListBitmap[id >> 3] |= 1 << (id & 7);
  1587.                     npcList[npcListSize++] = npc;
  1588.      
  1589.                     str.writeBits(14, id);
  1590.      
  1591.                     int z = npc.absY - absY;
  1592.                     if (z < 0)
  1593.                             z += 32;
  1594.                     str.writeBits(5, z);
  1595.                     z = npc.absX - absX;
  1596.                     if (z < 0)
  1597.                             z += 32;
  1598.                     str.writeBits(5, z);
  1599.      
  1600.                     str.writeBits(1, 0);
  1601.                     str.writeBits(14, npc.npcType);
  1602.      
  1603.                     boolean savedUpdateRequired = npc.updateRequired;
  1604.                     npc.updateRequired = true;
  1605.                     npc.appendNPCUpdateBlock(updateBlock);
  1606.                     npc.updateRequired = savedUpdateRequired;
  1607.                     str.writeBits(1, 1);
  1608.             }
  1609.      
  1610.             public void addNewPlayer(Player plr, Stream str, Stream updateBlock) {
  1611.                     // synchronized(this) {
  1612.                     if (playerListSize >= 255) {
  1613.                             return;
  1614.                     }
  1615.                     int id = plr.playerId;
  1616.                     playerInListBitmap[id >> 3] |= 1 << (id & 7);
  1617.                     playerList[playerListSize++] = plr;
  1618.                     str.writeBits(11, id);
  1619.                     str.writeBits(1, 1);
  1620.                     boolean savedFlag = plr.isAppearanceUpdateRequired();
  1621.                     boolean savedUpdateRequired = plr.updateRequired;
  1622.                     plr.setAppearanceUpdateRequired(true);
  1623.                     plr.updateRequired = true;
  1624.                     plr.appendPlayerUpdateBlock(updateBlock);
  1625.                     plr.setAppearanceUpdateRequired(savedFlag);
  1626.                     plr.updateRequired = savedUpdateRequired;
  1627.                     str.writeBits(1, 1);
  1628.                     int z = plr.absY - absY;
  1629.                     if (z < 0)
  1630.                             z += 32;
  1631.                     str.writeBits(5, z);
  1632.                     z = plr.absX - absX;
  1633.                     if (z < 0)
  1634.                             z += 32;
  1635.                     str.writeBits(5, z);
  1636.             }
  1637.      
  1638.             protected static Stream playerProps;
  1639.             static {
  1640.                     playerProps = new Stream(new byte[100]);
  1641.             }
  1642.      
  1643.             protected void appendPlayerAppearance(Stream str) {
  1644.                     playerProps.currentOffset = 0;
  1645.      
  1646.                     playerProps.writeByte(playerAppearance[0]);
  1647.      
  1648.                     playerProps.writeByte(playerTitle.length() > 0 ? 1 : 0);
  1649.                     playerProps.writeString(playerTitle);
  1650.                     playerProps.writeByte(titleColor);
  1651.                     playerProps.writeByte(nameColor);
  1652.                     playerProps.writeByte(headIcon);
  1653.                     playerProps.writeByte(headIconPk);
  1654.      
  1655.                     if (playerEquipment[playerHat] > 1) {
  1656.                             playerProps.writeWord(0x200 + playerEquipment[playerHat]);
  1657.                     } else {
  1658.                             playerProps.writeByte(0);
  1659.                     }
  1660.      
  1661.                     if (playerEquipment[playerCape] > 1) {
  1662.                             playerProps.writeWord(0x200 + playerEquipment[playerCape]);
  1663.                     } else {
  1664.                             playerProps.writeByte(0);
  1665.                     }
  1666.      
  1667.                     if (playerEquipment[playerAmulet] > 1) {
  1668.                             playerProps.writeWord(0x200 + playerEquipment[playerAmulet]);
  1669.                     } else {
  1670.                             playerProps.writeByte(0);
  1671.                     }
  1672.      
  1673.                     if (playerEquipment[playerWeapon] > 1) {
  1674.                             playerProps.writeWord(0x200 + playerEquipment[playerWeapon]);
  1675.                     } else {
  1676.                             playerProps.writeByte(0);
  1677.                     }
  1678.      
  1679.                     if (playerEquipment[playerChest] > 1) {
  1680.                             playerProps.writeWord(0x200 + playerEquipment[playerChest]);
  1681.                     } else {
  1682.                             playerProps.writeWord(0x100 + playerAppearance[2]);
  1683.                     }
  1684.      
  1685.                     if (playerEquipment[playerShield] > 1) {
  1686.                             playerProps.writeWord(0x200 + playerEquipment[playerShield]);
  1687.                     } else {
  1688.                             playerProps.writeByte(0);
  1689.                     }
  1690.      
  1691.                     if (!Item.isFullBody(playerEquipment[playerChest])) {
  1692.                             playerProps.writeWord(0x100 + playerAppearance[3]);
  1693.                     } else {
  1694.                             playerProps.writeByte(0);
  1695.                     }
  1696.      
  1697.                     if (playerEquipment[playerLegs] > 1) {
  1698.                             playerProps.writeWord(0x200 + playerEquipment[playerLegs]);
  1699.                     } else {
  1700.                             playerProps.writeWord(0x100 + playerAppearance[5]);
  1701.                     }
  1702.      
  1703.                     if (!Item.isFullHelm(playerEquipment[playerHat])
  1704.                                     && !Item.isFullMask(playerEquipment[playerHat])) {
  1705.                             playerProps.writeWord(0x100 + playerAppearance[1]);
  1706.                     } else {
  1707.                             playerProps.writeByte(0);
  1708.                     }
  1709.      
  1710.                     if (playerEquipment[playerHands] > 1) {
  1711.                             playerProps.writeWord(0x200 + playerEquipment[playerHands]);
  1712.                     } else {
  1713.                             playerProps.writeWord(0x100 + playerAppearance[4]);
  1714.                     }
  1715.      
  1716.                     if (playerEquipment[playerFeet] > 1) {
  1717.                             playerProps.writeWord(0x200 + playerEquipment[playerFeet]);
  1718.                     } else {
  1719.                             playerProps.writeWord(0x100 + playerAppearance[6]);
  1720.                     }
  1721.      
  1722.                     if (playerAppearance[0] != 1
  1723.                                     && !Item.isFullMask(playerEquipment[playerHat])) {
  1724.                             playerProps.writeWord(0x100 + playerAppearance[7]);
  1725.                     } else {
  1726.                             playerProps.writeByte(0);
  1727.                     }
  1728.      
  1729.                     playerProps.writeByte(playerAppearance[8]);
  1730.                     playerProps.writeByte(playerAppearance[9]);
  1731.                     playerProps.writeByte(playerAppearance[10]);
  1732.                     playerProps.writeByte(playerAppearance[11]);
  1733.                     playerProps.writeByte(playerAppearance[12]);
  1734.                     playerProps.writeWord(playerStandIndex); // standAnimIndex
  1735.                     playerProps.writeWord(playerTurnIndex); // standTurnAnimIndex
  1736.                     playerProps.writeWord(playerWalkIndex); // walkAnimIndex
  1737.                     playerProps.writeWord(playerTurn180Index); // turn180AnimIndex
  1738.                     playerProps.writeWord(playerTurn90CWIndex); // turn90CWAnimIndex
  1739.                     playerProps.writeWord(playerTurn90CCWIndex); // turn90CCWAnimIndex
  1740.                     playerProps.writeWord(playerRunIndex); // runAnimIndex
  1741.      
  1742.                     playerProps.writeQWord(Misc.playerNameToInt64(playerName));
  1743.      
  1744.                     /*
  1745.                      * int mag = (int) ((getLevelForXP(playerXP[6])) * 1.5); int ran = (int)
  1746.                      * ((getLevelForXP(playerXP[4])) * 1.5); int attstr = (int) ((double)
  1747.                      * (getLevelForXP(playerXP[0])) + (double)
  1748.                      * (getLevelForXP(playerXP[2])));
  1749.                      *
  1750.                      * combatLevel = 0; if (ran > attstr) { combatLevel = (int)
  1751.                      * (((getLevelForXP(playerXP[1])) * 0.25) +
  1752.                      * ((getLevelForXP(playerXP[3])) * 0.25) + ((getLevelForXP(playerXP[5]))
  1753.                      * * 0.125) + ((getLevelForXP(playerXP[4])) * 0.4875)); } else if (mag >
  1754.                      * attstr) { combatLevel = (int) (((getLevelForXP(playerXP[1])) * 0.25)
  1755.                      * + ((getLevelForXP(playerXP[3])) * 0.25) +
  1756.                      * ((getLevelForXP(playerXP[5])) * 0.125) +
  1757.                      * ((getLevelForXP(playerXP[6])) * 0.4875)); } else { combatLevel =
  1758.                      * (int) (((getLevelForXP(playerXP[1])) * 0.25) +
  1759.                      * ((getLevelForXP(playerXP[3])) * 0.25) + ((getLevelForXP(playerXP[5]))
  1760.                      * * 0.125) + ((getLevelForXP(playerXP[0])) * 0.325) +
  1761.                      * ((getLevelForXP(playerXP[2])) * 0.325)); }
  1762.                      */
  1763.                      int combat = 0;
  1764.                      int mag = (int) (realLevel(6) * 1.5);
  1765.         int ran = (int) (realLevel(4) * 1.5);
  1766.         int attstr = (int) (realLevel(0) + realLevel(2));
  1767.         if (ran > attstr) {
  1768.             combat = (int) ((realLevel(1) * 0.25) + (realLevel(3) * 0.25)
  1769.                     + (realLevel(5) * 0.125)
  1770.                     + (realLevel(4) * 0.4875));
  1771.         } else if (mag > attstr) {
  1772.             combat = (int) ((realLevel(1) * 0.25) + (realLevel(3) * 0.25)
  1773.                     + (realLevel(5) * 0.125)
  1774.                     + (realLevel(6) * 0.4875));//+ (realLevel[23] * 0.121212)
  1775.         } else {
  1776.             combat = (int) ((realLevel(1) * 0.25) + (realLevel(3) * 0.25)
  1777.                     + (realLevel(5) * 0.125)
  1778.                     + (realLevel(0) * 0.325)
  1779.                     + (realLevel(2) * 0.325));
  1780.         }
  1781.         //  combat += Math.round(realLevel(23) * 0.121212);
  1782.            
  1783.                     playerProps.writeByte(combat); // combat level
  1784.                     playerProps.writeWord(10);
  1785.                     str.writeByteC(playerProps.currentOffset);
  1786.                     str.writeBytes(playerProps.buffer, playerProps.currentOffset, 0);
  1787.             }
  1788.     public int realLevel(int skill){
  1789.     return getLevelForXP(playerXP[skill]);
  1790.     }
  1791.             public int getLevelForXP(int exp) {
  1792.                     int points = 0;
  1793.                     int output = 0;
  1794.      
  1795.                     for (int lvl = 1; lvl <= 99; lvl++) {
  1796.                             points += Math.floor(lvl + 300.0 * Math.pow(2.0, lvl / 7.0));
  1797.                             output = (int) Math.floor(points / 4);
  1798.                             if (output >= exp)
  1799.                                     return lvl;
  1800.                     }
  1801.                     return 99;
  1802.             }
  1803.      
  1804.             private boolean chatTextUpdateRequired = false;
  1805.             private byte chatText[] = new byte[4096];
  1806.             private byte chatTextSize = 0;
  1807.             private int chatTextColor = 0;
  1808.             private int chatTextEffects = 0;
  1809.      
  1810.             protected void appendPlayerChatText(Stream str) {
  1811.                     // synchronized(this) {
  1812.                     str.writeWordBigEndian(((getChatTextColor() & 0xFF) << 8)
  1813.                                     + (getChatTextEffects() & 0xFF));
  1814.                     str.writeByte(playerRights);
  1815.                     str.writeByteC(getChatTextSize());
  1816.                     str.writeBytes_reverse(getChatText(), getChatTextSize(), 0);
  1817.      
  1818.             }
  1819.      
  1820.             public void forcedChat(String text) {
  1821.                     forcedText = text;
  1822.                     forcedChatUpdateRequired = true;
  1823.                     updateRequired = true;
  1824.                     setAppearanceUpdateRequired(true);
  1825.             }
  1826.      
  1827.             public String forcedText = "null";
  1828.      
  1829.             public void appendForcedChat(Stream str) {
  1830.                     // synchronized(this) {
  1831.                     str.writeString(forcedText);
  1832.             }
  1833.      
  1834.             /**
  1835.              * Graphics
  1836.              **/
  1837.      
  1838.             public int mask100var1 = 0;
  1839.             public int mask100var2 = 0;
  1840.             protected boolean mask100update = false;
  1841.      
  1842.             public void appendMask100Update(Stream str) {
  1843.                     // synchronized(this) {
  1844.                     str.writeWordBigEndian(mask100var1);
  1845.                     str.writeDWord(mask100var2);
  1846.      
  1847.             }
  1848.      
  1849.             public void gfx100(int gfx) {
  1850.                     mask100var1 = gfx;
  1851.                     mask100var2 = 6553600;
  1852.                     mask100update = true;
  1853.                     updateRequired = true;
  1854.             }
  1855.      
  1856.             public void gfx0(int gfx) {
  1857.                     mask100var1 = gfx;
  1858.                     mask100var2 = 65536;
  1859.                     mask100update = true;
  1860.                     updateRequired = true;
  1861.             }
  1862.      
  1863.             public boolean wearing2h() {
  1864.                     Client c = (Client) this;
  1865.                     String s = c.getItems().getItemName(c.playerEquipment[c.playerWeapon]);
  1866.                     if (s.contains("2h"))
  1867.                             return true;
  1868.                     else if (s.contains("godsword"))
  1869.                             return true;
  1870.                     return false;
  1871.             }
  1872.      
  1873.             /**
  1874.              * Animations
  1875.              **/
  1876.             public void startAnimation(int animId) {
  1877.                     if (wearing2h() && animId == 829)
  1878.                             return;
  1879.                     animationRequest = animId;
  1880.                     animationWaitCycles = 0;
  1881.                     updateRequired = true;
  1882.             }
  1883.      
  1884.             public void startAnimation(int animId, int time) {
  1885.                     animationRequest = animId;
  1886.                     animationWaitCycles = time;
  1887.                     updateRequired = true;
  1888.             }
  1889.      
  1890.             public void appendAnimationRequest(Stream str) {
  1891.                     // synchronized(this) {
  1892.                     str.writeWordBigEndian((animationRequest == -1) ? 65535
  1893.                                     : animationRequest);
  1894.                     str.writeByteC(animationWaitCycles);
  1895.      
  1896.             }
  1897.      
  1898.             /**
  1899.              * Face Update
  1900.              **/
  1901.      
  1902.             protected boolean faceUpdateRequired = false;
  1903.             public int face = -1;
  1904.             public int FocusPointX = -1, FocusPointY = -1;
  1905.      
  1906.             public void faceUpdate(int index) {
  1907.                     face = index;
  1908.                     faceUpdateRequired = true;
  1909.                     updateRequired = true;
  1910.             }
  1911.      
  1912.             public void appendFaceUpdate(Stream str) {
  1913.                     // synchronized(this) {
  1914.                     str.writeWordBigEndian(face);
  1915.      
  1916.             }
  1917.      
  1918.             public void turnPlayerTo(int pointX, int pointY) {
  1919.                     FocusPointX = 2 * pointX + 1;
  1920.                     FocusPointY = 2 * pointY + 1;
  1921.                     updateRequired = true;
  1922.             }
  1923.      
  1924.             private void appendSetFocusDestination(Stream str) {
  1925.                     // synchronized(this) {
  1926.                     str.writeWordBigEndianA(FocusPointX);
  1927.                     str.writeWordBigEndian(FocusPointY);
  1928.      
  1929.             }
  1930.      
  1931.             /**
  1932.              * Hit Update
  1933.              **/
  1934.      
  1935.             protected void appendHitUpdate(Stream str) {
  1936.                     // synchronized(this) {
  1937.                     str.writeByte(getHitDiff()); // What the perseon got 'hit' for
  1938.                     if (poisonMask == 1) {
  1939.                             str.writeByteA(2);
  1940.                     } else if (getHitDiff() > 0) {
  1941.                             str.writeByteA(1); // 0: red hitting - 1: blue hitting
  1942.                     } else {
  1943.                             str.writeByteA(0); // 0: red hitting - 1: blue hitting
  1944.                     }
  1945.                     if (playerLevel[3] <= 0) {
  1946.                             playerLevel[3] = 0;
  1947.                             isDead = true;
  1948.                     }
  1949.                     str.writeByteC(playerLevel[3]); // Their current hp, for HP bar
  1950.                     str.writeByte(getLevelForXP(playerXP[3])); // Their max hp, for HP bar
  1951.      
  1952.             }
  1953.      
  1954.             protected void appendHitUpdate2(Stream str) {
  1955.                     // synchronized(this) {
  1956.                     str.writeByte(hitDiff2); // What the perseon got 'hit' for
  1957.                     if (poisonMask == 2) {
  1958.                             str.writeByteS(2);
  1959.                             poisonMask = -1;
  1960.                     } else if (hitDiff2 > 0) {
  1961.                             str.writeByteS(1); // 0: red hitting - 1: blue hitting
  1962.                     } else {
  1963.                             str.writeByteS(0); // 0: red hitting - 1: blue hitting
  1964.                     }
  1965.                     if (playerLevel[3] <= 0) {
  1966.                             playerLevel[3] = 0;
  1967.                             isDead = true;
  1968.                     }
  1969.                     str.writeByte(playerLevel[3]); // Their current hp, for HP bar
  1970.                     str.writeByteC(getLevelForXP(playerXP[3])); // Their max hp, for HP bar
  1971.      
  1972.             }
  1973.      
  1974.             public void appendPlayerUpdateBlock(Stream str) {
  1975.                     // synchronized(this) {
  1976.                     if (!updateRequired && !isChatTextUpdateRequired())
  1977.                             return; // nothing required
  1978.                     int updateMask = 0;
  1979.                     if (mask100update) {
  1980.                             updateMask |= 0x100;
  1981.                     }
  1982.                     if (animationRequest != -1) {
  1983.                             updateMask |= 8;
  1984.                     }
  1985.                     if (forcedChatUpdateRequired) {
  1986.                             updateMask |= 4;
  1987.                     }
  1988.                     if (isChatTextUpdateRequired()) {
  1989.                             updateMask |= 0x80;
  1990.                     }
  1991.                     if (isAppearanceUpdateRequired()) {
  1992.                             updateMask |= 0x10;
  1993.                     }
  1994.                     if (faceUpdateRequired) {
  1995.                             updateMask |= 1;
  1996.                     }
  1997.                     if (FocusPointX != -1) {
  1998.                             updateMask |= 2;
  1999.                     }
  2000.                     if (isHitUpdateRequired()) {
  2001.                             updateMask |= 0x20;
  2002.                     }
  2003.      
  2004.                     if (hitUpdateRequired2) {
  2005.                             updateMask |= 0x200;
  2006.                     }
  2007.      
  2008.                     if (updateMask >= 0x100) {
  2009.                             updateMask |= 0x40;
  2010.                             str.writeByte(updateMask & 0xFF);
  2011.                             str.writeByte(updateMask >> 8);
  2012.                     } else {
  2013.                             str.writeByte(updateMask);
  2014.                     }
  2015.      
  2016.                     // now writing the various update blocks itself - note that their order
  2017.                     // crucial
  2018.                     if (mask100update) {
  2019.                             appendMask100Update(str);
  2020.                     }
  2021.                     if (animationRequest != -1) {
  2022.                             appendAnimationRequest(str);
  2023.                     }
  2024.                     if (forcedChatUpdateRequired) {
  2025.                             appendForcedChat(str);
  2026.                     }
  2027.                     if (isChatTextUpdateRequired()) {
  2028.                             appendPlayerChatText(str);
  2029.                     }
  2030.                     if (faceUpdateRequired) {
  2031.                             appendFaceUpdate(str);
  2032.                     }
  2033.                     if (isAppearanceUpdateRequired()) {
  2034.                             appendPlayerAppearance(str);
  2035.                     }
  2036.                     if (FocusPointX != -1) {
  2037.                             appendSetFocusDestination(str);
  2038.                     }
  2039.                     if (isHitUpdateRequired()) {
  2040.                             appendHitUpdate(str);
  2041.                     }
  2042.                     if (hitUpdateRequired2) {
  2043.                             appendHitUpdate2(str);
  2044.                     }
  2045.      
  2046.             }
  2047.      
  2048.             public void clearUpdateFlags() {
  2049.                     updateRequired = false;
  2050.                     setChatTextUpdateRequired(false);
  2051.                     setAppearanceUpdateRequired(false);
  2052.                     setHitUpdateRequired(false);
  2053.                     hitUpdateRequired2 = false;
  2054.                     forcedChatUpdateRequired = false;
  2055.                     mask100update = false;
  2056.                     animationRequest = -1;
  2057.                     FocusPointX = -1;
  2058.                     FocusPointY = -1;
  2059.                     poisonMask = -1;
  2060.                     faceUpdateRequired = false;
  2061.                     face = 65535;
  2062.             }
  2063.      
  2064.             public void stopMovement() {
  2065.                     if (teleportToX <= 0 && teleportToY <= 0) {
  2066.                             teleportToX = absX;
  2067.                             teleportToY = absY;
  2068.                     }
  2069.                     newWalkCmdSteps = 0;
  2070.                     getNewWalkCmdX()[0] = getNewWalkCmdY()[0] = travelBackX[0] = travelBackY[0] = 0;
  2071.                     getNextPlayerMovement();
  2072.             }
  2073.      
  2074.             private int newWalkCmdX[] = new int[walkingQueueSize];
  2075.             private int newWalkCmdY[] = new int[walkingQueueSize];
  2076.             public int newWalkCmdSteps = 0;
  2077.             private boolean newWalkCmdIsRunning = false;
  2078.             protected int travelBackX[] = new int[walkingQueueSize];
  2079.             protected int travelBackY[] = new int[walkingQueueSize];
  2080.             protected int numTravelBackSteps = 0;
  2081.      
  2082.             public void preProcessing() {
  2083.                     newWalkCmdSteps = 0;
  2084.             }
  2085.      
  2086.             public abstract void process();
  2087.      
  2088.             public abstract boolean processQueuedPackets();
  2089.      
  2090.             public synchronized void postProcessing() {
  2091.                     if (newWalkCmdSteps > 0) {
  2092.                             int firstX = getNewWalkCmdX()[0], firstY = getNewWalkCmdY()[0];
  2093.      
  2094.                             int lastDir = 0;
  2095.                             boolean found = false;
  2096.                             numTravelBackSteps = 0;
  2097.                             int ptr = wQueueReadPtr;
  2098.                             int dir = Misc.direction(currentX, currentY, firstX, firstY);
  2099.                             if (dir != -1 && (dir & 1) != 0) {
  2100.                                     do {
  2101.                                             lastDir = dir;
  2102.                                             if (--ptr < 0)
  2103.                                                     ptr = walkingQueueSize - 1;
  2104.      
  2105.                                             travelBackX[numTravelBackSteps] = walkingQueueX[ptr];
  2106.                                             travelBackY[numTravelBackSteps++] = walkingQueueY[ptr];
  2107.                                             dir = Misc.direction(walkingQueueX[ptr],
  2108.                                                             walkingQueueY[ptr], firstX, firstY);
  2109.                                             if (lastDir != dir) {
  2110.                                                     found = true;
  2111.                                                     break;
  2112.                                             }
  2113.      
  2114.                                     } while (ptr != wQueueWritePtr);
  2115.                             } else
  2116.                                     found = true;
  2117.      
  2118.                             if (!found)
  2119.                                     println_debug("Fatal: couldn't find connection vertex! Dropping packet.");
  2120.                             else {
  2121.                                     wQueueWritePtr = wQueueReadPtr;
  2122.      
  2123.                                     addToWalkingQueue(currentX, currentY);
  2124.      
  2125.                                     if (dir != -1 && (dir & 1) != 0) {
  2126.      
  2127.                                             for (int i = 0; i < numTravelBackSteps - 1; i++) {
  2128.                                                     addToWalkingQueue(travelBackX[i], travelBackY[i]);
  2129.                                             }
  2130.                                             int wayPointX2 = travelBackX[numTravelBackSteps - 1], wayPointY2 = travelBackY[numTravelBackSteps - 1];
  2131.                                             int wayPointX1, wayPointY1;
  2132.                                             if (numTravelBackSteps == 1) {
  2133.                                                     wayPointX1 = currentX;
  2134.                                                     wayPointY1 = currentY;
  2135.                                             } else {
  2136.                                                     wayPointX1 = travelBackX[numTravelBackSteps - 2];
  2137.                                                     wayPointY1 = travelBackY[numTravelBackSteps - 2];
  2138.                                             }
  2139.      
  2140.                                             dir = Misc.direction(wayPointX1, wayPointY1, wayPointX2,
  2141.                                                             wayPointY2);
  2142.                                             if (dir == -1 || (dir & 1) != 0) {
  2143.                                                     println_debug("Fatal: The walking queue is corrupt! wp1=("
  2144.                                                                     + wayPointX1
  2145.                                                                     + ", "
  2146.                                                                     + wayPointY1
  2147.                                                                     + "), "
  2148.                                                                     + "wp2=("
  2149.                                                                     + wayPointX2
  2150.                                                                     + ", "
  2151.                                                                     + wayPointY2
  2152.                                                                     + ")");
  2153.                                             } else {
  2154.                                                     dir >>= 1;
  2155.                                                     found = false;
  2156.                                                     int x = wayPointX1, y = wayPointY1;
  2157.                                                     while (x != wayPointX2 || y != wayPointY2) {
  2158.                                                             x += Misc.directionDeltaX[dir];
  2159.                                                             y += Misc.directionDeltaY[dir];
  2160.                                                             if ((Misc.direction(x, y, firstX, firstY) & 1) == 0) {
  2161.                                                                     found = true;
  2162.                                                                     break;
  2163.                                                             }
  2164.                                                     }
  2165.                                                     if (!found) {
  2166.                                                             println_debug("Fatal: Internal error: unable to determine connection vertex!"
  2167.                                                                             + "  wp1=("
  2168.                                                                             + wayPointX1
  2169.                                                                             + ", "
  2170.                                                                             + wayPointY1
  2171.                                                                             + "), wp2=("
  2172.                                                                             + wayPointX2
  2173.                                                                             + ", "
  2174.                                                                             + wayPointY2
  2175.                                                                             + "), "
  2176.                                                                             + "first=("
  2177.                                                                             + firstX + ", " + firstY + ")");
  2178.                                                     } else
  2179.                                                             addToWalkingQueue(wayPointX1, wayPointY1);
  2180.                                             }
  2181.                                     } else {
  2182.                                             for (int i = 0; i < numTravelBackSteps; i++) {
  2183.                                                     addToWalkingQueue(travelBackX[i], travelBackY[i]);
  2184.                                             }
  2185.                                     }
  2186.      
  2187.                                     for (int i = 0; i < newWalkCmdSteps; i++) {
  2188.                                             addToWalkingQueue(getNewWalkCmdX()[i], getNewWalkCmdY()[i]);
  2189.                                     }
  2190.      
  2191.                             }
  2192.      
  2193.                             isRunning = isNewWalkCmdIsRunning() || isRunning2;
  2194.                     }
  2195.             }
  2196.      
  2197.             public int getMapRegionX() {
  2198.                     return mapRegionX;
  2199.             }
  2200.      
  2201.             public int getMapRegionY() {
  2202.                     return mapRegionY;
  2203.             }
  2204.      
  2205.             public int getX() {
  2206.                     return absX;
  2207.             }
  2208.      
  2209.             public int getY() {
  2210.                     return absY;
  2211.             }
  2212.      
  2213.             public int getId() {
  2214.                     return playerId;
  2215.             }
  2216.      
  2217.             public boolean inPcBoat() {
  2218.                     return absX >= 2660 && absX <= 2663 && absY >= 2638 && absY <= 2643;
  2219.             }
  2220.      
  2221.             public boolean inPcGame() {
  2222.                     return absX >= 2624 && absX <= 2690 && absY >= 2550 && absY <= 2619;
  2223.             }
  2224.            
  2225.             public boolean isInBarrows() {        
  2226.                     return absX > 3543 && absX < 3584 && absY > 3265 && absY < 3311;
  2227.                     //      return true;
  2228.             }
  2229.            
  2230.             public boolean isInBarrows2() {        
  2231.                     return absX > 3529 && absX < 3581 && absY > 9673 && absY < 9722;
  2232.             }
  2233.      
  2234.             public void setHitDiff(int hitDiff) {
  2235.                     this.hitDiff = hitDiff;
  2236.             }
  2237.      
  2238.             public void setHitDiff2(int hitDiff2) {
  2239.                     this.hitDiff2 = hitDiff2;
  2240.             }
  2241.      
  2242.             public int getHitDiff() {
  2243.                     return hitDiff;
  2244.             }
  2245.      
  2246.             public int[][] barrowCrypt = {
  2247.                             {4921, 0},
  2248.                             {2035, 0}
  2249.             };
  2250.            
  2251.             public void setHitUpdateRequired(boolean hitUpdateRequired) {
  2252.                     this.hitUpdateRequired = hitUpdateRequired;
  2253.             }
  2254.      
  2255.             public void setHitUpdateRequired2(boolean hitUpdateRequired2) {
  2256.                     this.hitUpdateRequired2 = hitUpdateRequired2;
  2257.             }
  2258.      
  2259.             public boolean isHitUpdateRequired() {
  2260.                     return hitUpdateRequired;
  2261.             }
  2262.      
  2263.             public boolean getHitUpdateRequired() {
  2264.                     return hitUpdateRequired;
  2265.             }
  2266.      
  2267.             public boolean getHitUpdateRequired2() {
  2268.                     return hitUpdateRequired2;
  2269.             }
  2270.      
  2271.             public void setAppearanceUpdateRequired(boolean appearanceUpdateRequired) {
  2272.                     this.appearanceUpdateRequired = appearanceUpdateRequired;
  2273.             }
  2274.      
  2275.             public boolean isAppearanceUpdateRequired() {
  2276.                     return appearanceUpdateRequired;
  2277.             }
  2278.      
  2279.             public void setChatTextEffects(int chatTextEffects) {
  2280.                     this.chatTextEffects = chatTextEffects;
  2281.             }
  2282.      
  2283.             public int getChatTextEffects() {
  2284.                     return chatTextEffects;
  2285.             }
  2286.      
  2287.             public void setChatTextSize(byte chatTextSize) {
  2288.                     this.chatTextSize = chatTextSize;
  2289.             }
  2290.      
  2291.             public byte getChatTextSize() {
  2292.                     return chatTextSize;
  2293.             }
  2294.      
  2295.             public void setChatTextUpdateRequired(boolean chatTextUpdateRequired) {
  2296.                     this.chatTextUpdateRequired = chatTextUpdateRequired;
  2297.             }
  2298.      
  2299.             public boolean isChatTextUpdateRequired() {
  2300.                     return chatTextUpdateRequired;
  2301.             }
  2302.      
  2303.             public void setChatText(byte chatText[]) {
  2304.                     this.chatText = chatText;
  2305.             }
  2306.      
  2307.             public byte[] getChatText() {
  2308.                     return chatText;
  2309.             }
  2310.      
  2311.             public void setChatTextColor(int chatTextColor) {
  2312.                     this.chatTextColor = chatTextColor;
  2313.             }
  2314.      
  2315.             public int getChatTextColor() {
  2316.                     return chatTextColor;
  2317.             }
  2318.      
  2319.             public void setNewWalkCmdX(int newWalkCmdX[]) {
  2320.                     this.newWalkCmdX = newWalkCmdX;
  2321.             }
  2322.      
  2323.             public int[] getNewWalkCmdX() {
  2324.                     return newWalkCmdX;
  2325.             }
  2326.      
  2327.             public void setNewWalkCmdY(int newWalkCmdY[]) {
  2328.                     this.newWalkCmdY = newWalkCmdY;
  2329.             }
  2330.      
  2331.             public int[] getNewWalkCmdY() {
  2332.                     return newWalkCmdY;
  2333.             }
  2334.      
  2335.             public void setNewWalkCmdIsRunning(boolean newWalkCmdIsRunning) {
  2336.                     this.newWalkCmdIsRunning = newWalkCmdIsRunning;
  2337.             }
  2338.      
  2339.             public boolean isNewWalkCmdIsRunning() {
  2340.                     return newWalkCmdIsRunning;
  2341.             }
  2342.      
  2343.             public void setInStreamDecryption(ISAACRandomGen inStreamDecryption) {
  2344.             }
  2345.      
  2346.             public void setOutStreamDecryption(ISAACRandomGen outStreamDecryption) {
  2347.             }
  2348.      
  2349.      
  2350.             public boolean samePlayer() {
  2351.                     for (int j = 0; j < PlayerHandler.players.length; j++) {
  2352.                             if (j == playerId)
  2353.                                     continue;
  2354.                             if (PlayerHandler.players[j] != null) {
  2355.                                     if (PlayerHandler.players[j].playerName
  2356.                                                     .equalsIgnoreCase(playerName)) {
  2357.                                             disconnected = true;
  2358.                                             return true;
  2359.                                     }
  2360.                             }
  2361.                     }
  2362.                     return false;
  2363.             }
  2364.      
  2365.             public void putInCombat(int attacker) {
  2366.                     underAttackBy = attacker;
  2367.                     logoutDelay = System.currentTimeMillis();
  2368.                     singleCombatDelay = System.currentTimeMillis();
  2369.             }
  2370.      
  2371.             public void dealDamage(int damage) {
  2372.                     if (teleTimer <= 0)
  2373.                             playerLevel[3] -= damage;
  2374.                     else {
  2375.                             if (hitUpdateRequired)
  2376.                                     hitUpdateRequired = false;
  2377.                             if (hitUpdateRequired2)
  2378.                                     hitUpdateRequired2 = false;
  2379.                     }
  2380.      
  2381.             }
  2382.      
  2383.             public int[] damageTaken = new int[Config.MAX_PLAYERS];
  2384.      
  2385.             public void handleHitMask(int damage) {
  2386.                     if (!hitUpdateRequired) {
  2387.                             hitUpdateRequired = true;
  2388.                             hitDiff = damage;
  2389.                     } else if (!hitUpdateRequired2) {
  2390.                             hitUpdateRequired2 = true;
  2391.                             hitDiff2 = damage;
  2392.                     }
  2393.                     updateRequired = true;
  2394.             }
  2395.      
  2396.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement