Guest User

Untitled

a guest
May 18th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 435.12 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.BufferedWriter;
  3. import java.io.FileNotFoundException;
  4. import java.io.FileReader;
  5. import java.io.FileWriter;
  6. import java.io.IOException;
  7. import java.util.Random;
  8. import java.util.concurrent.CopyOnWriteArrayList;
  9.  
  10.  
  11. public class Client extends Player implements Runnable {
  12.    
  13.  
  14.    
  15.  
  16.     /**
  17.      * teleEffect ints
  18.      */
  19.     public int teleEffect = 0;
  20.    
  21.    
  22.    
  23.    
  24.  
  25.     public int fletchAmount = -1;
  26.     public int fletchTimer = 0;
  27.  
  28.     /**
  29.      *List of Potions for Dose Mixing
  30.      */
  31.     public static final int potions[][] = { { 229, 125, 123, 121, 2428 },
  32.             { 229, 179, 177, 175, 2446 }, { 229, 119, 117, 115, 113 },
  33.             { 229, 131, 129, 127, 2430 }, { 229, 137, 135, 133, 2432 },
  34.             { 229, 143, 141, 139, 2434 }, { 229, 149, 147, 145, 2436 },
  35.             { 229, 161, 159, 157, 2440 }, { 229, 3030, 3028, 3026, 3024 },
  36.             { 229, 167, 165, 163, 2442 }, { 229, 6691, 6689, 6687, 6685 } };
  37.     // End Potion List
  38.  
  39.     /**
  40.      *Special Regain
  41.      */
  42.     public boolean specRegain = true;
  43.  
  44.     /**
  45.      *Arrow Dropping On Ground
  46.      */
  47.     public void DropArrows() {
  48.         int EnemyX = PlayerHandler.players[AttackingOn].absX;
  49.         int EnemyY = PlayerHandler.players[AttackingOn].absY;
  50.         if (playerEquipment[playerWeapon] != 4214
  51.                 && playerEquipmentN[playerArrows] != 0)
  52.             if (ItemHandler.itemAmount(playerEquipment[playerArrows], EnemyX,
  53.                     EnemyY) == 0) {
  54.                 ItemHandler.addItem(playerEquipment[playerArrows], EnemyX,
  55.                         EnemyY, 1, playerId, false);
  56.             } else if (ItemHandler.itemAmount(playerEquipment[playerArrows],
  57.                     EnemyX, EnemyY) != 0) {
  58.                 int amount = ItemHandler.itemAmount(
  59.                         playerEquipment[playerArrows], EnemyX, EnemyY);
  60.                 ItemHandler.removeItem(playerEquipment[playerArrows], EnemyX,
  61.                         EnemyY, amount);
  62.                 ItemHandler.addItem(playerEquipment[playerArrows], EnemyX,
  63.                         EnemyY, amount + 1, playerId, false);
  64.             }
  65.     }
  66.  
  67.     public void DropArrowsNPC() {
  68.         int EnemyX = Server.npcHandler.npcs[attacknpc].absX;
  69.         int EnemyY = Server.npcHandler.npcs[attacknpc].absY;
  70.         if (playerEquipment[playerWeapon] != 4214
  71.                 && playerEquipmentN[playerArrows] != 0)
  72.             if (ItemHandler.itemAmount(playerEquipment[playerArrows], EnemyX,
  73.                     EnemyY) == 0) {
  74.                 ItemHandler.addItem(playerEquipment[playerArrows], EnemyX,
  75.                         EnemyY, 1, playerId, false);
  76.             } else if (ItemHandler.itemAmount(playerEquipment[playerArrows],
  77.                     EnemyX, EnemyY) != 0) {
  78.                 int amount = ItemHandler.itemAmount(
  79.                         playerEquipment[playerArrows], EnemyX, EnemyY);
  80.                 ItemHandler.removeItem(playerEquipment[playerArrows], EnemyX,
  81.                         EnemyY, amount);
  82.                 ItemHandler.addItem(playerEquipment[playerArrows], EnemyX,
  83.                         EnemyY, amount + 1, playerId, false);
  84.             }
  85.     }
  86.  
  87.     public int fletchShortbow = 0;
  88.     public int fletchLongbow = 0;
  89.  
  90.     /**
  91.      *These methods handle the First Click, Make 1, Make 5, Make 10 and Make X
  92.      * Option.
  93.      */
  94.  
  95.     public void fletchLogs() {
  96.  
  97.         if (fletchShafts == 1) {
  98.             closeInterface();
  99.             setAnimation(1248);
  100.             deleteItem(1511, 1);
  101.             addItem(52, 15);
  102.             addSkillXP(100 * 5, 9);
  103.             sM("You make some Arrow Shafts");
  104.         }
  105.         if (fletchShortbow == 0) { // Shortbow
  106.             if (playerLevel[9] > 4) {
  107.                 closeInterface();
  108.                 setAnimation(1248);
  109.                 deleteItem(1511, 1);
  110.                 addItem(50, 1);
  111.                 addSkillXP(100 * 10, 9);
  112.                 sM("You make a Shortbow (u)");
  113.             } else {
  114.                 closeInterface();
  115.                 sM("You need a fletching level of 5 to make this.");
  116.             }
  117.         }
  118.         if (fletchShortbow == 1) { // Oak
  119.             if (playerLevel[9] > 19) {
  120.                 closeInterface();
  121.                 setAnimation(1248);
  122.                 deleteItem(1521, 1);
  123.                 addItem(54, 1);
  124.                 addSkillXP(100 * 33, 9);
  125.                 sM("You make an Oak Shortbow (u)");
  126.             } else {
  127.                 closeInterface();
  128.                 sM("You need a fletching level of 20 to make this.");
  129.             }
  130.         }
  131.         if (fletchShortbow == 2) { // Willow
  132.             if (playerLevel[9] > 34) {
  133.                 closeInterface();
  134.                 setAnimation(1248);
  135.                 deleteItem(1519, 1);
  136.                 addItem(60, 1);
  137.                 addSkillXP(100 * 66, 9);
  138.                 sM("You make a Willow Shortbow (u)");
  139.             } else {
  140.                 closeInterface();
  141.                 sM("You need a fletching level of 35 to make this.");
  142.             }
  143.         }
  144.         if (fletchShortbow == 3) { // Maple
  145.             if (playerLevel[9] > 49) {
  146.                 closeInterface();
  147.                 setAnimation(1248);
  148.                 deleteItem(1517, 1);
  149.                 addItem(64, 1);
  150.                 addSkillXP(100 * 100, 9);
  151.                 sM("You make a Maple Shortbow (u)");
  152.             } else {
  153.                 closeInterface();
  154.                 sM("You need a fletching level of 50 to make this.");
  155.             }
  156.         }
  157.         if (fletchShortbow == 4) { // Yew
  158.             if (playerLevel[9] > 64) {
  159.                 closeInterface();
  160.                 setAnimation(1248);
  161.                 deleteItem(1515, 1);
  162.                 addItem(68, 1);
  163.                 addSkillXP(100 * 133, 9);
  164.                 sM("You make a Yew Shortbow (u)");
  165.             } else {
  166.                 closeInterface();
  167.                 sM("You need a fletching level of 65 to make this.");
  168.             }
  169.         }
  170.         if (fletchShortbow == 5) { // Magic
  171.             if (playerLevel[9] > 79) {
  172.                 closeInterface();
  173.                 setAnimation(1248);
  174.                 deleteItem(1513, 1);
  175.                 addItem(72, 1);
  176.                 addSkillXP(100 * 166, 9);
  177.                 sM("You make a Magic Shortbow (u)");
  178.             } else {
  179.                 sM("You need a fletching level of 80 to make this.");
  180.             }
  181.         }
  182.  
  183.         if (fletchLongbow == 0) { // Longbow
  184.             if (playerLevel[9] > 9) {
  185.                 closeInterface();
  186.                 setAnimation(1248);
  187.                 deleteItem(1511, 1);
  188.                 addItem(48, 1);
  189.                 addSkillXP(100 * 20, 9);
  190.                 sM("You make a Longbow (u)");
  191.             } else {
  192.                 closeInterface();
  193.                 sM("You need a fletching level of 10 to make this.");
  194.             }
  195.         }
  196.         if (fletchLongbow == 1) { // Oak Longbow
  197.             if (playerLevel[9] > 24) {
  198.                 closeInterface();
  199.                 setAnimation(1248);
  200.                 deleteItem(1521, 1);
  201.                 addItem(56, 1);
  202.                 addSkillXP(100 * 50, 9);
  203.                 sM("You make an Oak Longbow");
  204.             } else {
  205.                 closeInterface();
  206.                 sM("You need a fletching level of 25 to make this.");
  207.             }
  208.         }
  209.         if (fletchLongbow == 2) { // Willow Longbow
  210.             if (playerLevel[9] > 39) {
  211.                 closeInterface();
  212.                 setAnimation(1248);
  213.                 deleteItem(1519, 1);
  214.                 addItem(58, 1);
  215.                 addSkillXP(100 * 66, 9);
  216.                 sM("You make a Willow Longbow (u)");
  217.             } else {
  218.                 closeInterface();
  219.                 sM("You need a fletching level of 40 to make this.");
  220.             }
  221.         }
  222.         if (fletchLongbow == 3) { // Maple Longbow
  223.             if (playerLevel[9] > 54) {
  224.                 closeInterface();
  225.                 setAnimation(1248);
  226.                 deleteItem(1517, 1);
  227.                 addItem(62, 1);
  228.                 addSkillXP(100 * 116, 9);
  229.                 sM("You make a Maple Longbow (u)");
  230.             } else {
  231.                 closeInterface();
  232.                 sM("You need a fletching level of 55 to make this.");
  233.             }
  234.         }
  235.         if (fletchLongbow == 4) { // Yew Longbow
  236.             if (playerLevel[9] > 69) {
  237.                 closeInterface();
  238.                 setAnimation(1248);
  239.                 deleteItem(1515, 1);
  240.                 addItem(66, 1);
  241.                 addSkillXP(100 * 150, 9);
  242.                 sM("You make a Yew Longbow (u)");
  243.             } else {
  244.                 closeInterface();
  245.                 sM("You need a fletching level of 70 to make this.");
  246.             }
  247.         }
  248.         if (fletchLongbow == 5) { // Magic Longbow
  249.             if (playerLevel[9] > 84) {
  250.                 closeInterface();
  251.                 setAnimation(1248);
  252.                 deleteItem(1513, 1);
  253.                 addItem(70, 1);
  254.                 addSkillXP(100 * 183, 9);
  255.                 sM("You make a Magic Longbow (u)");
  256.             } else {
  257.                 closeInterface();
  258.                 sM("You need a fletching level of 85 to make this.");
  259.             }
  260.         }
  261.  
  262.     }
  263.  
  264.     public int fletchShafts = 0;
  265.  
  266.  
  267.     /**
  268.     * Make X, If User enters any number above 28 it sets it automatically to 28 to prevent extra items given.
  269.     */
  270.     public void initFletchX(int amount) {
  271.         fletchAmount = amount;
  272.         if (fletchAmount > 28) {
  273.             fletchAmount = 28;
  274.         }
  275.         fletchTimer = 0;
  276.         if (!HasItemAmount(1511, 1) && !HasItemAmount(1513, 1)
  277.                 && !HasItemAmount(1515, 1) && !HasItemAmount(1517, 1)
  278.                 && !HasItemAmount(1519, 1) && !HasItemAmount(1521, 1)) {
  279.             sM("You run out of logs");
  280.             fletchAmount = 0;
  281.         }
  282.     }
  283.  
  284.     public void tryFletchX() {
  285.         fletchTimer = 0;
  286.         if (fletchAmount == 0) {
  287.             updateRequired = true;
  288.             appearanceUpdateRequired = true;
  289.             resetAnimation();
  290.             fletchAmount = -1;
  291.             return;
  292.         }
  293.         if (HasItemAmount(1511, 1) || HasItemAmount(1513, 1)
  294.                 || HasItemAmount(1515, 1) || HasItemAmount(1517, 1)
  295.                 || HasItemAmount(1519, 1) || HasItemAmount(1521, 1)) {
  296.             fletchLogs();
  297.             fletchAmount--;
  298.         } else {
  299.             sM("You run out of logs.");
  300.             fletchAmount = -1;
  301.         }
  302.     }
  303.  
  304.     public void skullOff() {
  305.         EventManager.getSingleton().addEvent(new Event() {
  306.             public void execute(EventContainer c) {
  307.                 turnOffHead();
  308.                 updateRequired = true;
  309.                 appearanceUpdateRequired = true;
  310.                 isSkulled = false;
  311.             }
  312.         }, 60000);
  313.     }
  314.  
  315.     public void wildySign() {
  316.         EventManager.getSingleton().addEvent(new Event() {
  317.             public void execute(EventContainer c) {
  318.                 if (hasMultiSign && !multiCombat()) {
  319.                     frame61(-1);
  320.                     hasMultiSign = false;
  321.                 }
  322.                 if (multiCombat()) {
  323.                     frame61(1);
  324.                     hasMultiSign = true;
  325.                 }
  326.                 if (isInWilderness(absX, absY, 1)) {
  327.                     if (!hasWildySign) {
  328.                         hasWildySign = true;
  329.                         outStream.createFrame(208);
  330.                         outStream.writeWordBigEndian_dup(197);
  331.                         sendQuest("Level: " + wildyLevel, 199);
  332.                     }
  333.                     int level = ((absY - 3520) / 8) + 1;
  334.                     if (level != wildyLevel) {
  335.                         wildyLevel = level;
  336.                         sendQuest("Level: " + wildyLevel, 199);
  337.                     }
  338.                 } else {
  339.                     if (hasWildySign) {
  340.                         hasWildySign = false;
  341.                         setInterfaceWalkable(-1);
  342.                     }
  343.                 }
  344.             }
  345.         }, 1000);
  346.     }
  347.  
  348.     public void moreSpec() {
  349.         EventManager.getSingleton().addEvent(new Event() {
  350.             public void execute(EventContainer c) {
  351.                 if (specialAmount < 100) {
  352.                     specialAmount = (specialAmount + 10);
  353.                     if (specialAmount > 95)
  354.                         specialAmount = 100;
  355.                     if (specialAmount == 100) {
  356.                         specRegain = false;
  357.                         c.stop(); // stops the event from running
  358.                     }
  359.                     specAttack();
  360.                 } else {
  361.                     c.stop(); // stops the event from running
  362.                 }
  363.             }
  364.         }, 15000);
  365.     }
  366.  
  367.     public int getEnergyRestoreRate() {
  368.         return (5950 - (playerLevel[16] * 50));
  369.     }
  370.  
  371.     public void runEnergy() {
  372.         if (System.currentTimeMillis() - updateEnergy > 500) {
  373.             if (System.currentTimeMillis() - lastEnergyUpdate > getEnergyRestoreRate()) {
  374.                 if (playerEnergy <= 99) {
  375.                     playerEnergy = (playerEnergy + 1);
  376.                 }
  377.                 lastEnergyUpdate = System.currentTimeMillis();
  378.             }
  379.             if (playerEnergy >= 25)
  380.                 WriteEnergy();
  381.             else if (playerEnergy >= 0 && playerEnergy <= 24)
  382.                 sendFrame126("@red@" + playerEnergy + " %", 149);
  383.             updateEnergy = System.currentTimeMillis();
  384.         }
  385.     }
  386.  
  387.     public int disconnectedDelay = 0;
  388.     public boolean tradeAccepted;
  389.  
  390.     public boolean hasAccepted = false;
  391.     public int hlevel = 0;
  392.  
  393.     public boolean onlyxp = false;
  394.  
  395.     public int total = 0;
  396.     public int totalXP = 0;
  397.  
  398.     public int apickupid = -1;
  399.  
  400.     public int apickupx = -1;
  401.  
  402.     public int apickupy = -1;
  403.     public boolean hasntLoggedin = false;
  404.     public boolean teleblock = false;
  405.  
  406.     /* MISC */
  407.     public int i;
  408.     private java.io.InputStream in; // private java.io.DataInputStream in;
  409.     private java.io.OutputStream out; // private java.io.DataOutputStream out;
  410.     public Stream inStream = null, outStream = null;
  411.  
  412.     public Cryption inStreamDecryption = null, outStreamDecryption = null;
  413.     private java.net.Socket mySock;
  414.     public int killerId = playerId;
  415.     public static boolean autoSave = false;
  416.     public static final int bufferSize = 30000;
  417.  
  418.     public static final int packetSizes[] = { 0, 0, 0, 1, -1, 0, 0, 0, 0, 0, // 0
  419.             0, 0, 0, 0, 8, 0, 6, 2, 2, 0, // 10
  420.             0, 2, 0, 6, 0, 12, 0, 0, 0, 0, // 20
  421.             0, 0, 0, 0, 0, 8, 4, 0, 0, 2, // 30
  422.             2, 6, 0, 6, 0, -1, 0, 0, 0, 0, // 40
  423.             0, 0, 0, 12, 0, 0, 0, 8, 8, 0, // 50
  424.             0, 8, 0, 0, 0, 0, 0, 0, 0, 0, // 60
  425.             6, 0, 2, 2, 8, 6, 0, -1, 0, 6, // 70
  426.             0, 0, 0, 0, 0, 1, 4, 6, 0, 0, // 80
  427.             0, 0, 0, 0, 0, 3, 0, 0, -1, 0, // 90
  428.             0, 13, 0, -1, 0, 0, 0, 0, 0, 0,// 100
  429.             0, 0, 0, 0, 0, 0, 0, 6, 0, 0, // 110
  430.             1, 0, 6, 0, 0, 0, -1, 0, 2, 6, // 120
  431.             0, 4, 6, 8, 0, 6, 0, 0, 0, 2, // 130
  432.             0, 0, 0, 0, 0, 6, 0, 0, 0, 0, // 140
  433.             0, 0, 1, 2, 0, 2, 6, 0, 0, 0, // 150
  434.             0, 0, 0, 0, -1, -1, 0, 0, 0, 0,// 160
  435.             0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 170
  436.             0, 8, 0, 3, 0, 2, 0, 0, 8, 1, // 180
  437.             0, 0, 12, 0, 0, 0, 0, 0, 0, 0, // 190
  438.             2, 0, 0, 0, 0, 0, 0, 0, 4, 0, // 200
  439.             4, 0, 0, 0, 7, 8, 0, 0, 10, 0, // 210
  440.             0, 0, 0, 0, 0, 0, -1, 0, 6, 0, // 220
  441.             1, 0, 0, 0, 6, 0, 6, 8, 1, 0, // 230
  442.             0, 4, 0, 0, 0, 0, -1, 0, -1, 4,// 240
  443.             0, 0, 6, 6, 0, 0, 0 // 250
  444.     };
  445.  
  446.     public static final int validPackets[] = { 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, // 0
  447.             0, 0, 0, 0, 1, 0, 1, 1, 1, 0, // 10
  448.             0, 1, 0, 0, 0, 1, 0, 0, 0, 0, // 20
  449.             0, 0, 0, 0, 0, 1, 1, 0, 0, 1, // 30
  450.             1, 1, 0, 1, 0, 1, 0, 0, 0, 0, // 40
  451.             0, 0, 0, 1, 0, 0, 0, 1, 0, 0, // 50
  452.             1, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 60
  453.             1, 0, 1, 1, 1, 1, 0, 1, 1, 1, // 70
  454.             0, 0, 0, 0, 0, 1, 1, 1, 0, 0, // 80
  455.             0, 0, 0, 0, 0, 1, 0, 0, 1, 0, // 90
  456.             0, 1, 0, 1, 0, 0, 0, 0, 0, 0, // 100
  457.             0, 0, 0, 0, 0, 0, 0, 1, 0, 0, // 110
  458.             1, 1, 1, 0, 0, 0, 1, 0, 1, 1, // 120
  459.             1, 1, 1, 1, 0, 1, 1, 0, 0, 1, // 130
  460.             0, 0, 0, 0, 0, 1, 0, 0, 1, 0, // 140
  461.             1, 0, 1, 1, 0, 1, 1, 0, 0, 0, // 150
  462.             0, 0, 0, 0, 1, 1, 0, 0, 0, 0, // 160
  463.             0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 170
  464.             0, 1, 0, 1, 0, 1, 0, 0, 1, 1, // 180
  465.             0, 0, 1, 0, 0, 0, 0, 0, 0, 0, // 190
  466.             1, 0, 1, 0, 0, 0, 0, 0, 1, 0, // 200
  467.             1, 0, 0, 0, 1, 1, 0, 0, 1, 0, // 210
  468.             0, 0, 0, 0, 0, 0, 1, 0, 1, 0, // 220
  469.             1, 0, 0, 0, 1, 0, 1, 1, 1, 0, // 230
  470.             0, 1, 0, 0, 0, 0, 1, 0, 1, 1, // 240
  471.             0, 0, 1, 1, 0, 0, 0 // 250
  472.     };
  473.     public int[] noTrade = { 5509, 5510, 5512, 5514, 4565, 4566, 6570, 1580,
  474.             6729, 4045, 4046, 714, 771, 772, 1891, 1892, 983, 1550, 4031, 4035,
  475.             1613, 1629, 4277, 739, 1982, 1796 };
  476.     public int NPCID; // GLOBALLY NOW last clicked npcID
  477.  
  478.     public int NPCSlot; // GLOBALLY NOW last clicked npc slot
  479.     public CopyOnWriteArrayList<GameItem> offeredItems = new CopyOnWriteArrayList<GameItem>();
  480.     public boolean officialClient = false;
  481.     public int OriginalShield = -1;
  482.  
  483.     public int OriginalWeapon = -1;
  484.     public CopyOnWriteArrayList<GameItem> otherOfferedItems = new CopyOnWriteArrayList<GameItem>();
  485.     public int packetSize = 0, packetType = -1;
  486.  
  487.     public int pCArms;
  488.     public int pCBeard;
  489.     public int pCFeet;
  490.     public int pCHands;
  491.     public int pCHead;
  492.     public int pCLegs;
  493.     public int pColor;
  494.     public int pCTorso;
  495.     public int PickUpAmount = 0;
  496.  
  497.     public int PickUpDelete = 0;
  498.     public int PickUpID = 0;
  499.  
  500.     public String properName = "";
  501.  
  502.     public int Publicchat = 0;
  503.     public int[] QuestInterface = { 8145, 8147, 8148, 8149, 8150, 8151, 8152,
  504.             8153, 8154, 8155, 8156, 8157, 8158, 8159, 8160, 8161, 8162, 8163,
  505.             8164, 8165, 8166, 8167, 8168, 8169, 8170, 8171, 8172, 8173, 8174,
  506.             8175, 8176, 8177, 8178, 8179, 8180, 8181, 8182, 8183, 8184, 8185,
  507.             8186, 8187, 8188, 8189, 8190, 8191, 8192, 8193, 8194, 8195, 12174,
  508.             12175, 12176, 12177, 12178, 12179, 12180, 12181, 12182, 12183,
  509.             12184, 12185, 12186, 12187, 12188, 12189, 12190, 12191, 12192,
  510.             12193, 12194, 12195, 12196, 12197, 12198, 12199, 12200, 12201,
  511.             12202, 12203, 12204, 12205, 12206, 12207, 12208, 12209, 12210,
  512.             12211, 12212, 12213, 12214, 12215, 12216, 12217, 12218, 12219,
  513.             12220, 12221, 12222, 12223 };
  514.     public int random_skill = -1, npcId = -1;
  515.     public int readPtr, writePtr;
  516.  
  517.     public int[] requiredLevel = { 1, 10, 25, 38, 50, 60, 62, 64, 66, 68, 70,
  518.             72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96 };
  519.     public int restart = 0;
  520.     public int returnCode = 2; // Tells the Client if the login was successfull
  521.     public int rune1, rune1Am, rune2, rune2Am, rune3, rune3Am, rune4, rune4Am,
  522.             spellXP;
  523.     public int sameclick = 0;
  524.     public int savecounter = 0;
  525.     public boolean saveNeeded = true;
  526.  
  527.     public boolean shafting = false;
  528.  
  529.     public int SkillID = 0;
  530.     public int skillX = -1;
  531.     public int skillY = -1;
  532.     private int somejunk;
  533.     public int spellHit; // also same added so it won't be static ROFL
  534.     public int spellHitTimer;
  535.     public int spellNpcIndex = -1; // added so it won't be static ROFL..
  536.     public int spellPlayerIndex = -1; // same added so it won't be static ROFL
  537.     public boolean spellSet = true; //false
  538.     public int stairDistance = 1;
  539.     public int stairDistanceAdd = 0;
  540.     public int stairs = 0;
  541.     public int[] statId = { 10252, 11000, 10253, 11001, 10254, 11002, 10255,
  542.             11011, 11013, 11014, 11010, 11012, 11006, 11009, 11008, 11004,
  543.             11003, 11005, 47002, 54090, 11007 };
  544.     public String statName[] = { "attack", "defence", "strength", "hitpoints",
  545.             "range", "prayer", "magic", "cooking", "woodcutting", "fletching",
  546.             "fishing", "firemaking", "crafting", "smithing", "mining",
  547.             "herblore", "agility", "thieving", "slayer", "farming",
  548.             "runecrafting" };
  549.     public int stealtimer;
  550.     public int stillSpellGFX;
  551.     public int timeOutCounter = 0; // to detect timeouts on the connection to
  552.     // the Client
  553.     public int trade_reqId = 0, trade_other;
  554.     public int Tradecompete = 0;
  555.  
  556.     public boolean tradeRequested = false, inTrade = false, canOffer = true,
  557.             tradeConfirmed = false, tradeConfirmed2 = false,
  558.             tradeResetNeeded = false;
  559.  
  560.     long tTime = 0;
  561.     long tTime2 = 0;
  562.  
  563.     // Devolution: teleports
  564.     int tX = 0, tY = 0, tH = 1;
  565.  
  566.     public boolean validClient = true, muted = false, attackedNpc = false;
  567.  
  568.     public boolean validLogin = false;
  569.  
  570.     // public int[] restrictedItem = { 4716, 4718, 4720, 4722, 4724, 4726, 4728,
  571.     // 4730};
  572.     private int WanneBank = 0;
  573.  
  574.     private int WanneShop = 0;
  575.     public boolean wearing = false;
  576.     public boolean WildernessWarning = false;
  577.     public boolean WildernessWarning2 = false;
  578.     private int XinterfaceID = 0;
  579.     private int XremoveID = 0;
  580.     private int XremoveSlot = 0;
  581.     public int ipPart1 = 127;
  582.     public int ipPart2 = 0;
  583.     public int ipPart3 = 0;
  584.     public int ipPart4 = 1;
  585.  
  586.     public Client(java.net.Socket s, int _playerId) {
  587.         super(_playerId);
  588.         mySock = s;
  589.         try {
  590.             in = s.getInputStream();
  591.             out = s.getOutputStream();
  592.         } catch (java.io.IOException ioe) {
  593.             Misc.println("DeltaClean (1): Exception!");
  594.             Server.logError(ioe.getMessage());
  595.         }
  596.         outStream = new Stream(new byte[bufferSize]);
  597.         outStream.currentOffset = 0;
  598.         inStream = new Stream(new byte[bufferSize]);
  599.         inStream.currentOffset = 0;
  600.         readPtr = writePtr = 0;
  601.         buffer = buffer = new byte[bufferSize];
  602.     }
  603.  
  604.     public void actionReset() {
  605.         actionName = "";
  606.     }
  607.  
  608.     public boolean addItem(int item, int amount) {
  609.         try {
  610.             if (item == -1)
  611.                 return false;
  612.             if (!Item.itemStackable[item] || amount < 1) {
  613.                 amount = 1;
  614.             }
  615.  
  616.             if ((freeSlots() >= amount && !Item.itemStackable[item])
  617.                     || freeSlots() > 0) {
  618.                 for (int i = 0; i < playerItems.length; i++) {
  619.                     if (playerItems[i] == (item + 1)
  620.                             && Item.itemStackable[item] && playerItems[i] > 0) {
  621.                         playerItems[i] = (item + 1);
  622.                         if ((playerItemsN[i] + amount) < maxItemAmount
  623.                                 && (playerItemsN[i] + amount) > -1) {
  624.                             playerItemsN[i] += amount;
  625.                         } else {
  626.                             playerItemsN[i] = maxItemAmount;
  627.                         }
  628.                         outStream.createFrameVarSizeWord(34);
  629.                         outStream.writeWord(3214);
  630.                         outStream.writeByte(i);
  631.                         outStream.writeWord(playerItems[i]);
  632.                         if (playerItemsN[i] > 254) {
  633.                             outStream.writeByte(255);
  634.                             outStream.writeDWord(playerItemsN[i]);
  635.                         } else {
  636.                             outStream.writeByte(playerItemsN[i]); // amount
  637.                         }
  638.                         outStream.endFrameVarSizeWord();
  639.                         i = 30;
  640.                         return true;
  641.                     }
  642.                 }
  643.                 for (int i = 0; i < playerItems.length; i++) {
  644.                     if (playerItems[i] <= 0) {
  645.                         playerItems[i] = item + 1;
  646.                         if (amount < maxItemAmount && amount > -1) {
  647.                             playerItemsN[i] = amount;
  648.                         } else {
  649.                             playerItemsN[i] = maxItemAmount;
  650.                         }
  651.                         outStream.createFrameVarSizeWord(34);
  652.                         outStream.writeWord(3214);
  653.                         outStream.writeByte(i);
  654.                         outStream.writeWord(playerItems[i]);
  655.                         if (playerItemsN[i] > 254) {
  656.                             outStream.writeByte(255);
  657.                             outStream.writeDWord(playerItemsN[i]);
  658.                         } else {
  659.                             outStream.writeByte(playerItemsN[i]); // amount
  660.                         }
  661.                         outStream.endFrameVarSizeWord();
  662.                         i = 30;
  663.                         return true;
  664.                     }
  665.                 }
  666.                 return false;
  667.             } else {
  668.                 sM("Not enough space in your inventory.");
  669.                 return false;
  670.             }
  671.         } catch (Exception E) {
  672.             return false;
  673.         }
  674.     }
  675.  
  676.     public boolean addItem2(int item, int amount) {
  677.         try {
  678.             if (item == -1)
  679.                 return false;
  680.             if (!Item.itemStackable[item] || amount < 1) {
  681.                 amount = 1;
  682.             }
  683.  
  684.             if ((freeSlots() >= amount && !Item.itemStackable[item])
  685.                     || freeSlots() > 0) {
  686.                 for (int i = 0; i < playerItems.length; i++) {
  687.                     if (playerItems[i] == (item + 1)
  688.                             && Item.itemStackable[item] && playerItems[i] > 0) {
  689.                         playerItems[i] = (item + 1);
  690.                         if ((playerItemsN[i] + amount) < maxItemAmount
  691.                                 && (playerItemsN[i] + amount) > -1) {
  692.                             playerItemsN[i] += amount;
  693.                         } else {
  694.                             playerItemsN[i] = maxItemAmount;
  695.                         }
  696.                         outStream.createFrameVarSizeWord(34);
  697.                         outStream.writeWord(3214);
  698.                         outStream.writeByte(i);
  699.                         outStream.writeWord(playerItems[i]);
  700.                         if (playerItemsN[i] > 254) {
  701.                             outStream.writeByte(255);
  702.                             outStream.writeDWord(playerItemsN[i]);
  703.                         } else {
  704.                             outStream.writeByte(playerItemsN[i]); // amount
  705.                         }
  706.                         outStream.endFrameVarSizeWord();
  707.                         i = 30;
  708.                         return true;
  709.                     }
  710.                 }
  711.                 for (int i = 0; i < playerItems.length; i++) {
  712.                     if (playerItems[i] <= 0) {
  713.                         playerItems[i] = item + 1;
  714.                         if (amount < maxItemAmount && amount > -1) {
  715.                             playerItemsN[i] = amount;
  716.                         } else {
  717.                             playerItemsN[i] = maxItemAmount;
  718.                         }
  719.                         outStream.createFrameVarSizeWord(34);
  720.                         outStream.writeWord(3214);
  721.                         outStream.writeByte(i);
  722.                         outStream.writeWord(playerItems[i]);
  723.                         if (playerItemsN[i] > 254) {
  724.                             outStream.writeByte(255);
  725.                             outStream.writeDWord(playerItemsN[i]);
  726.                         } else {
  727.                             outStream.writeByte(playerItemsN[i]); // amount
  728.                         }
  729.                         outStream.endFrameVarSizeWord();
  730.                         i = 30;
  731.                         return true;
  732.                     }
  733.                 }
  734.                 return false;
  735.             } else {
  736.                 ItemHandler.addItem(item, absX, absY, amount, playerId, false);
  737.                 return false;
  738.             }
  739.         } catch (Exception E) {
  740.             return false;
  741.         }
  742.     }
  743.  
  744.     public void addObject(int objectX, int objectY, int NewObjectID, int Face) {
  745.         outStream.createFrameVarSizeWord(60);
  746.         outStream.writeByte(objectY - (mapRegionY * 8));
  747.         outStream.writeByteC(objectX - (mapRegionX * 8));
  748.  
  749.         /* CREATE OBJECT */
  750.         if (NewObjectID > -1) {
  751.             outStream.writeByte(151);
  752.             outStream.writeByteS(0);
  753.             outStream.writeWordBigEndian(NewObjectID);
  754.             outStream.writeByteA(Face); // 0= WEST | -1 = NORTH | -2 = EAST | -3
  755.             // = SOUTH
  756.         }
  757.         outStream.endFrameVarSizeWord();
  758.     }
  759.  
  760.     public boolean addShopItem(int itemID, int amount) {
  761.         boolean Added = false;
  762.  
  763.         if (amount <= 0) {
  764.             return false;
  765.         }
  766.         if (Item.itemIsNote[itemID] == true) {
  767.             itemID = GetUnnotedItem(itemID);
  768.         }
  769.         for (int i = 0; i < ShopHandler.ShopItems.length; i++) {
  770.             if ((ShopHandler.ShopItems[MyShopID][i] - 1) == itemID) {
  771.                 ShopHandler.ShopItemsN[MyShopID][i] += amount;
  772.                 Added = true;
  773.             }
  774.         }
  775.         if (Added == false) {
  776.             for (int i = 0; i < ShopHandler.ShopItems.length; i++) {
  777.                 if (ShopHandler.ShopItems[MyShopID][i] == 0) {
  778.                     ShopHandler.ShopItems[MyShopID][i] = (itemID + 1);
  779.                     ShopHandler.ShopItemsN[MyShopID][i] = amount;
  780.                     ShopHandler.ShopItemsDelay[MyShopID][i] = 0;
  781.                     break;
  782.                 }
  783.             }
  784.         }
  785.         return true;
  786.     }
  787.  
  788.     public boolean addSkillXP(int amount, int skill) {
  789.         if (randomed) {
  790.             sM("You must answer the genie before you can gain experience!");
  791.             return false;
  792.         }
  793.         if ((amount + playerXP[skill]) < 0
  794.                 || amount + playerXP[skill] > 200000000
  795.                 || playerXP[skill] >= 200000000) {
  796.             playerXP[skill] = 200000000;
  797.             refreshSkills();
  798.             return false;
  799.         }
  800.         int oldLevel = getLevelForXP(playerXP[skill]);
  801.         // int[] statId = {4004, 4008, 4006, 4016, 4010, 4012, 4014, 4034, 4038,
  802.         // 4026, 4032, 4036, 4024, 4030, 4028, 4020, 4018, 4022, 4152};
  803.         playerXP[skill] += amount;
  804.         if (oldLevel < getLevelForXP(playerXP[skill])) {
  805.             // if(oldLevel >= 85)
  806.             specGFX(199);
  807.             // checkPlayerCapes.achievedMax(skill, this);
  808.  
  809.             playerLevel[skill] = getLevelForXP(playerXP[skill]);
  810.             // stillgfx(623, absY, absX);
  811.             // levelup(skill);
  812.             updateRequired = true;
  813.             appearanceUpdateRequired = true;
  814.             sM("Congratulations, you just advanced a " + statName[skill]
  815.                     + " level.");
  816.  
  817.             if (playerLevel[skill] > 90)
  818.                 // sendFrame126(playerName + " (" + combatLevel + ")", 6572);
  819.                 setSkillLevel(skill, playerLevel[skill], playerXP[skill]);
  820.         }
  821.         refreshSkills();
  822.         // setSkillLevel(skill, playerLevel[skill], playerXP[skill]);
  823.         if (skill == 2) {
  824.             CalculateMaxHit();
  825.         }
  826.         return true;
  827.  
  828.     }
  829.  
  830.     public int amountOfItem(int itemID) {
  831.         int i1 = 0;
  832.  
  833.         for (int i = 0; i < 28; i++) {
  834.             if (playerItems[i] == (itemID + 1)) {
  835.                 i1++;
  836.             }
  837.         }
  838.         return i1;
  839.     }
  840.  
  841.     public boolean antiHax() {
  842.         if (System.currentTimeMillis() - lastMouse > 1000) {
  843.             println("Suspicious activity!");
  844.             disconnected = true;
  845.             // sM("Client hack detected!");
  846.             // sM("The only supported clients are the DeltaScape Client and moparscape");
  847.             return false;
  848.         }
  849.         return true;
  850.     }
  851.  
  852.     public void appendHitToNpc(int index, int hitDiff, boolean stillSpell) // Used
  853.     // for
  854.     // MagicHandler
  855.     {
  856.         boolean splash = false;
  857.         if (!playerMage2(index)) {
  858.             splash = true;
  859.         }
  860.         if (!splash) {
  861.             getEnd();
  862.         }
  863.         if (splash) {
  864.             stillgfx(85, fenemyY, fenemyX);
  865.         }
  866.         if (MagicHandler.npcHP - hitDiff < 0 && !splash) {
  867.             hitDiff = MagicHandler.npcHP;
  868.         }
  869.         if (MagicHandler.itHeals && !splash) {
  870.             if (Misc.random(2) == 1) {
  871.                 currentHealth += hitDiff / 4;
  872.                 if (currentHealth > playerLevel[playerHitpoints])
  873.                     currentHealth = playerLevel[playerHitpoints];
  874.                 sendQuest("" + currentHealth + "", 4016);
  875.                 sM("You drain the enemies health.");
  876.             }
  877.         }
  878.         if (rune1 != -1)
  879.             deleteItem(rune1, getItemSlot(rune1), rune1Am);
  880.         if (rune2 != -1)
  881.             deleteItem(rune2, getItemSlot(rune2), rune2Am);
  882.         if (rune3 != -1)
  883.             deleteItem(rune3, getItemSlot(rune3), rune3Am);
  884.         if (rune4 != -1)
  885.             deleteItem(rune4, getItemSlot(rune4), rune4Am);
  886.         addSkillXP((spellXP * hitDiff), 6);
  887.         addSkillXP((spellXP * hitDiff / 2), 3);
  888.         if (!splash) {
  889.             Server.npcHandler.npcs[index].StartKilling = playerId;
  890.             Server.npcHandler.npcs[index].RandomWalk = false;
  891.             Server.npcHandler.npcs[index].IsUnderAttack = true;
  892.             Server.npcHandler.npcs[index].hitDiff = hitDiff;
  893.             Server.npcHandler.npcs[index].Killing[playerId] += hitDiff;
  894.             Server.npcHandler.npcs[index].updateRequired = true;
  895.             Server.npcHandler.npcs[index].hitUpdateRequired = true;
  896.             Server.npcHandler.npcs[index].hit = true;
  897.         }
  898.     }
  899.  
  900.     public void appendHitToPlayer(int index, int hitDiff, boolean stillSpell) // Used
  901.     // for
  902.     // MagicHandler
  903.     {
  904.         try {
  905.             if (PlayerHandler.players[index] != null) {
  906.                 Client mage = (Client) PlayerHandler.players[index];
  907.                 boolean splash = false;
  908.                 if (!playerMage(index)) {
  909.                     splash = true;
  910.                 }
  911.                 if (!splash) {
  912.                     getEnd();
  913.                 }
  914.                 if (splash) {
  915.                     stillgfx(85, fenemyY, fenemyX);
  916.                 }
  917.                 if (MagicHandler.playerHP - hitDiff < 0 && !splash) {
  918.                     hitDiff = MagicHandler.playerHP;
  919.                 }
  920.                 if (MagicHandler.itHeals && !splash) {
  921.                     if (hitDiff > 0) {
  922.                         currentHealth += hitDiff / 4;
  923.                         if (currentHealth > playerLevel[playerHitpoints])
  924.                             currentHealth = playerLevel[playerHitpoints];
  925.                         sendQuest("" + currentHealth + "", 4016);
  926.                         sM("You drain the enemies health.");
  927.                     }
  928.                 }
  929.                 if (MagicHandler.itTeleblocks && !splash) {
  930.                     if (System.currentTimeMillis() - lastTeleblock >= 300000) {
  931.                         mage.sM("You have been teleblocked!");
  932.                         PlayerHandler.players[index].lastTeleblock = System
  933.                                 .currentTimeMillis();
  934.                     }
  935.                 }
  936.                 if (MagicHandler.itFreezes && !splash) {
  937.                     if (PlayerHandler.players[index].EntangleDelay <= 0) {
  938.                         PlayerHandler.players[index].lastEntangle = System
  939.                                 .currentTimeMillis();
  940.                         PlayerHandler.players[index].entangleDelay = getFreezeTimer(MagicHandler.spellID);
  941.                         mage.sM("You have been frozen!");
  942.                         mage.toX = mage.absX;
  943.                         mage.toY = mage.absY;
  944.                     }
  945.                 }
  946.                 Client player = (Client) PlayerHandler.players[playerId];
  947.                 if (mage.vengon && hitDiff != 0 && !splash) {
  948.                     player.hitDiff = (int) (hitDiff / 1.2); // Simple math, 100
  949.                     // divided by 1.30,
  950.                     // and you get 76.
  951.                     player.currentHealth -= (int) (hitDiff / 1.2);
  952.                     player.hitUpdateRequired = true; // So the hit will append
  953.                     // to you.
  954.                     player.updateRequired = true; // So the hit will append to
  955.                     // you.
  956.                     player.appearanceUpdateRequired = true; // So the hit will
  957.                     // append to you.
  958.                     mage.vengon = false;
  959.                     mage.plrText = "Taste vengeance!"; // This says it in
  960.                     // itself.
  961.                     mage.plrTextUpdateRequired = true; // Make sure the txt4
  962.                     // will update.
  963.                 }
  964.                 if (rune1 != -1)
  965.                     deleteItem(rune1, getItemSlot(rune1), rune1Am);
  966.                 if (rune2 != -1)
  967.                     deleteItem(rune2, getItemSlot(rune2), rune2Am);
  968.                 if (rune3 != -1)
  969.                     deleteItem(rune3, getItemSlot(rune3), rune3Am);
  970.                 if (rune4 != -1)
  971.                     deleteItem(rune4, getItemSlot(rune4), rune4Am);
  972.                 addSkillXP((spellXP * hitDiff), 6);
  973.                 addSkillXP((spellXP * hitDiff / 2), 3);
  974.                 if (!MagicHandler.itTeleblocks && !splash) {
  975.                     PlayerHandler.players[index].dealDamage(hitDiff);
  976.                     PlayerHandler.players[index].hitDiff = hitDiff;
  977.                     PlayerHandler.players[index].updateRequired = true;
  978.                     PlayerHandler.players[index].hitUpdateRequired = true;
  979.                     PlayerHandler.players[index].KilledBy[playerId] += hitDiff;
  980.                     PlayerHandler.players[index].offTimer = System
  981.                             .currentTimeMillis();
  982.                     PlayerHandler.players[index].hitID = playerId;
  983.                     mage.killerId = playerId;
  984.                 }
  985.             }
  986.         } catch (Exception e) {
  987.         }
  988.     }
  989.  
  990.     public void appendToDupe(String player) {
  991.  
  992.         BufferedWriter bw = null;
  993.  
  994.         try {
  995.             bw = new BufferedWriter(new FileWriter("config//dupers.txt", true));
  996.             bw.write(player);
  997.             bw.newLine();
  998.             bw.flush();
  999.         } catch (IOException ioe) {
  1000.             ioe.printStackTrace();
  1001.         } finally {
  1002.             if (bw != null) {
  1003.                 try {
  1004.                     bw.close();
  1005.                 } catch (IOException ioe2) {
  1006.                     sM("Error with dupers!");
  1007.                 }
  1008.             }
  1009.         }
  1010.  
  1011.     }
  1012.  
  1013.     public void applyProtectItemProt() {
  1014.         if (!isSkulled)
  1015.             keepItem4();
  1016.         if (itemKept4 > 0) {
  1017.             if (itemSlot4)
  1018.                 deleteItem(itemKept4, itemKept4Slot, 1);
  1019.             else if (!itemSlot4)
  1020.                 deleteequiment(itemKept4, itemKept4Slot);
  1021.         }
  1022.         if (isSkulled)
  1023.             keepItem1();
  1024.         if (itemKept1 > 0) {
  1025.             if (itemSlot1)
  1026.                 deleteItem(itemKept1, itemKept1Slot, 1);
  1027.             else if (!itemSlot1)
  1028.                 deleteequiment(itemKept1, itemKept1Slot);
  1029.         }
  1030.     }
  1031.  
  1032.     public boolean AreXItemsInBag(int ItemID, int Amount) {
  1033.         int ItemCount = 0;
  1034.  
  1035.         for (int pItem : playerItems) {
  1036.             if ((pItem - 1) == ItemID) {
  1037.                 ItemCount++;
  1038.             }
  1039.             if (ItemCount == Amount) {
  1040.                 return true;
  1041.             }
  1042.         }
  1043.         return false;
  1044.     }
  1045.  
  1046.     // pk: 2726 9193
  1047.  
  1048.     private boolean Attack() {
  1049.         Client AttackingOn2 = (Client) PlayerHandler.players[AttackingOn];
  1050.         if (AttackingOn2.heightLevel != heightLevel)
  1051.             return false;
  1052.         int EnemyX = PlayerHandler.players[AttackingOn].absX;
  1053.         int EnemyY = PlayerHandler.players[AttackingOn].absY;
  1054.  
  1055.         if (specOn) {
  1056.             if (!specRegain && specialAmount == 100) {
  1057.                 moreSpec();
  1058.                 specRegain = true;
  1059.             }
  1060.         }
  1061.  
  1062.         if (AttackingOn2.hitID != playerId && AttackingOn2.hitID != 0
  1063.                 && !multiCombat()) {
  1064.             sM("He is already under attack!");
  1065.             ResetAttack();
  1066.             return false;
  1067.         }
  1068.         if ((AttackingOn2.combatLevel + wildyLevel < combatLevel || combatLevel
  1069.                 + wildyLevel < AttackingOn2.combatLevel)
  1070.                 && !isInPitGame()) {
  1071.             sM("Your level difference is too great!");
  1072.             AttackingOn = 0;
  1073.             return false;
  1074.         }
  1075.         if (hasKnife()) {
  1076.             sM("Knives are disabled for now!");
  1077.             ResetAttack();
  1078.             return false;
  1079.         }
  1080.         if (hitID != AttackingOn2.playerId && hitID != 0 && !multiCombat()) {
  1081.             sM("I'm already under attack.");
  1082.             ResetAttack();
  1083.             faceNPC(32768 + AttackingOn);
  1084.             return false;
  1085.         }
  1086.         if (!(AttackingOn > 0) || !(AttackingOn < PlayerHandler.players.length)) {
  1087.             ResetAttack();
  1088.             return false;
  1089.         }
  1090.         if (playerId < 1) {
  1091.             sM("Error: Your player id is invalid. Please try again or logout and back in");
  1092.         }
  1093.  
  1094.         boolean UseBow = false;
  1095.         if (playerEquipment[playerWeapon] == 839
  1096.                 || playerEquipment[playerWeapon] == 841
  1097.                 || playerEquipment[playerWeapon] == 843
  1098.                 || playerEquipment[playerWeapon] == 845
  1099.                 || playerEquipment[playerWeapon] == 847
  1100.                 || playerEquipment[playerWeapon] == 849
  1101.                 || playerEquipment[playerWeapon] == 851
  1102.                 || playerEquipment[playerWeapon] == 853
  1103.                 || playerEquipment[playerWeapon] == 855
  1104.                 || playerEquipment[playerWeapon] == 857
  1105.                 || playerEquipment[playerWeapon] == 837
  1106.                 || playerEquipment[playerWeapon] == 861
  1107.                 || playerEquipment[playerWeapon] == 4734
  1108.                 || playerEquipment[playerWeapon] == 859
  1109.                 || playerEquipment[playerWeapon] == 4827 || hasCrystalBow()) {
  1110.             UseBow = true;
  1111.         }
  1112.         boolean UseCrossBow = false;
  1113.         if (playerEquipment[playerWeapon] == 837) {
  1114.             UseCrossBow = true;
  1115.         }
  1116.         boolean UseRing = false;
  1117.         if (playerEquipment[playerWeapon] == 6522) {
  1118.             UseRing = true;
  1119.         }
  1120.         if (UseBow) {
  1121.             HasArrows = false;
  1122.             CheckArrows();
  1123.             // CalculateRange();
  1124.             hitDiff = Misc.random(maxRangeHit());
  1125.             // drawback();
  1126.             DropArrows();
  1127.         }
  1128.         if (UseCrossBow) {
  1129.             HasBolts = false;
  1130.             CheckBolts();
  1131.             // CalculateRange();
  1132.             hitDiff = Misc.random(maxRangeHit());
  1133.         }
  1134.         if (UseRing) {
  1135.             HasRings = false;
  1136.             CheckRings();
  1137.             // CalculateRange();
  1138.             hitDiff = Misc.random(maxRangeHit());
  1139.         }
  1140.         if (UseBow || UseCrossBow || UseRing) {
  1141.             if (GoodDistance(EnemyX, EnemyY, absX, absY, 8) == false) {
  1142.                 sM("You are too far to range your enemy!");
  1143.                 ResetAttack();
  1144.                 return false;
  1145.             }
  1146.         }
  1147.         int EnemyHP = PlayerHandler.players[AttackingOn].currentHealth;
  1148.         int[] arrowIds = { 882, 884, 886, 888, 890, 892, 78 };
  1149.         int[] arrowGfx = { 10, 9, 11, 12, 13, 15, 16 };
  1150.         int[] staffs = { 1381, 1383, 1385, 1387, 4675 };
  1151.         faceNPC(32768 + AttackingOn);
  1152.         updateRequired = true;
  1153.         appearanceUpdateRequired = true;
  1154.         @SuppressWarnings("unused")
  1155.         int arrowgfx = 10;
  1156.         for (int i1 = 0; i1 < arrowIds.length; i1++) {
  1157.             if (playerEquipment[playerArrows] == arrowIds[i1]) {
  1158.                 arrowgfx = arrowGfx[i1];
  1159.             }
  1160.         }
  1161.         if (hasCrystalBow()) {
  1162.             arrowgfx = 249;
  1163.         }
  1164.         for (int element : staffs) {
  1165.             if ((playerEquipment[playerWeapon] == element)
  1166.                     && autocasting
  1167.                     && autocastID > 0
  1168.                     && (isInPitGame() && !AttackingOn2.isInPitRoom() || isInWilderness(
  1169.                             absX, absY, 1) == true
  1170.                             && AttackingOn2.isInWilderness(AttackingOn2.absX,
  1171.                                     AttackingOn2.absY, 1) == true)) {
  1172.                 int playerTargetX = PlayerHandler.players[AttackingOn].absX;
  1173.                 int playerTargetY = PlayerHandler.players[AttackingOn].absY;
  1174.                 int playerTargetHealth = PlayerHandler.players[AttackingOn].playerLevel[playerHitpoints];
  1175.                 if (System.currentTimeMillis() - lastAttack < 4000) {
  1176.                     // sM("You must wait 4 seconds before casting this kind of spell again");
  1177.                     return false;
  1178.                 }
  1179.                 if (!playerMage(AttackingOn)) {
  1180.                     return false;
  1181.                 }
  1182.                 inCombat = true;
  1183.                 lastCombat = System.currentTimeMillis();
  1184.                 lastAttack = lastCombat;
  1185.  
  1186.                 TurnPlayerTo(playerTargetX, playerTargetY);
  1187.                 updateRequired = true;
  1188.                 appearanceUpdateRequired = true;
  1189.  
  1190.                 toX = absX;
  1191.                 toY = absY;
  1192.                 newWalkCmdSteps = 0;
  1193.                 newWalkCmdX[0] = newWalkCmdY[0] = tmpNWCX[0] = tmpNWCY[0] = 0;
  1194.                 getNextPlayerMovement();
  1195.                 MagicHandler.playerX = playerTargetX;
  1196.                 MagicHandler.playerY = playerTargetY;
  1197.                 MagicHandler.playerHP = playerTargetHealth;
  1198.                 AttackingOn2.offTimer = System.currentTimeMillis();
  1199.                 AttackingOn2.hitID = playerId;
  1200.                 spellPlayerIndex = MagicHandler.magicSpellPlayer(autocastID,
  1201.                         playerId, AttackingOn, playerLevel[6]);
  1202.                 return true;
  1203.             }
  1204.         }
  1205.         int voidmelee = 0;
  1206.         int hitDiff = 0;
  1207.         int aBonus = 0;
  1208.         int rand_att = Misc.random(playerLevel[0]) * 3
  1209.                 + Misc.random(AtkPray * 8);
  1210.         int rand_def = (int) (0.65 * Misc.random(AttackingOn2.playerLevel[1]) + AttackingOn2.DefPray * 8);
  1211.         if (AttackingOn2.ProtMelee) {
  1212.             rand_def += Misc.random(100);
  1213.         }
  1214.         if (FullVMelee()) {
  1215.             voidmelee += 10;
  1216.         }
  1217.         if (FightType == 1)
  1218.             aBonus += (int) (playerBonus[1] / 20);
  1219.         int random_u = Misc.random(playerBonus[1] + aBonus) * 2;
  1220.         int dBonus = 0;
  1221.         if (AttackingOn2.FightType == 4)
  1222.             dBonus += (int) (AttackingOn2.playerBonus[6] / 20);
  1223.         int random_def = Misc.random(AttackingOn2.playerBonus[6] + dBonus
  1224.                 + AttackingOn2.AtkPray * 8);
  1225.         if ((random_u >= random_def) && (rand_att > rand_def)) {
  1226.             hitDiff = Misc.random(playerMaxHit) + Misc.random(StrPrayer)
  1227.                     + Misc.random(voidmelee);
  1228.             if (AttackingOn2.ProtMelee)
  1229.                 hitDiff /= 2;
  1230.         } else {
  1231.             hitDiff = 0;
  1232.         }
  1233.         if (UseBow && playerEquipment[playerWeapon] == 4734) {
  1234.             // CalculateRange();
  1235.             hitDiff = Misc.random(maxRangeHit());
  1236.             if (DeleteArrow() && playerEquipment[playerArrows] == 4740) {
  1237.                 lastArrow = System.currentTimeMillis();
  1238.                 arrow = true;
  1239.                 actionInterval = getbattleTimer();
  1240.                 lastAction = System.currentTimeMillis();
  1241.             } else {
  1242.                 ResetAttack();
  1243.                 sM("There is no ammo left in your quiver.");
  1244.                 return false;
  1245.             }
  1246.         }
  1247.         if (UseBow && hasCrystalBow()) {
  1248.             // CalculateRange();
  1249.             drawback();
  1250.             DropArrows();
  1251.             hitDiff = Misc.random(maxRangeHit());
  1252.  
  1253.             if (DeleteArrow()) {
  1254.                 lastArrow = System.currentTimeMillis();
  1255.                 arrow = true;
  1256.                 arrowsLeft -= 1;
  1257.                 actionInterval = getbattleTimer();
  1258.                 lastAction = System.currentTimeMillis();
  1259.             } else {
  1260.                 ResetAttack();
  1261.                 sM("There is no ammo left in your quiver.");
  1262.                 return false;
  1263.             }
  1264.         }
  1265.         if (UseBow && !UseCrossBow && playerEquipment[playerWeapon] != 4734
  1266.                 && playerEquipment[playerWeapon] != 4827 && !hasCrystalBow()) {
  1267.             // CalculateRange();
  1268.             drawback();
  1269.             DropArrows();
  1270.             hitDiff = Misc.random(maxRangeHit());
  1271.             if (DeleteArrow() && HasArrows) {
  1272.                 lastArrow = System.currentTimeMillis();
  1273.                 arrow = true;
  1274.                 actionInterval = getbattleTimer();
  1275.                 lastAction = System.currentTimeMillis();
  1276.             } else {
  1277.                 ResetAttack();
  1278.                 sM("There is no ammo left in your quiver.");
  1279.                 return false;
  1280.             }
  1281.         }
  1282.         if (UseBow && playerEquipment[playerWeapon] == 4827) {
  1283.             // CalculateRange();
  1284.             drawback();
  1285.             DropArrows();
  1286.             hitDiff = Misc.random(maxRangeHit());
  1287.             if (DeleteArrow() && HasArrows) {
  1288.                 lastArrow = System.currentTimeMillis();
  1289.                 arrow = true;
  1290.                 actionInterval = getbattleTimer();
  1291.                 lastAction = System.currentTimeMillis();
  1292.             } else {
  1293.                 ResetAttack();
  1294.                 sM("There is no ammo left in your quiver.");
  1295.                 return false;
  1296.             }
  1297.         }
  1298.         if (UseCrossBow) {
  1299.             // CalculateRange();
  1300.             hitDiff = Misc.random(maxRangeHit());
  1301.             if (DeleteArrow() && HasBolts) {
  1302.                 lastArrow = System.currentTimeMillis();
  1303.                 arrow = true;
  1304.                 actionInterval = getbattleTimer();
  1305.                 lastAction = System.currentTimeMillis();
  1306.             } else {
  1307.                 ResetAttack();
  1308.                 sM("There is no ammo left in your quiver.");
  1309.                 return false;
  1310.             }
  1311.         }
  1312.         if (UseRing) {
  1313.             // CalculateRange();
  1314.             hitDiff = Misc.random(maxRangeHit());
  1315.             if (deleteRing() && HasRings) {
  1316.                 lastArrow = System.currentTimeMillis();
  1317.                 arrow = true;
  1318.                 actionInterval = getbattleTimer();
  1319.                 lastAction = System.currentTimeMillis();
  1320.             } else {
  1321.                 ResetAttack();
  1322.                 return false;
  1323.             }
  1324.         }
  1325.         long thisAttack = System.currentTimeMillis();
  1326.         if (Smite == true && AttackingOn2.playerLevel[5] > 0
  1327.                 && GoodDistance(EnemyX, EnemyY, absX, absY, 1)) {
  1328.             AttackingOn2.playerLevel[5] -= hitDiff / 4;
  1329.             AttackingOn2.sendQuest("" + AttackingOn2.playerLevel[5] + "", 4012);
  1330.             AttackingOn2.sendFrame126("Prayer: " + AttackingOn2.playerLevel[5]
  1331.                     + "/" + AttackingOn2.getLevelForXP(playerXP[5]) + "", 687);
  1332.         }
  1333.         if (playerEquipment[playerWeapon] == 6528
  1334.                 && playerEquipment[playerAmulet] == 6577 && Misc.random(3) == 1) {
  1335.             hitDiff = Misc.random(8) + Misc.random(playerMaxHit)
  1336.                     + Misc.random(StrPrayer);
  1337.         }
  1338.         if (FullDharokEquipped() && Misc.random(2) == 1 && currentHealth > 80
  1339.                 && currentHealth < 100) {
  1340.             hitDiff = Misc.random(8) + Misc.random(playerMaxHit)
  1341.                     + Misc.random(StrPrayer);
  1342.  
  1343.         }
  1344.         if (FullDharokEquipped() && Misc.random(2) == 1 && currentHealth > 60
  1345.                 && currentHealth < 79) {
  1346.             hitDiff = Misc.random(18) + Misc.random(playerMaxHit)
  1347.                     + Misc.random(StrPrayer);
  1348.  
  1349.         }
  1350.         if (FullDharokEquipped() && Misc.random(2) == 1 && currentHealth > 40
  1351.                 && currentHealth < 59) {
  1352.             hitDiff = Misc.random(28) + Misc.random(playerMaxHit)
  1353.                     + Misc.random(StrPrayer);
  1354.  
  1355.         }
  1356.         if (FullDharokEquipped() && Misc.random(2) == 1 && currentHealth > 20
  1357.                 && currentHealth < 39) {
  1358.             hitDiff = Misc.random(38) + Misc.random(playerMaxHit)
  1359.                     + Misc.random(StrPrayer);
  1360.  
  1361.         }
  1362.         if (FullDharokEquipped() && Misc.random(2) == 1 && currentHealth > 0
  1363.                 && currentHealth < 18) {
  1364.             hitDiff = Misc.random(58) + Misc.random(playerMaxHit)
  1365.                     + Misc.random(StrPrayer);
  1366.  
  1367.         }
  1368.         if (FullVeracEquipped()) {
  1369.             if (Misc.random(2) == 1) {
  1370.                 hitDiff = Misc.random(playerMaxHit) + Misc.random(StrPrayer);
  1371.             }
  1372.         }
  1373.         if (FullGuthanEquipped()) {
  1374.             if (Misc.random(3) == 1) {
  1375.                 if ((currentHealth + hitDiff) <= getLevelForXP(playerXP[3])) {
  1376.                     currentHealth += hitDiff;
  1377.                 }
  1378.                 if ((currentHealth + hitDiff) > getLevelForXP(playerXP[3])) {
  1379.                     currentHealth = getLevelForXP(playerXP[3]);
  1380.                 }
  1381.                 sendQuest("" + currentHealth + "", 4016);
  1382.                 stillgfx(398, EnemyY, EnemyX);
  1383.             }
  1384.         }
  1385.         actionInterval = getbattleTimer();
  1386.         lastAction = System.currentTimeMillis();
  1387.         if (AttackingOn2.prayOn && AttackingOn2.Redemption
  1388.                 && AttackingOn2.currentHealth < 10
  1389.                 && AttackingOn2.currentHealth > 0) {
  1390.             AttackingOn2.prayOff();
  1391.             AttackingOn2.currentHealth += 20;
  1392.             AttackingOn2.lowGFX(436, 0);
  1393.             AttackingOn2.playerLevel[5] = 0;
  1394.         }
  1395.         if (AttackingOn2.skulledBy != playerName && !isInPitGame()) {
  1396.             lastSkull = System.currentTimeMillis();
  1397.             isSkulled = true;
  1398.             skulledBy = AttackingOn2.playerName;
  1399.             getHead();
  1400.         }
  1401.         if (playerEquipment[playerWeapon] == 4827 && !specOn) {
  1402.             DDS2Damg3 = true;
  1403.             ddsInterval = 2000;
  1404.             lastDds = System.currentTimeMillis();
  1405.             actionInterval = getbattleTimer();
  1406.             lastAction = System.currentTimeMillis();
  1407.         }
  1408.         if (playerEquipment[playerWeapon] == 4827 && specialAmount > 74
  1409.                 && specOn && AttackingOn2.currentHealth > 0) {
  1410.             specialAtk(true, 75, 250, 1074);
  1411.             hitDiff = Misc.random(maxRangeHit()) + Misc.random(23);
  1412.             rangeGFX(85, 643);
  1413.             rangeGFX(65, 643);
  1414.             actionInterval = getbattleTimer();
  1415.             lastAction = System.currentTimeMillis();
  1416.             specAttack();
  1417.             usingSpecial = true;
  1418.         }
  1419.         if (playerEquipment[playerWeapon] == 861 && specialAmount > 74
  1420.                 && specOn && AttackingOn2.currentHealth > 0) {
  1421.             specialAtk(true, 75, 256, 1074);
  1422.             hitDiff = Misc.random(maxRangeHit()) + Misc.random(3);
  1423.             rangeGFX(75, 249);
  1424.             rangeGFX(95, 249);
  1425.             specAttack();
  1426.             actionInterval = getbattleTimer();
  1427.             lastAction = System.currentTimeMillis();
  1428.             usingSpecial = true;
  1429.         }
  1430.         if (playerEquipment[playerWeapon] == 859 && specialAmount > 99
  1431.                 && specOn && AttackingOn2.currentHealth > 0) {
  1432.             specialAtk(false, 100, 250, 426);
  1433.             hitDiff = Misc.random(maxRangeHit()) + Misc.random(10);
  1434.             rangeGFX(75, 249);
  1435.             specAttack();
  1436.         }
  1437.  
  1438.         if (AttackingOn2.playerEquipment[AttackingOn2.playerRing] == 2570
  1439.                 && AttackingOn2.currentHealth > 0
  1440.                 && AttackingOn2.currentHealth < 6) {
  1441.             AttackingOn2.triggerTele(3689 + Misc.random(3), 3468 + Misc
  1442.                     .random(3), 0);
  1443.             AttackingOn2.playerEquipment[AttackingOn2.playerRing] = -1;
  1444.             AttackingOn2.playerEquipmentN[AttackingOn2.playerRing] = 0;
  1445.             AttackingOn2.setEquipment(-1, 0, AttackingOn2.playerRing);
  1446.         }
  1447.         if (GoodDistance(EnemyX, EnemyY, absX, absY, 1) == true && !UseBow
  1448.                 && !UseCrossBow && !UseRing) {
  1449.             inCombat = true;
  1450.             lastCombat = System.currentTimeMillis();
  1451.             if (isInPitGame()
  1452.                     && !AttackingOn2.isInPitRoom()
  1453.                     || isInWilderness(absX, absY, 1) == true
  1454.                     && AttackingOn2.isInWilderness(AttackingOn2.absX,
  1455.                             AttackingOn2.absY, 1) == true
  1456.                     || matchId == PlayerHandler.players[AttackingOn].matchId
  1457.                     && matchId >= 0) {
  1458.                 if (PlayerHandler.players[AttackingOn].deathStage > 0) {
  1459.                     ResetAttack();
  1460.                 } else {
  1461.                     if (inRange(EnemyX, EnemyY)) {
  1462.                         if (thisAttack - lastAttack >= 4000)
  1463.                             ((Client) PlayerHandler.players[AttackingOn])
  1464.                                     .sM("You are under attack!");
  1465.                         PlayerHandler.players[AttackingOn].resetWalkingQueue();
  1466.                         PlayerHandler.players[AttackingOn].hits++;
  1467.                         PlayerHandler.players[AttackingOn].fighting = true;
  1468.                         PlayerHandler.players[AttackingOn].fightId = localId;
  1469.                         PlayerHandler.players[AttackingOn].IsAttacking = true;
  1470.                         ((Client) PlayerHandler.players[AttackingOn]).Attack();
  1471.                         fightId = AttackingOn;
  1472.                         fighting = true;
  1473.                         resetWalkingQueue();
  1474.                     }
  1475.                     if (AttackingOn2.hitID != playerId
  1476.                             && AttackingOn2.hitID != 0 && !multiCombat()) {
  1477.                         sM("Someone else is already fighting your opponent.");
  1478.                         ResetAttack();
  1479.                         faceNPC(32768 + AttackingOn);
  1480.                         return false;
  1481.                     }
  1482.                     Client player = (Client) PlayerHandler.players[playerId];
  1483.                     if (AttackingOn2.vengon && hitDiff != 0) {
  1484.                         player.hitDiff = (int) (hitDiff / 1.2);
  1485.                         player.currentHealth -= (int) (hitDiff / 1.2);
  1486.                         player.hitUpdateRequired = true; // So the hit will
  1487.                         // append to you.
  1488.                         player.updateRequired = true; // So the hit will append
  1489.                         // to you.
  1490.                         player.appearanceUpdateRequired = true; // So the hit
  1491.                         // will append
  1492.                         // to you.
  1493.                         AttackingOn2.vengon = false;
  1494.                         AttackingOn2.plrText = "Taste vengeance!"; // This says
  1495.                         // it in
  1496.                         // itself.
  1497.                         AttackingOn2.plrTextUpdateRequired = true; // Make sure
  1498.                         // the txt4
  1499.                         // will
  1500.                         // update.
  1501.                     }
  1502.                     double TotalExp = 0;
  1503.                     if (UseBow || UseCrossBow) {
  1504.                         TotalExp = (double) (120 * hitDiff);
  1505.                         TotalExp = (double) (TotalExp * CombatExpRate);
  1506.                         addSkillXP((int) (TotalExp), 4);
  1507.                     } else if (FightType != 3) {
  1508.                         TotalExp = (double) (120 * hitDiff);
  1509.                         TotalExp = (double) (TotalExp * CombatExpRate);
  1510.                         addSkillXP((int) (TotalExp), SkillID);
  1511.                     } else {
  1512.                         TotalExp = (double) (50 * hitDiff);
  1513.                         TotalExp = (double) (TotalExp * CombatExpRate);
  1514.                         addSkillXP((int) (TotalExp), playerAttack);
  1515.                         addSkillXP((int) (TotalExp), playerDefence);
  1516.                         addSkillXP((int) (TotalExp), playerStrength);
  1517.                     }
  1518.                     TotalExp = (double) (50 * hitDiff);
  1519.                     TotalExp = (double) (TotalExp * CombatExpRate);
  1520.                     addSkillXP((int) (TotalExp), playerHitpoints);
  1521.                     attackTimer = 7;
  1522.                     setAnimation(GetWepAnim(playerEquipment[playerWeapon]));
  1523.                     AttackingOn2.killerId = playerId;
  1524.                     actionInterval = getbattleTimer();
  1525.                     lastAction = System.currentTimeMillis();
  1526.                     AttackingOn2.setAnimation(AttackingOn2.GetBlockAnim());
  1527.                     AttackingOn2.offTimer = System.currentTimeMillis();
  1528.                     AttackingOn2.hitID = playerId;
  1529.                     if (AttackingOn2.prayOn && AttackingOn2.Redemption
  1530.                             && AttackingOn2.currentHealth < 10
  1531.                             && AttackingOn2.currentHealth > 0) {
  1532.                         AttackingOn2.prayOff();
  1533.                         AttackingOn2.currentHealth += 20;
  1534.                         AttackingOn2.lowGFX(436, 0);
  1535.                         AttackingOn2.playerLevel[5] = 0;
  1536.                     }
  1537.                     if (specOn == true && AttackingOn2.currentHealth > 0
  1538.                             && GoodDistance(EnemyX, EnemyY, absX, absY, 1)) {// players
  1539.                         if (playerEquipment[playerWeapon] == 3204
  1540.                                 && specialAmount > 74) {
  1541.                             specialAtk(true, 75, 282, 1203);
  1542.                             getHit(3);
  1543.                             usingSpecial = true;
  1544.                         }
  1545.                         if (playerEquipment[playerWeapon] == 5698
  1546.                                 && specialAmount > 24) {
  1547.                             specialAtk(true, 25, 252, 0x426);
  1548.                             getHit(8);
  1549.                             usingSpecial = true;
  1550.                         }
  1551.                         if (playerEquipment[playerWeapon] == 1305
  1552.                                 && specialAmount > 24) {
  1553.                             specialAtk(false, 25, 248, 1058);
  1554.                             getHit(10);
  1555.                         }
  1556.                         if (playerEquipment[playerWeapon] == 4587
  1557.                                 && specialAmount > 74) {
  1558.                             specialAtk(false, 75, 347, 1872);
  1559.                             getHit(0);
  1560.                             AttackingOn2.setClientConfig(95, 0);
  1561.                             AttackingOn2.setClientConfig(96, 0);
  1562.                             AttackingOn2.setClientConfig(97, 0);
  1563.                             AttackingOn2.ProtMage = false;
  1564.                             AttackingOn2.ProtRange = false;
  1565.                             AttackingOn2.ProtMelee = false;
  1566.                             AttackingOn2.sM("You have been injured!");
  1567.                             AttackingOn2.checkHead();
  1568.                         }
  1569.                         if (playerEquipment[playerWeapon] == 4151
  1570.                                 && specialAmount > 49) {
  1571.                             AttackingOn2.specGFX(341);
  1572.                             specialAmount -= 50;
  1573.                             hitDiff = Misc.random(playerMaxHit)
  1574.                                     + Misc.random(StrPrayer)
  1575.                                     + Misc.random(voidmelee);
  1576.                             lastSpecial = System.currentTimeMillis();
  1577.                             setAnimation(1658);
  1578.                             actionInterval = getbattleTimer();
  1579.                             lastAction = System.currentTimeMillis();
  1580.                             specOn = false;
  1581.                         }
  1582.                         if (playerEquipment[playerWeapon] == 667
  1583.                                 && specialAmount > 99) {
  1584.                             AttackingOn2.playerLevel[1] -= hitDiff;
  1585.                             AttackingOn2.sendQuest(""
  1586.                                     + AttackingOn2.playerLevel[0] + "", 4004);
  1587.                             AttackingOn2.sendQuest(""
  1588.                                     + AttackingOn2.playerLevel[1] + "", 4008);
  1589.                             AttackingOn2.sendQuest(""
  1590.                                     + AttackingOn2.playerLevel[2] + "", 4006);
  1591.                             AttackingOn2.sendQuest(""
  1592.                                     + AttackingOn2.playerLevel[4] + "", 4010);
  1593.                             AttackingOn2.sendQuest(""
  1594.                                     + AttackingOn2.playerLevel[5] + "", 4012);
  1595.                             AttackingOn2.sendQuest(""
  1596.                                     + AttackingOn2.playerLevel[6] + "", 4014);
  1597.                             setAnimation(2927);
  1598.                             specialAmount -= 100;
  1599.                             lastSpecial = System.currentTimeMillis();
  1600.                             specGFX(654);
  1601.                             getHit(10);
  1602.                             specOn = false;
  1603.                         }
  1604.                         if (playerEquipment[playerWeapon] == 35
  1605.                                 && specialAmount > 49) {
  1606.                             setAnimation(3547);
  1607.                             specialAmount -= 50;
  1608.                             getHit(30);
  1609.                             specOn = false;
  1610.                             lastSpecial = System.currentTimeMillis();
  1611.                             specGFX(655);
  1612.                         }
  1613.                         if (playerEquipment[playerWeapon] == 2402
  1614.                                 && specialAmount > 49) {
  1615.                             specialAtk(false, 50, 600, 2967);
  1616.                             specGFX(611);
  1617.                             getHit(0);
  1618.                             currentHealth += hitDiff;
  1619.                             playerLevel[5] += 5 + Misc.random(15);
  1620.                             sendQuest("" + playerLevel[5] + "", 4012);
  1621.                             if (currentHealth > playerLevel[playerHitpoints])
  1622.                                 currentHealth = playerLevel[playerHitpoints];
  1623.                             sendQuest("" + currentHealth + "", 4016);
  1624.                             if (playerLevel[5] > getLevelForXP(playerXP[5]))
  1625.                                 playerLevel[5] = getLevelForXP(playerXP[5]);
  1626.                             sendQuest("" + playerLevel[5] + "", 4012);
  1627.                         }
  1628.                         if (playerEquipment[playerWeapon] == 746
  1629.                                 && specialAmount > 74) {
  1630.                             stillgfx(369, EnemyY, EnemyX);
  1631.                             stillgfx(644, absY, absX);
  1632.                             specialAtk(false, 75, 600, 2927);
  1633.                             getHit(0);
  1634.                             AttackingOn2.EntangleDelay = 5;
  1635.                         }
  1636.                         if (playerEquipment[playerWeapon] == 8100
  1637.                                 && specialAmount > 99) {
  1638.                             specialAtk(true, 100, 600, 811);
  1639.                             AttackingOn2.specGFX(656);
  1640.                             getHit(5);
  1641.                             usingSpecial = true;
  1642.                         }
  1643.                         specAttack();
  1644.                         actionInterval = getbattleTimer();
  1645.                         lastAction = System.currentTimeMillis();
  1646.                     }
  1647.                     if (playerEquipment[playerShield] == 2621
  1648.                             && Misc.random(6) == 1) {
  1649.                         specialAtk(true, 0, 600, 2836);
  1650.                         hitDiff = Misc.random(25);
  1651.                         AttackingOn2.lowGFX(579, 0);
  1652.                     }
  1653.                     if (AttackingOn2.autoRetaliate == 1
  1654.                             && AttackingOn2.AttackingOn == 0) {
  1655.                         AttackingOn2.AttackingOn = playerId;
  1656.                         AttackingOn2.IsAttacking = true;
  1657.                     }
  1658.                     if (hasCrystalShield()) {
  1659.                         shieldLeft -= 1;
  1660.                         ;
  1661.                     }
  1662.                     if (AttackingOn2.playerEquipment[playerRing] == 2550
  1663.                             && hitDiff > 0) {
  1664.                         applyRecoil();
  1665.                     }
  1666.                     if (AttackingOn2.playerEquipment[playerRing] == 2550
  1667.                             && Misc.random(15) == 1) {
  1668.                         AttackingOn2.sM("Your ring of recoil shatters.");
  1669.                         AttackingOn2.playerEquipment[AttackingOn2.playerRing] = -1;
  1670.                         AttackingOn2.playerEquipmentN[AttackingOn2.playerRing] = 0;
  1671.                         AttackingOn2.setEquipment(-1, 0,
  1672.                                 AttackingOn2.playerRing);
  1673.                     }
  1674.                     if (AttackingOn2.tStage == 0) {
  1675.                         PlayerHandler.players[AttackingOn].hitUpdateRequired = true;
  1676.                         PlayerHandler.players[AttackingOn].updateRequired = true;
  1677.                         PlayerHandler.players[AttackingOn].appearanceUpdateRequired = true;
  1678.                     }
  1679.                     if ((AttackingOn2.currentHealth - hitDiff) < 0) {
  1680.                         hitDiff = AttackingOn2.currentHealth;
  1681.                     }
  1682.                     if (AttackingOn2.tStage == 0) {
  1683.                         PlayerHandler.players[AttackingOn].dealDamage(hitDiff);
  1684.                         PlayerHandler.players[AttackingOn].hitDiff = hitDiff;
  1685.                         PlayerHandler.players[AttackingOn].killers[playerId] += hitDiff;
  1686.                         PlayerHandler.players[AttackingOn].KilledBy[playerId] += hitDiff;
  1687.                     }
  1688.                     attackTimer = 7;
  1689.                     lastAttack = System.currentTimeMillis();
  1690.                     // sM("You hit " + hitDiff + ", time=" +
  1691.                     // lastAttack);
  1692.                 }
  1693.                 return true;
  1694.             } else {
  1695.                 sM("This player is not in the wilderness!");
  1696.                 ResetAttack();
  1697.             }
  1698.         }
  1699.  
  1700.         if (isInPitGame()
  1701.                 && !AttackingOn2.isInPitRoom()
  1702.                 || isInWilderness(absX, absY, 1) == true
  1703.                 && AttackingOn2.isInWilderness(AttackingOn2.absX,
  1704.                         AttackingOn2.absY, 1) == true) {
  1705.             if (PlayerHandler.players[AttackingOn].deathStage > 0) {
  1706.                 ResetAttack();
  1707.  
  1708.                 if ((EnemyHP - hitDiff) <= 0) {
  1709.                     hitDiff = EnemyHP;
  1710.                     // animation(437, absY, absX);
  1711.  
  1712.                 }
  1713.             } else if (UseBow || UseCrossBow || UseRing) {
  1714.                 if (AttackingOn2.skulledBy != playerName && !isInPitGame()) {
  1715.                     lastSkull = System.currentTimeMillis();
  1716.                     isSkulled = true;
  1717.                     skulledBy = AttackingOn2.playerName;
  1718.                     getHead();
  1719.                 }
  1720.                 if (AttackingOn2.hitID != playerId && AttackingOn2.hitID != 0
  1721.                         && !multiCombat()) {
  1722.                     sM("Someone else is already fighting your opponent.");
  1723.                     ResetAttack();
  1724.                     faceNPC(32768 + AttackingOn);
  1725.                     return false;
  1726.                 }
  1727.                 if (AttackingOn2.autoRetaliate == 1
  1728.                         && AttackingOn2.AttackingOn == 0) {
  1729.                     AttackingOn2.AttackingOn = playerId;
  1730.                     AttackingOn2.IsAttacking = true;
  1731.                 }
  1732.                 if (hasCrystalShield()) {
  1733.                     shieldLeft -= 1;
  1734.                     ;
  1735.                 }
  1736.                 if (AttackingOn2.playerEquipment[playerRing] == 2550
  1737.                         && hitDiff > 0) {
  1738.                     applyRecoil();
  1739.                 }
  1740.                 if (AttackingOn2.playerEquipment[playerRing] == 2550
  1741.                         && Misc.random(15) == 1) {
  1742.                     AttackingOn2.sM("Your ring of recoil shatters.");
  1743.                     AttackingOn2.playerEquipment[AttackingOn2.playerRing] = -1;
  1744.                     AttackingOn2.playerEquipmentN[AttackingOn2.playerRing] = 0;
  1745.                     AttackingOn2.setEquipment(-1, 0, AttackingOn2.playerRing);
  1746.                 }
  1747.                 AttackingOn2.killerId = playerId;
  1748.                 setAnimation(GetWepAnim(playerEquipment[playerWeapon]));
  1749.                 lastArrow = System.currentTimeMillis();
  1750.                 arrow = true;
  1751.                 AttackingOn2.offTimer = System.currentTimeMillis();
  1752.                 double TotalExp = 0;
  1753.                 if (UseBow || UseCrossBow) {
  1754.                     TotalExp = (double) (120 * hitDiff);
  1755.                     TotalExp = (double) (TotalExp * CombatExpRate);
  1756.                     addSkillXP((int) (TotalExp), 4);
  1757.                 } else if (FightType != 3) {
  1758.                     TotalExp = (double) (120 * hitDiff);
  1759.                     TotalExp = (double) (TotalExp * CombatExpRate);
  1760.                     addSkillXP((int) (TotalExp), SkillID);
  1761.                 } else {
  1762.                     TotalExp = (double) (50 * hitDiff);
  1763.                     TotalExp = (double) (TotalExp * CombatExpRate);
  1764.                     addSkillXP((int) (TotalExp), playerAttack);
  1765.                     addSkillXP((int) (TotalExp), playerDefence);
  1766.                     addSkillXP((int) (TotalExp), playerStrength);
  1767.                 }
  1768.                 TotalExp = (double) (50 * hitDiff);
  1769.                 TotalExp = (double) (TotalExp * CombatExpRate);
  1770.                 addSkillXP((int) (TotalExp), playerHitpoints);
  1771.                 attackTimer = 7;
  1772.                 lastAttack = System.currentTimeMillis();
  1773.                 Client player = (Client) PlayerHandler.players[playerId];
  1774.                 if (AttackingOn2.vengon && hitDiff != 0) {
  1775.                     player.hitDiff = (int) (hitDiff / 1.2);
  1776.                     player.currentHealth -= (int) (hitDiff / 1.2);
  1777.                     player.hitUpdateRequired = true; // So the hit will append
  1778.                     // to you.
  1779.                     player.updateRequired = true; // So the hit will append to
  1780.                     // you.
  1781.                     player.appearanceUpdateRequired = true; // So the hit will
  1782.                     // append to you.
  1783.                     AttackingOn2.vengon = false;
  1784.                     AttackingOn2.plrText = "Taste vengeance!"; // This says it
  1785.                     // in itself.
  1786.                     AttackingOn2.plrTextUpdateRequired = true; // Make sure the
  1787.                     // txt4 will
  1788.                     // update.
  1789.                 }
  1790.                 if (Smite == true && AttackingOn2.playerLevel[5] > 0
  1791.                         && GoodDistance(EnemyX, EnemyY, absX, absY, 1)) {
  1792.                     AttackingOn2.playerLevel[5] -= hitDiff / 4;
  1793.                     AttackingOn2.sendQuest("" + AttackingOn2.playerLevel[5]
  1794.                             + "", 4012);
  1795.                     AttackingOn2
  1796.                             .sendFrame126("Prayer: "
  1797.                                     + AttackingOn2.playerLevel[5] + "/"
  1798.                                     + AttackingOn2.getLevelForXP(playerXP[5])
  1799.                                     + "", 687);
  1800.                 }
  1801.                 if (playerEquipment[playerShield] == 2621
  1802.                         && Misc.random(6) == 1) {
  1803.                     specialAtk(true, 0, 600, 2836);
  1804.                     getHitDouble(25);
  1805.                     AttackingOn2.lowGFX(579, 0);
  1806.                 }
  1807.             }
  1808.             return true;
  1809.         } else {
  1810.             sM("This player is not in the wilderness!");
  1811.             ResetAttack();
  1812.         }
  1813.         return false;
  1814.     }
  1815.  
  1816.     private boolean AttackNPC() {
  1817.  
  1818.         if (hasKnife()) {
  1819.  
  1820.             sM("Knives are disabled for now!");
  1821.             ResetAttackNPC();
  1822.             return false;
  1823.         }
  1824.         int EnemyX = Server.npcHandler.npcs[attacknpc].absX;
  1825.         int EnemyY = Server.npcHandler.npcs[attacknpc].absY;
  1826.         int EnemyHP = Server.npcHandler.npcs[attacknpc].HP;
  1827.         int hitDiff = 0;
  1828.  
  1829.         if (EnemyHP < 1) {
  1830.             sM("");
  1831.             return false;
  1832.         }
  1833.         int type = Server.npcHandler.npcs[attacknpc].npcType;
  1834.         int[] staffs = { 1381, 1383, 1385, 1387, 4675 };
  1835.         int[] arrowIds = { 882, 884, 886, 888, 890, 892, 78 };
  1836.         int[] arrowGfx = { 10, 9, 11, 12, 13, 15, 16 };
  1837.  
  1838.         if (!FullVeracEquipped() && type == 1160) {
  1839.             sM("The kalphite queen seems uneffected by your attacks..");
  1840.             ResetAttackNPC();
  1841.             return false;
  1842.         }
  1843.         if (type == 1616) {
  1844.             if (playerLevel[18] < 10) {
  1845.                 sM("You must be level 10 slayer or higher to attack this monster.");
  1846.                 ResetAttackNPC();
  1847.                 return false;
  1848.             }
  1849.         }
  1850.         if (type == 1637) {
  1851.             if (playerLevel[18] < 30) {
  1852.                 sM("You must be level 30 slayer or higher to attack this monster.");
  1853.                 ResetAttackNPC();
  1854.                 return false;
  1855.             }
  1856.         }
  1857.         if (type == 1626) {
  1858.             if (playerLevel[18] < 45) {
  1859.                 sM("You must be level 45 slayer or higher to attack this monster.");
  1860.                 ResetAttackNPC();
  1861.                 return false;
  1862.             }
  1863.         }
  1864.         if (type == 1624) {
  1865.             if (playerLevel[18] < 60) {
  1866.                 sM("You must be level 60 slayer or higher to attack this monster.");
  1867.                 ResetAttackNPC();
  1868.                 return false;
  1869.             }
  1870.         }
  1871.         if (type == 1615) {
  1872.             if (playerLevel[18] < 85) {
  1873.                 sM("You must be level 85 slayer or higher to attack this monster.");
  1874.                 ResetAttackNPC();
  1875.                 return false;
  1876.             }
  1877.         }
  1878.         if (type == 1613) {
  1879.             if (playerLevel[18] < 70) {
  1880.                 sM("You must be level 70 slayer or higher to attack this monster.");
  1881.                 ResetAttackNPC();
  1882.                 return false;
  1883.             }
  1884.         }
  1885.         if (type == 2783) {
  1886.             if (playerLevel[18] < 90) {
  1887.                 sM("You must be level 90 slayer or higher to attack this monster.");
  1888.                 ResetAttackNPC();
  1889.                 return false;
  1890.             }
  1891.         }
  1892.         if ((type == 110) || (type == 936)) {
  1893.             if (!playerHasItem(1543)) {
  1894.                 resetPos();
  1895.                 ResetAttackNPC();
  1896.                 return false;
  1897.             }
  1898.         }
  1899.         if ((type == 221) || (type == 1961)) {
  1900.             if (!playerHasItem(1544)) {
  1901.                 resetPos();
  1902.                 ResetAttackNPC();
  1903.                 return false;
  1904.             }
  1905.         }
  1906.         for (int element : staffs) {
  1907.             if ((playerEquipment[playerWeapon] == element) && autocasting
  1908.                     && autocastID > 0) {
  1909.                 int npcTargetX = Server.npcHandler.npcs[attacknpc].absX;
  1910.                 int npcTargetY = Server.npcHandler.npcs[attacknpc].absY;
  1911.                 int npcTargetHealth = Server.npcHandler.npcs[attacknpc].HP;
  1912.                 if (System.currentTimeMillis() - lastAttack < 4000) {
  1913.                     // sM("You must wait 4 seconds before casting this kind of spell again");
  1914.                     return false;
  1915.                 }
  1916.                 if (!playerMage2(attacknpc)) {
  1917.                     return false;
  1918.                 }
  1919.                 inCombat = true;
  1920.                 lastCombat = System.currentTimeMillis();
  1921.                 lastAttack = lastCombat;
  1922.  
  1923.                 TurnPlayerTo(npcTargetX, npcTargetY);
  1924.                 updateRequired = true;
  1925.                 appearanceUpdateRequired = true;
  1926.  
  1927.                 toX = absX;
  1928.                 toY = absY;
  1929.                 newWalkCmdSteps = 0;
  1930.                 newWalkCmdX[0] = newWalkCmdY[0] = tmpNWCX[0] = tmpNWCY[0] = 0;
  1931.                 getNextPlayerMovement();
  1932.                 MagicHandler.npcX = npcTargetX;
  1933.                 MagicHandler.npcY = npcTargetY;
  1934.                 MagicHandler.npcHP = npcTargetHealth;
  1935.                 Server.npcHandler.npcs[attacknpc].hitIDNPC = playerId;
  1936.                 Server.npcHandler.npcs[attacknpc].offTimerNPC = 12;
  1937.                 spellNpcIndex = MagicHandler.magicSpellNpc(autocastID,
  1938.                         playerId, attacknpc, playerLevel[6]);
  1939.                 return true;
  1940.             }
  1941.         }
  1942.         long thisTime = System.currentTimeMillis();
  1943.         int voidmelee = 0;
  1944.         if (FullVMelee()) {
  1945.             voidmelee += 10;
  1946.         }
  1947.         if (npcHit()) {
  1948.             hitDiff = Misc.random(playerMaxHit) + Misc.random(StrPrayer) + Misc.random(voidmelee);
  1949.         } else {
  1950.             hitDiff = 0;
  1951.         }
  1952.         boolean UseBow = false;
  1953.         boolean UseCrossBow = false;
  1954.         boolean UseRing = false;
  1955.  
  1956.         for (int i = 0; i < shortbow.length; i++) {
  1957.             if ((playerEquipment[playerWeapon] == shortbow[i])
  1958.                     || (playerEquipment[playerWeapon] == longbow[i])) {
  1959.                 UseBow = true;
  1960.                 break;
  1961.             }
  1962.         }
  1963.         if (playerEquipment[playerWeapon] == 837) {
  1964.             UseCrossBow = true;
  1965.         }
  1966.         if (playerEquipment[playerWeapon] == 6522) {
  1967.             UseRing = true;
  1968.         }
  1969.         if (UseBow) {
  1970.             HasArrows = false;
  1971.             CheckArrows();
  1972.             // CalculateRange();
  1973.             hitDiff = npcRangeDamage();
  1974.             // drawback();
  1975.             DropArrowsNPC();
  1976.  
  1977.         }
  1978.         if (UseCrossBow) {
  1979.             HasBolts = false;
  1980.             CheckBolts();
  1981.             // CalculateRange();
  1982.             hitDiff = npcRangeDamage();
  1983.         }
  1984.         if (UseRing) {
  1985.             HasRings = false;
  1986.             CheckRings();
  1987.             // CalculateRange();
  1988.             hitDiff = npcRangeDamage();
  1989.         }
  1990.  
  1991.         if (UseBow || UseCrossBow || UseRing) {
  1992.             if (GoodDistance(EnemyX, EnemyY, absX, absY, 8) == false) {
  1993.                 sM("You are too far to range your enemy!");
  1994.                 ResetAttackNPC();
  1995.                 return false;
  1996.             }
  1997.         }
  1998.         if (type == 3200 && !UseBow && !UseCrossBow && !UseRing) {
  1999.             sM("You can only use magic and range on the Chaos Elemental!");
  2000.             ResetAttackNPC();
  2001.             return false;
  2002.         }
  2003.         @SuppressWarnings("unused")
  2004.         int arrowgfx = 10;
  2005.         for (int i1 = 0; i1 < arrowIds.length; i1++) {
  2006.             if (playerEquipment[playerArrows] == arrowIds[i1]) {
  2007.                 arrowgfx = arrowGfx[i1];
  2008.             }
  2009.         }
  2010.         if (hasCrystalBow()) {
  2011.             arrowgfx = 249;
  2012.         }
  2013.         if (UseBow && playerEquipment[playerWeapon] == 4734
  2014.                 && System.currentTimeMillis() - lastAction > actionInterval) {
  2015.             // CalculateRange();
  2016.             hitDiff = npcRangeDamage();
  2017.             if (DeleteArrow() && playerEquipment[playerArrows] == 4740) {
  2018.                 actionInterval = getbattleTimer();
  2019.                 lastAction = System.currentTimeMillis();
  2020.             } else {
  2021.                 ResetAttackNPC();
  2022.                 sM("You're out of bolts!");
  2023.                 return false;
  2024.             }
  2025.         }
  2026.         if (hasCrystalBow()
  2027.                 && System.currentTimeMillis() - lastAction > actionInterval) {
  2028.             // CalculateRange();
  2029.             drawback();
  2030.             if (DeleteArrow()) {
  2031.                 lastArrow = System.currentTimeMillis();
  2032.                 arrow = true;
  2033.                 arrowsLeft -= 1;
  2034.                 actionInterval = getbattleTimer();
  2035.                 lastAction = System.currentTimeMillis();
  2036.             } else {
  2037.                 ResetAttackNPC();
  2038.                 sM("You're out of bolts!");
  2039.                 return false;
  2040.             }
  2041.         }
  2042.         if (UseBow && playerEquipment[playerWeapon] != 4734 && !hasCrystalBow()
  2043.                 && playerEquipment[playerWeapon] != 4827
  2044.                 && System.currentTimeMillis() - lastAction > actionInterval) {
  2045.             // CalculateRange();
  2046.             drawback();
  2047.             hitDiff = npcRangeDamage();
  2048.             if (DeleteArrow() && HasArrows) {
  2049.                 lastArrow = System.currentTimeMillis();
  2050.                 arrow = true;
  2051.                 actionInterval = getbattleTimer();
  2052.                 lastAction = System.currentTimeMillis();
  2053.             } else {
  2054.                 ResetAttackNPC();
  2055.                 sM("There is no ammo left in your quiver.");
  2056.                 return false;
  2057.             }
  2058.         }
  2059.         if (UseBow && playerEquipment[playerWeapon] == 4827
  2060.                 && System.currentTimeMillis() - lastAction > actionInterval) {
  2061.             // CalculateRange();
  2062.             drawback();
  2063.             hitDiff = npcRangeDamage();
  2064.             if (DeleteArrow() && HasArrows) {
  2065.                 lastArrow = System.currentTimeMillis();
  2066.                 arrow = true;
  2067.                 actionInterval = getbattleTimer();
  2068.                 lastAction = System.currentTimeMillis();
  2069.             } else {
  2070.                 ResetAttackNPC();
  2071.                 sM("There is no ammo left in your quiver.");
  2072.                 return false;
  2073.             }
  2074.         }
  2075.  
  2076.         if (UseCrossBow
  2077.                 && System.currentTimeMillis() - lastAction > actionInterval) {
  2078.             // CalculateRange();
  2079.             hitDiff = npcRangeDamage();
  2080.             if (DeleteArrow() && HasBolts) {
  2081.                 lastArrow = System.currentTimeMillis();
  2082.                 arrow = true;
  2083.                 actionInterval = getbattleTimer();
  2084.                 lastAction = System.currentTimeMillis();
  2085.             } else {
  2086.                 ResetAttackNPC();
  2087.                 sM("There is no ammo left in your quiver.");
  2088.                 return false;
  2089.             }
  2090.         }
  2091.         if (UseRing && System.currentTimeMillis() - lastAction > actionInterval) {
  2092.             // CalculateRange();
  2093.             hitDiff = npcRangeDamage();
  2094.             if (deleteRing() && HasRings) {
  2095.                 lastArrow = System.currentTimeMillis();
  2096.                 arrow = true;
  2097.                 actionInterval = getbattleTimer();
  2098.                 lastAction = System.currentTimeMillis();
  2099.             } else {
  2100.                 ResetAttackNPC();
  2101.                 return false;
  2102.             }
  2103.         }
  2104.         actionInterval = getbattleTimer();
  2105.         lastAction = System.currentTimeMillis();
  2106.         inCombat = true;
  2107.         lastCombat = System.currentTimeMillis();
  2108.         if (UseCrossBow || UseBow || UseRing
  2109.                 || GoodDistance(EnemyX, EnemyY, absX, absY, 1) == true) {
  2110.             if (Server.npcHandler.npcs[attacknpc].IsDead == true) {
  2111.                 ResetAttackNPC();
  2112.             } else {
  2113.                 if (Server.npcHandler.npcs[attacknpc].hitIDNPC != 0
  2114.                         && Server.npcHandler.npcs[attacknpc].hitIDNPC != playerId
  2115.                         && !multiCombat()) {
  2116.                     sM("Someone else is already fighting your opponent.");
  2117.                     faceNPC(attacknpc);
  2118.                     ResetAttackNPC();
  2119.                     return false;
  2120.                 }
  2121.                 if (hitID != attacknpc && hitID != 0 && !multiCombat()) {
  2122.                     sM("I'm already under attack.");
  2123.                     faceNPC(attacknpc);
  2124.                     ResetAttackNPC();
  2125.                     return false;
  2126.                 }
  2127.                 if (type == 2630 && !UseBow && !UseCrossBow && !UseRing
  2128.                         && hitDiff > 0) {
  2129.                     applyRecoil();
  2130.                 }
  2131.  
  2132.                 if (playerEquipment[playerWeapon] == 6528
  2133.                         && playerEquipment[playerAmulet] == 6577
  2134.                         && Misc.random(3) == 1) {
  2135.                     hitDiff = Misc.random(8) + Misc.random(playerMaxHit)
  2136.                             + Misc.random(StrPrayer) + Misc.random(voidmelee);
  2137.                 }
  2138.                 if (FullDharokEquipped() && Misc.random(2) == 1
  2139.                         && currentHealth > 80 && currentHealth < 100) {
  2140.                     hitDiff = Misc.random(8) + Misc.random(playerMaxHit)
  2141.                             + Misc.random(StrPrayer);
  2142.  
  2143.                 }
  2144.                 if (FullDharokEquipped() && Misc.random(2) == 1
  2145.                         && currentHealth > 60 && currentHealth < 79) {
  2146.                     hitDiff = Misc.random(18) + Misc.random(playerMaxHit)
  2147.                             + Misc.random(StrPrayer);
  2148.  
  2149.                 }
  2150.                 if (FullDharokEquipped() && Misc.random(2) == 1
  2151.                         && currentHealth > 40 && currentHealth < 59) {
  2152.                     hitDiff = Misc.random(28) + Misc.random(playerMaxHit)
  2153.                             + Misc.random(StrPrayer);
  2154.  
  2155.                 }
  2156.                 if (FullDharokEquipped() && Misc.random(2) == 1
  2157.                         && currentHealth > 20 && currentHealth < 39) {
  2158.                     hitDiff = Misc.random(38) + Misc.random(playerMaxHit)
  2159.                             + Misc.random(StrPrayer);
  2160.  
  2161.                 }
  2162.                 if (FullDharokEquipped() && Misc.random(2) == 1
  2163.                         && currentHealth > 0 && currentHealth < 18) {
  2164.                     hitDiff = Misc.random(58) + Misc.random(playerMaxHit)
  2165.                             + Misc.random(StrPrayer);
  2166.  
  2167.                 }
  2168.                 if (FullGuthanEquipped()) {
  2169.                     if (Misc.random(3) == 1) {
  2170.                         if ((currentHealth + hitDiff) <= getLevelForXP(playerXP[3])) {
  2171.                             currentHealth += hitDiff;
  2172.                         }
  2173.                         if ((currentHealth + hitDiff) > getLevelForXP(playerXP[3])) {
  2174.                             currentHealth = getLevelForXP(playerXP[3]);
  2175.                         }
  2176.                         sendQuest("" + currentHealth + "", 4016);
  2177.                         stillgfx(398, EnemyY, EnemyX);
  2178.                     }
  2179.                 }
  2180.                 if (FullVeracEquipped()) {
  2181.                     if (Misc.random(2) == 1) {
  2182.                         hitDiff = Misc.random(playerMaxHit)
  2183.                                 + Misc.random(StrPrayer);
  2184.                     }
  2185.                 }
  2186.                 setAnimation(GetWepAnim(playerEquipment[playerWeapon]));
  2187.                 if (UseCrossBow && Misc.random(5) == 1
  2188.                         && playerEquipment[playerArrows] == 881) {
  2189.                     hitDiff = Misc.random(maxRangeHit2()) + Misc.random(30);
  2190.                     stillgfx(197, EnemyY, EnemyX);
  2191.                     actionInterval = getbattleTimer();
  2192.                     lastAction = System.currentTimeMillis();
  2193.                 }
  2194.                 if (playerEquipment[playerShield] == 2621
  2195.                         && Misc.random(6) == 1) {
  2196.                     specialAtkNPC(true, 0, 600, 2836);
  2197.                     hitDiff = Misc.random(25);
  2198.                     stillgfx(579, EnemyY, EnemyX);
  2199.                 }
  2200.                 if (playerEquipment[playerWeapon] == 4827 && !specOn) {
  2201.                     DDS2Damg = true;
  2202.                     ddsInterval = 2000;
  2203.                     lastDds = System.currentTimeMillis();
  2204.                     setAnimation(426);
  2205.                     actionInterval = getbattleTimer();
  2206.                     lastAction = System.currentTimeMillis();
  2207.                 }
  2208.                 if (specOn) {
  2209.                     if (playerEquipment[playerWeapon] == 4827
  2210.                             && specialAmount > 74) {
  2211.                         specialAtkNPC(true, 75, 250, 1074);
  2212.                         hitDiff = Misc.random(maxRangeHit2());
  2213.                         rangeGFXNPC(85, 643);
  2214.                         rangeGFXNPC(65, 643);
  2215.                     }
  2216.                     if (playerEquipment[playerWeapon] == 861
  2217.                             && specialAmount > 74) {
  2218.                         specialAtkNPC(true, 75, 256, 1074);
  2219.                         hitDiff = Misc.random(maxRangeHit2());
  2220.                         rangeGFXNPC(75, 249);
  2221.                         rangeGFXNPC(95, 249);
  2222.                     }
  2223.                     specAttack();
  2224.                     actionInterval = getbattleTimer();
  2225.                     lastAction = System.currentTimeMillis();
  2226.                 }
  2227.                 if (specOn == true) {// npcs
  2228.                     if (playerEquipment[playerWeapon] == 3204
  2229.                             && specialAmount > 74) {
  2230.                         specialAtkNPC(true, 75, 282, 1203);
  2231.                         npcDamage(5);
  2232.                     }
  2233.                     if (playerEquipment[playerWeapon] == 859
  2234.                             && specialAmount > 99) {
  2235.                         specialAtkNPC(false, 100, 250, 426);
  2236.                         hitDiff = Misc.random(maxRangeHit2()) + Misc.random(5);
  2237.                         rangeGFXNPC(75, 249);
  2238.                     }
  2239.                     if (playerEquipment[playerWeapon] == 5698
  2240.                             && specialAmount > 24) {
  2241.                         specialAtkNPC(true, 25, 252, 0x426);
  2242.                         npcDamage(8);
  2243.                     }
  2244.                     if (playerEquipment[playerWeapon] == 1305
  2245.                             && specialAmount > 24) {
  2246.                         specialAtkNPC(false, 25, 248, 1058);
  2247.                         npcDamage(8);
  2248.                     }
  2249.                     if (playerEquipment[playerWeapon] == 4578
  2250.                             && specialAmount > 74) {
  2251.                         specialAtkNPC(false, 75, 347, 1872);
  2252.                         npcDamage(0);
  2253.                     }
  2254.                     if (playerEquipment[playerWeapon] == 4151
  2255.                             && specialAmount > 49) {
  2256.                         specialAtkNPC(false, 50, 600, 1658);
  2257.                         stillgfx(341, EnemyY, EnemyX);
  2258.                     }
  2259.                     if (playerEquipment[playerWeapon] == 667
  2260.                             && specialAmount > 99) {
  2261.                         specialAtkNPC(false, 100, 600, 2927);
  2262.                         specGFX(654);
  2263.                     }
  2264.                     if (playerEquipment[playerWeapon] == 35
  2265.                             && specialAmount > 49) {
  2266.                         specialAtkNPC(false, 50, 600, 3547);
  2267.                         npcDamage(30);
  2268.                         specGFX(655);
  2269.                     }
  2270.                     if (playerEquipment[playerWeapon] == 2402
  2271.                             && specialAmount > 49) {
  2272.                         specialAtkNPC(false, 50, 600, 2927);
  2273.                         specGFX(611);
  2274.                         currentHealth += hitDiff;
  2275.                         playerLevel[5] += 5 + Misc.random(10);
  2276.                         if (currentHealth > playerLevel[playerHitpoints])
  2277.                             currentHealth = playerLevel[playerHitpoints];
  2278.                         sendQuest("" + currentHealth + "", 4016);
  2279.                         if (playerLevel[5] > getLevelForXP(playerXP[5]))
  2280.                             playerLevel[5] = getLevelForXP(playerXP[5]);
  2281.                         sendQuest("" + playerLevel[5] + "", 4012);
  2282.                     }
  2283.                     if (playerEquipment[playerWeapon] == 746
  2284.                             && specialAmount > 74) {
  2285.                         specialAtkNPC(false, 75, 600, 2927);
  2286.                         stillgfx(369, EnemyY, EnemyX);
  2287.                         stillgfx(644, absY, absX);
  2288.                     }
  2289.                     if (playerEquipment[playerWeapon] == 8100
  2290.                             && specialAmount > 99) {
  2291.                         specialAtkNPC(true, 100, 600, 811);
  2292.                         hitDiff = Misc.random(playerMaxHit) + Misc.random(5)
  2293.                                 + Misc.random(StrPrayer)
  2294.                                 + Misc.random(voidmelee);
  2295.                         stillgfx(656, EnemyY, EnemyX);
  2296.                     }
  2297.                     specAttack();
  2298.                     actionInterval = getbattleTimer();
  2299.                     lastAction = System.currentTimeMillis();
  2300.                 }
  2301.                 Server.npcHandler.npcs[attacknpc].hitIDNPC = playerId;
  2302.                 Server.npcHandler.npcs[attacknpc].offTimerNPC = 12;
  2303.                 Server.npcHandler.npcs[attacknpc].StartKilling = playerId;
  2304.                 Server.npcHandler.npcs[attacknpc].RandomWalk = false;
  2305.                 Server.npcHandler.npcs[attacknpc].IsUnderAttack = true;
  2306.                 actionInterval = getbattleTimer();
  2307.                 lastAction = System.currentTimeMillis();
  2308.                 faceNPC(attacknpc);
  2309.                 updateRequired = true;
  2310.                 appearanceUpdateRequired = true;
  2311.                 if (!UseBow && !UseCrossBow && !UseRing) {
  2312.                     if ((EnemyHP - hitDiff) < 0) {
  2313.                         hitDiff = EnemyHP;
  2314.                     }
  2315.                     Server.npcHandler.npcs[attacknpc].hitDiff = hitDiff;
  2316.                     Server.npcHandler.npcs[attacknpc].updateRequired = true;
  2317.                     Server.npcHandler.npcs[attacknpc].hitUpdateRequired = true;
  2318.                     Server.npcHandler.npcs[attacknpc].hit = true;
  2319.                 }
  2320.                 Server.npcHandler.npcs[attacknpc].Killing[playerId] += hitDiff;
  2321.                 attackedNpc = true;
  2322.                 attackedNpcId = attacknpc;
  2323.                 double TotalExp = 0;
  2324.                 if (!UseBow)
  2325.                     animationReset = System.currentTimeMillis() + 1200;
  2326.                 if (Server.npcHandler.npcs[attacknpc].npcType != 0) {
  2327.                     if (UseBow || UseCrossBow || UseRing) {
  2328.                         TotalExp = (double) (120 * hitDiff);
  2329.                         TotalExp = (double) (TotalExp * CombatExpRate);
  2330.                         addSkillXP((int) (TotalExp), 4);
  2331.                     } else if (FightType != 3) {
  2332.                         TotalExp = (double) (120 * hitDiff);
  2333.                         TotalExp = (double) (TotalExp * CombatExpRate);
  2334.                         addSkillXP((int) (TotalExp), SkillID);
  2335.                     } else {
  2336.                         TotalExp = (double) (50 * hitDiff);
  2337.                         TotalExp = (double) (TotalExp * CombatExpRate);
  2338.                         addSkillXP((int) (TotalExp), playerAttack);
  2339.                         addSkillXP((int) (TotalExp), playerDefence);
  2340.                         addSkillXP((int) (TotalExp), playerStrength);
  2341.                     }
  2342.                     TotalExp = (double) (50 * hitDiff);
  2343.                     TotalExp = (double) (TotalExp * CombatExpRate);
  2344.                     addSkillXP((int) (TotalExp), playerHitpoints);
  2345.                     attackTimer = 7;
  2346.                     specOn = false;
  2347.                     specAttack();
  2348.  
  2349.                     if (debug)
  2350.                         sM("hitDiff=" + hitDiff + ", elapsed="
  2351.                                 + (thisTime - lastAttack));
  2352.                     lastAttack = System.currentTimeMillis();
  2353.                 }
  2354.                 return true;
  2355.  
  2356.             }
  2357.         }
  2358.         return false;
  2359.     }
  2360.  
  2361.     public void attackPlayersWithin(int gfx, int maxDamage, int range) {
  2362.         // for (Player p : PlayerHandler.players) {
  2363.         // Linux (java 1.4.2-compatible) change - Devolution
  2364.         for (Player p : PlayerHandler.players) {
  2365.             if (p != null) {
  2366.                 Client person = (Client) p;
  2367.  
  2368.                 if (person.playerName != null) {
  2369.                     if ((person.distanceToPoint(absX, absY) <= range)
  2370.                             && (person.playerId != playerId)) {
  2371.                         int damage = Misc.random(maxDamage);
  2372.  
  2373.                         person.specGFX(gfx);
  2374.                         if (person.playerLevel[3] - damage < 0) {
  2375.                             damage = person.playerLevel[3];
  2376.                         }
  2377.                         person.hitDiff = damage;
  2378.                         person.killerId = playerId;
  2379.                         person.updateRequired = true;
  2380.                         person.hitUpdateRequired = true;
  2381.                         person.currentHealth -= Misc.random(30);
  2382.                     }
  2383.                 }
  2384.             }
  2385.         }
  2386.     }
  2387.  
  2388.     public void attackPlayersWithin2(int gfx, int maxDamage, int range) {
  2389.         // for (Player p : PlayerHandler.players) {
  2390.         // Linux (java 1.4.2-compatible) change - Devolution
  2391.         for (Player p : PlayerHandler.players) {
  2392.             if (p != null) {
  2393.                 Client person = (Client) p;
  2394.  
  2395.                 if (person.playerName != null) {
  2396.                     if ((person.distanceToPoint(absX, absY) <= range)
  2397.                             && (person.playerId != playerId)) {
  2398.                         int damage = Misc.random(maxDamage);
  2399.  
  2400.                         person.specGFX(gfx);
  2401.                         if (person.playerLevel[3] - damage < 0) {
  2402.                             damage = person.playerLevel[3];
  2403.                         }
  2404.                         if (person.ProtMage == false) {
  2405.                             person.hitDiff = damage;
  2406.                             person.killerId = playerId;
  2407.                             person.updateRequired = true;
  2408.                             person.hitUpdateRequired = true;
  2409.                             person.currentHealth -= Misc.random(30);
  2410.                         }
  2411.                         if (person.ProtMage == true) {
  2412.                             person.hitDiff = 0;
  2413.                             person.killerId = playerId;
  2414.                             person.updateRequired = true;
  2415.                             person.hitUpdateRequired = true;
  2416.                         }
  2417.                     }
  2418.                 }
  2419.             }
  2420.         }
  2421.     }
  2422.  
  2423.     public boolean bankItem(int itemID, int fromSlot, int amount) {
  2424.         if (!IsBanking)
  2425.             return false;
  2426.         if (playerItemsN[fromSlot] <= 0) {
  2427.             return false;
  2428.         }
  2429.         if (!Item.itemIsNote[playerItems[fromSlot] - 1]) {
  2430.             if (playerItems[fromSlot] <= 0) {
  2431.                 return false;
  2432.             }
  2433.             if (Item.itemStackable[playerItems[fromSlot] - 1]
  2434.                     || (playerItemsN[fromSlot] > 1)) {
  2435.                 int toBankSlot = 0;
  2436.                 boolean alreadyInBank = false;
  2437.  
  2438.                 for (int i = 0; i < playerBankSize; i++) {
  2439.                     if (bankItems[i] == playerItems[fromSlot]) {
  2440.                         if (playerItemsN[fromSlot] < amount) {
  2441.                             amount = playerItemsN[fromSlot];
  2442.                         }
  2443.                         alreadyInBank = true;
  2444.                         toBankSlot = i;
  2445.                         i = playerBankSize + 1;
  2446.                     }
  2447.                 }
  2448.  
  2449.                 if (!alreadyInBank && (freeBankSlots() > 0)) {
  2450.                     for (int i = 0; i < playerBankSize; i++) {
  2451.                         if (bankItems[i] <= 0) {
  2452.                             toBankSlot = i;
  2453.                             i = playerBankSize + 1;
  2454.                         }
  2455.                     }
  2456.                     bankItems[toBankSlot] = playerItems[fromSlot];
  2457.                     if (playerItemsN[fromSlot] < amount) {
  2458.                         amount = playerItemsN[fromSlot];
  2459.                     }
  2460.                     if (((bankItemsN[toBankSlot] + amount) <= maxItemAmount)
  2461.                             && ((bankItemsN[toBankSlot] + amount) > -1)) {
  2462.                         bankItemsN[toBankSlot] += amount;
  2463.                     } else {
  2464.                         sM("Bank full!");
  2465.                         return false;
  2466.                     }
  2467.                     deleteItem((playerItems[fromSlot] - 1), fromSlot, amount);
  2468.                     resetItems(5064);
  2469.                     resetBank();
  2470.                     return true;
  2471.                 } else if (alreadyInBank) {
  2472.                     if (((bankItemsN[toBankSlot] + amount) <= maxItemAmount)
  2473.                             && ((bankItemsN[toBankSlot] + amount) > -1)) {
  2474.                         bankItemsN[toBankSlot] += amount;
  2475.                     } else {
  2476.                         sM("Bank full!");
  2477.                         return false;
  2478.                     }
  2479.                     deleteItem((playerItems[fromSlot] - 1), fromSlot, amount);
  2480.                     resetItems(5064);
  2481.                     resetBank();
  2482.                     return true;
  2483.                 } else {
  2484.                     sM("Bank full!");
  2485.                     return false;
  2486.                 }
  2487.             } else {
  2488.                 itemID = playerItems[fromSlot];
  2489.                 int toBankSlot = 0;
  2490.                 boolean alreadyInBank = false;
  2491.  
  2492.                 for (int i = 0; i < playerBankSize; i++) {
  2493.                     if (bankItems[i] == playerItems[fromSlot]) {
  2494.                         alreadyInBank = true;
  2495.                         toBankSlot = i;
  2496.                         i = playerBankSize + 1;
  2497.                     }
  2498.                 }
  2499.                 if (!alreadyInBank && (freeBankSlots() > 0)) {
  2500.                     for (int i = 0; i < playerBankSize; i++) {
  2501.                         if (bankItems[i] <= 0) {
  2502.                             toBankSlot = i;
  2503.                             i = playerBankSize + 1;
  2504.                         }
  2505.                     }
  2506.                     int firstPossibleSlot = 0;
  2507.                     boolean itemExists = false;
  2508.  
  2509.                     while (amount > 0) {
  2510.                         itemExists = false;
  2511.                         for (int i = firstPossibleSlot; i < playerItems.length; i++) {
  2512.                             if ((playerItems[i]) == itemID) {
  2513.                                 firstPossibleSlot = i;
  2514.                                 itemExists = true;
  2515.                                 i = 30;
  2516.                             }
  2517.                         }
  2518.                         if (itemExists) {
  2519.                             bankItems[toBankSlot] = playerItems[firstPossibleSlot];
  2520.                             bankItemsN[toBankSlot] += 1;
  2521.                             deleteItem((playerItems[firstPossibleSlot] - 1),
  2522.                                     firstPossibleSlot, 1);
  2523.                             amount--;
  2524.                         } else {
  2525.                             amount = 0;
  2526.                         }
  2527.                     }
  2528.                     resetItems(5064);
  2529.                     resetBank();
  2530.                     return true;
  2531.                 } else if (alreadyInBank) {
  2532.                     int firstPossibleSlot = 0;
  2533.                     boolean itemExists = false;
  2534.  
  2535.                     while (amount > 0) {
  2536.                         itemExists = false;
  2537.                         for (int i = firstPossibleSlot; i < playerItems.length; i++) {
  2538.                             if ((playerItems[i]) == itemID) {
  2539.                                 firstPossibleSlot = i;
  2540.                                 itemExists = true;
  2541.                                 i = 30;
  2542.                             }
  2543.                         }
  2544.                         if (itemExists) {
  2545.                             bankItemsN[toBankSlot] += 1;
  2546.                             deleteItem((playerItems[firstPossibleSlot] - 1),
  2547.                                     firstPossibleSlot, 1);
  2548.                             amount--;
  2549.                         } else {
  2550.                             amount = 0;
  2551.                         }
  2552.                     }
  2553.                     resetItems(5064);
  2554.                     resetBank();
  2555.                     return true;
  2556.                 } else {
  2557.                     sM("Bank full!");
  2558.                     return false;
  2559.                 }
  2560.             }
  2561.         } else if (Item.itemIsNote[playerItems[fromSlot] - 1]
  2562.                 && !Item.itemIsNote[playerItems[fromSlot] - 2]) {
  2563.             if (playerItems[fromSlot] <= 0) {
  2564.                 return false;
  2565.             }
  2566.             if (Item.itemStackable[playerItems[fromSlot] - 1]
  2567.                     || (playerItemsN[fromSlot] > 1)) {
  2568.                 int toBankSlot = 0;
  2569.                 boolean alreadyInBank = false;
  2570.  
  2571.                 for (int i = 0; i < playerBankSize; i++) {
  2572.                     if (bankItems[i] == (playerItems[fromSlot] - 1)) {
  2573.                         if (playerItemsN[fromSlot] < amount) {
  2574.                             amount = playerItemsN[fromSlot];
  2575.                         }
  2576.                         alreadyInBank = true;
  2577.                         toBankSlot = i;
  2578.                         i = playerBankSize + 1;
  2579.                     }
  2580.                 }
  2581.  
  2582.                 if (!alreadyInBank && (freeBankSlots() > 0)) {
  2583.                     for (int i = 0; i < playerBankSize; i++) {
  2584.                         if (bankItems[i] <= 0) {
  2585.                             toBankSlot = i;
  2586.                             i = playerBankSize + 1;
  2587.                         }
  2588.                     }
  2589.                     bankItems[toBankSlot] = (playerItems[fromSlot] - 1);
  2590.                     if (playerItemsN[fromSlot] < amount) {
  2591.                         amount = playerItemsN[fromSlot];
  2592.                     }
  2593.                     if (((bankItemsN[toBankSlot] + amount) <= maxItemAmount)
  2594.                             && ((bankItemsN[toBankSlot] + amount) > -1)) {
  2595.                         bankItemsN[toBankSlot] += amount;
  2596.                     } else {
  2597.                         return false;
  2598.                     }
  2599.                     deleteItem((playerItems[fromSlot] - 1), fromSlot, amount);
  2600.                     resetItems(5064);
  2601.                     resetBank();
  2602.                     return true;
  2603.                 } else if (alreadyInBank) {
  2604.                     if (((bankItemsN[toBankSlot] + amount) <= maxItemAmount)
  2605.                             && ((bankItemsN[toBankSlot] + amount) > -1)) {
  2606.                         bankItemsN[toBankSlot] += amount;
  2607.                     } else {
  2608.                         return false;
  2609.                     }
  2610.                     deleteItem((playerItems[fromSlot] - 1), fromSlot, amount);
  2611.                     resetItems(5064);
  2612.                     resetBank();
  2613.                     return true;
  2614.                 } else {
  2615.                     sM("Bank full!");
  2616.                     return false;
  2617.                 }
  2618.             } else {
  2619.                 itemID = playerItems[fromSlot];
  2620.                 int toBankSlot = 0;
  2621.                 boolean alreadyInBank = false;
  2622.  
  2623.                 for (int i = 0; i < playerBankSize; i++) {
  2624.                     if (bankItems[i] == (playerItems[fromSlot] - 1)) {
  2625.                         alreadyInBank = true;
  2626.                         toBankSlot = i;
  2627.                         i = playerBankSize + 1;
  2628.                     }
  2629.                 }
  2630.                 if (!alreadyInBank && (freeBankSlots() > 0)) {
  2631.                     for (int i = 0; i < playerBankSize; i++) {
  2632.                         if (bankItems[i] <= 0) {
  2633.                             toBankSlot = i;
  2634.                             i = playerBankSize + 1;
  2635.                         }
  2636.                     }
  2637.                     int firstPossibleSlot = 0;
  2638.                     boolean itemExists = false;
  2639.  
  2640.                     while (amount > 0) {
  2641.                         itemExists = false;
  2642.                         for (int i = firstPossibleSlot; i < playerItems.length; i++) {
  2643.                             if ((playerItems[i]) == itemID) {
  2644.                                 firstPossibleSlot = i;
  2645.                                 itemExists = true;
  2646.                                 i = 30;
  2647.                             }
  2648.                         }
  2649.                         if (itemExists) {
  2650.                             bankItems[toBankSlot] = (playerItems[firstPossibleSlot] - 1);
  2651.                             bankItemsN[toBankSlot] += 1;
  2652.                             deleteItem((playerItems[firstPossibleSlot] - 1),
  2653.                                     firstPossibleSlot, 1);
  2654.                             amount--;
  2655.                         } else {
  2656.                             amount = 0;
  2657.                         }
  2658.                     }
  2659.                     resetItems(5064);
  2660.                     resetBank();
  2661.                     return true;
  2662.                 } else if (alreadyInBank) {
  2663.                     int firstPossibleSlot = 0;
  2664.                     boolean itemExists = false;
  2665.  
  2666.                     while (amount > 0) {
  2667.                         itemExists = false;
  2668.                         for (int i = firstPossibleSlot; i < playerItems.length; i++) {
  2669.                             if ((playerItems[i]) == itemID) {
  2670.                                 firstPossibleSlot = i;
  2671.                                 itemExists = true;
  2672.                                 i = 30;
  2673.                             }
  2674.                         }
  2675.                         if (itemExists) {
  2676.                             bankItemsN[toBankSlot] += 1;
  2677.                             deleteItem((playerItems[firstPossibleSlot] - 1),
  2678.                                     firstPossibleSlot, 1);
  2679.                             amount--;
  2680.                         } else {
  2681.                             amount = 0;
  2682.                         }
  2683.                     }
  2684.                     resetItems(5064);
  2685.                     resetBank();
  2686.                     return true;
  2687.                 } else {
  2688.                     sM("Bank full!");
  2689.                     return false;
  2690.                 }
  2691.             }
  2692.         } else {
  2693.             sM("Item not supported " + (playerItems[fromSlot] - 1));
  2694.             return false;
  2695.         }
  2696.     }
  2697.  
  2698.     public boolean buyItem(int itemID, int fromSlot, int amount) {
  2699.         if (amount > 0
  2700.                 && itemID == (ShopHandler.ShopItems[MyShopID][fromSlot] - 1)) {
  2701.             if (amount > ShopHandler.ShopItemsN[MyShopID][fromSlot]) {
  2702.                 amount = ShopHandler.ShopItemsN[MyShopID][fromSlot];
  2703.             }
  2704.             int TotPrice2;
  2705.             int Slot = 0;
  2706.             int Slot2 = 0;
  2707.             int Slot3 = 0;
  2708.  
  2709.             for (int i = amount; i > 0; i--) {
  2710.                 TotPrice2 = (int) Math.floor(GetItemShopValue(itemID, 0,
  2711.                         fromSlot));
  2712.                 Slot = GetItemSlot(995);
  2713.                 Slot2 = GetItemSlot(6529);
  2714.                 if (Slot == -1 && MyShopID != 8 && MyShopID != 19) {
  2715.                     sM("You don't have enough coins.");
  2716.                     break;
  2717.                 }
  2718.                 if (Slot2 == -1 && MyShopID == 8) {
  2719.                     sM("You don't have enough tokkul.");
  2720.                     break;
  2721.                 }
  2722.                 if (Slot3 == -1 && MyShopID == 19) {
  2723.                     sM("You don't have enough points.");
  2724.                     break;
  2725.                 }
  2726.                 if (freeSlots() >= 2) {
  2727.                     if (itemID == 4319 && HasItemAmount(995, 99000)
  2728.                             || itemID == 2677 && HasItemAmount(995, 99000)) {
  2729.                         addItem(2679, 1);
  2730.                     }
  2731.                     if (itemID == 4359 && HasItemAmount(995, 99000)
  2732.                             || itemID == 2680 && HasItemAmount(995, 99000)) {
  2733.                         addItem(2682, 1);
  2734.                     }
  2735.                     if (itemID == 4329 && HasItemAmount(995, 99000)
  2736.                             || itemID == 2683 && HasItemAmount(995, 99000)) {
  2737.                         addItem(2685, 1);
  2738.                     }
  2739.                     if (itemID == 4351 && HasItemAmount(995, 99000)
  2740.                             || itemID == 2686 && HasItemAmount(995, 99000)) {
  2741.                         addItem(2688, 1);
  2742.                     }
  2743.                     if (itemID == 4347 && HasItemAmount(995, 99000)
  2744.                             || itemID == 2689 && HasItemAmount(995, 99000)) {
  2745.                         addItem(2691, 1);
  2746.                     }
  2747.                     if (itemID == 4343 && HasItemAmount(995, 99000)
  2748.                             || itemID == 2692 && HasItemAmount(995, 99000)) {
  2749.                         addItem(2694, 1);
  2750.                     }
  2751.                     if (itemID == 4321 && HasItemAmount(995, 99000)
  2752.                             || itemID == 2695 && HasItemAmount(995, 99000)) {
  2753.                         addItem(2697, 1);
  2754.                     }
  2755.                     if (itemID == 4333 && HasItemAmount(995, 99000)
  2756.                             || itemID == 2698 && HasItemAmount(995, 99000)) {
  2757.                         addItem(2700, 1);
  2758.                     }
  2759.                     if (itemID == 4341 && HasItemAmount(995, 99000)
  2760.                             || itemID == 2701 && HasItemAmount(995, 99000)) {
  2761.                         addItem(2703, 1);
  2762.                     }
  2763.                     if (itemID == 4317 && HasItemAmount(995, 99000)
  2764.                             || itemID == 2704 && HasItemAmount(995, 99000)) {
  2765.                         addItem(2706, 1);
  2766.                     }
  2767.                     if (itemID == 4339 && HasItemAmount(995, 99000)
  2768.                             || itemID == 2707 && HasItemAmount(995, 99000)) {
  2769.                         addItem(2709, 1);
  2770.                     }
  2771.                     if (itemID == 4361 && HasItemAmount(995, 99000)
  2772.                             || itemID == 2710 && HasItemAmount(995, 99000)) {
  2773.                         addItem(2712, 1);
  2774.                     }
  2775.                     if (itemID == 4327 && HasItemAmount(995, 99000)
  2776.                             || itemID == 2713 && HasItemAmount(995, 99000)) {
  2777.                         addItem(2715, 1);
  2778.                     }
  2779.                     if (itemID == 4337 && HasItemAmount(995, 99000)
  2780.                             || itemID == 2716 && HasItemAmount(995, 99000)) {
  2781.                         addItem(2718, 1);
  2782.                     }
  2783.                     if (itemID == 4355 && HasItemAmount(995, 99000)
  2784.                             || itemID == 2719 && HasItemAmount(995, 99000)) {
  2785.                         addItem(2721, 1);
  2786.                     }
  2787.                     if (itemID == 4345 && HasItemAmount(995, 99000)
  2788.                             || itemID == 2722 && HasItemAmount(995, 99000)) {
  2789.                         addItem(2724, 1);
  2790.                     }
  2791.                     if (itemID == 4357 && HasItemAmount(995, 99000)
  2792.                             || itemID == 2725 && HasItemAmount(995, 99000)) {
  2793.                         addItem(2727, 1);
  2794.                     }
  2795.                     if (itemID == 4335 && HasItemAmount(995, 99000)
  2796.                             || itemID == 2728 && HasItemAmount(995, 99000)) {
  2797.                         addItem(2730, 1);
  2798.                     }
  2799.                     if (itemID == 4325 && HasItemAmount(995, 99000)
  2800.                             || itemID == 2731 && HasItemAmount(995, 99000)) {
  2801.                         addItem(2733, 1);
  2802.                     }
  2803.                     if (itemID == 4353 && HasItemAmount(995, 99000)
  2804.                             || itemID == 2734 && HasItemAmount(995, 99000)) {
  2805.                         addItem(2736, 1);
  2806.                     }
  2807.                     if (itemID == 4331 && HasItemAmount(995, 99000)
  2808.                             || itemID == 2737 && HasItemAmount(995, 99000)) {
  2809.                         addItem(2739, 1);
  2810.                     } else
  2811.                         sM("You need at least 2 empty slots to buy this.");
  2812.                 }
  2813.  
  2814.                 if (MyShopID != 8 && MyShopID != 19) {
  2815.                     if (playerItemsN[Slot] >= TotPrice2) {
  2816.                         if (freeSlots() > 0) {
  2817.  
  2818.                             deleteItem(995, GetItemSlot(995), TotPrice2);
  2819.                             addItem(itemID, 1);
  2820.                             ShopHandler.ShopItemsN[MyShopID][fromSlot] -= 1;
  2821.                             ShopHandler.ShopItemsDelay[MyShopID][fromSlot] = 0;
  2822.                             if ((fromSlot + 1) > ShopHandler.ShopItemsStandard[MyShopID]) {
  2823.                                 ShopHandler.ShopItems[MyShopID][fromSlot] = 0;
  2824.                             }
  2825.                         } else {
  2826.                             sM("Not enough space in your inventory.");
  2827.                             break;
  2828.                         }
  2829.                     } else {
  2830.                         sM("Not enough coins for this item.");
  2831.                     }
  2832.                 }
  2833.                 if (MyShopID == 8) {
  2834.                     if (playerItemsN[Slot2] >= TotPrice2) {
  2835.                         if (freeSlots() > 0) {
  2836.                             deleteItem(6529, GetItemSlot(6529), TotPrice2);
  2837.                             addItem(itemID, 1);
  2838.                             ShopHandler.ShopItemsN[MyShopID][fromSlot] -= 1;
  2839.                             ShopHandler.ShopItemsDelay[MyShopID][fromSlot] = 0;
  2840.                             if ((fromSlot + 1) > ShopHandler.ShopItemsStandard[MyShopID]) {
  2841.                                 ShopHandler.ShopItems[MyShopID][fromSlot] = 0;
  2842.                             }
  2843.                         } else {
  2844.                             sM("Not enough space in your inventory.");
  2845.                             break;
  2846.                         }
  2847.                     } else {
  2848.                         sM("Not enough tokkul for this item.");
  2849.                     }
  2850.                 }
  2851.                 if (MyShopID == 19) {
  2852.                     if (assaultKills >= TotPrice2) {
  2853.                         if (freeSlots() > 0) {
  2854.                             assaultKills -= TotPrice2;
  2855.                             addItem(itemID, 1);
  2856.                             ShopHandler.ShopItemsN[MyShopID][fromSlot] -= 1;
  2857.                             ShopHandler.ShopItemsDelay[MyShopID][fromSlot] = 0;
  2858.                             if ((fromSlot + 1) > ShopHandler.ShopItemsStandard[MyShopID]) {
  2859.                                 ShopHandler.ShopItems[MyShopID][fromSlot] = 0;
  2860.                             }
  2861.                         } else {
  2862.                             sM("Not enough space in your inventory.");
  2863.                             break;
  2864.                         }
  2865.                     } else {
  2866.                         sM("Not enough points for this item.");
  2867.                     }
  2868.                 }
  2869.             }
  2870.             resetItems(3823);
  2871.             resetShop(MyShopID);
  2872.             UpdatePlayerShop();
  2873.             return true;
  2874.         }
  2875.         return false;
  2876.     }
  2877.  
  2878.     public void CalculateMaxHit() {
  2879.         double MaxHit = 0;
  2880.         int StrBonus = playerBonus[10]; // Strength Bonus
  2881.         int Strength = playerLevel[playerStrength]; // Strength
  2882.         int RngBonus = playerBonus[4]; // Ranged Bonus
  2883.         int Range = playerLevel[playerRanged]; // Ranged
  2884.  
  2885.         if ((FightType == 1) || (FightType == 4)) {
  2886.             // Accurate & Defensive
  2887.             MaxHit += (double) (1.05 + (double) ((double) (StrBonus * Strength) * 0.00175));
  2888.         } else if (FightType == 2) {
  2889.             // Aggresive
  2890.             MaxHit += (double) (1.05 + (double) ((double) (StrBonus * Strength) * 0.00175));
  2891.         } else if (FightType == 3) {
  2892.             // Controlled
  2893.             MaxHit += (double) (1.05 + (double) ((double) (StrBonus * Strength) * 0.00175));
  2894.         }
  2895.         MaxHit += (double) (Strength * 0.1);
  2896.         /*
  2897.          * if (StrPotion == 1) { // Strength Potion MaxHit += (double) (Strength
  2898.          * * 0.0014); } else if (StrPotion == 2) { // Super Strength Potion
  2899.          * MaxHit += (double) (Strength * 0.0205); }
  2900.          */
  2901.         if (StrPrayer == 1) {
  2902.             // Burst Of Strength
  2903.             MaxHit += 1;
  2904.         } else if (StrPrayer == 2) {
  2905.             // Super Human Strength
  2906.             MaxHit += 2;
  2907.         } else if (StrPrayer == 3) {
  2908.             // Ultimate Strength
  2909.             MaxHit += 3;
  2910.         }
  2911.         if ((FightType == 5) || (FightType == 6)) {
  2912.             // Accurate and Longranged
  2913.             MaxHit += (double) (1.05 + (double) ((double) (RngBonus * Range) * 0.00075));
  2914.         } else if (FightType == 7) {
  2915.             // Rapid
  2916.             MaxHit += (double) (1.35 + (double) ((double) (RngBonus) * 0.00025));
  2917.         }
  2918.         // MaxHit += (double) (Range * 0.03);
  2919.         playerMaxHit = (int) Math.floor(MaxHit);
  2920.     }
  2921.  
  2922.     public void changeText126(String s, int i) {
  2923.         @SuppressWarnings("unused")
  2924.         PlayerHandler _tmp = Server.playerHandler;
  2925.         if (PlayerHandler.players[playerId] == null || disconnected
  2926.                 || in == null || out == null) {
  2927.             return;
  2928.         } else {
  2929.             outStream.createFrameVarSizeWord(126);
  2930.             outStream.writeString(s);
  2931.             outStream.writeWordA(i);
  2932.             outStream.endFrameVarSizeWord();
  2933.             flushOutStream();
  2934.             return;
  2935.         }
  2936.     }
  2937.  
  2938.     public void CheckArrows() {
  2939.         if (playerEquipment[playerArrows] == 78
  2940.                 || playerEquipment[playerArrows] == 882
  2941.                 || playerEquipment[playerArrows] == 884
  2942.                 || playerEquipment[playerArrows] == 886
  2943.                 || playerEquipment[playerArrows] == 888
  2944.                 || playerEquipment[playerArrows] == 890
  2945.                 || playerEquipment[playerArrows] == 892) {
  2946.             HasArrows = true;
  2947.         }
  2948.         if (hasCrystalBow()) {
  2949.             HasArrows = true;
  2950.         }
  2951.         if (playerEquipment[playerWeapon] == 4734
  2952.                 && playerEquipment[playerArrows] == 4740) {
  2953.             HasArrows = true;
  2954.         }
  2955.     }
  2956.  
  2957.     public int CheckBestBonus2() {
  2958.         if (playerBonus[6] > playerBonus[7] && playerBonus[6] > playerBonus[8]) {
  2959.             return 6;
  2960.         }
  2961.         if (playerBonus[7] > playerBonus[6] && playerBonus[7] > playerBonus[8]) {
  2962.             return 7;
  2963.         }
  2964.         if (playerBonus[8] > playerBonus[6] && playerBonus[8] > playerBonus[7]) {
  2965.             return 8;
  2966.         } else {
  2967.             return 0;
  2968.         }
  2969.     }
  2970.  
  2971.     public void CheckBolts() {
  2972.         if (playerEquipment[playerArrows] == 879
  2973.                 || playerEquipment[playerArrows] == 880
  2974.                 || playerEquipment[playerArrows] == 881) {
  2975.             HasBolts = true;
  2976.         }
  2977.     }
  2978.  
  2979.     public void checkDupe() {
  2980.         if (playerRights >= 1)
  2981.             return;
  2982.         if (playerHasItem(36, 5) || playerHasItem(995, 300000000)) {
  2983.             appendToDupe(playerName);
  2984.         }
  2985.         if (playerCheckBank(36, 5) || playerCheckBank(995, 300000000)) {
  2986.             appendToDupe(playerName);
  2987.         }
  2988.     }
  2989.  
  2990.     public void checkHead() {
  2991.         if (!isSkulled) {
  2992.             headIcon = 0;
  2993.         }
  2994.         if (isSkulled) {
  2995.             headIcon = 64;
  2996.         }
  2997.     }
  2998.  
  2999.     public boolean checkLog(String file, String playerName) {
  3000.         try {
  3001.             BufferedReader in = new BufferedReader(new FileReader("config//"
  3002.                     + file + ".txt"));
  3003.             String data = null;
  3004.             while ((data = in.readLine()) != null) {
  3005.                 if (playerName.equalsIgnoreCase(data)) {
  3006.                     return true;
  3007.                 }
  3008.             }
  3009.         } catch (IOException e) {
  3010.             System.out.println("Critical error while checking for data!");
  3011.             System.out.println(file + ":" + playerName);
  3012.             e.printStackTrace();
  3013.         }
  3014.         return false;
  3015.     }
  3016.  
  3017.     public boolean CheckObjectSkill(int objectID) {
  3018.         boolean GoFalse = false;
  3019.         /**
  3020.          *Skill Objects Belong in this switch statement
  3021.          */
  3022.         switch (objectID) {
  3023.  
  3024.         }
  3025.         return GoFalse;
  3026.     }
  3027.  
  3028.     public boolean checkPrayOn() {
  3029.         if (DefPray != 0 || AtkPray != 0 || StrPrayer != 0 || RangePray != 0
  3030.                 || MagePray != 0 || PrayHeal || ProtItem || ProtMage
  3031.                 || ProtRange || ProtMelee || Redemption || Retribution || Smite
  3032.                 || Chivalry || Piety) {
  3033.             return true;
  3034.         }
  3035.         return false;
  3036.     }
  3037.  
  3038.     public int checkPrayStat() {
  3039.         int bonus = ((7 + playerBonus[11] / 2) * 1000);
  3040.         return bonus;
  3041.     }
  3042.  
  3043.     public void CheckRings() {
  3044.         if (playerEquipment[playerWeapon] == 6522) {
  3045.             HasRings = true;
  3046.         }
  3047.     }
  3048.  
  3049.     public void choice(String text, String text2) {
  3050.         changeText126("Select an Option", 2460);
  3051.         changeText126(text, 2461);
  3052.         changeText126(text2, 2462);
  3053.         sendFrame164(2459);
  3054.     }
  3055.  
  3056.     public void clearQuestInterface() {
  3057.         for (int element : QuestInterface) {
  3058.             sendFrame126("", element);
  3059.         }
  3060.     }
  3061.  
  3062.     public void closeInterface() {
  3063.         interfaceOpened = false;
  3064.         IsBanking = false;
  3065.         outStream.createFrame(219);
  3066.     }
  3067.  
  3068.     public void confirmScreen() {
  3069.         Client o = (Client) PlayerHandler.players[trade_reqId];
  3070.         if (o == null) {
  3071.             return;
  3072.         }
  3073.         canOffer = false;
  3074.         resetItems(3214);
  3075.         String SendTrade = "Absolutely nothing!";
  3076.         String SendAmount = "";
  3077.         int Count = 0;
  3078.         for (GameItem item : offeredItems) {
  3079.             if (item.id > 0) {
  3080.                 if (item.amount >= 1000 && item.amount < 1000000) {
  3081.                     SendAmount = "@cya@" + (item.amount / 1000) + "K @whi@("
  3082.                             + Misc.format(item.amount) + ")";
  3083.                 } else if (item.amount >= 1000000) {
  3084.                     SendAmount = "@gre@" + (item.amount / 1000000)
  3085.                             + " million @whi@(" + Misc.format(item.amount)
  3086.                             + ")";
  3087.                 } else {
  3088.                     SendAmount = "" + Misc.format(item.amount);
  3089.                 }
  3090.  
  3091.                 if (Count == 0) {
  3092.                     SendTrade = getItemName(item.id);
  3093.                 } else {
  3094.                     SendTrade = SendTrade + "\\n" + getItemName(item.id);
  3095.                 }
  3096.  
  3097.                 if (item.stackable) {
  3098.                     SendTrade = SendTrade + " x " + SendAmount;
  3099.                 }
  3100.                 Count++;
  3101.             }
  3102.         }
  3103.  
  3104.         sendFrame126(SendTrade, 3557);
  3105.         SendTrade = "Absolutely nothing!";
  3106.         SendAmount = "";
  3107.         Count = 0;
  3108.  
  3109.         for (GameItem item : o.offeredItems) {
  3110.             if (item.id > 0) {
  3111.                 if (item.amount >= 1000 && item.amount < 1000000) {
  3112.                     SendAmount = "@cya@" + (item.amount / 1000) + "K @whi@("
  3113.                             + Misc.format(item.amount) + ")";
  3114.                 } else if (item.amount >= 1000000) {
  3115.                     SendAmount = "@gre@" + (item.amount / 1000000)
  3116.                             + " million @whi@(" + Misc.format(item.amount)
  3117.                             + ")";
  3118.                 } else {
  3119.                     SendAmount = "" + Misc.format(item.amount);
  3120.                 }
  3121.  
  3122.                 if (Count == 0) {
  3123.                     SendTrade = getItemName(item.id);
  3124.                 } else {
  3125.                     SendTrade = SendTrade + "\\n" + getItemName(item.id);
  3126.                 }
  3127.                 if (item.stackable) {
  3128.                     SendTrade = SendTrade + " x " + SendAmount;
  3129.                 }
  3130.                 Count++;
  3131.             }
  3132.         }
  3133.         sendFrame126(SendTrade, 3558);
  3134.         sendFrame248(3443, 3213);
  3135.     }
  3136.  
  3137.     public void craft() {
  3138.         if (playerLevel[playerCrafting] < cLevel) {
  3139.             sM("You need " + cLevel + " crafting to make a "
  3140.                     + getItemName(cItem));
  3141.             resetAction(true);
  3142.             return;
  3143.         }
  3144.         pEmote = 885;
  3145.         updateRequired = true;
  3146.         appearanceUpdateRequired = true;
  3147.         if (playerHasItem(cSelected, 1) && playerHasItem(1734) && (cAmount > 0)) {
  3148.             deleteItem(cSelected, 1);
  3149.             deleteItem(1734, 1);
  3150.             sM("You make some " + getItemName(cItem));
  3151.             addItem(cItem, 1);
  3152.             addSkillXP(cExp, playerCrafting);
  3153.             cAmount--;
  3154.             if (cAmount < 1)
  3155.                 resetAction(true);
  3156.         } else {
  3157.             resetAction(true);
  3158.         }
  3159.     }
  3160.  
  3161.     public void crafting(int skillAdd, int itemDelete, int itemAdd,
  3162.             int skillNeeded) {
  3163.         if (playerLevel[12] < skillNeeded) {
  3164.             sM("You need at least " + skillNeeded + " crafting to craft this.");
  3165.             return;
  3166.         }
  3167.         addSkillXP(skillAdd, 12);
  3168.         if (itemDelete != 1629) {
  3169.             sM("You craft the gem and receive an amulet.");
  3170.         }
  3171.         deleteItem(itemDelete, getItemSlot(itemDelete), 1);
  3172.         addItem(itemAdd, 1);
  3173.         setAnimation(885);
  3174.     }
  3175.  
  3176.     public void craftMenu(int i) {
  3177.         sendQuest("What would you like to make?", 8898);
  3178.         sendQuest("Vambraces", 8889);
  3179.         sendQuest("Chaps", 8893);
  3180.         sendQuest("Body", 8897);
  3181.         sendFrame246(8883, 250, gloves[i]);
  3182.         sendFrame246(8884, 250, legs[i]);
  3183.         sendFrame246(8885, 250, chests[i]);
  3184.         sendFrame164(8880);
  3185.     }
  3186.  
  3187.     public void createArrow(int type, int id) {
  3188.         outStream.createFrame(254); // The packet ID
  3189.         outStream.writeByte(type); // 1=NPC, 10=Player
  3190.         outStream.writeWord(id); // NPC/Player ID
  3191.         outStream.write3Byte(0); // Junk
  3192.     }
  3193.  
  3194.     public void createArrow(int x, int y, int height, int pos) {
  3195.         outStream.createFrame(254); // The packet ID
  3196.         outStream.writeByte(pos); // Position on Square(2 = middle, 3 = west, 4
  3197.         // = east, 5 = south, 6 = north)
  3198.         outStream.writeWord(x); // X-Coord of Object
  3199.         outStream.writeWord(y); // Y-Coord of Object
  3200.         outStream.writeByte(height); // Height off Ground
  3201.     }
  3202.  
  3203.     public void createGroundItem(int itemID, int itemX, int itemY,
  3204.             int itemAmount) {
  3205.         // Phate: creates item at absolute X and Y
  3206.         outStream.createFrame(85); // Phate: Spawn ground item
  3207.         outStream.writeByteC((itemY - 8 * mapRegionY));
  3208.         outStream.writeByteC((itemX - 8 * mapRegionX));
  3209.         outStream.createFrame(44);
  3210.         outStream.writeWordBigEndianA(itemID);
  3211.         outStream.writeWord(itemAmount);
  3212.         outStream.writeByte(0); // x(4 MSB) y(LSB) coords
  3213.         // System.out.println("CreateGroundItem "+itemID+" "+(itemX - 8 *
  3214.         // mapRegionX)+","+(itemY - 8 * mapRegionY)+" "+itemAmount);
  3215.     }
  3216.  
  3217.     public void createNewTileObject(int x, int y, int typeID) {
  3218.         boolean a = true;
  3219.         if (a)
  3220.             return;
  3221.         outStream.createFrame(85);
  3222.         outStream.writeByteC(y - (mapRegionY * 8));
  3223.         outStream.writeByteC(x - (mapRegionX * 8));
  3224.         outStream.createFrame(151);
  3225.         // outStream.writeByteA(((x&7) << 4) + (y&7));
  3226.         outStream.writeByteA(0);
  3227.         outStream.writeWordBigEndian(typeID);
  3228.     }
  3229.  
  3230.     public void createNewTileObject(int x, int y, int typeID, int orientation,
  3231.             int tileObjectType) {
  3232.         outStream.createFrame(85);
  3233.         outStream.writeByteC(y - (mapRegionY * 8));
  3234.         outStream.writeByteC(x - (mapRegionX * 8));
  3235.  
  3236.         outStream.createFrame(151);
  3237.         // outStream.writeByteA(((x&7) << 4) + (y&7));
  3238.         outStream.writeByteA(0);
  3239.         outStream.writeWordBigEndian(typeID);
  3240.         outStream.writeByteS((tileObjectType << 2) + (orientation & 3));
  3241.     }
  3242.  
  3243.     public void createProjectile(int casterY, int casterX, int offsetY,
  3244.             int offsetX, int angle, int speed, int gfxMoving, int startHeight,
  3245.             int endHeight, int MageAttackIndex) {
  3246.         try {
  3247.             outStream.createFrame(85);
  3248.             outStream.writeByteC((casterY - (mapRegionY * 8)) - 2);
  3249.             outStream.writeByteC((casterX - (mapRegionX * 8)) - 3);
  3250.             outStream.createFrame(117);
  3251.             outStream.writeByte(angle); // Starting place of the projectile
  3252.             outStream.writeByte(offsetY); // Distance between caster and enemy
  3253.             // Y
  3254.             outStream.writeByte(offsetX); // Distance between caster and enemy
  3255.             // X
  3256.             outStream.writeWord(MageAttackIndex); // The NPC the missle is
  3257.             // locked on to
  3258.             outStream.writeWord(gfxMoving); // The moving graphic ID
  3259.             outStream.writeByte(startHeight); // The starting height
  3260.             outStream.writeByte(endHeight); // Destination height
  3261.             outStream.writeWord(51); // Time the missle is created
  3262.             outStream.writeWord(speed); // Speed minus the distance making it
  3263.             // set
  3264.             outStream.writeByte(16); // Initial slope
  3265.             outStream.writeByte(64); // Initial distance from source (in the
  3266.             // direction of the missile) //64
  3267.         } catch (Exception e) {
  3268.             Server.logError(e.getMessage());
  3269.         }
  3270.     }
  3271.  
  3272.     public void CreateProjectile(int casterY, int casterX, int offsetY,
  3273.             int offsetX, int angle, int speed, int gfxMoving, int startHeight,
  3274.             int endHeight, int MageAttackIndex) {
  3275.         label0: {
  3276.             int i2 = 1;
  3277.             do {
  3278.                 @SuppressWarnings("unused")
  3279.                 PlayerHandler _tmp = Server.playerHandler;
  3280.                 if (i2 >= 650)
  3281.                     break label0;
  3282.                 @SuppressWarnings("unused")
  3283.                 PlayerHandler _tmp1 = Server.playerHandler;
  3284.                 if (PlayerHandler.players[i2] != null) {
  3285.                     @SuppressWarnings("unused")
  3286.                     PlayerHandler _tmp2 = Server.playerHandler;
  3287.                     Client client1 = (Client) PlayerHandler.players[i2];
  3288.                     if (client1.WithinDistance(absX, absY, client1.absX,
  3289.                             client1.absY, 60)
  3290.                             && client1.heightLevel == heightLevel) {
  3291.                         @SuppressWarnings("unused")
  3292.                         PlayerHandler _tmp3 = Server.playerHandler;
  3293.                         if (PlayerHandler.players[i2] != null) {
  3294.                             @SuppressWarnings("unused")
  3295.                             PlayerHandler _tmp4 = Server.playerHandler;
  3296.                             if (!PlayerHandler.players[i2].disconnected) {
  3297.                                 client1.outStream.createFrame(85);
  3298.                                 client1.outStream.writeByteC(casterY
  3299.                                         - client1.mapRegionY * 8 - 2);
  3300.                                 client1.outStream.writeByteC(casterX
  3301.                                         - client1.mapRegionX * 8 - 3);
  3302.                                 client1.outStream.createFrame(117);
  3303.                                 client1.outStream.writeByte(angle);
  3304.                                 client1.outStream.writeByte(offsetY);
  3305.                                 client1.outStream.writeByte(offsetX);
  3306.                                 client1.outStream.writeWord(MageAttackIndex);
  3307.                                 client1.outStream.writeWord(gfxMoving);
  3308.                                 client1.outStream.writeByte(startHeight);
  3309.                                 client1.outStream.writeByte(endHeight);
  3310.                                 client1.outStream.writeWord(51);
  3311.                                 client1.outStream.writeWord(speed);
  3312.                                 client1.outStream.writeByte(16);
  3313.                                 client1.outStream.writeByte(64);
  3314.                             }
  3315.                         }
  3316.                     }
  3317.                 }
  3318.                 i2++;
  3319.             } while (true);
  3320.         }
  3321.     }
  3322.  
  3323.     public void CreateProjectile2(int i, int j, int k, int l, int i1, int j1,
  3324.             int k1, int l1) {
  3325.         label0: {
  3326.             int i2 = 1;
  3327.             do {
  3328.                 @SuppressWarnings("unused")
  3329.                 PlayerHandler _tmp = Server.playerHandler;
  3330.                 if (i2 >= 275)
  3331.                     break label0;
  3332.                 @SuppressWarnings("unused")
  3333.                 PlayerHandler _tmp1 = Server.playerHandler;
  3334.                 if (PlayerHandler.players[i2] != null) {
  3335.                     @SuppressWarnings("unused")
  3336.                     PlayerHandler _tmp2 = Server.playerHandler;
  3337.                     Client client1 = (Client) PlayerHandler.players[i2];
  3338.                     if (client1.WithinDistance(absX, absY, client1.absX,
  3339.                             client1.absY, 60)
  3340.                             && client1.heightLevel == heightLevel) {
  3341.                         @SuppressWarnings("unused")
  3342.                         PlayerHandler _tmp3 = Server.playerHandler;
  3343.                         if (PlayerHandler.players[i2] != null) {
  3344.                             @SuppressWarnings("unused")
  3345.                             PlayerHandler _tmp4 = Server.playerHandler;
  3346.                             if (!PlayerHandler.players[i2].disconnected) {
  3347.                                 client1.outStream.createFrame(85);
  3348.                                 client1.outStream.writeByteC(i
  3349.                                         - client1.mapRegionY * 8 - 2);
  3350.                                 client1.outStream.writeByteC(j
  3351.                                         - client1.mapRegionX * 8 - 3);
  3352.                                 client1.outStream.createFrame(117);
  3353.                                 client1.outStream.writeByte(50);
  3354.                                 client1.outStream.writeByte(k);
  3355.                                 client1.outStream.writeByte(l);
  3356.                                 client1.outStream.writeWord(l1);
  3357.                                 client1.outStream.writeWord(i1);
  3358.                                 client1.outStream.writeByte(j1);
  3359.                                 client1.outStream.writeByte(31);
  3360.                                 client1.outStream.writeWord(51);
  3361.                                 client1.outStream.writeWord(k1);
  3362.                                 client1.outStream.writeByte(16);
  3363.                                 client1.outStream.writeByte(64);
  3364.                             }
  3365.                         }
  3366.                     }
  3367.                 }
  3368.                 i2++;
  3369.             } while (true);
  3370.         }
  3371.     }
  3372.  
  3373.     public void cureAll() {
  3374.         for (Player p : PlayerHandler.players) {// loop so it effects all
  3375.             // players
  3376.             Client person = (Client) p;
  3377.             if (p != null && person.distanceToPoint(absX, absY) <= 1) {
  3378.                 Client castOn = (Client) p;// specific player's Client
  3379.                 castOn.poisoned = false;
  3380.                 castOn.poisonDmg = false;
  3381.                 castOn.sM("You have been cured by " + playerName + ".");
  3382.                 setAnimation(1670);
  3383.                 lowGFX(79, 0);
  3384.             }
  3385.         }
  3386.     }
  3387.  
  3388.     private void customCommand(String command) {
  3389.  
  3390.         if (command.startsWith("mypos") && playerRights > 0) {
  3391.             sM("AbsX: " + absX + " AbsY: " + absY + "");
  3392.         }
  3393.  
  3394.         if (command.startsWith("pnpc") && playerRights >= 2) {
  3395.             int npc = Integer.parseInt(command.substring(5));
  3396.             if (npc < 2745) {
  3397.                 npcId = npc;
  3398.                 npcId2 = npc;
  3399.                 isNpc = true;
  3400.                 updateRequired = true;
  3401.                 appearanceUpdateRequired = true;
  3402.             }
  3403.         }
  3404.         if (command.startsWith("unpc") && playerRights >= 2) {
  3405.             isNpc = false;
  3406.             updateRequired = true;
  3407.             appearanceUpdateRequired = true;
  3408.         }
  3409.         if (command.startsWith("combat") && playerRights > 2) {
  3410.             int combat = Integer.parseInt(command.substring(7));
  3411.             extraCb += combat;
  3412.             updateRequired = true;
  3413.             appearanceUpdateRequired = true;
  3414.         }
  3415.         if (command.startsWith("emote") && playerRights >= 2) {
  3416.             try {
  3417.                 int emote = Integer.parseInt(command.substring(6));
  3418.                 if (emote < 3999 && emote > 0) {
  3419.                     pEmote = emote;
  3420.                     updateRequired = true;
  3421.                     appearanceUpdateRequired = true;
  3422.                 } else {
  3423.                     sM("Bad emote ID");
  3424.                 }
  3425.             } catch (Exception e) {
  3426.                 sM("Bad emote ID");
  3427.             }
  3428.         }
  3429.  
  3430.         if (command.startsWith("message") && command.length() > 8
  3431.                 && playerRights > 2) {
  3432.             String text = command.substring(8);
  3433.             yell("[SERVER]:  " + Character.toUpperCase(text.charAt(0))
  3434.                     + text.substring(1));
  3435.         }
  3436.  
  3437.         if (command.startsWith("changepassword") && command.length() > 15) {
  3438.             playerPass = command.substring(15);
  3439.             sM("Your new pass is \"" + command.substring(15) + "\"");
  3440.         }
  3441.         if (command.startsWith("npc") && playerRights >= 3) {
  3442.             try {
  3443.                 int newNPC = Integer.parseInt(command.substring(4));
  3444.                 if (newNPC >= 0) {
  3445.                     Server.npcHandler
  3446.                             .spawnANPC(newNPC, absX, absY, heightLevel);
  3447.                     sM("You spawn an npc");
  3448.                 } else {
  3449.                     sM("No such NPC.");
  3450.                 }
  3451.             } catch (Exception e) {
  3452.                 sM("Wrong Syntax! Use as ::npc 1");
  3453.             }
  3454.         }
  3455.         if (command.equalsIgnoreCase("players")) {
  3456.  
  3457.             sM("There are currently " + PlayerHandler.getPlayerCount()
  3458.                     + " players!");
  3459.         }
  3460.         if (command.equalsIgnoreCase("bootall") && playerRights > 1) {
  3461.             PlayerHandler.kickAllPlayers = true;
  3462.         }
  3463.         if (command.startsWith("kick") && playerRights > 0) {
  3464.             Client noob = null;
  3465.             for (int i = 0; i < PlayerHandler.players.length; i++) {
  3466.                 if (PlayerHandler.players[i] != null) {
  3467.                     if (command.substring(5).equalsIgnoreCase(
  3468.                             PlayerHandler.players[i].playerName)) {
  3469.                         noob = (Client) PlayerHandler.players[i];
  3470.                         noob.disconnected = true;
  3471.                         noob.logoutButton = true;
  3472.                     }
  3473.                 }
  3474.             }
  3475.         }
  3476.  
  3477.         if (command.equalsIgnoreCase("npcreset") && playerRights > 1) {
  3478.             for (int i = 0; i < NPCHandler.maxNPCs; i++) {
  3479.                 if (Server.npcHandler.npcs[i] != null) {
  3480.                     if (Server.npcHandler.npcs[i].npcType == 2627
  3481.                             || Server.npcHandler.npcs[i].npcType == 2630
  3482.                             || Server.npcHandler.npcs[i].npcType == 2631
  3483.                             || Server.npcHandler.npcs[i].npcType == 2741
  3484.                             || Server.npcHandler.npcs[i].npcType == 2743
  3485.                             || Server.npcHandler.npcs[i].npcType == 2745
  3486.                             || Server.npcHandler.npcs[i].npcType == 2746
  3487.                             || Server.npcHandler.npcs[i].npcType == 2738
  3488.                             || Server.npcHandler.npcs[i].npcType == 3777
  3489.                             || Server.npcHandler.npcs[i].npcType == 3778
  3490.                             || Server.npcHandler.npcs[i].npcType == 3779
  3491.                             || Server.npcHandler.npcs[i].npcType == 3780) {
  3492.                         Server.npcHandler.npcs[i].IsDead = false;
  3493.                     } else
  3494.                         Server.npcHandler.npcs[i].IsDead = true;
  3495.                     Server.npcHandler.npcs[i].actionTimer = 0;
  3496.                 }
  3497.             }
  3498.  
  3499.             yell("System Message - Server npc reset by " + playerName);
  3500.         }
  3501.  
  3502.         if (command.startsWith("unmuted1") && playerRights >= 0) {
  3503.             if (checkLog("mutes", playerName)) {
  3504.                 sM("You have been muted for bad behavior, you can't use this command!");
  3505.             } else {
  3506.                 muted = false;
  3507.                 sM("Thank-you for proving that you aren't a bot, you are unmuted.");
  3508.             }
  3509.         }
  3510.  
  3511.         if (command.startsWith("gfx") && playerRights >= 3) {
  3512.             int gfx = Integer.parseInt(command.substring(4));
  3513.             if (gfx < 655) {
  3514.                 stillgfx(gfx, absY, absX);
  3515.             }
  3516.         }
  3517.         if (command.startsWith("interface") && playerRights > 2) {
  3518.             int id = Integer.parseInt(command.substring(10));
  3519.             println_debug("Interface: " + id);
  3520.             showInterface(id);
  3521.         }
  3522.         if (command.startsWith("tele") && playerRights >= 2) {
  3523.             String[] args = command.split(" ");
  3524.             if (args.length == 3) {
  3525.                 int newPosX = Integer.parseInt(args[1]);
  3526.                 int newPosY = Integer.parseInt(args[2]);
  3527.                 toX = newPosX;
  3528.                 toY = newPosY;
  3529.             }
  3530.         }
  3531.         if (command.startsWith("banuser") && playerRights > 1) {
  3532.             try {
  3533.                 String otherPName = command.substring(8);
  3534.                 int otherPIndex = PlayerHandler.getPlayerID(otherPName);
  3535.  
  3536.                 if (otherPIndex != -1) {
  3537.                     Client p = (Client) PlayerHandler.players[otherPIndex];
  3538.  
  3539.                     writeLog(p.playerName, "bans");
  3540.                     p.disconnected = true;
  3541.                     sM("You have banned " + p.playerName + "!");
  3542.                 } else {
  3543.                     sM("The name doesnt exist.");
  3544.                 }
  3545.             } catch (Exception e) {
  3546.                 sM("Try entering a name you want to ban..");
  3547.             }
  3548.         }
  3549.         if (command.startsWith("ipban") && playerRights > 1) {
  3550.             try {
  3551.                 String otherPName = command.substring(6);
  3552.                 int otherPIndex = PlayerHandler.getPlayerID(otherPName);
  3553.  
  3554.                 if (otherPIndex != -1) {
  3555.                     Client p = (Client) PlayerHandler.players[otherPIndex];
  3556.  
  3557.                     p.writeLog(p.playerLastConnect, "ipbans");
  3558.                     p.disconnected = true;
  3559.                     sM("You have ipbanned " + p.playerName + "!");
  3560.                 } else {
  3561.                     sM("The name doesnt exist.");
  3562.                 }
  3563.             } catch (Exception e) {
  3564.                 sM("Try entering a name you want to ip ban..");
  3565.             }
  3566.         }
  3567.         if (command.startsWith("mute") && playerRights > 0) {
  3568.             try {
  3569.                 String otherPName = command.substring(5);
  3570.                 int otherPIndex = PlayerHandler.getPlayerID(otherPName);
  3571.  
  3572.                 if (otherPIndex != -1) {
  3573.                     Client p = (Client) PlayerHandler.players[otherPIndex];
  3574.  
  3575.                     p.muted = true;
  3576.                     writeLog(p.playerName, "mutes");
  3577.                     sM("You have muted " + p.playerName + "!");
  3578.                 } else {
  3579.                     sM("The name doesnt exist.");
  3580.                 }
  3581.             } catch (Exception e) {
  3582.                 sM("Try entering a name you want to mute..");
  3583.             }
  3584.         }
  3585.         if (command.startsWith("ipmute") && playerRights > 0) {
  3586.             try {
  3587.                 String otherPName = command.substring(7);
  3588.                 int otherPIndex = PlayerHandler.getPlayerID(otherPName);
  3589.  
  3590.                 if (otherPIndex != -1) {
  3591.                     Client p = (Client) PlayerHandler.players[otherPIndex];
  3592.                     writeLog(p.connectedFrom, "mutes2");
  3593.                     p.muted = true;
  3594.                     p.sM("You have been ip muted by " + playerName);
  3595.                     sM("You have ip muted " + p.playerName + "");
  3596.                 } else {
  3597.                     sM("The name doesnt exist.");
  3598.                 }
  3599.             } catch (Exception e) {
  3600.                 sM("Try entering a name you want to tele to ip mute..");
  3601.             }
  3602.         }
  3603.  
  3604.         if (command.startsWith("xteletome") && playerRights >= 2) {
  3605.             try {
  3606.                 String otherPName = command.substring(10);
  3607.                 int otherPIndex = PlayerHandler.getPlayerID(otherPName);
  3608.  
  3609.                 if (otherPIndex != -1) {
  3610.                     Client p = (Client) PlayerHandler.players[otherPIndex];
  3611.                     {
  3612.                         p.toX = absX;
  3613.                         p.toY = absY;
  3614.                         p.heightLevel = heightLevel;
  3615.                         p.updateRequired = true;
  3616.                         p.appearanceUpdateRequired = true;
  3617.                         p.sM("You have been teleported to " + playerName);
  3618.                     }
  3619.                 } else {
  3620.                     sM("The name doesnt exist.");
  3621.                 }
  3622.             } catch (Exception e) {
  3623.                 sM("Try entering a name you want to tele to you..");
  3624.             }
  3625.         }
  3626.         if (command.startsWith("xteleto") && (playerRights >= 2)) {
  3627.             try {
  3628.                 String otherPName = command.substring(8);
  3629.                 int otherPIndex = PlayerHandler.getPlayerID(otherPName);
  3630.                 if (otherPIndex != -1) {
  3631.                     Client p = (Client) PlayerHandler.players[otherPIndex];
  3632.                     {
  3633.                         toX = p.absX;
  3634.                         toY = p.absY;
  3635.                         heightLevel = p.heightLevel;
  3636.                         updateRequired = true;
  3637.                         // PlayerHandler.messageToAdmins =
  3638.                         // "Teleto: "+playerName+" has teleported to "+p.playerName;
  3639.                         sM("Teleto: You teleport to " + p.playerName);
  3640.                     }
  3641.                 }
  3642.             } catch (Exception e) {
  3643.                 sM("Try entering a name you want to tele to..");
  3644.             }
  3645.  
  3646.         }
  3647.         if (command.equalsIgnoreCase("bank") && playerRights > 1
  3648.                 && !isInPitGame()) {
  3649.             openUpBank();
  3650.         }
  3651.         if (command.startsWith("empty")) {
  3652.             long now = System.currentTimeMillis();
  3653.             if (now - lastAction < 60000) {
  3654.                 sM("You must wait 60 seconds after an action to ::empty!");
  3655.                 lastAction = now;
  3656.             } else {
  3657.                 removeAllItems();
  3658.             }
  3659.         }
  3660.         if (command.startsWith("pickup") && playerRights > 1) {
  3661.             String[] args = command.split(" ");
  3662.             if (args.length == 3) {
  3663.                 int newItemID = Integer.parseInt(args[1]);
  3664.                 int newItemAmount = Integer.parseInt(args[2]);
  3665.                 if (newItemID <= 160000 && newItemID >= 0) {
  3666.                     addItem(newItemID, newItemAmount);
  3667.                 } else {
  3668.                     sM("No such item.");
  3669.                 }
  3670.             } else {
  3671.                 sM("Oops! Use as ::pickup 995 100");
  3672.             }
  3673.         }
  3674.     }
  3675.  
  3676.     public void debug(String text) {
  3677.         if (debug)
  3678.             sM(text);
  3679.     }
  3680.  
  3681.     public void declineTrade() {
  3682.         tradeStatus = 0;
  3683.         declineTrade(true);
  3684.     }
  3685.  
  3686.     public void declineTrade(boolean tellOther) {
  3687.         try {
  3688.             if (acceptedTrade)
  3689.                 return;
  3690.             RemoveAllWindows();
  3691.             Client o = (Client) PlayerHandler.players[trade_reqId];
  3692.             if (o == null) {
  3693.                 return;
  3694.             }
  3695.  
  3696.             if (tellOther) {
  3697.                 o.declineTrade(false);
  3698.                 o.RemoveAllWindows();
  3699.             }
  3700.  
  3701.             for (GameItem item : offeredItems) {
  3702.                 if (item.amount < 1) {
  3703.                     continue;
  3704.                 }
  3705.                 if (item.stackable) {
  3706.                     addItem(item.id, item.amount);
  3707.                 } else {
  3708.                     for (int i = 0; i < item.amount; i++) {
  3709.                         addItem(item.id, 1);
  3710.                     }
  3711.                 }
  3712.             }
  3713.             canOffer = true;
  3714.             tradeConfirmed = false;
  3715.             tradeConfirmed2 = false;
  3716.             offeredItems.clear();
  3717.             inTrade = false;
  3718.             trade_reqId = 0;
  3719.             // savegame(false);
  3720.         } catch (Exception Ex) {
  3721.         }
  3722.     }
  3723.  
  3724.     public boolean DeleteArrow() {
  3725.         if (playerEquipmentN[playerArrows] == 0 && !hasCrystalBow()) {
  3726.             deleteequiment(playerEquipment[playerArrows], playerArrows);
  3727.             return false;
  3728.         }
  3729.         if ((!hasCrystalBow()) && (playerEquipmentN[playerArrows] > 0)
  3730.                 && System.currentTimeMillis() - lastAction > actionInterval) {
  3731.             outStream.createFrameVarSizeWord(34);
  3732.             outStream.writeWord(1688);
  3733.             outStream.writeByte(playerArrows);
  3734.             outStream.writeWord(playerEquipment[playerArrows] + 1);
  3735.             if (playerEquipmentN[playerArrows] - 1 > 254) {
  3736.                 outStream.writeByte(255);
  3737.                 outStream.writeDWord(playerEquipmentN[playerArrows] - 1);
  3738.             } else {
  3739.                 outStream.writeByte(playerEquipmentN[playerArrows] - 1); // amount
  3740.             }
  3741.             outStream.endFrameVarSizeWord();
  3742.             playerEquipmentN[playerArrows] -= 1;
  3743.         }
  3744.         updateRequired = true;
  3745.         appearanceUpdateRequired = true;
  3746.         return true;
  3747.     }
  3748.  
  3749.     public void deleteequiment(int wearID, int slot) {
  3750.         playerEquipment[slot] = -1;
  3751.         playerEquipmentN[slot] = 0;
  3752.         outStream.createFrame(34);
  3753.         outStream.writeWord(6);
  3754.         outStream.writeWord(1688);
  3755.         outStream.writeByte(slot);
  3756.         outStream.writeWord(0);
  3757.         outStream.writeByte(0);
  3758.         ResetBonus();
  3759.         GetBonus();
  3760.         WriteBonus();
  3761.         updateRequired = true;
  3762.         appearanceUpdateRequired = true;
  3763.     }
  3764.  
  3765.     public void deleteItem(int id, int amount) {
  3766.         deleteItem(id, GetItemSlot(id), amount);
  3767.     }
  3768.  
  3769.     public void deleteItem(int id, int slot, int amount) {
  3770.         if ((slot > -1) && (slot < playerItems.length)) {
  3771.             if ((playerItems[slot] - 1) == id) {
  3772.                 if (playerItemsN[slot] > amount) {
  3773.                     playerItemsN[slot] -= amount;
  3774.                 } else {
  3775.                     playerItemsN[slot] = 0;
  3776.                     playerItems[slot] = 0;
  3777.                 }
  3778.                 resetItems(3214);
  3779.             }
  3780.         } else {
  3781.         }
  3782.     }
  3783.  
  3784.     public void Deleteobjects() {
  3785.  
  3786.         // deletethatobject(2898, 3428);
  3787.  
  3788.     }
  3789.  
  3790.     public boolean deleteRing() {
  3791.         if (playerEquipmentN[playerWeapon] == 0) {
  3792.             deleteequiment(playerEquipment[playerWeapon], playerWeapon);
  3793.             return false;
  3794.         }
  3795.         if ((playerEquipmentN[playerWeapon] > 0)
  3796.                 && System.currentTimeMillis() - lastAction > actionInterval) {
  3797.             outStream.createFrameVarSizeWord(34);
  3798.             outStream.writeWord(1688);
  3799.             outStream.writeByte(playerWeapon);
  3800.             outStream.writeWord(playerEquipment[playerWeapon] + 1);
  3801.             if (playerEquipmentN[playerWeapon] - 1 > 254) {
  3802.                 outStream.writeByte(255);
  3803.                 outStream.writeDWord(playerEquipmentN[playerWeapon] - 1);
  3804.             } else {
  3805.                 outStream.writeByte(playerEquipmentN[playerWeapon] - 1); // amount
  3806.             }
  3807.             outStream.endFrameVarSizeWord();
  3808.             playerEquipmentN[playerWeapon] -= 1;
  3809.         }
  3810.         updateRequired = true;
  3811.         appearanceUpdateRequired = true;
  3812.         return true;
  3813.     }
  3814.  
  3815.     public void deletethatobject(int objectX, int objectY) {
  3816.         ReplaceObject2(objectX, objectY, 6951, -1, 10);
  3817.     }
  3818.  
  3819.     public boolean destroyItem(int item) {
  3820.         for (int i = 0; i < noTrade.length; i++) {
  3821.             if (noTrade[i] == item)
  3822.                 return true;
  3823.         }
  3824.         return false;
  3825.     }
  3826.  
  3827.     public void destruct() {
  3828.         /*
  3829.          * if (!logoutButton) { if (!destruct) destruct = true; if (destruct &&
  3830.          * !waited) return; }
  3831.          */
  3832.         if (mySock == null) {
  3833.             return;
  3834.         } // already shutdown
  3835.         try {
  3836.             Misc.println("ClientHandler: Client " + playerName
  3837.                     + " disconnected (" + connectedFrom + ")");
  3838.             disconnected = true;
  3839.             if (saveNeeded)
  3840.                 savegame(true);
  3841.             if (in != null) {
  3842.                 in.close();
  3843.             }
  3844.             if (out != null) {
  3845.                 out.close();
  3846.             }
  3847.             mySock = null;
  3848.             in = null;
  3849.             out = null;
  3850.             inStream = null;
  3851.             outStream = null;
  3852.             isActive = false;
  3853.             synchronized (this) {
  3854.                 notify();
  3855.             } // make sure this threads gets control so it can terminate
  3856.             buffer = null;
  3857.         } catch (java.io.IOException ioe) {
  3858.             ioe.printStackTrace();
  3859.         }
  3860.         super.destruct();
  3861.     }
  3862.  
  3863.     // two methods that are only used for login procedure
  3864.     private void directFlushOutStream() throws java.io.IOException {
  3865.         out.write(outStream.buffer, 0, outStream.currentOffset);
  3866.         outStream.currentOffset = 0; // reset
  3867.     }
  3868.  
  3869.     public int distanceToPoint(int pointX, int pointY) {
  3870.         return (int) Math.sqrt(Math.pow(absX - pointX, 2)
  3871.                 + Math.pow(absY - pointY, 2));
  3872.     }
  3873.  
  3874.     public void drawback() {
  3875.         if (hasCrystalBow()) {
  3876.             specGFX(250);
  3877.         }
  3878.         if (playerEquipment[playerArrows] == 882 && !hasCrystalBow()) {
  3879.             specGFX(18);
  3880.         } else if (playerEquipment[playerArrows] == 884 && !hasCrystalBow()) {
  3881.             specGFX(19);
  3882.         } else if (playerEquipment[playerArrows] == 886 && !hasCrystalBow()) {
  3883.             specGFX(20);
  3884.         } else if (playerEquipment[playerArrows] == 888 && !hasCrystalBow()) {
  3885.             specGFX(21);
  3886.         } else if (playerEquipment[playerArrows] == 890 && !hasCrystalBow()) {
  3887.             specGFX(22);
  3888.         } else if (playerEquipment[playerArrows] == 892 && !hasCrystalBow()) {
  3889.             specGFX(24);
  3890.  
  3891.         }
  3892.     }
  3893.  
  3894.     public void dropItem(int droppedItem, int slot) {
  3895.         // Misc.printlnTag("droppeditem ["+playerItems[slot]+"] which is
  3896.         // ["+(droppedItem+1)+"]");
  3897.         if (playerRights == 2) {
  3898.             sM("Dropping has been disabled, use ::empty to delete your inventoy instead.");
  3899.             return;
  3900.         }
  3901.         if (froze)
  3902.             return;
  3903.         if (!playerHasItem(droppedItem))
  3904.             return;
  3905.         if (playerName == null)
  3906.             return;
  3907.         if (deathStage > 0)
  3908.             return;
  3909.         if (inCombat && GetItemValue(droppedItem) > 10000) {
  3910.             sM("You may not drop an item worth more than 10,000 coins while in combat.");
  3911.             return;
  3912.         }
  3913.         if (droppedItem == 4708) {
  3914.             replaceitem2(4708, 4860);
  3915.         }
  3916.         if (droppedItem == 4710) {
  3917.             replaceitem2(4710, 4866);
  3918.         }
  3919.         if (droppedItem == 4712) {
  3920.             replaceitem2(4712, 4872);
  3921.         }
  3922.         if (droppedItem == 4714) {
  3923.             replaceitem2(4714, 4878);
  3924.         }
  3925.         if (droppedItem == 4716) {
  3926.             replaceitem2(4716, 4884);
  3927.         }
  3928.         if (droppedItem == 4718) {
  3929.             replaceitem2(4718, 4890);
  3930.         }
  3931.         if (droppedItem == 4720) {
  3932.             replaceitem2(4720, 4896);
  3933.         }
  3934.         if (droppedItem == 4722) {
  3935.             replaceitem2(4722, 4902);
  3936.         }
  3937.         if (droppedItem == 4724) {
  3938.             replaceitem2(4724, 4908);
  3939.         }
  3940.         if (droppedItem == 4726) {
  3941.             replaceitem2(4726, 4914);
  3942.         }
  3943.         if (droppedItem == 4728) {
  3944.             replaceitem2(4728, 4920);
  3945.         }
  3946.         if (droppedItem == 4730) {
  3947.             replaceitem2(4730, 4926);
  3948.         }
  3949.         if (droppedItem == 4732) {
  3950.             replaceitem2(4732, 4932);
  3951.         }
  3952.         if (droppedItem == 4734) {
  3953.             replaceitem2(4734, 4938);
  3954.         }
  3955.         if (droppedItem == 4736) {
  3956.             replaceitem2(4736, 4944);
  3957.         }
  3958.         if (droppedItem == 4738) {
  3959.             replaceitem2(4738, 4950);
  3960.         }
  3961.         if (droppedItem == 4745) {
  3962.             replaceitem2(4745, 4956);
  3963.         }
  3964.         if (droppedItem == 4747) {
  3965.             replaceitem2(4747, 4962);
  3966.         }
  3967.         if (droppedItem == 4749) {
  3968.             replaceitem2(4749, 4968);
  3969.         }
  3970.         if (droppedItem == 4751) {
  3971.             replaceitem2(4751, 4974);
  3972.         }
  3973.         if (droppedItem == 4753) {
  3974.             replaceitem2(4753, 4980);
  3975.         }
  3976.         if (droppedItem == 4755) {
  3977.             replaceitem2(4755, 4986);
  3978.         }
  3979.         if (droppedItem == 4757) {
  3980.             replaceitem2(4757, 4992);
  3981.         }
  3982.         if (droppedItem == 4759) {
  3983.             replaceitem2(4759, 4998);
  3984.         }
  3985.         if (droppedItem == 4045 && !isInJail()) {
  3986.             deleteItem(4045, 1);
  3987.             dealDamage(15);
  3988.             hitDiff = 15;
  3989.             plrText = "Ouch!";
  3990.             plrTextUpdateRequired = true;
  3991.             updateRequired = true;
  3992.             hitUpdateRequired = true;
  3993.             setAnimation(827);
  3994.             return;
  3995.         }
  3996.         if ((playerItemsN[slot] != 0) && (droppedItem != -1)
  3997.                 && (playerItems[slot] == droppedItem + 1)) {
  3998.             for (@SuppressWarnings("unused")
  3999.             int element : noTrade) {
  4000.             }
  4001.             if (destroyItem(droppedItem)) {
  4002.                 outStream.createFrameVarSizeWord(34);
  4003.                 outStream.writeWord(14171);
  4004.                 outStream.writeByte(0);
  4005.                 outStream.writeWord(droppedItem + 1);
  4006.                 outStream.writeByte(255);
  4007.                 outStream.writeDWord(1);
  4008.                 outStream.endFrameVarSizeWord();
  4009.                 sendFrame126("Are you sure you want to destroy this object?",
  4010.                         14174);
  4011.                 sendFrame126("Yes.", 14175);
  4012.                 sendFrame126("No.", 141756);
  4013.                 sendFrame126("" + GetItemName(droppedItem), 14184);
  4014.                 sendFrame126(getMessageA(droppedItem), 14182);
  4015.                 sendFrame126(getMessageB(droppedItem), 14183);
  4016.                 sendFrame164(14170);
  4017.                 publicDroppendItem = droppedItem;
  4018.                 return;
  4019.             }
  4020.             ItemHandler.addItem(playerItems[slot] - 1, absX, absY,
  4021.                     playerItemsN[slot], playerId, false);
  4022.             // createGroundItem(droppedItem, absX, absY, c);
  4023.             deleteItem(droppedItem, slot, playerItemsN[slot]);
  4024.             updateRequired = true;
  4025.             savegame(false);
  4026.         }
  4027.     }
  4028.  
  4029.     public void emptyGiantPouch() {
  4030.         if (giantPouch < 12) {
  4031.             sM("You do not have 12 rune essence.");
  4032.             return;
  4033.         }
  4034.         if (freeSlots() < 12) {
  4035.             sM("You need at least 12 free slots before emptying your pouch.");
  4036.             return;
  4037.         }
  4038.         if (giantPouch == 12 && freeSlots() >= 12) {
  4039.             giantPouch -= 12;
  4040.             addItem(1436, 1);
  4041.             addItem(1436, 1);
  4042.             addItem(1436, 1);
  4043.             addItem(1436, 1);
  4044.             addItem(1436, 1);
  4045.             addItem(1436, 1);
  4046.             addItem(1436, 1);
  4047.             addItem(1436, 1);
  4048.             addItem(1436, 1);
  4049.             addItem(1436, 1);
  4050.             addItem(1436, 1);
  4051.             addItem(1436, 1);
  4052.         }
  4053.     }
  4054.  
  4055.     public void emptyLargePouch() {
  4056.         if (largePouch < 9) {
  4057.             sM("You do not have 9 rune essence.");
  4058.             return;
  4059.         }
  4060.         if (freeSlots() < 9) {
  4061.             sM("You need at least 9 free slots before emptying your pouch.");
  4062.             return;
  4063.         }
  4064.         if (largePouch == 9 && freeSlots() >= 9) {
  4065.             largePouch -= 9;
  4066.             addItem(1436, 1);
  4067.             addItem(1436, 1);
  4068.             addItem(1436, 1);
  4069.             addItem(1436, 1);
  4070.             addItem(1436, 1);
  4071.             addItem(1436, 1);
  4072.             addItem(1436, 1);
  4073.             addItem(1436, 1);
  4074.             addItem(1436, 1);
  4075.         }
  4076.     }
  4077.  
  4078.     public void emptyMediumPouch() {
  4079.         if (mediumPouch < 6) {
  4080.             sM("You do not have 6 rune essence.");
  4081.             return;
  4082.         }
  4083.         if (freeSlots() < 6) {
  4084.             sM("You need at least 6 free slots before emptying your pouch.");
  4085.             return;
  4086.         }
  4087.         if (mediumPouch == 6 && freeSlots() >= 6) {
  4088.             mediumPouch -= 6;
  4089.             addItem(1436, 1);
  4090.             addItem(1436, 1);
  4091.             addItem(1436, 1);
  4092.             addItem(1436, 1);
  4093.             addItem(1436, 1);
  4094.             addItem(1436, 1);
  4095.         }
  4096.     }
  4097.  
  4098.     public void emptySmallPouch() {
  4099.         if (smallPouch < 3) {
  4100.             sM("You do not have 3 rune essence.");
  4101.             return;
  4102.         }
  4103.         if (freeSlots() < 3) {
  4104.             sM("You need at least 3 free slots before emptying your pouch.");
  4105.             return;
  4106.         }
  4107.         if (smallPouch == 3 && freeSlots() >= 3) {
  4108.             smallPouch -= 3;
  4109.             addItem(1436, 1);
  4110.             addItem(1436, 1);
  4111.             addItem(1436, 1);
  4112.         }
  4113.     }
  4114.  
  4115.     public void farm(int req, int itemAdd, int itemDelete, int xp) {
  4116.         if (playerLevel[19] < req) {
  4117.             sM("You need at least " + req + " farming to plant this seed!");
  4118.             return;
  4119.         }
  4120.         if (System.currentTimeMillis() - lastAction < actionInterval)
  4121.             return;
  4122.         actionInterval = 5000;
  4123.         lastAction = System.currentTimeMillis();
  4124.         sM("You plant the seeds and grow some herbs.");
  4125.         setAnimation(2273);
  4126.         addItem(itemAdd, 1);
  4127.         deleteItem(itemDelete, getItemSlot(itemDelete), 1);
  4128.         addSkillXP(xp, 19);
  4129.     }
  4130.  
  4131.     public void fillGiantPouch() {
  4132.         int essence = amountOfItem(1436);
  4133.         if (!playerHasItem(1436)) {
  4134.             sM("You do not have any rune essence to fill.");
  4135.             return;
  4136.         }
  4137.         if (essence < 12) {
  4138.             sM("You do not have 12 rune essence to put in this pouch.");
  4139.             return;
  4140.         }
  4141.         if (essence >= 12 && (giantPouch == 0)) {
  4142.             deleteItem(1436, 1);
  4143.             deleteItem(1436, 1);
  4144.             deleteItem(1436, 1);
  4145.             deleteItem(1436, 1);
  4146.             deleteItem(1436, 1);
  4147.             deleteItem(1436, 1);
  4148.             deleteItem(1436, 1);
  4149.             deleteItem(1436, 1);
  4150.             deleteItem(1436, 1);
  4151.             deleteItem(1436, 1);
  4152.             deleteItem(1436, 1);
  4153.             deleteItem(1436, 1);
  4154.             giantPouch += 12;
  4155.             return;
  4156.         }
  4157.         if (giantPouch == 12) {
  4158.             sM("Your pouch is full.");
  4159.             return;
  4160.         }
  4161.     }
  4162.  
  4163.     // forces to read forceRead bytes from the Client - block until we have
  4164.     // received those
  4165.     private void fillInStream(int forceRead) throws java.io.IOException {
  4166.         inStream.currentOffset = 0;
  4167.         in.read(inStream.buffer, 0, forceRead);
  4168.         // in.readFully(inStream.buffer, 0,
  4169.         // forceRead);//in.read(inStream.buffer, 0, forceRead);
  4170.     }
  4171.  
  4172.     public void fillLargePouch() {
  4173.         int essence = amountOfItem(1436);
  4174.         if (!playerHasItem(1436)) {
  4175.             sM("You do not have any rune essence to fill.");
  4176.             return;
  4177.         }
  4178.         if (essence < 9) {
  4179.             sM("You do not have 9 rune essence to put in this pouch.");
  4180.             return;
  4181.         }
  4182.         if (essence >= 9 && (largePouch == 0)) {
  4183.             deleteItem(1436, 1);
  4184.             deleteItem(1436, 1);
  4185.             deleteItem(1436, 1);
  4186.             deleteItem(1436, 1);
  4187.             deleteItem(1436, 1);
  4188.             deleteItem(1436, 1);
  4189.             deleteItem(1436, 1);
  4190.             deleteItem(1436, 1);
  4191.             deleteItem(1436, 1);
  4192.             largePouch += 9;
  4193.             return;
  4194.         }
  4195.         if (largePouch == 9) {
  4196.             sM("Your pouch is full.");
  4197.             return;
  4198.         }
  4199.     }
  4200.  
  4201.     public void fillMediumPouch() {
  4202.         int essence = amountOfItem(1436);
  4203.         if (!playerHasItem(1436)) {
  4204.             sM("You do not have any rune essence to fill.");
  4205.             return;
  4206.         }
  4207.         if (essence < 6) {
  4208.             sM("You do not have 6 rune essence to put in this pouch.");
  4209.             return;
  4210.         }
  4211.         if (essence >= 6 && (mediumPouch == 0)) {
  4212.             deleteItem(1436, 1);
  4213.             deleteItem(1436, 1);
  4214.             deleteItem(1436, 1);
  4215.             deleteItem(1436, 1);
  4216.             deleteItem(1436, 1);
  4217.             deleteItem(1436, 1);
  4218.             mediumPouch += 6;
  4219.             return;
  4220.         }
  4221.         if (mediumPouch == 6) {
  4222.             sM("Your pouch is full.");
  4223.             return;
  4224.         }
  4225.     }
  4226.  
  4227.     public void fillSmallPouch() {
  4228.         int essence = amountOfItem(1436);
  4229.         if (!playerHasItem(1436)) {
  4230.             sM("You do not have any rune essence to fill.");
  4231.             return;
  4232.         }
  4233.         if (essence < 3) {
  4234.             sM("You do not have 3 rune essence to put in this pouch.");
  4235.             return;
  4236.         }
  4237.         if (essence >= 3 && (smallPouch == 0)) {
  4238.             deleteItem(1436, 1);
  4239.             deleteItem(1436, 1);
  4240.             deleteItem(1436, 1);
  4241.             smallPouch += 3;
  4242.         }
  4243.         if (smallPouch == 3) {
  4244.             sM("Your pouch is full.");
  4245.             return;
  4246.         }
  4247.     }
  4248.  
  4249.     public int findItem(int id, int[] items, int[] amounts) {
  4250.         for (int i = 0; i < playerItems.length; i++) {
  4251.             if (((items[i] - 1) == id) && (amounts[i] > 0)) {
  4252.                 return i;
  4253.             }
  4254.         }
  4255.         return -1;
  4256.     }
  4257.  
  4258.     public boolean firespell(int castID, int casterY, int casterX, int offsetY,
  4259.             int offsetX, int angle, int speed, int movegfxID, int startHeight,
  4260.             int endHeight, int MageAttackIndex, int finishID, int enemyY,
  4261.             int enemyX) {
  4262.         fcastid = castID;
  4263.         fcasterY = casterY;
  4264.         fcasterX = casterX;
  4265.         foffsetY = offsetY;
  4266.         foffsetX = offsetX;
  4267.         fangle = angle;
  4268.         fspeed = speed;
  4269.         fmgfxid = movegfxID;
  4270.         fsh = startHeight;
  4271.         feh = endHeight;
  4272.         ffinishid = finishID;
  4273.         fenemyY = enemyY;
  4274.         fenemyX = enemyX;
  4275.  
  4276.         // Casts Spell In Hands
  4277.         if ((cast == false) && Projectile(MagicHandler.spellID)
  4278.                 && casterY == absY && casterX == absX) {
  4279.             specGFX(castID);
  4280.             cast = true;
  4281.             firingspell = true;
  4282.         }
  4283.         if ((cast == false) && !Projectile(MagicHandler.spellID)) {
  4284.             cast = true;
  4285.             firingspell = true;
  4286.         }
  4287.         // Fires Projectile
  4288.         if ((cast == true) && (fired == false)
  4289.                 && Projectile(MagicHandler.spellID)) {
  4290.             createProjectile(casterY, casterX, offsetY, offsetX, angle, speed,
  4291.                     movegfxID, startHeight, endHeight, MageAttackIndex);
  4292.             fired = true;
  4293.         }
  4294.         if ((cast == true) && (fired == false)
  4295.                 && !Projectile(MagicHandler.spellID)) {
  4296.             fired = true;
  4297.         }
  4298.         // Finishes Spell
  4299.         if (fired == true) {
  4300.             resetGFX(castID, enemyX, enemyY);
  4301.             return false;
  4302.         }
  4303.         return true;
  4304.  
  4305.     } // Resets Projectiles
  4306.  
  4307.     public void fish(int id) {
  4308.         if (!playerHasItem(-1)) {
  4309.             resetAction(true);
  4310.         }
  4311.         if (fishTries > 0) {
  4312.             fishTries--;
  4313.         } else {
  4314.             resetAction(true);
  4315.         }
  4316.         boolean success = false;
  4317.         int exp = 0;
  4318.         switch (id) {
  4319.         case 317:
  4320.             if (Misc.random(playerLevel[playerFishing] + 5) >= 5) {
  4321.                 success = true;
  4322.                 exp = 250;
  4323.             }
  4324.             break;
  4325.         case 377:
  4326.             if (Misc.random(playerLevel[playerFishing] + 5) >= 25) {
  4327.                 success = true;
  4328.                 exp = 400;
  4329.             }
  4330.             break;
  4331.         case 383:
  4332.             if (Misc.random(playerLevel[playerFishing] + 5) >= 25) {
  4333.                 success = true;
  4334.                 exp = 1000;
  4335.             }
  4336.             break;
  4337.         case 389:
  4338.             if (Misc.random(playerLevel[playerFishing] + 5) >= 25) {
  4339.                 success = true;
  4340.                 exp = 1500;
  4341.             }
  4342.             break;
  4343.         }
  4344.         if (success) {
  4345.             if (playerHasItem(-1)) {
  4346.                 sM("You catch a " + getItemName(id));
  4347.                 addItem(id, 1);
  4348.                 addSkillXP(exp, playerFishing);
  4349.             } else {
  4350.                 sM("Not enough space in your inventory.");
  4351.                 resetAction(true);
  4352.             }
  4353.         } else {
  4354.             sM("Failed attempt!");
  4355.         }
  4356.     }
  4357.  
  4358.     // writes any data in outStream to the relaying buffer
  4359.     public void flushOutStream() {
  4360.         if (disconnected || (outStream.currentOffset == 0)) {
  4361.             return;
  4362.         }
  4363.  
  4364.         synchronized (this) {
  4365.             int maxWritePtr = (readPtr + bufferSize - 2) % bufferSize;
  4366.  
  4367.             for (int i = 0; i < outStream.currentOffset; i++) {
  4368.                 buffer[writePtr] = outStream.buffer[i];
  4369.                 writePtr = (writePtr + 1) % bufferSize;
  4370.                 if (writePtr == maxWritePtr) {
  4371.                     shutdownError("Buffer overflow.");
  4372.                     // outStream.currentOffset = 0;
  4373.                     disconnected = true;
  4374.                     return;
  4375.                 }
  4376.             }
  4377.             outStream.currentOffset = 0;
  4378.  
  4379.             notify();
  4380.         }
  4381.     }
  4382.  
  4383.     public void followDirection() {
  4384.         faceNPC(32768 + followID);
  4385.         int i = PlayerHandler.players[followID].absX;
  4386.         int k = PlayerHandler.players[followID].absY;
  4387.         boolean flag1 = WithinDistance(i, k, absX, absY, 1);
  4388.         boolean flag3 = WithinDistance(i, k, absX, absY, 2);
  4389.         boolean UseBow = false;
  4390.         if (playerEquipment[playerWeapon] == 839
  4391.                 || playerEquipment[playerWeapon] == 841
  4392.                 || playerEquipment[playerWeapon] == 843
  4393.                 || playerEquipment[playerWeapon] == 845
  4394.                 || playerEquipment[playerWeapon] == 847
  4395.                 || playerEquipment[playerWeapon] == 849
  4396.                 || playerEquipment[playerWeapon] == 851
  4397.                 || playerEquipment[playerWeapon] == 853
  4398.                 || playerEquipment[playerWeapon] == 855
  4399.                 || playerEquipment[playerWeapon] == 857
  4400.                 || playerEquipment[playerWeapon] == 837
  4401.                 || playerEquipment[playerWeapon] == 861
  4402.                 || playerEquipment[playerWeapon] == 4734
  4403.                 || playerEquipment[playerWeapon] == 859
  4404.                 || playerEquipment[playerWeapon] == 4827 || hasCrystalBow()) {
  4405.             UseBow = true;
  4406.         }
  4407.         boolean UseCrossBow = false;
  4408.         if (playerEquipment[playerWeapon] == 837) {
  4409.             UseCrossBow = true;
  4410.         }
  4411.         boolean UseRing = false;
  4412.         if (playerEquipment[playerWeapon] == 6522) {
  4413.             UseRing = true;
  4414.         }
  4415.         if (isInArena() || isInGraardor() || isInApe() || isInJail()
  4416.                 || isInRock()) {
  4417.             return;
  4418.         }
  4419.         if (isInPitRoom()) {
  4420.             sM("You can't follow in the waiting room!");
  4421.             return;
  4422.         }
  4423.         if (isInAssault()) {
  4424.             sM("You can't follow in assault!");
  4425.             return;
  4426.         }
  4427.         if (k == absY && i == absX)
  4428.             walkTo(0, getMove(absY, k - 1));
  4429.         if (!UseBow && !UseCrossBow && !UseRing && !flag1 || !inCombat
  4430.                 && !flag1) {
  4431.             if (flag3 && PlayerHandler.players[followID] != null) {
  4432.                 if (k > absY && i == absX)
  4433.                     walkTo(0, getMove(absY, k - 1));
  4434.                 else if (k < absY && i == absX)
  4435.                     walkTo(0, getMove(absY, k + 1));
  4436.                 else if (i > absX && k == absY)
  4437.                     walkTo(getMove(absX, i - 1), 0);
  4438.                 else if (i < absX && k == absY)
  4439.                     walkTo(getMove(absX, i + 1), 0);
  4440.                 else if (i < absX && k < absY)
  4441.                     walkTo(getMove(absX, i + 1), getMove(absY, k + 1));
  4442.                 else if (i > absX && k > absY)
  4443.                     walkTo(getMove(absX, i - 1), getMove(absY, k - 1));
  4444.                 else if (i < absX && k > absY)
  4445.                     walkTo(getMove(absX, i + 1), getMove(absY, k - 1));
  4446.                 else if (i > absX && k < absY) {
  4447.                     walkTo(getMove(absX, i - 1), getMove(absY, k + 1));
  4448.                 } else {
  4449.                     sM("Undocumented movement.");
  4450.                     sM((new StringBuilder()).append("followX - absX = ")
  4451.                             .append(i - absX).toString());
  4452.                     sM((new StringBuilder()).append("followY - absY = ")
  4453.                             .append(k - absY).toString());
  4454.                 }
  4455.             } else if (!flag3 && PlayerHandler.players[followID] != null) {
  4456.                 if (k > absY && i == absX)
  4457.                     walkTo(0, getMove(absY, k - 1) + getMove(absY, k - 1));
  4458.                 else if (k < absY && i == absX)
  4459.                     walkTo(0, getMove(absY, k + 1) + getMove(absY, k + 1));
  4460.                 else if (i > absX && k == absY)
  4461.                     walkTo(getMove(absX, i - 1) + getMove(absX, i - 1), 0);
  4462.                 else if (i < absX && k == absY)
  4463.                     walkTo(getMove(absX, i + 1) + getMove(absX, i + 1), 0);
  4464.                 else if (i < absX && k < absY)
  4465.                     walkTo(getMove(absX, i + 1) + getMove(absX, i + 1),
  4466.                             getMove(absY, k + 1) + getMove(absY, k + 1));
  4467.                 else if (i > absX && k > absY)
  4468.                     walkTo(getMove(absX, i - 1) + getMove(absX, i - 1),
  4469.                             getMove(absY, k - 1) + getMove(absY, k - 1));
  4470.                 else if (i < absX && k > absY)
  4471.                     walkTo(getMove(absX, i + 1) + getMove(absX, i + 1),
  4472.                             getMove(absY, k - 1) + getMove(absY, k - 1));
  4473.                 else if (i > absX && k < absY) {
  4474.                     walkTo(getMove(absX, i + 1) + getMove(absX, i + 1),
  4475.                             getMove(absY, k - 1) + getMove(absY, k - 1));
  4476.                 } else {
  4477.                     sM("Undocumented movement.");
  4478.                     sM((new StringBuilder()).append("followX - absX = ")
  4479.                             .append(i - absX).toString());
  4480.                     sM((new StringBuilder()).append("followY - absY = ")
  4481.                             .append(k - absY).toString());
  4482.                 }
  4483.             }
  4484.         }
  4485.     }
  4486.  
  4487.     public void followDirection2() {
  4488.         if (followID2 > 0 && Server.npcHandler.npcs[followID2] != null) {
  4489.             if (Server.npcHandler.npcs[followID2].IsDead
  4490.                     || Server.npcHandler.npcs[followID2].HP <= 0) {
  4491.                 followID2 = 0;
  4492.                 return;
  4493.             }
  4494.             int j = Server.npcHandler.npcs[followID2].absX;
  4495.             int l = Server.npcHandler.npcs[followID2].absY;
  4496.             boolean flag2 = WithinDistance(j, l, absX, absY, 1);
  4497.             boolean flag4 = WithinDistance(j, l, absX, absY, 2);
  4498.             boolean UseBow = false;
  4499.             if (playerEquipment[playerWeapon] == 839
  4500.                     || playerEquipment[playerWeapon] == 841
  4501.                     || playerEquipment[playerWeapon] == 843
  4502.                     || playerEquipment[playerWeapon] == 845
  4503.                     || playerEquipment[playerWeapon] == 847
  4504.                     || playerEquipment[playerWeapon] == 849
  4505.                     || playerEquipment[playerWeapon] == 851
  4506.                     || playerEquipment[playerWeapon] == 853
  4507.                     || playerEquipment[playerWeapon] == 855
  4508.                     || playerEquipment[playerWeapon] == 857
  4509.                     || playerEquipment[playerWeapon] == 837
  4510.                     || playerEquipment[playerWeapon] == 861
  4511.                     || playerEquipment[playerWeapon] == 4734
  4512.                     || playerEquipment[playerWeapon] == 859
  4513.                     || playerEquipment[playerWeapon] == 4827 || hasCrystalBow()) {
  4514.                 UseBow = true;
  4515.             }
  4516.             boolean UseCrossBow = false;
  4517.             if (playerEquipment[playerWeapon] == 837) {
  4518.                 UseCrossBow = true;
  4519.             }
  4520.             boolean UseRing = false;
  4521.             if (playerEquipment[playerWeapon] == 6522) {
  4522.                 UseRing = true;
  4523.             }
  4524.             if (l == absY && j == absX)
  4525.                 walkTo(0, getMove(absY, l - 1));
  4526.             if (!UseBow && !UseCrossBow && !UseRing && !flag2)
  4527.                 if (flag4) {
  4528.                     if (l > absY && j == absX)
  4529.                         walkTo(0, getMove(absY, l - 1));
  4530.                     else if (l < absY && j == absX)
  4531.                         walkTo(0, getMove(absY, l + 1));
  4532.                     else if (j > absX && l == absY)
  4533.                         walkTo(getMove(absX, j - 1), 0);
  4534.                     else if (j < absX && l == absY)
  4535.                         walkTo(getMove(absX, j + 1), 0);
  4536.                     else if (j < absX && l < absY)
  4537.                         walkTo(getMove(absX, j + 1), getMove(absY, l + 1));
  4538.                     else if (j > absX && l > absY)
  4539.                         walkTo(getMove(absX, j - 1), getMove(absY, l - 1));
  4540.                     else if (j < absX && l > absY)
  4541.                         walkTo(getMove(absX, j + 1), getMove(absY, l - 1));
  4542.                     else if (j > absX && l < absY) {
  4543.                         walkTo(getMove(absX, j - 1), getMove(absY, l + 1));
  4544.                     } else {
  4545.                         sM("Undocumented movement.");
  4546.                         sM((new StringBuilder()).append("followX - absX = ")
  4547.                                 .append(j - absX).toString());
  4548.                         sM((new StringBuilder()).append("followY - absY = ")
  4549.                                 .append(l - absY).toString());
  4550.                     }
  4551.                 } else if (!flag4)
  4552.                     if (l > absY && j == absX)
  4553.                         walkTo(0, getMove(absY, l - 1) + getMove(absY, l - 1));
  4554.                     else if (l < absY && j == absX)
  4555.                         walkTo(0, getMove(absY, l + 1) + getMove(absY, l + 1));
  4556.                     else if (j > absX && l == absY)
  4557.                         walkTo(getMove(absX, j - 1) + getMove(absX, j - 1), 0);
  4558.                     else if (j < absX && l == absY)
  4559.                         walkTo(getMove(absX, j + 1) + getMove(absX, j + 1), 0);
  4560.                     else if (j < absX && l < absY)
  4561.                         walkTo(getMove(absX, j + 1) + getMove(absX, j + 1),
  4562.                                 getMove(absY, l + 1) + getMove(absY, l + 1));
  4563.                     else if (j > absX && l > absY)
  4564.                         walkTo(getMove(absX, j - 1) + getMove(absX, j - 1),
  4565.                                 getMove(absY, l - 1) + getMove(absY, l - 1));
  4566.                     else if (j < absX && l > absY)
  4567.                         walkTo(getMove(absX, j + 1) + getMove(absX, j + 1),
  4568.                                 getMove(absY, l - 1) + getMove(absY, l - 1));
  4569.                     else if (j > absX && l < absY) {
  4570.                         walkTo(getMove(absX, j + 1) + getMove(absX, j + 1),
  4571.                                 getMove(absY, l - 1) + getMove(absY, l - 1));
  4572.                     } else {
  4573.                         sM("Undocumented movement.");
  4574.                         sM((new StringBuilder()).append("followX - absX = ")
  4575.                                 .append(j - absX).toString());
  4576.                         sM((new StringBuilder()).append("followY - absY = ")
  4577.                                 .append(l - absY).toString());
  4578.                     }
  4579.         }
  4580.     }
  4581.  
  4582.     public void frame1() {
  4583.         // cancels all player and npc emotes within area!
  4584.         outStream.createFrame(1);
  4585.         updateRequired = true;
  4586.         appearanceUpdateRequired = true;
  4587.     }
  4588.  
  4589.     public void frame61(int i1) {
  4590.         outStream.createFrame(61);
  4591.         outStream.writeByte(i1);
  4592.         updateRequired = true;
  4593.         appearanceUpdateRequired = true;
  4594.     }
  4595.  
  4596.     public int freeBankSlots() {
  4597.         int freeS = 0;
  4598.  
  4599.         for (int i = 0; i < playerBankSize; i++) {
  4600.             if (bankItems[i] <= 0) {
  4601.                 freeS++;
  4602.             }
  4603.         }
  4604.         return freeS;
  4605.     }
  4606.  
  4607.     public int freeSlots() {
  4608.         int freeS = 0;
  4609.  
  4610.         for (int element : playerItems) {
  4611.             if (element <= 0) {
  4612.                 freeS++;
  4613.             }
  4614.         }
  4615.         return freeS;
  4616.     }
  4617.  
  4618.     public void fromBank(int itemID, int fromSlot, int amount) {
  4619.         if (!IsBanking) {
  4620.             closeInterface();
  4621.             return;
  4622.         }
  4623.         if (amount > 0) {
  4624.             if (bankItems[fromSlot] > 0) {
  4625.                 if (!takeAsNote) {
  4626.                     if (Item.itemStackable[bankItems[fromSlot] - 1]) {
  4627.                         if (bankItemsN[fromSlot] > amount) {
  4628.                             if (addItem((bankItems[fromSlot] - 1), amount)) {
  4629.                                 bankItemsN[fromSlot] -= amount;
  4630.                                 resetBank();
  4631.                                 resetItems(5064);
  4632.                             }
  4633.                         } else {
  4634.                             if (addItem((bankItems[fromSlot] - 1),
  4635.                                     bankItemsN[fromSlot])) {
  4636.                                 bankItems[fromSlot] = 0;
  4637.                                 bankItemsN[fromSlot] = 0;
  4638.                                 resetBank();
  4639.                                 resetItems(5064);
  4640.                             }
  4641.                         }
  4642.                     } else {
  4643.                         while (amount > 0) {
  4644.                             if (bankItemsN[fromSlot] > 0) {
  4645.                                 if (addItem((bankItems[fromSlot] - 1), 1)) {
  4646.                                     bankItemsN[fromSlot] += -1;
  4647.                                     amount--;
  4648.                                 } else {
  4649.                                     amount = 0;
  4650.                                 }
  4651.                             } else {
  4652.                                 amount = 0;
  4653.                             }
  4654.                         }
  4655.                         resetBank();
  4656.                         resetItems(5064);
  4657.                     }
  4658.                 } else if (takeAsNote && Item.itemIsNote[bankItems[fromSlot]]) {
  4659.                     // if (Item.itemStackable[bankItems[fromSlot]+1])
  4660.                     // {
  4661.                     if (bankItemsN[fromSlot] > amount) {
  4662.                         if (addItem(bankItems[fromSlot], amount)) {
  4663.                             bankItemsN[fromSlot] -= amount;
  4664.                             resetBank();
  4665.                             resetItems(5064);
  4666.                         }
  4667.                     } else {
  4668.                         if (addItem(bankItems[fromSlot], bankItemsN[fromSlot])) {
  4669.                             bankItems[fromSlot] = 0;
  4670.                             bankItemsN[fromSlot] = 0;
  4671.                             resetBank();
  4672.                             resetItems(5064);
  4673.                         }
  4674.                     }
  4675.                 } else {
  4676.                     sM("Item can't be drawn as note.");
  4677.                     if (Item.itemStackable[bankItems[fromSlot] - 1]) {
  4678.                         if (bankItemsN[fromSlot] > amount) {
  4679.                             if (addItem((bankItems[fromSlot] - 1), amount)) {
  4680.                                 bankItemsN[fromSlot] -= amount;
  4681.                                 resetBank();
  4682.                                 resetItems(5064);
  4683.                             }
  4684.                         } else {
  4685.                             if (addItem((bankItems[fromSlot] - 1),
  4686.                                     bankItemsN[fromSlot])) {
  4687.                                 bankItems[fromSlot] = 0;
  4688.                                 bankItemsN[fromSlot] = 0;
  4689.                                 resetBank();
  4690.                                 resetItems(5064);
  4691.                             }
  4692.                         }
  4693.                     } else {
  4694.                         while (amount > 0) {
  4695.                             if (bankItemsN[fromSlot] > 0) {
  4696.                                 if (addItem((bankItems[fromSlot] - 1), 1)) {
  4697.                                     bankItemsN[fromSlot] += -1;
  4698.                                     amount--;
  4699.                                 } else {
  4700.                                     amount = 0;
  4701.                                 }
  4702.                             } else {
  4703.                                 amount = 0;
  4704.                             }
  4705.                         }
  4706.                         resetBank();
  4707.                         resetItems(5064);
  4708.                     }
  4709.                 }
  4710.             }
  4711.         }
  4712.     }
  4713.  
  4714.     public boolean fromTrade(int itemID, int fromSlot, int amount) {
  4715.         Client o = (Client) PlayerHandler.players[trade_reqId];
  4716.         if (o == null) {
  4717.             return false;
  4718.         }
  4719.         try {
  4720.             if (!inTrade || !canOffer) {
  4721.                 declineTrade();
  4722.                 return false;
  4723.             }
  4724.             tradeConfirmed = false;
  4725.             o.tradeConfirmed = false;
  4726.             if (!Item.itemStackable[itemID]) {
  4727.                 for (int a = 0; a < amount; a++) {
  4728.                     for (GameItem item : offeredItems) {
  4729.                         if (item.id == itemID) {
  4730.                             if (!item.stackable) {
  4731.                                 offeredItems.remove(item);
  4732.                                 addItem(itemID, 1);
  4733.                                 o.sendFrame126("Trading with: " + playerName
  4734.                                         + " who has @gre@" + freeSlots()
  4735.                                         + " free slots", 3417);
  4736.                             } else {
  4737.                                 if (item.amount > amount) {
  4738.                                     item.amount -= amount;
  4739.                                     addItem(itemID, amount);
  4740.                                     o
  4741.                                             .sendFrame126("Trading with: "
  4742.                                                     + playerName
  4743.                                                     + " who has @gre@"
  4744.                                                     + freeSlots()
  4745.                                                     + " free slots", 3417);
  4746.                                 } else {
  4747.                                     amount = item.amount;
  4748.                                     offeredItems.remove(item);
  4749.                                     addItem(itemID, amount);
  4750.                                     o
  4751.                                             .sendFrame126("Trading with: "
  4752.                                                     + playerName
  4753.                                                     + " who has @gre@"
  4754.                                                     + freeSlots()
  4755.                                                     + " free slots", 3417);
  4756.                                 }
  4757.                             }
  4758.                             break;
  4759.                         }
  4760.                         o.sendFrame126("Trading with: " + playerName
  4761.                                 + " who has @gre@" + freeSlots()
  4762.                                 + " free slots", 3417);
  4763.                         tradeConfirmed = false;
  4764.                         o.tradeConfirmed = false;
  4765.                         resetItems(3322);
  4766.                         resetTItems(3415);
  4767.                         o.resetOTItems(3416);
  4768.                         sendFrame126("", 3431);
  4769.                         o.sendFrame126("", 3431);
  4770.                     }
  4771.                 }
  4772.             }
  4773.             for (GameItem item : offeredItems) {
  4774.                 if (item.id == itemID) {
  4775.                     if (!item.stackable) {
  4776.                     } else {
  4777.                         if (item.amount > amount) {
  4778.                             item.amount -= amount;
  4779.                             addItem(itemID, amount);
  4780.                             o.sendFrame126("Trading with: " + playerName
  4781.                                     + " who has @gre@" + freeSlots()
  4782.                                     + " free slots", 3417);
  4783.                         } else {
  4784.                             amount = item.amount;
  4785.                             offeredItems.remove(item);
  4786.                             addItem(itemID, amount);
  4787.                             o.sendFrame126("Trading with: " + playerName
  4788.                                     + " who has @gre@" + freeSlots()
  4789.                                     + " free slots", 3417);
  4790.                         }
  4791.                     }
  4792.                     break;
  4793.                 }
  4794.             }
  4795.  
  4796.             o.sendFrame126("Trading with: " + playerName + " who has @gre@"
  4797.                     + freeSlots() + " free slots", 3417);
  4798.             tradeConfirmed = false;
  4799.             o.tradeConfirmed = false;
  4800.             resetItems(3322);
  4801.             resetTItems(3415);
  4802.             o.resetOTItems(3416);
  4803.             sendFrame126("", 3431);
  4804.             o.sendFrame126("", 3431);
  4805.         } catch (Exception e) {
  4806.         }
  4807.         return true;
  4808.     }
  4809.  
  4810.     public boolean FullDharokEquipped() {
  4811.         if (playerEquipment[playerHat] == 4716
  4812.                 && playerEquipment[playerChest] == 4720
  4813.                 && playerEquipment[playerLegs] == 4722
  4814.                 && playerEquipment[playerWeapon] == 4718) {
  4815.             return true;
  4816.         }
  4817.         return false;
  4818.     }
  4819.  
  4820.     public boolean FullGuthanEquipped() {
  4821.         if (playerEquipment[playerHat] == 4724
  4822.                 && playerEquipment[playerChest] == 4728
  4823.                 && playerEquipment[playerLegs] == 4730
  4824.                 && playerEquipment[playerWeapon] == 4726) {
  4825.             return true;
  4826.         }
  4827.         return false;
  4828.     }
  4829.  
  4830.     public boolean FullVeracEquipped() {
  4831.         if (playerEquipment[playerHat] == 4753
  4832.                 && playerEquipment[playerChest] == 4757
  4833.                 && playerEquipment[playerLegs] == 4759
  4834.                 && playerEquipment[playerWeapon] == 4755) {
  4835.             return true;
  4836.         }
  4837.         return false;
  4838.     }
  4839.  
  4840.     public boolean FullVMage() {
  4841.         if (playerEquipment[playerHat] == 2518
  4842.                 && playerEquipment[playerChest] == 2520
  4843.                 && playerEquipment[playerLegs] == 2522) {
  4844.             return true;
  4845.         }
  4846.         return false;
  4847.     }
  4848.  
  4849.     public boolean FullVMelee() {
  4850.         if (playerEquipment[playerHat] == 2526
  4851.                 && playerEquipment[playerChest] == 2520
  4852.                 && playerEquipment[playerLegs] == 2522) {
  4853.             return true;
  4854.         }
  4855.         return false;
  4856.     }
  4857.  
  4858.     public boolean FullVRange() {
  4859.         if (playerEquipment[playerHat] == 2524
  4860.                 && playerEquipment[playerChest] == 2520
  4861.                 && playerEquipment[playerLegs] == 2523) {
  4862.             return true;
  4863.         }
  4864.         return false;
  4865.     }
  4866.  
  4867.     public int getarrowgfxnow() {
  4868.         if (playerEquipment[playerArrows] == 892) {
  4869.             return 15;
  4870.         }
  4871.         if (playerEquipment[playerArrows] == 890) {
  4872.             return 13;
  4873.         }
  4874.         if (playerEquipment[playerArrows] == 888) {
  4875.             return 12;
  4876.         }
  4877.         if (playerEquipment[playerArrows] == 886) {
  4878.             return 11;
  4879.         }
  4880.         if (playerEquipment[playerArrows] == 884) {
  4881.             return 9;
  4882.         }
  4883.         if (playerEquipment[playerArrows] == 882) {
  4884.             return 10;
  4885.         } else {
  4886.             return -1;
  4887.         }
  4888.     }
  4889.  
  4890.     public int getbattleTimer() {
  4891.         if (playerEquipment[playerWeapon] == 35
  4892.                 || playerEquipment[playerWeapon] == 667
  4893.                 || playerEquipment[playerWeapon] == 2402
  4894.                 || playerEquipment[playerWeapon] == 746
  4895.                 || playerEquipment[playerWeapon] == 6528
  4896.                 || playerEquipment[playerWeapon] == 4153
  4897.                 || playerEquipment[playerWeapon] == 4718
  4898.                 || playerEquipment[playerWeapon] == 1377
  4899.                 || playerEquipment[playerWeapon] == 3204
  4900.                 || playerEquipment[playerWeapon] == 4827
  4901.                 || playerEquipment[playerWeapon] == 7158
  4902.                 || playerEquipment[playerWeapon] == 1319) {
  4903.             return 4500;
  4904.         } else {
  4905.             if (playerEquipment[playerWeapon] == 837
  4906.                     || playerEquipment[playerWeapon] == 1305) {
  4907.                 return 3000;
  4908.             } else {
  4909.                 if (playerEquipment[playerWeapon] == 839
  4910.                         || playerEquipment[playerWeapon] == 841
  4911.                         || playerEquipment[playerWeapon] == 843
  4912.                         || playerEquipment[playerWeapon] == 845
  4913.                         || playerEquipment[playerWeapon] == 847
  4914.                         || playerEquipment[playerWeapon] == 849
  4915.                         || playerEquipment[playerWeapon] == 851
  4916.                         || playerEquipment[playerWeapon] == 853
  4917.                         || playerEquipment[playerWeapon] == 855
  4918.                         || playerEquipment[playerWeapon] == 857
  4919.                         || playerEquipment[playerWeapon] == 861
  4920.                         || playerEquipment[playerWeapon] == 4734
  4921.                         || playerEquipment[playerWeapon] == 6522) {
  4922.                     return 1500;
  4923.                 } else {
  4924.                     return 2500;
  4925.                 }
  4926.             }
  4927.         }
  4928.     }
  4929.  
  4930.     public int GetBlockAnim() {
  4931.         if (playerEquipment[playerShield] == 3095
  4932.                 || playerEquipment[playerShield] == 3096
  4933.                 || playerEquipment[playerShield] == 3097
  4934.                 || playerEquipment[playerShield] == 3098
  4935.                 || playerEquipment[playerShield] == 3099
  4936.                 || playerEquipment[playerShield] == 3100
  4937.                 || playerEquipment[playerShield] == 3101
  4938.                 || playerEquipment[playerShield] == 2621
  4939.                 || playerEquipment[playerShield] == 2589
  4940.                 || playerEquipment[playerShield] == 3101
  4941.                 || playerEquipment[playerShield] == 1201
  4942.                 || playerEquipment[playerShield] == 6524
  4943.                 || playerEquipment[playerShield] == 1187
  4944.                 || playerEquipment[playerShield] == 1540
  4945.                 || playerEquipment[playerShield] == 1171 || hasCrystalShield()) {
  4946.             return 0x484;
  4947.         }
  4948.         if (playerEquipment[playerWeapon] == 1321
  4949.                 || playerEquipment[playerWeapon] == 1323
  4950.                 || playerEquipment[playerWeapon] == 1333
  4951.                 || playerEquipment[playerWeapon] == 6611
  4952.                 || playerEquipment[playerWeapon] == 1291
  4953.                 || playerEquipment[playerWeapon] == 4587
  4954.                 || playerEquipment[playerWeapon] == 1305
  4955.                 || playerEquipment[playerWeapon] == 1377) {
  4956.             return 404;
  4957.         }
  4958.         if (playerEquipment[playerWeapon] == 4755) // veracs flail
  4959.         {
  4960.             return 2063;
  4961.         }
  4962.         if (playerEquipment[playerWeapon] == 6528) // obby maul
  4963.         {
  4964.             return 1666;
  4965.         }
  4966.         if (playerEquipment[playerWeapon] == 6818) // veracs flail
  4967.         {
  4968.             return 1125;
  4969.         }
  4970.         if (playerEquipment[playerWeapon] == 5698) {
  4971.             return 403;
  4972.         }
  4973.         if (playerEquipment[playerWeapon] == 4151) // whip
  4974.         {
  4975.             return 1659;
  4976.         }
  4977.         if (playerEquipment[playerWeapon] == 839
  4978.                 || playerEquipment[playerWeapon] == 841
  4979.                 || playerEquipment[playerWeapon] == 843
  4980.                 || playerEquipment[playerWeapon] == 845
  4981.                 || playerEquipment[playerWeapon] == 847
  4982.                 || playerEquipment[playerWeapon] == 849
  4983.                 || playerEquipment[playerWeapon] == 851
  4984.                 || playerEquipment[playerWeapon] == 853
  4985.                 || playerEquipment[playerWeapon] == 855
  4986.                 || playerEquipment[playerWeapon] == 857
  4987.                 || playerEquipment[playerWeapon] == 837
  4988.                 || playerEquipment[playerWeapon] == 861
  4989.                 || playerEquipment[playerWeapon] == 4734
  4990.                 || playerEquipment[playerWeapon] == 859
  4991.                 || playerEquipment[playerWeapon] == 4827 || hasCrystalBow()) {
  4992.             return 424;
  4993.         }
  4994.         if (playerEquipment[playerWeapon] == 4718) {
  4995.             return 424;
  4996.         }
  4997.         if (playerEquipment[playerWeapon] == 4153) // maul
  4998.         {
  4999.             return 1666;
  5000.         } else {
  5001.             return 424;
  5002.         }
  5003.     }
  5004.  
  5005.     public void GetBonus() {
  5006.         for (int i = 0; i < playerEquipment.length; i++) {
  5007.             if (playerEquipment[i] > -1) {
  5008.                 for (int j = 0; j < 9999; j++) {
  5009.                     if (ItemHandler.ItemList[j] != null) {
  5010.                         if (ItemHandler.ItemList[j].itemId == playerEquipment[i]) {
  5011.                             for (int k = 0; k < playerBonus.length; k++) {
  5012.                                 playerBonus[k] += ItemHandler.ItemList[j].Bonuses[k];
  5013.                             }
  5014.                             break;
  5015.                         }
  5016.                     }
  5017.                 }
  5018.             }
  5019.         }
  5020.     }
  5021.  
  5022.     public Client getClient(int index) {
  5023.         return ((Client) PlayerHandler.players[index]);
  5024.     }
  5025.  
  5026.     public void getEnd() {
  5027.         if (Projectile(MagicHandler.spellID)) {
  5028.             stillgfx(ffinishid, fenemyY, fenemyX);
  5029.         }
  5030.         if (!Projectile(MagicHandler.spellID)) {
  5031.             stillgfx(fcastid, fenemyY, fenemyX);
  5032.         }
  5033.     }
  5034.  
  5035.     public int getFreezeTimer(int spell) {
  5036.         if (spell == 12861) {
  5037.             return 10000;
  5038.         }
  5039.         if (spell == 12881) {
  5040.             return 20000;
  5041.         }
  5042.         if (spell == 12871) {
  5043.             return 30000;
  5044.         }
  5045.         if (spell == 12891) {
  5046.             return 35000;
  5047.         }
  5048.         if (spell == 1572) {
  5049.             return 10000;
  5050.         }
  5051.         if (spell == 1582) {
  5052.             return 20000;
  5053.         }
  5054.         if (spell == 1592) {
  5055.             return 30000;
  5056.         }
  5057.         return 30;
  5058.     }
  5059.  
  5060.     public void getHead() {
  5061.         if (ProtMage && !isSkulled)
  5062.             headIcon = 4;
  5063.         if (ProtRange && !isSkulled)
  5064.             headIcon = 2;
  5065.         if (ProtMelee && !isSkulled)
  5066.             headIcon = 1;
  5067.         if (Retribution && !isSkulled)
  5068.             headIcon = 8;
  5069.         if (Redemption && !isSkulled)
  5070.             headIcon = 32;
  5071.         if (Smite && !isSkulled)
  5072.             headIcon = 16;
  5073.         if (ProtMage && isSkulled)
  5074.             headIcon = 68;
  5075.         if (ProtRange && isSkulled)
  5076.             headIcon = 66;
  5077.         if (ProtMelee && isSkulled)
  5078.             headIcon = 65;
  5079.         if (Retribution && isSkulled)
  5080.             headIcon = 72;
  5081.         if (Redemption && isSkulled)
  5082.             headIcon = 96;
  5083.         if (Smite && isSkulled)
  5084.             headIcon = 80;
  5085.         else if (!ProtMage && !ProtRange && !ProtMelee && !Retribution
  5086.                 && !Redemption && !Smite)
  5087.             headIcon = 64;
  5088.     }
  5089.  
  5090.     public void getHit(int extraDamage) {
  5091.         Client AttackingOn2 = (Client) PlayerHandler.players[AttackingOn];
  5092.         int voidmelee = 0;
  5093.         if (FullVMelee()) {
  5094.             voidmelee += 10;
  5095.         }
  5096.         if (AttackingOn2.deathStage != 0 || AttackingOn2.currentHealth <= 0)
  5097.             return;
  5098.         int hit = Misc.random(playerMaxHit) + Misc.random(StrPrayer)
  5099.                 + Misc.random(extraDamage) + Misc.random(voidmelee);
  5100.         int aBonus = 0;
  5101.         int rand_att = Misc.random(playerLevel[0]) * 3
  5102.                 + Misc.random(AtkPray * 8);
  5103.         int rand_def = (int) (0.65 * Misc.random(AttackingOn2.playerLevel[1]) + AttackingOn2.DefPray * 8);
  5104.         if (AttackingOn2.ProtMelee) {
  5105.             rand_def += Misc.random(100);
  5106.         }
  5107.         if (FightType == 1)
  5108.             aBonus += (int) (playerBonus[1] / 20);
  5109.         int random_u = Misc.random(playerBonus[1] + aBonus) * 2;
  5110.         int dBonus = 0;
  5111.         if (AttackingOn2.FightType == 4)
  5112.             dBonus += (int) (AttackingOn2.playerBonus[6] / 20);
  5113.         int random_def = Misc.random(AttackingOn2.playerBonus[6] + dBonus
  5114.                 + AttackingOn2.AtkPray * 8);
  5115.         int noHit = Misc.random(2);
  5116.         if (AttackingOn2.ProtMelee && noHit == 2) {
  5117.             hit /= 2;
  5118.         }
  5119.         if ((random_u >= random_def) && (rand_att > rand_def)) {
  5120.             // PlayerHandler.players[AttackingOn].dealDamage(hit);
  5121.             PlayerHandler.players[AttackingOn].hitDiff = hit;
  5122.             SpecDamg(hit);
  5123.         } else {
  5124.             PlayerHandler.players[AttackingOn].hitDiff = 0;
  5125.         }
  5126.  
  5127.         PlayerHandler.players[AttackingOn].updateRequired = true;
  5128.         PlayerHandler.players[AttackingOn].hitUpdateRequired = true;
  5129.     }
  5130.  
  5131.     public void getHit2() {
  5132.         if (IsAttacking && AttackingOn > 0) {
  5133.             int hit = Misc.random(maxRangeHit());
  5134.             PlayerHandler.players[AttackingOn].dealDamage(hit);
  5135.             PlayerHandler.players[AttackingOn].hitDiff = hit;
  5136.             PlayerHandler.players[AttackingOn].updateRequired = true;
  5137.             PlayerHandler.players[AttackingOn].hitUpdateRequired = true;
  5138.         }
  5139.         if (IsAttackingNPC && attacknpc > 0) {
  5140.             if (Server.npcHandler.npcs[attacknpc] != null) {
  5141.                 if (Server.npcHandler.npcs[attacknpc].IsDead == false) {
  5142.                     Server.npcHandler.npcs[attacknpc].hitDiff = Misc.random(maxRangeHit2());
  5143.                     Server.npcHandler.npcs[attacknpc].HP -= hitDiff;
  5144.                     Server.npcHandler.npcs[attacknpc].updateRequired = true;
  5145.                     Server.npcHandler.npcs[attacknpc].hitUpdateRequired = true;
  5146.                     Server.npcHandler.npcs[attacknpc].hit = true;
  5147.                 }
  5148.             }
  5149.         }
  5150.     }
  5151.  
  5152.     public void getHitDouble(int extraDamage) {
  5153.         Client AttackingOn2 = (Client) PlayerHandler.players[AttackingOn];
  5154.         int voidmelee = 0;
  5155.         if (FullVMelee()) {
  5156.             voidmelee += 10;
  5157.         }
  5158.         if (AttackingOn2.deathStage != 0 || AttackingOn2.currentHealth <= 0)
  5159.             return;
  5160.         int hit = Misc.random(playerMaxHit) + Misc.random(StrPrayer)
  5161.                 + Misc.random(extraDamage) + Misc.random(voidmelee);
  5162.         int aBonus = 0;
  5163.         int rand_att = Misc.random(playerLevel[0]) * 3
  5164.                 + Misc.random(AtkPray * 8);
  5165.         int rand_def = (int) (0.65 * Misc.random(AttackingOn2.playerLevel[1]) + AttackingOn2.DefPray * 8);
  5166.         if (AttackingOn2.ProtMelee) {
  5167.             rand_def += Misc.random(100);
  5168.         }
  5169.         if (FightType == 1)
  5170.             aBonus += (int) (playerBonus[1] / 20);
  5171.         int random_u = Misc.random(playerBonus[1] + aBonus) * 2;
  5172.         int dBonus = 0;
  5173.         if (AttackingOn2.FightType == 4)
  5174.             dBonus += (int) (AttackingOn2.playerBonus[6] / 20);
  5175.         int random_def = Misc.random(AttackingOn2.playerBonus[6] + dBonus
  5176.                 + AttackingOn2.AtkPray * 8);
  5177.         int noHit = Misc.random(2);
  5178.         if (AttackingOn2.ProtMelee && noHit == 2) {
  5179.             hit /= 2;
  5180.         }
  5181.         if ((random_u >= random_def) && (rand_att > rand_def)) {
  5182.             PlayerHandler.players[AttackingOn].dealDamage(hit);
  5183.             PlayerHandler.players[AttackingOn].hitDiff = hit;
  5184.             SpecDamg(hit);
  5185.         } else {
  5186.             PlayerHandler.players[AttackingOn].hitDiff = 0;
  5187.         }
  5188.         PlayerHandler.players[AttackingOn].updateRequired = true;
  5189.         PlayerHandler.players[AttackingOn].hitUpdateRequired = true;
  5190.     }
  5191.  
  5192.     public String getItemName(int ItemID) {
  5193.         for (int i = 0; i < ItemHandler.MaxListedItems; i++) {
  5194.             if (ItemHandler.ItemList[i] != null) {
  5195.                 if (ItemHandler.ItemList[i].itemId == ItemID) {
  5196.                     return ItemHandler.ItemList[i].itemName;
  5197.                 }
  5198.             }
  5199.         }
  5200.         return "ItemID:" + ItemID;
  5201.     }
  5202.  
  5203.     public String GetItemName(int ItemID) {
  5204.         for (int i = 0; i < ItemHandler.MaxListedItems; i++) {
  5205.             if (ItemHandler.ItemList[i] != null) {
  5206.                 if (ItemHandler.ItemList[i].itemId == ItemID) {
  5207.                     return ItemHandler.ItemList[i].itemName;
  5208.                 }
  5209.                 if (ItemID == -1) {
  5210.                     return "Unarmed";
  5211.                 }
  5212.             }
  5213.         }
  5214.         return "ItemID:" + ItemID;
  5215.     }
  5216.  
  5217.     public double GetItemShopValue(int ItemID, int Type, int fromSlot) {
  5218.         double ShopValue = 1;
  5219.         double TotPrice = 0;
  5220.  
  5221.         for (int i = 0; i < ItemHandler.MaxListedItems; i++) {
  5222.             if (ItemHandler.ItemList[i] != null) {
  5223.                 if (ItemHandler.ItemList[i].itemId == ItemID) {
  5224.                     ShopValue = ItemHandler.ItemList[i].ShopValue;
  5225.                 }
  5226.             }
  5227.         }
  5228.         /*
  5229.          * Overstock = ShopHandler.ShopItemsN[MyShopID][fromSlot] -
  5230.          * ShopHandler.ShopItemsSN[MyShopID][fromSlot];
  5231.          */
  5232.         TotPrice = (ShopValue * 1); // Calculates price for 1 item, in
  5233.         // db is stored for 0 items (strange
  5234.         // but true)
  5235.         /*
  5236.          * if (Overstock > 0) { // more then default -> cheaper TotPrice -=
  5237.          * ((ShopValue / 100) * (1.26875 * Overstock)); } else if (Overstock <
  5238.          * 0) { // less then default -> exspensive TotPrice += ((ShopValue /
  5239.          * 100) * (1.26875 * Overstock)); }
  5240.          */
  5241.         if (ShopHandler.ShopBModifier[MyShopID] == 1) {
  5242.             TotPrice *= 1; // 25% more expensive (general stores only)
  5243.             if (Type == 1) {
  5244.                 TotPrice *= 0.4; // general store buys item at 40% of its own
  5245.                 // selling value
  5246.             }
  5247.         } else if (Type == 1) {
  5248.             TotPrice *= 0.6; // other stores buy item at 60% of their own
  5249.             // selling value
  5250.         }
  5251.         return TotPrice;
  5252.     }
  5253.  
  5254.     public int getItemSlot(int itemID) {
  5255.         for (int slot = 0; slot < playerItems.length; slot++) {
  5256.             if (playerItems[slot] == (itemID + 1)) {
  5257.                 return slot;
  5258.             }
  5259.         }
  5260.         return -1;
  5261.     }
  5262.  
  5263.     public int GetItemSlot(int ItemID) {
  5264.         for (int i = 0; i < playerItems.length; i++) {
  5265.             if ((playerItems[i] - 1) == ItemID) {
  5266.                 return i;
  5267.             }
  5268.         }
  5269.         return -1;
  5270.     }
  5271.  
  5272.     public double GetItemValue(int ItemID) {
  5273.         double ShopValue = 1;
  5274.         double TotPrice = 0;
  5275.  
  5276.         for (int i = 0; i < ItemHandler.MaxListedItems; i++) {
  5277.             if (ItemHandler.ItemList[i] != null) {
  5278.                 if (ItemHandler.ItemList[i].itemId == ItemID) {
  5279.                     ShopValue = ItemHandler.ItemList[i].ShopValue;
  5280.                 }
  5281.             }
  5282.         }
  5283.         TotPrice = (ShopValue * 1); // Calculates price for 1 item, in
  5284.         return TotPrice;
  5285.     }
  5286.  
  5287.     public int getLevelForXP(int exp) {
  5288.         int points = 0;
  5289.         int output = 0;
  5290.         if (exp > 13034430)
  5291.             return 99;
  5292.         for (int lvl = 1; lvl <= 99; lvl++) {
  5293.             points += Math.floor((double) lvl + 300.0
  5294.                     * Math.pow(2.0, (double) lvl / 7.0));
  5295.             output = (int) Math.floor(points / 4);
  5296.             if (output >= exp) {
  5297.                 return lvl;
  5298.             }
  5299.         }
  5300.         return 0;
  5301.     }
  5302.  
  5303.     public int[] getLook() {
  5304.         return new int[] { pGender, pHead, pBeard, pTorso, pArms, pHands,
  5305.                 pLegs, pFeet, pHairC, pTorsoC, pLegsC, pFeetC, pSkinC,
  5306.                 playerLook[0], playerLook[1], playerLook[2], playerLook[3],
  5307.                 playerLook[4], playerLook[5] };
  5308.     }
  5309.  
  5310.     public String getMessageA(int itemID) {
  5311.         switch (itemID) {
  5312.         case 6570:
  5313.             return "You can get another from the Fight";
  5314.         }
  5315.         return "Are you sure you want to destroy this item!";
  5316.     }
  5317.  
  5318.     public String getMessageB(int itemID) {
  5319.         switch (itemID) {
  5320.         case 6570:
  5321.             return "Caves minigame.";
  5322.         }
  5323.         return "";
  5324.     }
  5325.  
  5326.     public int getMove(int i, int j) {
  5327.         if (i - j == 0) {
  5328.             return 0;
  5329.         }
  5330.         if (i - j < 0) {
  5331.             return 1;
  5332.         }
  5333.         return i - j <= 0 ? 0 : -1;
  5334.     }
  5335.  
  5336.     public int GetNPCID(int coordX, int coordY) {
  5337.         for (int i = 0; i < NPCHandler.maxNPCSpawns; i++) {
  5338.             if (Server.npcHandler.npcs[i] != null) {
  5339.                 if ((Server.npcHandler.npcs[i].absX == coordX)
  5340.                         && (Server.npcHandler.npcs[i].absY == coordY)) {
  5341.                     return Server.npcHandler.npcs[i].npcType;
  5342.                 }
  5343.             }
  5344.         }
  5345.         return 1;
  5346.     }
  5347.  
  5348.     public String GetNpcName(int NpcID) {
  5349.         for (int i = 0; i < NPCHandler.maxListedNPCs; i++) {
  5350.             if (Server.npcHandler.NpcList[i] != null) {
  5351.                 if (Server.npcHandler.NpcList[i].npcId == NpcID) {
  5352.                     return Server.npcHandler.NpcList[i].npcName;
  5353.                 }
  5354.             }
  5355.         }
  5356.         return "!! NOT EXISTING NPC !!! - ID:" + NpcID;
  5357.     }
  5358.  
  5359.     public int GetRunAnim(int id) {
  5360.         if (id == 837) {
  5361.             return 2251;
  5362.         }
  5363.         if (id == 4084) {
  5364.             return 1468;
  5365.         }
  5366.         if (id == 4151) // whip
  5367.         {
  5368.             return 1661;
  5369.         }
  5370.         if (id == 6818) {
  5371.             return 1765;
  5372.         }
  5373.         if (id == 7158 || id == 1319 || id == 6609) {
  5374.             return 2563;
  5375.         }
  5376.         if (id == 4734) // karils x bow
  5377.         {
  5378.             return 2077;
  5379.         }
  5380.         if (id == 6528) // maul
  5381.         {
  5382.             return 1664;
  5383.         }
  5384.         if (id == 4153) // maul
  5385.         {
  5386.             return 1664;
  5387.         } else {
  5388.             return 0x338;
  5389.         }
  5390.     }
  5391.  
  5392.     public int GetStandAnim(int id) {
  5393.         if (id == 837) {
  5394.             return 2257;
  5395.         }
  5396.         if (id == 4084) {
  5397.             return 1462;
  5398.         }
  5399.         if (id == 4718) // dharoks axe
  5400.         {
  5401.             return 2065;
  5402.         }
  5403.         if (id == 746 || id == 667 || id == 35 || id == 2402 || id == 8100) {
  5404.             return 2065;
  5405.         }
  5406.         if (id == 7158 || id == 1319 || id == 6609) {
  5407.             return 2561;
  5408.         }
  5409.         if (id == 4755) // veracs flail
  5410.         {
  5411.             return 2061;
  5412.         }
  5413.         if (id == 4734) // karils x bow
  5414.         {
  5415.             return 2074;
  5416.         }
  5417.         if (id == 4153) // maul
  5418.         {
  5419.             return 1662;
  5420.         }
  5421.         if (id == 6528)// Obby Maul
  5422.         {
  5423.             return 0x811;
  5424.         }
  5425.         if (id == 4565) // basket of eggs :)
  5426.         {
  5427.             return 1836;
  5428.         }
  5429.         if (id == 1305 || id == 11962 || id == 11963 || id == 10395
  5430.                 || id == 11964 || id == 11965 || id == 1379 || id == 1381
  5431.                 || id == 1383 || id == 1385 || id == 1387 || id == 1389
  5432.                 || id == 1391 || id == 1393 || id == 1395 || id == 1397
  5433.                 || id == 1399 || id == 1401 || id == 1403 || id == 145
  5434.                 || id == 1407 || id == 1409 || id == 3053 || id == 6914
  5435.                 || id == 3054 || id == 4170 || id == 4675 || id == 4710
  5436.                 || id == 6526 || id == 4726 || id == 6562 || id == 6563
  5437.                 || id == 5730 || id == 3190 || id == 3192 || id == 3194
  5438.                 || id == 3196 || id == 3198 || id == 3200 || id == 3202
  5439.                 || id == 3204 || id == 772) // staves
  5440.         {
  5441.             return 809;
  5442.         } else {
  5443.             return 0x328;
  5444.         }
  5445.     }
  5446.  
  5447.     public void getTotalXP() {
  5448.         if (playerRights >= 2)
  5449.             return;
  5450.         int a1 = getLevelForXP(playerXP[1]);
  5451.         int a2 = getLevelForXP(playerXP[2]);
  5452.         int a3 = getLevelForXP(playerXP[3]);
  5453.         int a4 = getLevelForXP(playerXP[4]);
  5454.         int a5 = getLevelForXP(playerXP[5]);
  5455.         int a6 = getLevelForXP(playerXP[6]);
  5456.         int a7 = getLevelForXP(playerXP[7]);
  5457.         int a8 = getLevelForXP(playerXP[8]);
  5458.         int a9 = getLevelForXP(playerXP[9]);
  5459.         int a10 = getLevelForXP(playerXP[10]);
  5460.         int a11 = getLevelForXP(playerXP[11]);
  5461.         int a12 = getLevelForXP(playerXP[12]);
  5462.         int a13 = getLevelForXP(playerXP[13]);
  5463.         int a14 = getLevelForXP(playerXP[14]);
  5464.         int a15 = getLevelForXP(playerXP[15]);
  5465.         int a16 = getLevelForXP(playerXP[16]);
  5466.         int a17 = getLevelForXP(playerXP[17]);
  5467.         int a18 = getLevelForXP(playerXP[18]);
  5468.         int a19 = getLevelForXP(playerXP[19]);
  5469.         int a20 = getLevelForXP(playerXP[20]);
  5470.         int a21 = getLevelForXP(playerXP[21]);
  5471.         int b1 = getXPForLevel(a1);
  5472.         int b2 = getXPForLevel(a2);
  5473.         int b3 = getXPForLevel(a3);
  5474.         int b4 = getXPForLevel(a4);
  5475.         int b5 = getXPForLevel(a5);
  5476.         int b6 = getXPForLevel(a6);
  5477.         int b7 = getXPForLevel(a7);
  5478.         int b8 = getXPForLevel(a8);
  5479.         int b9 = getXPForLevel(a9);
  5480.         int b10 = getXPForLevel(a10);
  5481.         int b11 = getXPForLevel(a11);
  5482.         int b12 = getXPForLevel(a12);
  5483.         int b13 = getXPForLevel(a13);
  5484.         int b14 = getXPForLevel(a14);
  5485.         int b15 = getXPForLevel(a15);
  5486.         int b16 = getXPForLevel(a16);
  5487.         int b17 = getXPForLevel(a17);
  5488.         int b18 = getXPForLevel(a18);
  5489.         int b19 = getXPForLevel(a19);
  5490.         int b20 = getXPForLevel(a20);
  5491.         int b21 = getXPForLevel(a21);
  5492.  
  5493.         totalXP = b1 + b2 + b3 + b4 + b5 + b6 + b7 + b8 + b9 + b10 + b11 + b12
  5494.                 + b13 + b14 + b15 + b16 + b17 + b18 + b19 + b20 + b21;
  5495.     }
  5496.  
  5497.     public int GetUnnotedItem(int ItemID) {
  5498.         int NewID = 0;
  5499.         String NotedName = "";
  5500.  
  5501.         for (int i = 0; i < ItemHandler.MaxListedItems; i++) {
  5502.             if (ItemHandler.ItemList[i] != null) {
  5503.                 if (ItemHandler.ItemList[i].itemId == ItemID) {
  5504.                     NotedName = ItemHandler.ItemList[i].itemName;
  5505.                 }
  5506.             }
  5507.         }
  5508.         for (int i = 0; i < ItemHandler.MaxListedItems; i++) {
  5509.             if (ItemHandler.ItemList[i] != null) {
  5510.                 if (ItemHandler.ItemList[i].itemName == NotedName) {
  5511.                     if (ItemHandler.ItemList[i].itemDescription
  5512.                             .startsWith("Swap this note at any bank for a") == false) {
  5513.                         NewID = ItemHandler.ItemList[i].itemId;
  5514.                         break;
  5515.                     }
  5516.                 }
  5517.             }
  5518.         }
  5519.         return NewID;
  5520.     }
  5521.  
  5522.     public int GetWalkAnim(int id) {
  5523.         if (id == 837) {
  5524.             return 2258;
  5525.         }
  5526.         if (id == 4084) {
  5527.             return 1468;
  5528.         }
  5529.         if (id == 6528) // dharoks axe
  5530.         {
  5531.             return 2064;
  5532.         }
  5533.         if (id == 746 || id == 667 || id == 35 || id == 2402 || id == 8100) {
  5534.             return 2064;
  5535.         }
  5536.         if (id == 4718) // dharoks axe
  5537.         {
  5538.             return 2064;
  5539.         }
  5540.         if (id == 4039 || id == 4037 || id == 1379 || id == 3204 || id == 1381
  5541.                 || id == 1383 || id == 1385 || id == 1387 || id == 1389
  5542.                 || id == 1391 || id == 1393 || id == 1395 || id == 1397
  5543.                 || id == 1399 || id == 1401 || id == 1403 || id == 145
  5544.                 || id == 1407 || id == 1409 || id == 3053 || id == 3054
  5545.                 || id == 4170 || id == 4675 || id == 4710 || id == 6526
  5546.                 || id == 4726 || id == 6562 || id == 6563 || id == 6914
  5547.                 || id == 5730) // staves + d long and most other weps with str8
  5548.         // up emote
  5549.         {
  5550.             return 1146;
  5551.         }
  5552.         if (id == 7158 || id == 1319 || id == 6609) {
  5553.             return 2562;
  5554.         }
  5555.         if (id == 4565) // basket of eggs :)
  5556.         {
  5557.             return 1836;
  5558.         }
  5559.         if (id == 4755) // veracs flail
  5560.         {
  5561.             return 2060;
  5562.         }
  5563.         if (id == 4734) // karils x bow
  5564.         {
  5565.             return 2076;
  5566.         }
  5567.         if (id == 4153) // maul
  5568.         {
  5569.             return 1663;
  5570.         }
  5571.         if (id == 4718) // 2h + gr8 axe
  5572.         {
  5573.             return 1662;
  5574.         }
  5575.         if (id == 4151) // whip
  5576.         {
  5577.             return 1660;
  5578.         } else {
  5579.             return 0x333;
  5580.         }
  5581.     }
  5582.  
  5583.     public int GetWepAnim(int id) {
  5584.         if (id == -1) // unarmed
  5585.         {
  5586.             return 422;
  5587.         }
  5588.         if (id == 837) {
  5589.             return 1084;
  5590.         }
  5591.         if (id == 3190 || id == 3192 || id == 3194 || id == 3196 || id == 3198
  5592.                 || id == 3200 || id == 3202 || id == 3204) // halberds
  5593.         {
  5594.             return 440;
  5595.         }
  5596.         if (id == 4170 || id == 4675) {
  5597.             return 414;
  5598.         }
  5599.         if (id == 4151) // whip
  5600.         {
  5601.             return 1658;
  5602.         }
  5603.         if (id == 6528) {
  5604.             return 2661;
  5605.         }
  5606.         if (id == 4827) {
  5607.             return 426;
  5608.         }
  5609.         if (id == 6522) {
  5610.             return 3353;
  5611.         }
  5612.         if ((id == 1291 || id == 1321 || id == 1323 || id == 1325 || id == 1327
  5613.                 || id == 1329 || id == 6611 || id == 1327 || id == 1321
  5614.                 || id == 1333 || id == 1305 || id == 6739 || id == 4587)
  5615.                 && FightType != 3) // scimitars
  5616.         {
  5617.             return 451;
  5618.         }
  5619.         if ((id == 1291 || id == 1321 || id == 1323 || id == 1325 || id == 1327
  5620.                 || id == 1329 || id == 6611 || id == 1327 || id == 1321
  5621.                 || id == 1333 || id == 1305 || id == 6739 || id == 4587)
  5622.                 && FightType == 3) // scimitars
  5623.         {
  5624.             return 412;
  5625.         }
  5626.         if (id == 841 || id == 843 || id == 845 || id == 849 || id == 847
  5627.                 || id == 853 || id == 851 || hasCrystalBow() || id == 859
  5628.                 || id == 861) {
  5629.             return 426;
  5630.         }
  5631.         if (id == 837) {
  5632.             return 427;
  5633.         }
  5634.         if (id == 746 || id == 667 || id == 35 || id == 2402 || id == 8100) {
  5635.             return 3496;
  5636.         }
  5637.         if (id == 4153) // maul
  5638.         {
  5639.             return 1665;
  5640.         }
  5641.         if (id == 1377) // dragon b axe
  5642.         {
  5643.             return 1833;
  5644.         }
  5645.         if (id == 4718 && FightType != 3) // dharoks axe
  5646.         {
  5647.             return 2067;
  5648.         }
  5649.         if (id == 4718 && FightType == 3) // dharoks axe
  5650.         {
  5651.             return 2066;
  5652.         }
  5653.         if (id == 4726) // guthans spear
  5654.         {
  5655.             return 2080;
  5656.         }
  5657.         if (id == 4747) // torags hammers
  5658.         {
  5659.             return 2068;
  5660.         }
  5661.         if (id == 4755) // veracs flail
  5662.         {
  5663.             return 2062;
  5664.         }
  5665.         if (id == 4734) // karils x bow
  5666.         {
  5667.             return 2075;
  5668.         }
  5669.         if ((id == 1215 || id == 1231 || id == 5680 || id == 5698)
  5670.                 && FightType != 3) // dragon daggers
  5671.         {
  5672.             return 402;
  5673.         }
  5674.         if ((id == 1215 || id == 1231 || id == 5680 || id == 5698)
  5675.                 && FightType == 3) // dragon daggers
  5676.         {
  5677.             return 395;
  5678.         }
  5679.         if (id == 6609 || id == 1307 || id == 1309 || id == 1311 || id == 1313
  5680.                 || id == 1315 || id == 1317 || id == 1319 || id == 7158)
  5681.         // 2 handers
  5682.         {
  5683.             return 407;
  5684.         } else {
  5685.             return 451;
  5686.         }
  5687.     }
  5688.  
  5689.     public int GetWorld(int PlayerID) {
  5690.         String Server = PlayerHandler.players[PlayerID].playerServer;
  5691.  
  5692.         if (Server.equals("deltascape.no-ip.info")
  5693.                 || Server.equals("localhost")) {
  5694.             return 1;
  5695.         } else if (Server.equals("deltascape.servequake.com")) {
  5696.             return 2;
  5697.         } else {
  5698.             println_debug("Invalid Server: " + Server);
  5699.             return 1;
  5700.         }
  5701.     }
  5702.  
  5703.     public int GetXItemsInBag(int ItemID) {
  5704.         int ItemCount = 0;
  5705.  
  5706.         for (int element : playerItems) {
  5707.             if ((element - 1) == ItemID) {
  5708.                 ItemCount++;
  5709.             }
  5710.         }
  5711.         return ItemCount;
  5712.     }
  5713.  
  5714.     public int getXPForLevel(int level) {
  5715.         int points = 0;
  5716.         int output = 0;
  5717.  
  5718.         for (int lvl = 1; lvl <= level; lvl++) {
  5719.             points += Math.floor((double) lvl + 300.0
  5720.                     * Math.pow(2.0, (double) lvl / 7.0));
  5721.             if (lvl >= level) {
  5722.                 return output;
  5723.             }
  5724.             output = (int) Math.floor(points / 4);
  5725.         }
  5726.         return 0;
  5727.     }
  5728.  
  5729.     public void giveItems() {
  5730.         Client o = (Client) PlayerHandler.players[trade_reqId];
  5731.         if (o == null) {
  5732.             return;
  5733.         }
  5734.         try {
  5735.             for (GameItem item : o.offeredItems) {
  5736.                 if (item.id > 0) {
  5737.                     addItem(item.id, item.amount);
  5738.                 }
  5739.             }
  5740.             disconnectedDelay = 20;
  5741.             RemoveAllWindows();
  5742.             tradeResetNeeded = true;
  5743.         } catch (Exception e) {
  5744.         }
  5745.     }
  5746.  
  5747.     public boolean GoodDistance(int objectX, int objectY, int playerX,
  5748.             int playerY, int distance) {
  5749.         for (int i = 0; i <= distance; i++) {
  5750.             for (int j = 0; j <= distance; j++) {
  5751.                 if (((objectX + i) == playerX)
  5752.                         && (((objectY + j) == playerY)
  5753.                                 || ((objectY - j) == playerY) || (objectY == playerY))) {
  5754.                     return true;
  5755.                 } else if (((objectX - i) == playerX)
  5756.                         && (((objectY + j) == playerY)
  5757.                                 || ((objectY - j) == playerY) || (objectY == playerY))) {
  5758.                     return true;
  5759.                 } else if ((objectX == playerX)
  5760.                         && (((objectY + j) == playerY)
  5761.                                 || ((objectY - j) == playerY) || (objectY == playerY))) {
  5762.                     return true;
  5763.                 }
  5764.             }
  5765.         }
  5766.         return false;
  5767.     }
  5768.  
  5769.     public boolean GoodDistance2(int objectX, int objectY, int playerX,
  5770.             int playerY, int distance) {
  5771.         for (int i = 0; i <= distance; i++) {
  5772.             for (int j = 0; j <= distance; j++) {
  5773.                 if ((objectX == playerX)
  5774.                         && (((objectY + j) == playerY)
  5775.                                 || ((objectY - j) == playerY) || (objectY == playerY))) {
  5776.                     return true;
  5777.                 } else if ((objectY == playerY)
  5778.                         && (((objectX + j) == playerX)
  5779.                                 || ((objectX - j) == playerX) || (objectX == playerX))) {
  5780.                     return true;
  5781.                 }
  5782.             }
  5783.         }
  5784.         return false;
  5785.     }
  5786.  
  5787.     public boolean hasCrystalBow() {
  5788.         if (playerEquipment[playerWeapon] == 4214
  5789.                 || playerEquipment[playerWeapon] == 4215
  5790.                 || playerEquipment[playerWeapon] == 4216
  5791.                 || playerEquipment[playerWeapon] == 4217
  5792.                 || playerEquipment[playerWeapon] == 4218
  5793.                 || playerEquipment[playerWeapon] == 4219
  5794.                 || playerEquipment[playerWeapon] == 4220
  5795.                 || playerEquipment[playerWeapon] == 4221
  5796.                 || playerEquipment[playerWeapon] == 4222
  5797.                 || playerEquipment[playerWeapon] == 4223) {
  5798.             return true;
  5799.         }
  5800.         return false;
  5801.     }
  5802.  
  5803.     public boolean hasCrystalShield() {
  5804.         if (playerEquipment[playerShield] == 4224
  5805.                 || playerEquipment[playerShield] == 4225
  5806.                 || playerEquipment[playerShield] == 4226
  5807.                 || playerEquipment[playerShield] == 4227
  5808.                 || playerEquipment[playerShield] == 4228
  5809.                 || playerEquipment[playerShield] == 4229
  5810.                 || playerEquipment[playerShield] == 4230
  5811.                 || playerEquipment[playerShield] == 4231
  5812.                 || playerEquipment[playerShield] == 4232
  5813.                 || playerEquipment[playerShield] == 4234
  5814.                 || playerEquipment[playerShield] == 4234) {
  5815.             return true;
  5816.         }
  5817.         return false;
  5818.     }
  5819.  
  5820.     public boolean HasItemAmount(int itemID, int itemAmount) {
  5821.         int playerItemAmountCount = 0;
  5822.         for (int i = 0; i < playerItems.length; i++) {
  5823.             if (playerItems[i] == itemID + 1) {
  5824.                 playerItemAmountCount = playerItemsN[i];
  5825.             }
  5826.             if (playerItemAmountCount >= itemAmount) {
  5827.                 return true;
  5828.             }
  5829.         }
  5830.         return false;
  5831.     }
  5832.  
  5833.     public boolean hasKnife() {
  5834.         int a = playerEquipment[playerWeapon];
  5835.         if (a == 863 || a == 864 || a == 865 || a == 866 || a == 867
  5836.                 || a == 868 || a == 869) {
  5837.             return true;
  5838.         }
  5839.         return false;
  5840.     }
  5841.  
  5842.     public void healAll() {
  5843.         for (Player p : PlayerHandler.players) {// loop so it effects all
  5844.             // players
  5845.             Client person = (Client) p;
  5846.             if (p != null && person.distanceToPoint(absX, absY) <= 1) {
  5847.                 Client castOn = (Client) p;// specific player's Client
  5848.                 castOn.currentHealth += 5;
  5849.                 if (castOn.currentHealth > castOn.playerLevel[castOn.playerHitpoints])
  5850.                     castOn.currentHealth = castOn.playerLevel[castOn.playerHitpoints];
  5851.                 castOn.sendQuest("" + castOn.currentHealth + "", 4016);
  5852.                 castOn.sM("You have been healed by " + playerName + ".");
  5853.                 setAnimation(1670);
  5854.                 lowGFX(568, 0);
  5855.             }
  5856.         }
  5857.     }
  5858.  
  5859.     public void ifFreeze(int delay2) {
  5860.         if (EntangleDelay == 0) {
  5861.             EntangleDelay = delay2;
  5862.             sM("You have been frozen!");
  5863.             toX = absX;
  5864.             toY = absY;
  5865.             newWalkCmdSteps = 0;
  5866.             newWalkCmdX[0] = newWalkCmdY[0] = tmpNWCX[0] = tmpNWCY[0] = 0;
  5867.             getNextPlayerMovement();
  5868.         }
  5869.     }
  5870.  
  5871.     // upon connection of a new Client all the info has to be sent to Client
  5872.     // prior to starting the regular communication
  5873.     public void initialize() {
  5874.         // first packet sent
  5875.         Server.setConfig.initializeClientConfiguration(playerId);
  5876.         if (splitChat == 1) {
  5877.             setClientConfig(287, 1);
  5878.         }
  5879.         if (autoRetaliate == 0) {
  5880.             setClientConfig(172, 1);
  5881.         }
  5882.         setClientConfig(43, FightType - 1);
  5883.         setClientConfig(166, brightness);
  5884.         outStream.createFrame(249);
  5885.         outStream.writeByteA(playerIsMember); // 1 for members, zero for free
  5886.         outStream.writeWordBigEndianA(playerId);
  5887.         // here is the place for seting up the UI, stats, etc...
  5888.         setChatOptions(0, 0, 0);
  5889.         for (int i = 0; i < 25; i++) {
  5890.             setSkillLevel(i, playerLevel[i], playerXP[i]);
  5891.         }
  5892.         refreshSkills();
  5893.  
  5894.         outStream.createFrame(107); // resets something in the Client
  5895.  
  5896.         setSidebarInterface(0, 2423); // attack tab
  5897.         setSidebarInterface(1, 3917); // skills tab
  5898.         setSidebarInterface(2, 638); // quest tab
  5899.         setSidebarInterface(3, 3213); // backpack tab
  5900.         setSidebarInterface(4, 1644); // items wearing tab
  5901.         setSidebarInterface(5, 5608); // pray tab
  5902.         if (playerAncientMagics == 0) {
  5903.             setSidebarInterface(6, 1151);
  5904.             playerAncientMagics = 0;
  5905.         }
  5906.         if (playerAncientMagics == 1) {
  5907.             setSidebarInterface(6, 12855);
  5908.             playerAncientMagics = 1;
  5909.         }
  5910.         setSidebarInterface(7, -1); // clan chat
  5911.         setSidebarInterface(8, 5065); // friend
  5912.         setSidebarInterface(9, 5715); // ignore
  5913.         setSidebarInterface(10, 2449); // logout tab
  5914.         setSidebarInterface(11, 4445); // wrench tab
  5915.         setSidebarInterface(12, 147); // run tab
  5916.         setSidebarInterface(13, -1); // harp tab
  5917.         // add player commands...
  5918.         outStream.createFrameVarSize(104);
  5919.         outStream.writeByteC(3); // command slot (does it matter which one?)
  5920.         outStream.writeByteA(1); // 0 or 1; 1 if command should be placed on top
  5921.         // in context menu
  5922.         outStream.writeString("Attack");
  5923.         outStream.endFrameVarSize();
  5924.  
  5925.         outStream.createFrameVarSize(104);
  5926.         outStream.writeByteC(4); // command slot (does it matter which one?)
  5927.         outStream.writeByteA(0); // 0 or 1; 0 if command should be placed on top
  5928.         // in context menu
  5929.         outStream.writeString("Follow");
  5930.         outStream.endFrameVarSize();
  5931.  
  5932.         outStream.createFrameVarSize(104);
  5933.         outStream.writeByteC(5); // command slot (does it matter which one?)
  5934.         outStream.writeByteA(0); // 0 or 1; 0 if command should be placed on top
  5935.         // in context menu
  5936.         outStream.writeString("Trade with");
  5937.         outStream.endFrameVarSize();
  5938.  
  5939.         int dots = 0;
  5940.         int start[] = { 0, 0, 0, 0 };
  5941.  
  5942.         if (playerLastConnect.length() < 7) {
  5943.             playerLastConnect = connectedFrom;
  5944.         }
  5945.         if (playerLastConnect.length() <= 15) {
  5946.             for (int j = 0; j <= playerLastConnect.length(); j++) {
  5947.                 if ((j + 1) <= playerLastConnect.length()) {
  5948.                     if (playerLastConnect.substring(j, (j + 1)).equals(".")) {
  5949.                         start[dots] = j;
  5950.                         dots++;
  5951.                     }
  5952.                     if (dots == 3) {
  5953.                         break;
  5954.                     }
  5955.                 }
  5956.             }
  5957.             if (dots == 3) {
  5958.                 ipPart1 = Integer.parseInt(playerLastConnect.substring(0,
  5959.                         start[0]));
  5960.                 ipPart2 = Integer.parseInt(playerLastConnect.substring(
  5961.                         (start[0] + 1), start[1]));
  5962.                 ipPart3 = Integer.parseInt(playerLastConnect.substring(
  5963.                         (start[1] + 1), start[2]));
  5964.                 ipPart4 = Integer.parseInt(playerLastConnect
  5965.                         .substring((start[2] + 1)));
  5966.             }
  5967.         } else {
  5968.             for (int j = 0; j <= playerLastConnect.length(); j++) {
  5969.                 if ((j + 1) <= playerLastConnect.length()) {
  5970.                     if (playerLastConnect.substring(j, (j + 1)).equals("-")) {
  5971.                         start[dots] = j;
  5972.                         dots++;
  5973.                     }
  5974.                     if (dots == 4) {
  5975.                         break;
  5976.                     }
  5977.                 }
  5978.             }
  5979.             if (dots == 4) {
  5980.                 try {
  5981.                     ipPart1 = Integer.parseInt(playerLastConnect.substring(0,
  5982.                             start[0]));
  5983.                     ipPart2 = Integer.parseInt(playerLastConnect.substring(
  5984.                             (start[0] + 1), start[1]));
  5985.                     ipPart3 = Integer.parseInt(playerLastConnect.substring(
  5986.                             (start[1] + 1), start[2]));
  5987.                     ipPart4 = Integer.parseInt(playerLastConnect.substring(
  5988.                             (start[2] + 1), (start[3])));
  5989.                 } catch (NumberFormatException e) {
  5990.                 }
  5991.             }
  5992.         }
  5993.         WriteEnergy();
  5994.         wildySign();
  5995.         specAttack();
  5996.         l33thax(12323);
  5997.         l33thax(7574);
  5998.         l33thax(7599);
  5999.         l33thax(7549);
  6000.         l33thax(8493);
  6001.         l33thax(7499);
  6002.  
  6003.         sM("Welcome to Deltascape.");
  6004.         checkDupe();
  6005.  
  6006.         Server.special.loginSpec(this, playerEquipment[playerWeapon]);
  6007.         if (absX >= 2997 && absX <= 2998 && absY >= 3917 && absY <= 3917) {
  6008.             toX = 2998;
  6009.             toY = 3931;
  6010.         }
  6011.  
  6012.         sendFrame126("Prayer: " + playerLevel[5] + "/"
  6013.                 + getLevelForXP(playerXP[5]) + "", 687);
  6014.         if (checkLog("mutes", playerName)) {
  6015.  
  6016.             muted = true;
  6017.             sM("You Have been muted by a moderator and will be unmuted in a while.");
  6018.         }
  6019.         if (checkLog("mutes2", connectedFrom)) {
  6020.             muted = true;
  6021.             sM("You are IP muted.");
  6022.         }
  6023.         if (starter == 0) { // Starter kit starts here!
  6024.             starter = 1;
  6025.             showInterface(3559);
  6026.             apset = true;
  6027.             addItem(554, 100); // Water Runes
  6028.         }
  6029.         if (specialAmount < 100) {
  6030.             moreSpec();
  6031.         }
  6032.  
  6033.         for (int a = 0; a < lastMessage.length; a++) {
  6034.             lastMessage[a] = "";
  6035.         }
  6036.         if (playerMessages > 0)
  6037.             sM("You have "
  6038.                     + playerMessages
  6039.                     + " new messages.  Check your inbox at Devolution.com to view them.");
  6040.         // FACE: 0= WEST | -1 = NORTH | -2 = EAST | -3 = SOUTH
  6041.         if (lookNeeded) {
  6042.             showInterface(3559);
  6043.         } else
  6044.             sendFrame126("" + playerLevel[0] + "", 4004);
  6045.         sendFrame126("" + getLevelForXP(playerXP[0]) + "", 4005);
  6046.         sendFrame126("" + playerLevel[1] + "", 4008);
  6047.         sendFrame126("" + getLevelForXP(playerXP[1]) + "", 4009);
  6048.         sendFrame126("" + playerLevel[2] + "", 4006);
  6049.         sendFrame126("" + getLevelForXP(playerXP[2]) + "", 4007);
  6050.         sendFrame126("" + playerLevel[3] + "", 4016);
  6051.         sendFrame126("" + getLevelForXP(playerXP[3]) + "", 4017);
  6052.         sendFrame126("" + playerLevel[4] + "", 4010);
  6053.         sendFrame126("" + getLevelForXP(playerXP[4]) + "", 4011);
  6054.         sendFrame126("" + playerLevel[5] + "", 4012);
  6055.         sendFrame126("" + getLevelForXP(playerXP[5]) + "", 4013);
  6056.         sendFrame126("" + playerLevel[6] + "", 4014);
  6057.         sendFrame126("" + getLevelForXP(playerXP[6]) + "", 4015);
  6058.         sendFrame126("" + playerLevel[7] + "", 4034);
  6059.         sendFrame126("" + getLevelForXP(playerXP[7]) + "", 4035);
  6060.         sendFrame126("" + playerLevel[8] + "", 4038);
  6061.         sendFrame126("" + getLevelForXP(playerXP[8]) + "", 4039);
  6062.         sendFrame126("" + playerLevel[9] + "", 4026);
  6063.         sendFrame126("" + getLevelForXP(playerXP[9]) + "", 4027);
  6064.         sendFrame126("" + playerLevel[10] + "", 4032);
  6065.         sendFrame126("" + getLevelForXP(playerXP[10]) + "", 4033);
  6066.         sendFrame126("" + playerLevel[11] + "", 4036);
  6067.         sendFrame126("" + getLevelForXP(playerXP[11]) + "", 4037);
  6068.         sendFrame126("" + playerLevel[12] + "", 4024);
  6069.         sendFrame126("" + getLevelForXP(playerXP[12]) + "", 4025);
  6070.         sendFrame126("" + playerLevel[13] + "", 4030);
  6071.         sendFrame126("" + getLevelForXP(playerXP[13]) + "", 4031);
  6072.         sendFrame126("" + playerLevel[14] + "", 4028);
  6073.         sendFrame126("" + getLevelForXP(playerXP[14]) + "", 4029);
  6074.         sendFrame126("" + playerLevel[15] + "", 4020);
  6075.         sendFrame126("" + getLevelForXP(playerXP[15]) + "", 4021);
  6076.         sendFrame126("" + playerLevel[16], 4018);
  6077.         sendFrame126("" + getLevelForXP(playerXP[16]), 4019);
  6078.         sendFrame126("" + playerLevel[17], 4022);
  6079.         sendFrame126("" + getLevelForXP(playerXP[17]), 4023);
  6080.         sendFrame126("" + playerLevel[20], 4152);
  6081.         sendFrame126("" + getLevelForXP(playerXP[20]), 4153);
  6082.         if (playerPass.equals("")) {
  6083.             sM("No password set! Use ::pass PASSWORD to set ur password.");
  6084.         }
  6085.  
  6086.         sendFrame126("", 6067);
  6087.         sendFrame126("", 6071);
  6088.         SendWeapon(-1, "Unarmed");
  6089.  
  6090.         PlayerHandler.updatePlayer(this, outStream);
  6091.         Server.playerHandler.updateNPC(this, outStream);
  6092.         setEquipment(playerEquipment[playerHat], playerEquipmentN[playerHat],
  6093.                 playerHat);
  6094.         setEquipment(playerEquipment[playerCape], playerEquipmentN[playerCape],
  6095.                 playerCape);
  6096.         setEquipment(playerEquipment[playerAmulet],
  6097.                 playerEquipmentN[playerAmulet], playerAmulet);
  6098.         setEquipment(playerEquipment[playerArrows],
  6099.                 playerEquipmentN[playerArrows], playerArrows);
  6100.         setEquipment(playerEquipment[playerChest],
  6101.                 playerEquipmentN[playerChest], playerChest);
  6102.         setEquipment(playerEquipment[playerShield],
  6103.                 playerEquipmentN[playerShield], playerShield);
  6104.         setEquipment(playerEquipment[playerLegs], playerEquipmentN[playerLegs],
  6105.                 playerLegs);
  6106.         setEquipment(playerEquipment[playerHands],
  6107.                 playerEquipmentN[playerHands], playerHands);
  6108.         setEquipment(playerEquipment[playerFeet], playerEquipmentN[playerFeet],
  6109.                 playerFeet);
  6110.         setEquipment(playerEquipment[playerRing], playerEquipmentN[playerRing],
  6111.                 playerRing);
  6112.         setEquipment(playerEquipment[playerWeapon],
  6113.                 playerEquipmentN[playerWeapon], playerWeapon);
  6114.         resetItems(3214);
  6115.         resetBank();
  6116.  
  6117.         ResetBonus();
  6118.         GetBonus();
  6119.         WriteBonus();
  6120.         replaceDoors();
  6121.  
  6122.         pmstatus(2);
  6123.         boolean pmloaded = false;
  6124.  
  6125.         for (long element : friends) {
  6126.             if (element != 0) {
  6127.                 for (int i2 = 1; i2 < PlayerHandler.maxPlayers; i2++) {
  6128.                     if ((PlayerHandler.players[i2] != null)
  6129.                             && PlayerHandler.players[i2].isActive
  6130.                             && (Misc
  6131.                                     .playerNameToInt64(PlayerHandler.players[i2].playerName) == element)) {
  6132.                         if ((playerRights >= 2)
  6133.                                 || (PlayerHandler.players[i2].Privatechat == 0)
  6134.                                 || ((PlayerHandler.players[i2].Privatechat == 1) && PlayerHandler.players[i2]
  6135.                                         .isinpm(Misc
  6136.                                                 .playerNameToInt64(playerName)))) {
  6137.                             loadpm(element, GetWorld(i2));
  6138.                             pmloaded = true;
  6139.                         }
  6140.                         break;
  6141.                     }
  6142.                 }
  6143.                 if (!pmloaded) {
  6144.                     loadpm(element, 0);
  6145.                 }
  6146.                 pmloaded = false;
  6147.             }
  6148.         }
  6149.         for (int i1 = 1; i1 < PlayerHandler.maxPlayers; i1++) {
  6150.             if ((PlayerHandler.players[i1] != null)
  6151.                     && (PlayerHandler.players[i1].isActive == true)) {
  6152.                 PlayerHandler.players[i1]
  6153.                         .pmupdate(playerId, GetWorld(playerId));
  6154.             }
  6155.         }
  6156.         Server.textHandler.startText(playerId);
  6157.         // main
  6158.         setInterfaceWalkable(6673);
  6159.         playerLastConnect = connectedFrom;
  6160.         updateRequired = true;
  6161.         appearanceUpdateRequired = true;
  6162.     }
  6163.  
  6164.     public boolean inRange(int x, int y) {
  6165.         if (localId > 0)
  6166.             return false;
  6167.         if ((Math.abs(absX - x) < 4) && (Math.abs(absY - y) < 4)) {
  6168.             return true;
  6169.         }
  6170.         return false;
  6171.     }
  6172.  
  6173.     public boolean isinpm(long l) {
  6174.         for (long element : friends) {
  6175.             if (element != 0) {
  6176.                 if (l == element) {
  6177.                     return true;
  6178.                 }
  6179.             }
  6180.         }
  6181.         return false;
  6182.     }
  6183.  
  6184.     public boolean isInWilderness(int coordX, int coordY, int Type) {
  6185.         if (Type == 1) {
  6186.             if ((coordY >= 3523) && (coordY <= 3967) && (coordX <= 3392)
  6187.                     && (coordX >= 2942) || absX >= 3220 && absX <= 3299
  6188.                     && absY >= 3520 && absY <= 3548 || absX >= 2250
  6189.                     && absX <= 2296 && absY >= 4676 && absY <= 4715) {
  6190.                 return true;
  6191.             }
  6192.         } else if (Type == 2) {
  6193.             if ((coordY >= 3512) && (coordY <= 3967) && (coordX <= 3392)
  6194.                     && (coordX >= 2942)) {
  6195.                 return true;
  6196.             }
  6197.         }
  6198.         return false;
  6199.     }
  6200.  
  6201.     public boolean IsItemInBag(int ItemID) {
  6202.         for (int element : playerItems) {
  6203.             if ((element - 1) == ItemID) {
  6204.                 return true;
  6205.             }
  6206.         }
  6207.         return false;
  6208.     }
  6209.  
  6210.     public int itemAmount(int itemID) {
  6211.         int tempAmount = 0;
  6212.  
  6213.         for (int i = 0; i < playerItems.length; i++) {
  6214.             if (playerItems[i] == itemID) {
  6215.                 tempAmount += playerItemsN[i];
  6216.             }
  6217.         }
  6218.         return tempAmount;
  6219.     }
  6220.  
  6221.     public int itemType(int item) {
  6222.         for (int element : Item.capes) {
  6223.             if (item == element) {
  6224.                 return playerCape;
  6225.             }
  6226.         }
  6227.         for (int element : Item.hats) {
  6228.             if (item == element) {
  6229.                 return playerHat;
  6230.             }
  6231.         }
  6232.         for (int element : Item.boots) {
  6233.             if (item == element) {
  6234.                 return playerFeet;
  6235.             }
  6236.         }
  6237.         for (int element : Item.gloves) {
  6238.             if (item == element) {
  6239.                 return playerHands;
  6240.             }
  6241.         }
  6242.         for (int element : Item.shields) {
  6243.             if (item == element) {
  6244.                 return playerShield;
  6245.             }
  6246.         }
  6247.         for (int element : Item.amulets) {
  6248.             if (item == element) {
  6249.                 return playerAmulet;
  6250.             }
  6251.         }
  6252.         for (int element : Item.arrows) {
  6253.             if (item == element) {
  6254.                 return playerArrows;
  6255.             }
  6256.         }
  6257.         for (int element : Item.rings) {
  6258.             if (item == element) {
  6259.                 return playerRing;
  6260.             }
  6261.         }
  6262.         for (int element : Item.body) {
  6263.             if (item == element) {
  6264.                 return playerChest;
  6265.             }
  6266.         }
  6267.         for (int element : Item.legs) {
  6268.             if (item == element) {
  6269.                 return playerLegs;
  6270.             }
  6271.         }
  6272.  
  6273.         // Default
  6274.         return playerWeapon;
  6275.     }
  6276.  
  6277.     public void keepItem1() {
  6278.         int highest = 0;
  6279.         for (int i = 0; i < playerItems.length; i++) {
  6280.             int value = (int) Math.floor(GetItemValue(playerItems[i] - 1));
  6281.             if (value > highest && playerItems[i] - 1 != -1) {
  6282.                 highest = value;
  6283.                 itemKept1 = playerItems[i] - 1;
  6284.                 itemKept1Slot = i;
  6285.                 itemSlot1 = true;
  6286.             }
  6287.         }
  6288.         for (int i = 0; i < playerEquipment.length; i++) {
  6289.             int value = (int) Math.floor(GetItemValue(playerEquipment[i]));
  6290.             if (value > highest && playerEquipment[i] != -1) {
  6291.                 highest = value;
  6292.                 itemKept1 = playerEquipment[i];
  6293.                 itemKept1Slot = i;
  6294.                 itemSlot1 = false;
  6295.             }
  6296.         }
  6297.     }
  6298.  
  6299.     public void keepItem2() {
  6300.         int highest = 0;
  6301.         for (int i = 0; i < playerItems.length; i++) {
  6302.             if (itemKept1Slot != i) {
  6303.                 int value = (int) Math.floor(GetItemValue(playerItems[i] - 1));
  6304.                 if (value > highest && playerItems[i] - 1 != -1) {
  6305.                     highest = value;
  6306.                     itemKept2 = playerItems[i] - 1;
  6307.                     itemKept2Slot = i;
  6308.                     itemSlot2 = true;
  6309.                 }
  6310.             }
  6311.         }
  6312.         for (int i = 0; i < playerEquipment.length; i++) {
  6313.             if (itemKept1Slot != i) {
  6314.                 int value = (int) Math.floor(GetItemValue(playerEquipment[i]));
  6315.                 if (value > highest && playerEquipment[i] != -1) {
  6316.                     highest = value;
  6317.                     itemKept2 = playerEquipment[i];
  6318.                     itemKept2Slot = i;
  6319.                     itemSlot2 = false;
  6320.                 }
  6321.             }
  6322.         }
  6323.     }
  6324.  
  6325.     public void keepItem3() {
  6326.         int highest = 0;
  6327.         for (int i = 0; i < playerItems.length; i++) {
  6328.             if (itemKept1Slot != i && itemKept2Slot != i) {
  6329.                 int value = (int) Math.floor(GetItemValue(playerItems[i] - 1));
  6330.                 if (value > highest && playerItems[i] - 1 != -1) {
  6331.                     highest = value;
  6332.                     itemKept3 = playerItems[i] - 1;
  6333.                     itemKept3Slot = i;
  6334.                     itemSlot3 = true;
  6335.                 }
  6336.             }
  6337.         }
  6338.         for (int i = 0; i < playerEquipment.length; i++) {
  6339.             if (itemKept1Slot != i && itemKept2Slot != i) {
  6340.                 int value = (int) Math.floor(GetItemValue(playerEquipment[i]));
  6341.                 if (value > highest && playerEquipment[i] != -1) {
  6342.                     highest = value;
  6343.                     itemKept3 = playerEquipment[i];
  6344.                     itemKept3Slot = i;
  6345.                     itemSlot3 = false;
  6346.                 }
  6347.             }
  6348.         }
  6349.     }
  6350.  
  6351.     public void keepItem4() {
  6352.         int highest = 0;
  6353.         for (int i = 0; i < playerItems.length; i++) {
  6354.             if (itemKept1Slot != i && itemKept2Slot != i && itemKept3Slot != i) {
  6355.                 int value = (int) Math.floor(GetItemValue(playerItems[i] - 1));
  6356.                 if (value > highest && playerItems[i] - 1 != -1) {
  6357.                     highest = value;
  6358.                     itemKept4 = playerItems[i] - 1;
  6359.                     itemKept4Slot = i;
  6360.                     itemSlot4 = true;
  6361.                 }
  6362.             }
  6363.         }
  6364.         for (int i = 0; i < playerEquipment.length; i++) {
  6365.             if (itemKept1Slot != i && itemKept2Slot != i && itemKept3Slot != i) {
  6366.                 int value = (int) Math.floor(GetItemValue(playerEquipment[i]));
  6367.                 if (value > highest && playerEquipment[i] != -1) {
  6368.                     highest = value;
  6369.                     itemKept4 = playerEquipment[i];
  6370.                     itemKept4Slot = i;
  6371.                     itemSlot4 = false;
  6372.                 }
  6373.             }
  6374.         }
  6375.     }
  6376.  
  6377.     public void keepItemHandle() {
  6378.         keepItem1();
  6379.         keepItem2();
  6380.         keepItem3();
  6381.         if (itemKept1 > 0) {
  6382.             if (itemSlot1)
  6383.                 deleteItem(itemKept1, itemKept1Slot, 1);
  6384.             else if (!itemSlot1)
  6385.                 deleteequiment(itemKept1, itemKept1Slot);
  6386.         }
  6387.         if (itemKept2 > 0) {
  6388.             if (itemSlot2)
  6389.                 deleteItem(itemKept2, itemKept2Slot, 1);
  6390.             else if (!itemSlot2)
  6391.                 deleteequiment(itemKept2, itemKept2Slot);
  6392.         }
  6393.         if (itemKept3 > 0) {
  6394.             if (itemSlot3)
  6395.                 deleteItem(itemKept3, itemKept3Slot, 1);
  6396.             else if (!itemSlot3)
  6397.                 deleteequiment(itemKept3, itemKept3Slot);
  6398.         }
  6399.     }
  6400.  
  6401.     public void l33thax(int id) {
  6402.         outStream.createFrame(171);
  6403.         outStream.writeByte(0);
  6404.         outStream.writeWord(id);
  6405.         flushOutStream();
  6406.     }
  6407.  
  6408.     public int loadgame(String playerName, String playerPass) {
  6409.         for (Integer bUid : Server.bannedUid) {
  6410.             if (uid == bUid.intValue()) {
  6411.                 return 4;
  6412.             }
  6413.         }
  6414.  
  6415.         long start = System.currentTimeMillis();
  6416.         String line = "";
  6417.         String token = "";
  6418.         String token2 = "";
  6419.         String[] token3 = new String[3];
  6420.         boolean EndOfFile = false;
  6421.         int ReadMode = 0;
  6422.         BufferedReader characterfile = null;
  6423.         boolean charFileFound = false;
  6424.         int[] playerLooks = new int[19];
  6425.  
  6426.         try {
  6427.             characterfile = new BufferedReader(new FileReader("./CharData/"
  6428.                     + playerName + ".txt"));
  6429.             charFileFound = true;
  6430.         } catch (FileNotFoundException fileex1) {
  6431.         }
  6432.         if (charFileFound == false) {
  6433.             Misc.println(playerName + ": character file not found.");
  6434.             return 0;
  6435.         }
  6436.  
  6437.         try {
  6438.             line = characterfile.readLine();
  6439.         } catch (IOException ioexception) {
  6440.             Misc.println(playerName + ": error loading file.");
  6441.             return 3;
  6442.         }
  6443.         while ((EndOfFile == false) && (line != null)) {
  6444.             line = line.trim();
  6445.             int spot = line.indexOf("=");
  6446.             if (spot > -1) {
  6447.                 token = line.substring(0, spot);
  6448.                 token = token.trim();
  6449.                 token2 = line.substring(spot + 1);
  6450.                 token2 = token2.trim();
  6451.                 token3 = token2.split("\t");
  6452.                 switch (ReadMode) {
  6453.                 case 1:
  6454.                     if (token.equals("character-username")) {
  6455.                         if (playerName.equalsIgnoreCase(token2)) {
  6456.                         } else {
  6457.                             saveNeeded = false;
  6458.                             validClient = false;
  6459.                             return 3;
  6460.                         }
  6461.                     } /*else if (token.equals("character-password")) {
  6462.                         if (playerPass.equalsIgnoreCase(token2)) {
  6463.                         } else {
  6464.                             saveNeeded = false;
  6465.                             validClient = false;
  6466.                             return 3;
  6467.                         }
  6468.                     }*/
  6469.                     break;
  6470.                 case 2:
  6471.                     if (token.equals("character-height")) {
  6472.                         heightLevel = Integer.parseInt(token2);
  6473.                     } else if (token.equals("character-posx")) {
  6474.                         toX = Integer.parseInt(token2) == -1 ? 2999 : Integer
  6475.                                 .parseInt(token2);
  6476.                     } else if (token.equals("character-posy")) {
  6477.                         toY = Integer.parseInt(token2) == -1 ? 3377 : Integer
  6478.                                 .parseInt(token2);
  6479.                     } else if (token.equals("character-rights")) {
  6480.                         playerRights = Integer.parseInt(token2);
  6481.                     } else if (token.equals("character-lastconnection")) {
  6482.                         playerLastConnect = token2;
  6483.                     } else if (token.equals("character-special")) {
  6484.                         specialAmount = Integer.parseInt(token2);
  6485.                     } else if (token.equals("character-tz")) {
  6486.                         TzWave = Integer.parseInt(token2);
  6487.                     } else if (token.equals("character-starter")) {
  6488.                         starter = Integer.parseInt(token2);
  6489.                     } else if (token.equals("character-pouch1")) {
  6490.                         smallPouch = Integer.parseInt(token2);
  6491.                     } else if (token.equals("character-pouch2")) {
  6492.                         mediumPouch = Integer.parseInt(token2);
  6493.                     } else if (token.equals("character-pouch3")) {
  6494.                         largePouch = Integer.parseInt(token2);
  6495.                     } else if (token.equals("character-pouch4")) {
  6496.                         giantPouch = Integer.parseInt(token2);
  6497.                     } else if (token.equals("character-energy")) {
  6498.                         playerEnergy = Integer.parseInt(token2);
  6499.  
  6500.                     } else if (token.equals("character-brightness")) {
  6501.                         brightness = Integer.parseInt(token2);
  6502.                     } else if (token.equals("character-fighttype")) {
  6503.                         FightType = Integer.parseInt(token2);
  6504.                     } else if (token.equals("character-skill")) {
  6505.                         SkillID = Integer.parseInt(token2);
  6506.                     } else if (token.equals("character-chat")) {
  6507.                         splitChat = Integer.parseInt(token2);
  6508.                     } else if (token.equals("character-ancients")) {
  6509.                         playerAncientMagics = Integer.parseInt(token2);
  6510.                     } else if (token.equals("character-pin")) {
  6511.                         bankPin = Integer.parseInt(token2);
  6512.                     } else if (token.equals("character-saradomin")) {
  6513.                         saraKills = Integer.parseInt(token2);
  6514.                     } else if (token.equals("character-retaliate")) {
  6515.                         autoRetaliate = Integer.parseInt(token2);
  6516.                     } else if (token.equals("character-action")) {
  6517.                         action = Integer.parseInt(token2);
  6518.                     } else if (token.equals("character-pcpoints")) {
  6519.                         pcPoints = Integer.parseInt(token2);
  6520.                     } else if (token.equals("character-assault")) {
  6521.                         assaultKills = Integer.parseInt(token2);
  6522.                     } else if (token.equals("character-donator")) {
  6523.                         donator = Integer.parseInt(token2);
  6524.                     } else if (token.equals("character-bow")) {
  6525.                         arrowsLeft = Integer.parseInt(token2);
  6526.                     } else if (token.equals("character-shield")) {
  6527.                         shieldLeft = Integer.parseInt(token2);
  6528.                     }
  6529.                     break;
  6530.                 case 3:
  6531.                     if (token.equals("character-equip")) {
  6532.                         playerEquipment[Integer.parseInt(token3[0])] = Integer
  6533.                                 .parseInt(token3[1]);
  6534.                         playerEquipmentN[Integer.parseInt(token3[0])] = Integer
  6535.                                 .parseInt(token3[2]);
  6536.                     }
  6537.                     break;
  6538.                 case 4:
  6539.                     if (token.equals("character-look")) {
  6540.                         playerLooks[Integer.parseInt(token3[0])] = Integer
  6541.                                 .parseInt(token3[1]);
  6542.                     }
  6543.                     break;
  6544.                 case 5:
  6545.                     if (token.equals("character-skill")) {
  6546.                         playerLevel[Integer.parseInt(token3[0])] = Integer
  6547.                                 .parseInt(token3[1]);
  6548.                         playerXP[Integer.parseInt(token3[0])] = Integer
  6549.                                 .parseInt(token3[2]);
  6550.  
  6551.                         int level = 0;
  6552.                         level = playerLevel[Integer.parseInt(token3[0])];
  6553.                         playerLevel[Integer.parseInt(token3[0])] = level;
  6554.                         setSkillLevel(Integer.parseInt(token3[0]), level,
  6555.                                 playerXP[Integer.parseInt(token3[0])]);
  6556.                         if (Integer.parseInt(token3[0]) == 3) {
  6557.                             currentHealth = level;
  6558.                             maxHealth = level;
  6559.                         }
  6560.                     }
  6561.                     break;
  6562.  
  6563.                 case 6:
  6564.                     if (token.equals("character-item")) {
  6565.                         playerItems[Integer.parseInt(token3[0])] = Integer
  6566.                                 .parseInt(token3[1]);
  6567.                         playerItemsN[Integer.parseInt(token3[0])] = Integer
  6568.                                 .parseInt(token3[2]);
  6569.                     }
  6570.                     break;
  6571.                 case 7:
  6572.                     if (token.equals("character-bank")) {
  6573.                         bankItems[Integer.parseInt(token3[0])] = Integer
  6574.                                 .parseInt(token3[1]);
  6575.                         bankItemsN[Integer.parseInt(token3[0])] = Integer
  6576.                                 .parseInt(token3[2]);
  6577.                     }
  6578.                     break;
  6579.                 case 8:
  6580.                     if (token.equals("character-friend")) {
  6581.                         friends[Integer.parseInt(token3[0])] = Long
  6582.                                 .parseLong(token3[1]);
  6583.                     }
  6584.                     break;
  6585.                 case 9:
  6586.                     if (token.equals("character-ignore")) {
  6587.                         ignores[Integer.parseInt(token3[0])] = Long
  6588.                                 .parseLong(token3[1]);
  6589.                     }
  6590.                     break;
  6591.                 }
  6592.             } else {
  6593.                 if (line.equals("[ACCOUNT]"))
  6594.                     ReadMode = 1;
  6595.                 else if (line.equals("[CHARACTER]"))
  6596.                     ReadMode = 2;
  6597.                 else if (line.equals("[EQUIPMENT]"))
  6598.                     ReadMode = 3;
  6599.                 else if (line.equals("[LOOK]"))
  6600.                     ReadMode = 4;
  6601.                 else if (line.equals("[SKILLS]"))
  6602.                     ReadMode = 5;
  6603.                 else if (line.equals("[ITEMS]"))
  6604.                     ReadMode = 6;
  6605.                 else if (line.equals("[BANK]"))
  6606.                     ReadMode = 7;
  6607.                 else if (line.equals("[FRIENDS]"))
  6608.                     ReadMode = 8;
  6609.                 else if (line.equals("[IGNORES]"))
  6610.                     ReadMode = 9;
  6611.                 else if (line.equals("[EOF]")) {
  6612.                     // end of file now do whatever you set.
  6613.                     try {
  6614.                         characterfile.close();
  6615.                     } catch (IOException ioexception) {
  6616.                     }
  6617.                     setLook(playerLooks);
  6618.                     updateRequired = true;
  6619.                     appearanceUpdateRequired = true;
  6620.                     long end = System.currentTimeMillis() - start;
  6621.                     println("Character Loaded Sucessfully  ["
  6622.                             + (playerRights > 0 ? "Has powers"
  6623.                                     : "Regular player") + ", lag: " + end
  6624.                             + " ms]");
  6625.                     return 0;
  6626.                 }
  6627.             }
  6628.  
  6629.             // Exception occured @ some line
  6630.             try {
  6631.                 line = characterfile.readLine();
  6632.             } catch (IOException ioexception1) {
  6633.                 EndOfFile = true;
  6634.             }
  6635.         }
  6636.  
  6637.         try {
  6638.             characterfile.close();
  6639.         } catch (IOException ioexception) {
  6640.         }
  6641.         println("Failed to load player: " + playerName);
  6642.         return 13;
  6643.     }
  6644.  
  6645.     public void loadpm(long name, int world) {
  6646.         if (world != 0) {
  6647.             world += 9;
  6648.         } else if (world == 0) {
  6649.             world += 1;
  6650.         }
  6651.         outStream.createFrame(50);
  6652.         outStream.writeQWord(name);
  6653.         outStream.writeByte(world);
  6654.     }
  6655.  
  6656.     public void logout() {
  6657.  
  6658.         savegame(true);
  6659.         outStream.createFrame(109);
  6660.         // logoutButton = true;
  6661.     }
  6662.  
  6663.     public void lowGFX(int id, int delay) {
  6664.         mask100var1 = id;
  6665.         mask100var2 = delay;
  6666.         mask100update = true;
  6667.         updateRequired = true;
  6668.     }
  6669.  
  6670.     public void makeGlobalObject(int x, int y, int typeID, int orientation,
  6671.             int tileObjectType) { // Makes Global objects
  6672.         for (Player p : PlayerHandler.players) {
  6673.             if (p != null) {
  6674.                 Client person = (Client) p;
  6675.                 if ((person.playerName != null || person.playerName != "null")) {
  6676.                     if (person.distanceToPoint(x, y) <= 60) {
  6677.                         person.createNewTileObject(x, y, typeID, orientation,
  6678.                                 tileObjectType);
  6679.                     }
  6680.                 }
  6681.             }
  6682.         }
  6683.     }
  6684.  
  6685.     public int maxRangeHit() {
  6686.         double d = 0.0D;
  6687.         double d1 = playerLevel[playerRanged];
  6688.         d += 1.399D + d1 * 0.00125D;
  6689.         d += d1 * 0.11D;
  6690.         Client AttackingOn2 = (Client) PlayerHandler.players[AttackingOn];
  6691.         if (AttackingOn2 != null) {
  6692.             if (hasCrystalBow()) {
  6693.                 d *= 1.5D;
  6694.             } else if (!hasCrystalBow()
  6695.                     && (playerEquipment[playerArrows] == 882 || playerEquipment[playerArrows] == 883)) {
  6696.                 d *= 1.042D;
  6697.             } else if (!hasCrystalBow()
  6698.                     && (playerEquipment[playerArrows] == 884 || playerEquipment[playerArrows] == 885)) {
  6699.                 d *= 1.044D;
  6700.             } else if (!hasCrystalBow()
  6701.                     && (playerEquipment[playerArrows] == 886 || playerEquipment[playerArrows] == 887)) {
  6702.                 d *= 1.1339999999999999D;
  6703.             } else if (!hasCrystalBow()
  6704.                     && (playerEquipment[playerArrows] == 888 || playerEquipment[playerArrows] == 889)) {
  6705.                 d *= 1.2D;
  6706.             } else if (!hasCrystalBow()
  6707.                     && (playerEquipment[playerArrows] == 890 || playerEquipment[playerArrows] == 891)) {
  6708.                 d *= 1.3500000000000001D;
  6709.             } else if (!hasCrystalBow()
  6710.                     && (playerEquipment[playerArrows] == 892 || playerEquipment[playerArrows] == 893)) {
  6711.                 d *= 1.6000000000000001D;
  6712.             } else if (!hasCrystalBow()
  6713.                     && (playerEquipment[playerArrows] == 4740)) {
  6714.                 d *= 1.95D;
  6715.             } else if (!hasCrystalBow()
  6716.                     && (playerEquipment[playerWeapon] == 837)) {
  6717.                 d *= 1.55D;
  6718.             } else if (playerEquipment[playerWeapon] == 4827) {
  6719.                 d *= 1.95D;
  6720.             } else if (playerEquipment[playerWeapon] == 6522) {
  6721.                 d *= 1.55D;
  6722.             } else if (RangePray == 5) {
  6723.                 d += d1 * 0.021999999999999999D;
  6724.             }
  6725.             if (specOn) {
  6726.                 if (playerEquipment[playerWeapon] == 861) {
  6727.                     d *= 1.05D;
  6728.                 } else if (playerEquipment[playerWeapon] == 859) {
  6729.                     d /= 0.94999999999999996D;
  6730.                 } else if (playerEquipment[playerWeapon] == 4827) {
  6731.                     d *= 1.75D;
  6732.                 }
  6733.             }
  6734.             if (FullVRange()) {
  6735.                 d += d * 0.20000000000000001D;
  6736.             }
  6737.             int hit = (int) Math.floor(d);
  6738.             int protrange = 0;
  6739.             int noHit = Misc.random(2);
  6740.             if (AttackingOn2.ProtRange && noHit == 2) {
  6741.                 hit /= 2;
  6742.             }
  6743.             if (AttackingOn2.ProtRange) {
  6744.                 protrange = 100;
  6745.             }
  6746.             int aBonus = 0;
  6747.             int rand_att = Misc.random(playerLevel[4])
  6748.                     + Misc.random(playerBonus[4]);
  6749.             int rand_def = (int) (0.65 * Misc
  6750.                     .random(AttackingOn2.playerLevel[1]))
  6751.                     + Misc.random(protrange);
  6752.             int random_u = Misc.random(playerBonus[4] + aBonus);
  6753.             int dBonus = 0;
  6754.             int random_def = Misc.random(AttackingOn2.playerBonus[9] + dBonus);
  6755.             if ((random_u >= random_def) && (rand_att > rand_def)) {
  6756.                 return hit;
  6757.             } else {
  6758.                 return 0;
  6759.             }
  6760.         }
  6761.         return 0;
  6762.     }
  6763.  
  6764.     public int maxRangeHit2() {
  6765.         double d = 0.0D;
  6766.         double d1 = playerLevel[playerRanged];
  6767.         d += 1.399D + d1 * 0.00125D;
  6768.         d += d1 * 0.11D;
  6769.         if (hasCrystalBow()) {
  6770.             d *= 1.5D;
  6771.         } else if (!hasCrystalBow()
  6772.                 && (playerEquipment[playerArrows] == 882 || playerEquipment[playerArrows] == 883)) {
  6773.             d *= 1.042D;
  6774.         } else if (!hasCrystalBow()
  6775.                 && (playerEquipment[playerArrows] == 884 || playerEquipment[playerArrows] == 885)) {
  6776.             d *= 1.044D;
  6777.         } else if (!hasCrystalBow()
  6778.                 && (playerEquipment[playerArrows] == 886 || playerEquipment[playerArrows] == 887)) {
  6779.             d *= 1.1339999999999999D;
  6780.         } else if (!hasCrystalBow()
  6781.                 && (playerEquipment[playerArrows] == 888 || playerEquipment[playerArrows] == 889)) {
  6782.             d *= 1.2D;
  6783.         } else if (!hasCrystalBow()
  6784.                 && (playerEquipment[playerArrows] == 890 || playerEquipment[playerArrows] == 891)) {
  6785.             d *= 1.3500000000000001D;
  6786.         } else if (!hasCrystalBow()
  6787.                 && (playerEquipment[playerArrows] == 892 || playerEquipment[playerArrows] == 893)) {
  6788.             d *= 1.6000000000000001D;
  6789.         } else if (!hasCrystalBow() && (playerEquipment[playerArrows] == 4740)) {
  6790.             d *= 1.95D;
  6791.         } else if (!hasCrystalBow() && (playerEquipment[playerWeapon] == 837)) {
  6792.             d *= 1.55D;
  6793.         } else if (playerEquipment[playerWeapon] == 4827) {
  6794.             d *= 1.95D;
  6795.         } else if (playerEquipment[playerWeapon] == 6522) {
  6796.             d *= 1.55D;
  6797.         } else if (RangePray == 5) {
  6798.             d += d1 * 0.021999999999999999D;
  6799.         }
  6800.         if (specOn) {
  6801.             if (playerEquipment[playerWeapon] == 861) {
  6802.                 d *= 1.05D;
  6803.             } else if (playerEquipment[playerWeapon] == 859) {
  6804.                 d /= 0.94999999999999996D;
  6805.             } else if (playerEquipment[playerWeapon] == 4827) {
  6806.                 d *= 1.75D;
  6807.             }
  6808.         }
  6809.         if (FullVRange()) {
  6810.             d += d * 0.20000000000000001D;
  6811.         }
  6812.         int hit = (int) Math.floor(d);
  6813.         return hit;
  6814.     }
  6815.  
  6816.     public int MICheckPickAxe() {
  6817.         int Hand;
  6818.         int PickAxe;
  6819.  
  6820.         Hand = playerEquipment[playerWeapon];
  6821.         PickAxe = 0;
  6822.         switch (Hand) {
  6823.         case 1265:
  6824.             // Bronze Pick Axe
  6825.             PickAxe = 1;
  6826.             break;
  6827.  
  6828.         case 1267:
  6829.             // Iron Pick Axe
  6830.             PickAxe = 2;
  6831.             break;
  6832.  
  6833.         case 1269:
  6834.             // Steel Pick Axe
  6835.             PickAxe = 3;
  6836.             break;
  6837.  
  6838.         case 1273:
  6839.             // Mithril Pick Axe
  6840.             PickAxe = 4;
  6841.             break;
  6842.  
  6843.         case 1271:
  6844.             // Adamant Pick Axe
  6845.             PickAxe = 5;
  6846.             break;
  6847.  
  6848.         case 1275:
  6849.             // Rune Pick Axe
  6850.             PickAxe = 6;
  6851.             break;
  6852.         }
  6853.         if (PickAxe > 0) {
  6854.             return PickAxe;
  6855.         }
  6856.         return 0;
  6857.     }
  6858.  
  6859.     public void moveItems(int from, int to, int moveWindow) {
  6860.         if (moveWindow == 3724) {
  6861.             int tempI;
  6862.             int tempN;
  6863.             tempI = playerItems[from];
  6864.             tempN = playerItemsN[from];
  6865.             playerItems[from] = playerItems[to];
  6866.             playerItemsN[from] = playerItemsN[to];
  6867.             playerItems[to] = tempI;
  6868.             playerItemsN[to] = tempN;
  6869.         }
  6870.         if ((moveWindow == 34453) && (from >= 0) && (to >= 0)
  6871.                 && (from < playerBankSize) && (to < playerBankSize)) {
  6872.             int tempI;
  6873.             int tempN;
  6874.             tempI = bankItems[from];
  6875.             tempN = bankItemsN[from];
  6876.             bankItems[from] = bankItems[to];
  6877.             bankItemsN[from] = bankItemsN[to];
  6878.             bankItems[to] = tempI;
  6879.             bankItemsN[to] = tempN;
  6880.         }
  6881.         if (moveWindow == 34453) {
  6882.             resetBank();
  6883.         } else if (moveWindow == 18579) {
  6884.             resetItems(5064);
  6885.         } else if (moveWindow == 3724) {
  6886.             resetItems(3214);
  6887.         }
  6888.     }
  6889.  
  6890.     public boolean multiCombat() {
  6891.         if ((absX >= 3144 && absX <= 3184 && absY >= 3519 && absY <= 3656)
  6892.                 || (absX >= 3185 && absX <= 3350 && absY >= 3502 && absY <= 3900)
  6893.                 || (absX >= 2983 && absX <= 3007 && absY >= 3905 && absY <= 3917)
  6894.                 || (absX >= 3007 && absX <= 3075 && absY >= 3608 && absY <= 3713)
  6895.                 || (absX >= 2944 && absX <= 2963 && absY >= 3812 && absY <= 3827)
  6896.                 || (absX >= 3041 && absX <= 3057 && absY >= 3869 && absY <= 3883)
  6897.                 || (absX >= 3157 && absX <= 3181 && absY >= 3874 && absY <= 3895)
  6898.                 || (absX >= 2720 && absX <= 2760 && absY >= 5073 && absY <= 5114)
  6899.                 || (absX >= 2256 && absX <= 2287 && absY >= 4680 && absY <= 4711)
  6900.                 || (absX >= 2360 && absX <= 2445 && absY >= 5045 && absY <= 5125)
  6901.                 || (absX >= 2760 && absX <= 2780 && absY >= 2790 && absY <= 2810)
  6902.                 || (absX >= 2624 && absX <= 2690 && absY >= 2550 && absY <= 2619)
  6903.                 || (absX >= 3460 && absX <= 3520 && absY >= 9470 && absY <= 9530)
  6904.                 || (absX >= 2371 && absX <= 2424 && absY >= 5125 && absY <= 5167)
  6905.                 || (absX >= 2627 && absX <= 2677 && absY >= 4550 && absY <= 4602)
  6906.                 || (absX >= 3249 && absX <= 3307 && absY >= 3904 && absY <= 3952)
  6907.                 || (absX >= 2420 && absX <= 2520 && absY >= 10100 && absY <= 10200)
  6908.                 || (absX >= 2992 && absX <= 3090 && absY >= 4804 && absY <= 4872))
  6909.             return true;
  6910.         else
  6911.             return false;
  6912.     }
  6913.  
  6914.     public void nearNPC() {
  6915.         for (int i = 0; i < NPCHandler.maxNPCs; i++) {
  6916.             if (Server.npcHandler.npcs[i] != null
  6917.                     && Server.npcHandler.npcs[i].npcType == 1505) {
  6918.                 if (GoodDistance(Server.npcHandler.npcs[i].absX,
  6919.                         Server.npcHandler.npcs[i].absY, absX, absY, 1)
  6920.                         && npcId != 1463) {
  6921.                     Server.npcHandler.npcs[i].animNumber = 1402;
  6922.                     Server.npcHandler.npcs[i].updateRequired = true;
  6923.                     Server.npcHandler.npcs[i].animUpdateRequired = true;
  6924.                     toX = 2772;
  6925.                     toY = 2794;
  6926.                     hitDiff = 10;
  6927.                     currentHealth -= hitDiff;
  6928.                     updateRequired = true;
  6929.                     hitUpdateRequired = true;
  6930.                 }
  6931.             }
  6932.         }
  6933.     }
  6934.  
  6935.     public void NewObjects() {
  6936.         // makeGlobalObject(3509, 9496, 3831, 0, 10);
  6937.  
  6938.     }
  6939.  
  6940.     public void npcDamage(int extraDamage) {
  6941.         int voidmelee = 0;
  6942.         if (FullVMelee()) {
  6943.             voidmelee += 10;
  6944.         }
  6945.         if (npcHit()) {
  6946.             hitDiff = Misc.random(playerMaxHit) + Misc.random(StrPrayer)
  6947.                     + Misc.random(voidmelee) + Misc.random(extraDamage);
  6948.         }
  6949.         if (!npcHit()) {
  6950.             hitDiff = 0;
  6951.         }
  6952.     }
  6953.  
  6954.     public boolean npcHit() {
  6955.         int rand_att = Misc.random(playerLevel[0])
  6956.                 + Misc.random(playerBonus[1]) + Misc.random(AtkPray * 8);
  6957.         int rand_npc = 0;
  6958.         if (Server.npcHandler.npcs[attacknpc].npcType == 117
  6959.                 || Server.npcHandler.npcs[attacknpc].npcType == 112) { // giant
  6960.             rand_npc = Misc.random(50);
  6961.         }
  6962.         if (Server.npcHandler.npcs[attacknpc].npcType == 1338) { // dagg
  6963.             rand_npc = Misc.random(50);
  6964.         }
  6965.         if (Server.npcHandler.npcs[attacknpc].npcType == 1610) { // gargoyle
  6966.             rand_npc = Misc.random(170);
  6967.         }
  6968.         if (Server.npcHandler.npcs[attacknpc].npcType == 1616) { // basilisk
  6969.             rand_npc = Misc.random(60);
  6970.         }
  6971.         if (Server.npcHandler.npcs[attacknpc].npcType == 1637) { // jelly
  6972.             rand_npc = Misc.random(50);
  6973.         }
  6974.         if (Server.npcHandler.npcs[attacknpc].npcType == 1624) { // dust devil
  6975.             rand_npc = Misc.random(80);
  6976.         }
  6977.         if (Server.npcHandler.npcs[attacknpc].npcType == 1615) { // abyssal
  6978.             // demon
  6979.             rand_npc = Misc.random(180);
  6980.         }
  6981.         if (Server.npcHandler.npcs[attacknpc].npcType == 2783) { // dark beast
  6982.             rand_npc = Misc.random(200);
  6983.         }
  6984.         if (Server.npcHandler.npcs[attacknpc].npcType == 941) { // green dragons
  6985.             rand_npc = Misc.random(90);
  6986.         }
  6987.         if (Server.npcHandler.npcs[attacknpc].npcType == 1625) { // turoth
  6988.             rand_npc = Misc.random(70);
  6989.         }
  6990.         if (Server.npcHandler.npcs[attacknpc].npcType == 1613) { // nechryael
  6991.             rand_npc = Misc.random(120);
  6992.         }
  6993.         if (Server.npcHandler.npcs[attacknpc].npcType == 1264) { // saradomin
  6994.             // wizard
  6995.             rand_npc = Misc.random(50);
  6996.         }
  6997.         if (Server.npcHandler.npcs[attacknpc].npcType == 1459) { // gorilla
  6998.             // guard
  6999.             rand_npc = Misc.random(150);
  7000.         }
  7001.         if (Server.npcHandler.npcs[attacknpc].npcType == 1030) { // wolfman
  7002.             rand_npc = Misc.random(60);
  7003.         }
  7004.         if (Server.npcHandler.npcs[attacknpc].npcType == 2631) { // tok-xil
  7005.             rand_npc = Misc.random(50);
  7006.         }
  7007.         if (Server.npcHandler.npcs[attacknpc].npcType == 2741) { // yt-mejkot
  7008.             rand_npc = Misc.random(100);
  7009.         }
  7010.         if (Server.npcHandler.npcs[attacknpc].npcType == 2743) { // ket-zek
  7011.             rand_npc = Misc.random(300);
  7012.         }
  7013.         if (Server.npcHandler.npcs[attacknpc].npcType == 2745) { // tz-tok-jad
  7014.             rand_npc = Misc.random(500);
  7015.         }
  7016.         if (Server.npcHandler.npcs[attacknpc].npcType == 50) { // king black
  7017.             // dragon
  7018.             rand_npc = Misc.random(200);
  7019.         }
  7020.         if (Server.npcHandler.npcs[attacknpc].npcType == 1160) { // kalphite
  7021.             // queen
  7022.             rand_npc = Misc.random(200);
  7023.         }
  7024.         if (Server.npcHandler.npcs[attacknpc].npcType == 3200) { // chaos
  7025.             // elemental
  7026.             rand_npc = Misc.random(200);
  7027.         }
  7028.         if (Server.npcHandler.npcs[attacknpc].npcType == 2881
  7029.                 || Server.npcHandler.npcs[attacknpc].npcType == 2882
  7030.                 || Server.npcHandler.npcs[attacknpc].npcType == 2883) { // daggonaths
  7031.             rand_npc = Misc.random(300);
  7032.         }
  7033.         if (Server.npcHandler.npcs[attacknpc].npcType == 258) { // general
  7034.             // khazard
  7035.             rand_npc = Misc.random(120);
  7036.         }
  7037.         if (Server.npcHandler.npcs[attacknpc].npcType == 2025
  7038.                 || Server.npcHandler.npcs[attacknpc].npcType == 2026
  7039.                 || Server.npcHandler.npcs[attacknpc].npcType == 2027
  7040.                 || Server.npcHandler.npcs[attacknpc].npcType == 2028
  7041.                 || Server.npcHandler.npcs[attacknpc].npcType == 2029
  7042.                 || Server.npcHandler.npcs[attacknpc].npcType == 2030) { // barrows
  7043.             rand_npc = Misc.random(150);
  7044.         }
  7045.         if (Server.npcHandler.npcs[attacknpc].npcType == 1183) { // elf warrior
  7046.             rand_npc = Misc.random(150);
  7047.         }
  7048.         if (Server.npcHandler.npcs[attacknpc].npcType == 3777
  7049.                 || Server.npcHandler.npcs[attacknpc].npcType == 3778
  7050.                 || Server.npcHandler.npcs[attacknpc].npcType == 3779
  7051.                 || Server.npcHandler.npcs[attacknpc].npcType == 3780) { // pest
  7052.             // control
  7053.             rand_npc = Misc.random(200);
  7054.         }
  7055.         if (Server.npcHandler.npcs[attacknpc].npcType == 1472) { // jungle demon
  7056.             rand_npc = Misc.random(200);
  7057.         }
  7058.         if (Server.npcHandler.npcs[attacknpc].npcType == 988
  7059.                 || Server.npcHandler.npcs[attacknpc].npcType == 989
  7060.                 || Server.npcHandler.npcs[attacknpc].npcType == 990) { // knights
  7061.             // legend
  7062.             rand_npc = Misc.random(250);
  7063.         }
  7064.         if (Server.npcHandler.npcs[attacknpc].npcType == 1115) { // general
  7065.             // graardor
  7066.             rand_npc = Misc.random(300);
  7067.         }
  7068.         if (Server.npcHandler.npcs[attacknpc].npcType == 655) { // tree spirit
  7069.             rand_npc = Misc.random(100);
  7070.         }
  7071.         if (Server.npcHandler.npcs[attacknpc].npcType == 72) { // mithril dragon
  7072.             rand_npc = Misc.random(170);
  7073.         }
  7074.         if (Server.npcHandler.npcs[attacknpc].npcType == 2591
  7075.                 || Server.npcHandler.npcs[attacknpc].npcType == 2604
  7076.                 || Server.npcHandler.npcs[attacknpc].npcType == 2610) { // tzhaar
  7077.             rand_npc = Misc.random(70);
  7078.         }
  7079.         if (rand_att >= rand_npc) {
  7080.             return true;
  7081.         }
  7082.         return false;
  7083.     }
  7084.  
  7085.     public int npcRangeDamage() {
  7086.         if (npcRangeHit()) {
  7087.             return Misc.random(maxRangeHit2());
  7088.         } else {
  7089.             return 0;
  7090.         }
  7091.     }
  7092.  
  7093.     public boolean npcRangeHit() {
  7094.         int rand_att = Misc.random(playerLevel[4])
  7095.                 + Misc.random(playerBonus[4]) + Misc.random(RangePray * 8);
  7096.         int rand_npc = 0;
  7097.         if (Server.npcHandler.npcs[attacknpc].npcType == 117
  7098.                 || Server.npcHandler.npcs[attacknpc].npcType == 112) { // giant
  7099.             rand_npc = Misc.random(50);
  7100.         }
  7101.         if (Server.npcHandler.npcs[attacknpc].npcType == 1338) { // dagg
  7102.             rand_npc = Misc.random(50);
  7103.         }
  7104.         if (Server.npcHandler.npcs[attacknpc].npcType == 1610) { // gargoyle
  7105.             rand_npc = Misc.random(170);
  7106.         }
  7107.         if (Server.npcHandler.npcs[attacknpc].npcType == 1616) { // basilisk
  7108.             rand_npc = Misc.random(60);
  7109.         }
  7110.         if (Server.npcHandler.npcs[attacknpc].npcType == 1637) { // jelly
  7111.             rand_npc = Misc.random(50);
  7112.         }
  7113.         if (Server.npcHandler.npcs[attacknpc].npcType == 1624) { // dust devil
  7114.             rand_npc = Misc.random(80);
  7115.         }
  7116.         if (Server.npcHandler.npcs[attacknpc].npcType == 1615) { // abyssal
  7117.             // demon
  7118.             rand_npc = Misc.random(180);
  7119.         }
  7120.         if (Server.npcHandler.npcs[attacknpc].npcType == 2783) { // dark beast
  7121.             rand_npc = Misc.random(200);
  7122.         }
  7123.         if (Server.npcHandler.npcs[attacknpc].npcType == 941) { // green dragons
  7124.             rand_npc = Misc.random(90);
  7125.         }
  7126.         if (Server.npcHandler.npcs[attacknpc].npcType == 1625) { // turoth
  7127.             rand_npc = Misc.random(70);
  7128.         }
  7129.         if (Server.npcHandler.npcs[attacknpc].npcType == 1613) { // nechryael
  7130.             rand_npc = Misc.random(120);
  7131.         }
  7132.         if (Server.npcHandler.npcs[attacknpc].npcType == 1264) { // saradomin
  7133.             // wizard
  7134.             rand_npc = Misc.random(50);
  7135.         }
  7136.         if (Server.npcHandler.npcs[attacknpc].npcType == 1459) { // gorilla
  7137.             // guard
  7138.             rand_npc = Misc.random(150);
  7139.         }
  7140.         if (Server.npcHandler.npcs[attacknpc].npcType == 1030) { // wolfman
  7141.             rand_npc = Misc.random(60);
  7142.         }
  7143.         if (Server.npcHandler.npcs[attacknpc].npcType == 2631) { // tok-xil
  7144.             rand_npc = Misc.random(20);
  7145.         }
  7146.         if (Server.npcHandler.npcs[attacknpc].npcType == 2741) { // yt-mejkot
  7147.             rand_npc = Misc.random(30);
  7148.         }
  7149.         if (Server.npcHandler.npcs[attacknpc].npcType == 2743) { // ket-zek
  7150.             rand_npc = Misc.random(150);
  7151.         }
  7152.         if (Server.npcHandler.npcs[attacknpc].npcType == 2745) { // tz-tok-jad
  7153.             rand_npc = Misc.random(300);
  7154.         }
  7155.         if (Server.npcHandler.npcs[attacknpc].npcType == 50) { // king black
  7156.             // dragon
  7157.             rand_npc = Misc.random(200);
  7158.         }
  7159.         if (Server.npcHandler.npcs[attacknpc].npcType == 1160) { // kalphite
  7160.             // queen
  7161.             rand_npc = Misc.random(200);
  7162.         }
  7163.         if (Server.npcHandler.npcs[attacknpc].npcType == 3200) { // chaos
  7164.             // elemental
  7165.             rand_npc = Misc.random(200);
  7166.         }
  7167.         if (Server.npcHandler.npcs[attacknpc].npcType == 2881
  7168.                 || Server.npcHandler.npcs[attacknpc].npcType == 2882
  7169.                 || Server.npcHandler.npcs[attacknpc].npcType == 2883) { // daggonaths
  7170.             rand_npc = Misc.random(300);
  7171.         }
  7172.         if (Server.npcHandler.npcs[attacknpc].npcType == 258) { // general
  7173.             // khazard
  7174.             rand_npc = Misc.random(120);
  7175.         }
  7176.         if (Server.npcHandler.npcs[attacknpc].npcType == 2025
  7177.                 || Server.npcHandler.npcs[attacknpc].npcType == 2026
  7178.                 || Server.npcHandler.npcs[attacknpc].npcType == 2027
  7179.                 || Server.npcHandler.npcs[attacknpc].npcType == 2028
  7180.                 || Server.npcHandler.npcs[attacknpc].npcType == 2029
  7181.                 || Server.npcHandler.npcs[attacknpc].npcType == 2030) { // barrows
  7182.             rand_npc = Misc.random(150);
  7183.         }
  7184.         if (Server.npcHandler.npcs[attacknpc].npcType == 1183) { // elf warrior
  7185.             rand_npc = Misc.random(150);
  7186.         }
  7187.         if (Server.npcHandler.npcs[attacknpc].npcType == 3777
  7188.                 || Server.npcHandler.npcs[attacknpc].npcType == 3778
  7189.                 || Server.npcHandler.npcs[attacknpc].npcType == 3779
  7190.                 || Server.npcHandler.npcs[attacknpc].npcType == 3780) { // pest
  7191.             // control
  7192.             rand_npc = Misc.random(200);
  7193.         }
  7194.         if (Server.npcHandler.npcs[attacknpc].npcType == 1472) { // jungle demon
  7195.             rand_npc = Misc.random(200);
  7196.         }
  7197.         if (Server.npcHandler.npcs[attacknpc].npcType == 988
  7198.                 || Server.npcHandler.npcs[attacknpc].npcType == 989
  7199.                 || Server.npcHandler.npcs[attacknpc].npcType == 990) { // knights
  7200.             // legend
  7201.             rand_npc = Misc.random(250);
  7202.         }
  7203.         if (Server.npcHandler.npcs[attacknpc].npcType == 1115) { // general
  7204.             // graardor
  7205.             rand_npc = Misc.random(300);
  7206.         }
  7207.         if (Server.npcHandler.npcs[attacknpc].npcType == 655) { // tree spirit
  7208.             rand_npc = Misc.random(100);
  7209.         }
  7210.         if (Server.npcHandler.npcs[attacknpc].npcType == 72) { // mithril dragon
  7211.             rand_npc = Misc.random(170);
  7212.         }
  7213.         if (Server.npcHandler.npcs[attacknpc].npcType == 2591
  7214.                 || Server.npcHandler.npcs[attacknpc].npcType == 2604
  7215.                 || Server.npcHandler.npcs[attacknpc].npcType == 2610) { // tzhaar
  7216.             rand_npc = Misc.random(70);
  7217.         }
  7218.         if (rand_att >= rand_npc) {
  7219.             return true;
  7220.         }
  7221.         return false;
  7222.     }
  7223.  
  7224.     /* ITEMS */
  7225.  
  7226.     public void openTan() {
  7227.         sendQuest("Regular Leather", 14777);
  7228.         sendQuest("50gp", 14785);
  7229.         sendQuest("Hard Leather", 14781);
  7230.         sendQuest("100gp", 14789);
  7231.         sendQuest("", 14778);
  7232.         sendQuest("", 14786);
  7233.         sendQuest("", 14782);
  7234.         sendQuest("", 14790);
  7235.         int[] soon = { 14779, 14787, 14783, 14791, 14780, 14788, 14784, 14792 };
  7236.         String[] dhide = { "Green", "Red", "Blue", "Black" };
  7237.         String[] cost = { "1,000gp", "5,000gp", "2,000gp", "10,000gp" };
  7238.         int type = 0;
  7239.         for (int i = 0; i < soon.length; i++) {
  7240.             if (type == 0) {
  7241.                 sendQuest(dhide[(int) (i / 2)], soon[i]);
  7242.                 type = 1;
  7243.             } else {
  7244.                 sendQuest(cost[(int) (i / 2)], soon[i]);
  7245.                 type = 0;
  7246.             }
  7247.         }
  7248.         sendFrame246(14769, 250, 1741);
  7249.         sendFrame246(14773, 250, 1743);
  7250.         sendFrame246(14771, 250, 1753);
  7251.         sendFrame246(14772, 250, 1751);
  7252.         sendFrame246(14775, 250, 1749);
  7253.         sendFrame246(14776, 250, 1747);
  7254.         showInterface(14670);
  7255.  
  7256.     }
  7257.  
  7258.     public void openTrade() {
  7259.         Client o = (Client) PlayerHandler.players[trade_reqId];
  7260.  
  7261.         if (o == null) {
  7262.             return;
  7263.         }
  7264.         inTrade = true;
  7265.         canOffer = true;
  7266.         tradeStatus = 1;
  7267.         tradeRequested = false;
  7268.         resetItems(3322);
  7269.         resetTItems(3415);
  7270.         resetOTItems(3416);
  7271.         String out = o.playerName;
  7272.  
  7273.         if (o.playerRights == 1) {
  7274.             out = "@cr1@" + out;
  7275.         } else if (o.playerRights == 2) {
  7276.             out = "@cr2@" + out;
  7277.         }
  7278.         sendFrame126("Trading with: " + o.playerName + " who has @gre@"
  7279.                 + o.freeSlots() + " free slots", 3417);
  7280.         sendFrame126("", 3431);
  7281.         sendFrame126("Are you sure you want to make this trade?", 3535);
  7282.         sendFrame248(3323, 3321);
  7283.     }
  7284.  
  7285.     public void rearrangeBank() {
  7286.         int totalItems = 0;
  7287.         int highestSlot = 0;
  7288.         for (int i = 0; i < playerBankSize; i++) {
  7289.             if (bankItems[i] != 0) {
  7290.                 totalItems++;
  7291.                 if (highestSlot <= i)
  7292.                     highestSlot = i;
  7293.             }
  7294.         }
  7295.  
  7296.         for (int i = 0; i <= highestSlot; i++) {
  7297.             if (bankItems[i] == 0) {
  7298.                 boolean stop = false;
  7299.  
  7300.                 for (int k = i; k <= highestSlot; k++) {
  7301.                     if (bankItems[k] != 0 && !stop) {
  7302.                         int spots = k - i;
  7303.                         for (int j = k; j <= highestSlot; j++) {
  7304.                             bankItems[j - spots] = bankItems[j];
  7305.                             bankItemsN[j - spots] = bankItemsN[j];
  7306.                             stop = true;
  7307.                             bankItems[j] = 0;
  7308.                             bankItemsN[j] = 0;
  7309.                         }
  7310.                     }
  7311.                 }
  7312.             }
  7313.         }
  7314.  
  7315.         int totalItemsAfter = 0;
  7316.         for (int i = 0; i < playerBankSize; i++) {
  7317.             if (bankItems[i] != 0) {
  7318.                 totalItemsAfter++;
  7319.             }
  7320.         }
  7321.  
  7322.         if (totalItems != totalItemsAfter)
  7323.             outStream.createFrame(109); // disconnects when duping
  7324.  
  7325.     }
  7326.  
  7327.     public void openUpBank() {
  7328.         rearrangeBank();
  7329.         resetBank();
  7330.         sendFrame248(5292, 5063);
  7331.         resetItems(5064);
  7332.         IsBanking = true;
  7333.     }
  7334.  
  7335.     public void openUpDepBox() {
  7336.         sendFrame248(4465, 197);// 197 just because you can't see it =\
  7337.         resetItems(7423);
  7338.         IsBanking = true;
  7339.     }
  7340.  
  7341.     public void openUpShop(int ShopID) {
  7342.         sendFrame126(ShopHandler.ShopName[ShopID], 3901);
  7343.         sendFrame248(3824, 3822);
  7344.         resetItems(3823);
  7345.         resetShop(ShopID);
  7346.         IsShopping = true;
  7347.         MyShopID = ShopID;
  7348.     }
  7349.  
  7350.     public void openWelcomeScreen(int recoveryChange, boolean memberWarning,
  7351.             int messages, int lastLoginIP, int lastLogin) {
  7352.         outStream.createFrame(176);
  7353.         // days since last recovery change 200 for not yet set 201 for members
  7354.         // server,
  7355.         // otherwise, how many days ago recoveries have been changed.
  7356.         outStream.writeByteC(recoveryChange);
  7357.         outStream.writeWordA(messages); // # of unread messages
  7358.         outStream.writeByte(memberWarning ? 1 : 0); // 1 for member on
  7359.         // non-members world warning
  7360.         outStream.writeDWord_v2(lastLoginIP); // ip of last login
  7361.         outStream.writeWord(lastLogin); // days
  7362.     }
  7363.  
  7364.     public boolean packetProcess() throws NullPointerException {
  7365.         if (disconnected || destruct) {
  7366.             return false;
  7367.         }
  7368.         try {
  7369.             /*
  7370.              * if (timeOutCounter++ > 20) {
  7371.              * misc.println("Disconnected "+playerName
  7372.              * +", Data transfer timeout."); disconnected = true; return false;
  7373.              * }
  7374.              */
  7375.             if (in == null)
  7376.                 return false;
  7377.             int avail = in.available();
  7378.             if (avail == 0)
  7379.                 return false;
  7380.  
  7381.             if (packetType == -1) {
  7382.                 packetType = in.read() & 0xff;
  7383.                 if (inStreamDecryption != null)
  7384.                     packetType = packetType - inStreamDecryption.getNextKey()
  7385.                             & 0xff;
  7386.                 packetSize = packetSizes[packetType];
  7387.                 avail--;
  7388.             }
  7389.             if (packetSize == -1) {
  7390.                 if (avail > 0) {
  7391.                     packetSize = in.read() & 0xff;
  7392.                     avail--;
  7393.                 } else
  7394.                     return false;
  7395.             }
  7396.             if (avail < packetSize)
  7397.                 return false;
  7398.             fillInStream(packetSize);
  7399.             timeOutCounter = 0;
  7400.             parseIncomingPackets();
  7401.             packetType = -1;
  7402.         } catch (java.lang.Exception __ex) {
  7403.             Misc
  7404.                     .println("Exception encountered while parsing incoming packets from "
  7405.                             + playerName + ".");
  7406.             __ex.printStackTrace();
  7407.             disconnected = true;
  7408.         }
  7409.         return true;
  7410.     }
  7411.  
  7412.     private void parseIncomingPackets() {
  7413.         int i;
  7414.         @SuppressWarnings("unused")
  7415.         int junk, junk2, junk3;
  7416.         lastPacket = System.currentTimeMillis();
  7417.         // if(packetType != 0) println("" + packetType);
  7418.         switch (packetType) {
  7419.         case 25:
  7420.             // item in inventory used with item on floor
  7421.             int unknown1 = inStream.readSignedWordBigEndian(); // interface id
  7422.             // of item
  7423.             int unknown2 = inStream.readUnsignedWordA(); // item in bag id
  7424.             int floorID = inStream.readUnsignedByte();
  7425.             int floorY = inStream.readUnsignedWordA();
  7426.             int unknown3 = inStream.readUnsignedWordBigEndianA();
  7427.             int floorX = inStream.readUnsignedByte();
  7428.             System.out.println("Unknown1 = " + unknown1);
  7429.             System.out.println("Unknown2 = " + unknown2);
  7430.             System.out.println("FloorID = " + floorID);
  7431.             System.out.println("FloorY = " + floorY);
  7432.             System.out.println("Unknown3 = " + unknown3);
  7433.             System.out.println("FloorX = " + floorX);
  7434.             break;
  7435.         case 57:
  7436.             break;
  7437.  
  7438.         case 0:
  7439.             break; // idle packet - keeps on reseting timeOutCounter
  7440.         case 202:
  7441.             // idle logout packet
  7442.         case 45:
  7443.             // flagged account data
  7444.             // inStream.readBytes(pmchatText, pmchatTextSize, 0);
  7445.             @SuppressWarnings("unused")
  7446.             int part2 = -1,
  7447.             part3 = -1,
  7448.             part4 = -1;
  7449.             try {
  7450.                 part2 = inStream.readUnsignedWord();
  7451.             } catch (Exception e) {
  7452.                 println("part2 not sent");
  7453.             }
  7454.             // if(part2 == -1){ //exect input (Client if/else)
  7455.             try {
  7456.                 part3 = inStream.readDWord_v1();
  7457.             } catch (Exception e) {
  7458.                 println("part3 not sent");
  7459.             }
  7460.             try {
  7461.                 part4 = inStream.readDWord();
  7462.             } catch (Exception e) {
  7463.                 println("part4 not sent");
  7464.             }
  7465.             // }
  7466.             // println("blah=" + blah + ", " + "part2=" + part2 + ", part3="
  7467.             // + part3 + ", part4=" + part4);
  7468.             break;
  7469.  
  7470.         case 210:
  7471.             // loads new area
  7472.             break;
  7473.  
  7474.         case 40:
  7475.             if (NpcDialogue == 1 || NpcDialogue == 2 || NpcDialogue == 3
  7476.                     || NpcDialogue == 4 || NpcDialogue == 5 || NpcDialogue == 6
  7477.                     || NpcDialogue == 8 || NpcDialogue == 10
  7478.                     || NpcDialogue == 13 || NpcDialogue == 16
  7479.                     || NpcDialogue == 18 || NpcDialogue == 19
  7480.                     || NpcDialogue == 21 || NpcDialogue == 22
  7481.                     || NpcDialogue == 23 || NpcDialogue == 27
  7482.                     || NpcDialogue == 28 || NpcDialogue == 30
  7483.                     || NpcDialogue == 31 || NpcDialogue == 32
  7484.                     || NpcDialogue == 34 || NpcDialogue == 37
  7485.                     || NpcDialogue == 41 || NpcDialogue == 42
  7486.                     || NpcDialogue == 44 || NpcDialogue == 45
  7487.                     || NpcDialogue == 48 || NpcDialogue == 49
  7488.                     || NpcDialogue == 50 || NpcDialogue == 52
  7489.                     || NpcDialogue == 54 || NpcDialogue == 57
  7490.                     || NpcDialogue == 60 || NpcDialogue == 64
  7491.                     || NpcDialogue == 65 || NpcDialogue == 66
  7492.                     || NpcDialogue == 73 || NpcDialogue == 75
  7493.                     || NpcDialogue == 77 || NpcDialogue == 81
  7494.                     || NpcDialogue == 82 || NpcDialogue == 83
  7495.                     || NpcDialogue == 85 || NpcDialogue == 87
  7496.                     || NpcDialogue == 91 || NpcDialogue == 89
  7497.                     || NpcDialogue == 90 || NpcDialogue == 91
  7498.                     || NpcDialogue == 92 || NpcDialogue == 95
  7499.                     || NpcDialogue == 96 || NpcDialogue == 97
  7500.                     || NpcDialogue == 98 || NpcDialogue == 100
  7501.                     || NpcDialogue == 102 || NpcDialogue == 103
  7502.                     || NpcDialogue == 105 || NpcDialogue == 106
  7503.                     || NpcDialogue == 107 || NpcDialogue == 108
  7504.                     || NpcDialogue == 109 || NpcDialogue == 111
  7505.                     || NpcDialogue == 112 || NpcDialogue == 114
  7506.                     || NpcDialogue == 116) {
  7507.                 NpcDialogue += 1;
  7508.                 NpcDialogueSend = false;
  7509.             } else if (NpcDialogue == 15) {
  7510.                 NpcDialogue = 0;
  7511.                 NpcDialogueSend = false;
  7512.                 RemoveAllWindows();
  7513.             } else {
  7514.                 closeInterface();
  7515.             }
  7516.             if (NpcDialogue == 71) {
  7517.                 NpcDialogue += 9;
  7518.                 NpcDialogueSend = false;
  7519.             }
  7520.  
  7521.             if (NpcDialogue == 119) {
  7522.                 openUpShop(41);
  7523.             }
  7524.  
  7525.             break;
  7526.         case 192:
  7527.             // Use an item on object
  7528.             junk = inStream.readSignedWordBigEndianA();
  7529.             int UsedOnObjectID = inStream.readUnsignedWordBigEndian();
  7530.             int UsedOnY = inStream.readSignedWordBigEndianA();
  7531.             int ItemSlot = (inStream.readSignedWordBigEndianA() - 128);
  7532.             int UsedOnX = inStream.readUnsignedWordBigEndianA();
  7533.             int ItemID = inStream.readUnsignedWord();
  7534.             if (!playerHasItem(ItemID))
  7535.                 break;
  7536.             if (!antiHax())
  7537.                 break;
  7538.  
  7539.             Server.Cooking.StartCooking(ItemID, UsedOnObjectID, ID);
  7540.    
  7541.  
  7542.             /**
  7543.              * Spinning Flax/Wool
  7544.              */
  7545.             // Flax
  7546.             if (UsedOnObjectID == 2644) {
  7547.                 if (ItemID == 1779) {
  7548.                     deleteItem(1779, 1);
  7549.                     addSkillXP(60 * getLevelForXP(playerXP[12]), 12);
  7550.                     addItem(1777, 1);
  7551.                     setAnimation(894);
  7552.                     sM("You spin some Flax");
  7553.                 }
  7554.                 TurnPlayerTo(UsedOnX, UsedOnY);
  7555.                 // Wool
  7556.                 if (ItemID == 1737) {
  7557.                     deleteItem(1737, 1);
  7558.                     addSkillXP(40 * getLevelForXP(playerXP[12]), 12);
  7559.                     addItem(1759, 1);
  7560.                     setAnimation(894);
  7561.                     sM("You spin some Wool");
  7562.                 }
  7563.                 TurnPlayerTo(UsedOnX, UsedOnY);
  7564.             }
  7565.             /**
  7566.              * End of Spinning
  7567.              */
  7568.             if (UsedOnObjectID == 3994) {
  7569.                 for (int fi = 0; fi < Misc.smelt_frame.length; fi++)
  7570.                     sendFrame246(Misc.smelt_frame[fi], 150, Misc.smelt_bars[fi]);
  7571.                 sendFrame164(2400);
  7572.                 // smelting = true;
  7573.                 // smelt_id = ItemID;
  7574.             }
  7575.             if (UsedOnObjectID == 10638) {
  7576.                 if (ItemID == 526) {
  7577.                     deleteItem(526, 1);
  7578.                     addSkillXP(40 * getLevelForXP(playerXP[5]), 5);
  7579.                     sM("You receive some prayer experience.");
  7580.                     setAnimation(894);
  7581.                     lowGFX(247, 0);
  7582.                 }
  7583.                 if (ItemID == 532) {
  7584.                     deleteItem(532, 1);
  7585.                     addSkillXP(80 * getLevelForXP(playerXP[5]), 5);
  7586.                     sM("You receive some prayer experience.");
  7587.                     setAnimation(894);
  7588.                     lowGFX(247, 0);
  7589.                 }
  7590.                 if (ItemID == 536) {
  7591.                     deleteItem(536, 1);
  7592.                     addSkillXP(160 * getLevelForXP(playerXP[5]), 5);
  7593.                     sM("You receive some prayer experience.");
  7594.                     setAnimation(894);
  7595.                     lowGFX(247, 0);
  7596.                 }
  7597.                 TurnPlayerTo(UsedOnX, UsedOnY);
  7598.             }
  7599.             if (UsedOnObjectID == 2644 && ItemID == 1737) {
  7600.                 deleteItem(1737, 1);
  7601.                 addItem(1759, 1);
  7602.                 setAnimation(894);
  7603.             }
  7604.             if ((UsedOnObjectID == 2781) || (UsedOnObjectID == 2728)) {
  7605.                 // furnace, range
  7606.                 if ( /* CheckForSkillUse2(ItemID, ItemSlot) == */true) {
  7607.                     cookingOn = true;
  7608.                 }
  7609.             }
  7610.             break;
  7611.         case 218:
  7612.  
  7613.             String abuser = Misc.longToPlayerName(inStream.readQWord());
  7614.             int rule = inStream.readUnsignedByte();
  7615.             int mute = inStream.readUnsignedByte();
  7616.             reportAbuse(abuser, rule, mute);
  7617.             break;
  7618.         case 130:
  7619.             // Clicking some stuff in game
  7620.             int interfaceID = inStream.readSignedByte();
  7621.             if (inTrade) {
  7622.                 if (!acceptedTrade) {
  7623.                     declineTrade();
  7624.                 }
  7625.             }
  7626.             if (IsShopping == true) {
  7627.                 IsShopping = false;
  7628.                 MyShopID = 0;
  7629.                 UpdateShop = false;
  7630.             }
  7631.             if (IsBanking == true) {
  7632.                 IsBanking = false;
  7633.             }
  7634.  
  7635.             if ((Misc.HexToInt(inStream.buffer, 0, packetSize) != 63363)
  7636.                     && (Misc.HexToInt(inStream.buffer, 0, packetSize) != 0)) {
  7637.                 println_debug("handled packet [" + packetType
  7638.                         + ", InterFaceId: " + interfaceID + ", size="
  7639.                         + packetSize + "]: ]"
  7640.                         + Misc.Hex(inStream.buffer, 1, packetSize) + "[");
  7641.                 println_debug("Action Button: "
  7642.                         + Misc.HexToInt(inStream.buffer, 0, packetSize));
  7643.             }
  7644.             break;
  7645.  
  7646.         case 155:
  7647.             // first Click npc
  7648.             NPCSlot = inStream.readSignedWordBigEndian();
  7649.             if ((NPCSlot < 0) || (NPCSlot >= Server.npcHandler.npcs.length)
  7650.                     || (Server.npcHandler.npcs[NPCSlot] == null))
  7651.                 break;
  7652.             NPCID = Server.npcHandler.npcs[NPCSlot].npcType;
  7653.             boolean PutNPCCoords = false;
  7654.             if (Misc.random(100) == 1) {
  7655.                 triggerRandom();
  7656.                 break;
  7657.             }
  7658.  
  7659.             if (GoodDistance(Server.npcHandler.npcs[NPCSlot].absX,
  7660.                     Server.npcHandler.npcs[NPCSlot].absY, absX, absY, 2) == false) {
  7661.                 break;
  7662.             }
  7663.             if (!antiHax())
  7664.                 break;
  7665.  
  7666.             if (NPCID == 316) {
  7667.                 /* Net From Net & Bait - Any Sea */
  7668.                 if ((IsItemInBag(303) == true)) {
  7669.                     // startFishing(316);
  7670.                 } else {
  7671.                     sM("You need a " + getItemName(303) + " to fish here.");
  7672.                 }
  7673.             } else if (NPCID == 321) {
  7674.                 // startFishing(321);
  7675.  
  7676.             } else if (NPCID == 322) {
  7677.                 // startFishing(322);
  7678.  
  7679.             } else if (NPCID == 323) {
  7680.                 // startFishing(323);
  7681.  
  7682.                 if (NPCID == 545) {
  7683.                     openTan();
  7684.                 }
  7685.                 if (NPCID == 2537) {
  7686.                     // PutNPCCoords = true;
  7687.                     WanneShop = 16;
  7688.                 }
  7689.                 if (NPCID == 2536) {
  7690.                     PutNPCCoords = true;
  7691.                     WanneShop = 47;
  7692.                 }
  7693.                 if (NPCID == 2538) {
  7694.                     // PutNPCCoords = true;
  7695.                     WanneShop = 20;
  7696.                 }
  7697.                 if (NPCID == 1055) {
  7698.                     toX = 2477;
  7699.                     toY = 3437;
  7700.                 }
  7701.                 if (NPCID == 2261) {
  7702.                     teleEffect = 2;
  7703.                     sendQuest("Teleport to the abyss?", 2470);
  7704.                     sendQuest("Yes", 2471);
  7705.                     sendQuest("No", 2472);
  7706.                     sendQuest("", 2473);
  7707.                     sendFrame164(2469);
  7708.                 }
  7709.                 if (NPCID == 702) {
  7710.                     PutNPCCoords = true;
  7711.                     WanneShop = 18;
  7712.                 }
  7713.                 if (NPCID == 804) {
  7714.                     openTan();
  7715.                 }
  7716.                 if (NPCID == 2617) {
  7717.                     toX = 2480;
  7718.                     toY = 5175;
  7719.                 }
  7720.                 if (NPCID == 599) {
  7721.                     showInterface(3559);
  7722.                     apset = true;
  7723.                 }
  7724.                 if (NPCID == 1281) {
  7725.                     PutNPCCoords = true;
  7726.                     WanneShop = 6;
  7727.                 }
  7728.             } else if (NPCID == 321) {
  7729.                 // startFishing(321);
  7730.             } else if (NPCID == 322) {
  7731.                 // startFishing(322);
  7732.             } else if (NPCID == 323) {
  7733.                 // startFishing(323);
  7734.  
  7735.             } else {
  7736.                 faceNPC(NPCSlot);
  7737.             }
  7738.             if (PutNPCCoords == true) {
  7739.                 skillX = Server.npcHandler.npcs[NPCSlot].absX;
  7740.                 skillY = Server.npcHandler.npcs[NPCSlot].absY;
  7741.             }
  7742.             break;
  7743.  
  7744.         case 17:
  7745.             // second Click npc
  7746.             NPCSlot = inStream.readUnsignedWordBigEndianA();
  7747.             if ((NPCSlot < 0) || (NPCSlot >= Server.npcHandler.npcs.length)
  7748.                     || (Server.npcHandler.npcs[NPCSlot] == null))
  7749.                 break;
  7750.             NPCID = Server.npcHandler.npcs[NPCSlot].npcType;
  7751.             long time = System.currentTimeMillis();
  7752.             if (Misc.random(100) == 1) {
  7753.                 triggerRandom();
  7754.                 break;
  7755.             }
  7756.             if (time - globalCooldown[0] <= 50) {
  7757.                 sM("Action throttled... please wait longer before acting!");
  7758.                 break;
  7759.             }
  7760.             if (time - lastMouse > 5000) {
  7761.                 // sM("Client hack detected!");
  7762.                 println("Suspicious activity!");
  7763.                 disconnected = true;
  7764.                 break;
  7765.             }
  7766.             if (action == 1) {
  7767.                 sM("Suspicious activity!");
  7768.                 break;
  7769.             }
  7770.  
  7771.             globalCooldown[0] = time;
  7772.             int npcX = Server.npcHandler.npcs[NPCSlot].absX;
  7773.             int npcY = Server.npcHandler.npcs[NPCSlot].absY;
  7774.             if ((Math.abs(absX - npcX) > 50) || (Math.abs(absY - npcY) > 50)) {
  7775.                 // sM("Client hack detected!");
  7776.                 break;
  7777.             }
  7778.             if (Server.npcHandler.npcs[NPCSlot].IsDead) {
  7779.                 // sM("That monster has been killed!");
  7780.                 break;
  7781.             }
  7782.             PutNPCCoords = false;
  7783.  
  7784.             if (NPCID == 1) {
  7785.                 robPerson("man", 995, 105, 29, 1);
  7786.             }
  7787.             if (NPCID == 9) {
  7788.                 robPerson("guard", 995, 272, 48, 41);
  7789.             }
  7790.             if (NPCID == 23) {
  7791.                 robPerson("knight", 995, 440, 102, 52);
  7792.             }
  7793.             if (NPCID == 21) {
  7794.                 robPerson("hero", 995, 760, 120, 80);
  7795.             }
  7796.             if (NPCID == 66) {
  7797.                 robPerson("gnome", 995, 1200, 150, 90);
  7798.  
  7799.             } else {
  7800.                 faceNPC(NPCSlot);
  7801.             }
  7802.             /**
  7803.              *Start of NPC Shops Second Click
  7804.              */
  7805.             if (NPCID == 522) {
  7806.                 PutNPCCoords = true;
  7807.                 WanneShop = 1;
  7808.             }
  7809.             if (NPCID == 550) {
  7810.                 PutNPCCoords = true;
  7811.                 WanneShop = 3;
  7812.             }
  7813.             if (NPCID == 554) {
  7814.                 PutNPCCoords = true;
  7815.                 WanneShop = 4;
  7816.             }
  7817.             if (NPCID == 553) {
  7818.                 PutNPCCoords = true;
  7819.                 WanneShop = 5;
  7820.             }
  7821.             if (NPCID == 541) {
  7822.                 PutNPCCoords = true;
  7823.                 WanneShop = 7;
  7824.             }
  7825.  
  7826.             if (NPCID == 1597) {
  7827.                 PutNPCCoords = true;
  7828.                 WanneShop = 41;
  7829.             }
  7830.             if (NPCID == 959) {
  7831.                 sM("You have been healed.");
  7832.                 lowGFX(436, 0);
  7833.                 currentHealth += 10;
  7834.                 if (currentHealth > playerLevel[playerHitpoints])
  7835.                     currentHealth = playerLevel[playerHitpoints];
  7836.                 sendQuest("" + currentHealth + "", 4016);
  7837.             }
  7838.             if (NPCID == 534) {
  7839.                 PutNPCCoords = true;
  7840.                 WanneShop = 42;
  7841.             }
  7842.             if (NPCID == 594) {
  7843.                 PutNPCCoords = true;
  7844.                 WanneShop = 17;
  7845.             }
  7846.             if (NPCID == 569) {
  7847.                 PutNPCCoords = true;
  7848.                 WanneShop = 8;
  7849.             }
  7850.             if (NPCID == 3789) {
  7851.                 PutNPCCoords = true;
  7852.                 WanneShop = 44;
  7853.             }
  7854.             if (NPCID == 683) {
  7855.                 PutNPCCoords = true;
  7856.                 WanneShop = 33;
  7857.             }
  7858.             if (NPCID == 682) {
  7859.                 PutNPCCoords = true;
  7860.                 WanneShop = 3;
  7861.             }
  7862.  
  7863.             if ((NPCID == 494) || (NPCID == 495) || (NPCID == 496)
  7864.                     || (NPCID == 497) || (NPCID == 2354) || (NPCID == 2355)
  7865.                     || (NPCID == 2619) || (NPCID == 3198)) {
  7866.                 /* Banking */
  7867.                 WanneBank = 2;
  7868.             }
  7869.             if (NPCID == 3789) {
  7870.                 PutNPCCoords = true;
  7871.                 WanneShop = 44;
  7872.             }
  7873.             if (NPCID == 683) {
  7874.                 PutNPCCoords = true;
  7875.                 WanneShop = 33;
  7876.             }
  7877.             if (NPCID == 682) {
  7878.                 PutNPCCoords = true;
  7879.                 WanneShop = 3;
  7880.  
  7881.             }
  7882.             if (NPCID == 461) {
  7883.                 // Magic store owner shop -bakatool
  7884.                 PutNPCCoords = true;
  7885.                 WanneShop = 39; // Magic store owner shop
  7886.             }
  7887.             if (NPCID == 553) {
  7888.                 // Aubury rune shop
  7889.                 PutNPCCoords = true;
  7890.                 WanneShop = 2; // Aubury Magic Shop
  7891.  
  7892.             }
  7893.             if ((NPCID == 526) || (NPCID == 527)) {
  7894.                 // Shop Keeper + Assistant
  7895.                 PutNPCCoords = true;
  7896.                 WanneShop = 3; // Falador General Store
  7897.             }
  7898.             if (NPCID == 1039) {
  7899.                 // robe seller
  7900.                 PutNPCCoords = true;
  7901.                 WanneShop = 38;
  7902.             }
  7903.             if (NPCID == 577) {
  7904.                 // Cassie
  7905.                 PutNPCCoords = true;
  7906.                 WanneShop = 4; // Falador Shield Shop
  7907.             }
  7908.             if (NPCID == 580) {
  7909.                 // Flynn
  7910.                 PutNPCCoords = true;
  7911.                 WanneShop = 5; // Falador Mace Shop
  7912.             }
  7913.             if (NPCID == 538) {
  7914.                 // Peksa
  7915.                 PutNPCCoords = true;
  7916.                 WanneShop = 8; // Barbarian Vullage Helmet Shop
  7917.             }
  7918.             if (NPCID == 546) {
  7919.                 // Zaff
  7920.                 PutNPCCoords = true;
  7921.                 WanneShop = 24; // Varrock Staff Shop
  7922.  
  7923.             }
  7924.             if (NPCID == 548) { // Thessalia PutNPCCoords = true;
  7925.                 WanneShop = 7; // Varrock Cloth shop
  7926.  
  7927.             }
  7928.             if ((NPCID == 551) || (NPCID == 552)) {
  7929.                 // Shop Keeper + Assistant
  7930.                 PutNPCCoords = true;
  7931.                 WanneShop = 9; // Varrock Sword shop
  7932.             }
  7933.             if (NPCID == 549) {
  7934.                 // Horvik
  7935.                 PutNPCCoords = true;
  7936.                 WanneShop = 10; // Varrock Armor shop
  7937.             }
  7938.             if (NPCID == 550) {
  7939.                 // Lowe
  7940.                 PutNPCCoords = true;
  7941.                 WanneShop = 11; // Varrock Armor shop
  7942.             }
  7943.             if (NPCID == 520) {
  7944.                 // Heruin
  7945.                 PutNPCCoords = true;
  7946.                 WanneShop = 12; // Falador Gem Shop
  7947.             }
  7948.             if (NPCID == 581) {
  7949.                 // Wayne
  7950.                 PutNPCCoords = true;
  7951.                 WanneShop = 32; // Falador Chainmail Shop
  7952.             }
  7953.             if (NPCID == 585) {
  7954.                 // Rommik
  7955.                 PutNPCCoords = true;
  7956.                 WanneShop = 9; // Rimmington Crafting Shop
  7957.             }
  7958.             if ((NPCID == 531) || (NPCID == 530)) {
  7959.                 // Shop Keeper + Assistant
  7960.                 PutNPCCoords = true;
  7961.                 WanneShop = 15; // Rimmington General Store
  7962.             }
  7963.             if (NPCID == 1860) {
  7964.                 // Brian
  7965.                 PutNPCCoords = true;
  7966.                 WanneShop = 23; // Rimmington Archery Shop
  7967.             }
  7968.             if (NPCID == 557) {
  7969.                 // Wydin
  7970.                 PutNPCCoords = true;
  7971.                 WanneShop = 17; // Port Sarim Food Shop
  7972.             }
  7973.             if (NPCID == 559) {
  7974.                 // Brian
  7975.                 PutNPCCoords = true;
  7976.                 WanneShop = 19; // Port Sarim Battleaxe Shop
  7977.             }
  7978.             if (NPCID == 583) {
  7979.                 // Betty
  7980.                 PutNPCCoords = true;
  7981.                 WanneShop = 21; // Port Sarim Magic Shop
  7982.             }
  7983.             if ((NPCID == 520) || (NPCID == 521)) {
  7984.                 // Shop Keeper + Assistant
  7985.                 PutNPCCoords = true;
  7986.                 WanneShop = 22; // Lumbridge General Store
  7987.             }
  7988.             if (NPCID == 519) {
  7989.                 PutNPCCoords = true;
  7990.                 WanneShop = 26;
  7991.             }
  7992.             if (NPCID == 541) {
  7993.                 // Zeke
  7994.                 PutNPCCoords = true;
  7995.                 WanneShop = 13; // Al-Kharid Scimitar Shop
  7996.             }
  7997.             if (NPCID == 545) {
  7998.                 // Dommik
  7999.                 PutNPCCoords = true;
  8000.                 WanneShop = 25; // Al-Kharid Crafting Shop
  8001.             }
  8002.             if ((NPCID == 524) || (NPCID == 525)) {
  8003.                 // Shop Keeper + Assistant
  8004.                 PutNPCCoords = true;
  8005.                 WanneShop = 26; // Al-Kharid General Store
  8006.             }
  8007.             if (NPCID == 542) {
  8008.                 // Louie Legs
  8009.                 PutNPCCoords = true;
  8010.                 WanneShop = 27; // Al-Kharid Legs Shop
  8011.             }
  8012.             if (NPCID == 2621) {
  8013.                 // Hur-Koz
  8014.                 PutNPCCoords = true;
  8015.                 WanneShop = 29; // TzHaar Shop Weapons,Amour
  8016.             }
  8017.             if (NPCID == 2622) {
  8018.                 // Hur-Lek
  8019.                 PutNPCCoords = true;
  8020.                 WanneShop = 30; // TzHaar Shop Runes
  8021.             }
  8022.             if (NPCID == 2620) {
  8023.                 // Hur-Tel
  8024.                 PutNPCCoords = true;
  8025.                 WanneShop = 8; // TzHaar Shop General Store
  8026.             }
  8027.             if (NPCID == 692) {
  8028.                 // Throwing shop
  8029.                 PutNPCCoords = true;
  8030.                 WanneShop = 32; // Authentic Throwing Weapons
  8031.             }
  8032.             if (NPCID == 537) {
  8033.                 // Scavvo
  8034.                 PutNPCCoords = true;
  8035.                 WanneShop = 45; // Champion's Rune shop
  8036.             }
  8037.             if (NPCID == 536) {
  8038.                 // Valaine
  8039.                 PutNPCCoords = true;
  8040.                 WanneShop = 36; // Champion's guild shop
  8041.             }
  8042.             if (NPCID == 933) {
  8043.                 // Legend's Shop
  8044.                 PutNPCCoords = true;
  8045.                 WanneShop = 37; // Legend's Shop
  8046.             }
  8047.             if (NPCID == 932) {
  8048.                 // Legends General Store
  8049.                 PutNPCCoords = true;
  8050.                 WanneShop = 42; // Legend's Gen. Store
  8051.             }
  8052.             if (NPCID == 804) {
  8053.                 PutNPCCoords = true;
  8054.                 WanneShop = 25; // Crafting shop
  8055.             }
  8056.             /**
  8057.              *End of of NPC Shops Second Click
  8058.              */
  8059.             if (PutNPCCoords == true) {
  8060.                 skillX = Server.npcHandler.npcs[NPCSlot].absX;
  8061.                 skillY = Server.npcHandler.npcs[NPCSlot].absY;
  8062.             }
  8063.  
  8064.             break;
  8065.  
  8066.         case 21:
  8067.             // third Click npc
  8068.             NPCSlot = inStream.readSignedWord();
  8069.  
  8070.             NPCID = Server.npcHandler.npcs[NPCSlot].npcType;
  8071.             if ((NPCID < Server.npcHandler.npcs.length) && (NPCID > 0)) {
  8072.                 if (NPCID == 1526) {
  8073.                     openUpShop(19);
  8074.                 } else {
  8075.                     faceNPC(NPCSlot);
  8076.                 }
  8077.             }
  8078.             break;
  8079.  
  8080.         case 72:
  8081.             // Click to attack
  8082.             if (!antiHax())
  8083.                 break;
  8084.             if (deathStage < 1) {
  8085.                 attacknpc = inStream.readUnsignedWordA();
  8086.                 boolean UseBow = false;
  8087.                 if (playerEquipment[playerWeapon] == 839
  8088.                         || playerEquipment[playerWeapon] == 841
  8089.                         || playerEquipment[playerWeapon] == 843
  8090.                         || playerEquipment[playerWeapon] == 845
  8091.                         || playerEquipment[playerWeapon] == 847
  8092.                         || playerEquipment[playerWeapon] == 849
  8093.                         || playerEquipment[playerWeapon] == 851
  8094.                         || playerEquipment[playerWeapon] == 853
  8095.                         || playerEquipment[playerWeapon] == 855
  8096.                         || playerEquipment[playerWeapon] == 857
  8097.                         || playerEquipment[playerWeapon] == 837
  8098.                         || playerEquipment[playerWeapon] == 861
  8099.                         || playerEquipment[playerWeapon] == 4734
  8100.                         || playerEquipment[playerWeapon] == 859
  8101.                         || playerEquipment[playerWeapon] == 4827
  8102.                         || hasCrystalBow()
  8103.                         || playerEquipment[playerWeapon] == 6522
  8104.                         || playerEquipment[playerWeapon] == 1381
  8105.                         || playerEquipment[playerWeapon] == 1383
  8106.                         || playerEquipment[playerWeapon] == 1385
  8107.                         || playerEquipment[playerWeapon] == 1387
  8108.                         || playerEquipment[playerWeapon] == 4675) {
  8109.                     UseBow = true;
  8110.                 }
  8111.                 if (Server.npcHandler.npcs[attacknpc].hitIDNPC != 0
  8112.                         && Server.npcHandler.npcs[attacknpc].hitIDNPC != playerId
  8113.                         && !multiCombat()) {
  8114.                     sM("Someone else is already fighting your opponent.");
  8115.                     faceNPC(attacknpc);
  8116.                     break;
  8117.                 }
  8118.                 if (hitID != attacknpc && hitID != 0 && !multiCombat()) {
  8119.                     sM("I'm already under attack.");
  8120.                     faceNPC(attacknpc);
  8121.                     break;
  8122.                 }
  8123.                 if (Server.npcHandler.npcs[attacknpc].npcType == 655)
  8124.                     break;
  8125.                 if (Server.npcHandler.npcs[attacknpc].npcType == 757
  8126.                         && !playerHasItem(1550, 1)) {
  8127.                     sM("The vampire is not effected by your attacks.");
  8128.                     break;
  8129.                 }
  8130.                 if (Server.npcHandler.npcs[attacknpc].npcType == 757)
  8131.                     break;
  8132.                 if (Server.npcHandler.npcs[attacknpc].npcType == 1472)
  8133.                     break;
  8134.                 if (Server.npcHandler.npcs[attacknpc].npcType == 84)
  8135.                     break;
  8136.                 if (Server.npcHandler.npcs[attacknpc].npcType == 2060)
  8137.                     break;
  8138.                 if (Server.npcHandler.npcs[attacknpc].npcType == 988)
  8139.                     break;
  8140.                 if (Server.npcHandler.npcs[attacknpc].npcType == 989) {
  8141.                     sM("You must beat the first knight first!");
  8142.                     break;
  8143.                 }
  8144.                 if (Server.npcHandler.npcs[attacknpc].npcType == 990) {
  8145.                     sM("You must beat the second knight first!");
  8146.                     break;
  8147.                 }
  8148.                 if (UseBow) {
  8149.                     toX = absX;
  8150.                     toY = absY;
  8151.                     newWalkCmdSteps = 0;
  8152.                     newWalkCmdX[0] = newWalkCmdY[0] = tmpNWCX[0] = tmpNWCY[0] = 0;
  8153.                     getNextPlayerMovement();
  8154.                 }
  8155.                 if (!UseBow
  8156.                         && Server.npcHandler.npcs[attacknpc].npcType != 3777
  8157.                         && Server.npcHandler.npcs[attacknpc].npcType != 3778
  8158.                         && Server.npcHandler.npcs[attacknpc].npcType != 3779
  8159.                         && Server.npcHandler.npcs[attacknpc].npcType != 3780
  8160.                         && Server.npcHandler.npcs[attacknpc].npcType != 2627
  8161.                         && Server.npcHandler.npcs[attacknpc].npcType != 2630
  8162.                         && Server.npcHandler.npcs[attacknpc].npcType != 2631
  8163.                         && Server.npcHandler.npcs[attacknpc].npcType != 2741
  8164.                         && Server.npcHandler.npcs[attacknpc].npcType != 2743
  8165.                         && Server.npcHandler.npcs[attacknpc].npcType != 2745
  8166.                         && Server.npcHandler.npcs[attacknpc].npcType != 2746
  8167.                         && Server.npcHandler.npcs[attacknpc].npcType != 2738) {
  8168.                     followID2 = attacknpc;
  8169.                 }
  8170.                 if ((attacknpc >= 0) && (attacknpc < NPCHandler.maxNPCSpawns)) {
  8171.                     IsAttackingNPC = true;
  8172.  
  8173.                     if (Server.npcHandler.npcs[attacknpc].StartKilling == 0) {
  8174.                         Server.npcHandler.npcs[attacknpc].StartKilling = playerId;
  8175.                     }
  8176.                     Server.npcHandler.npcs[attacknpc].RandomWalk = false;
  8177.                     Server.npcHandler.npcs[attacknpc].IsUnderAttack = true;
  8178.                     faceNPC(attacknpc);
  8179.                 } else {
  8180.                     sM("Exception catched, npc id was invalid.");
  8181.                     ResetAttackNPC();
  8182.                 }
  8183.             }
  8184.             break;
  8185.  
  8186.         case 121:
  8187.             replaceDoors();
  8188.             // if(heightLevel == 1)
  8189.             // ReplaceObject(2591, 3107, 375, -3, 11);
  8190.             // we could use this to make the char appear for other players only
  8191.             // until
  8192.             // this guys loading is done. Also wait with regular player updates
  8193.             // until we receive this command.
  8194.             // println_debug("Loading finished.");
  8195.             Deleteobjects();
  8196.             NewObjects();
  8197.             hasntLoggedin = true;
  8198.             // server.checkPlayerCapes.processAll(this);
  8199.             if (!isInWilderness(absX, absY, 1)) {
  8200.                 setInterfaceWalkable(-1);
  8201.                 hasWildySign = false;
  8202.             }
  8203.             break;
  8204.  
  8205.         case 122:
  8206.             // Call for burying bones
  8207.             junk = inStream.readSignedWordBigEndianA();
  8208.             ItemSlot = inStream.readUnsignedWordA();
  8209.             ItemID = inStream.readUnsignedWordBigEndian();
  8210.             Server.UseItem.buryItem(ItemID, ItemSlot, playerId);
  8211.  
  8212.             /**
  8213.              * Start of Herb Identification
  8214.              */
  8215.             if (System.currentTimeMillis() - lastAction > actionInterval) {
  8216.                 actionInterval = 1800;
  8217.                 lastAction = System.currentTimeMillis();
  8218.                 switch (ItemID) {
  8219.  
  8220.                 case 199: // Guam Leaf Indentifier
  8221.                     if (playerLevel[15] >= 1) {
  8222.                         deleteItem(199, 1);
  8223.                         sM("You indentify the herb, it's a Guam Leaf");
  8224.                         addItem(249, 1);
  8225.                         addSkillXP(100, 15);
  8226.                     }
  8227.  
  8228.                     break;
  8229.                 case 201: // Marentill Indentifier
  8230.                     if (playerLevel[15] >= 5) {
  8231.                         deleteItem(201, 1);
  8232.                         sM("You indentify the herb, it's a Marrentill");
  8233.                         addItem(251, 1);
  8234.                         addSkillXP(200, 15);
  8235.                     } else {
  8236.                         sM("You need a Herblore Level of 5 to indentify this");
  8237.                     }
  8238.  
  8239.                     break;
  8240.                 case 203: // Tarromin Indentifier
  8241.                     if (playerLevel[15] >= 11) {
  8242.                         deleteItem(203, 1);
  8243.                         sM("You indentify the herb, it's a Tarromin");
  8244.                         addItem(253, 1);
  8245.                         addSkillXP(400, 15);
  8246.                     } else {
  8247.                         sM("You need a Herblore Level of 11 to indentify this");
  8248.                     }
  8249.                     break;
  8250.                 case 205: // Harralander Indentifier
  8251.                     if (playerLevel[15] >= 20) {
  8252.                         deleteItem(205, 1);
  8253.                         sM("You indentify the herb, it's a Harralander");
  8254.                         addItem(255, 1);
  8255.                         addSkillXP(800, 15);
  8256.                     } else {
  8257.                         sM("You need a Herblore Level of 20 to indentify this");
  8258.                     }
  8259.                     break;
  8260.                 case 207: // Ranarr Weed Indentifier
  8261.                     if (playerLevel[15] >= 25) {
  8262.                         deleteItem(207, 1);
  8263.                         sM("You indentify the herb, it's a Ranarr Weed");
  8264.                         addItem(257, 1);
  8265.                         addSkillXP(1600, 15);
  8266.                     } else {
  8267.                         sM("You need a Herblore Level of 25 to indentify this");
  8268.                     }
  8269.                     break;
  8270.  
  8271.                 case 209: // Irit Leaf Indentifier
  8272.                     if (playerLevel[15] >= 40) {
  8273.                         deleteItem(209, 1);
  8274.                         sM("You indentify the herb, it's an Irit Leaf");
  8275.                         addItem(259, 1);
  8276.                         addSkillXP(3200, 15);
  8277.                     } else {
  8278.                         sM("You need a Herblore Level of 40 to indentify this");
  8279.                     }
  8280.                     break;
  8281.                 case 211: // Avantoe Indentifier
  8282.                     if (playerLevel[15] >= 48) {
  8283.                         deleteItem(211, 1);
  8284.                         sM("You indentify the herb, it's an Avantoe");
  8285.                         addItem(261, 1);
  8286.                         addSkillXP(6400, 15);
  8287.                     } else {
  8288.                         sM("You need a Herblore Level of 48 to indentify this");
  8289.                     }
  8290.                     break;
  8291.                 case 213: // Kwuarm Indentifier
  8292.                     if (playerLevel[15] >= 54) {
  8293.                         deleteItem(213, 1);
  8294.                         sM("You indentify the herb, it's a Kwuarm");
  8295.                         addItem(263, 1);
  8296.                         addSkillXP(12800, 15);
  8297.                     } else {
  8298.                         sM("You need a Herblore Level of 54 to indentify this");
  8299.                     }
  8300.                     break;
  8301.                 case 215: // Cadantine Indentifier
  8302.                     if (playerLevel[15] >= 65) {
  8303.                         deleteItem(215, 1);
  8304.                         sM("You indentify the herb, it's a Cadantine");
  8305.                         addItem(265, 1);
  8306.                         addSkillXP(25600, 15);
  8307.                     } else {
  8308.                         sM("You need a Herblore Level of 65 to indentify this");
  8309.                     }
  8310.                     break;
  8311.                 case 217: // Dwarf Weed Indentifier
  8312.                     if (playerLevel[15] >= 70) {
  8313.                         deleteItem(217, 1);
  8314.                         sM("You indentify the herb, it's a Dwarf Weed");
  8315.                         addItem(267, 1);
  8316.                         addSkillXP(51200, 15);
  8317.                     } else {
  8318.                         sM("You need a Herblore Level of 70 to indentify this");
  8319.                     }
  8320.                     break;
  8321.                 case 219: // Torstol Indentifier
  8322.                     if (playerLevel[15] >= 75) {
  8323.                         deleteItem(219, 1);
  8324.                         sM("You indentify the herb, it's a Torstol");
  8325.                         addItem(269, 1);
  8326.                         addSkillXP(102400, 15);
  8327.                     } else {
  8328.                         sM("You need a Herblore Level of 75 to indentify this");
  8329.                     }
  8330.                     break;
  8331.                 }
  8332.             }
  8333.             /**
  8334.              *End of Identifying
  8335.              */
  8336.             break;
  8337.  
  8338.         case 53:
  8339.             // Use item on item
  8340.             int usedWithSlot = inStream.readUnsignedWord();
  8341.             int itemUsedSlot = inStream.readUnsignedWordA();
  8342.             int useWith = playerItems[usedWithSlot] - 1;
  8343.             int itemUsed = playerItems[itemUsedSlot] - 1;
  8344.             if (useWith == -1 || itemUsed == -1) {
  8345.                 break;
  8346.             }
  8347.  
  8348.             potionLoop: for (int i2 = 0; i2 < potions.length; i2++) {
  8349.                 for (int i3 = 1; i3 < potions[i2].length; i3++) {
  8350.                     if (itemUsed == potions[i2][i3]) {
  8351.                         for (int i4 = 1; i4 < potions[i2].length; i4++) {
  8352.                             if (useWith == potions[i2][i4]) {
  8353.                                 int newDosage1 = 0;
  8354.                                 int newDosage2 = i3 + i4;
  8355.                                 if (newDosage2 >= potions[i2].length) {
  8356.                                     newDosage1 = (newDosage2)
  8357.                                             - (potions[i2].length - 1);
  8358.                                     newDosage2 = potions[i2].length - 1;
  8359.                                 }
  8360.                                 playerItems[itemUsedSlot] = potions[i2][newDosage1] + 1;
  8361.                                 playerItems[usedWithSlot] = potions[i2][newDosage2] + 1;
  8362.                                 resetItems(3214);
  8363.                                 break potionLoop;
  8364.                             }
  8365.                         }
  8366.                         break potionLoop;
  8367.                     }
  8368.                 }
  8369.             }
  8370.  
  8371.             /**
  8372.              * Start of Gem cutting
  8373.              */
  8374.             // Sapphire
  8375.             if (itemUsed == 1755 && useWith == 1623 || itemUsed == 2623
  8376.                     && useWith == 1755) {
  8377.                 if (playerLevel[12] >= 20) {
  8378.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8379.                         actionInterval = 2800;
  8380.                         lastAction = System.currentTimeMillis();
  8381.                         setAnimation(888);
  8382.                         deleteItem(1623, 1);
  8383.                         addItem(1607, 1);
  8384.                         addSkillXP(1000, 12);
  8385.                         sM("You cut the Sapphire");
  8386.                     }
  8387.                 } else {
  8388.                     // sM("You need a Crafting Level of 20 to cut a Sapphire");
  8389.                 }
  8390.             }
  8391.  
  8392.             // Emerald
  8393.             if (itemUsed == 1755 && useWith == 1621 || itemUsed == 1621
  8394.                     && useWith == 1755) {
  8395.                 if (playerLevel[12] >= 27) {
  8396.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8397.                         actionInterval = 2800;
  8398.                         lastAction = System.currentTimeMillis();
  8399.                         deleteItem(1621, 1);
  8400.                         setAnimation(889);
  8401.                         addItem(1605, 1);
  8402.                         addSkillXP(2000, 12);
  8403.                         sM("You cut the Emerald");
  8404.                     }
  8405.                 } else {
  8406.                     sM("You need a Crafting Level of 27 to cut an Emerald");
  8407.                 }
  8408.             }
  8409.             // Ruby
  8410.             if (itemUsed == 1755 && useWith == 1619 || itemUsed == 1619
  8411.                     && useWith == 1755) {
  8412.                 if (playerLevel[12] >= 34) {
  8413.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8414.                         actionInterval = 2800;
  8415.                         lastAction = System.currentTimeMillis();
  8416.                         deleteItem(1619, 1);
  8417.                         setAnimation(887);
  8418.                         addItem(1603, 1);
  8419.                         addSkillXP(4000, 12);
  8420.                         sM("You cut the Ruby");
  8421.                     }
  8422.                 } else {
  8423.                     sM("You need a Crafting Level of 34 to cut an Emerald");
  8424.                 }
  8425.             }
  8426.             // Diamond
  8427.             if (itemUsed == 1755 && useWith == 1617 || itemUsed == 1617
  8428.                     && useWith == 1755) {
  8429.                 if (playerLevel[12] >= 43) {
  8430.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8431.                         actionInterval = 2800;
  8432.                         lastAction = System.currentTimeMillis();
  8433.                         deleteItem(1617, 1);
  8434.                         setAnimation(886);
  8435.                         addItem(1601, 1);
  8436.                         addSkillXP(8000, 12);
  8437.                         sM("You cut the Diamond");
  8438.                     }
  8439.                 } else {
  8440.                     sM("You need a Crafting Level of 43 to cut an Diamond");
  8441.                 }
  8442.             }
  8443.             // DragonStone
  8444.             if (itemUsed == 1755 && useWith == 1631 || itemUsed == 1631
  8445.                     && useWith == 1755) {
  8446.                 if (playerLevel[12] >= 55) {
  8447.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8448.                         actionInterval = 2800;
  8449.                         lastAction = System.currentTimeMillis();
  8450.                         deleteItem(1631, 1);
  8451.                         setAnimation(885);
  8452.                         addItem(1615, 1);
  8453.                         addSkillXP(16000, 12);
  8454.                         sM("You cut the DragonStone");
  8455.                     }
  8456.                 } else {
  8457.                     sM("You need a Crafting Level of 55 to cut a DragonStone");
  8458.                 }
  8459.             }
  8460.             // Onyx
  8461.             if (itemUsed == 1755 && useWith == 6571 || itemUsed == 6571
  8462.                     && useWith == 1755) {
  8463.                 if (playerLevel[12] >= 67) {
  8464.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8465.                         actionInterval = 2800;
  8466.                         lastAction = System.currentTimeMillis();
  8467.                         deleteItem(6571, 1);
  8468.                         setAnimation(2717);
  8469.                         addItem(6573, 1);
  8470.                         addSkillXP(32000, 12);
  8471.                         sM("You cut the Onyx");
  8472.                     }
  8473.                 } else {
  8474.                     sM("You need a Crafting Level of 67 to cut an Onyx");
  8475.                 }
  8476.             }
  8477.             /*
  8478.              * End of Gem Cutting
  8479.              */
  8480.  
  8481.             /**
  8482.              * Start of Herblore potion making
  8483.              */
  8484.             // Guam used on Vial
  8485.             if (itemUsed == 227 && useWith == 249 || itemUsed == 249
  8486.                     && useWith == 227) {
  8487.                 if (playerLevel[15] >= 1) {
  8488.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8489.                         actionInterval = 2800;
  8490.                         lastAction = System.currentTimeMillis();
  8491.                         deleteItem(227, 1);
  8492.                         deleteItem(249, 1);
  8493.                         setAnimation(3283);
  8494.                         addItem(91, 1);
  8495.                         sM("You combine the ingredients together to form an unfinished potion");
  8496.                     }
  8497.                 }
  8498.             }
  8499.             // Marrentill used on Vial
  8500.             if (itemUsed == 227 && useWith == 251 || itemUsed == 251
  8501.                     && useWith == 227) {
  8502.                 if (playerLevel[15] >= 5) {
  8503.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8504.                         actionInterval = 2800;
  8505.                         lastAction = System.currentTimeMillis();
  8506.                         deleteItem(227, 1);
  8507.                         deleteItem(251, 1);
  8508.                         setAnimation(3283);
  8509.                         addItem(93, 1);
  8510.                         sM("You combine the ingredients together to form an unfinished potion");
  8511.                     }
  8512.                 } else {
  8513.                     sM("You need an Herblore Level of 5 to make this");
  8514.                 }
  8515.             }
  8516.  
  8517.             // Tarromin used on Vial
  8518.             if (itemUsed == 227 && useWith == 253 || itemUsed == 253
  8519.                     && useWith == 227) {
  8520.                 if (playerLevel[15] >= 12) {
  8521.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8522.                         actionInterval = 2800;
  8523.                         lastAction = System.currentTimeMillis();
  8524.                         deleteItem(227, 1);
  8525.                         deleteItem(253, 1);
  8526.                         setAnimation(3283);
  8527.                         addItem(95, 1);
  8528.                         sM("You combine the ingredients together to form an unfinished potion");
  8529.                     }
  8530.                 } else {
  8531.                     sM("You need an Herblore Level of 12 to make this");
  8532.                 }
  8533.             }
  8534.  
  8535.             // Harralander Weed used on Vial
  8536.             if (itemUsed == 227 && useWith == 255 || itemUsed == 255
  8537.                     && useWith == 227) {
  8538.                 if (playerLevel[15] >= 22) {
  8539.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8540.                         actionInterval = 2800;
  8541.                         lastAction = System.currentTimeMillis();
  8542.                         deleteItem(227, 1);
  8543.                         deleteItem(255, 1);
  8544.                         setAnimation(3283);
  8545.                         addItem(97, 1);
  8546.                         sM("You combine the ingredients together to form an unfinished potion");
  8547.                     }
  8548.                 } else {
  8549.                     sM("You need an Herblore Level of 22 to make this");
  8550.                 }
  8551.             }
  8552.  
  8553.             // Ranarr Weed used on Vial
  8554.             if (itemUsed == 227 && useWith == 257 || itemUsed == 257
  8555.                     && useWith == 227) {
  8556.                 if (playerLevel[15] >= 30) {
  8557.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8558.                         actionInterval = 2800;
  8559.                         lastAction = System.currentTimeMillis();
  8560.                         deleteItem(227, 1);
  8561.                         deleteItem(257, 1);
  8562.                         setAnimation(3283);
  8563.                         addItem(99, 1);
  8564.                         sM("You combine the ingredients together to form an unfinished potion");
  8565.                     }
  8566.                 } else {
  8567.                     sM("You need an Herblore Level of 30 to make this");
  8568.                 }
  8569.             }
  8570.  
  8571.             // Irit Leaf used on Vial
  8572.             if (itemUsed == 227 && useWith == 259 || itemUsed == 259
  8573.                     && useWith == 227) {
  8574.                 if (playerLevel[15] >= 45) {
  8575.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8576.                         actionInterval = 2800;
  8577.                         lastAction = System.currentTimeMillis();
  8578.                         deleteItem(227, 1);
  8579.                         deleteItem(259, 1);
  8580.                         setAnimation(3283);
  8581.                         addItem(101, 1);
  8582.                         sM("You combine the ingredients together to form an unfinished potion");
  8583.                     }
  8584.                 } else {
  8585.                     sM("You need an Herblore Level of 45 to make this");
  8586.                 }
  8587.             }
  8588.             // Avantoe used on Vial
  8589.             if (itemUsed == 227 && useWith == 261 || itemUsed == 261
  8590.                     && useWith == 227) {
  8591.                 if (playerLevel[15] >= 52) {
  8592.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8593.                         actionInterval = 2800;
  8594.                         lastAction = System.currentTimeMillis();
  8595.                         deleteItem(227, 1);
  8596.                         deleteItem(261, 1);
  8597.                         setAnimation(3283);
  8598.                         addItem(103, 1);
  8599.                         sM("You combine the ingredients together to form an unfinished potion");
  8600.                     }
  8601.                 } else {
  8602.                     sM("You need an Herblore Level of 52 to make this");
  8603.                 }
  8604.             }
  8605.             // Kwuarm used on Vial
  8606.             if (itemUsed == 227 && useWith == 263 || itemUsed == 263
  8607.                     && useWith == 227) {
  8608.                 if (playerLevel[15] >= 55) {
  8609.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8610.                         actionInterval = 2800;
  8611.                         lastAction = System.currentTimeMillis();
  8612.                         deleteItem(227, 1);
  8613.                         deleteItem(263, 1);
  8614.                         setAnimation(3283);
  8615.                         addItem(105, 1);
  8616.                         sM("You combine the ingredients together to form an unfinished potion");
  8617.                     }
  8618.                 } else {
  8619.                     sM("You need an Herblore Level of 55 to make this");
  8620.                 }
  8621.             }
  8622.  
  8623.             // Cadantine used on Vial
  8624.             if (itemUsed == 227 && useWith == 265 || itemUsed == 265
  8625.                     && useWith == 227) {
  8626.                 if (playerLevel[15] >= 66) {
  8627.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8628.                         actionInterval = 2800;
  8629.                         lastAction = System.currentTimeMillis();
  8630.                         deleteItem(227, 1);
  8631.                         deleteItem(265, 1);
  8632.                         setAnimation(3283);
  8633.                         addItem(107, 1);
  8634.                         sM("You combine the ingredients together to form an unfinished potion");
  8635.                     }
  8636.                 } else {
  8637.                     sM("You need an Herblore Level of 66 to make this");
  8638.                 }
  8639.             }
  8640.             // Dwarf Weed used on Vial
  8641.             if (itemUsed == 227 && useWith == 267 || itemUsed == 267
  8642.                     && useWith == 227) {
  8643.                 if (playerLevel[15] >= 72) {
  8644.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8645.                         actionInterval = 2800;
  8646.                         lastAction = System.currentTimeMillis();
  8647.                         deleteItem(227, 1);
  8648.                         deleteItem(267, 1);
  8649.                         setAnimation(3283);
  8650.                         addItem(109, 1);
  8651.                         sM("You combine the ingredients together to form an unfinished potion");
  8652.                     }
  8653.                 } else {
  8654.                     sM("You need an Herblore Level of 72 to make this");
  8655.                 }
  8656.             }
  8657.             // Eye of Newt used on Unfinished Potion
  8658.             if (itemUsed == 221 && useWith == 91 || itemUsed == 91
  8659.                     && useWith == 221) {
  8660.                 if (playerLevel[15] >= 1) {
  8661.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8662.                         actionInterval = 2800;
  8663.                         lastAction = System.currentTimeMillis();
  8664.                         deleteItem(221, 1);
  8665.                         deleteItem(91, 1);
  8666.                         setAnimation(3283);
  8667.                         addItem(121, 1);
  8668.                         addSkillXP(1000, 15);
  8669.                         sM("You add an Eye of Newt to create an Attack Potion");
  8670.                     }
  8671.                 }
  8672.             }
  8673.  
  8674.             // Unicorn horn dust on Unfinished potion
  8675.             if (itemUsed == 235 && useWith == 93 || itemUsed == 93
  8676.                     && useWith == 235) {
  8677.                 if (playerLevel[15] >= 5) {
  8678.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8679.                         actionInterval = 2800;
  8680.                         lastAction = System.currentTimeMillis();
  8681.                         deleteItem(235, 1);
  8682.                         deleteItem(93, 1);
  8683.                         setAnimation(3283);
  8684.                         addItem(175, 1);
  8685.                         addSkillXP(1000, 15);
  8686.                         sM("You add Unicorn horn dust to create an Anti-Posion Potion");
  8687.                     }
  8688.                 } else {
  8689.                     sM("You need an Herblore Level of 5 to make this");
  8690.                 }
  8691.             }
  8692.  
  8693.             // Limpwurt root used on Unfinished potion
  8694.             if (itemUsed == 225 && useWith == 95 || itemUsed == 95
  8695.                     && useWith == 225) {
  8696.                 if (playerLevel[15] >= 12) {
  8697.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8698.                         actionInterval = 2800;
  8699.                         lastAction = System.currentTimeMillis();
  8700.                         deleteItem(221, 1);
  8701.                         deleteItem(95, 1);
  8702.                         setAnimation(3283);
  8703.                         addItem(113, 1);
  8704.                         addSkillXP(1000, 15);
  8705.                         sM("You add Limpwurt root to create an Strength Potion");
  8706.                     }
  8707.                 } else {
  8708.                     sM("You need an Herblore Level of 12 to make this");
  8709.                 }
  8710.             }
  8711.             // Red spider eggs root used on Unfinished potion
  8712.             if (itemUsed == 223 && useWith == 97 || itemUsed == 97
  8713.                     && useWith == 223) {
  8714.                 if (playerLevel[15] >= 22) {
  8715.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8716.                         actionInterval = 2800;
  8717.                         lastAction = System.currentTimeMillis();
  8718.                         deleteItem(223, 1);
  8719.                         deleteItem(97, 1);
  8720.                         setAnimation(3283);
  8721.                         addItem(127, 1);
  8722.                         addSkillXP(1000, 15);
  8723.                         sM("You add Red Spider eggs to create a Restore Potion");
  8724.                     }
  8725.                 } else {
  8726.                     sM("You need an Herblore Level of 22 to make this");
  8727.                 }
  8728.             }
  8729.  
  8730.             // White berries used on Unfinished potion
  8731.             if (itemUsed == 239 && useWith == 99 || itemUsed == 99
  8732.                     && useWith == 239) {
  8733.                 if (playerLevel[15] >= 30) {
  8734.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8735.                         actionInterval = 2800;
  8736.                         lastAction = System.currentTimeMillis();
  8737.                         deleteItem(239, 1);
  8738.                         deleteItem(99, 1);
  8739.                         setAnimation(3283);
  8740.                         addItem(134, 1);
  8741.                         addSkillXP(1000, 15);
  8742.                         sM("You add White berries to create a Defence Potion");
  8743.                     }
  8744.                 } else {
  8745.                     sM("You need an Herblore Level of 30 to make this");
  8746.                 }
  8747.             }
  8748.  
  8749.             // Snape Grass used on Unfinished potion
  8750.             if (itemUsed == 231 && useWith == 99 || itemUsed == 99
  8751.                     && useWith == 231) {
  8752.                 if (playerLevel[15] >= 38) {
  8753.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8754.                         actionInterval = 2800;
  8755.                         lastAction = System.currentTimeMillis();
  8756.                         deleteItem(231, 1);
  8757.                         deleteItem(99, 1);
  8758.                         setAnimation(3283);
  8759.                         addItem(139, 1);
  8760.                         addSkillXP(1000, 15);
  8761.                         sM("You add Snape Grass to create a Prayer Potion");
  8762.                     }
  8763.                 } else {
  8764.                     sM("You need an Herblore Level of 38 to make this");
  8765.                 }
  8766.             }
  8767.  
  8768.             // Eye of Newt used on Unfinished potion
  8769.             if (itemUsed == 221 && useWith == 101 || itemUsed == 101
  8770.                     && useWith == 221) {
  8771.                 if (playerLevel[15] >= 45) {
  8772.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8773.                         actionInterval = 2800;
  8774.                         lastAction = System.currentTimeMillis();
  8775.                         deleteItem(221, 1);
  8776.                         deleteItem(101, 1);
  8777.                         setAnimation(3283);
  8778.                         addItem(145, 1);
  8779.                         addSkillXP(1000, 15);
  8780.                         sM("You add an Eye of Newt to create an Super Attack Potion");
  8781.                     }
  8782.                 } else {
  8783.                     sM("You need an Herblore Level of 45 to make this");
  8784.                 }
  8785.             }
  8786.  
  8787.             // Limpwurt Root used on Unfinished potion
  8788.             if (itemUsed == 225 && useWith == 103 || itemUsed == 103
  8789.                     && useWith == 225) {
  8790.                 if (playerLevel[15] >= 55) {
  8791.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8792.                         actionInterval = 2800;
  8793.                         lastAction = System.currentTimeMillis();
  8794.                         deleteItem(225, 1);
  8795.                         deleteItem(103, 1);
  8796.                         setAnimation(3283);
  8797.                         addItem(157, 1);
  8798.                         addSkillXP(1000, 15);
  8799.                         sM("You add a Limpwurt Root to create a Super Strength Potion");
  8800.                     }
  8801.                 } else {
  8802.                     sM("You need an Herblore Level of 55 to make this");
  8803.                 }
  8804.             }
  8805.  
  8806.             // Whiteberries used on Unfinished potion
  8807.             if (itemUsed == 239 && useWith == 107 || itemUsed == 107
  8808.                     && useWith == 239) {
  8809.                 if (playerLevel[15] >= 66) {
  8810.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8811.                         actionInterval = 2800;
  8812.                         lastAction = System.currentTimeMillis();
  8813.                         deleteItem(239, 1);
  8814.                         deleteItem(107, 1);
  8815.                         setAnimation(3283);
  8816.                         addItem(163, 1);
  8817.                         addSkillXP(1000, 15);
  8818.                         sM("You add Whiteberries to create a Super Defence Potion");
  8819.                     }
  8820.                 } else {
  8821.                     sM("You need an Herblore Level of 66 to make this");
  8822.                 }
  8823.             }
  8824.  
  8825.             /**
  8826.              *Making Headless Arrows
  8827.              */
  8828.             if (itemUsed == 314 && useWith == 52 || itemUsed == 52
  8829.                     && useWith == 314) {
  8830.                 if (System.currentTimeMillis() - lastAction > actionInterval) {
  8831.                     actionInterval = 300;
  8832.                     lastAction = System.currentTimeMillis();
  8833.                     deleteItem(314, 15);
  8834.                     deleteItem(52, 15);
  8835.                     addItem(53, 15);
  8836.                     addSkillXP(100 * 15, 9);
  8837.                 }
  8838.             }
  8839.  
  8840.             /**
  8841.              *Making Arrows
  8842.              */
  8843.             // Bronze Arrows
  8844.             if (itemUsed == 53 && useWith == 39 || itemUsed == 39
  8845.                     && useWith == 53) {
  8846.                 if (System.currentTimeMillis() - lastAction > actionInterval) {
  8847.                     actionInterval = 300;
  8848.                     lastAction = System.currentTimeMillis();
  8849.                     deleteItem(39, 15);
  8850.                     deleteItem(53, 15);
  8851.                     addItem(882, 15);
  8852.                     addSkillXP(100 * 39, 9);
  8853.                 }
  8854.             }
  8855.             // Iron Arrows
  8856.             if (itemUsed == 53 && useWith == 40 || itemUsed == 40
  8857.                     && useWith == 53) {
  8858.                 if (playerLevel[9] > 14) {
  8859.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8860.                         actionInterval = 300;
  8861.                         lastAction = System.currentTimeMillis();
  8862.                         deleteItem(40, 15);
  8863.                         deleteItem(53, 15);
  8864.                         addItem(884, 15);
  8865.                         addSkillXP(100 * 57, 9);
  8866.                     }
  8867.                 } else {
  8868.                     sM("You need a fletching level of 15 to make these.");
  8869.                 }
  8870.             }
  8871.  
  8872.             // Steel Arrows
  8873.             if (itemUsed == 53 && useWith == 41 || itemUsed == 41
  8874.                     && useWith == 53) {
  8875.                 if (playerLevel[9] > 29) {
  8876.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8877.                         actionInterval = 300;
  8878.                         lastAction = System.currentTimeMillis();
  8879.                         deleteItem(41, 15);
  8880.                         deleteItem(53, 15);
  8881.                         addItem(886, 15);
  8882.                         addSkillXP(100 * 95, 9);
  8883.                     }
  8884.                 } else {
  8885.                     sM("You need a fletching level of 30 to make these.");
  8886.                 }
  8887.             }
  8888.  
  8889.             // Mith Arrows
  8890.             if (itemUsed == 53 && useWith == 42 || itemUsed == 42
  8891.                     && useWith == 53) {
  8892.                 if (playerLevel[9] > 44) {
  8893.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8894.                         actionInterval = 300;
  8895.                         lastAction = System.currentTimeMillis();
  8896.                         deleteItem(42, 15);
  8897.                         deleteItem(53, 15);
  8898.                         addItem(888, 15);
  8899.                         addSkillXP(100 * 132, 9);
  8900.                     }
  8901.                 } else {
  8902.                     sM("You need a fletching level of 45 to make these.");
  8903.                 }
  8904.             }
  8905.  
  8906.             // Addy Arrows
  8907.             if (itemUsed == 53 && useWith == 43 || itemUsed == 43
  8908.                     && useWith == 53) {
  8909.                 if (playerLevel[9] > 59) {
  8910.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8911.                         actionInterval = 300;
  8912.                         lastAction = System.currentTimeMillis();
  8913.                         deleteItem(43, 15);
  8914.                         deleteItem(53, 15);
  8915.                         addItem(890, 15);
  8916.                         addSkillXP(100 * 165, 9);
  8917.                     }
  8918.                 } else {
  8919.                     sM("You need a fletching level of 60 to make these.");
  8920.                 }
  8921.             }
  8922.  
  8923.             // Rune Arrows
  8924.             if (itemUsed == 53 && useWith == 44 || itemUsed == 44
  8925.                     && useWith == 53) {
  8926.                 if (playerLevel[9] > 74) {
  8927.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8928.                         actionInterval = 300;
  8929.                         lastAction = System.currentTimeMillis();
  8930.                         deleteItem(44, 15);
  8931.                         deleteItem(53, 15);
  8932.                         addItem(892, 15);
  8933.                         addSkillXP(100 * 207, 9);
  8934.                     }
  8935.                 } else {
  8936.                     sM("You need a fletching level of 75 to make these.");
  8937.                 }
  8938.             }
  8939.  
  8940.             /**
  8941.              *Stringing bows
  8942.              */
  8943.             // Shortbow
  8944.             if (itemUsed == 1777 && useWith == 50 || itemUsed == 50
  8945.                     && useWith == 1777) {
  8946.                 if (playerLevel[9] > 4) {
  8947.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8948.                         actionInterval = 2000;
  8949.                         lastAction = System.currentTimeMillis();
  8950.                         deleteItem(50, 1);
  8951.                         deleteItem(1777, 1);
  8952.                         addItem(841, 1);
  8953.                         addSkillXP(100 * 10, 9);
  8954.                         sM("You Make a shortbow");
  8955.                     }
  8956.                 } else {
  8957.                     sM("You need to have a fletching level of 5 to make this");
  8958.                 }
  8959.             }
  8960.             // Longbow
  8961.             if (itemUsed == 1777 && useWith == 48 || itemUsed == 48
  8962.                     && useWith == 1777) {
  8963.                 if (playerLevel[9] > 9) {
  8964.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8965.                         actionInterval = 2000;
  8966.                         lastAction = System.currentTimeMillis();
  8967.                         deleteItem(48, 1);
  8968.                         deleteItem(1777, 1);
  8969.                         addItem(839, 1);
  8970.                         addSkillXP(100 * 20, 9);
  8971.                         sM("You Make a Longbow");
  8972.                     }
  8973.                 } else {
  8974.                     sM("You need to have a fletching level of 10 to make this.");
  8975.                 }
  8976.             }
  8977.  
  8978.             // Oak Shortbow
  8979.             if (itemUsed == 1777 && useWith == 54 || itemUsed == 54
  8980.                     && useWith == 1777) {
  8981.                 if (playerLevel[9] > 19) {
  8982.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  8983.                         actionInterval = 2000;
  8984.                         lastAction = System.currentTimeMillis();
  8985.                         deleteItem(54, 1);
  8986.                         deleteItem(1777, 1);
  8987.                         addItem(843, 1);
  8988.                         addSkillXP(100 * 33, 9);
  8989.                         sM("You Make an Oak Shortbow");
  8990.                     }
  8991.                 } else {
  8992.                     sM("You need to have a fletching level of 20 to make this.");
  8993.                 }
  8994.             }
  8995.  
  8996.             // Oak Longbow
  8997.             if (itemUsed == 1777 && useWith == 56 || itemUsed == 56
  8998.                     && useWith == 1777) {
  8999.                 if (playerLevel[9] > 24) {
  9000.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  9001.                         actionInterval = 2000;
  9002.                         lastAction = System.currentTimeMillis();
  9003.                         deleteItem(56, 1);
  9004.                         deleteItem(1777, 1);
  9005.                         addItem(845, 1);
  9006.                         addSkillXP(100 * 50, 9);
  9007.                         sM("You Make an Oak Longbow");
  9008.                     }
  9009.                 } else {
  9010.                     sM("You need to have a fletching level of 25 to make this.");
  9011.                 }
  9012.             }
  9013.  
  9014.             // Willow Shortbow
  9015.             if (itemUsed == 1777 && useWith == 60 || itemUsed == 60
  9016.                     && useWith == 1777) {
  9017.                 if (playerLevel[9] > 34) {
  9018.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  9019.                         actionInterval = 2000;
  9020.                         lastAction = System.currentTimeMillis();
  9021.                         deleteItem(60, 1);
  9022.                         deleteItem(1777, 1);
  9023.                         addItem(849, 1);
  9024.                         addSkillXP(100 * 66, 9);
  9025.                         sM("You Make a Willow Shortbow");
  9026.                     }
  9027.                 } else {
  9028.                     sM("You need to have a fletching level of 35 to make this.");
  9029.                 }
  9030.             }
  9031.  
  9032.             // Willow Longbow
  9033.             if (itemUsed == 1777 && useWith == 58 || itemUsed == 58
  9034.                     && useWith == 1777) {
  9035.                 if (playerLevel[9] > 39) {
  9036.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  9037.                         actionInterval = 2000;
  9038.                         lastAction = System.currentTimeMillis();
  9039.                         deleteItem(58, 1);
  9040.                         deleteItem(1777, 1);
  9041.                         addItem(847, 1);
  9042.                         addSkillXP(100 * 66, 9);
  9043.                         sM("You Make a Willow Longbow");
  9044.                     }
  9045.                 } else {
  9046.                     sM("You need to have a fletching level of 40 to make this.");
  9047.                 }
  9048.             }
  9049.  
  9050.             // Maple Shortbow
  9051.             if (itemUsed == 1777 && useWith == 64 || itemUsed == 64
  9052.                     && useWith == 1777) {
  9053.                 if (playerLevel[9] > 49) {
  9054.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  9055.                         actionInterval = 2000;
  9056.                         lastAction = System.currentTimeMillis();
  9057.                         deleteItem(64, 1);
  9058.                         deleteItem(1777, 1);
  9059.                         addItem(853, 1);
  9060.                         addSkillXP(100 * 100, 9);
  9061.                         sM("You Make a Maple Shortbow");
  9062.                     }
  9063.                 } else {
  9064.                     sM("You need to have a fletching level of 50 to make this.");
  9065.                 }
  9066.             }
  9067.             // Maple Longbow
  9068.             if (itemUsed == 1777 && useWith == 62 || itemUsed == 62
  9069.                     && useWith == 1777) {
  9070.                 if (playerLevel[9] > 54) {
  9071.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  9072.                         actionInterval = 2000;
  9073.                         lastAction = System.currentTimeMillis();
  9074.                         deleteItem(62, 1);
  9075.                         deleteItem(1777, 1);
  9076.                         addItem(851, 1);
  9077.                         addSkillXP(100 * 116, 9);
  9078.                         sM("You Make a Maple Longbow");
  9079.                     }
  9080.                 } else {
  9081.                     sM("You need to have a fletching level of 55 to make this.");
  9082.                 }
  9083.             }
  9084.  
  9085.             // Yew Shortbow
  9086.             if (itemUsed == 1777 && useWith == 68 || itemUsed == 68
  9087.                     && useWith == 1777) {
  9088.                 if (playerLevel[9] > 64) {
  9089.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  9090.                         actionInterval = 2000;
  9091.                         lastAction = System.currentTimeMillis();
  9092.                         deleteItem(68, 1);
  9093.                         deleteItem(1777, 1);
  9094.                         addItem(857, 1);
  9095.                         addSkillXP(100 * 133, 9);
  9096.                         sM("You Make a Yew Shortbow");
  9097.                     }
  9098.                 } else {
  9099.                     sM("You need to have a fletching level of 65 to make this.");
  9100.                 }
  9101.             }
  9102.             // Yew Longbow
  9103.             if (itemUsed == 1777 && useWith == 66 || itemUsed == 66
  9104.                     && useWith == 1777) {
  9105.                 if (playerLevel[9] > 69) {
  9106.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  9107.                         actionInterval = 2000;
  9108.                         lastAction = System.currentTimeMillis();
  9109.                         deleteItem(66, 1);
  9110.                         deleteItem(1777, 1);
  9111.                         addItem(855, 1);
  9112.                         addSkillXP(100 * 150, 9);
  9113.                         sM("You Make a Yew Longbow");
  9114.                     }
  9115.                 } else {
  9116.                     sM("You need to have a fletching level of 70 to make this.");
  9117.                 }
  9118.             }
  9119.  
  9120.             // Magic Shortbow
  9121.             if (itemUsed == 1777 && useWith == 72 || itemUsed == 72
  9122.                     && useWith == 1777) {
  9123.                 if (playerLevel[9] > 79) {
  9124.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  9125.                         actionInterval = 2000;
  9126.                         lastAction = System.currentTimeMillis();
  9127.                         deleteItem(72, 1);
  9128.                         deleteItem(1777, 1);
  9129.                         addItem(861, 1);
  9130.                         addSkillXP(100 * 166, 9);
  9131.                         sM("You Make a Magic Shortbow");
  9132.                     }
  9133.                 } else {
  9134.                     sM("You need to have a fletching level of 80 to make this.");
  9135.                 }
  9136.             }
  9137.             // Magic Longbow
  9138.             if (itemUsed == 1777 && useWith == 70 || itemUsed == 70
  9139.                     && useWith == 1777) {
  9140.                 if (playerLevel[9] > 84) {
  9141.                     if (System.currentTimeMillis() - lastAction > actionInterval) {
  9142.                         actionInterval = 2000;
  9143.                         lastAction = System.currentTimeMillis();
  9144.                         deleteItem(70, 1);
  9145.                         deleteItem(1777, 1);
  9146.                         addItem(859, 1);
  9147.                         addSkillXP(100 * 183, 9);
  9148.                         sM("You Make a Magic Longbow");
  9149.                     }
  9150.                 } else {
  9151.                     sM("You need to have a fletching level of 85 to make this.");
  9152.                 }
  9153.             }
  9154.  
  9155.             /**
  9156.              *Arrow Shafts / Shortbow / Longbow
  9157.              */
  9158.  
  9159.             if (itemUsed == 946 && useWith == 1511) {
  9160.                 fletchShortbow = 0;
  9161.                 fletchLongbow = 0;
  9162.                 RemoveAllWindows();
  9163.                 sendFrame164(8880);
  9164.                 sendFrame246(8883, 250, 50);
  9165.                 sendFrame246(8884, 200, 52);
  9166.                 sendFrame246(8885, 200, 48);
  9167.                 changeText126("Longbow (u)", 8897);
  9168.                 changeText126("Arrow Shaft", 8893);
  9169.                 changeText126("Shortbow (u)", 8889);
  9170.             }
  9171.             /**
  9172.              *Oak Shortbow / Oak Longbow
  9173.              */
  9174.             if (itemUsed == 946 && useWith == 1521) {
  9175.                 fletchShortbow = 1;
  9176.                 fletchLongbow = 1;
  9177.                 RemoveAllWindows();
  9178.                 sendFrame164(8880);
  9179.                 sendFrame246(8883, 250, 54);
  9180.                 sendFrame246(8884, 200, -1);
  9181.                 sendFrame246(8885, 200, 56);
  9182.                 changeText126("Oak Longbow (u)", 8897);
  9183.                 changeText126("", 8893);
  9184.                 changeText126("Oak Shortbow (u)", 8889);
  9185.             }
  9186.  
  9187.             /**
  9188.              *Willow Shortbow / Willow Longbow
  9189.              */
  9190.             if (itemUsed == 946 && useWith == 1519) {
  9191.                 fletchShortbow = 2;
  9192.                 fletchLongbow = 2;
  9193.                 RemoveAllWindows();
  9194.                 sendFrame164(8880);
  9195.                 sendFrame246(8883, 250, 60);
  9196.                 sendFrame246(8884, 200, -1);
  9197.                 sendFrame246(8885, 200, 58);
  9198.                 changeText126("Willow Longbow (u)", 8897);
  9199.                 changeText126("", 8893);
  9200.                 changeText126("Willow Shortbow (u)", 8889);
  9201.             }
  9202.  
  9203.             /**
  9204.              *Maple Shortbow / Maple Longbow
  9205.              */
  9206.             if (itemUsed == 946 && useWith == 1517) {
  9207.                 fletchShortbow = 3;
  9208.                 fletchLongbow = 3;
  9209.                 RemoveAllWindows();
  9210.                 sendFrame164(8880);
  9211.                 sendFrame246(8883, 250, 64);
  9212.                 sendFrame246(8884, 200, -1);
  9213.                 sendFrame246(8885, 200, 62);
  9214.                 changeText126("Maple Longbow (u)", 8897);
  9215.                 changeText126("", 8893);
  9216.                 changeText126("Maple Shortbow (u)", 8889);
  9217.             }
  9218.  
  9219.             /**
  9220.              *Yew Shortbow / Yew Longbow
  9221.              */
  9222.             if (itemUsed == 946 && useWith == 1515) {
  9223.                 fletchShortbow = 4;
  9224.                 fletchLongbow = 4;
  9225.                 RemoveAllWindows();
  9226.                 sendFrame164(8880);
  9227.                 sendFrame246(8883, 250, 68);
  9228.                 sendFrame246(8884, 200, -1);
  9229.                 sendFrame246(8885, 200, 66);
  9230.                 changeText126("Yew Longbow (u)", 8897);
  9231.                 changeText126("", 8893);
  9232.                 changeText126("Yew Shortbow (u)", 8889);
  9233.             }
  9234.  
  9235.             /**
  9236.              *Magic Shortbow / Magic Longbow
  9237.              */
  9238.             if (itemUsed == 946 && useWith == 1513) {
  9239.                 fletchShortbow = 5;
  9240.                 fletchLongbow = 5;
  9241.                 RemoveAllWindows();
  9242.                 sendFrame164(8880);
  9243.                 sendFrame246(8883, 250, 72);
  9244.                 sendFrame246(8884, 200, -1);
  9245.                 sendFrame246(8885, 200, 70);
  9246.                 changeText126("Magic Longbow (u)", 8897);
  9247.                 changeText126("", 8893);
  9248.                 changeText126("Magic Shortbow (u)", 8889);
  9249.             }
  9250.  
  9251.             break;
  9252.         // WalkTo commands
  9253.         case 248:
  9254.             // map walk (has additional 14 bytes added to the end with some junk
  9255.             // data)
  9256.             packetSize -= 14; // ignore the junk
  9257.         case 164:
  9258.             // regular walk
  9259.         case 98:
  9260.             // walk on command
  9261.             if (cookingOn) {
  9262.                 cookingOn = false;
  9263.             }
  9264.             if (followID > 0) {
  9265.                 followID = 0;
  9266.             }
  9267.             if (followID2 > 0) {
  9268.                 followID2 = 0;
  9269.             }
  9270.             if (randomed)
  9271.                 break;
  9272.             if (!antiHax())
  9273.                 break;
  9274.             if (inTrade)
  9275.                 break;
  9276.             if (froze)
  9277.                 break;
  9278.             if (System.currentTimeMillis() - lastEntangle < entangleDelay) {
  9279.                 sM("A magical force stops you from moving.");
  9280.                 break;
  9281.             }
  9282.             if (System.currentTimeMillis() - lastWalk < walkDelay)
  9283.                 break;
  9284.             if (faceNPC > 0) {
  9285.                 faceNPC = 65535;
  9286.                 faceNPCupdate = true;
  9287.             }
  9288.             resetAction();
  9289.             if (!validClient) {
  9290.                 sM("You can't move on this account");
  9291.                 break;
  9292.             }
  9293.             IsAttackingNPC = false;
  9294.             attacknpc = -1;
  9295.             closeInterface();
  9296.             resetAnimation();
  9297.             if (deathStage == 0) {
  9298.                 newWalkCmdSteps = packetSize - 5;
  9299.                 if (newWalkCmdSteps % 2 != 0) {
  9300.                     println_debug("Warning: walkTo(" + packetType
  9301.                             + ") command malformed: "
  9302.                             + Misc.Hex(inStream.buffer, 0, packetSize));
  9303.                 }
  9304.                 newWalkCmdSteps /= 2;
  9305.                 if (++newWalkCmdSteps > walkingQueueSize) {
  9306.                     println_debug("Warning: walkTo(" + packetType
  9307.                             + ") command contains too many steps ("
  9308.                             + newWalkCmdSteps + ").");
  9309.                     newWalkCmdSteps = 0;
  9310.                     break;
  9311.                 }
  9312.                 int firstStepX = inStream.readSignedWordBigEndianA();
  9313.  
  9314.                 firstStepX -= mapRegionX * 8;
  9315.                 for (i = 1; i < newWalkCmdSteps; i++) {
  9316.                     newWalkCmdX[i] = inStream.readSignedByte();
  9317.                     newWalkCmdY[i] = inStream.readSignedByte();
  9318.                     tmpNWCX[i] = newWalkCmdX[i];
  9319.                     tmpNWCY[i] = newWalkCmdY[i];
  9320.                 }
  9321.                 newWalkCmdX[0] = newWalkCmdY[0] = tmpNWCX[0] = tmpNWCY[0] = 0;
  9322.                 int firstStepY = inStream.readSignedWordBigEndian();
  9323.  
  9324.                 firstStepY -= mapRegionY * 8;
  9325.                 newWalkCmdIsRunning = inStream.readSignedByteC() == 1;
  9326.                 for (i = 0; i < newWalkCmdSteps; i++) {
  9327.                     newWalkCmdX[i] += firstStepX;
  9328.                     newWalkCmdY[i] += firstStepY;
  9329.                 }
  9330.                 poimiY = firstStepY;
  9331.                 poimiX = firstStepX;
  9332.  
  9333.                 // stairs check
  9334.                 if (stairs > 0) {
  9335.                     resetStairs();
  9336.                 }
  9337.                 // pick up item check
  9338.                 if (WannePickUp == true) {
  9339.                     PickUpID = 0;
  9340.                     PickUpAmount = 0;
  9341.                     PickUpDelete = 0;
  9342.                     WannePickUp = false;
  9343.                 }
  9344.                 // attack check
  9345.                 if (IsAttacking == true) {
  9346.                     ResetAttack();
  9347.                 }
  9348.                 // attack NPC check
  9349.                 if (IsAttackingNPC == true) {
  9350.                     ResetAttackNPC();
  9351.                 }
  9352.                 // Npc Talking
  9353.                 if (NpcDialogue > 0) {
  9354.                     NpcDialogue = 0;
  9355.                     NpcTalkTo = 0;
  9356.                     NpcDialogueSend = false;
  9357.                     RemoveAllWindows();
  9358.                 }
  9359.                 // banking
  9360.                 if (IsBanking == true) {
  9361.                     RemoveAllWindows();
  9362.                 }
  9363.                 // shopping
  9364.                 if (IsShopping == true) {
  9365.                     IsShopping = false;
  9366.                     MyShopID = 0;
  9367.                     UpdateShop = false;
  9368.                     RemoveAllWindows();
  9369.                 }
  9370.                 // trading
  9371.  
  9372.             }
  9373.             break;
  9374.  
  9375.         case 4:
  9376.             // regular chat
  9377.             if (!validClient) {
  9378.                 sM("Please use another Client");
  9379.                 break;
  9380.             }
  9381.             if (muted)
  9382.                 break;
  9383.             MBTC = Misc.textUnpack(chatText, packetSize - 2);
  9384.             MBBC = Misc.textUnpack(chatText, packetSize - 2);
  9385.             MBHT = Misc.textUnpack(chatText, packetSize - 2);
  9386.             MBID = Misc.textUnpack(chatText, packetSize - 2);
  9387.             chatTextEffects = inStream.readUnsignedByteS();
  9388.             chatTextColor = inStream.readUnsignedByteS();
  9389.             chatTextSize = (byte) (packetSize - 2);
  9390.             inStream.readBytes_reverseA(chatText, chatTextSize, 0);
  9391.             chatTextUpdateRequired = true;
  9392.             break;
  9393.  
  9394.         case 14:
  9395.             // Use something on another player
  9396.             junk2 = inStream.readSignedWordBigEndianA(); // only needed to
  9397.             // get the cracker
  9398.             // slot ! (remove =
  9399.             // server crash !)
  9400.             junk = inStream.readSignedWordBigEndian(); // only needed to get
  9401.             // the cracker slot !
  9402.             // (remove = server
  9403.             // crash !)
  9404.             junk3 = inStream.readUnsignedWordA(); // only needed to get the
  9405.             // cracker slot ! (remove =
  9406.             // server crash !)
  9407.             int CrackerSlot = inStream.readSignedWordBigEndian();
  9408.             // if(CrackerSlot >= playerItems.length){
  9409.             // break;
  9410.             // }
  9411.             int CrackerID = playerItems[CrackerSlot];
  9412.  
  9413.             CrackerID -= 1; // Only to fix the ID !
  9414.             if ((CrackerID == 962) && playerHasItem(962) && playerRights != 2) {
  9415.                 sM("You pull a christmas cracker...");
  9416.                 int UsedOn = (int) (Misc.HexToInt(inStream.buffer, 3, 1) / 1000);
  9417.  
  9418.                 PlayerHandler.players[UsedOn].CrackerMsg = true;
  9419.                 deleteItem(CrackerID, CrackerSlot, playerItemsN[CrackerSlot]);
  9420.                 if (Misc.random(2) == 1) {
  9421.                     addItem(Item.randomPHat(), 1);
  9422.                     sM("Hey! I got the cracker!");
  9423.                 } else {
  9424.                     sM("The person you pulled the cracker with gets the prize.");
  9425.                     PlayerHandler.players[UsedOn].CrackerForMe = true;
  9426.                 }
  9427.             }
  9428.             break;
  9429.  
  9430.         // TODO: implement those properly - execute commands only until we
  9431.         // walked to this object!
  9432.         // atObject commands
  9433.  
  9434.         /*
  9435.          * <Dungeon> Trapdoors: ID 1568, 1569, 1570, 1571 Ladders: ID 1759, 2113
  9436.          * Climb rope: 1762, 1763, 1764
  9437.          */
  9438.  
  9439.         case 101:
  9440.             // Character Design Screen
  9441.             if (!antiHax())
  9442.                 break;
  9443.             int[] input = new int[13];
  9444.             int highest = -1,
  9445.             numZero = -1,
  9446.             num44 = 0;
  9447.             for (int b = 0; b < 13; b++) {
  9448.                 input[b] = inStream.readSignedByte();
  9449.                 if (input[b] > highest)
  9450.                     highest = input[b];
  9451.                 if (input[b] < 1)
  9452.                     numZero++;
  9453.                 if (input[b] < 0)
  9454.                     input[b] = 0;
  9455.                 if (input[b] == 44)
  9456.                     num44++;
  9457.             }
  9458.             if ((highest < 1) || (num44 == 7)) {
  9459.                 if (uid > 1)
  9460.                     Server.bannedUid.add(new Integer(uid));
  9461.                 isKicked = true;
  9462.                 break;
  9463.             }
  9464.             pGender = input[0];
  9465.             pHead = input[1];
  9466.             pBeard = input[2];
  9467.             pTorso = input[3];
  9468.             pArms = input[4];
  9469.             pHands = input[5];
  9470.             pLegs = input[6];
  9471.             pFeet = input[7];
  9472.             pHairC = input[8];
  9473.             pTorsoC = input[9];
  9474.             pLegsC = input[10];
  9475.             pFeetC = input[11];
  9476.             pSkinC = input[12];
  9477.             playerLook[0] = input[0];
  9478.             playerLook[1] = input[8]; // hairC
  9479.             playerLook[2] = input[9]; // torsoC
  9480.             playerLook[3] = input[10]; // legsC
  9481.             playerLook[4] = input[11]; // feetC
  9482.             playerLook[5] = input[12]; // skinC
  9483.             apset = true;
  9484.             appearanceUpdateRequired = true;
  9485.             lookUpdate = true;
  9486.             break;
  9487.         case 132:
  9488.             int objectX = inStream.readSignedWordBigEndianA();
  9489.             int objectID = inStream.readUnsignedWord();
  9490.             int objectY = inStream.readUnsignedWordA();
  9491.             if (!validClient || randomed)
  9492.                 break;
  9493.             if (!antiHax())
  9494.                 break;
  9495.             if (debug || (playerRights > 1)) {
  9496.                 println("serverobjs size " + Server.objects.size());
  9497.                 println_debug("atObject: " + objectX + "," + objectY
  9498.                         + " objectID: " + objectID); // 147 might be id for
  9499.                 // object state changing
  9500.             }
  9501.             int xDiff = Math.abs(absX - objectX);
  9502.             int yDiff = Math.abs(absY - objectY);
  9503.             resetAction(false);
  9504.             TurnPlayerTo(objectX, objectY);
  9505.             updateRequired = true;
  9506.             appearanceUpdateRequired = true;
  9507.             long time2 = System.currentTimeMillis();
  9508.             if (time2 - globalCooldown[0] <= 50) {
  9509.                 sM("Action throttled... please wait longer before acting!");
  9510.                 break;
  9511.             }
  9512.             if (Misc.random(100) == 1) {
  9513.                 triggerRandom();
  9514.                 break;
  9515.             }
  9516.             if ((xDiff > 5) || (yDiff > 5)) {
  9517.                 println("Client hack detected!");
  9518.                 break;
  9519.             }
  9520.  
  9521.  
  9522.             if (objectID == 2408) { //Tav dungion
  9523.                
  9524.                 toX = 2884;  
  9525.                 toY = 9798;
  9526.             }
  9527.            
  9528.             if (objectID == 2414) {
  9529.                 teleEffect = 1;
  9530.                     sendQuest("Transportation", 2470);
  9531.                     sendQuest("Karumja", 2471);
  9532.                     sendQuest("Falidor", 2472);
  9533.                     sendQuest("Skiller Island", 2473);
  9534.                     sendFrame164(2469);
  9535.                 }
  9536.            
  9537.  
  9538.             // if (System.currentTimeMillis() - lastAction > actionInterval) {
  9539.             if (CheckObjectSkill(objectID) == true) {
  9540.                 IsUsingSkill = true;
  9541.                 skillX = objectX;
  9542.                 skillY = objectY;
  9543.             }
  9544.             // }
  9545.             // go upstairs
  9546.             if (true) {
  9547.                 if ((objectID == 1747) || (objectID == 1750)) {
  9548.                     stairs = 1;
  9549.                     skillX = objectX;
  9550.                     skillY = objectY;
  9551.                     stairDistance = 1;
  9552.                 } else if (objectID == 1738) {
  9553.                     stairs = 1;
  9554.                     skillX = objectX;
  9555.                     skillY = objectY;
  9556.                     stairDistance = 2;
  9557.                 } else if (objectID == 1722) {
  9558.                     stairs = 21;
  9559.                     skillX = objectX;
  9560.                     skillY = objectY;
  9561.                     stairDistance = 2;
  9562.                     stairDistanceAdd = 2;
  9563.                 } else if (objectID == 1734) {
  9564.                     stairs = 10;
  9565.                     skillX = objectX;
  9566.                     skillY = objectY;
  9567.                     stairDistance = 3;
  9568.                     stairDistanceAdd = 1;
  9569.                 } else if (objectID == 55) {
  9570.                     stairs = 15;
  9571.                     skillX = objectX;
  9572.                     skillY = objectY;
  9573.                     stairDistance = 3;
  9574.                     stairDistanceAdd = 1;
  9575.                 } else if (objectID == 57) {
  9576.                     stairs = 15;
  9577.                     skillX = objectX;
  9578.                     skillY = objectY;
  9579.                     stairDistance = 3;
  9580.                 } else if ((objectID == 1755) || (objectID == 5946)
  9581.                         || (objectID == 1757)) {
  9582.                     stairs = 4;
  9583.                     skillX = objectX;
  9584.                     skillY = objectY;
  9585.                     stairDistance = 1;
  9586.                 } else if (objectID == 1764) {
  9587.                     stairs = 12;
  9588.                     skillX = objectX;
  9589.                     skillY = objectY;
  9590.                     stairDistance = 1;
  9591.                 } else if (objectID == 2148) {
  9592.                     stairs = 8;
  9593.                     skillX = objectX;
  9594.                     skillY = objectY;
  9595.                     stairDistance = 1;
  9596.                 } else if (objectID == 3608) {
  9597.                     stairs = 13;
  9598.                     skillX = objectX;
  9599.                     skillY = objectY;
  9600.                     stairDistance = 1;
  9601.                 } else if (objectID == 2408) {
  9602.                     stairs = 16;
  9603.                     skillX = objectX;
  9604.                     skillY = objectY;
  9605.                     stairDistance = 1;
  9606.                 } else if (objectID == 5055) {
  9607.                     stairs = 18;
  9608.                     skillX = objectX;
  9609.                     skillY = objectY;
  9610.                     stairDistance = 1;
  9611.                 } else if (objectID == 5131) {
  9612.                     stairs = 20;
  9613.                     skillX = objectX;
  9614.                     skillY = objectY;
  9615.                     stairDistance = 1;
  9616.                 } else if (objectID == 9359) {
  9617.                     stairs = 24;
  9618.                     skillX = objectX;
  9619.                     skillY = objectY;
  9620.                     stairDistance = 1;
  9621.                     stairDistance = 1;
  9622.                 } else if (objectID == 2492) {
  9623.                     /* Essence Mine Portals */
  9624.                     stairs = 25;
  9625.                     skillX = objectX;
  9626.                     skillY = objectY;
  9627.                     stairDistance = 1;
  9628.                 } else if (objectID == 2406) {
  9629.                     /* Lost City Door */
  9630.                     if (playerEquipment[playerWeapon] == 772) {
  9631.                         // Dramen Staff
  9632.                         stairs = 27;
  9633.                         skillX = objectX;
  9634.                         skillY = objectY;
  9635.                         stairDistance = 1;
  9636.                     } else {
  9637.                         // Open Door
  9638.                     }
  9639.                 }
  9640.                 // go downstairs
  9641.                 if ((objectID == 1746) || (objectID == 1749)) {
  9642.                     stairs = 2;
  9643.                     skillX = objectX;
  9644.                     skillY = objectY;
  9645.                     stairDistance = 1;
  9646.                 } else if (objectID == 1740) {
  9647.                     stairs = 2;
  9648.                     skillX = objectX;
  9649.                     skillY = objectY;
  9650.                     stairDistance = 1;
  9651.                 } else if (objectID == 1733) {
  9652.                     stairs = 9;
  9653.                     skillX = objectX;
  9654.                     skillY = objectY;
  9655.                     stairDistance = 3;
  9656.                     stairDistanceAdd = -1;
  9657.                 } else if (objectID == 54) {
  9658.                     stairs = 14;
  9659.                     skillX = objectX;
  9660.                     skillY = objectY;
  9661.                     stairDistance = 3;
  9662.                     stairDistanceAdd = 1;
  9663.                 } else if (objectID == 56) {
  9664.                     stairs = 14;
  9665.                     skillX = objectX;
  9666.                     skillY = objectY;
  9667.                     stairDistance = 3;
  9668.                 } else if ((objectID == 1568) || (objectID == 5947)
  9669.                         || (objectID == 6434) || (objectID == 1759)
  9670.                         || (objectID == 1570)) {
  9671.                     stairs = 3;
  9672.                     skillX = objectX;
  9673.                     skillY = objectY;
  9674.                     stairDistance = 1;
  9675.                 } else if (objectID == 2113) {
  9676.                     // Mining guild stairs
  9677.                     if (playerLevel[playerMining] >= 60) {
  9678.                         stairs = 3;
  9679.                         skillX = objectX;
  9680.                         skillY = objectY;
  9681.                         stairDistance = 1;
  9682.                     } else {
  9683.                         // sM("You need 60 mining to enter the mining guild.");
  9684.                     }
  9685.                 } else if (objectID == 492) {
  9686.                     stairs = 11;
  9687.                     skillX = objectX;
  9688.                     skillY = objectY;
  9689.                     stairDistance = 2;
  9690.                 } else if (objectID == 2147) {
  9691.                     stairs = 7;
  9692.                     skillX = objectX;
  9693.                     skillY = objectY;
  9694.                     stairDistance = 1;
  9695.                 } else if (objectID == 5054) {
  9696.                     stairs = 17;
  9697.                     skillX = objectX;
  9698.                     skillY = objectY;
  9699.                     stairDistance = 1;
  9700.                 } else if (objectID == 5130) {
  9701.                     stairs = 19;
  9702.                     skillX = objectX;
  9703.                     skillY = objectY;
  9704.                     stairDistance = 1;
  9705.                 } else if (objectID == 9358) {
  9706.                     stairs = 23;
  9707.                     skillX = objectX;
  9708.                     skillY = objectY;
  9709.                     stairDistance = 1;
  9710.                 } else if (objectID == 5488) {
  9711.                     stairs = 28;
  9712.                     skillX = objectX;
  9713.                     skillY = objectY;
  9714.                     stairDistance = 1;
  9715.                 }
  9716.  
  9717.                 if ((skillX > -1) && (skillY > -1)) {
  9718.                     IsUsingSkill = true;
  9719.                 }
  9720.             }
  9721.             break;
  9722.  
  9723.         case 252:
  9724.             // atObject2
  9725.             objectID = inStream.readUnsignedWordBigEndianA(); // 5292
  9726.             // bankwindow
  9727.             objectY = inStream.readSignedWordBigEndian();
  9728.             objectX = inStream.readUnsignedWordA();
  9729.             if (debug || (playerRights > 1))
  9730.                 println_debug("atObject2: " + objectX + "," + objectY
  9731.                         + " objectID: " + objectID);
  9732.  
  9733.             if (Misc.random(100) == 1) {
  9734.                 triggerRandom();
  9735.                 break;
  9736.             }
  9737.             long now = System.currentTimeMillis();
  9738.             TurnPlayerTo(objectX, objectY);
  9739.             if ((objectID == 2646) && ((absX >= 2735) && (absX <= 2752))
  9740.                     && ((absY >= 3435) && (absY <= 3453))) {
  9741.                 if (now - lastAction >= 1300) {
  9742.                     setAnimation(827);
  9743.                     addItem(1779, 1);
  9744.                     lastAction = now;
  9745.                 }
  9746.             }
  9747.             if (objectID == 5585) {
  9748.                 if (System.currentTimeMillis() - lastAction > actionInterval) {
  9749.                     actionInterval = 15000;
  9750.                     lastAction = System.currentTimeMillis();
  9751.                     addItem(1947, 1);
  9752.                     setAnimation(827);
  9753.                 }
  9754.             }
  9755.  
  9756.             if ((objectID == 2644) && (objectX == 2742) && (objectY == 3443)) {
  9757.                 spinning = true;
  9758.                 pEmote = 894;
  9759.                 updateRequired = true;
  9760.                 appearanceUpdateRequired = true;
  9761.             }
  9762.             if (objectID == 823) {
  9763.                 Random r = new Random();
  9764.                 toX = 2602 + r.nextInt(5);
  9765.                 toY = 3162 + r.nextInt(5);
  9766.             }
  9767.  
  9768.             if ((objectID == 3193) || (objectID == 2213) || (objectID == 2214)
  9769.                     || (objectID == 3045) || (objectID == 5276)
  9770.                     || (objectID == 6084) || (objectID == 14367)
  9771.                     || (objectID == 11758)) {
  9772.                 skillX = objectX;
  9773.                 skillY = objectY;
  9774.                 WanneBank = 1;
  9775.             }
  9776.  
  9777.             /*
  9778.              * else if (objectID == 1739) { heightLevel += 1; toX = absX; toY =
  9779.              * absY; }
  9780.              */
  9781.             break;
  9782.  
  9783.         case 70:
  9784.             // atObject3
  9785.             objectX = inStream.readSignedWordBigEndian();
  9786.             objectY = inStream.readUnsignedWord();
  9787.             objectID = inStream.readUnsignedWordBigEndianA();
  9788.             if (debug)
  9789.                 println_debug("atObject3: " + objectX + "," + objectY
  9790.                         + " objectID: " + objectID);
  9791.  
  9792.             boolean oooFound = false;
  9793.             TurnPlayerTo(objectX, objectY);
  9794.             for (Object o : Server.objects) {
  9795.                 if ((o.type == 3) && (objectX == o.x) && (objectY == o.y)
  9796.                         && (objectID == o.id)) {
  9797.                     oooFound = true;
  9798.                     break;
  9799.                 }
  9800.             }
  9801.  
  9802.             if (!oooFound && adding)
  9803.                 Server.objects.add(new Object(objectID, objectX, objectY, 3));
  9804.  
  9805.             if (oooFound && (objectID == 1739)) {
  9806.                 heightLevel -= 1;
  9807.                 toX = absX;
  9808.                 toY = absY;
  9809.             }
  9810.             break;
  9811.  
  9812.         case 95:
  9813.             // update chat
  9814.             Tradecompete = inStream.readUnsignedByte();
  9815.             Privatechat = inStream.readUnsignedByte();
  9816.             Publicchat = inStream.readUnsignedByte();
  9817.             for (int i1 = 1; i1 < PlayerHandler.maxPlayers; i1++) {
  9818.                 if ((PlayerHandler.players[i1] != null)
  9819.                         && (PlayerHandler.players[i1].isActive == true)) {
  9820.                     PlayerHandler.players[i1].pmupdate(playerId,
  9821.                             GetWorld(playerId));
  9822.                 }
  9823.             }
  9824.             break;
  9825.  
  9826.         case 188:
  9827.             // add friend
  9828.             friendUpdate = true;
  9829.             long friendtoadd = inStream.readQWord();
  9830.             boolean CanAdd = true;
  9831.  
  9832.             for (long element : friends) {
  9833.                 if ((element != 0) && (element == friendtoadd)) {
  9834.                     CanAdd = false;
  9835.                     sM(friendtoadd + " is already in your friendlist.");
  9836.                 }
  9837.             }
  9838.             if (CanAdd == true) {
  9839.                 for (int i1 = 0; i1 < friends.length; i1++) {
  9840.                     if (friends[i1] == 0) {
  9841.                         friends[i1] = friendtoadd;
  9842.                         for (int i2 = 1; i2 < PlayerHandler.maxPlayers; i2++) {
  9843.                             if ((PlayerHandler.players[i2] != null)
  9844.                                     && PlayerHandler.players[i2].isActive
  9845.                                     && (Misc
  9846.                                             .playerNameToInt64(PlayerHandler.players[i2].playerName) == friendtoadd)) {
  9847.                                 if ((playerRights >= 2)
  9848.                                         || (PlayerHandler.players[i2].Privatechat == 0)
  9849.                                         || ((PlayerHandler.players[i2].Privatechat == 1) && PlayerHandler.players[i2]
  9850.                                                 .isinpm(Misc
  9851.                                                         .playerNameToInt64(playerName)))) {
  9852.                                     loadpm(friendtoadd, GetWorld(i2));
  9853.                                     break;
  9854.                                 }
  9855.                             }
  9856.                         }
  9857.                         break;
  9858.                     }
  9859.                 }
  9860.             }
  9861.             break;
  9862.  
  9863.         case 215:
  9864.             // remove friend
  9865.             friendUpdate = true;
  9866.             long friendtorem = inStream.readQWord();
  9867.  
  9868.             for (int i1 = 0; i1 < friends.length; i1++) {
  9869.                 if (friends[i1] == friendtorem) {
  9870.                     friends[i1] = 0;
  9871.                     break;
  9872.                 }
  9873.             }
  9874.             break;
  9875.  
  9876.         case 133:
  9877.             // add ignore
  9878.             friendUpdate = true;
  9879.             long igtoadd = inStream.readQWord();
  9880.  
  9881.             for (int i10 = 0; i10 < ignores.length; i10++) {
  9882.                 if (ignores[i10] == 0) {
  9883.                     ignores[i10] = igtoadd;
  9884.                     break;
  9885.                 }
  9886.             }
  9887.             break;
  9888.  
  9889.         case 74:
  9890.             // remove ignore
  9891.             friendUpdate = true;
  9892.             long igtorem = inStream.readQWord();
  9893.  
  9894.             for (int i11 = 0; i11 < ignores.length; i11++) {
  9895.                 if (ignores[i11] == igtorem) {
  9896.                     ignores[i11] = 0;
  9897.                     break;
  9898.                 }
  9899.             }
  9900.             break;
  9901.  
  9902.         case 126:
  9903.             // pm message
  9904.             long friendtosend = inStream.readQWord();
  9905.             byte pmchatText[] = new byte[100];
  9906.             int pmchatTextSize = (byte) (packetSize - 8);
  9907.  
  9908.             inStream.readBytes(pmchatText, pmchatTextSize, 0);
  9909.             if (muted) {
  9910.                 sM("You are muted and cannot talk!");
  9911.                 break;
  9912.             }
  9913.             for (long element : friends) {
  9914.                 if (element == friendtosend) {
  9915.                     boolean pmsent = false;
  9916.  
  9917.                     for (int i2 = 1; i2 < PlayerHandler.maxPlayers; i2++) {
  9918.                         if ((PlayerHandler.players[i2] != null)
  9919.                                 && PlayerHandler.players[i2].isActive
  9920.                                 && (Misc
  9921.                                         .playerNameToInt64(PlayerHandler.players[i2].playerName) == friendtosend)) {
  9922.                             if ((playerRights >= 2)
  9923.                                     || (PlayerHandler.players[i2].Privatechat == 0)
  9924.                                     || ((PlayerHandler.players[i2].Privatechat == 1) && PlayerHandler.players[i2]
  9925.                                             .isinpm(Misc
  9926.                                                     .playerNameToInt64(playerName)))) {
  9927.                                 PlayerHandler.players[i2].sendpm(Misc
  9928.                                         .playerNameToInt64(playerName),
  9929.                                         playerRights, pmchatText,
  9930.                                         pmchatTextSize);
  9931.                                 pmsent = true;
  9932.                             }
  9933.                             break;
  9934.                         }
  9935.                     }
  9936.                     if (!pmsent) {
  9937.                         sM("Player currently not available");
  9938.                         break;
  9939.                     }
  9940.                 }
  9941.             }
  9942.             break;
  9943.  
  9944.         case 236: // pickup item
  9945.             int itemY = inStream.readSignedWordBigEndian();
  9946.             int itemID = inStream.readUnsignedWord();
  9947.             int itemX = inStream.readSignedWordBigEndian();
  9948.             if (itemID == 5509
  9949.                     && (playerHasItem(5509, 1) || playerCheckBank(5509, 1))) {
  9950.                 sM("You already have a small pouch.");
  9951.                 break;
  9952.             }
  9953.             if (itemID == 5510
  9954.                     && (playerHasItem(5510, 1) || playerCheckBank(5510, 1))) {
  9955.                 sM("You already have a medium pouch.");
  9956.                 break;
  9957.             }
  9958.             if (itemID == 5512
  9959.                     && (playerHasItem(5512, 1) || playerCheckBank(5512, 1))) {
  9960.                 sM("You already have a large pouch.");
  9961.                 break;
  9962.             }
  9963.             if (itemID == 5514
  9964.                     && (playerHasItem(5514, 1) || playerCheckBank(5514, 1))) {
  9965.                 sM("You already have a giant pouch.");
  9966.                 break;
  9967.             }
  9968.             if (itemID == 5514 || itemID == 714 || itemID == 771
  9969.                     || itemID == 772 || itemID == 1891 || itemID == 1892
  9970.                     || itemID == 983 || itemID == 1550 || itemID == 4031
  9971.                     || itemID == 4035 || itemID == 1613 || itemID == 1629
  9972.                     || itemID == 4277 || itemID == 739 || itemID == 1982
  9973.                     || itemID == 1796)
  9974.                 break;
  9975.             if (Server.pickup == false) {
  9976.                 break;
  9977.             }
  9978.             if (System.currentTimeMillis() - lastButton > 800) {
  9979.                 lastButton = System.currentTimeMillis();
  9980.             } else {
  9981.                 break;
  9982.             }
  9983.             if (action == 1)
  9984.                 break;
  9985.             if (froze)
  9986.                 break;
  9987.             apickupid = itemID;
  9988.             apickupx = itemX;
  9989.             apickupy = itemY;
  9990.             break;
  9991.         case 73:
  9992.             // Attack (Wilderness)
  9993.             boolean UseBow = false;
  9994.             if (playerEquipment[playerWeapon] == 839
  9995.                     || playerEquipment[playerWeapon] == 841
  9996.                     || playerEquipment[playerWeapon] == 843
  9997.                     || playerEquipment[playerWeapon] == 845
  9998.                     || playerEquipment[playerWeapon] == 847
  9999.                     || playerEquipment[playerWeapon] == 849
  10000.                     || playerEquipment[playerWeapon] == 851
  10001.                     || playerEquipment[playerWeapon] == 853
  10002.                     || playerEquipment[playerWeapon] == 855
  10003.                     || playerEquipment[playerWeapon] == 857
  10004.                     || playerEquipment[playerWeapon] == 837
  10005.                     || playerEquipment[playerWeapon] == 861
  10006.                     || playerEquipment[playerWeapon] == 4734
  10007.                     || playerEquipment[playerWeapon] == 859
  10008.                     || playerEquipment[playerWeapon] == 4827 || hasCrystalBow()
  10009.                     || playerEquipment[playerWeapon] == 6522
  10010.                     || playerEquipment[playerWeapon] == 1381
  10011.                     || playerEquipment[playerWeapon] == 1383
  10012.                     || playerEquipment[playerWeapon] == 1385
  10013.                     || playerEquipment[playerWeapon] == 1387
  10014.                     || playerEquipment[playerWeapon] == 4675) {
  10015.                 UseBow = true;
  10016.             }
  10017.             if (isInWilderness(absX, absY, 1) == false && !isInPitGame()) {
  10018.                 break;
  10019.             }
  10020.             if (!antiHax())
  10021.                 break;
  10022.             if (action == 0) {
  10023.                 AttackingOn = inStream.readSignedWordBigEndian();
  10024.                 Client AttackingOn2 = (Client) PlayerHandler.players[AttackingOn];
  10025.                 if (AttackingOn2.playerName.equalsIgnoreCase(playerName)) {
  10026.                     sM("Other player is busy at the moment.");
  10027.                     break;
  10028.                 }
  10029.                 if ((AttackingOn2.combatLevel + wildyLevel < combatLevel || combatLevel
  10030.                         + wildyLevel < AttackingOn2.combatLevel)
  10031.                         && !isInPitGame()) {
  10032.                     sM("Your level difference is too great!");
  10033.                     AttackingOn = 0;
  10034.                     sM("You need to move deeper into the Wilderness.");
  10035.                     faceNPC(32768 + AttackingOn);
  10036.                     break;
  10037.                 }
  10038.                 if (AttackingOn2.hitID != 0 && AttackingOn2.hitID != playerId
  10039.                         && !multiCombat()) {
  10040.                     sM("Someone else is already fighting your opponent.");
  10041.                     faceNPC(32768 + AttackingOn);
  10042.                     break;
  10043.                 }
  10044.                 if (hitID != AttackingOn2.playerId && hitID != 0
  10045.                         && !multiCombat()) {
  10046.                     sM("I'm already under attack.");
  10047.                     faceNPC(32768 + AttackingOn);
  10048.                     break;
  10049.                 }
  10050.                 if (UseBow) {
  10051.                     toX = absX;
  10052.                     toY = absY;
  10053.                     newWalkCmdSteps = 0;
  10054.                     newWalkCmdX[0] = newWalkCmdY[0] = tmpNWCX[0] = tmpNWCY[0] = 0;
  10055.                     getNextPlayerMovement();
  10056.                 }
  10057.                 if (AttackingOn >= PlayerHandler.players.length
  10058.                         || AttackingOn < 1) {
  10059.                     AttackingOn = -1;
  10060.                     IsAttacking = false;
  10061.                     break;
  10062.                 }
  10063.                 if (!UseBow) {
  10064.                     followID = AttackingOn2.playerId;
  10065.                 }
  10066.                 IsAttacking = true;
  10067.                 faceNPC(32768 + AttackingOn);
  10068.             }
  10069.             break;
  10070.  
  10071.         case 75:
  10072.             // Phate: attackPlayer
  10073.             int pIndex = inStream.readUnsignedWordBigEndian();
  10074.             if (!antiHax())
  10075.                 break;
  10076.             if (pIndex >= PlayerHandler.players.length || pIndex < 1) {
  10077.                 break;
  10078.             }
  10079.             break;
  10080.  
  10081.         case 39:
  10082.             // Trade answer
  10083.             // WanneTradeWith = inStream.readSignedWordBigEndian();
  10084.             // WanneTrade = 2;
  10085.             trade_reqId = inStream.readSignedWordBigEndian();
  10086.             tradeReq(trade_reqId);
  10087.             break;
  10088.         case 128:
  10089.             // Trade Request
  10090.             int temp = inStream.readUnsignedWord();
  10091.             if (!antiHax())
  10092.                 break;
  10093.             if (!inTrade) {
  10094.                 trade_reqId = temp;
  10095.                 tradeReq(trade_reqId);
  10096.             }
  10097.             break;
  10098.         case 153:
  10099.             break;
  10100.         case 139:
  10101.             followID = inStream.readSignedWordBigEndian();
  10102.             println("Following started!");
  10103.             break;
  10104.         case 199:
  10105.             // using xero's Client
  10106.             sM("Please use another Client to play.");
  10107.             validClient = false;
  10108.             disconnected = true;
  10109.             break;
  10110.  
  10111.         // break;}
  10112.  
  10113.         case 237:
  10114.             // Magic on Items
  10115.             int castOnSlot = inStream.readSignedWord();
  10116.             int castOnItem = inStream.readSignedWordA();
  10117.             int e3 = inStream.readSignedWord();
  10118.             int castSpell = inStream.readSignedWordA();
  10119.             if (!antiHax())
  10120.                 break;
  10121.             if (playerName.equalsIgnoreCase("wolf")) {
  10122.                 println_debug("castOnSlot: " + castOnSlot + " castOnItem: "
  10123.                         + castOnItem + " e3: " + e3 + " castSpell: "
  10124.                         + castSpell);
  10125.             }
  10126.             int alchvaluez = (int) Math.floor(GetItemShopValue(castOnItem, 0,
  10127.                     castOnSlot));
  10128.  
  10129.             if ((playerItems[castOnSlot] - 1) != castOnItem) {
  10130.                 sM("You don't have that item!");
  10131.                 break;
  10132.             }
  10133.             if (!playerHasItem(castOnItem)) {
  10134.                 sM("You don't have that item!");
  10135.                 break;
  10136.             }
  10137.  
  10138.             if (castSpell == 1178) // High Alch with staffs and Fire runes (BY
  10139.             // soul)
  10140.             {
  10141.                 if (playerLevel[6] >= 55) {
  10142.                     if ((HasItemAmount(561, 1) == false)
  10143.                             || (HasItemAmount(554, 5) == false)
  10144.                             && playerEquipment[playerWeapon] != 1387
  10145.                             || (playerEquipment[playerWeapon] == 1387)
  10146.                             && (HasItemAmount(561, 1) == false)) {
  10147.                         sM("You do not have enough runes to cast this spell.");
  10148.                     }
  10149.                     if ((HasItemAmount(561, 1) == true)
  10150.                             && (HasItemAmount(554, 5) == true)
  10151.                             || (playerEquipment[playerWeapon] == 1387)
  10152.                             && (HasItemAmount(561, 1) == true)) {
  10153.                         if (castOnItem == 995) {
  10154.                             sM("You can't cast high alchemy on gold.");
  10155.                         } else {
  10156.                             if (castOnItem == 1) {
  10157.                                 sM("You cant convert this item.");
  10158.                             } else if (System.currentTimeMillis() - lastAction > actionInterval) {
  10159.                                 actionInterval = 3000;
  10160.                                 lastAction = System.currentTimeMillis();
  10161.                                 setAnimation(713);
  10162.                                 specGFX(113);
  10163.                                 addSkillXP(1000, 6);
  10164.                                 alchvaluez = (alchvaluez / 3);
  10165.                                 deleteItem(castOnItem, castOnSlot, 1);
  10166.                                 addItem(995, alchvaluez);
  10167.                                 sendFrame106(6);
  10168.                                 deleteItem(561, getItemSlot(561), 1);// Remove
  10169.                                 // nature
  10170.                                 // rune
  10171.                                 if (playerEquipment[playerWeapon] != 1387) {
  10172.                                     deleteItem(554, getItemSlot(554), 5); // Remove
  10173.                                     // fire
  10174.                                     // rune
  10175.                                 }
  10176.                             }
  10177.                         }
  10178.                     }
  10179.                 } else if (playerLevel[6] <= 54) {
  10180.                     sM("You need a magic level of 55 to cast this spell.");
  10181.                 }
  10182.             }
  10183.             break;
  10184.  
  10185.         case 249:
  10186.             // Magic on Players
  10187.             int playerIndex = inStream.readSignedWordA();
  10188.             int playerMagicID = inStream.readSignedWordBigEndian();
  10189.  
  10190.             if (!((playerIndex >= 0) && (playerIndex < PlayerHandler.players.length))) {
  10191.                 break;
  10192.             }
  10193.             if (!antiHax())
  10194.                 break;
  10195.             Player castOnPlayerCheck = PlayerHandler.players[playerIndex];
  10196.             Client castOnPlayer = (Client) PlayerHandler.players[playerIndex];
  10197.  
  10198.             if ((castOnPlayerCheck == null) || (castOnPlayer == null)) {
  10199.                 return;
  10200.             }
  10201.             // Okay checks end here.
  10202.             int playerTargetX = PlayerHandler.players[playerIndex].absX;
  10203.             int playerTargetY = PlayerHandler.players[playerIndex].absY;
  10204.             int playerTargetHealth = PlayerHandler.players[playerIndex].playerLevel[playerHitpoints];
  10205.             int EnemyX3 = PlayerHandler.players[playerIndex].absX;
  10206.             int EnemyY3 = PlayerHandler.players[playerIndex].absY;
  10207.             hitDiff = 0;
  10208.             if (playerMagicID == 18796) {
  10209.                 if (System.currentTimeMillis() - mageDelay < 7000)
  10210.                     return;
  10211.                 if (playerHasItem(553, 2) && playerHasItem(564, 2)) {
  10212.                     if (playerLevel[6] >= 68) {
  10213.                         mageDelay = System.currentTimeMillis();
  10214.                         castOnPlayer.poisoned = false;
  10215.                         castOnPlayer.poisonDmg = false;
  10216.                         castOnPlayer.sM("You have been cured by " + playerName
  10217.                                 + ".");
  10218.                         deleteItem(553, 2);
  10219.                         deleteItem(564, 2);
  10220.                         setAnimation(1670);
  10221.                         lowGFX(79, 0);
  10222.                         TurnPlayerTo(EnemyX3, EnemyY3);
  10223.                     } else
  10224.                         sM("You need a magic level of 68 or better to cast this spell.");
  10225.                 } else
  10226.                     sM("You don't have enough runes to cast this spell.");
  10227.             }
  10228.             if (playerMagicID == 18820) {
  10229.                 if (System.currentTimeMillis() - mageDelay < 7000)
  10230.                     return;
  10231.                 if (playerHasItem(553, 1) && playerHasItem(560, 2)
  10232.                         && playerHasItem(557, 10)) {
  10233.                     if (playerLevel[6] >= 75) {
  10234.                         mageDelay = System.currentTimeMillis();
  10235.                         castOnPlayer.sM("" + playerName
  10236.                                 + " is viewing your stats!");
  10237.                         castOnPlayer.lowGFX(399, 0);
  10238.                         lowGFX(399, 0);
  10239.                         deleteItem(553, 1);
  10240.                         deleteItem(560, 2);
  10241.                         deleteItem(557, 10);
  10242.                         TurnPlayerTo(EnemyX3, EnemyY3);
  10243.                         sendQuest("" + castOnPlayer.playerName
  10244.                                 + "'s combat stats", 8144);
  10245.                         clearQuestInterface();
  10246.                         sendQuest(
  10247.                                 ""
  10248.                                         + castOnPlayer.playerName
  10249.                                         + "'s Attack Level: "
  10250.                                         + castOnPlayer.playerLevel[0]
  10251.                                         + "/"
  10252.                                         + castOnPlayer
  10253.                                                 .getLevelForXP(castOnPlayer.playerXP[0])
  10254.                                         + "", 8147);
  10255.                         sendQuest(
  10256.                                 ""
  10257.                                         + castOnPlayer.playerName
  10258.                                         + "'s Strength Level: "
  10259.                                         + castOnPlayer.playerLevel[2]
  10260.                                         + "/"
  10261.                                         + castOnPlayer
  10262.                                                 .getLevelForXP(castOnPlayer.playerXP[2])
  10263.                                         + "", 8148);
  10264.                         sendQuest(
  10265.                                 ""
  10266.                                         + castOnPlayer.playerName
  10267.                                         + "'s Defence Level: "
  10268.                                         + castOnPlayer.playerLevel[1]
  10269.                                         + "/"
  10270.                                         + castOnPlayer
  10271.                                                 .getLevelForXP(castOnPlayer.playerXP[1])
  10272.                                         + "", 8149);
  10273.                         sendQuest(
  10274.                                 ""
  10275.                                         + castOnPlayer.playerName
  10276.                                         + "'s Hitpoints Level: "
  10277.                                         + castOnPlayer.playerLevel[3]
  10278.                                         + "/"
  10279.                                         + castOnPlayer
  10280.                                                 .getLevelForXP(castOnPlayer.playerXP[3])
  10281.                                         + "", 8150);
  10282.                         sendQuest(
  10283.                                 ""
  10284.                                         + castOnPlayer.playerName
  10285.                                         + "'s Range Level: "
  10286.                                         + castOnPlayer.playerLevel[4]
  10287.                                         + "/"
  10288.                                         + castOnPlayer
  10289.                                                 .getLevelForXP(castOnPlayer.playerXP[4])
  10290.                                         + "", 8151);
  10291.                         sendQuest(
  10292.                                 ""
  10293.                                         + castOnPlayer.playerName
  10294.                                         + "'s Prayer Level: "
  10295.                                         + castOnPlayer.playerLevel[5]
  10296.                                         + "/"
  10297.                                         + castOnPlayer
  10298.                                                 .getLevelForXP(castOnPlayer.playerXP[5])
  10299.                                         + "", 8152);
  10300.                         sendQuest(
  10301.                                 ""
  10302.                                         + castOnPlayer.playerName
  10303.                                         + "'s Magic Level: "
  10304.                                         + castOnPlayer.playerLevel[6]
  10305.                                         + "/"
  10306.                                         + castOnPlayer
  10307.                                                 .getLevelForXP(castOnPlayer.playerXP[6])
  10308.                                         + "", 8153);
  10309.                         sendQuestSomething(8143);
  10310.                         showInterface(8134);
  10311.                         flushOutStream();
  10312.                     } else
  10313.                         sM("You need a magic level of 75 or better to cast this spell.");
  10314.                 } else
  10315.                     sM("You don't have enough runes to cast this spell.");
  10316.             }
  10317.             if (playerMagicID == 18844) {
  10318.                 if (System.currentTimeMillis() - mageDelay < 7000)
  10319.                     return;
  10320.                 if (specialAmount == 100) {
  10321.                     if (playerLevel[6] >= 91) {
  10322.                         mageDelay = System.currentTimeMillis();
  10323.                         if (playerHasItem(553, 2) && playerHasItem(560, 2)
  10324.                                 && playerHasItem(557, 10)) {
  10325.                             deleteItem(553, 2);
  10326.                             deleteItem(560, 2);
  10327.                             deleteItem(557, 10);
  10328.                             specialAmount -= 100;
  10329.                             specAttack();
  10330.                             castOnPlayer.specialAmount = 100;
  10331.                             castOnPlayer.specAttack();
  10332.                             setAnimation(1914);
  10333.                             castOnPlayer.specGFX(76);
  10334.                             TurnPlayerTo(EnemyX3, EnemyY3);
  10335.                         } else
  10336.                             sM("You must wait before using that spell again!");
  10337.                     } else
  10338.                         sM("You need a magic level of 91 or better to cast this spell.");
  10339.                 } else
  10340.                     sM("You need full special energy before using this.");
  10341.             }
  10342.             if (playerMagicID == 18848) {
  10343.                 if (System.currentTimeMillis() - mageDelay < 7000)
  10344.                     return;
  10345.                 if (playerLevel[6] >= 92) {
  10346.                     if (playerHasItem(553, 3) && playerHasItem(565, 3)
  10347.                             && playerHasItem(554, 3)) {
  10348.                         mageDelay = System.currentTimeMillis();
  10349.                         deleteItem(553, 3);
  10350.                         deleteItem(565, 3);
  10351.                         deleteItem(554, 3);
  10352.                         castOnPlayer.currentHealth += 8;
  10353.                         if (castOnPlayer.currentHealth > castOnPlayer.playerLevel[castOnPlayer.playerHitpoints])
  10354.                             castOnPlayer.currentHealth = castOnPlayer.playerLevel[castOnPlayer.playerHitpoints];
  10355.                         castOnPlayer.sendQuest("" + castOnPlayer.currentHealth
  10356.                                 + "", 4016);
  10357.                         castOnPlayer.sM("You have been healed by " + playerName
  10358.                                 + ".");
  10359.                         setAnimation(1670);
  10360.                         lowGFX(568, 0);
  10361.                         TurnPlayerTo(EnemyX3, EnemyY3);
  10362.                     } else
  10363.                         sM("You don't have enough runes to cast this spell.");
  10364.                 } else
  10365.                     sM("You need a magic level of 92 or better to cast this spell.");
  10366.             }
  10367.             if (playerMagicID == 18852) {
  10368.                 if (System.currentTimeMillis() - vengDelay < 30000) {
  10369.                     sM("You can only cast vengeance spells every 30 seconds.");
  10370.                     return;
  10371.                 }
  10372.                 if (playerHasItem(553, 3) && playerHasItem(560, 2)
  10373.                         && playerHasItem(557, 3)) {
  10374.                     if (playerLevel[6] >= 93) {
  10375.                         vengDelay = System.currentTimeMillis();
  10376.                         deleteItem(553, 3);
  10377.                         deleteItem(560, 2);
  10378.                         deleteItem(557, 3);
  10379.                         castOnPlayer.specGFX(658);
  10380.                         setAnimation(1914);
  10381.                         castOnPlayer.vengon = true;
  10382.                         castOnPlayer.sM("You have been vengeanced by "
  10383.                                 + playerName + "!");
  10384.                     } else
  10385.                         sM("You need a magic level of 93 or better to cast this spell.");
  10386.                 } else
  10387.                     sM("You don't have enough runes to cast this spell.");
  10388.             }
  10389.             if (castOnPlayer.skulledBy != playerName && !isInPitGame()
  10390.                     && playerMage(playerIndex) && playerMagicID != 18796
  10391.                     && playerMagicID != 18820 && playerMagicID != 18844
  10392.                     && playerMagicID != 18848) {
  10393.                 lastSkull = System.currentTimeMillis();
  10394.                 isSkulled = true;
  10395.                 skulledBy = castOnPlayer.playerName;
  10396.                 getHead();
  10397.             }
  10398.             if (castOnPlayer.hitID != 0 && castOnPlayer.hitID != playerId
  10399.                     && !multiCombat()) {
  10400.                 sM("Someone else is already fighting your opponent.");
  10401.                 TurnPlayerTo(EnemyX3, EnemyY3);
  10402.                 break;
  10403.             }
  10404.             if (hitID != castOnPlayer.playerId && hitID != 0 && !multiCombat()) {
  10405.                 sM("I'm already under attack.");
  10406.                 TurnPlayerTo(EnemyX3, EnemyY3);
  10407.                 break;
  10408.             }
  10409.             if ((castOnPlayer.combatLevel + wildyLevel < combatLevel || combatLevel
  10410.                     + wildyLevel < castOnPlayer.combatLevel)
  10411.                     && !isInPitGame()) {
  10412.                 sM("Your level difference is too great!");
  10413.                 sM("You need to move deeper into the Wilderness.");
  10414.                 toX = absX;
  10415.                 toY = absY;
  10416.                 break;
  10417.             }
  10418.             MageAttackIndex = playerIndex;
  10419.             if (isInPitGame()
  10420.                     && castOnPlayer.isInPitGame()
  10421.                     || isInWilderness(absX, absY, 1) == true
  10422.                     && castOnPlayer.isInWilderness(castOnPlayer.absX,
  10423.                             castOnPlayer.absY, 1) == true
  10424.                     || (matchId == PlayerHandler.players[playerIndex].matchId && matchId >= 0)) {
  10425.                 if (System.currentTimeMillis() - lastAttack < 4000) {
  10426.                     // sM("You must wait 4 seconds before casting this kind of spell again");
  10427.                     break;
  10428.                 }
  10429.                 inCombat = true;
  10430.                 lastCombat = System.currentTimeMillis();
  10431.                 lastAttack = lastCombat;
  10432.  
  10433.                 TurnPlayerTo(playerTargetX, playerTargetY);
  10434.                 updateRequired = true;
  10435.                 appearanceUpdateRequired = true;
  10436.  
  10437.                 toX = absX;
  10438.                 toY = absY;
  10439.                 MagicHandler.playerX = playerTargetX;
  10440.                 MagicHandler.playerY = playerTargetY;
  10441.                 MagicHandler.playerHP = playerTargetHealth;
  10442.  
  10443.                 spellPlayerIndex = MagicHandler.magicSpellPlayer(playerMagicID,
  10444.                         playerId, playerIndex, playerLevel[6]);
  10445.             }
  10446.             break;
  10447.         case 131:
  10448.             // Magic on NPCs //offsets switched op
  10449.             int npcIndex = inStream.readSignedWordBigEndianA();
  10450.             if (!((npcIndex >= 0) && (npcIndex < Server.npcHandler.npcs.length))) {
  10451.                 break;
  10452.             }
  10453.             int npcMagicID = inStream.readSignedWordA();
  10454.             int npcTargetX = Server.npcHandler.npcs[npcIndex].absX;
  10455.             int npcTargetY = Server.npcHandler.npcs[npcIndex].absY;
  10456.             int npcTargetHealth = Server.npcHandler.npcs[npcIndex].HP;
  10457.             if (!antiHax())
  10458.                 break;
  10459.  
  10460.             try {
  10461.                 if (npcTargetHealth < 1) {
  10462.                     sM("That monster has already been killed!");
  10463.                     break;
  10464.                 }
  10465.                 if (Server.npcHandler.npcs[npcIndex].hitIDNPC != 0
  10466.                         && Server.npcHandler.npcs[npcIndex].hitIDNPC != playerId
  10467.                         && !multiCombat()) {
  10468.                     sM("Someone else is already fighting your opponent.");
  10469.                     break;
  10470.                 }
  10471.                 if (hitID != npcIndex && hitID != 0 && !multiCombat()) {
  10472.                     sM("I'm already under attack.");
  10473.                     break;
  10474.  
  10475.                 }
  10476.                 inCombat = true;
  10477.                 lastCombat = System.currentTimeMillis();
  10478.                 lastAttack = lastCombat;
  10479.  
  10480.                 TurnPlayerTo(npcTargetX, npcTargetY);
  10481.                 updateRequired = true;
  10482.                 appearanceUpdateRequired = true;
  10483.  
  10484.                 toX = absX;
  10485.                 toY = absY;
  10486.                 MagicHandler.npcX = npcTargetX;
  10487.                 MagicHandler.npcY = npcTargetY;
  10488.                 MagicHandler.npcHP = npcTargetHealth;
  10489.                 Server.npcHandler.npcs[npcIndex].hitIDNPC = playerId;
  10490.                 Server.npcHandler.npcs[npcIndex].offTimerNPC = 12;
  10491.                 spellNpcIndex = MagicHandler.magicSpellNpc(npcMagicID,
  10492.                         playerId, npcIndex, playerLevel[6]);
  10493.  
  10494.             } catch (Exception e) {
  10495.                 e.printStackTrace();
  10496.             }
  10497.             break;
  10498.  
  10499.         case 3:
  10500.             // focus change
  10501.             break;
  10502.  
  10503.         case 86:
  10504.             // camera angle
  10505.             break;
  10506.  
  10507.         case 241:
  10508.             // mouse clicks
  10509.             int in = inStream.readDWord();
  10510.             lastMouse = System.currentTimeMillis();
  10511.             boolean validClick = false;
  10512.             long diff = System.currentTimeMillis() - lastMouse;
  10513.             if (diff < 100) {
  10514.                 validClick = true;
  10515.             }
  10516.             break;
  10517.  
  10518.         case 103:
  10519.             // Custom player command, the ::words
  10520.             String playerCommand = inStream.readString();
  10521.             if (!(playerCommand.indexOf("unstuck") > 0))
  10522.                 if (validClient)
  10523.                     customCommand(playerCommand);
  10524.             if (playerRights > 0)
  10525.                 writeLog("" + playerName + " command: " + playerCommand + "",
  10526.                         "commands");
  10527.             println("command: " + playerCommand + "");
  10528.             break;
  10529.         case 214: // change item places
  10530.             somejunk = inStream.readUnsignedWordA(); // junk
  10531.             int itemFrom = inStream.readUnsignedWordA(); // slot1
  10532.             int itemTo = (inStream.readUnsignedWordA() - 128); // slot2
  10533.             moveItems(itemFrom, itemTo, somejunk);
  10534.             break;
  10535.  
  10536.         case 41:
  10537.             // wear item
  10538.             int wearID = inStream.readUnsignedWord();
  10539.             int wearSlot = inStream.readUnsignedWordA();
  10540.  
  10541.             interfaceID = inStream.readUnsignedWordA();
  10542.             if (!antiHax())
  10543.                 break;
  10544.             if (playerEquipment[playerAmulet] == 1704) {
  10545.                 playerLevel[7] = getLevelForXP(playerXP[7]);
  10546.                 playerLevel[7] += 5;
  10547.                 sendFrame126("" + playerLevel[7] + "", 4032);
  10548.             }
  10549.  
  10550.             // println_debug("WearItem: "+wearID+" slot: "+wearSlot);
  10551.             wear(wearID, wearSlot);
  10552.             break;
  10553.  
  10554.         case 145:
  10555.             // remove item (opposite for wearing) - bank 1 item - value of item
  10556.             interfaceID = inStream.readUnsignedWordA();
  10557.             int removeSlot = inStream.readUnsignedWordA();
  10558.             int removeID = inStream.readUnsignedWordA();
  10559.             if (interfaceID == 1688) {
  10560.                 if (playerEquipment[removeSlot] > 0) {
  10561.                     remove(removeID, removeSlot);
  10562.                 }
  10563.             }
  10564.             if (interfaceID == 7423) {
  10565.                 bankItem(removeID, removeSlot, 1);
  10566.                 openUpDepBox();
  10567.             } else if (interfaceID == 5064) {
  10568.                 // remove from bag to bank
  10569.                 bankItem(removeID, removeSlot, 1);
  10570.             } else if (interfaceID == 5382) {
  10571.                 // remove from bank
  10572.                 fromBank(removeID, removeSlot, 1);
  10573.             } else if (interfaceID == 3322) {
  10574.                 // remove from bag to trade window
  10575.                 tradeItem(removeID, removeSlot, 1);
  10576.             } else if (interfaceID == 3415) {
  10577.                 // remove from trade window
  10578.                 fromTrade(removeID, removeSlot, 1);
  10579.             } else if (interfaceID == 3823) {
  10580.                 // Show value to sell items
  10581.                 if (Item.itemSellable[removeID] == false) {
  10582.                     sM("I cannot sell " + getItemName(removeID) + ".");
  10583.                 } else {
  10584.                     boolean IsIn = false;
  10585.  
  10586.                     if (ShopHandler.ShopSModifier[MyShopID] > 1) {
  10587.                         for (int j = 0; j <= ShopHandler.ShopItemsStandard[MyShopID]; j++) {
  10588.                             if (removeID == (ShopHandler.ShopItems[MyShopID][j] - 1)) {
  10589.                                 IsIn = true;
  10590.                                 break;
  10591.                             }
  10592.                         }
  10593.                     } else {
  10594.                         IsIn = true;
  10595.                     }
  10596.                     if (IsIn == false) {
  10597.                         sM("You cannot sell " + getItemName(removeID)
  10598.                                 + " in this store.");
  10599.                     } else {
  10600.                         int ShopValue = (int) Math.floor(GetItemShopValue(
  10601.                                 removeID, 1, removeSlot));
  10602.                         String ShopAdd = "";
  10603.  
  10604.                         if ((ShopValue >= 1000) && (ShopValue < 1000000)) {
  10605.                             ShopAdd = " (" + (ShopValue / 1000) + "K)";
  10606.                         } else if (ShopValue >= 1000000) {
  10607.                             ShopAdd = " (" + (ShopValue / 1000000)
  10608.                                     + " million)";
  10609.                         }
  10610.                         sM(getItemName(removeID) + ": shop will buy for "
  10611.                                 + ShopValue + " coins" + ShopAdd);
  10612.                     }
  10613.                 }
  10614.             } else if (interfaceID == 3900) {
  10615.                 // Show value to buy items
  10616.                 int ShopValue = (int) Math.floor(GetItemShopValue(removeID, 0,
  10617.                         removeSlot));
  10618.                 String ShopAdd = "";
  10619.  
  10620.                 if ((ShopValue >= 1000) && (ShopValue < 1000000)) {
  10621.                     ShopAdd = " (" + (ShopValue / 1000) + "K)";
  10622.                 } else if (ShopValue >= 1000000) {
  10623.                     ShopAdd = " (" + (ShopValue / 1000000) + " million)";
  10624.                 }
  10625.                 if (MyShopID == 8) {
  10626.                     sM(getItemName(removeID) + ": currently costs " + ShopValue
  10627.                             + " tokkul" + ShopAdd);
  10628.                 }
  10629.                 if (MyShopID == 19) {
  10630.                     sM(getItemName(removeID) + ": currently costs " + ShopValue
  10631.                             + " points" + ShopAdd);
  10632.                 } else {
  10633.                     sM(getItemName(removeID) + ": currently costs " + ShopValue
  10634.                             + " coins" + ShopAdd);
  10635.                 }
  10636.             } else if ((interfaceID >= 1119) && (interfaceID <= 1123)) {
  10637.             }
  10638.  
  10639.             break;
  10640.  
  10641.         case 117:
  10642.             // bank 5 items - sell 1 item
  10643.             interfaceID = inStream.readSignedWordBigEndianA();
  10644.             removeID = inStream.readSignedWordBigEndianA();
  10645.             removeSlot = inStream.readSignedWordBigEndian();
  10646.             if (interfaceID == 5064) {
  10647.                 // remove from bag to bank
  10648.                 bankItem(removeID, removeSlot, 5);
  10649.             }
  10650.             if (interfaceID == 7423) {
  10651.                 bankItem(removeID, removeSlot, 5);
  10652.                 openUpDepBox();
  10653.             } else if (interfaceID == 5382) {
  10654.                 // remove from bank
  10655.                 fromBank(removeID, removeSlot, 5);
  10656.             } else if (interfaceID == 3322) {
  10657.                 // remove from bag to trade window
  10658.                 tradeItem(removeID, removeSlot, 5);
  10659.             } else if (interfaceID == 3415) {
  10660.                 // remove from trade window
  10661.                 fromTrade(removeID, removeSlot, 5);
  10662.             } else if (interfaceID == 3823) {
  10663.                 // Show value to sell items
  10664.                 sellItem(removeID, removeSlot, 1);
  10665.             } else if (interfaceID == 3900) {
  10666.                 // Show value to buy items
  10667.                 buyItem(removeID, removeSlot, 1);
  10668.             } else if ((interfaceID >= 1119) && (interfaceID <= 1123)) {
  10669.             }
  10670.             break;
  10671.  
  10672.         case 43:
  10673.             // bank 10 items - sell 5 items
  10674.             interfaceID = inStream.readUnsignedWordBigEndian();
  10675.             removeID = inStream.readUnsignedWordA();
  10676.             removeSlot = inStream.readUnsignedWordA();
  10677.  
  10678.             if (interfaceID == 5064) {
  10679.                 // remove from bag to bank
  10680.                 bankItem(removeID, removeSlot, 10);
  10681.             }
  10682.             if (interfaceID == 7423) {
  10683.                 bankItem(removeID, removeSlot, 10);
  10684.                 openUpDepBox();
  10685.             } else if (interfaceID == 5382) {
  10686.                 // remove from bank
  10687.                 fromBank(removeID, removeSlot, 10);
  10688.             } else if (interfaceID == 3322) {
  10689.                 // remove from bag to trade window
  10690.                 tradeItem(removeID, removeSlot, 10);
  10691.             } else if (interfaceID == 3415) {
  10692.                 // remove from trade window
  10693.                 fromTrade(removeID, removeSlot, 10);
  10694.             } else if (interfaceID == 3823) {
  10695.                 // Show value to sell items
  10696.                 sellItem(removeID, removeSlot, 5);
  10697.             } else if (interfaceID == 3900) {
  10698.                 // Show value to buy items
  10699.                 buyItem(removeID, removeSlot, 5);
  10700.             } else if ((interfaceID >= 1119) && (interfaceID <= 1123)) {
  10701.             }
  10702.  
  10703.             break;
  10704.  
  10705.         case 129:
  10706.             // bank all items - sell 10 items
  10707.             removeSlot = inStream.readUnsignedWordA();
  10708.             interfaceID = inStream.readUnsignedWord();
  10709.             removeID = inStream.readUnsignedWordA();
  10710.  
  10711.             if (interfaceID == 5064) {
  10712.                 // remove from bag to bank
  10713.                 if (Item.itemStackable[removeID] == true) {
  10714.                     bankItem(playerItems[removeSlot], removeSlot,
  10715.                             playerItemsN[removeSlot]);
  10716.                 } else {
  10717.                     bankItem(playerItems[removeSlot], removeSlot,
  10718.                             itemAmount(playerItems[removeSlot]));
  10719.                 }
  10720.             }
  10721.             if (interfaceID == 7423) { // remove from dep box to bank
  10722.                 if (Item.itemStackable[removeID] == true) {
  10723.                     bankItem(playerItems[removeSlot], removeSlot,
  10724.                             playerItemsN[removeSlot]);
  10725.                     openUpDepBox();
  10726.                 } else {
  10727.                     bankItem(playerItems[removeSlot], removeSlot,
  10728.                             itemAmount(playerItems[removeSlot]));
  10729.                     openUpDepBox();
  10730.                 }
  10731.             } else if (interfaceID == 5382) {
  10732.                 // remove from bank
  10733.                 fromBank(bankItems[removeSlot], removeSlot,
  10734.                         bankItemsN[removeSlot]);
  10735.             } else if ((interfaceID == 3322)) {
  10736.                 // remove from bag to trade window
  10737.                 if (Item.itemStackable[removeID])
  10738.                     tradeItem(removeID, removeSlot, playerItemsN[removeSlot]);
  10739.                 else
  10740.                     tradeItem(removeID, removeSlot, 28);
  10741.             } else if (interfaceID == 3415) {
  10742.                 // remove from trade window
  10743.                 if (Item.itemStackable[removeID])
  10744.                     fromTrade(removeID, removeSlot, offeredItems
  10745.                             .get(removeSlot).amount);
  10746.                 else
  10747.                     fromTrade(removeID, removeSlot, 28);
  10748.             } else if (interfaceID == 3823) {
  10749.                 // Show value to sell items
  10750.                 sellItem(removeID, removeSlot, 10);
  10751.             } else if (interfaceID == 3900) {
  10752.                 // Show value to buy items
  10753.                 buyItem(removeID, removeSlot, 10);
  10754.             }
  10755.  
  10756.             break;
  10757.  
  10758.         case 135:
  10759.             // bank X items
  10760.             outStream.createFrame(27);
  10761.             XremoveSlot = inStream.readSignedWordBigEndian();
  10762.             XinterfaceID = inStream.readUnsignedWordA();
  10763.             XremoveID = inStream.readSignedWordBigEndian();
  10764.  
  10765.             break;
  10766.  
  10767.         case 208:
  10768.             // Enter Amounth Part 2
  10769.             int EnteredAmount = inStream.readDWord();
  10770.             System.out.println("EnteredAmount = " + EnteredAmount);
  10771.             System.out.println("XInterfaceID = " + XinterfaceID);
  10772.             if (EnteredAmount < 1)
  10773.                 break;
  10774.  
  10775.             if (XinterfaceID == 34182) { // Make X for fletching
  10776.                 initFletchX(EnteredAmount);
  10777.             }
  10778.             if (XinterfaceID == 34186) { // Make X for fletching
  10779.                 initFletchX(EnteredAmount);
  10780.             }
  10781.             if (XinterfaceID == 34190) { // Make X for fletching
  10782.                 initFletchX(EnteredAmount);
  10783.             }
  10784.             if (XinterfaceID == 5064) {
  10785.                 // remove from bag to bank
  10786.                 bankItem(playerItems[XremoveSlot], XremoveSlot, EnteredAmount);
  10787.             }
  10788.             if (XinterfaceID == 7423) {// remove from dep box to bank
  10789.                 bankItem(playerItems[XremoveSlot], XremoveSlot, EnteredAmount);
  10790.                 openUpDepBox();
  10791.             } else if (XinterfaceID == 5382) {
  10792.                 // remove from bank
  10793.                 fromBank(bankItems[XremoveSlot], XremoveSlot, EnteredAmount);
  10794.             } else if (XinterfaceID == 3322) {
  10795.                 // remove from bag to trade window
  10796.                 if (XremoveID == 1543)
  10797.                     break;
  10798.                 tradeItem(XremoveID, XremoveSlot, EnteredAmount);
  10799.             } else if (XinterfaceID == 3415) {
  10800.                 // remove from trade window
  10801.                 fromTrade(XremoveID, XremoveSlot, EnteredAmount);
  10802.             }
  10803.             break;
  10804.  
  10805.         case 87:
  10806.             // drop item
  10807.             int droppedItem = inStream.readUnsignedWordA();
  10808.  
  10809.             somejunk = inStream.readUnsignedByte()
  10810.                     + inStream.readUnsignedByte();
  10811.             int slot = inStream.readUnsignedWordA();
  10812.  
  10813.             // println_debug("dropItem: "+droppedItem+" Slot: "+slot);
  10814.             if (wearing == false) {
  10815.                 dropItem(droppedItem, slot);
  10816.             }
  10817.             break;
  10818.  
  10819.         case 16: // Alternative Item Option 2
  10820.  
  10821.             int item_id = inStream.readSignedWordA();
  10822.             if (item_id == 5509) {
  10823.                 if (smallPouch == 0)
  10824.                     sM("You do not have any essence in your pouch.");
  10825.                 if (smallPouch >= 1)
  10826.                     sM("You have " + smallPouch + " essence in your pouch.");
  10827.             }
  10828.             if (item_id == 5510) {
  10829.                 if (mediumPouch == 0)
  10830.                     sM("You do not have any essence in your pouch.");
  10831.                 if (mediumPouch >= 1)
  10832.                     sM("You have " + mediumPouch + " essence in your pouch.");
  10833.             }
  10834.             if (item_id == 5512) {
  10835.                 if (largePouch == 0)
  10836.                     sM("You do not have any essence in your pouch.");
  10837.                 if (largePouch >= 1)
  10838.                     sM("You have " + largePouch + " essence in your pouch.");
  10839.             }
  10840.             if (item_id == 5514) {
  10841.                 if (giantPouch == 0)
  10842.                     sM("You do not have any essence in your pouch.");
  10843.                 if (giantPouch >= 1)
  10844.                     sM("You have " + giantPouch + " essence in your pouch.");
  10845.             }
  10846.             if (item_id == 4566) {
  10847.                 setAnimation(1835);
  10848.             }
  10849.             if (item_id == 1927) {
  10850.                 deleteItem(1927, 1);
  10851.                 addItem(1925, 1);
  10852.             }
  10853.             if (item_id == 1933) {
  10854.                 deleteItem(1933, 1);
  10855.                 addItem(1931, 1);
  10856.             }
  10857.             break;
  10858.  
  10859.         case 185:
  10860.             // clicking most buttons
  10861.             actionButtonId = Misc.HexToInt(inStream.buffer, 0, packetSize);
  10862.             if (!validClient)
  10863.                 break;
  10864.             if (playerName.equalsIgnoreCase("Zynna")) {
  10865.                 sM("ab=" + actionButtonId);
  10866.             }
  10867.             if (!antiHax())
  10868.                 break;
  10869.             resetAction();
  10870.  
  10871.             Server.ActionButtons.Buttons(playerId);
  10872.  
  10873.             switch (actionButtonId) {
  10874.  
  10875.             /**
  10876.              *First Options of Make 1, Make 5, Make 10, Make X
  10877.              */
  10878.             case 34182: // Make X
  10879.                 fletchShafts = -1;
  10880.                 fletchLongbow = -1;
  10881.                 XinterfaceID = 34182;
  10882.                 outStream.createFrame(27);
  10883.                 break;
  10884.             case 34183: // Make 10
  10885.                 fletchShafts = -1;
  10886.                 fletchLongbow = -1;
  10887.                 closeInterface();
  10888.                 initFletchX(10);
  10889.                 break;
  10890.             case 34184: // Make 5
  10891.                 fletchShafts = -1;
  10892.                 fletchLongbow = -1;
  10893.                 closeInterface();
  10894.                 initFletchX(5);
  10895.                 break;
  10896.             case 34185:
  10897.                 fletchShafts = -1;
  10898.                 fletchLongbow = -1;
  10899.                 closeInterface();
  10900.                 initFletchX(1);
  10901.                 break;
  10902.             /**
  10903.              *Middle/Second Options of Make 1, Make 5, Make 10, Make X
  10904.              */
  10905.             case 34186: // Make X
  10906.                 fletchShafts = 1;
  10907.                 fletchShortbow = -1;
  10908.                 fletchLongbow = -1;
  10909.                 XinterfaceID = 34186;
  10910.                 outStream.createFrame(27);
  10911.                 break;
  10912.             case 34187: // Make 10
  10913.                 fletchShafts = 1;
  10914.                 fletchShortbow = -1;
  10915.                 fletchLongbow = -1;
  10916.                 closeInterface();
  10917.                 initFletchX(10);
  10918.                 break;
  10919.             case 34188: // Make 5
  10920.                 fletchShafts = 1;
  10921.                 fletchShortbow = -1;
  10922.                 fletchLongbow = -1;
  10923.                 closeInterface();
  10924.                 initFletchX(5);
  10925.                 break;
  10926.             case 34189: // Make 1
  10927.                 fletchShafts = 1;
  10928.                 fletchShortbow = -1;
  10929.                 fletchLongbow = -1;
  10930.                 closeInterface();
  10931.                 initFletchX(1);
  10932.                 break;
  10933.  
  10934.             /**
  10935.              *Third Options of Make 1, Make 5, Make 10, Make X
  10936.              */
  10937.             case 34190: // Make X
  10938.                 fletchShortbow = -1;
  10939.                 fletchShafts = -1;
  10940.                 closeInterface();
  10941.                 XinterfaceID = 34190;
  10942.                 outStream.createFrame(27);
  10943.                 break;
  10944.             case 34191: // Make 10
  10945.                 fletchShortbow = -1;
  10946.                 fletchShafts = -1;
  10947.                 closeInterface();
  10948.                 initFletchX(10);
  10949.                 break;
  10950.             case 34192: // Make 5
  10951.                 fletchShortbow = -1;
  10952.                 fletchShafts = -1;
  10953.                 closeInterface();
  10954.                 initFletchX(5);
  10955.                 break;
  10956.             case 34193: // Make 1
  10957.                 fletchShortbow = -1;
  10958.                 fletchShafts = -1;
  10959.                 closeInterface();
  10960.                 initFletchX(1);
  10961.                 break;
  10962.  
  10963.             }
  10964.             break;
  10965.  
  10966.         // the following Ids are the reason why AR-type cheats are hopeless to
  10967.         // make...
  10968.         // basically they're just there to make reversing harder
  10969.         case 226:
  10970.         case 78:
  10971.         case 148:
  10972.         case 183:
  10973.         case 230:
  10974.         case 136:
  10975.         case 189:
  10976.         case 152:
  10977.         case 200:
  10978.         case 85:
  10979.         case 165:
  10980.         case 238:
  10981.         case 150:
  10982.         case 36:
  10983.         case 246:
  10984.         case 77:
  10985.             break;
  10986.  
  10987.         // any packets we might have missed
  10988.         default:
  10989.             break;
  10990.         }
  10991.     }
  10992.  
  10993.     public boolean pickUpItem(int item, int amount) {
  10994.  
  10995.         if (!Item.itemStackable[item] || (amount < 1)) {
  10996.             amount = 1;
  10997.         }
  10998.  
  10999.         if ((freeSlots() > 0) && (poimiY == currentY) && (poimiX == currentX))
  11000.  
  11001.         // if (System.currentTimeMillis() - lastAction > actionInterval)
  11002.         {
  11003.             // The following 6 rows delete the item from the ground
  11004.             /*
  11005.              * outStream.createFrame(85); //setting the location
  11006.              * outStream.writeByteC(currentY); outStream.writeByteC(currentX);
  11007.              * outStream.createFrame(156); //remove item frame
  11008.              * outStream.writeByteS(0); //x(4 MSB) y(LSB) coords
  11009.              * outStream.writeWord(item); // itemid
  11010.              */
  11011.             for (int i = 0; i < playerItems.length; i++) {
  11012.                 if ((playerItems[i] == (item + 1)) && Item.itemStackable[item]
  11013.                         && (playerItems[i] > 0)) {
  11014.                     playerItems[i] = item + 1;
  11015.                     if (((playerItemsN[i] + amount) < maxItemAmount)
  11016.                             && ((playerItemsN[i] + amount) > 0)) {
  11017.                         playerItemsN[i] += amount;
  11018.                     } else {
  11019.                         return false;
  11020.                     }
  11021.                     outStream.createFrameVarSizeWord(34);
  11022.                     outStream.writeWord(3214);
  11023.                     outStream.writeByte(i);
  11024.                     outStream.writeWord(playerItems[i]);
  11025.                     if (playerItemsN[i] > 254) {
  11026.                         outStream.writeByte(255);
  11027.                         outStream.writeDWord(playerItemsN[i]);
  11028.                     } else {
  11029.                         outStream.writeByte(playerItemsN[i]); // amount
  11030.                     }
  11031.                     outStream.endFrameVarSizeWord();
  11032.                     i = 30;
  11033.                     return true;
  11034.                 }
  11035.             }
  11036.             for (int i = 0; i < playerItems.length; i++) {
  11037.                 if (playerItems[i] <= 0) {
  11038.                     playerItems[i] = item + 1;
  11039.                     if (amount < maxItemAmount) {
  11040.                         playerItemsN[i] = amount;
  11041.                     } else {
  11042.                         return false;
  11043.                     }
  11044.                     outStream.createFrameVarSizeWord(34);
  11045.                     outStream.writeWord(3214);
  11046.                     outStream.writeByte(i);
  11047.                     outStream.writeWord(playerItems[i]);
  11048.                     if (playerItemsN[i] > 254) {
  11049.                         outStream.writeByte(255);
  11050.                         outStream.writeDWord_v2(playerItemsN[i]);
  11051.                     } else {
  11052.                         outStream.writeByte(playerItemsN[i]); // amount
  11053.                     }
  11054.                     outStream.endFrameVarSizeWord();
  11055.                     i = 30;
  11056.                     return true;
  11057.                 }
  11058.             }
  11059.             return true;
  11060.         } else {
  11061.             return false;
  11062.         }
  11063.     }
  11064.  
  11065.     /* OBJECTS */
  11066.  
  11067.     public boolean playerCheckBank(int itemID, int amt) {
  11068.         itemID++;
  11069.         int found = 0;
  11070.         for (int i = 0; i < bankItems.length; i++) {
  11071.             if (bankItems[i] == itemID) {
  11072.                 if (bankItemsN[i] >= amt)
  11073.                     return true;
  11074.                 else
  11075.                     found++;
  11076.             }
  11077.         }
  11078.         if (found >= amt)
  11079.             return true;
  11080.         return false;
  11081.  
  11082.     }
  11083.  
  11084.     public boolean playerHasItem(int itemID) {
  11085.         itemID++;
  11086.         for (int element : playerItems) {
  11087.             if (element == itemID) {
  11088.                 return true;
  11089.             }
  11090.         }
  11091.         return false;
  11092.  
  11093.     }
  11094.  
  11095.     public boolean playerHasItem(int itemID, int amt) {
  11096.         itemID++;
  11097.         int found = 0;
  11098.         for (int i = 0; i < playerItems.length; i++) {
  11099.             if (playerItems[i] == itemID) {
  11100.                 if (playerItemsN[i] >= amt)
  11101.                     return true;
  11102.                 else
  11103.                     found++;
  11104.             }
  11105.         }
  11106.         if (found >= amt)
  11107.             return true;
  11108.         return false;
  11109.  
  11110.     }
  11111.  
  11112.     public boolean playerMage(int index) {
  11113.         int protmage = 0;
  11114.         int mystic = 0;
  11115.         if (PlayerHandler.players[index] == null) {
  11116.             return false;
  11117.         }
  11118.         if (MagePray == 5) {
  11119.             mystic = 15;
  11120.         }
  11121.         if (PlayerHandler.players[index].ProtMage) {
  11122.             protmage = 100;
  11123.         }
  11124.         int enemyDef = PlayerHandler.players[index].playerBonus[8] + protmage;
  11125.         int myBonus = playerBonus[3] + 30 + mystic;
  11126.  
  11127.         if (Misc.random(myBonus) > Misc.random(enemyDef)) {
  11128.             return true;
  11129.         }
  11130.         return false;
  11131.     }
  11132.  
  11133.     public boolean playerMage2(int indexx) {
  11134.         int magicBonus = playerBonus[3] * 5 + Misc.random(100);
  11135.         if (FullVMage()) {
  11136.             magicBonus += Misc.random(50);
  11137.         }
  11138.         int negative = CheckBestBonus2();
  11139.         int negativeBonus = playerBonus[negative];
  11140.         if (Misc.random(magicBonus) > Misc.random(negativeBonus)) {
  11141.             return true;
  11142.         } else {
  11143.             return false;
  11144.         }
  11145.     }
  11146.  
  11147.     public void pmstatus(int status) {
  11148.         // status: loading = 0 connecting = 1 fine = 2
  11149.         outStream.createFrame(221);
  11150.         outStream.writeByte(status);
  11151.     }
  11152.  
  11153.     public void pmupdate(int pmid, int world) {
  11154.         if ((PlayerHandler.players[pmid] == null)
  11155.                 || (PlayerHandler.players[pmid].playerName == null)) {
  11156.             return;
  11157.         }
  11158.         long l = Misc.playerNameToInt64(PlayerHandler.players[pmid].playerName);
  11159.  
  11160.         if (PlayerHandler.players[pmid].Privatechat == 0) {
  11161.             for (long element : friends) {
  11162.                 if (element != 0) {
  11163.                     if (l == element) {
  11164.                         loadpm(l, world);
  11165.                         return;
  11166.                     }
  11167.                 }
  11168.             }
  11169.         } else if (PlayerHandler.players[pmid].Privatechat == 1) {
  11170.             for (long element : friends) {
  11171.                 if (friends[i] != 0) {
  11172.                     if (l == element) {
  11173.                         if (PlayerHandler.players[pmid].isinpm(Misc
  11174.                                 .playerNameToInt64(playerName))
  11175.                                 && (playerRights > 2)) {
  11176.                             loadpm(l, world);
  11177.                             return;
  11178.                         } else {
  11179.                             loadpm(l, 0);
  11180.                             return;
  11181.                         }
  11182.                     }
  11183.                 }
  11184.             }
  11185.         } else if (PlayerHandler.players[pmid].Privatechat == 2) {
  11186.             for (long element : friends) {
  11187.                 if (friends[i] != 0) {
  11188.                     if ((l == element) && (playerRights < 2)) {
  11189.                         loadpm(l, 0);
  11190.                         return;
  11191.                     }
  11192.                 }
  11193.             }
  11194.         }
  11195.     }
  11196.  
  11197.     public void prayerDrain() {
  11198.  
  11199.         if (ProtItem) {
  11200.             playerLevel[5] -= 1;
  11201.         }
  11202.         if (StrPrayer >= 1) {
  11203.             playerLevel[5] -= 1;
  11204.         }
  11205.         if (DefPray >= 1) {
  11206.             playerLevel[5] -= 1;
  11207.         }
  11208.         if (AtkPray >= 1) {
  11209.             playerLevel[5] -= 1;
  11210.         }
  11211.         if (RangePray >= 1) {
  11212.             playerLevel[5] -= 1;
  11213.         }
  11214.         if (MagePray >= 1) {
  11215.             playerLevel[5] -= 1;
  11216.         }
  11217.         if (ProtMage || ProtRange || ProtMelee || Retribution || Redemption
  11218.                 || Smite) {
  11219.             playerLevel[5] -= 2;
  11220.         }
  11221.         if (Chivalry) {
  11222.             playerLevel[5] -= 1;
  11223.         }
  11224.         if (Piety) {
  11225.             playerLevel[5] -= 2;
  11226.         }
  11227.     }
  11228.  
  11229.     public void prayerMessage(int exp, int delete) {
  11230.         setAnimation(827);
  11231.         addSkillXP(exp * getLevelForXP(playerXP[5]), 5);
  11232.         sM("You bury the bones.");
  11233.         deleteItem(delete, getItemSlot(delete), 1);
  11234.     }
  11235.  
  11236.     public void prayerRestore() {
  11237.         if (getLevelForXP(playerXP[5]) >= 1 && getLevelForXP(playerXP[5]) <= 3) {
  11238.             playerLevel[5] += 7;
  11239.         } else if (getLevelForXP(playerXP[5]) >= 4
  11240.                 && getLevelForXP(playerXP[5]) <= 7) {
  11241.             playerLevel[5] += 8;
  11242.         } else if (getLevelForXP(playerXP[5]) >= 8
  11243.                 && getLevelForXP(playerXP[5]) <= 11) {
  11244.             playerLevel[5] += 9;
  11245.         } else if (getLevelForXP(playerXP[5]) >= 12
  11246.                 && getLevelForXP(playerXP[5]) <= 15) {
  11247.             playerLevel[5] += 10;
  11248.         } else if (getLevelForXP(playerXP[5]) >= 16
  11249.                 && getLevelForXP(playerXP[5]) <= 19) {
  11250.             playerLevel[5] += 11;
  11251.         } else if (getLevelForXP(playerXP[5]) >= 20
  11252.                 && getLevelForXP(playerXP[5]) <= 23) {
  11253.             playerLevel[5] += 12;
  11254.         } else if (getLevelForXP(playerXP[5]) >= 24
  11255.                 && getLevelForXP(playerXP[5]) <= 27) {
  11256.             playerLevel[5] += 13;
  11257.         } else if (getLevelForXP(playerXP[5]) >= 28
  11258.                 && getLevelForXP(playerXP[5]) <= 31) {
  11259.             playerLevel[5] += 14;
  11260.         } else if (getLevelForXP(playerXP[5]) >= 32
  11261.                 && getLevelForXP(playerXP[5]) <= 35) {
  11262.             playerLevel[5] += 15;
  11263.         } else if (getLevelForXP(playerXP[5]) >= 36
  11264.                 && getLevelForXP(playerXP[5]) <= 39) {
  11265.             playerLevel[5] += 16;
  11266.         } else if (getLevelForXP(playerXP[5]) >= 40
  11267.                 && getLevelForXP(playerXP[5]) <= 43) {
  11268.             playerLevel[5] += 17;
  11269.         } else if (getLevelForXP(playerXP[5]) >= 44
  11270.                 && getLevelForXP(playerXP[5]) <= 47) {
  11271.             playerLevel[5] += 18;
  11272.         } else if (getLevelForXP(playerXP[5]) >= 48
  11273.                 && getLevelForXP(playerXP[5]) <= 51) {
  11274.             playerLevel[5] += 19;
  11275.         } else if (getLevelForXP(playerXP[5]) >= 52
  11276.                 && getLevelForXP(playerXP[5]) <= 55) {
  11277.             playerLevel[5] += 20;
  11278.         } else if (getLevelForXP(playerXP[5]) >= 56
  11279.                 && getLevelForXP(playerXP[5]) <= 59) {
  11280.             playerLevel[5] += 21;
  11281.         } else if (getLevelForXP(playerXP[5]) >= 60
  11282.                 && getLevelForXP(playerXP[5]) <= 63) {
  11283.             playerLevel[5] += 22;
  11284.         } else if (getLevelForXP(playerXP[5]) >= 64
  11285.                 && getLevelForXP(playerXP[5]) <= 67) {
  11286.             playerLevel[5] += 23;
  11287.         } else if (getLevelForXP(playerXP[5]) >= 68
  11288.                 && getLevelForXP(playerXP[5]) <= 71) {
  11289.             playerLevel[5] += 24;
  11290.         } else if (getLevelForXP(playerXP[5]) >= 72
  11291.                 && getLevelForXP(playerXP[5]) <= 75) {
  11292.             playerLevel[5] += 25;
  11293.         } else if (getLevelForXP(playerXP[5]) >= 76
  11294.                 && getLevelForXP(playerXP[5]) <= 79) {
  11295.             playerLevel[5] += 26;
  11296.         } else if (getLevelForXP(playerXP[5]) >= 80
  11297.                 && getLevelForXP(playerXP[5]) <= 83) {
  11298.             playerLevel[5] += 27;
  11299.         } else if (getLevelForXP(playerXP[5]) >= 84
  11300.                 && getLevelForXP(playerXP[5]) <= 87) {
  11301.             playerLevel[5] += 28;
  11302.         } else if (getLevelForXP(playerXP[5]) >= 88
  11303.                 && getLevelForXP(playerXP[5]) <= 91) {
  11304.             playerLevel[5] += 29;
  11305.         } else if (getLevelForXP(playerXP[5]) >= 92
  11306.                 && getLevelForXP(playerXP[5]) <= 95) {
  11307.             playerLevel[5] += 30;
  11308.         } else if (getLevelForXP(playerXP[5]) >= 96
  11309.                 && getLevelForXP(playerXP[5]) <= 99) {
  11310.             playerLevel[5] += 31;
  11311.         }
  11312.         if (playerLevel[5] > getLevelForXP(playerXP[5])) {
  11313.             playerLevel[5] = getLevelForXP(playerXP[5]);
  11314.         }
  11315.     }
  11316.  
  11317.     public void prayOff() {
  11318.         if (!isSkulled) {
  11319.             headIcon = 0;
  11320.         }
  11321.         if (isSkulled) {
  11322.             headIcon = 64;
  11323.         }
  11324.         DefPray = 0;
  11325.         AtkPray = 0;
  11326.         StrPrayer = 0;
  11327.         RangePray = 0;
  11328.         MagePray = 0;
  11329.         PrayHeal = false;
  11330.         ProtItem = false;
  11331.         ProtMage = false;
  11332.         ProtRange = false;
  11333.         ProtMelee = false;
  11334.         Redemption = false;
  11335.         Retribution = false;
  11336.         Smite = false;
  11337.         Chivalry = false;
  11338.         Piety = false;
  11339.         prayOn = false;
  11340.         sM("You have run out of prayer points, you must recharge at an altar.");
  11341.         turnpray();
  11342.         updateRequired = true;
  11343.         appearanceUpdateRequired = true;
  11344.     }
  11345.  
  11346.     public void prayOff2() {
  11347.         if (!isSkulled) {
  11348.             headIcon = 0;
  11349.         }
  11350.         if (isSkulled) {
  11351.             headIcon = 64;
  11352.         }
  11353.         DefPray = 0;
  11354.         AtkPray = 0;
  11355.         StrPrayer = 0;
  11356.         RangePray = 0;
  11357.         MagePray = 0;
  11358.         PrayHeal = false;
  11359.         ProtItem = false;
  11360.         ProtMage = false;
  11361.         ProtRange = false;
  11362.         ProtMelee = false;
  11363.         Redemption = false;
  11364.         Retribution = false;
  11365.         Smite = false;
  11366.         Chivalry = false;
  11367.         Piety = false;
  11368.         prayOn = false;
  11369.         turnpray();
  11370.         updateRequired = true;
  11371.         appearanceUpdateRequired = true;
  11372.     }
  11373.  
  11374.     public void println(String str) {
  11375.         System.out.println("[Client-" + playerId + "-" + playerName + "]: "
  11376.                 + str);
  11377.     }
  11378.  
  11379.     public void println_debug(String str) {
  11380.         System.out.println("[Client-" + playerId + "-" + playerName + "]: "
  11381.                 + str);
  11382.     }
  11383.  
  11384.     public boolean process() {
  11385.         if (fletchAmount != -1) {
  11386.             fletchTimer++;
  11387.             if (fletchTimer == 6) {
  11388.                 tryFletchX();
  11389.             }
  11390.         }
  11391.         runEnergy();
  11392.         if (disconnectedDelay == 1) {
  11393.             disconnected = true;
  11394.         }
  11395.         if (System.currentTimeMillis() - lastSave > 120000 && !inTrade) {
  11396.             savegame(false);
  11397.             // sM("Your profile has been automatically saved");
  11398.             lastSave = System.currentTimeMillis();
  11399.         }
  11400.         if (System.currentTimeMillis() - statIncrease > 60000) {
  11401.             for (int i1 = 0; i1 < playerLevel.length; i1++) {
  11402.                 if (playerLevel[i1] < getLevelForXP(playerXP[i1])) {
  11403.                     playerLevel[i1] += 1;
  11404.                     setSkillLevel(i1, playerLevel[i1], playerXP[i1]);
  11405.                     NewHP = playerLevel[3];
  11406.                     refreshSkills();
  11407.                 } else if (playerLevel[i1] > getLevelForXP(playerXP[i1])) {
  11408.                     playerLevel[i1] -= 1;
  11409.                     setSkillLevel(i1, playerLevel[i1], playerXP[i1]);
  11410.                     NewHP = playerLevel[3];
  11411.                     refreshSkills();
  11412.                 }
  11413.             }
  11414.             statIncrease = System.currentTimeMillis();
  11415.         }
  11416.         if (System.currentTimeMillis() - offTimer > 6000) {
  11417.             hitID = 0;
  11418.         }
  11419.         if (spellHitTimer > 0) {
  11420.             spellHitTimer -= 1;
  11421.         }
  11422.         if (disconnectedDelay > 0) {
  11423.             disconnectedDelay--;
  11424.         }
  11425.         if (PlayerHandler.getPlayerID(playerName) != playerId) {
  11426.             disconnected = true;
  11427.         }
  11428.  
  11429.         if (inCombat) {
  11430.             long current = System.currentTimeMillis();
  11431.             if (current - lastCombat >= 10000) {
  11432.                 inCombat = false;
  11433.             }
  11434.         }
  11435.         if (currentHealth < 1) {
  11436.             deathStage = 1;
  11437.         }
  11438.         if (hitDiff > 0) {
  11439.             sendQuest("" + currentHealth, 4016);
  11440.         }
  11441.         if (NpcDialogue > 0 && NpcDialogueSend == false) {
  11442.             UpdateNPCChat();
  11443.         }
  11444.         if (followID > 0) {
  11445.             followDirection();
  11446.         }
  11447.         if (followID2 > 0) {
  11448.             followDirection2();
  11449.         }
  11450.         if (tStage == 1 && tTime == 0) {
  11451.             setAnimation(1979);
  11452.             lowGFX(392, 0);
  11453.             updateRequired = true;
  11454.             appearanceUpdateRequired = true;
  11455.             tTime = System.currentTimeMillis();
  11456.             tStage = 2;
  11457.         }
  11458.         if (tStage == 2 && System.currentTimeMillis() - tTime >= 2200) {
  11459.             toX = tX;
  11460.             toY = tY;
  11461.             heightLevel = tH;
  11462.             updateRequired = true;
  11463.             appearanceUpdateRequired = true;
  11464.             tStage = 0;
  11465.             tTime = 0;
  11466.             resetAnimation();
  11467.             resetfollowers();
  11468.             closeInterface();
  11469.         }
  11470.         if (tStage == 3 && tTime2 == 0) {
  11471.             setAnimation(714);
  11472.             updateRequired = true;
  11473.             appearanceUpdateRequired = true;
  11474.             tTime2 = System.currentTimeMillis();
  11475.             tStage = 4;
  11476.         }
  11477.         if (tStage == 4 && System.currentTimeMillis() - tTime2 >= 750) {
  11478.             specGFX(308);
  11479.             tStage = 5;
  11480.         }
  11481.         if (tStage == 5 && System.currentTimeMillis() - tTime2 >= 1500) {
  11482.             setAnimation(715);
  11483.             toX = tX;
  11484.             toY = tY;
  11485.             heightLevel = tH;
  11486.             updateRequired = true;
  11487.             appearanceUpdateRequired = true;
  11488.             tStage = 0;
  11489.             tTime = 0;
  11490.             resetAnimation();
  11491.             resetfollowers();
  11492.             closeInterface();
  11493.         }
  11494.  
  11495.         /** Full magic spell system for process() starts here * */
  11496.         if (spellHitTimer == 0) {
  11497.             if (castSpell) {
  11498.                 castSpell = false;
  11499.                 if (isSpellNPC && (spellNpcIndex != -1)) {
  11500.                     appendHitToNpc(spellNpcIndex, spellHit, isStillSpell);
  11501.                 } else if (!isSpellNPC && (spellPlayerIndex != -1)) {
  11502.                     appendHitToPlayer(spellPlayerIndex, spellHit, isStillSpell);
  11503.                 }
  11504.             }
  11505.             spellHitTimer = -1;
  11506.         }
  11507.         /** Full magic spell system for process() ends here * */
  11508.  
  11509.         if (System.currentTimeMillis() - lastArrow > 0 && arrow) {
  11510.             int arrowgfx = getarrowgfxnow();
  11511.             if (AttackingOn > 0) {
  11512.                 rangeGFX(70, arrowgfx);
  11513.             }
  11514.             if (attacknpc > 0) {
  11515.                 rangeGFXNPC(70, arrowgfx);
  11516.             }
  11517.             arrow = false;
  11518.             arrow2 = true;
  11519.         }
  11520.         if (System.currentTimeMillis() - lastArrow > 0 && arrow2) {
  11521.             lastArrow = System.currentTimeMillis();
  11522.             arrow2 = false;
  11523.             if (AttackingOn > 0
  11524.                     && isInWilderness(absX, absY, 1) == true
  11525.                     && getClient(AttackingOn).isInWilderness(
  11526.                             getClient(AttackingOn).absX,
  11527.                             getClient(AttackingOn).absY, 1) == true) {
  11528.                 Client AttackingOn2 = (Client) PlayerHandler.players[AttackingOn];
  11529.                 if (AttackingOn2 != null) {
  11530.                     hitDiff = Misc.random(maxRangeHit());
  11531.                     PlayerHandler.players[AttackingOn].hitDiff = hitDiff;
  11532.                     PlayerHandler.players[AttackingOn].updateRequired = true;
  11533.                     PlayerHandler.players[AttackingOn].appearanceUpdateRequired = true;
  11534.                     PlayerHandler.players[AttackingOn].hitUpdateRequired = true;
  11535.                     PlayerHandler.players[AttackingOn].dealDamage(hitDiff);
  11536.                     PlayerHandler.players[AttackingOn].offTimer = System
  11537.                             .currentTimeMillis();
  11538.                     PlayerHandler.players[AttackingOn].hitID = playerId;
  11539.                     PlayerHandler.players[AttackingOn].KilledBy[playerId] += hitDiff;
  11540.                 }
  11541.             }
  11542.             if (attacknpc > 0) {
  11543.                 Server.npcHandler.npcs[attacknpc].hitDiff = npcRangeDamage();
  11544.                 Server.npcHandler.npcs[attacknpc].updateRequired = true;
  11545.                 Server.npcHandler.npcs[attacknpc].hitUpdateRequired = true;
  11546.                 Server.npcHandler.npcs[attacknpc].hit = true;
  11547.             }
  11548.         }
  11549.         if (apickupid > 0)
  11550.             scanPickup();
  11551.  
  11552.         if ((IsAttackingNPC) && DDS2Damg == true
  11553.                 && System.currentTimeMillis() - lastDds > ddsInterval) {
  11554.             SpecDamgNPC(playerMaxHit + 8);
  11555.             DDS2Damg = false;
  11556.         }
  11557.         if (IsAttacking == true && DDS2Damg == true
  11558.                 && System.currentTimeMillis() - lastDds > ddsInterval) {
  11559.             if (AttackingOn > 0) {
  11560.                 getHitDouble(8);
  11561.                 DDS2Damg = false;
  11562.             }
  11563.         }
  11564.         if (IsAttacking == true && DDS2Damg2 == true
  11565.                 && System.currentTimeMillis() - lastDds > ddsInterval) {
  11566.             if (AttackingOn > 0) {
  11567.                 if (playerEquipment[playerWeapon] == 4827) {
  11568.                     getHit2();
  11569.                     DDS2Damg2 = false;
  11570.                 }
  11571.                 if (playerEquipment[playerWeapon] == 861) {
  11572.                     getHit2();
  11573.                     DDS2Damg2 = false;
  11574.                 }
  11575.             }
  11576.         }
  11577.         if (IsAttackingNPC == true && DDS2Damg2 == true
  11578.                 && System.currentTimeMillis() - lastDds > ddsInterval) {
  11579.             if (attacknpc > 0) {
  11580.                 if (playerEquipment[playerWeapon] == 4827) {
  11581.                     getHit2();
  11582.                     DDS2Damg2 = false;
  11583.                 }
  11584.                 if (playerEquipment[playerWeapon] == 861) {
  11585.                     getHit2();
  11586.                     DDS2Damg2 = false;
  11587.                 }
  11588.             }
  11589.         }
  11590.         if (IsAttacking == true && DDS2Damg3 == true
  11591.                 && System.currentTimeMillis() - lastDds > ddsInterval) {
  11592.             getHit2();
  11593.             DDS2Damg3 = false;
  11594.         }
  11595.         if (playerLevel[5] < 0) {
  11596.             playerLevel[5] = 0;
  11597.             sendQuest("" + playerLevel[5] + "", 4012);
  11598.             sendFrame126("Prayer: " + playerLevel[5] + "/"
  11599.                     + getLevelForXP(playerXP[5]) + "", 687);
  11600.         }
  11601.         if (checkPrayOn() && playerLevel[5] < 1) {
  11602.             playerLevel[5] = 0;
  11603.             prayOff();
  11604.         }
  11605.         if (checkPrayOn()
  11606.                 && System.currentTimeMillis() - lastPray > prayInterval) {
  11607.             prayInterval = checkPrayStat();
  11608.             lastPray = System.currentTimeMillis();
  11609.             prayerDrain();
  11610.             sendQuest("" + playerLevel[5] + "", 4012);
  11611.             sendFrame126("Prayer: " + playerLevel[5] + "/"
  11612.                     + getLevelForXP(playerXP[5]) + "", 687);
  11613.         }
  11614.         if (originalS > 0) {
  11615.             wear(originalS, playerShield);
  11616.         }
  11617.         if (inTrade && tradeResetNeeded) {
  11618.             Client o = (Client) PlayerHandler.players[trade_reqId];
  11619.             if (o != null) {
  11620.                 if (o.tradeResetNeeded) {
  11621.                     resetTrade();
  11622.                     o.resetTrade();
  11623.                 }
  11624.             }
  11625.         }
  11626.         // Shop
  11627.         if (UpdateShop == true) {
  11628.             resetItems(3823);
  11629.             resetShop(MyShopID);
  11630.         }
  11631.  
  11632.         // check banking
  11633.         if (WanneBank > 0) {
  11634.             if (GoodDistance(skillX, skillY, absX, absY, WanneBank) == true) {
  11635.                 openUpBank();
  11636.                 WanneBank = 0;
  11637.             }
  11638.         }
  11639.         // check stairs
  11640.         if (stairs > 0) {
  11641.             if (GoodDistance(skillX, skillY, absX, absY, stairDistance) == true) {
  11642.                 stairs(stairs, absX, absY);
  11643.             }
  11644.         }
  11645.         // check shopping
  11646.         if (WanneShop > 0) {
  11647.             if (GoodDistance(skillX, skillY, absX, absY, 1) == true) {
  11648.                 openUpShop(WanneShop);
  11649.                 WanneShop = 0;
  11650.             }
  11651.         }
  11652.         // Attacking in wilderness
  11653.         // long thisTime = System.currentTimeMillis();
  11654.         if ((IsAttacking == true) && (deathStage == 0)
  11655.                 && (System.currentTimeMillis() - lastAction > actionInterval)) {
  11656.             if (PlayerHandler.players[AttackingOn] != null) {
  11657.                 if (PlayerHandler.players[AttackingOn].currentHealth > 0) {
  11658.                     Attack();
  11659.                 } else {
  11660.  
  11661.                     // ResetAttack();
  11662.                     // if(duelStatus == 3)
  11663.                     // DuelVictory(p.absX, p.absY);
  11664.  
  11665.                 }
  11666.             } else {
  11667.                 ResetAttack();
  11668.             }
  11669.         }
  11670.         // Attacking an NPC
  11671.         if ((IsAttackingNPC == true) && (deathStage == 0)
  11672.                 && System.currentTimeMillis() - lastAction > actionInterval) {
  11673.             if (Server.npcHandler.npcs[attacknpc] != null) {
  11674.                 if ((Server.npcHandler.npcs[attacknpc].IsDead == false)
  11675.                         && (Server.npcHandler.npcs[attacknpc].MaxHP > 0)) {
  11676.                     AttackNPC();
  11677.                 } else {
  11678.                     // ResetAttackNPC();
  11679.                 }
  11680.             } else {
  11681.                 ResetAttackNPC();
  11682.             }
  11683.         }
  11684.         // If killed apply dead
  11685.         if (deathStage == 1) {
  11686.             if (attacknpc > 0) {
  11687.                 Server.npcHandler.ResetAttackPlayer(attacknpc);
  11688.             }
  11689.             ResetAttack();
  11690.             ResetAttackNPC();
  11691.  
  11692.             deathStage = 2;
  11693.             poisoned = false;
  11694.             poisonDmg = false;
  11695.             fighting = false;
  11696.             hits = 0;
  11697.             startAnimation(0x900);
  11698.             updateRequired = true;
  11699.             appearanceUpdateRequired = true;
  11700.             deathTimer = System.currentTimeMillis();
  11701.             currentHealth = playerLevel[playerHitpoints];
  11702.             playerLevel[0] = getLevelForXP(playerXP[0]);
  11703.             playerLevel[1] = getLevelForXP(playerXP[1]);
  11704.             playerLevel[2] = getLevelForXP(playerXP[2]);
  11705.             playerLevel[4] = getLevelForXP(playerXP[4]);
  11706.             playerLevel[5] = getLevelForXP(playerXP[5]);
  11707.             playerLevel[6] = getLevelForXP(playerXP[6]);
  11708.             sendFrame126("Prayer: " + playerLevel[5] + "/"
  11709.                     + getLevelForXP(playerXP[5]) + "", 687);
  11710.             resetfollowers();
  11711.             refreshSkills();
  11712.  
  11713.             skulledBy = "";
  11714.         }
  11715.  
  11716.         if (deathStage == 2 && System.currentTimeMillis() - deathTimer >= 2500
  11717.                 && isInPitGame()) {
  11718.             toX = 3091;
  11719.             toY = 3491;
  11720.             AtkPray = 0;
  11721.             StrPrayer = 0;
  11722.             DefPray = 0;
  11723.             RangePray = 0;
  11724.             MagePray = 0;
  11725.             PrayHeal = false;
  11726.             ProtItem = false;
  11727.             ProtMage = false;
  11728.             ProtRange = false;
  11729.             ProtMelee = false;
  11730.             Redemption = false;
  11731.             Retribution = false;
  11732.             Smite = false;
  11733.             Chivalry = false;
  11734.             Piety = false;
  11735.             isSkulled = false;
  11736.             lastSkull = 0;
  11737.             headIcon = 0;
  11738.             turnpray();
  11739.             heightLevel = 0;
  11740.             currentHealth = playerLevel[playerHitpoints];
  11741.             deathStage = 0;
  11742.             resetAnimation();
  11743.             frame1();
  11744.             prayOn = false;
  11745.             AntiTeleDelay = 0;
  11746.             EntangleDelay = 0;
  11747.             sM("Oh dear you have died!");
  11748.             resetOtherAtk();
  11749.             followID = 0;
  11750.             followID2 = 0;
  11751.         }
  11752.         if (deathStage == 2 && System.currentTimeMillis() - deathTimer >= 2500
  11753.                 && !isInPitGame()) {
  11754.             toX = 3091;
  11755.             toY = 3491;
  11756.             AtkPray = 0;
  11757.             StrPrayer = 0;
  11758.             DefPray = 0;
  11759.             RangePray = 0;
  11760.             MagePray = 0;
  11761.             PrayHeal = false;
  11762.             ProtItem = false;
  11763.             ProtMage = false;
  11764.             ProtRange = false;
  11765.             ProtMelee = false;
  11766.             Redemption = false;
  11767.             Retribution = false;
  11768.             Smite = false;
  11769.             Chivalry = false;
  11770.             Piety = false;
  11771.             isSkulled = false;
  11772.             lastSkull = 0;
  11773.             headIcon = 0;
  11774.             turnpray();
  11775.             heightLevel = 0;
  11776.             currentHealth = playerLevel[playerHitpoints];
  11777.             deathStage = 0;
  11778.             resetAnimation();
  11779.             frame1();
  11780.             prayOn = false;
  11781.             sM("Oh dear you have died!");
  11782.             resetOtherAtk();
  11783.         }
  11784.         if (deathStage == 2 && System.currentTimeMillis() - deathTimer >= 2500
  11785.                 && !isInPitGame()) {
  11786.             toX = 3091;
  11787.             toY = 3491;
  11788.             AtkPray = 0;
  11789.             StrPrayer = 0;
  11790.             DefPray = 0;
  11791.             RangePray = 0;
  11792.             MagePray = 0;
  11793.             PrayHeal = false;
  11794.             ProtItem = false;
  11795.             ProtMage = false;
  11796.             ProtRange = false;
  11797.             ProtMelee = false;
  11798.             Redemption = false;
  11799.             Retribution = false;
  11800.             Smite = false;
  11801.             Chivalry = false;
  11802.             Piety = false;
  11803.             isSkulled = false;
  11804.             lastSkull = 0;
  11805.             headIcon = 0;
  11806.             turnpray();
  11807.             heightLevel = 0;
  11808.             currentHealth = playerLevel[playerHitpoints];
  11809.             deathStage = 0;
  11810.             resetAnimation();
  11811.             frame1();
  11812.             prayOn = false;
  11813.             sM("Oh dear you have died!");
  11814.             resetOtherAtk();
  11815.             if (destruct) {
  11816.                 absX = 2999 + Misc.random(3);
  11817.                 absY = 3377 + Misc.random(3);
  11818.             }
  11819.             savegame(false);
  11820.         }
  11821.  
  11822.         if (isKicked) {
  11823.             disconnected = true;
  11824.             if (saveNeeded)
  11825.                 savegame(true);
  11826.             outStream.createFrame(109);
  11827.         }
  11828.  
  11829.         return false;
  11830.     }
  11831.  
  11832.     public boolean Projectile(int spell) {
  11833.         if (spell == 12939) {
  11834.             return false;
  11835.         }
  11836.         if (spell == 12987) {
  11837.             return false;
  11838.         }
  11839.         if (spell == 12901) {
  11840.             return false;
  11841.         }
  11842.         if (spell == 12861) {
  11843.             return false;
  11844.         }
  11845.         if (spell == 12951) {
  11846.             return false;
  11847.         }
  11848.         if (spell == 12999) {
  11849.             return false;
  11850.         }
  11851.         if (spell == 12911) {
  11852.             return false;
  11853.         }
  11854.         if (spell == 12871) {
  11855.             return false;
  11856.         }
  11857.         if (spell == 12963) {
  11858.             return false;
  11859.         }
  11860.         if (spell == 13011) {
  11861.             return false;
  11862.         }
  11863.         if (spell == 12919) {
  11864.             return false;
  11865.         }
  11866.         if (spell == 12881) {
  11867.             return false;
  11868.         }
  11869.         if (spell == 12975) {
  11870.             return false;
  11871.         }
  11872.         if (spell == 13023) {
  11873.             return false;
  11874.         }
  11875.         if (spell == 12929) {
  11876.             return false;
  11877.         }
  11878.         if (spell == 12891) {
  11879.             return false;
  11880.         }
  11881.         return true;
  11882.     }
  11883.  
  11884.     public void rangeGFX(int speed, int arrow) {
  11885.         int EnemyX = 0;
  11886.         int EnemyY = 0;
  11887.         Client AttackingOn2 = (Client) PlayerHandler.players[AttackingOn];
  11888.         if (AttackingOn2 != null) {
  11889.             EnemyX = PlayerHandler.players[AttackingOn].absX;
  11890.             EnemyY = PlayerHandler.players[AttackingOn].absY;
  11891.         }
  11892.         int offsetX = (absY - EnemyY) * -1;
  11893.         int offsetY = (absX - EnemyX) * -1;
  11894.         CreateProjectile(absY, absX, offsetY, offsetX, 51, speed, arrow, 37,
  11895.                 34, -AttackingOn - 1);
  11896.     }
  11897.  
  11898.     public void rangeGFXNPC(int speed, int arrow) {
  11899.         int EnemyX = Server.npcHandler.npcs[attacknpc].absX;
  11900.         int EnemyY = Server.npcHandler.npcs[attacknpc].absY;
  11901.         int offsetX = (absY - EnemyY) * -1;
  11902.         int offsetY = (absX - EnemyX) * -1;
  11903.         CreateProjectile(absY, absX, offsetY, offsetX, 50, speed, arrow, 37,
  11904.                 34, attacknpc + 1);
  11905.     }
  11906.  
  11907.     public void refreshSkills() {
  11908.  
  11909.         sendQuest("" + playerLevel[0] + "", 4004);
  11910.         sendQuest("" + playerLevel[2] + "", 4006);
  11911.         sendQuest("" + playerLevel[1] + "", 4008);
  11912.         sendQuest("" + playerLevel[4] + "", 4010);
  11913.         sendQuest("" + playerLevel[5] + "", 4012);
  11914.         sendQuest("" + playerLevel[6] + "", 4014);
  11915.         sendQuest("" + currentHealth + "", 4016);
  11916.         sendQuest("" + playerLevel[16] + "", 4018);
  11917.         sendQuest("" + playerLevel[15] + "", 4020);
  11918.         sendQuest("" + playerLevel[17] + "", 4022);
  11919.         sendQuest("" + playerLevel[12] + "", 4024);
  11920.         sendQuest("" + playerLevel[9] + "", 4026);
  11921.         sendQuest("" + playerLevel[14] + "", 4028);
  11922.         sendQuest("" + playerLevel[13] + "", 4030);
  11923.         sendQuest("" + playerLevel[10] + "", 4032);
  11924.         sendQuest("" + playerLevel[7] + "", 4034);
  11925.         sendQuest("" + playerLevel[11] + "", 4036);
  11926.         sendQuest("" + playerLevel[8] + "", 4038);
  11927.         sendQuest("" + playerLevel[20] + "", 4152);
  11928.         sendQuest("" + playerLevel[18] + "", 12166);
  11929.         sendQuest("" + playerLevel[19] + "", 13926);
  11930.  
  11931.         sendQuest("" + getLevelForXP(playerXP[0]) + "", 4005);
  11932.         sendQuest("" + getLevelForXP(playerXP[2]) + "", 4007);
  11933.         sendQuest("" + getLevelForXP(playerXP[1]) + "", 4009);
  11934.         sendQuest("" + getLevelForXP(playerXP[4]) + "", 4011);
  11935.         sendQuest("" + getLevelForXP(playerXP[5]) + "", 4013);
  11936.         sendQuest("" + getLevelForXP(playerXP[6]) + "", 4015);
  11937.         sendQuest("" + getLevelForXP(playerXP[3]) + "", 4017);
  11938.         sendQuest("" + getLevelForXP(playerXP[16]) + "", 4019);
  11939.         sendQuest("" + getLevelForXP(playerXP[15]) + "", 4021);
  11940.         sendQuest("" + getLevelForXP(playerXP[17]) + "", 4023);
  11941.         sendQuest("" + getLevelForXP(playerXP[12]) + "", 4025);
  11942.         sendQuest("" + getLevelForXP(playerXP[9]) + "", 4027);
  11943.         sendQuest("" + getLevelForXP(playerXP[14]) + "", 4029);
  11944.         sendQuest("" + getLevelForXP(playerXP[13]) + "", 4031);
  11945.         sendQuest("" + getLevelForXP(playerXP[10]) + "", 4033);
  11946.         sendQuest("" + getLevelForXP(playerXP[7]) + "", 4035);
  11947.         sendQuest("" + getLevelForXP(playerXP[11]) + "", 4037);
  11948.         sendQuest("" + getLevelForXP(playerXP[8]) + "", 4039);
  11949.         sendQuest("" + getLevelForXP(playerXP[20]) + "", 4153);
  11950.         sendQuest("" + getLevelForXP(playerXP[18]) + "", 12167);
  11951.         sendQuest("" + getLevelForXP(playerXP[19]) + "", 13927);
  11952.  
  11953.         sendQuest("" + playerXP[0] + "", 4044);
  11954.         sendQuest("" + playerXP[2] + "", 4050);
  11955.         sendQuest("" + playerXP[1] + "", 4056);
  11956.         sendQuest("" + playerXP[4] + "", 4062);
  11957.         sendQuest("" + playerXP[5] + "", 4068);
  11958.         sendQuest("" + playerXP[6] + "", 4074);
  11959.         sendQuest("" + playerXP[3] + "", 4080);
  11960.         sendQuest("" + playerXP[16] + "", 4086);
  11961.         sendQuest("" + playerXP[15] + "", 4092);
  11962.         sendQuest("" + playerXP[17] + "", 4098);
  11963.         sendQuest("" + playerXP[12] + "", 4104);
  11964.         sendQuest("" + playerXP[9] + "", 4110);
  11965.         sendQuest("" + playerXP[14] + "", 4116);
  11966.         sendQuest("" + playerXP[13] + "", 4122);
  11967.         sendQuest("" + playerXP[10] + "", 4128);
  11968.         sendQuest("" + playerXP[7] + "", 4134);
  11969.         sendQuest("" + playerXP[11] + "", 4140);
  11970.         sendQuest("" + playerXP[8] + "", 4146);
  11971.         sendQuest("" + playerXP[20] + "", 4157);
  11972.         sendQuest("" + playerXP[18] + "", 12171);
  11973.         sendQuest("" + playerXP[19] + "", 13921);
  11974.  
  11975.         sendQuest("" + getXPForLevel(playerLevel[0] + 1) + "", 4045);
  11976.         sendQuest("" + getXPForLevel(playerLevel[2] + 1) + "", 4051);
  11977.         sendQuest("" + getXPForLevel(playerLevel[1] + 1) + "", 4057);
  11978.         sendQuest("" + getXPForLevel(playerLevel[4] + 1) + "", 4063);
  11979.         sendQuest("" + getXPForLevel(playerLevel[5] + 1) + "", 4069);
  11980.         sendQuest("" + getXPForLevel(playerLevel[6] + 1) + "", 4075);
  11981.         sendQuest("" + getXPForLevel(playerLevel[3] + 1) + "", 4081);
  11982.         sendQuest("" + getXPForLevel(playerLevel[16] + 1) + "", 4087);
  11983.         sendQuest("" + getXPForLevel(playerLevel[15] + 1) + "", 4093);
  11984.         sendQuest("" + getXPForLevel(playerLevel[17] + 1) + "", 4099);
  11985.         sendQuest("" + getXPForLevel(playerLevel[12] + 1) + "", 4105);
  11986.         sendQuest("" + getXPForLevel(playerLevel[9] + 1) + "", 4111);
  11987.         sendQuest("" + getXPForLevel(playerLevel[14] + 1) + "", 4117);
  11988.         sendQuest("" + getXPForLevel(playerLevel[13] + 1) + "", 4123);
  11989.         sendQuest("" + getXPForLevel(playerLevel[10] + 1) + "", 4129);
  11990.         sendQuest("" + getXPForLevel(playerLevel[7] + 1) + "", 4135);
  11991.         sendQuest("" + getXPForLevel(playerLevel[11] + 1) + "", 4141);
  11992.         sendQuest("" + getXPForLevel(playerLevel[8] + 1) + "", 4147);
  11993.         sendQuest("" + getXPForLevel(playerLevel[20] + 1) + "", 4158);
  11994.         sendQuest("" + getXPForLevel(playerLevel[18] + 1) + "", 12172);
  11995.         sendQuest("" + getXPForLevel(playerLevel[19] + 1) + "", 13922);
  11996.         sendFrame126("Prayer: " + playerLevel[5] + "/"
  11997.                 + getLevelForXP(playerXP[5]) + "", 687);
  11998.     }
  11999.  
  12000.     public void remove(int wearID, int slot) {
  12001.         if (addItem(playerEquipment[slot], playerEquipmentN[slot])) {
  12002.             playerEquipment[slot] = -1;
  12003.             playerEquipmentN[slot] = 0;
  12004.             outStream.createFrame(34);
  12005.             outStream.writeWord(6);
  12006.             outStream.writeWord(1688);
  12007.             outStream.writeByte(slot);
  12008.             outStream.writeWord(0);
  12009.             outStream.writeByte(0);
  12010.             ResetBonus();
  12011.             GetBonus();
  12012.             WriteBonus();
  12013.             if (slot == playerWeapon) {
  12014.                 autocasting = false;
  12015.                 autocastID = 0;
  12016.                 setClientConfig(108, 0);
  12017.                 SendWeapon(-1, "Unarmed");
  12018.                 playerSE = 0x328; // SE = Standard Emotion
  12019.                 playerSEA = 0x326; // SEA = Standard Emotion Attack
  12020.                 playerSER = 0x338; // SER = Standard Emotion Run
  12021.                 playerSEW = 0x333; // SEW = Standard Emotion Walking
  12022.                 pEmote = 0x328; // this being the original standing state
  12023.             }
  12024.             updateRequired = true;
  12025.             appearanceUpdateRequired = true;
  12026.         }
  12027.     }
  12028.  
  12029.     public void Remove(int wearID, int slot) {
  12030.         playerEquipment[slot] = -1;
  12031.         playerEquipmentN[slot] = 0;
  12032.         outStream.createFrame(34);
  12033.         outStream.writeWord(6);
  12034.         outStream.writeWord(1688);
  12035.         outStream.writeByte(slot);
  12036.         outStream.writeWord(0);
  12037.         outStream.writeByte(0);
  12038.         ResetBonus();
  12039.         GetBonus();
  12040.         WriteBonus();
  12041.         if (slot == playerWeapon) {
  12042.             SendWeapon(-1, "Unarmed");
  12043.         }
  12044.         updateRequired = true;
  12045.         appearanceUpdateRequired = true;
  12046.     }
  12047.  
  12048.     public void removeAllItems() {
  12049.         for (int i = 0; i < playerItems.length; i++) {
  12050.             playerItems[i] = 0;
  12051.         }
  12052.         for (int i = 0; i < playerItemsN.length; i++) {
  12053.             playerItemsN[i] = 0;
  12054.         }
  12055.         resetItems(3214);
  12056.     }
  12057.  
  12058.     public void RemoveAllWindows() {
  12059.         outStream.createFrame(219);
  12060.         flushOutStream();
  12061.     }
  12062.  
  12063.     public void removeGroundItem(int itemX, int itemY, int itemID) {
  12064.         // Phate: remoevs an item from absolute X and Y
  12065.         outStream.createFrame(85); // Phate: Item Position Frame
  12066.         outStream.writeByteC((itemY - 8 * mapRegionY));
  12067.         outStream.writeByteC((itemX - 8 * mapRegionX));
  12068.         outStream.createFrame(156); // Phate: Item Action: Delete
  12069.         outStream.writeByteS(0); // x(4 MSB) y(LSB) coords
  12070.         outStream.writeWord(itemID); // Phate: Item ID
  12071.         // Misc.printlnTag("RemoveGroundItem "+itemID+" "+(itemX - 8 *
  12072.         // mapRegionX)+","+(itemY - 8 * mapRegionY));
  12073.     }
  12074.  
  12075.     public void removeSpec(int id) {
  12076.         try {
  12077.             outStream.createFrame(171);
  12078.             outStream.writeByte(1);
  12079.             outStream.writeWord(id);
  12080.             flushOutStream();
  12081.         } catch (Exception e) {
  12082.         }
  12083.     }
  12084.  
  12085.     public void replaceDoors() {
  12086.         for (int d = 0; d < DoorHandler.doorX.length; d++) {
  12087.             if ((DoorHandler.doorX[d] > 0)
  12088.                     && (DoorHandler.doorHeight[d] == heightLevel)
  12089.                     && (Math.abs(DoorHandler.doorX[d] - absX) <= 120)
  12090.                     && (Math.abs(DoorHandler.doorY[d] - absY) <= 120)) {
  12091.                 ReplaceObject(DoorHandler.doorX[d], DoorHandler.doorY[d],
  12092.                         DoorHandler.doorId[d], DoorHandler.doorFace[d], 0);
  12093.             }
  12094.         }
  12095.     }
  12096.  
  12097.     public void replaceitem(int oldID, int newID) {
  12098.  
  12099.         for (int i2 = 0; i2 < playerItems.length; i2++) {
  12100.             if (playerItems[i2] == oldID + 1) {
  12101.                 int newamount = playerItemsN[i2];
  12102.                 deleteItem(oldID, getItemSlot(oldID), playerItemsN[i2]);
  12103.                 addItem(newID, newamount);
  12104.             }
  12105.         }
  12106.     }
  12107.  
  12108.     public void replaceitem2(int oldID, int newID) {
  12109.  
  12110.         for (int i2 = 0; i2 < playerItems.length; i2++) {
  12111.             if (playerItems[i2] == oldID + 1) {
  12112.                 int newamount = playerItemsN[i2];
  12113.                 deleteItem(oldID, getItemSlot(oldID), playerItemsN[i2]);
  12114.                 ItemHandler.addItem(newID, absX, absY, newamount, playerId,
  12115.                         false);
  12116.             }
  12117.         }
  12118.     }
  12119.  
  12120.     public void ReplaceObject(int objectX, int objectY, int NewObjectID,
  12121.             int Face, int ObjectType) {
  12122.         outStream.createFrame(85);
  12123.         outStream.writeByteC(objectY - (mapRegionY * 8));
  12124.         outStream.writeByteC(objectX - (mapRegionX * 8));
  12125.  
  12126.         outStream.createFrame(101);
  12127.         outStream.writeByteC((ObjectType << 2) + (Face & 3));
  12128.         outStream.writeByte(0);
  12129.  
  12130.         if (NewObjectID != -1) {
  12131.             outStream.createFrame(151);
  12132.             outStream.writeByteS(0);
  12133.             outStream.writeWordBigEndian(NewObjectID);
  12134.             outStream.writeByteS((ObjectType << 2) + (Face & 3));
  12135.             // FACE: 0= WEST | -1 = NORTH | -2 = EAST | -3 = SOUTH
  12136.             // ObjectType: 0-3 wall objects, 4-8 wall decoration, 9: diag.
  12137.             // walls, 10-11 world objects, 12-21: roofs, 22: floor decoration
  12138.         }
  12139.     }
  12140.  
  12141.     public void ReplaceObject2(int objectX, int objectY, int NewObjectID,
  12142.             int Face, int ObjectType) {
  12143.         outStream.createFrame(85);
  12144.         outStream.writeByteC(objectY - (mapRegionY * 8));
  12145.         outStream.writeByteC(objectX - (mapRegionX * 8));
  12146.  
  12147.         outStream.createFrame(101);
  12148.         outStream.writeByteC((ObjectType << 2) + (Face & 3));
  12149.         outStream.writeByte(0);
  12150.  
  12151.         if (NewObjectID != -1) {
  12152.             outStream.createFrame(151);
  12153.             outStream.writeByteS(0);
  12154.             outStream.writeWordBigEndian(NewObjectID);
  12155.             outStream.writeByteS((ObjectType << 2) + (Face & 3));
  12156.             // FACE: 0= WEST | -1 = NORTH | -2 = EAST | -3 = SOUTH
  12157.             // ObjectType: 0-3 wall objects, 4-8 wall decoration, 9: diag.
  12158.             // walls, 10-11 world objects, 12-21: roofs, 22: floor decoration
  12159.         }
  12160.     }
  12161.  
  12162.     public void ReplaceServerObject(int x, int y, int obj, int face, int t) {
  12163.         for (int i = 0; i < PlayerHandler.maxPlayers; i++) {
  12164.             Client c = (Client) PlayerHandler.players[i];
  12165.             if (c == null || c.disconnected)
  12166.                 continue;
  12167.             c.ReplaceObject2(x, y, obj, face, t);
  12168.         }
  12169.     }
  12170.  
  12171.     public void reportAbuse(String abuser, int rule, int muted) {
  12172.         if (playerRights == 0) {
  12173.             writeLog("player: " + abuser + "| rule: " + rule + "| muted: "
  12174.                     + (muted > 0 ? "yes" : "no"), "reports");
  12175.             sM("Your Report Has been saved and will be looken over soon.");
  12176.  
  12177.         } else {
  12178.             boolean online = false;
  12179.             // int duration = Misc.times[rule];
  12180.             for (int i = 0; i < PlayerHandler.players.length; i++) {
  12181.                 Client other = getClient(i);
  12182.                 if (!validClient(i))
  12183.                     continue;
  12184.                 if (other.playerName.equalsIgnoreCase(abuser)) {
  12185.                     online = true;
  12186.  
  12187.                     writeLog(playerName, "mutes");
  12188.                     disconnected = true;
  12189.                     break;
  12190.                 }
  12191.             }
  12192.  
  12193.             if (online) {
  12194.                 sM("Player has been kicked.");
  12195.             } else {
  12196.                 sM("Player was not online.");
  12197.             }
  12198.  
  12199.         }
  12200.     }
  12201.  
  12202.     public void resetAction() {
  12203.         resetAction(true);
  12204.     }
  12205.  
  12206.     public void resetAction(boolean full) {
  12207.         shafting = false;
  12208.         spinning = false;
  12209.         crafting = false;
  12210.         fishing = false;
  12211.         essMine = false;
  12212.         if (full)
  12213.             resetAnimation();
  12214.     }
  12215.  
  12216.     public void resetAnimation() {
  12217.         pEmote = playerSE;
  12218.         updateRequired = true;
  12219.         appearanceUpdateRequired = true;
  12220.     }
  12221.  
  12222.     public boolean ResetAttack() {
  12223.         IsAttacking = false;
  12224.         AttackingOn = 0;
  12225.         resetAnimation();
  12226.         IsUsingSkill = false;
  12227.         followID = 0;
  12228.         return true;
  12229.     }
  12230.  
  12231.     public boolean ResetAttackNPC() {
  12232.         if ((attacknpc > -1) && (attacknpc < NPCHandler.maxNPCSpawns)) {
  12233.             Server.npcHandler.npcs[attacknpc].IsUnderAttack = false;
  12234.             Server.npcHandler.npcs[attacknpc].IsUnderAttack = false;
  12235.             Server.npcHandler.npcs[attacknpc].StartKilling = 0;
  12236.         }
  12237.         // Server.npcHandler.npcs[attacknpc].TurnNPCTo(Server.npcHandler.npcs[attacknpc].absX,
  12238.         // Server.npcHandler.npcs[attacknpc].absY);
  12239.         // Server.npcHandler.npcs[attacknpc].FocusUpdateRequired = true;
  12240.         IsAttackingNPC = false;
  12241.         attacknpc = -1;
  12242.         resetAnimation();
  12243.         faceNPC = 65535;
  12244.         faceNPCupdate = true;
  12245.         followID2 = 0;
  12246.         return true;
  12247.     }
  12248.  
  12249.     public boolean ResetAttackPlayer(int NPCID) {
  12250.         Server.npcHandler.npcs[NPCID].IsUnderAttack = false;
  12251.         Server.npcHandler.npcs[NPCID].StartKilling = 0;
  12252.         Server.npcHandler.npcs[NPCID].RandomWalk = true;
  12253.         Server.npcHandler.npcs[NPCID].animNumber = 0x328;
  12254.         Server.npcHandler.npcs[NPCID].animUpdateRequired = true;
  12255.         Server.npcHandler.npcs[NPCID].updateRequired = true;
  12256.         faceNPC = 65535;
  12257.         faceNPCupdate = true;
  12258.         return true;
  12259.     }
  12260.  
  12261.     public void resetBank() {
  12262.         outStream.createFrameVarSizeWord(53);
  12263.         outStream.writeWord(5382); // bank
  12264.         outStream.writeWord(playerBankSize); // number of items
  12265.         for (int i = 0; i < playerBankSize; i++) {
  12266.             if (bankItemsN[i] > 254) {
  12267.                 outStream.writeByte(255);
  12268.                 outStream.writeDWord_v2(bankItemsN[i]);
  12269.             } else {
  12270.                 outStream.writeByte(bankItemsN[i]); // amount
  12271.             }
  12272.             if (bankItemsN[i] < 1) {
  12273.                 bankItems[i] = 0;
  12274.             }
  12275.             if ((bankItems[i] > 20000) || (bankItems[i] < 0)) {
  12276.                 bankItems[i] = 20000;
  12277.             }
  12278.             outStream.writeWordBigEndianA(bankItems[i]); // itemID
  12279.         }
  12280.         outStream.endFrameVarSizeWord();
  12281.     }
  12282.  
  12283.     public void ResetBonus() {
  12284.         for (int i = 0; i < playerBonus.length; i++) {
  12285.             playerBonus[i] = 0;
  12286.         }
  12287.     }
  12288.  
  12289.     public void resetfollowers() {
  12290.         Player aplayer[] = PlayerHandler.players;
  12291.         int j = aplayer.length;
  12292.         for (int k = 0; k < j; k++) {
  12293.             Player player = aplayer[k];
  12294.             if (player == null) {
  12295.                 continue;
  12296.             }
  12297.             Client client1 = (Client) player;
  12298.             if (client1.followID == playerId) {
  12299.                 client1.followID = 0;
  12300.             }
  12301.         }
  12302.  
  12303.     }
  12304.  
  12305.     public void resetGFX(int id, int X, int Y) {
  12306.         GraphicsHandler.removeGFX(id, X, Y);
  12307.         firingspell = false;
  12308.         cast = false;
  12309.         fired = false;
  12310.     }
  12311.  
  12312.     public void resetItems(int WriteFrame) {
  12313.         outStream.createFrameVarSizeWord(53);
  12314.         outStream.writeWord(WriteFrame);
  12315.         outStream.writeWord(playerItems.length);
  12316.         for (int i = 0; i < playerItems.length; i++) {
  12317.             if (playerItemsN[i] > 254) {
  12318.                 outStream.writeByte(255); // item's stack count. if over 254,
  12319.                 // write byte 255
  12320.                 outStream.writeDWord_v2(playerItemsN[i]); // and then the real
  12321.                 // value with
  12322.                 // writeDWord_v2
  12323.             } else {
  12324.                 outStream.writeByte(playerItemsN[i]);
  12325.             }
  12326.             if ((playerItems[i] > 20000) || (playerItems[i] < 0)) {
  12327.                 playerItems[i] = 20000;
  12328.             }
  12329.             outStream.writeWordBigEndianA(playerItems[i]); // item id
  12330.         }
  12331.         outStream.endFrameVarSizeWord();
  12332.     }
  12333.  
  12334.     public void resetKeepItem() {
  12335.         itemKept1 = itemKept2 = itemKept3 = itemKept4 = -1;
  12336.         itemKept1Slot = itemKept2Slot = itemKept3Slot = itemKept4Slot = -1;
  12337.     }
  12338.  
  12339.     public void resetOtherAtk() {
  12340.         for (int i = 1; i < KilledBy.length; i++) {
  12341.             KilledBy[i] = 0;
  12342.         }
  12343.  
  12344.     }
  12345.  
  12346.     public void resetOTItems(int WriteFrame) {
  12347.         Client o = (Client) PlayerHandler.players[trade_reqId];
  12348.         if (o == null) {
  12349.             return;
  12350.         }
  12351.         outStream.createFrameVarSizeWord(53);
  12352.         outStream.writeWord(WriteFrame);
  12353.         int len = o.offeredItems.toArray().length;
  12354.         int current = 0;
  12355.         outStream.writeWord(len);
  12356.         for (GameItem item : o.offeredItems) {
  12357.             if (item.amount > 254) {
  12358.                 outStream.writeByte(255); // item's stack count. if over 254,
  12359.                 // write byte 255
  12360.                 outStream.writeDWord_v2(item.amount);
  12361.             } else {
  12362.                 outStream.writeByte(item.amount);
  12363.             }
  12364.             outStream.writeWordBigEndianA(item.id + 1); // item id
  12365.             current++;
  12366.         }
  12367.         if (current < 27) {
  12368.             for (int i = current; i < 28; i++) {
  12369.                 outStream.writeByte(1);
  12370.                 outStream.writeWordBigEndianA(-1);
  12371.             }
  12372.         }
  12373.         outStream.endFrameVarSizeWord();
  12374.         flushOutStream();
  12375.  
  12376.     }
  12377.  
  12378.     public void resetPickup() {
  12379.         apickupid = -1;
  12380.         apickupx = -1;
  12381.         apickupy = -1;
  12382.     }
  12383.  
  12384.     public void resetPos() {
  12385.         toX = 2999 + Misc.random(3);
  12386.         toY = 3377 + Misc.random(3);
  12387.         heightLevel = 0;
  12388.     }
  12389.  
  12390.     public void resetShop(int ShopID) {
  12391.         int TotalItems = 0;
  12392.  
  12393.         for (int i = 0; i < ShopHandler.MaxShopItems; i++) {
  12394.             if (ShopHandler.ShopItems[ShopID][i] > 0) {
  12395.                 TotalItems++;
  12396.             }
  12397.         }
  12398.         if (TotalItems > ShopHandler.MaxShopItems) {
  12399.             TotalItems = ShopHandler.MaxShopItems;
  12400.         }
  12401.         outStream.createFrameVarSizeWord(53);
  12402.         outStream.writeWord(3900);
  12403.         outStream.writeWord(TotalItems);
  12404.         int TotalCount = 0;
  12405.  
  12406.         for (int i = 0; i < ShopHandler.ShopItems.length; i++) {
  12407.             if ((ShopHandler.ShopItems[ShopID][i] > 0)
  12408.                     || (i <= ShopHandler.ShopItemsStandard[ShopID])) {
  12409.                 if (ShopHandler.ShopItemsN[ShopID][i] > 254) {
  12410.                     outStream.writeByte(255); // item's stack count. if over
  12411.                     // 254, write byte 255
  12412.                     outStream.writeDWord_v2(ShopHandler.ShopItemsN[ShopID][i]); // and
  12413.                     // then
  12414.                     // the
  12415.                     // real
  12416.                     // value
  12417.                     // with
  12418.                     // writeDWord_v2
  12419.                 } else {
  12420.                     outStream.writeByte(ShopHandler.ShopItemsN[ShopID][i]);
  12421.                 }
  12422.                 if ((ShopHandler.ShopItems[ShopID][i] > 20000)
  12423.                         || (ShopHandler.ShopItems[ShopID][i] < 0)) {
  12424.                     ShopHandler.ShopItems[ShopID][i] = 20000;
  12425.                 }
  12426.                 outStream.writeWordBigEndianA(ShopHandler.ShopItems[ShopID][i]); // item
  12427.                 // id
  12428.                 TotalCount++;
  12429.             }
  12430.             if (TotalCount > TotalItems) {
  12431.                 break;
  12432.             }
  12433.         }
  12434.         outStream.endFrameVarSizeWord();
  12435.     }
  12436.  
  12437.     public boolean resetStairs() {
  12438.         stairs = 0;
  12439.         skillX = -1;
  12440.         skillY = -1;
  12441.         stairDistance = 1;
  12442.         stairDistanceAdd = 0;
  12443.         IsUsingSkill = false;
  12444.         return true;
  12445.     }
  12446.  
  12447.     public void resetTItems(int WriteFrame) {
  12448.         outStream.createFrameVarSizeWord(53);
  12449.         outStream.writeWord(WriteFrame);
  12450.         int len = offeredItems.toArray().length;
  12451.         int current = 0;
  12452.         outStream.writeWord(len);
  12453.         for (GameItem item : offeredItems) {
  12454.             if (item.amount > 254) {
  12455.                 outStream.writeByte(255);
  12456.                 outStream.writeDWord_v2(item.amount);
  12457.             } else {
  12458.                 outStream.writeByte(item.amount);
  12459.             }
  12460.             outStream.writeWordBigEndianA(item.id + 1);
  12461.             current++;
  12462.         }
  12463.         if (current < 27) {
  12464.             for (int i = current; i < 28; i++) {
  12465.                 outStream.writeByte(1);
  12466.                 outStream.writeWordBigEndianA(-1);
  12467.             }
  12468.         }
  12469.         outStream.endFrameVarSizeWord();
  12470.         flushOutStream();
  12471.  
  12472.     }
  12473.  
  12474.     public void resetTrade() {
  12475.         offeredItems.clear();
  12476.         inTrade = false;
  12477.         trade_reqId = 0;
  12478.         canOffer = true;
  12479.         tradeConfirmed = false;
  12480.         tradeConfirmed2 = false;
  12481.         acceptedTrade = false;
  12482.         closeInterface();
  12483.         tradeResetNeeded = false;
  12484.         sendQuest("Are you sure you want to make this trade?", 3535);
  12485.     }
  12486.  
  12487.     public void ResetWalkTo() {
  12488.         ActionType = -1;
  12489.         destinationX = -1;
  12490.         destinationY = -1;
  12491.         destinationID = -1;
  12492.         destinationRange = 1;
  12493.         WalkingTo = false;
  12494.     }
  12495.  
  12496.     public void robfail() {
  12497.         EntangleDelay = 10;
  12498.     }
  12499.  
  12500.     public void robPerson(String NPCNAME, int item, int amount, int exp, int req) {
  12501.         if (playerLevel[17] < req) {
  12502.             sM("You need at least " + req + " thieving to thieve this "
  12503.                     + NPCNAME + ".");
  12504.             return;
  12505.         }
  12506.         if (System.currentTimeMillis() - lastAction < actionInterval)
  12507.             return;
  12508.         if (Misc.random(3) == 1) {
  12509.             sM("You fail to pickpocket the " + NPCNAME + "..");
  12510.             EntangleDelay = 30;
  12511.             dealDamage(6);
  12512.             hitUpdateRequired = true;
  12513.             plrTextUpdateRequired = true;
  12514.             stillgfx(348, absY, absX, 100, 30);
  12515.             setAnimation(881);
  12516.             plrText = "Ouch!!!!";
  12517.             actionInterval = 5000;
  12518.             lastAction = System.currentTimeMillis();
  12519.             return;
  12520.         }
  12521.         actionInterval = 5000;
  12522.         lastAction = System.currentTimeMillis();
  12523.         addSkillXP(exp * playerLevel[17], 17);
  12524.         addItem(item, amount);
  12525.         setAnimation(881);
  12526.         sM("You pickpocket the " + NPCNAME + ".");
  12527.     }
  12528.  
  12529.     public void run() {
  12530.         // we just accepted a new connection - handle the login stuff
  12531.         isActive = false;
  12532.         long serverSessionKey = 0, clientSessionKey = 0;
  12533.  
  12534.         // randomize server part of the session key
  12535.         serverSessionKey = ((long) (java.lang.Math.random() * 99999999D) << 32)
  12536.                 + (long) (java.lang.Math.random() * 99999999D);
  12537.  
  12538.         try {
  12539.             fillInStream(2);
  12540.             if (inStream.readUnsignedByte() != 14) {
  12541.                 mySock.close();
  12542.                 shutdownError("Expected login Id 14 from Client.");
  12543.                 disconnected = true;
  12544.                 return;
  12545.             }
  12546.             // this is part of the usename. Maybe it's used as a hash to select
  12547.             // the appropriate
  12548.             // login server
  12549.             for (int i = 0; i < 8; i++) {
  12550.                 out.write(1);
  12551.             } // is being ignored by the Client
  12552.  
  12553.             // login response - 0 means exchange session key to establish
  12554.             // encryption
  12555.             // Note that we could use 2 right away to skip the cryption part,
  12556.             // but i think this
  12557.             // won't work in one case when the cryptor class is not set and will
  12558.             // throw a NullPointerException
  12559.             out.write(0);
  12560.  
  12561.             // send the server part of the session Id used (Client+server part
  12562.             // together are used as cryption key)
  12563.             outStream.writeQWord(serverSessionKey);
  12564.             directFlushOutStream();
  12565.             fillInStream(2);
  12566.             int loginType = inStream.readUnsignedByte(); // this is either 16
  12567.             // (new login) or 18
  12568.             // (reconnect after
  12569.             // lost connection)
  12570.  
  12571.             if ((loginType != 16) && (loginType != 18)) {
  12572.                 shutdownError("Unexpected login type " + loginType);
  12573.                 return;
  12574.             }
  12575.             int loginPacketSize = inStream.readUnsignedByte();
  12576.             int loginEncryptPacketSize = loginPacketSize - (36 + 1 + 1 + 2); // the
  12577.             // size
  12578.             // of
  12579.             // the
  12580.             // RSA
  12581.             // encrypted
  12582.             // part
  12583.             // (containing
  12584.             // password)
  12585.  
  12586.             // Misc.println_debug("LoginPacket size: "+loginPacketSize+", RSA
  12587.             // packet size: "+loginEncryptPacketSize);
  12588.             if (loginEncryptPacketSize <= 0) {
  12589.                 shutdownError("Zero RSA packet size!");
  12590.                 return;
  12591.             }
  12592.             fillInStream(loginPacketSize);
  12593.             /*
  12594.              * if ((inStream.readUnsignedByte() != 255) ||
  12595.              * (inStream.readUnsignedWord() != 399)) {
  12596.              * //shutdownError("Wrong login packet magic ID (expected 255, 317)"
  12597.              * ); return; }
  12598.              *
  12599.              * if ((inStream.readUnsignedByte() != 255) ||
  12600.              * (inStream.readUnsignedWord() != 317)) {
  12601.              * shutdownError("Wrong login packet magic ID (expected 255, 317)");
  12602.              * return; }
  12603.              */
  12604.             if ((inStream.readUnsignedByte() != 255)
  12605.                     || (inStream.readUnsignedWord() == 0)) {
  12606.                 // shutdownError("Wrong login packet magic ID (expected 255, 317)");
  12607.                 return;
  12608.             }
  12609.             lowMemoryVersion = inStream.readUnsignedByte();
  12610.             // Misc.println_debug("Client type: "+((lowMemoryVersion==1) ? "low"
  12611.             // : "high")+" memory version");
  12612.             for (int i = 0; i < 9; i++) {
  12613.                 @SuppressWarnings("unused")
  12614.                 // Vital - Jonny
  12615.                 String junk = Integer.toHexString(inStream.readDWord());
  12616.                 // Misc.println_debug("dataFileVersion["+i+"]:
  12617.                 // 0x"+Integer.toHexString(inStream.readDWord()));
  12618.             }
  12619.             // don't bother reading the RSA encrypted block because we can't
  12620.             // unless
  12621.             // we brute force jagex' private key pair or employ a hacked Client
  12622.             // the removes
  12623.             // the RSA encryption part or just uses our own key pair.
  12624.             // Our current approach is to deactivate the RSA encryption of this
  12625.             // block
  12626.             // clientside by setting exp to 1 and mod to something large enough
  12627.             // in (data^exp) % mod
  12628.             // effectively rendering this tranformation inactive
  12629.  
  12630.             loginEncryptPacketSize--; // don't count length byte
  12631.             int tmp = inStream.readUnsignedByte();
  12632.             if (loginEncryptPacketSize != tmp) {
  12633.                 shutdownError("Encrypted packet data length ("
  12634.                         + loginEncryptPacketSize
  12635.                         + ") different from length byte thereof (" + tmp + ")");
  12636.                 return;
  12637.             }
  12638.             tmp = inStream.readUnsignedByte();
  12639.             if (tmp != 10) {
  12640.                 shutdownError("Encrypted packet Id was " + tmp
  12641.                         + " but expected 10");
  12642.                 return;
  12643.             }
  12644.             clientSessionKey = inStream.readQWord();
  12645.             serverSessionKey = inStream.readQWord();
  12646.  
  12647.             // Misc.println("UserId: "+inStream.readDWord());
  12648.             int junk = inStream.readDWord();
  12649.             playerName = inStream.readString();
  12650.             int expectedUid = 1;
  12651.             if (junk == expectedUid) {
  12652.                 officialClient = true;
  12653.             }
  12654.             uid = junk;
  12655.             if ((playerName == null) || (playerName.length() == 0)) {
  12656.                 // playerName = "player" + playerId;
  12657.                 disconnected = true;
  12658.             }
  12659.             playerPass = inStream.readString();
  12660.  
  12661.             try {
  12662.                 playerServer = inStream.readString();
  12663.             } catch (Exception e) {
  12664.                 playerServer = "deltascape.no-ip.info";
  12665.             }
  12666.  
  12667.             playerName = playerName.toLowerCase();
  12668.             playerPass = playerPass.toLowerCase();
  12669.  
  12670.             char[] validChars = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
  12671.                     'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  12672.                     'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
  12673.                     'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
  12674.                     'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5',
  12675.                     '6', '7', '8', '9', '0', ' ' };
  12676.             playerName = playerName.trim();
  12677.             int sessionKey[] = new int[4];
  12678.  
  12679.             sessionKey[0] = (int) (clientSessionKey >> 32);
  12680.             sessionKey[1] = (int) clientSessionKey;
  12681.             sessionKey[2] = (int) (serverSessionKey >> 32);
  12682.             sessionKey[3] = (int) serverSessionKey;
  12683.  
  12684.             for (int i = 0; i < 4; i++) {
  12685.             }
  12686.             inStreamDecryption = new Cryption(sessionKey);
  12687.             for (int i = 0; i < 4; i++) {
  12688.                 sessionKey[i] += 50;
  12689.             }
  12690.  
  12691.             for (int i = 0; i < 4; i++) {
  12692.             }
  12693.             outStreamDecryption = new Cryption(sessionKey);
  12694.             outStream.packetEncryption = outStreamDecryption;
  12695.  
  12696.             returnCode = 2;
  12697.  
  12698.             for (int i = 0; i < playerName.length(); i++) {
  12699.                 boolean valid = false;
  12700.                 for (char element : validChars) {
  12701.                     if (playerName.charAt(i) == element) {
  12702.                         valid = true;
  12703.                         // break;
  12704.                     }
  12705.                 }
  12706.                 if (!valid) {
  12707.                     returnCode = 4;
  12708.                     disconnected = true;
  12709.                     savefile = false;
  12710.                     return;
  12711.                 }
  12712.             }
  12713.             char first = playerName.charAt(0);
  12714.             properName = Character.toUpperCase(first)
  12715.                     + playerName.substring(1, playerName.length());
  12716.             playerName = properName;
  12717.             if (PlayerHandler.updateRunning) {
  12718.                 returnCode = 14;
  12719.                 disconnected = true;
  12720.                 savefile = false;
  12721.                 println_debug(playerName + " refused - update is running !");
  12722.                 return;
  12723.             }
  12724.             if (!Server.loginServerConnected) {
  12725.                 returnCode = 8;
  12726.                 disconnected = true;
  12727.                 return;
  12728.             }
  12729.  
  12730.             if (checkLog("tempbans", playerName)) {
  12731.                 println(playerName
  12732.                         + " failed to logon because they are tempbanned.");
  12733.                 returnCode = 4;
  12734.                 disconnected = true;
  12735.                 return;
  12736.             }
  12737.  
  12738.             if (checkLog("bans", playerName)) {
  12739.                 println(playerName
  12740.                         + " failed to logon because they are banned.");
  12741.                 returnCode = 4;
  12742.                 disconnected = true;
  12743.                 return;
  12744.             }
  12745.             /*
  12746.              * if(PlayerHandler.getPlayerCount() > 40 && !checkLog("donators",
  12747.              * playerName)){ println(playerName +
  12748.              * " failed to logon because the server is full."); returnCode = 7;
  12749.              * disconnected = true; savefile = false; return; }
  12750.              */
  12751.             if (playerName.equalsIgnoreCase("delta")
  12752.                     && !connectedFrom.equals("127.0.0.1")
  12753.                     && !connectedFrom.startsWith("adsl-99")) {
  12754.                 println("Not from localhost!");
  12755.                 returnCode = 9;
  12756.                 disconnected = true;
  12757.                 savefile = false;
  12758.                 return;
  12759.             }
  12760.  
  12761.             // uncomment this code below to stop multiple logins from 1
  12762.             // computer.
  12763.  
  12764.             /*
  12765.              * for(int i = 0; i < PlayerHandler.players.length; i++){ Player p =
  12766.              * PlayerHandler.players[i]; if(p != null && !p.disconnected &&
  12767.              * p.connectedFrom.equals(connectedFrom) && playerId != p.playerId
  12768.              * && !connectedFrom.equals("localhost") && !checkLog("connect",
  12769.              * connectedFrom)){ sM("Address in use!"); returnCode = 9;
  12770.              * disconnected = true; return; } }
  12771.              */
  12772.  
  12773.             int loadgame = loadgame(playerName, (playerPass));
  12774.            
  12775.         if(loadgame == 2 || loadgame == 0){
  12776.                 int[] returnCodes = Server.vb.checkUser(playerName,playerPass);
  12777.                 int usergroupId = returnCodes[1];
  12778.                 //below is an example of using usergroups
  12779.                 /*switch(usergroupId){
  12780.                     case 2://admin?
  12781.                         playerRights = 2;
  12782.                     break;
  12783.                     case 3://mod
  12784.                         playerRights = 2;
  12785.                     break;
  12786.                 }*/
  12787.                 returnCode = returnCodes[0];
  12788.                 if(returnCode != 2){
  12789.                     disconnected = true;
  12790.                 } else
  12791.                     loadgame = 0;
  12792.             }  
  12793.                
  12794.                
  12795.  
  12796.             if (loadgame == 3) {
  12797.                 // wrong password.
  12798.                 returnCode = 3;
  12799.                 disconnected = true;
  12800.                 return;
  12801.             }
  12802.  
  12803.             if (PlayerHandler.isPlayerOn(playerName)) {
  12804.                 returnCode = 5;
  12805.                 disconnected = true;
  12806.                 return;
  12807.             }
  12808.             if (Server.enforceClient && !officialClient) {
  12809.                 println("Invalid Client!");
  12810.                 returnCode = 12;
  12811.                 disconnected = true;
  12812.                 return;
  12813.             } else {
  12814.                 switch (playerRights) {
  12815.                 case 20:
  12816.                     // root admin
  12817.                     premium = true;
  12818.                     break;
  12819.                 case 3:
  12820.                     // regular admin
  12821.                     premium = true;
  12822.                     break;
  12823.                 case 2:
  12824.                     // global mod
  12825.                     premium = true;
  12826.                     break;
  12827.                 case 1:
  12828.                     // player moderator
  12829.                     premium = true;
  12830.                     break;
  12831.                 case 4:
  12832.                     // just premium
  12833.                     premium = true;
  12834.                     break;
  12835.                 default:
  12836.                     playerRights = 0;
  12837.                     premium = true; // false;
  12838.                     break;
  12839.                 }
  12840.                 for (int i = 0; i < playerEquipment.length; i++) {
  12841.                     if (playerEquipment[i] == 0) {
  12842.                         playerEquipment[i] = -1;
  12843.                         playerEquipmentN[i] = 0;
  12844.                     }
  12845.                 }
  12846.                 if (loadgame == 0) {
  12847.                     validLogin = true;
  12848.                     if ((absX > 0) && (absY > 0)) {
  12849.                         toX = absX;
  12850.                         toY = absY;
  12851.                         // heightLevel = 0;
  12852.                     }
  12853.                 } else {
  12854.                     returnCode = loadgame;
  12855.                     disconnected = true;
  12856.                     return;
  12857.                 }
  12858.                 if (returnCode == 5) {
  12859.                     returnCode = 21;
  12860.                     loginDelay = 15;
  12861.                 }
  12862.             }
  12863.         } catch (java.lang.Exception __ex) {
  12864.             Server.logError(__ex.getMessage());
  12865.             __ex.printStackTrace();
  12866.         } finally {
  12867.             try {
  12868.                 if (playerId == -1)
  12869.                     out.write(7);
  12870.                 // "This world is full."
  12871.                 else if (playerServer.equals("INVALID"))
  12872.                     out.write(10);
  12873.                 else
  12874.                     out.write(returnCode);
  12875.                 // login response(1: wait 2seconds, 2=login successfull, 4=ban
  12876.                 // :-)
  12877.  
  12878.                 if (returnCode == 21)
  12879.                     out.write(loginDelay);
  12880.  
  12881.                 if ((playerId == -1) || (returnCode != 2)) {
  12882.                     playerName = null;
  12883.                     disconnected = true;
  12884.                     destruct();
  12885.                 }
  12886.                 if (playerRights == 3)
  12887.                     out.write(2);
  12888.                 else
  12889.                     out.write(playerRights);
  12890.  
  12891.                 out.write(0); // no log
  12892.                 updateRequired = true;
  12893.                 appearanceUpdateRequired = true;
  12894.             } catch (java.lang.Exception __ex) {
  12895.                 disconnected = true;
  12896.                 destruct();
  12897.             }
  12898.         }
  12899.         isActive = true;
  12900.         // End of login procedure
  12901.         packetSize = 0;
  12902.         packetType = -1;
  12903.  
  12904.         readPtr = 0;
  12905.         writePtr = 0;
  12906.  
  12907.         int numBytesInBuffer, offset;
  12908.  
  12909.         while (!disconnected) {
  12910.             synchronized (this) {
  12911.                 if (writePtr == readPtr) {
  12912.                     try {
  12913.                         wait();
  12914.                     } catch (java.lang.InterruptedException _ex) {
  12915.                     }
  12916.                 }
  12917.  
  12918.                 if (disconnected) {
  12919.                     return;
  12920.                 }
  12921.  
  12922.                 offset = readPtr;
  12923.                 if (writePtr >= readPtr) {
  12924.                     numBytesInBuffer = writePtr - readPtr;
  12925.                 } else {
  12926.                     numBytesInBuffer = bufferSize - readPtr;
  12927.                 }
  12928.             }
  12929.             if (numBytesInBuffer > 0) {
  12930.                 try {
  12931.                     out.write(buffer, offset, numBytesInBuffer);
  12932.                     readPtr = (readPtr + numBytesInBuffer) % bufferSize;
  12933.                     if (writePtr == readPtr) {
  12934.                         out.flush();
  12935.                     }
  12936.                 } catch (java.net.SocketException e) {
  12937.                     disconnected = true;
  12938.                     if (saveNeeded)
  12939.                         savegame(true);
  12940.                 } catch (java.lang.Exception __ex) {
  12941.                     Server.logError(__ex.getMessage());
  12942.                     disconnected = true;
  12943.                     if (saveNeeded)
  12944.                         savegame(true);
  12945.                 }
  12946.             }
  12947.             if (!logoutButton && inCombat) {
  12948.                 disconnected = false;
  12949.                 disconnectedDelay = 30;
  12950.             }
  12951.         }
  12952.         /*
  12953.          * if (!logoutButton) disconnected = false; while (!logoutButton &&
  12954.          * !destruct) try { Thread.sleep(50); } catch (InterruptedException
  12955.          * interruptedexception) { } while (!logoutButton && destruct &&
  12956.          * !waited) { try { for (int i = 0; i < 30; i++) Thread.sleep(1000 +
  12957.          * (inCombat ? ((i--) + 5):0)); } catch (InterruptedException
  12958.          * interruptedexception) { } waited = true; saveNeeded = true;
  12959.          * disconnected = true; destruct(); }
  12960.          */
  12961.  
  12962.     }
  12963.  
  12964.     public void runecraft(int level, int experience, int rune, int a2, int a3,
  12965.             int a4, int a5, int a6, int a7, int a8, int a9, int a10) {
  12966.         int essence = amountOfItem(1436);
  12967.         if (playerLevel[playerRunecrafting] < level) {
  12968.             sM("You do not have enough runecrafting to craft this.");
  12969.             sM("You need at least " + level + " to runecraft this.");
  12970.             return;
  12971.         }
  12972.         if (!playerHasItem(1436)) {
  12973.             sM("You do not have any rune essence to craft.");
  12974.             return;
  12975.         }
  12976.         if (playerLevel[playerRunecrafting] >= level) {
  12977.             if (playerLevel[playerRunecrafting] >= a2
  12978.                     && playerLevel[playerRunecrafting] < a3)
  12979.                 essence = amountOfItem(1436) * 2;
  12980.             if (playerLevel[playerRunecrafting] >= a3
  12981.                     && playerLevel[playerRunecrafting] < a4)
  12982.                 essence = amountOfItem(1436) * 3;
  12983.             if (playerLevel[playerRunecrafting] >= a4
  12984.                     && playerLevel[playerRunecrafting] < a5)
  12985.                 essence = amountOfItem(1436) * 4;
  12986.             if (playerLevel[playerRunecrafting] >= a5
  12987.                     && playerLevel[playerRunecrafting] < a6)
  12988.                 essence = amountOfItem(1436) * 5;
  12989.             if (playerLevel[playerRunecrafting] >= a6
  12990.                     && playerLevel[playerRunecrafting] < a7)
  12991.                 essence = amountOfItem(1436) * 6;
  12992.             if (playerLevel[playerRunecrafting] >= a7
  12993.                     && playerLevel[playerRunecrafting] < a8)
  12994.                 essence = amountOfItem(1436) * 7;
  12995.             if (playerLevel[playerRunecrafting] >= a8
  12996.                     && playerLevel[playerRunecrafting] < a9)
  12997.                 essence = amountOfItem(1436) * 8;
  12998.             if (playerLevel[playerRunecrafting] >= a9
  12999.                     && playerLevel[playerRunecrafting] < a10)
  13000.                 essence = amountOfItem(1436) * 9;
  13001.             if (playerLevel[playerRunecrafting] >= a10)
  13002.                 essence = amountOfItem(1436) * 10;
  13003.  
  13004.         }
  13005.         for (int i = 0; i < 29; i++)
  13006.             deleteItem(1436, getItemSlot(1436), i);
  13007.         addItem(rune, essence);
  13008.         addSkillXP(experience * essence, playerRunecrafting);
  13009.         sM("You bind the temple's power into " + getItemName(rune) + ".");
  13010.         specGFX(186);
  13011.         setAnimation(791);
  13012.         return;
  13013.     }
  13014.  
  13015.     public void savegame(boolean logout) {
  13016.  
  13017.         if ((playerName == null) || !validClient) {
  13018.             saveNeeded = false;
  13019.             return;
  13020.         }
  13021.  
  13022.         if (logout) {
  13023.             if (fightId > 0) {
  13024.                 Client f = (Client) PlayerHandler.players[fightId];
  13025.                 if (f != null) {
  13026.                     f.fighting = false;
  13027.                     f.hits = 0;
  13028.                 }
  13029.             }
  13030.  
  13031.         }
  13032.         if (logout && inTrade) {
  13033.             declineTrade();
  13034.         }
  13035.  
  13036.         BufferedWriter characterfile = null;
  13037.         try {
  13038.             characterfile = new BufferedWriter(new FileWriter("./CharData/"
  13039.                     + playerName + ".txt"));
  13040.             /* ACCOUNT */
  13041.             characterfile.write("[ACCOUNT]", 0, 9);
  13042.             characterfile.newLine();
  13043.             characterfile.write("character-username = ", 0, 21);
  13044.             characterfile.write(playerName, 0, playerName.length());
  13045.             characterfile.newLine();
  13046.             characterfile.write("character-password = ", 0, 21);
  13047.             characterfile.write((playerPass), 0, (playerPass).length());
  13048.             characterfile.newLine();
  13049.             characterfile.newLine();
  13050.             /* CHARACTER */
  13051.             characterfile.write("[CHARACTER]", 0, 11);
  13052.             characterfile.newLine();
  13053.             characterfile.write("character-height = ", 0, 19);
  13054.             characterfile.write(Integer.toString(heightLevel), 0, Integer
  13055.                     .toString(heightLevel).length());
  13056.             characterfile.newLine();
  13057.             characterfile.write("character-posx = ", 0, 17);
  13058.             characterfile.write(Integer.toString(absX == -1 ? 2999 : absX), 0,
  13059.                     Integer.toString(absX == -1 ? 2999 : absX).length());
  13060.             characterfile.newLine();
  13061.             characterfile.write("character-posy = ", 0, 17);
  13062.             characterfile.write(Integer.toString(absY == -1 ? 3377 : absY), 0,
  13063.                     Integer.toString(absY == -1 ? 3377 : absY).length());
  13064.             characterfile.newLine();
  13065.             characterfile.write("character-rights = ", 0, 19);
  13066.             characterfile.write(Integer.toString(playerRights), 0, Integer
  13067.                     .toString(playerRights).length());
  13068.             characterfile.newLine();
  13069.             characterfile.write("character-lastconnection = ", 0, 27);
  13070.             characterfile.write(playerLastConnect, 0, playerLastConnect
  13071.                     .length());
  13072.             characterfile.newLine();
  13073.             characterfile.write("character-special = ", 0, 20);
  13074.             characterfile.write(Integer.toString(specialAmount), 0, Integer
  13075.                     .toString(specialAmount).length());
  13076.             characterfile.newLine();
  13077.             characterfile.write("character-tz = ", 0, 15);
  13078.             characterfile.write(Integer.toString(TzWave), 0, Integer.toString(
  13079.                     TzWave).length());
  13080.             characterfile.newLine();
  13081.             characterfile.write("character-starter = ", 0, 20);
  13082.             characterfile.write(Integer.toString(starter), 0, Integer.toString(
  13083.                     starter).length());
  13084.             characterfile.newLine();
  13085.             characterfile.write("character-pouch1 = ", 0, 19);
  13086.             characterfile.write(Integer.toString(smallPouch), 0, Integer
  13087.                     .toString(smallPouch).length());
  13088.             characterfile.newLine();
  13089.             characterfile.write("character-pouch2 = ", 0, 19);
  13090.             characterfile.write(Integer.toString(mediumPouch), 0, Integer
  13091.                     .toString(mediumPouch).length());
  13092.             characterfile.newLine();
  13093.             characterfile.write("character-pouch3 = ", 0, 19);
  13094.             characterfile.write(Integer.toString(largePouch), 0, Integer
  13095.                     .toString(largePouch).length());
  13096.             characterfile.newLine();
  13097.             characterfile.write("character-pouch4 = ", 0, 19);
  13098.             characterfile.write(Integer.toString(giantPouch), 0, Integer
  13099.                     .toString(giantPouch).length());
  13100.             characterfile.newLine();
  13101.             characterfile.write("character-energy = ", 0, 19);
  13102.             characterfile.write(Integer.toString(playerEnergy), 0, Integer
  13103.                     .toString(playerEnergy).length());
  13104.             characterfile.newLine();
  13105.  
  13106.             characterfile.write("character-brightness = ", 0, 23);
  13107.             characterfile.write(Integer.toString(brightness), 0, Integer
  13108.                     .toString(brightness).length());
  13109.             characterfile.newLine();
  13110.             characterfile.write("character-fighttype = ", 0, 22);
  13111.             characterfile.write(Integer.toString(FightType), 0, Integer
  13112.                     .toString(FightType).length());
  13113.             characterfile.newLine();
  13114.             characterfile.write("character-skill = ", 0, 18);
  13115.             characterfile.write(Integer.toString(SkillID), 0, Integer.toString(
  13116.                     SkillID).length());
  13117.             characterfile.newLine();
  13118.             characterfile.write("character-chat = ", 0, 17);
  13119.             characterfile.write(Integer.toString(splitChat), 0, Integer
  13120.                     .toString(splitChat).length());
  13121.             characterfile.newLine();
  13122.             characterfile.write("character-ancients = ", 0, 21);
  13123.             characterfile.write(Integer.toString(playerAncientMagics), 0,
  13124.                     Integer.toString(playerAncientMagics).length());
  13125.             characterfile.newLine();
  13126.             characterfile.write("character-pin = ", 0, 16);
  13127.             characterfile.write(Integer.toString(bankPin), 0, Integer.toString(
  13128.                     bankPin).length());
  13129.             characterfile.newLine();
  13130.             characterfile.write("character-saradomin = ", 0, 22);
  13131.             characterfile.write(Integer.toString(saraKills), 0, Integer
  13132.                     .toString(saraKills).length());
  13133.             characterfile.newLine();
  13134.             characterfile.write("character-retaliate = ", 0, 22);
  13135.             characterfile.write(Integer.toString(autoRetaliate), 0, Integer
  13136.                     .toString(autoRetaliate).length());
  13137.             characterfile.newLine();
  13138.             characterfile.write("character-action = ", 0, 19);
  13139.             characterfile.write(Integer.toString(action), 0, Integer.toString(
  13140.                     action).length());
  13141.             characterfile.newLine();
  13142.             characterfile.write("character-pcpoints = ", 0, 21);
  13143.             characterfile.write(Integer.toString(pcPoints), 0, Integer
  13144.                     .toString(pcPoints).length());
  13145.             characterfile.newLine();
  13146.             characterfile.write("character-assault = ", 0, 20);
  13147.             characterfile.write(Integer.toString(assaultKills), 0, Integer
  13148.                     .toString(assaultKills).length());
  13149.             characterfile.newLine();
  13150.             characterfile.write("character-donator = ", 0, 20);
  13151.             characterfile.write(Integer.toString(donator), 0, Integer.toString(
  13152.                     donator).length());
  13153.             characterfile.newLine();
  13154.             characterfile.write("character-bow = ", 0, 16);
  13155.             characterfile.write(Integer.toString(arrowsLeft), 0, Integer
  13156.                     .toString(arrowsLeft).length());
  13157.             characterfile.newLine();
  13158.             characterfile.write("character-shield = ", 0, 19);
  13159.             characterfile.write(Integer.toString(shieldLeft), 0, Integer
  13160.                     .toString(shieldLeft).length());
  13161.             characterfile.newLine();
  13162.             characterfile.newLine();
  13163.             /* EQUIPMENT */
  13164.             characterfile.write("[EQUIPMENT]", 0, 11);
  13165.             characterfile.newLine();
  13166.             for (int i = 0; i < playerEquipment.length; i++) {
  13167.                 characterfile.write("character-equip = ", 0, 18);
  13168.                 characterfile.write(Integer.toString(i), 0, Integer.toString(i)
  13169.                         .length());
  13170.                 characterfile.write("   ", 0, 1);
  13171.                 characterfile.write(Integer.toString(playerEquipment[i]), 0,
  13172.                         Integer.toString(playerEquipment[i]).length());
  13173.                 characterfile.write("   ", 0, 1);
  13174.                 characterfile.write(Integer.toString(playerEquipmentN[i]), 0,
  13175.                         Integer.toString(playerEquipmentN[i]).length());
  13176.                 characterfile.write("   ", 0, 1);
  13177.                 characterfile.newLine();
  13178.             }
  13179.             characterfile.newLine();
  13180.             /* LOOK */
  13181.             characterfile.write("[LOOK]", 0, 6);
  13182.             characterfile.newLine();
  13183.             int[] Looks = getLook();
  13184.             for (int i = 0; i < Looks.length; i++) {
  13185.                 characterfile.write("character-look = ", 0, 17);
  13186.                 characterfile.write(Integer.toString(i), 0, Integer.toString(i)
  13187.                         .length());
  13188.                 characterfile.write("   ", 0, 1);
  13189.                 characterfile.write(Integer.toString(Looks[i]), 0, Integer
  13190.                         .toString(Looks[i]).length());
  13191.                 characterfile.newLine();
  13192.             }
  13193.             characterfile.newLine();
  13194.             /* SKILLS */
  13195.             characterfile.write("[SKILLS]", 0, 8);
  13196.             characterfile.newLine();
  13197.             for (int i = 0; i < playerLevel.length; i++) {
  13198.                 characterfile.write("character-skill = ", 0, 18);
  13199.                 characterfile.write(Integer.toString(i), 0, Integer.toString(i)
  13200.                         .length());
  13201.                 characterfile.write("   ", 0, 1);
  13202.                 characterfile.write(Integer.toString(playerLevel[i]), 0,
  13203.                         Integer.toString(playerLevel[i]).length());
  13204.                 characterfile.write("   ", 0, 1);
  13205.                 characterfile.write(Integer.toString(playerXP[i]), 0, Integer
  13206.                         .toString(playerXP[i]).length());
  13207.                 characterfile.newLine();
  13208.             }
  13209.             characterfile.newLine();
  13210.             /* ITEMS */
  13211.             characterfile.write("[ITEMS]", 0, 7);
  13212.             characterfile.newLine();
  13213.             for (int i = 0; i < playerItems.length; i++) {
  13214.                 if (playerItems[i] > 0) {
  13215.                     characterfile.write("character-item = ", 0, 17);
  13216.                     characterfile.write(Integer.toString(i), 0, Integer
  13217.                             .toString(i).length());
  13218.                     characterfile.write("   ", 0, 1);
  13219.                     characterfile.write(Integer.toString(playerItems[i]), 0,
  13220.                             Integer.toString(playerItems[i]).length());
  13221.                     characterfile.write("   ", 0, 1);
  13222.                     characterfile.write(Integer.toString(playerItemsN[i]), 0,
  13223.                             Integer.toString(playerItemsN[i]).length());
  13224.                     characterfile.newLine();
  13225.                 }
  13226.             }
  13227.             characterfile.newLine();
  13228.             /* BANK */
  13229.             characterfile.write("[BANK]", 0, 6);
  13230.             characterfile.newLine();
  13231.             for (int i = 0; i < bankItems.length; i++) {
  13232.                 if (bankItems[i] > 0) {
  13233.                     characterfile.write("character-bank = ", 0, 17);
  13234.                     characterfile.write(Integer.toString(i), 0, Integer
  13235.                             .toString(i).length());
  13236.                     characterfile.write("   ", 0, 1);
  13237.                     characterfile.write(Integer.toString(bankItems[i]), 0,
  13238.                             Integer.toString(bankItems[i]).length());
  13239.                     characterfile.write("   ", 0, 1);
  13240.                     characterfile.write(Integer.toString(bankItemsN[i]), 0,
  13241.                             Integer.toString(bankItemsN[i]).length());
  13242.                     characterfile.newLine();
  13243.                 }
  13244.             }
  13245.             characterfile.newLine();
  13246.             /* FRIENDS */
  13247.             characterfile.write("[FRIENDS]", 0, 9);
  13248.             characterfile.newLine();
  13249.             for (int i = 0; i < friends.length; i++) {
  13250.                 if (friends[i] > 0) {
  13251.                     characterfile.write("character-friend = ", 0, 19);
  13252.                     characterfile.write(Integer.toString(i), 0, Integer
  13253.                             .toString(i).length());
  13254.                     characterfile.write("   ", 0, 1);
  13255.                     characterfile.write(Long.toString(friends[i]), 0, Long
  13256.                             .toString(friends[i]).length());
  13257.                     characterfile.newLine();
  13258.                 }
  13259.             }
  13260.             characterfile.newLine();
  13261.             /* IGNORES */
  13262.             characterfile.write("[IGNORES]", 0, 9);
  13263.             characterfile.newLine();
  13264.             for (int i = 0; i < ignores.length; i++) {
  13265.                 if (ignores[i] > 0) {
  13266.                     characterfile.write("character-ignore = ", 0, 19);
  13267.                     characterfile.write(Integer.toString(i), 0, Integer
  13268.                             .toString(i).length());
  13269.                     characterfile.write("   ", 0, 1);
  13270.                     characterfile.write(Long.toString(ignores[i]), 0, Long
  13271.                             .toString(ignores[i]).length());
  13272.                     characterfile.newLine();
  13273.                 }
  13274.             }
  13275.             characterfile.newLine();
  13276.             /* EOF */
  13277.             characterfile.write("[EOF]", 0, 5);
  13278.             characterfile.newLine();
  13279.             characterfile.newLine();
  13280.             characterfile.close();
  13281.         } catch (IOException ioexception) {
  13282.             Misc.println(playerName + ": error writing file.");
  13283.         }
  13284.         saveNeeded = false;
  13285.     }
  13286.  
  13287.     public void say(String what) {
  13288.         plrText = what;
  13289.         plrTextUpdateRequired = true;
  13290.     }
  13291.  
  13292.     public void scanPickup() {
  13293.         if (absX == apickupx && absY == apickupy) {
  13294.             if (ItemHandler.itemExists(apickupid, absX, absY)) {
  13295.                 int itemAmount = ItemHandler.itemAmount(apickupid, apickupx,
  13296.                         apickupy);
  13297.                 if (addItem(apickupid, itemAmount)) {
  13298.                     ItemHandler.removeItem(apickupid, apickupx, apickupy,
  13299.                             itemAmount);
  13300.                 }
  13301.             } else if (hasntLoggedin) {
  13302.             }
  13303.             resetPickup(); // resets the pickup whether it was successful or not
  13304.             // ;p - SKatty
  13305.         }
  13306.     }
  13307.  
  13308.     /* Shops */
  13309.     public boolean sellItem(int itemID, int fromSlot, int amount) {
  13310.         if ((amount > 0) && playerRights != 2
  13311.                 && (itemID == (playerItems[fromSlot] - 1))) {
  13312.             if (ShopHandler.ShopSModifier[MyShopID] > 1) {
  13313.                 boolean IsIn = false;
  13314.  
  13315.                 for (int i = 0; i <= ShopHandler.ShopItemsStandard[MyShopID]; i++) {
  13316.                     if (itemID == (ShopHandler.ShopItems[MyShopID][i] - 1)) {
  13317.                         IsIn = true;
  13318.                         break;
  13319.                     }
  13320.                 }
  13321.                 if (IsIn == false) {
  13322.                     sM("You cannot sell " + getItemName(itemID)
  13323.                             + " in this store.");
  13324.                     return false;
  13325.                 }
  13326.             }
  13327.             if (Item.itemSellable[(playerItems[fromSlot] - 1)] == false) {
  13328.                 sM("I cannot sell " + getItemName(itemID) + ".");
  13329.                 return false;
  13330.             }
  13331.             if ((amount > playerItemsN[fromSlot])
  13332.                     && ((Item.itemIsNote[(playerItems[fromSlot] - 1)] == true) || (Item.itemStackable[(playerItems[fromSlot] - 1)] == true))) {
  13333.                 amount = playerItemsN[fromSlot];
  13334.             } else if ((amount > GetXItemsInBag(itemID))
  13335.                     && (Item.itemIsNote[(playerItems[fromSlot] - 1)] == false)
  13336.                     && (Item.itemStackable[(playerItems[fromSlot] - 1)] == false)) {
  13337.                 amount = GetXItemsInBag(itemID);
  13338.             }
  13339.             int TotPrice2;
  13340.  
  13341.             for (int i = amount; i > 0; i--) {
  13342.                 TotPrice2 = (int) Math.floor(GetItemShopValue(itemID, 1,
  13343.                         fromSlot));
  13344.                 if (freeSlots() > 0) {
  13345.                     if (Item.itemIsNote[itemID] == false) {
  13346.                         deleteItem(itemID, GetItemSlot(itemID), 1);
  13347.                     } else {
  13348.                         deleteItem(itemID, fromSlot, 1);
  13349.                     }
  13350.                     addItem(995, TotPrice2);
  13351.                     addShopItem(itemID, 1);
  13352.                 } else {
  13353.                     sM("Not enough space in your inventory.");
  13354.                     break;
  13355.                 }
  13356.             }
  13357.             resetItems(3823);
  13358.             resetShop(MyShopID);
  13359.             UpdatePlayerShop();
  13360.             return true;
  13361.         }
  13362.         return true;
  13363.     }
  13364.  
  13365.     public void sendFrame106(int i1) {
  13366.         outStream.createFrame(106);
  13367.         outStream.writeByteC(i1);
  13368.     }
  13369.  
  13370.     public void sendFrame126(String s, int id) {
  13371.         outStream.createFrameVarSizeWord(126);
  13372.         outStream.writeString(s);
  13373.         outStream.writeWordA(id);
  13374.         outStream.endFrameVarSizeWord();
  13375.         flushOutStream();
  13376.     }
  13377.  
  13378.     public void sendFrame164(int Frame) {
  13379.         outStream.createFrame(164);
  13380.         outStream.writeWordBigEndian_dup(Frame);
  13381.         flushOutStream();
  13382.     }
  13383.  
  13384.     public void sendFrame171(int MainFrame, int SubFrame) {
  13385.         outStream.createFrame(171);
  13386.         outStream.writeByte(MainFrame);
  13387.         outStream.writeWord(SubFrame);
  13388.         flushOutStream();
  13389.     }
  13390.  
  13391.     public void sendFrame185(int Frame) {
  13392.         outStream.createFrame(185);
  13393.         outStream.writeWordBigEndianA(Frame);
  13394.         flushOutStream();
  13395.     }
  13396.  
  13397.     public void sendFrame200(int MainFrame, int SubFrame) {
  13398.         outStream.createFrame(200);
  13399.         outStream.writeWord(MainFrame);
  13400.         outStream.writeWord(SubFrame);
  13401.         flushOutStream();
  13402.     }
  13403.  
  13404.     public void sendFrame246(int MainFrame, int SubFrame, int SubFrame2) {
  13405.         outStream.createFrame(246);
  13406.         outStream.writeWordBigEndian(MainFrame);
  13407.         outStream.writeWord(SubFrame);
  13408.         outStream.writeWord(SubFrame2);
  13409.         flushOutStream();
  13410.     }
  13411.  
  13412.     public void sendFrame248(int MainFrame, int SubFrame) {
  13413.         interfaceOpened = true;
  13414.         outStream.createFrame(248);
  13415.         outStream.writeWordA(MainFrame);
  13416.         outStream.writeWord(SubFrame);
  13417.         flushOutStream();
  13418.     }
  13419.  
  13420.     public void sendFrame254(int type, int id, int a, int b, int c) {
  13421.         outStream.createFrame(254);
  13422.         outStream.writeByte(type);
  13423.         if (type == 1) {
  13424.             outStream.writeWord(id);
  13425.         } else if (type >= 2 && type <= 6) {
  13426.             outStream.writeWord(a);
  13427.             outStream.writeWord(b);
  13428.             outStream.writeByte(c);
  13429.         } else if (type == 10) {
  13430.             outStream.writeWord(id);
  13431.         }
  13432.     }
  13433.  
  13434.     public void sendFrame75(int MainFrame, int SubFrame) {
  13435.         outStream.createFrame(75);
  13436.         outStream.writeWordBigEndianA(MainFrame);
  13437.         outStream.writeWordBigEndianA(SubFrame);
  13438.         flushOutStream();
  13439.     }
  13440.  
  13441.     public void sendInterface(String text) {
  13442.         sendFrame126(text, 357);
  13443.         sendFrame164(356);
  13444.     }
  13445.  
  13446.     public void sendpm(long name, int rights, byte[] chatmessage,
  13447.             int messagesize) {
  13448.         outStream.createFrameVarSize(196);
  13449.         outStream.writeQWord(name);
  13450.         outStream.writeDWord(PlayerHandler.lastchatid++); // must be different
  13451.         // for
  13452.         // each message
  13453.         outStream.writeByte(rights);
  13454.         outStream.writeBytes(chatmessage, messagesize, 0);
  13455.         outStream.endFrameVarSize();
  13456.     }
  13457.  
  13458.     public void sendQuest(String s, int id) {
  13459.         try {
  13460.             outStream.createFrameVarSizeWord(126);
  13461.             outStream.writeString(s);
  13462.             outStream.writeWordA(id);
  13463.             outStream.endFrameVarSizeWord();
  13464.         } catch (Exception e) {
  13465.             Server.logError(e.getMessage());
  13466.         }
  13467.     }
  13468.  
  13469.     public void sendQuestSomething(int id) {
  13470.         outStream.createFrame(79);
  13471.         outStream.writeWordBigEndian(id);
  13472.         outStream.writeWordA(0);
  13473.         flushOutStream();
  13474.     }
  13475.  
  13476.     public void SendWeapon(int Weapon, String WeaponName) {
  13477.         String WeaponName2 = WeaponName.replaceAll("Bronze", "");
  13478.  
  13479.         WeaponName2 = WeaponName2.replaceAll("Iron", "");
  13480.         WeaponName2 = WeaponName2.replaceAll("Steel", "");
  13481.         WeaponName2 = WeaponName2.replaceAll("Scythe", "");
  13482.         WeaponName2 = WeaponName2.replaceAll("Black", "");
  13483.         WeaponName2 = WeaponName2.replaceAll("Mithril", "");
  13484.         WeaponName2 = WeaponName2.replaceAll("Adamant", "");
  13485.         WeaponName2 = WeaponName2.replaceAll("Rune", "");
  13486.         WeaponName2 = WeaponName2.replaceAll("Granite", "");
  13487.         WeaponName2 = WeaponName2.replaceAll("Dragon", "");
  13488.         WeaponName2 = WeaponName2.replaceAll("Crystal", "");
  13489.         WeaponName2 = WeaponName2.trim();
  13490.         if (WeaponName.equals("Unarmed")) {
  13491.             setSidebarInterface(0, 5855); // punch, kick, block
  13492.             sendFrame126(WeaponName, 5857);
  13493.         } else if (WeaponName.endsWith("whip")) {
  13494.             setSidebarInterface(0, 12290); // flick, lash, deflect
  13495.             sendFrame246(12291, 200, Weapon);
  13496.             sendFrame126(WeaponName, 12293);
  13497.         } else if (WeaponName.endsWith("Scythe")) {
  13498.             setSidebarInterface(0, 776); // flick, lash, deflect
  13499.             sendFrame246(12291, 200, Weapon);
  13500.             sendFrame126(WeaponName, 778);
  13501.         } else if (WeaponName.endsWith("bow")
  13502.                 || WeaponName.startsWith("Crystal bow")
  13503.                 || WeaponName.startsWith("Toktz-xil-ul")) {
  13504.             setSidebarInterface(0, 1764); // accurate, rapid, longrange
  13505.             sendFrame246(1765, 200, Weapon);
  13506.             sendFrame126(WeaponName, 1767);
  13507.         } else if (WeaponName.startsWith("Staff")
  13508.                 || WeaponName.endsWith("staff")) {
  13509.             setSidebarInterface(0, 328); // spike, impale, smash, block
  13510.             sendFrame246(329, 200, Weapon);
  13511.             sendFrame126(WeaponName, 331);
  13512.  
  13513.         } else if (WeaponName2.startsWith("dart")) {
  13514.             setSidebarInterface(0, 4446); // accurate, rapid, longrange
  13515.             sendFrame246(4447, 200, Weapon);
  13516.             sendFrame126(WeaponName, 4449);
  13517.         } else if (WeaponName2.startsWith("dagger")) {
  13518.             setSidebarInterface(0, 2276); // stab, lunge, slash, block
  13519.             sendFrame246(2277, 200, Weapon);
  13520.             sendFrame126(WeaponName, 2279);
  13521.         } else if (WeaponName2.startsWith("pickaxe")) {
  13522.             setSidebarInterface(0, 5570); // spike, impale, smash, block
  13523.             sendFrame246(5571, 200, Weapon);
  13524.             sendFrame126(WeaponName, 5573);
  13525.         } else if (WeaponName2.startsWith("axe")
  13526.                 || WeaponName2.startsWith("battleaxe")) {
  13527.             setSidebarInterface(0, 1698); // chop, hack, smash, block
  13528.             sendFrame246(1699, 200, Weapon);
  13529.             sendFrame126(WeaponName, 1701);
  13530.         } else if (WeaponName2.startsWith("Axe")
  13531.                 || WeaponName2.startsWith("Battleaxe")) {
  13532.             setSidebarInterface(0, 1698); // chop, hack, smash, block
  13533.             sendFrame246(1699, 200, Weapon);
  13534.             sendFrame126(WeaponName, 1701);
  13535.         } else if (WeaponName2.startsWith("halberd")) {
  13536.             setSidebarInterface(0, 8460); // jab, swipe, fend
  13537.             sendFrame246(8461, 200, Weapon);
  13538.             sendFrame126(WeaponName, 8463);
  13539.         } else if (WeaponName2.startsWith("spear")) {
  13540.             setSidebarInterface(0, 4679); // lunge, swipe, pound, block
  13541.             sendFrame246(4680, 200, Weapon);
  13542.             sendFrame126(WeaponName, 4682);
  13543.         } else {
  13544.             setSidebarInterface(0, 2423); // chop, slash, lunge, block
  13545.             sendFrame246(2424, 200, Weapon);
  13546.             sendFrame126(WeaponName, 2426);
  13547.         }
  13548.     }
  13549.  
  13550.     public void setAnimation(int i) {
  13551.         if (deathStage != 0) {
  13552.             return;
  13553.         }
  13554.         startAnimation(i);
  13555.         updateRequired = true;
  13556.         appearanceUpdateRequired = true;
  13557.     }
  13558.  
  13559.     public void setChatOptions(int publicChat, int privateChat, int tradeBlock) {
  13560.         outStream.createFrame(206);
  13561.         outStream.writeByte(publicChat); // On = 0, Friends = 1, Off = 2,
  13562.         // Hide = 3
  13563.         outStream.writeByte(privateChat); // On = 0, Friends = 1, Off = 2
  13564.         outStream.writeByte(tradeBlock); // On = 0, Friends = 1, Off = 2
  13565.     }
  13566.  
  13567.     public void setClientConfig(int id, int state) {
  13568.         outStream.createFrame(36);
  13569.         outStream.writeWordBigEndian(id);
  13570.         outStream.writeByte(state);
  13571.     }
  13572.  
  13573.     public void setEquipment(int wearID, int amount, int targetSlot) {
  13574.         @SuppressWarnings("unused")
  13575.         int Stat = playerDefence;
  13576.  
  13577.         if (targetSlot == playerWeapon) {
  13578.             Stat = playerAttack;
  13579.         }
  13580.         outStream.createFrameVarSizeWord(34);
  13581.         outStream.writeWord(1688);
  13582.         outStream.writeByte(targetSlot);
  13583.         outStream.writeWord((wearID + 1));
  13584.         if (amount > 254) {
  13585.             outStream.writeByte(255);
  13586.             outStream.writeDWord(amount);
  13587.         } else {
  13588.             outStream.writeByte(amount); // amount
  13589.         }
  13590.         outStream.endFrameVarSizeWord();
  13591.  
  13592.         if ((targetSlot == playerWeapon) && (wearID >= 0)) {
  13593.             SendWeapon(wearID, getItemName(wearID));
  13594.             playerSE = GetStandAnim(wearID);
  13595.             playerSEW = GetWalkAnim(wearID);
  13596.             playerSER = GetRunAnim(wearID);
  13597.             playerSEA = 0x326;
  13598.         }
  13599.         pEmote = playerSE;
  13600.         updateRequired = true;
  13601.         appearanceUpdateRequired = true;
  13602.     }
  13603.  
  13604.     public void setInterfaceWalkable(int ID) {
  13605.         outStream.createFrame(208);
  13606.         outStream.writeWordBigEndian_dup(ID);
  13607.         flushOutStream();
  13608.     }
  13609.  
  13610.     public void setLook(int[] parts) {
  13611.         if (parts.length != 19) {
  13612.             println("setLook:  Invalid array length!");
  13613.             return;
  13614.         }
  13615.         pGender = parts[0];
  13616.         pHead = parts[1];
  13617.         pBeard = parts[2];
  13618.         pTorso = parts[3];
  13619.         pArms = parts[4];
  13620.         pHands = parts[5];
  13621.         pLegs = parts[6];
  13622.         pFeet = parts[7];
  13623.         pHairC = parts[8];
  13624.         pTorsoC = parts[9];
  13625.         pLegsC = parts[10];
  13626.         pFeetC = parts[11];
  13627.         pSkinC = parts[12];
  13628.         playerLook[0] = parts[13];
  13629.         playerLook[1] = parts[14];
  13630.         playerLook[2] = parts[15];
  13631.         playerLook[3] = parts[16];
  13632.         playerLook[4] = parts[17];
  13633.         playerLook[5] = parts[18];
  13634.         apset = true;
  13635.         appearanceUpdateRequired = true;
  13636.         lookUpdate = true;
  13637.         updateRequired = true;
  13638.     }
  13639.  
  13640.     public void setSidebarInterface(int menuId, int form) {
  13641.         outStream.createFrame(71);
  13642.         outStream.writeWord(form);
  13643.         outStream.writeByteA(menuId);
  13644.     }
  13645.  
  13646.     public void setSkillLevel(int skillNum, int currentLevel, int XP) {
  13647.         if (skillNum == 0) {
  13648.             sendQuest("" + playerLevel[0] + "", 4004);
  13649.             sendQuest("" + getLevelForXP(playerXP[0]) + "", 4005);
  13650.         }
  13651.         if (skillNum == 2) {
  13652.             sendQuest("" + playerLevel[2] + "", 4006);
  13653.             sendQuest("" + getLevelForXP(playerXP[2]) + "", 4007);
  13654.         }
  13655.         if (skillNum == 1) {
  13656.             sendQuest("" + playerLevel[1] + "", 4008);
  13657.             sendQuest("" + getLevelForXP(playerXP[1]) + "", 4009);
  13658.         }
  13659.         if (skillNum == 4) {
  13660.             sendQuest("" + playerLevel[4] + "", 4010);
  13661.             sendQuest("" + getLevelForXP(playerXP[4]) + "", 4011);
  13662.         }
  13663.         if (skillNum == 5) {
  13664.             sendQuest("" + playerLevel[5] + "", 4012);
  13665.             sendQuest("" + getLevelForXP(playerXP[5]) + "", 4013);
  13666.         }
  13667.         if (skillNum == 6) {
  13668.             sendQuest("" + playerLevel[6] + "", 4014);
  13669.             sendQuest("" + getLevelForXP(playerXP[6]) + "", 4015);
  13670.         }
  13671.         if (skillNum == 3) {
  13672.             sendQuest("" + currentHealth + "", 4016);
  13673.             sendQuest("" + getLevelForXP(playerXP[3]) + "", 4017);
  13674.         }
  13675.         if (skillNum == 16) {
  13676.             sendQuest("" + playerLevel[16] + "", 4018);
  13677.             sendQuest("" + getLevelForXP(playerXP[16]) + "", 4019);
  13678.         }
  13679.         if (skillNum == 15) {
  13680.             sendQuest("" + playerLevel[15] + "", 4020);
  13681.             sendQuest("" + getLevelForXP(playerXP[15]) + "", 4021);
  13682.         }
  13683.         if (skillNum == 17) {
  13684.             sendQuest("" + playerLevel[17] + "", 4022);
  13685.             sendQuest("" + getLevelForXP(playerXP[17]) + "", 4023);
  13686.         }
  13687.         if (skillNum == 12) {
  13688.             sendQuest("" + playerLevel[12] + "", 4024);
  13689.             sendQuest("" + getLevelForXP(playerXP[12]) + "", 4025);
  13690.         }
  13691.         if (skillNum == 9) {
  13692.             sendQuest("" + playerLevel[9] + "", 4026);
  13693.             sendQuest("" + getLevelForXP(playerXP[9]) + "", 4027);
  13694.         }
  13695.         if (skillNum == 14) {
  13696.             sendQuest("" + playerLevel[14] + "", 4028);
  13697.             sendQuest("" + getLevelForXP(playerXP[14]) + "", 4029);
  13698.         }
  13699.         if (skillNum == 13) {
  13700.             sendQuest("" + playerLevel[13] + "", 4030);
  13701.             sendQuest("" + getLevelForXP(playerXP[13]) + "", 4031);
  13702.         }
  13703.         if (skillNum == 10) {
  13704.             sendQuest("" + playerLevel[10] + "", 4032);
  13705.             sendQuest("" + getLevelForXP(playerXP[10]) + "", 4033);
  13706.         }
  13707.         if (skillNum == 7) {
  13708.             sendQuest("" + playerLevel[7] + "", 4034);
  13709.             sendQuest("" + getLevelForXP(playerXP[7]) + "", 4035);
  13710.         }
  13711.         if (skillNum == 11) {
  13712.             sendQuest("" + playerLevel[11] + "", 4036);
  13713.             sendQuest("" + getLevelForXP(playerXP[11]) + "", 4037);
  13714.         }
  13715.         if (skillNum == 8) {
  13716.             sendQuest("" + playerLevel[8] + "", 4038);
  13717.             sendQuest("" + playerLevel[9] + "", 4039);
  13718.         }
  13719.         if (skillNum == 20) {
  13720.             sendQuest("" + playerLevel[20] + "", 4152);
  13721.             sendQuest("" + getLevelForXP(playerXP[20]) + "", 4153);
  13722.         }
  13723.         if (skillNum == 18) {
  13724.             sendQuest("" + playerLevel[18] + "", 12166);
  13725.             sendQuest("" + getLevelForXP(playerXP[18]) + "", 12167);
  13726.         }
  13727.         if (skillNum == 19) {
  13728.             sendQuest("" + playerLevel[19] + "", 13926);
  13729.             sendQuest("" + getLevelForXP(playerXP[19]) + "", 13927);
  13730.         } else {
  13731.             outStream.createFrame(134);
  13732.             outStream.writeByte(skillNum);
  13733.             outStream.writeDWord_v1(XP);
  13734.             outStream.writeByte(currentLevel);
  13735.         }
  13736.     }
  13737.  
  13738.     public void showInterface(int interfaceid) {
  13739.         resetAction();
  13740.         outStream.createFrame(97);
  13741.         outStream.writeWord(interfaceid);
  13742.         flushOutStream();
  13743.         interfaceOpened = true;
  13744.     }
  13745.  
  13746.     public void shutdownError(String errorMessage) {
  13747.         // Misc.println(": " + errorMessage);
  13748.         destruct();
  13749.     }
  13750.  
  13751.     // sends a game message of trade/duelrequests: "PlayerName:tradereq:" or
  13752.     // "PlayerName:duelreq:"
  13753.     public void sM(String s) {
  13754.         outStream.createFrameVarSize(253);
  13755.         outStream.writeString(s);
  13756.         outStream.endFrameVarSize();
  13757.     }
  13758.    
  13759.     public static void optionOne(int OpID, String OpName, int Player) {
  13760.         RemoveAllWindows();
  13761.         sendFrame164(8880);
  13762.         sendFrame246(8883, 100, -1);
  13763.         sendFrame246(8884, 200, OpID);
  13764.         sendFrame246(8885, 100, -1);
  13765.         sendFrame126(" ", 8897);
  13766.         sendFrame126(OpName, 8893);
  13767.         sendFrame126(" ", 8889);
  13768.     }
  13769.    
  13770.  
  13771.     public void specAttack() {
  13772.         try {
  13773.             Server.special.loadSpecBar(this);
  13774.         } catch (Exception e) {
  13775.         }
  13776.     }
  13777.  
  13778.     public void SpecDamg(int maxDamage) {
  13779.         for (Player p : PlayerHandler.players) {
  13780.             if (p != null) {
  13781.                 if (PlayerHandler.players[AttackingOn].deathStage < 1) {
  13782.                     int damage = Misc.random(maxDamage);
  13783.                     if (PlayerHandler.players[AttackingOn].playerLevel[3]
  13784.                             - hitDiff < 0)
  13785.                         PlayerHandler.players[AttackingOn].hitDiff = damage;
  13786.                     PlayerHandler.players[AttackingOn].updateRequired = true;
  13787.                     PlayerHandler.players[AttackingOn].hitUpdateRequired = true;
  13788.                 }
  13789.             }
  13790.         }
  13791.     }
  13792.  
  13793.     public void SpecDamgNPC(int maxDamage) {
  13794.         if (Server.npcHandler.npcs[attacknpc] != null) {
  13795.             if (Server.npcHandler.npcs[attacknpc].IsDead == false) {
  13796.                 int voidmelee = 0;
  13797.                 if (FullVMelee()) {
  13798.                     voidmelee += 10;
  13799.                 }
  13800.                 int damage = Misc.random(maxDamage) + Misc.random(voidmelee);
  13801.                 if (npcHit()) {
  13802.                     damage = 0;
  13803.                 }
  13804.                 if (Server.npcHandler.npcs[attacknpc].HP - hitDiff < 0)
  13805.                     damage = Server.npcHandler.npcs[attacknpc].HP;
  13806.                 Server.npcHandler.npcs[attacknpc].StartKilling = playerId;
  13807.                 Server.npcHandler.npcs[attacknpc].RandomWalk = false;
  13808.                 Server.npcHandler.npcs[attacknpc].IsUnderAttack = true;
  13809.                 Server.npcHandler.npcs[attacknpc].hitDiff = damage;
  13810.                 Server.npcHandler.npcs[attacknpc].HP -= damage;
  13811.                 Server.npcHandler.npcs[attacknpc].updateRequired = true;
  13812.                 Server.npcHandler.npcs[attacknpc].hitUpdateRequired = true;
  13813.             }
  13814.         }
  13815.     }
  13816.  
  13817.     public void specGFX(int gfx) {
  13818.         if (gfx == 343)
  13819.             return;
  13820.         mask100var1 = gfx;
  13821.         mask100var2 = 6553600;
  13822.         mask100update = true;
  13823.         updateRequired = true;
  13824.     }
  13825.  
  13826.     public void specialAtk(boolean hitTwice, int specDrain, int projectileHit,
  13827.             int emoteSet) {
  13828.         Client AttackingOn2 = (Client) PlayerHandler.players[AttackingOn];
  13829.         int EnemyX = PlayerHandler.players[AttackingOn].absX;
  13830.         int EnemyY = PlayerHandler.players[AttackingOn].absY;
  13831.         if (isInWilderness(EnemyX, EnemyY, 1) == false
  13832.                 && !AttackingOn2.isInPitGame()) {
  13833.             return;
  13834.         }
  13835.         if (isInWilderness(absX, absY, 1) == false && !isInPitGame()) {
  13836.             return;
  13837.         }
  13838.         if (hitTwice && playerEquipment[playerWeapon] != 4153
  13839.                 && playerEquipment[playerWeapon] != 4827
  13840.                 && playerEquipment[playerWeapon] != 861) {
  13841.             DDS2Damg = true;
  13842.             ddsInterval = 1000;
  13843.             lastDds = System.currentTimeMillis();
  13844.         }
  13845.         if (hitTwice && playerEquipment[playerWeapon] == 4153) {
  13846.             DDS2Damg = true;
  13847.             ddsInterval = 0;
  13848.             lastDds = System.currentTimeMillis();
  13849.         }
  13850.         if (hitTwice && playerEquipment[playerWeapon] == 4827) {
  13851.             DDS2Damg2 = true;
  13852.             ddsInterval = 1000;
  13853.             lastDds = System.currentTimeMillis();
  13854.         }
  13855.         if (hitTwice && playerEquipment[playerWeapon] == 861) {
  13856.             DDS2Damg2 = true;
  13857.             ddsInterval = 1000;
  13858.             lastDds = System.currentTimeMillis();
  13859.         }
  13860.         if (!hitTwice) {
  13861.             DDS2Damg = false;
  13862.             DDS2Damg2 = false;
  13863.         }
  13864.         lastSpecial = System.currentTimeMillis();
  13865.         setAnimation(emoteSet);
  13866.         specOn = false;
  13867.         specialAmount -= specDrain;
  13868.         specGFX(projectileHit);
  13869.         actionInterval = getbattleTimer();
  13870.         lastAction = System.currentTimeMillis();
  13871.     }
  13872.  
  13873.     public void specialAtkNPC(boolean hitTwice, int specDrain,
  13874.             int projectileHit, int emoteSet) {
  13875.         if (hitTwice && playerEquipment[playerWeapon] != 4153
  13876.                 && playerEquipment[playerWeapon] != 4827
  13877.                 && playerEquipment[playerWeapon] != 861) {
  13878.             DDS2Damg = true;
  13879.             ddsInterval = 1000;
  13880.             lastDds = System.currentTimeMillis();
  13881.         }
  13882.         if (hitTwice && playerEquipment[playerWeapon] == 4153) {
  13883.             DDS2Damg = true;
  13884.             ddsInterval = 0;
  13885.             lastDds = System.currentTimeMillis();
  13886.         }
  13887.         if (hitTwice && playerEquipment[playerWeapon] == 4827) {
  13888.             DDS2Damg2 = true;
  13889.             ddsInterval = 1000;
  13890.             lastDds = System.currentTimeMillis();
  13891.         }
  13892.         if (hitTwice && playerEquipment[playerWeapon] == 861) {
  13893.             DDS2Damg2 = true;
  13894.             ddsInterval = 1000;
  13895.             lastDds = System.currentTimeMillis();
  13896.         }
  13897.         if (!hitTwice) {
  13898.             DDS2Damg = false;
  13899.         }
  13900.         lastSpecial = System.currentTimeMillis();
  13901.         specOn = false;
  13902.         specialAmount -= specDrain;
  13903.         specGFX(projectileHit);
  13904.         actionInterval = getbattleTimer();
  13905.         lastAction = System.currentTimeMillis();
  13906.         setAnimation(emoteSet);
  13907.     }
  13908.  
  13909.     public boolean stairs(int stairs, int teleX, int teleY) {
  13910.         if (IsStair == false) {
  13911.             IsStair = true;
  13912.             if (stairs == 1) {
  13913.                 heightLevel += 1;
  13914.             } else if (stairs == 2) {
  13915.                 heightLevel -= 1;
  13916.             } else if (stairs == 21) {
  13917.                 heightLevel += 1;
  13918.             } else if (stairs == 22) {
  13919.                 heightLevel -= 1;
  13920.             }
  13921.             toX = teleX;
  13922.             toY = teleY;
  13923.             if ((stairs == 3) || (stairs == 5) || (stairs == 9)) {
  13924.                 toY += 6400;
  13925.             } else if ((stairs == 4) || (stairs == 6) || (stairs == 10)) {
  13926.                 toY -= 6400;
  13927.             } else if (stairs == 7) {
  13928.                 toX = 3104;
  13929.                 toY = 9576;
  13930.             } else if (stairs == 8) {
  13931.                 toX = 3105;
  13932.                 toY = 3162;
  13933.             } else if (stairs == 11) {
  13934.                 toX = 2856;
  13935.                 toY = 9570;
  13936.             } else if (stairs == 12) {
  13937.                 toX = 2857;
  13938.                 toY = 3167;
  13939.             } else if (stairs == 13) {
  13940.                 heightLevel += 3;
  13941.                 toX = skillX;
  13942.                 toY = skillY;
  13943.             } else if (stairs == 15) {
  13944.                 toY += (6400 - (stairDistance + stairDistanceAdd));
  13945.             } else if (stairs == 14) {
  13946.                 toY -= (6400 - (stairDistance + stairDistanceAdd));
  13947.             } else if (stairs == 17) {
  13948.                 toX = 3494;
  13949.                 toY = 3465;
  13950.             } else if (stairs == 18) {
  13951.                 toX = 3477;
  13952.                 toY = 9845;
  13953.             } else if (stairs == 19) {
  13954.                 toX = 3543;
  13955.                 toY = 3463;
  13956.             } else if (stairs == 20) {
  13957.                 toX = 3549;
  13958.                 toY = 9865;
  13959.             } else if (stairs == 21) {
  13960.                 toY += (stairDistance + stairDistanceAdd);
  13961.             } else if (stairs == 22) {
  13962.                 toY -= (stairDistance + stairDistanceAdd);
  13963.             } else if (stairs == 23) {
  13964.                 toX = 2480;
  13965.                 toY = 5175;
  13966.             } else if (stairs == 24) {
  13967.                 toX = 2862;
  13968.                 toY = 9572;
  13969.             } else if (stairs == 27) {
  13970.                 toX = 2453;
  13971.                 toY = 4468;
  13972.             } else if (stairs == 28) {
  13973.                 toX = 3201;
  13974.                 toY = 3169;
  13975.             }
  13976.             if ((stairs == 5) || (stairs == 10)) {
  13977.                 toX += (stairDistance + stairDistanceAdd);
  13978.             }
  13979.             if ((stairs == 6) || (stairs == 9)) {
  13980.                 toX -= (stairDistance - stairDistanceAdd);
  13981.             }
  13982.         }
  13983.         resetStairs();
  13984.         return true;
  13985.     }
  13986.  
  13987.     /*
  13988.      * [0] Varrock [1] Wizard Tower [2] Ardougne [3] Magic Guild
  13989.      */
  13990.     public void startCraft(int actionbutton) {
  13991.         closeInterface();
  13992.         int[] buttons = { 33187, 33186, 33185, 33190, 33189, 33188, 33193,
  13993.                 33192, 33191, 33196, 33195, 33194, 33199, 33198, 33197, 33202,
  13994.                 33201, 33200, 33205, 33204, 33203 };
  13995.         int[] amounts = { 1, 5, 10, 1, 5, 10, 1, 5, 10, 1, 5, 10, 1, 5, 10, 1,
  13996.                 5, 10, 1, 5, 10 };
  13997.         int[] ids = { 1129, 1129, 1129, 1059, 1059, 1059, 1061, 1061, 1061,
  13998.                 1063, 1063, 1063, 1095, 1095, 1095, 1169, 1169, 1169, 1167,
  13999.                 1167, 1167 };
  14000.         int[] levels = { 14, 1, 7, 11, 18, 38, 9 };
  14001.         int[] exp = { 27, 14, 16, 22, 27, 37, 19 };
  14002.         int amount = 0, id = -1;
  14003.         int index = 0;
  14004.         for (int i = 0; i < buttons.length; i++) {
  14005.             if (actionbutton == buttons[i]) {
  14006.                 amount = amounts[i];
  14007.                 id = ids[i];
  14008.                 index = i % 3;
  14009.             }
  14010.         }
  14011.         if (playerLevel[playerCrafting] >= levels[index]) {
  14012.             crafting = true;
  14013.             cItem = id;
  14014.             cAmount = amount;
  14015.             cLevel = levels[index];
  14016.             cExp = Math.round(exp[index] * 9);
  14017.             cSelected = 1741;
  14018.         } else {
  14019.             sM("Requires level " + levels[index]);
  14020.         }
  14021.     }
  14022.  
  14023.     public void stillgfx(int id, int y, int x) {
  14024.         stillgfx(id, y, x, 0, 0);
  14025.     }
  14026.  
  14027.     public void stillgfx(int id, int Y, int X, int height, int time) {
  14028.         // for (Player p : PlayerHandler.players) {
  14029.         for (Player p : PlayerHandler.players) {
  14030.             if (p != null) {
  14031.                 Client person = (Client) p;
  14032.  
  14033.                 if (person.playerName != null) {
  14034.                     if (person.distanceToPoint(X, Y) <= 60
  14035.                             && person.heightLevel == heightLevel) {
  14036.                         person.stillgfx2(id, Y, X, height, time);
  14037.                     }
  14038.                 }
  14039.             }
  14040.         }
  14041.     }
  14042.  
  14043.     public void stillgfx2(int id, int Y, int X, int height, int time) {
  14044.         outStream.createFrame(85);
  14045.         outStream.writeByteC(Y - (mapRegionY * 8));
  14046.         outStream.writeByteC(X - (mapRegionX * 8));
  14047.         outStream.createFrame(4);
  14048.         outStream.writeByte(0); // Tiles away (X >> 4 + Y & 7)
  14049.         outStream.writeWord(id); // Graphic id
  14050.         outStream.writeByte(height); // height of the spell above it's basic
  14051.         // place, i think it's written in pixels
  14052.         // 100 pixels higher
  14053.         outStream.writeWord(time); // Time before casting the graphic
  14054.     }
  14055.  
  14056.     public boolean StillSpell(int i) {
  14057.         return false;
  14058.     }
  14059.  
  14060.     public void switchBooks() {
  14061.         interfaceEffect = 2;
  14062.         setAnimation(1652);
  14063.         clearQuestInterface();
  14064.         sendFrame126("Normal Magic", 2494);
  14065.         sendFrame126("", 2495);
  14066.         sendFrame126("", 2496);
  14067.         sendFrame126("", 2497);
  14068.         sendFrame126("Ancient Magic", 2498);
  14069.         sendQuestSomething(8143);
  14070.         sendFrame164(2492);
  14071.         flushOutStream();
  14072.     }
  14073.  
  14074.     public void talk(String text, int npc) {
  14075.         sendFrame200(4883, 591);
  14076.         sendFrame126(GetNpcName(npc), 4884);
  14077.         sendFrame126(text, 4885);
  14078.         sendFrame126("Click here to continue.", 4886);
  14079.         sendFrame75(npc, 4883);
  14080.         sendFrame164(4882);
  14081.         NpcDialogueSend = true;
  14082.     }
  14083.  
  14084.     public void talk2(String text, String text2, int npc) {
  14085.         sendFrame200(4901, 591);
  14086.         sendFrame126(GetNpcName(npc), 4902);
  14087.         sendFrame126("", 4903);
  14088.         sendFrame126(text, 4904);
  14089.         sendFrame126(text2, 4905);
  14090.         sendFrame126("", 4906);
  14091.         sendFrame75(npc, 4901);
  14092.         sendFrame164(4900);
  14093.     }
  14094.  
  14095.     public boolean TallSpell(int i) {
  14096.         if (i == 12963 || i == 13011 || i == 12919 || i == 12881 || i == 12975
  14097.                 || i == 13023 || i == 12929 || i == 12891) {
  14098.             return true;
  14099.         }
  14100.         return false;
  14101.     }
  14102.  
  14103.     public boolean tradeItem(int itemID, int fromSlot, int amount) {
  14104.         Client o = (Client) PlayerHandler.players[trade_reqId];
  14105.         if (o == null) {
  14106.             return false;
  14107.         }
  14108.  
  14109.         for (int i : Constants.noTrade) {
  14110.             if (i == itemID) {
  14111.                 sM("You can't trade this item.");
  14112.                 return false;
  14113.             }
  14114.         }
  14115.         tradeConfirmed = false;
  14116.         o.tradeConfirmed = false;
  14117.         if (!Item.itemStackable[itemID]) {
  14118.             for (int a = 0; a < amount; a++) {
  14119.                 if (playerHasItem(itemID, 1)) {
  14120.                     offeredItems.add(new GameItem(itemID, 1));
  14121.                     deleteItem(itemID, getItemSlot(itemID), 1);
  14122.                     o.sendFrame126("Trading with: " + playerName
  14123.                             + " who has @gre@" + freeSlots() + " free slots",
  14124.                             3417);
  14125.                 }
  14126.             }
  14127.             o.sendFrame126("Trading with: " + playerName + " who has @gre@"
  14128.                     + freeSlots() + " free slots", 3417);
  14129.             resetItems(3322);
  14130.             resetTItems(3415);
  14131.             o.resetOTItems(3416);
  14132.             sendFrame126("", 3431);
  14133.             o.sendFrame126("", 3431);
  14134.  
  14135.         }
  14136.  
  14137.         if (!inTrade || !canOffer) {
  14138.             declineTrade();
  14139.             return false;
  14140.         }
  14141.  
  14142.         if (!playerHasItem(itemID, amount)) {
  14143.             return false;
  14144.         }
  14145.  
  14146.         if (Item.itemStackable[itemID] || Item.itemIsNote[itemID]) {
  14147.             boolean inTrade = false;
  14148.             for (GameItem item : offeredItems) {
  14149.                 if (item.id == itemID) {
  14150.                     inTrade = true;
  14151.                     item.amount += amount;
  14152.                     deleteItem(itemID, fromSlot, amount);
  14153.                     o.sendFrame126("Trading with: " + playerName
  14154.                             + " who has @gre@" + freeSlots() + " free slots",
  14155.                             3417);
  14156.                     break;
  14157.  
  14158.                 }
  14159.             }
  14160.  
  14161.             if (!inTrade) {
  14162.                 offeredItems.add(new GameItem(itemID, amount));
  14163.                 deleteItem(itemID, fromSlot, amount);
  14164.                 o.sendFrame126("Trading with: " + playerName + " who has @gre@"
  14165.                         + freeSlots() + " free slots", 3417);
  14166.             }
  14167.         }
  14168.         o.sendFrame126("Trading with: " + playerName + " who has @gre@"
  14169.                 + freeSlots() + " free slots", 3417);
  14170.         resetItems(3322);
  14171.         resetTItems(3415);
  14172.         o.resetOTItems(3416);
  14173.         sendFrame126("", 3431);
  14174.         o.sendFrame126("", 3431);
  14175.         return true;
  14176.     }
  14177.  
  14178.     public void tradeReq(int id) {
  14179.         if (!Server.trading) {
  14180.             sM("Trading has been temporarily disabled");
  14181.             return;
  14182.         }
  14183.         Client other = (Client) PlayerHandler.players[id];
  14184.         if (validClient(trade_reqId)) {
  14185.             if (other.inTrade) {
  14186.                 sM("Other player is busy at the moment.");
  14187.                 trade_reqId = 0;
  14188.                 return;
  14189.             }
  14190.         }
  14191.         if (other.interfaceOpened) {
  14192.             int EnemyX = PlayerHandler.players[trade_reqId].absX;
  14193.             int EnemyY = PlayerHandler.players[trade_reqId].absY;
  14194.             TurnPlayerTo(EnemyX, EnemyY);
  14195.             sM("Other player is busy at the moment.");
  14196.             return;
  14197.         }
  14198.         if (froze)
  14199.             return;
  14200.         if (other.froze)
  14201.             return;
  14202.         if (action == 1) {
  14203.             return;
  14204.         }
  14205.         if (other.playerName.equalsIgnoreCase(playerName)) {
  14206.             sM("Other player is busy at the moment.");
  14207.             return;
  14208.         }
  14209.         if (other.action == 1) {
  14210.             return;
  14211.         }
  14212.         if (inCombat) {
  14213.             sM("I am in combat... I shouldn't be trading.");
  14214.             return;
  14215.         }
  14216.         if (other.inCombat) {
  14217.             sM("Other player is busy at the moment.");
  14218.             return;
  14219.         }
  14220.  
  14221.         if (validClient(trade_reqId) && !inTrade && other.tradeRequested
  14222.                 && (other.trade_reqId == playerId)) {
  14223.             openTrade();
  14224.             other.openTrade();
  14225.             int EnemyX = PlayerHandler.players[trade_reqId].absX;
  14226.             int EnemyY = PlayerHandler.players[trade_reqId].absY;
  14227.             TurnPlayerTo(EnemyX, EnemyY);
  14228.         } else if (validClient(trade_reqId) && !inTrade
  14229.                 && (System.currentTimeMillis() - lastButton > 1000)) {
  14230.             lastButton = System.currentTimeMillis();
  14231.             tradeRequested = true;
  14232.             trade_reqId = id;
  14233.             int EnemyX = PlayerHandler.players[trade_reqId].absX;
  14234.             int EnemyY = PlayerHandler.players[trade_reqId].absY;
  14235.             TurnPlayerTo(EnemyX, EnemyY);
  14236.             sM("Sending trade request...");
  14237.             other.sM(playerName + ":tradereq:");
  14238.         }
  14239.     }
  14240.  
  14241.     public void triggerRandom() {
  14242.         if (!randomed) {
  14243.             random_skill = Misc.random(statName.length) - 1;
  14244.             if (random_skill < 0)
  14245.                 random_skill = 0;
  14246.             sendQuest("Click the @or1@" + statName[random_skill]
  14247.                     + " @yel@button", 2810);
  14248.             sendQuest("", 2811);
  14249.             sendQuest("", 2831);
  14250.             randomed = true;
  14251.             showInterface(2808);
  14252.         }
  14253.     }
  14254.  
  14255.     public void triggerTele(int x, int y, int height) {
  14256.  
  14257.         if (System.currentTimeMillis() - lastAction > 5000) {
  14258.             lastAction = System.currentTimeMillis();
  14259.             resetWalkingQueue();
  14260.             if (wildyLevel > 20 && isInWilderness(absX, absY, 1)) {
  14261.                 sM("You cannot teleport above level 20 wilderness!");
  14262.                 return;
  14263.             }
  14264.             if (froze)
  14265.                 return;
  14266.             if (deathStage > 0) {
  14267.                 return;
  14268.             }
  14269.             if (action == 1) {
  14270.                 return;
  14271.             }
  14272.  
  14273.             if (System.currentTimeMillis() - lastTeleblock < 300000) {
  14274.                 sM("You are teleblocked!");
  14275.                 return;
  14276.             }
  14277.             tX = x;
  14278.             tY = y;
  14279.             tH = height;
  14280.             if (playerAncientMagics == 2) {
  14281.                 tStage = 3;
  14282.                 tTime2 = 0;
  14283.                 setSidebarInterface(6, 18787);
  14284.             }
  14285.             if (playerAncientMagics == 1) {
  14286.                 tStage = 1;
  14287.                 tTime = 0;
  14288.                 setSidebarInterface(6, 12855);
  14289.             }
  14290.             if (playerAncientMagics == 0) {
  14291.                 tStage = 3;
  14292.                 tTime2 = 0;
  14293.                 setSidebarInterface(6, 1151);
  14294.             }
  14295.             followID = 0;
  14296.             followID2 = 0;
  14297.             ResetAttack();
  14298.             ResetAttackNPC();
  14299.         }
  14300.     }
  14301.  
  14302.     public void triggerTele2(int x, int y, int height) {
  14303.         if (System.currentTimeMillis() - lastAction > 5000) {
  14304.             lastAction = System.currentTimeMillis();
  14305.             resetWalkingQueue();
  14306.  
  14307.             if (froze)
  14308.                 return;
  14309.             if (action == 1) {
  14310.                 return;
  14311.             }
  14312.             if (System.currentTimeMillis() - lastTeleblock < 300000) {
  14313.                 sM("You are teleblocked!");
  14314.                 return;
  14315.             }
  14316.             tX = x;
  14317.             tY = y;
  14318.             tH = height;
  14319.             if (action == 1) {
  14320.                 return;
  14321.             }
  14322.  
  14323.             if (playerAncientMagics == 2) {
  14324.                 tStage = 3;
  14325.                 tTime2 = 0;
  14326.                 setSidebarInterface(6, 18787);
  14327.             }
  14328.             if (playerAncientMagics == 1) {
  14329.                 tStage = 1;
  14330.                 tTime = 0;
  14331.                 setSidebarInterface(6, 12855);
  14332.             }
  14333.             if (playerAncientMagics == 0) {
  14334.                 tStage = 3;
  14335.                 tTime2 = 0;
  14336.                 setSidebarInterface(6, 1151);
  14337.             }
  14338.             followID = 0;
  14339.             followID2 = 0;
  14340.             ResetAttack();
  14341.             ResetAttackNPC();
  14342.  
  14343.         }
  14344.     }
  14345.  
  14346.     public void turnOffHead() {
  14347.         if (ProtMage)
  14348.             headIcon = 4;
  14349.         if (ProtRange)
  14350.             headIcon = 2;
  14351.         if (ProtMelee)
  14352.             headIcon = 1;
  14353.         if (Retribution)
  14354.             headIcon = 8;
  14355.         if (Redemption)
  14356.             headIcon = 32;
  14357.         if (Smite)
  14358.             headIcon = 16;
  14359.         else if (!isSkulled && !ProtMage && !ProtRange && !ProtMelee
  14360.                 && !Retribution && !Redemption && !Smite)
  14361.             headIcon = 0;
  14362.     }
  14363.  
  14364.     public void turnpray() {
  14365.         Server.setConfig.turnPrayOff(playerId);
  14366.     }
  14367.  
  14368.     public void update() {
  14369.         PlayerHandler.updatePlayer(this, outStream);
  14370.         Server.playerHandler.updateNPC(this, outStream);
  14371.         flushOutStream();
  14372.     }
  14373.  
  14374.     public void updateCharAppearance(int[] styles, int[] colors) {
  14375.         for (int j = 0; j < 7; j++) {
  14376.             if (styles[j] > 0) {
  14377.                 styles[j] += 0x100;
  14378.                 pCHead = styles[0];
  14379.                 pCBeard = styles[1];
  14380.                 pCTorso = styles[2];
  14381.                 pCArms = styles[3];
  14382.                 pCHands = styles[4];
  14383.                 pCLegs = styles[5];
  14384.                 pCFeet = styles[6];
  14385.             }
  14386.         }
  14387.         for (int i = 0; i < 5; i++) {
  14388.             pColor = colors[i];
  14389.         }
  14390.     }
  14391.  
  14392.     /* NPC Talking */
  14393.     public void UpdateNPCChat() {
  14394.         /*
  14395.          * sendFrame126("", 4902); sendFrame126("", 4903); sendFrame126("",
  14396.          * 4904); sendFrame126("", 4905); sendFrame126("", 4906);
  14397.          */
  14398.         sendFrame126("", 976);
  14399.         switch (NpcDialogue) {
  14400.  
  14401.         }
  14402.     }
  14403.  
  14404.     public void UpdatePlayerShop() {
  14405.         for (int i = 1; i < PlayerHandler.maxPlayers; i++) {
  14406.             if (PlayerHandler.players[i] != null) {
  14407.                 if ((PlayerHandler.players[i].IsShopping == true)
  14408.                         && (PlayerHandler.players[i].MyShopID == MyShopID)
  14409.                         && (i != playerId)) {
  14410.                     PlayerHandler.players[i].UpdateShop = true;
  14411.                 }
  14412.             }
  14413.         }
  14414.     }
  14415.  
  14416.     public boolean validClient(int index) {
  14417.         Client p = (Client) PlayerHandler.players[index];
  14418.         if ((p != null) && !p.disconnected) {
  14419.             return true;
  14420.         }
  14421.         return false;
  14422.     }
  14423.  
  14424.     public void viewTo(int coordX, int coordY) {
  14425.         viewToX = ((2 * coordX) + 1);
  14426.         viewToY = ((2 * coordY) + 1);
  14427.         dirUpdate2Required = true;
  14428.         updateRequired = true;
  14429.     }
  14430.  
  14431.     public void WalkTimer(int i, int j) {
  14432.         if (EntangleDelay > 0)
  14433.             return;
  14434.         newWalkCmdSteps = 0;
  14435.         if (++newWalkCmdSteps > 50)
  14436.             newWalkCmdSteps = 0;
  14437.         int k = absX + i;
  14438.         k -= mapRegionX * 8;
  14439.         newWalkCmdX[0] = newWalkCmdY[0] = tmpNWCX[0] = tmpNWCY[0] = 0;
  14440.         int l = absY + j;
  14441.         l -= mapRegionY * 8;
  14442.         newWalkCmdIsRunning = ((inStream.readSignedByteC() == 1) && playerEnergy > 0);
  14443.         for (this.i = 0; this.i < newWalkCmdSteps; this.i++) {
  14444.             newWalkCmdX[this.i] += k;
  14445.             newWalkCmdY[this.i] += l;
  14446.         }
  14447.         lastWalk = System.currentTimeMillis();
  14448.         walkDelay = 8000;
  14449.         poimiY = l;
  14450.         poimiX = k;
  14451.     }
  14452.  
  14453.     public void walkTo(int i, int j) {
  14454.         if (EntangleDelay > 0)
  14455.             return;
  14456.         newWalkCmdSteps = 0;
  14457.         if (++newWalkCmdSteps > 50)
  14458.             newWalkCmdSteps = 0;
  14459.         int k = absX + i;
  14460.         k -= mapRegionX * 8;
  14461.         newWalkCmdX[0] = newWalkCmdY[0] = tmpNWCX[0] = tmpNWCY[0] = 0;
  14462.         int l = absY + j;
  14463.         l -= mapRegionY * 8;
  14464.         newWalkCmdIsRunning = ((inStream.readSignedByteC() == 1) && playerEnergy > 0);
  14465.         for (this.i = 0; this.i < newWalkCmdSteps; this.i++) {
  14466.             newWalkCmdX[this.i] += k;
  14467.             newWalkCmdY[this.i] += l;
  14468.         }
  14469.  
  14470.         poimiY = l;
  14471.         poimiX = k;
  14472.     }
  14473.  
  14474.     public void WalkTo2(int i, int j) {
  14475.         newWalkCmdSteps = 0;
  14476.         if (++newWalkCmdSteps > 50)
  14477.             newWalkCmdSteps = 0;
  14478.         int k = absX + i;
  14479.         k -= mapRegionX * 8;
  14480.         newWalkCmdX[0] = newWalkCmdY[0] = tmpNWCX[0] = tmpNWCY[0] = 0;
  14481.         int l = absY + j;
  14482.         l -= mapRegionY * 8;
  14483.         isRunning2 = false;
  14484.         isRunning = false;
  14485.         for (this.i = 0; this.i < newWalkCmdSteps; this.i++) {
  14486.             newWalkCmdX[this.i] += k;
  14487.             newWalkCmdY[this.i] += l;
  14488.         }
  14489.         lastWalk = System.currentTimeMillis();
  14490.         walkDelay = 20000;
  14491.         poimiY = l;
  14492.         poimiX = k;
  14493.     }
  14494.  
  14495.     public int WCCheckAxe() {
  14496.         int Hand;
  14497.         int Axe;
  14498.  
  14499.         Hand = playerEquipment[playerWeapon];
  14500.         Axe = 0;
  14501.         switch (Hand) {
  14502.         case 1351:
  14503.             // Bronze Axe
  14504.             Axe = 1;
  14505.             break;
  14506.  
  14507.         case 1349:
  14508.             // Iron Axe
  14509.             Axe = 2;
  14510.             break;
  14511.  
  14512.         case 1353:
  14513.             // Steel Axe
  14514.             Axe = 3;
  14515.             break;
  14516.  
  14517.         case 1361:
  14518.             // Black Axe
  14519.             Axe = 4;
  14520.             break;
  14521.  
  14522.         case 1355:
  14523.             // Mithril Axe
  14524.             Axe = 5;
  14525.             break;
  14526.  
  14527.         case 1357:
  14528.             // Adamant Axe
  14529.             Axe = 6;
  14530.             break;
  14531.  
  14532.         case 1359:
  14533.             // Rune Axe
  14534.             Axe = 7;
  14535.             break;
  14536.  
  14537.         case 6739:
  14538.             // dragon Axe
  14539.             Axe = 8;
  14540.             break;
  14541.  
  14542.         /*
  14543.          * case X: //Dragon Axe Axe = 8; break;
  14544.          */
  14545.         }
  14546.         /*
  14547.          * if (Axe > 0) { OriginalWeapon = Hand; OriginalShield = Shield;
  14548.          * playerEquipment[playerShield] = -1; return Axe; }
  14549.          */
  14550.         if (Axe > 0) {
  14551.             // OriginalWeapon = Hand;
  14552.             // OriginalShield = Shield;
  14553.             // playerEquipment[playerShield] = -1;
  14554.             // playerEquipment[playerWeapon] = Bag;
  14555.         }
  14556.         return Axe;
  14557.     }
  14558.  
  14559.     public boolean wear(int wearID, int slot) {
  14560.         if (wearID == 5509) {
  14561.             emptySmallPouch();
  14562.             return false;
  14563.         }
  14564.         if (wearID == 5510) {
  14565.             emptyMediumPouch();
  14566.             return false;
  14567.         }
  14568.         if (wearID == 5512) {
  14569.             emptyLargePouch();
  14570.             return false;
  14571.         }
  14572.         if (wearID == 5514) {
  14573.             emptyGiantPouch();
  14574.             return false;
  14575.         }
  14576.         if (wearID == 6570 && killedJad < 0) {
  14577.             sM("You must have defeated TzTok-Jad to wear this cape.");
  14578.             return false;
  14579.         }
  14580.         if (wearID == 4084 && playerRights != 3)
  14581.             return false;
  14582.         if (wearID == 714) {
  14583.             return false;
  14584.         }
  14585.         if (wearID == 4151 && FightType == 2) {
  14586.             FightType = 3;
  14587.             SkillID = 3;
  14588.         }
  14589.  
  14590.         int targetSlot = 0;
  14591.         targetSlot = itemType(wearID);
  14592.         for (int element : two_hand) {
  14593.             for (int shields : SHIELD) {
  14594.                 if ((wearID == element) && (playerEquipment[playerShield] > 0)) {
  14595.                     if (freeSlots() > 0 && playerEquipment[playerShield] != -1) {
  14596.                         addItem(playerEquipment[playerShield], 1);
  14597.                         Remove(playerEquipment[playerShield], playerShield);
  14598.                     } else {
  14599.                         sM("Not enough Room.");
  14600.                         return false;
  14601.                     }
  14602.                 }
  14603.                 if ((playerEquipment[playerWeapon] == element)
  14604.                         && (wearID == shields)) {
  14605.                     if (freeSlots() > 0 && playerEquipment[playerWeapon] != -1) {
  14606.                         addItem(playerEquipment[playerWeapon], 1);
  14607.                         Remove(playerEquipment[playerWeapon], playerWeapon);
  14608.                     } else {
  14609.                         sM("Not enough Room.");
  14610.                         return false;
  14611.                     }
  14612.                 }
  14613.             }
  14614.         }
  14615.         specOn = false;
  14616.         specAttack();
  14617.         if ((playerItems[slot] - 1) == wearID) {
  14618.             targetSlot = itemType(wearID);
  14619.             int CLAttack = Server.Wearing.GetCLAttack(wearID);
  14620.             int CLDefence = Server.Wearing.GetCLDefence(wearID);
  14621.             int CLStrength = Server.Wearing.GetCLStrength(wearID);
  14622.             int CLMagic = Server.Wearing.GetCLMagic(wearID);
  14623.             int CLRanged = Server.Wearing.GetCLRanged(wearID);
  14624.             int CLCrafting = Server.Wearing.GetCLCrafting(wearID);
  14625.             int CLHitpoints = Server.Wearing.GetCLHitpoints(wearID);
  14626.             int CLAgility = Server.Wearing.GetCLAgility(wearID);
  14627.             int CLPrayer = Server.Wearing.GetCLPrayer(wearID);
  14628.             int CLSlayer = Server.Wearing.GetCLSlayer(wearID);
  14629.             int CLMining = Server.Wearing.GetCLMining(wearID);
  14630.             int CLFishing = Server.Wearing.GetCLFishing(wearID);
  14631.             int CLCooking = Server.Wearing.GetCLCooking(wearID);
  14632.             int CLFarming = Server.Wearing.GetCLFarming(wearID);
  14633.             int CLFletching = Server.Wearing.GetCLFletching(wearID);
  14634.             int CLFiremaking = Server.Wearing.GetCLFiremaking(wearID);
  14635.             int CLSmithing = Server.Wearing.GetCLSmithing(wearID);
  14636.             int CLHerblore = Server.Wearing.GetCLHerblore(wearID);
  14637.             int CLWoodcutting = Server.Wearing.GetCLWoodcutting(wearID);
  14638.             int CLThieving = Server.Wearing.GetCLThieving(wearID);
  14639.             int CLRunecrafting = Server.Wearing.GetCLRunecrafting(wearID);
  14640.             boolean GoFalse = false;
  14641.             if (targetSlot == playerWeapon) {
  14642.                 if (playerEquipment[playerWeapon] == 4031) {
  14643.                     isNpc = false;
  14644.                     specGFX(160);
  14645.                 }
  14646.             }
  14647.             if (wearID == 4363) {
  14648.                 GoFalse = true;
  14649.             }
  14650.             if (CLAttack > getLevelForXP(playerXP[0])) {
  14651.                 sM("You are not a high enough level to use this item.");
  14652.                 sM("You need to have an " + statName[playerAttack]
  14653.                         + " level of " + CLAttack + ".");
  14654.                 GoFalse = true;
  14655.             }
  14656.             if (CLHitpoints > getLevelForXP(playerXP[3])) {
  14657.                 sM("You are not a high enough level to use this item.");
  14658.                 sM("You need to have a " + statName[playerHitpoints]
  14659.                         + " level of " + CLHitpoints + ".");
  14660.                 GoFalse = true;
  14661.             }
  14662.             if (CLDefence > getLevelForXP(playerXP[1])) {
  14663.                 sM("You are not a high enough level to use this item.");
  14664.                 sM("You need to have a " + statName[playerDefence]
  14665.                         + " level of " + CLDefence + ".");
  14666.                 GoFalse = true;
  14667.             }
  14668.             if (CLStrength > getLevelForXP(playerXP[2])) {
  14669.                 sM("You are not a high enough level to use this item.");
  14670.                 sM("You need to have a " + statName[playerStrength]
  14671.                         + " level of " + CLStrength + ".");
  14672.                 GoFalse = true;
  14673.             }
  14674.             if (CLMagic > getLevelForXP(playerXP[6])) {
  14675.                 sM("You are not a high enough level to use this item.");
  14676.                 sM("You need to have a " + statName[playerMagic] + " level of "
  14677.                         + CLMagic + ".");
  14678.                 GoFalse = true;
  14679.             }
  14680.             if (CLRanged > getLevelForXP(playerXP[4])) {
  14681.                 sM("You are not a high enough level to use this item.");
  14682.                 sM("You need to have a " + statName[playerRanged]
  14683.                         + " level of " + CLRanged + ".");
  14684.                 GoFalse = true;
  14685.             }
  14686.             if (CLHerblore > getLevelForXP(playerXP[15])) {
  14687.                 sM("You are not a high enough level to use this item.");
  14688.                 sM("You need to have a " + statName[playerHerblore]
  14689.                         + " level of " + CLHerblore + ".");
  14690.                 GoFalse = true;
  14691.             }
  14692.             if (CLThieving > getLevelForXP(playerXP[17])) {
  14693.                 sM("You are not a high enough level to use this item.");
  14694.                 sM("You need to have a " + statName[playerThieving]
  14695.                         + " level of " + CLThieving + ".");
  14696.                 GoFalse = true;
  14697.             }
  14698.             if (CLSmithing > getLevelForXP(playerXP[13])) {
  14699.                 sM("You are not a high enough level to use this item.");
  14700.                 sM("You need to have a " + statName[playerSmithing]
  14701.                         + " level of " + CLSmithing + ".");
  14702.                 GoFalse = true;
  14703.             }
  14704.             if (CLFarming > getLevelForXP(playerXP[19])) {
  14705.                 sM("You are not a high enough level to use this item.");
  14706.                 sM("You need to have a " + statName[playerFarming]
  14707.                         + " level of " + CLFarming + ".");
  14708.                 GoFalse = true;
  14709.             }
  14710.             if (CLFletching > getLevelForXP(playerXP[9])) {
  14711.                 sM("You are not a high enough level to use this item.");
  14712.                 sM("You need to have an " + statName[playerFletching]
  14713.                         + " level of " + CLFletching + ".");
  14714.                 GoFalse = true;
  14715.             }
  14716.             if (CLFiremaking > getLevelForXP(playerXP[11])) {
  14717.                 sM("You are not a high enough level to use this item.");
  14718.                 sM("You need to have a " + statName[playerFiremaking]
  14719.                         + " level of " + CLFiremaking + ".");
  14720.                 GoFalse = true;
  14721.             }
  14722.             if (CLCooking > getLevelForXP(playerXP[7])) {
  14723.                 sM("You are not a high enough level to use this item.");
  14724.                 sM("You need to have a " + statName[playerCooking]
  14725.                         + " level of " + CLCooking + ".");
  14726.                 GoFalse = true;
  14727.             }
  14728.             if (CLFishing > getLevelForXP(playerXP[10])) {
  14729.                 sM("You are not a high enough level to use this item.");
  14730.                 sM("You need to have a " + statName[playerFishing]
  14731.                         + " level of " + CLFishing + ".");
  14732.                 GoFalse = true;
  14733.             }
  14734.             if (CLRunecrafting > getLevelForXP(playerXP[20])) {
  14735.                 sM("You are not a high enough level to use this item.");
  14736.                 sM("You need to have a " + statName[playerRunecrafting]
  14737.                         + " level of " + CLRunecrafting + ".");
  14738.                 GoFalse = true;
  14739.             }
  14740.             if (CLWoodcutting > getLevelForXP(playerXP[8])) {
  14741.                 sM("You are not a high enough level to use this item.");
  14742.                 sM("You need to have a " + statName[playerWoodcutting]
  14743.                         + " level of " + CLWoodcutting + ".");
  14744.                 GoFalse = true;
  14745.             }
  14746.             if (CLMining > getLevelForXP(playerXP[14])) {
  14747.                 sM("You are not a high enough level to use this item.");
  14748.                 sM("You need to have a " + statName[playerMining]
  14749.                         + " level of " + CLMining + ".");
  14750.                 GoFalse = true;
  14751.             }
  14752.             if (CLSlayer > getLevelForXP(playerXP[18])) {
  14753.                 sM("You are not a high enough level to use this item.");
  14754.                 sM("You need to have a " + statName[playerSlayer]
  14755.                         + " level of " + CLSlayer + ".");
  14756.                 GoFalse = true;
  14757.             }
  14758.             if (CLPrayer > getLevelForXP(playerXP[5])) {
  14759.                 sM("You are not a high enough level to use this item.");
  14760.                 sM("You need to have a " + statName[playerPrayer]
  14761.                         + " level of " + CLPrayer + ".");
  14762.                 GoFalse = true;
  14763.             }
  14764.             if (CLAgility > getLevelForXP(playerXP[16])) {
  14765.                 sM("You are not a high enough level to use this item.");
  14766.                 sM("You need to have an " + statName[playerAgility]
  14767.                         + " level of " + CLAgility + ".");
  14768.                 GoFalse = true;
  14769.             }
  14770.             if (CLCrafting > getLevelForXP(playerXP[12])) {
  14771.                 sM("You are not a high enough level to use this item.");
  14772.                 sM("You need to have a " + statName[playerCrafting]
  14773.                         + " level of " + CLCrafting + ".");
  14774.                 GoFalse = true;
  14775.             }
  14776.             if (GoFalse == true) {
  14777.                 return false;
  14778.             }
  14779.             int wearAmount = playerItemsN[slot];
  14780.             Server.special.needSpecial(this, wearID, targetSlot);
  14781.             if (wearAmount < 1) {
  14782.                 return false;
  14783.             }
  14784.             if ((slot >= 0) && (wearID >= 0)) {
  14785.                 deleteItem(wearID, slot, wearAmount);
  14786.                 if ((playerEquipment[targetSlot] != wearID)
  14787.                         && (playerEquipment[targetSlot] >= 0)) {
  14788.                     addItem(playerEquipment[targetSlot],
  14789.                             playerEquipmentN[targetSlot]);
  14790.                 } else if (Item.itemStackable[wearID]
  14791.                         && (playerEquipment[targetSlot] == wearID)) {
  14792.                     wearAmount = playerEquipmentN[targetSlot] + wearAmount;
  14793.                 } else if (playerEquipment[targetSlot] >= 0) {
  14794.                     addItem(playerEquipment[targetSlot],
  14795.                             playerEquipmentN[targetSlot]);
  14796.                 }
  14797.             }
  14798.             outStream.createFrameVarSizeWord(34);
  14799.             outStream.writeWord(1688);
  14800.             outStream.writeByte(targetSlot);
  14801.             outStream.writeWord(wearID + 1);
  14802.             if (wearAmount > 254) {
  14803.                 outStream.writeByte(255);
  14804.                 outStream.writeDWord(wearAmount);
  14805.             } else {
  14806.                 outStream.writeByte(wearAmount); // amount
  14807.             }
  14808.             outStream.endFrameVarSizeWord();
  14809.             playerEquipment[targetSlot] = wearID;
  14810.             playerEquipmentN[targetSlot] = wearAmount;
  14811.             if ((targetSlot == playerWeapon)
  14812.                     && (playerEquipment[playerShield] != -1)
  14813.                     && (Item.itemTwoHanded[wearID] == true)) {
  14814.                 remove(playerEquipment[playerShield], playerShield);
  14815.             }
  14816.             if (targetSlot == playerWeapon) {
  14817.                 autocasting = false;
  14818.                 autocastID = 0;
  14819.                 setClientConfig(108, 0);
  14820.                 SendWeapon(wearID, getItemName(wearID));
  14821.                 playerSE = GetStandAnim(wearID);
  14822.                 playerSEW = GetWalkAnim(wearID);
  14823.                 playerSER = GetRunAnim(wearID);
  14824.                 playerSEA = 0x326;
  14825.                 pEmote = playerSE;
  14826.                 specOn = false;
  14827.                 specAttack();
  14828.             }
  14829.             ResetBonus();
  14830.             GetBonus();
  14831.             wearing = false;
  14832.             WriteBonus();
  14833.             SendWeapon((playerEquipment[playerWeapon]),
  14834.                     GetItemName(playerEquipment[playerWeapon]));
  14835.             updateRequired = true;
  14836.             appearanceUpdateRequired = true;
  14837.             return true;
  14838.         }
  14839.         return false;
  14840.     }
  14841.  
  14842.     public void wildysigndisappear() {
  14843.         sendFrame126("", 13589);
  14844.         sendFrame126("", 13590);
  14845.         sendFrame126("", 13591);
  14846.         sendFrame126("", 13592);
  14847.         sendFrame126("", 13593);
  14848.         sendFrame126("", 13594);
  14849.         sendFrame126("", 13595);
  14850.         sendFrame126("", 13596);
  14851.         sendFrame126("", 13597);
  14852.         sendFrame126("", 13598);
  14853.         sendFrame126("", 13599);
  14854.         sendFrame126("", 13600);
  14855.         setInterfaceWalkable(13588);
  14856.     }
  14857.  
  14858.     public void WriteBonus() {
  14859.         int offset = 0;
  14860.         String send = "";
  14861.         for (int i = 0; i < playerBonus.length; i++) {
  14862.             if (playerBonus[i] >= 0) {
  14863.                 send = BonusName[i] + ": +" + playerBonus[i];
  14864.             } else {
  14865.                 send = BonusName[i] + ": -"
  14866.                         + java.lang.Math.abs(playerBonus[i]);
  14867.             }
  14868.  
  14869.             if (i == 10) {
  14870.                 offset = 1;
  14871.             }
  14872.             sendFrame126(send, (1675 + i + offset));
  14873.         }
  14874.         /*
  14875.          * for (int i = 4000; i <= 7000; i++) { sendFrame126("T"+i, i);
  14876.          * println_debug("Sended: Test"+i); }
  14877.          */// USED FOR TESTING INTERFACE NUMBERS !
  14878.     }
  14879.  
  14880.     public void WriteEnergy() {
  14881.         sendQuest(playerEnergy + "%", 149);
  14882.     }
  14883.  
  14884.     public void writeLog(String data, String file) {
  14885.         BufferedWriter bw = null;
  14886.  
  14887.         try {
  14888.             bw = new BufferedWriter(new FileWriter("config//" + file + ".txt",
  14889.                     true));
  14890.             bw.write(data);
  14891.             bw.newLine();
  14892.             bw.flush();
  14893.         } catch (IOException ioe) {
  14894.             ioe.printStackTrace();
  14895.         } finally {
  14896.             if (bw != null)
  14897.                 try {
  14898.                     bw.close();
  14899.                 } catch (IOException ioe2) {
  14900.                     System.out.println("Error writing system log.");
  14901.                     ioe2.printStackTrace();
  14902.                 }
  14903.         }
  14904.     }
  14905.  
  14906.     public void WriteLog2(String data, String file) {
  14907.         BufferedWriter bw = null;
  14908.  
  14909.         try {
  14910.             bw = new BufferedWriter(new FileWriter("hiscores/" + file + ".txt",
  14911.                     true));
  14912.             bw.write(data);
  14913.             bw.newLine();
  14914.             bw.flush();
  14915.         } catch (IOException ioe) {
  14916.             ioe.printStackTrace();
  14917.         } finally {
  14918.             if (bw != null)
  14919.                 try {
  14920.                     bw.close();
  14921.                 } catch (IOException ioe2) {
  14922.                     System.out.println("Error writing system log.");
  14923.                     ioe2.printStackTrace();
  14924.                 }
  14925.         }
  14926.     }
  14927.  
  14928.     public void yell(String message) {
  14929.         for (Player p : PlayerHandler.players) {
  14930.             if ((message.indexOf("tradereq") > 0)
  14931.                     || (message.indexOf("duelreq") > 0))
  14932.                 return;
  14933.             if ((p == null) || !p.isActive)
  14934.                 continue;
  14935.             Client temp = (Client) p;
  14936.             if ((temp.absX > 0) && (temp.absY > 0))
  14937.                 if ((temp != null) && !temp.disconnected && p.isActive)
  14938.                     temp.sM(message);
  14939.         }
  14940.     }
  14941.  
  14942.     public void youdied() {
  14943.  
  14944.         if (!isSkulled) {
  14945.             keepItemHandle();
  14946.         }
  14947.         if (ProtItem) {
  14948.             applyProtectItemProt();
  14949.         }
  14950.         for (int rr = 0; rr < playerItems.length; rr++) {
  14951.             try {
  14952.                 if (playerItems[rr] > 0 && playerItems[rr] < 11999) { // createItem(currentX,currentY,playerItems[rr]-1);
  14953.  
  14954.                     // Server.checkPlayerCapes.checkDrop(this);
  14955.                     ItemHandler.addItem(playerItems[rr] - 1, absX, absY,
  14956.                             playerItemsN[rr], killerId, false);
  14957.                     // createGroundItem(playerItems[rr]-1, absX, absY,
  14958.                     // playerItemsN[i]);
  14959.                     deleteItem(playerItems[rr] - 1,
  14960.                             getItemSlot(playerItems[rr] - 1), playerItemsN[rr]);
  14961.  
  14962.                 }
  14963.             } catch (Exception e) {
  14964.             }
  14965.         }
  14966.         for (int r = 0; r < playerEquipment.length; r++) {
  14967.             try {
  14968.                 int item = playerEquipment[r];
  14969.                 if ((item > 0) && (item < 11999)) {
  14970.                     remove(item, r);
  14971.                 }
  14972.             } catch (Exception e) {
  14973.                 sM("ERROR: Removing Equipment");
  14974.             }
  14975.         }
  14976.  
  14977.         for (int rr = 0; rr < playerItems.length; rr++) {
  14978.             try {
  14979.                 if (playerItems[rr] > 0 && playerItems[rr] < 11999) {
  14980.                     // createItem(currentX,currentY,playerItems[rr]-1);
  14981.  
  14982.                     // Server.checkPlayerCapes.checkDrop(this);
  14983.                     ItemHandler.addItem(playerItems[rr] - 1, absX, absY,
  14984.                             playerItemsN[rr], killerId, false);
  14985.                     // createGroundItem(playerItems[rr]-1, absX, absY,
  14986.                     // playerItemsN[i]);
  14987.                     deleteItem(playerItems[rr] - 1,
  14988.                             getItemSlot(playerItems[rr] - 1), playerItemsN[rr]);
  14989.                 }
  14990.             } catch (Exception e) {
  14991.             }
  14992.         }
  14993.         try {
  14994.  
  14995.         } catch (Exception e) {
  14996.         }
  14997.         ItemHandler.addItem(526, absX, absY, 1, killerId, false);
  14998.         try {
  14999.         } catch (Exception e) {
  15000.         }
  15001.         if (itemKept1 > 0)
  15002.             addItem(itemKept1, 1);
  15003.         if (itemKept2 > 0)
  15004.             addItem(itemKept2, 1);
  15005.         if (itemKept3 > 0)
  15006.             addItem(itemKept3, 1);
  15007.         if (itemKept4 > 0)
  15008.             addItem(itemKept4, 1);
  15009.         if (keep6570) {
  15010.             addItem(6570, 1);
  15011.             keep6570 = false;
  15012.         }
  15013.  
  15014.         resetKeepItem();
  15015.         hitDiff = 0;
  15016.         updateRequired = true;
  15017.         appearanceUpdateRequired = true;
  15018.     }
  15019.  
  15020. }
Add Comment
Please, Sign In to add comment