Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package palidino76.rs2.players;
- import java.awt.Point;
- import java.io.FileWriter;
- import java.io.BufferedWriter;
- import java.io.IOException;
- import java.net.Socket;
- import java.util.Iterator;
- import java.util.List;
- import java.util.ArrayList;
- import java.util.LinkedList;
- import palidino76.rs2.Engine;
- import palidino76.rs2.Server;
- import palidino76.rs2.io.Frames;
- import palidino76.rs2.net.PlayerSocket;
- import palidino76.rs2.util.*;
- import palidino76.rs2.players.Trade.Trade;
- import palidino76.rs2.npcs.NPC;
- import palidino76.rs2.players.items.PlayerWeapon;
- import palidino76.rs2.io.packets.*;
- import palidino76.rs2.net.*;
- import palidino76.rs2.players.update.*;
- import palidino76.rs2.players.skills.*;
- public class Player {
- public Fishing fishy = new Fishing();
- public Mining mini = new Mining();
- public Woodcutting woody = new Woodcutting();
- public PrayerBury pray = new PrayerBury();
- public NPC n;
- public long lastVeng;
- public boolean vengOn = false;
- public boolean attackingNPC = false;
- public int playerPKDelay = 0;
- public int combatTimer = 0;
- public int prayTimer = 0;
- public boolean isDoingDfsSpecial = false;
- public int dfsCharges = 0;
- public boolean canPerformDfsSpecial = true;
- public int secondsTillNextDfsSpecial = 0;
- public int timeoutTimer = 0;
- public boolean autoRetaliating;
- public int skullDelay;
- public boolean hasSkull;
- public int muted;
- public int muteTimer;
- public String clanRoom = "";
- public boolean inClanChat = false;
- public int tutorial = 0;
- public int attackNPC = 0;
- public int npcDelay = 0;
- public int flaxTimer = 0;
- public boolean tutorialCompleted = false;
- public int followPlayer = 0;
- public boolean followingPlayer = false;
- public int newPlayerTimer = 0;
- /**
- * Resetting animation
- */
- public int resetAnimTimer;
- public void walkingTo(int x, int y) {
- int firstX = x - (mapRegionX - 6) * 8;
- int firstY = y - (mapRegionY - 6) * 8;
- Engine.playerMovement.resetWalkingQueue(this);
- Engine.playerMovement.addToWalkingQueue(this, firstX, firstY);
- appearanceUpdateReq = true;
- updateReq = true;
- }
- /**
- * UserInput.
- */
- public UserInput input = new UserInput(this);
- /**
- * Magic.
- */
- public int mageDamage;
- public int projectileTimer = -1;
- public boolean normalHomeTele = false;
- public boolean ancientsHomeTele = false;
- public int homeTele = 0;
- public int homeTeleDelay = 0;
- public double arenaSpellPower = 1;
- public int magicDelay = 0;
- public int freezeDelay = 0;
- /**
- * Option variable
- */
- public int optionId;
- public int maxArrays = 10;
- public boolean[] optionArray = new boolean[maxArrays];
- /**
- * Poisoning
- */
- public int poisonDelay;
- public int poisonHitCount;
- public boolean isPoisoned;
- /**
- *Eat delay
- */
- public int eatDelay = 0;
- /**
- * trade.
- */
- public Trade trade;
- /**
- * Destroy item arrays
- */
- public int[] destroyItem = new int[28];
- public int[] destroyItemAmt = new int[28];
- /**
- * NPC Dialogues Stage.
- */
- public boolean[] stage = new boolean[2];
- public int iStage;
- /**
- * Destroy item variable
- */
- public int destroyItemInt;
- /**
- * Attacking interface data.
- */
- public int attackStyle = 0;
- public int autoRetaliate = 0;
- /**
- * Private messages. Friends Ignores
- */
- public boolean splitChat = false;
- public List<Long> friends = new ArrayList<Long>(200);
- public List<Long> ignores = new ArrayList<Long>(100);
- /**
- * Set Drinking
- */
- public int drinkDelay = 0;
- public int statPotRestoreDelay = 5;
- /**
- * Player's Note's.
- */
- public boolean swapAsNote = false;
- /**
- * Prayer settings.
- */
- public int prayerDrain = 100;
- public int drainRate = 0;
- public int defLow = 0;
- public int strLow = 1;
- public int atkLow = 2;
- public int rangeLow = 3;
- public int mageLow = 4;
- public int defMid = 5;
- public int strMid = 6;
- public int atkMid = 7;
- public int rapidRestore = 8;
- public int rapidHeal = 9;
- public int protItems = 10;
- public int rangeMid = 11;
- public int Hitter = 5;
- public int mageMid = 12;
- public int defHigh = 13;
- public int strHigh = 14;
- public int atkHigh = 15;
- public int prayMage = 16;
- public int prayRange = 17;
- public int prayMelee = 18;
- public int rangeHigh = 19;
- public int mageHigh = 20;
- public int retribution = 21;
- public int redepmtion = 22;
- public int smite = 23;
- public int praySummon = 24;
- public int chivalry = 25;
- public int piety = 26;
- public boolean prayOn[] = new boolean[27];
- /**
- * Player's Skilltab's.
- */
- public int skillMenu = 0;
- /**
- * Player's index.
- */
- public int playerId = 0;
- /**
- * Class for storing and converting bytes.
- */
- public Stream stream = new Stream(500, 5000);
- /**
- * Player's socket for handling most io operations.
- */
- public PlayerSocket socket;
- /**
- * Set to true if the player has finished the login stage.
- */
- public boolean online = false;
- /**
- * This is for Welcome Interface.
- */
- public int randomMessage = Misc.random(9);
- public int messageCount = 1;
- public int memberCount = 0;
- /**
- * Player's username.
- */
- public String username = "null";
- /**
- * Player's password.
- */
- public String password = "";
- /**
- * Player's rights.
- */
- public int rights = 0;
- public int firstLog = 0;
- /**
- * 1 set to true means socket disconnected but logged in, both for removing
- * the player.
- */
- public boolean[] disconnected = new boolean[2];
- /**
- * Gives quick access to the frame class.
- */
- public Frames frames = Engine.frames;
- /**
- * The region this player is in.
- */
- public int mapRegionX = 0;
- public int mapRegionY = 0;
- /**
- * The position this player is at in the map region.
- */
- public int currentX = 0;
- public int currentY = 0;
- /**
- * The slot at which each bank tab starts at
- */
- public int[] tabStartSlot = new int[11];
- /**
- * The amount of items that you have last withdrew/deposited with the X
- * function
- */
- public int bankX = 50;
- /**
- * The tab you are viewing, used to store items in it when depositing
- */
- public int viewingBankTab = 10;
- /**
- * If you are withdrawing items as a note
- */
- public boolean withdrawNote;
- /**
- * If you are using insert mode
- */
- public boolean insertMode;
- /**
- * Absolute coordinates this player is at.
- */
- public int absX = 0;
- public int absY = 0;
- /**
- * KilledBy.
- */
- public int[] killedBy = new int[Engine.players.length];
- /**
- * The height level this player is at.
- */
- public int heightLevel = 0;
- /**
- * If either are above -1 then the player is in motion.
- */
- public int walkDir = -1;
- public int runDir = -1;
- /**
- * True if the player is running, false if it isn't.
- */
- public boolean isRunning = false;
- /**
- * Set to true if the player has entered a new map region.
- */
- public boolean mapRegionDidChange = false;
- public boolean mouse = false;
- public boolean chat = false;
- public boolean aid = false;
- /**
- * Set to true if teleported.
- */
- public boolean didTeleport = false;
- /**
- * Set Absolute coordinates to these.
- */
- public int teleportToX = -1;
- public int teleportToY = -1;
- /**
- * True if the player is requiring an update.
- */
- public boolean updateReq = false;
- /**
- * Max number of steps this player can have pending.
- */
- public int walkingQueueSize = 50;
- public int wQueueReadPtr = 0;
- public int wQueueWritePtr = 0;
- /**
- * Positions the player is requiring to walk to.
- */
- public int[] walkingQueueX = new int[walkingQueueSize];
- public int[] walkingQueueY = new int[walkingQueueSize];
- public int[] walkingQueue = new int[walkingQueueSize];
- /**
- * All the players within distance.
- */
- public Player[] playerList = new Player[Engine.players.length];
- /**
- * All the players stored in distance.
- */
- public byte[] playersInList = new byte[Engine.players.length];
- public int playerListSize = 0;
- /**
- * True if chat is requiring to be sent.
- */
- public boolean chatTextUpdateReq = false;
- public String chatText = "";
- public int chatTextEffects = 0;
- /**
- * True if an appearance update is needed.
- */
- public boolean appearanceUpdateReq = false;
- /**
- * Animation data.
- */
- public boolean animUpdateReq = false;
- public int animReq = -1;
- public int animDelay = 0;
- /**
- * GFX data.
- */
- public boolean gfxUpdateReq = false;
- public int gfxReq = -1;
- public int gfxDelay = 0;
- /**
- * Player and NPC facing data.
- */
- public boolean faceToUpdateReq = false;
- public int faceToReq = -1;
- /**
- * Damage data.
- */
- public boolean hit1UpdateReq = false;
- public boolean hit2UpdateReq = false;
- public int hitDiff1 = 0;
- public int hitDiff2 = 0;
- public int posionHit1 = 0;
- public int posionHit2 = 0;
- /**
- * Skill level data.
- */
- public int[] skillLvl = new int[25];
- public int[] skillXP = new int[25];
- public int combatLevel = 0;
- /**
- * Player head icons.
- */
- public int pkIcon = -1;
- public int prayerIcon = -1;
- public int headIcon = -1;
- /**
- * Wilderness variables.
- */
- public int wildyLevel;
- /**
- * If player updated the Wilderness level.
- */
- public boolean updatedLevel;
- /**
- * Wild ditch jumping.
- */
- public int jumpDelay = 0;
- public boolean jumpUpdateReq = false;
- public int enemyIndex;
- /**
- * Equipment data.
- */
- public int[] equipment = new int[14];
- public int[] equipmentN = new int[14];
- public int[] equipmentBonus = new int[12];
- /**
- * Player appearance.
- */
- public int[] color = new int[5];
- public int[] look = new int[7];
- public int npcType = -1;
- public int gender = 0;
- public int[] colour = new int[5];
- /**
- * Player emotions.
- */
- public int runEmote = 0x338;
- public int walkEmote = 0x333;
- public int standEmote = 0x328;
- public int attackEmote = 422;
- public int BlockEmote = 421;
- /**
- * All the NPCs within distance.
- */
- public NPC[] npcList = new NPC[Engine.npcs.length];
- /**
- * All the NPCs stored in distance.
- */
- public byte[] npcsInList = new byte[Engine.npcs.length];
- public int npcListSize = 0;
- /**
- * Rebuild the entire NPC list.
- */
- public boolean rebuildNPCList = false;
- /**
- * An array storing all the players items.
- */
- public int[] items = new int[28];
- public int[] itemsN = new int[28];
- /**
- * Open interfaces, use these to confirm an interface is open when trying to
- * use one.
- */
- public int interfaceId = -1;
- public int chatboxInterfaceId = -1;
- /**
- * The current position in the login stage.
- */
- public int loginStage = 0;
- /**
- * Click x position.
- */
- public int clickX = 0;
- /**
- * Click y position.
- */
- public int clickY = 0;
- /**
- * Click id.
- */
- public int clickId = 0;
- /**
- * True if the player is trying to pickup an item.
- */
- public boolean itemPickup = false;
- /**
- * True if the player is dead.
- */
- public boolean isDead = false;
- /**
- * Set run energy.
- */
- public boolean runEnergyUpdateReq = false;
- /**
- * Amount of current run energy.
- */
- public int runEnergy = 100;
- /**
- * Delay before run energy can increase.
- */
- public int runEnergyDelay = 0;
- /**
- * Clicked the first option on a player.
- */
- public boolean playerOption1 = false;
- /**
- * Clicked the second option on a player.
- */
- public boolean playerOption2 = false;
- /**
- * Clicked the third option on a player.
- */
- public boolean playerOption3 = false;
- /**
- * Clicked the first option on an object.
- */
- public boolean objectOption1 = false;
- /**
- * Setting the players weapon.
- */
- public PlayerWeapon playerWeapon = new PlayerWeapon(this);
- /**
- * Clicked the second option on an object.
- */
- public boolean objectOption2 = false;
- /**
- * Clicked the options on a NPC.
- */
- public boolean npcOption2 = false;
- public boolean npcOption1 = false;
- public boolean npcOption3 = false;
- /**
- * Forced chat.
- */
- public String forceChat = "";
- public boolean forceChatUpdateReq = false;
- /**
- * Stat restore delay.
- */
- public int statRestoreDelay = 75;
- /**
- * Teleporting variables.
- */
- public int teleX = -1;
- public int teleY = -1;
- public int teleDelay = -1;
- public int teleFinishGFX = 0;
- public int teleFinishGFXHeight = 0;
- public int teleFinishAnim = 0;
- /**
- * Special bar data.
- */
- public boolean specialAmountUpdateReq = false;
- public int specialAmountDelay = 0;
- public int specialAmount = 100;
- public boolean SpecialBar = false;
- public boolean usingSpecial = false;
- /**
- * Delay before receiving packets.
- */
- public int clickDelay = -1;
- public int attackDelay = 5;
- public long loginTimeout = System.currentTimeMillis();
- public int attackPlayer = 0;
- public boolean attackingPlayer = false;
- public int combatDelay = 0;
- public int deathDelay = 7;
- public boolean afterDeathUpdateReq = false;
- public int deathMessage = 0;
- /**
- * Arrays holding the items + their amounts of your bank
- */
- public int[] bankItems = new int[Engine.playerBank.SIZE];
- public int[] bankItemsN = new int[Engine.playerBank.SIZE];
- @SuppressWarnings("unused")
- private boolean mouseOptions = false;
- @SuppressWarnings("unused")
- private boolean genderOptions = false;
- @SuppressWarnings("unused")
- private boolean headOptions = false;
- @SuppressWarnings("unused")
- private boolean bodyOptions = false;
- /**
- * Home teleport method.
- */
- public void homeTeleport(int telex, int teley) {
- if (homeTele == 16) {
- requestAnim(1722, 0);
- } else if (homeTele == 15) {
- requestAnim(1723, 0);
- requestGFX(800, 0);
- } else if (homeTele == 14) {
- requestAnim(1724, 0);
- requestGFX(801, 0);
- } else if (homeTele == 13) {
- requestAnim(1725, 0);
- requestGFX(802, 0);
- } else if (homeTele == 12) {
- requestAnim(2798, 0);
- requestGFX(1703, 0);
- } else if (homeTele == 11) {
- requestAnim(2799, 0);
- requestGFX(1704, 0);
- } else if (homeTele == 10) {
- requestAnim(2800, 0);
- requestGFX(1705, 0);
- } else if (homeTele == 9) {
- requestAnim(4847, 0);
- requestGFX(1706, 0);
- } else if (homeTele == 8) {
- requestAnim(4848, 0);
- requestGFX(1707, 0);
- } else if (homeTele == 7) {
- requestAnim(4849, 0);
- requestGFX(1708, 0);
- } else if (homeTele == 6) {
- requestAnim(4849, 0);
- requestGFX(1709, 0);
- } else if (homeTele == 5) {
- requestAnim(4849, 0);
- requestGFX(1710, 0);
- } else if (homeTele == 4) {
- requestAnim(4850, 0);
- requestGFX(1711, 0);
- } else if (homeTele == 3) {
- requestAnim(4851, 0);
- requestGFX(1712, 0);
- } else if (homeTele == 2) {
- requestAnim(4852, 0);
- requestGFX(1713, 0);
- } else if (homeTele == 1) {
- homeTeleDelay = 3600;
- homeTele = 16;
- setCoords(telex, teley, 0);
- normalHomeTele = false;
- ancientsHomeTele = false;
- }
- }
- /**
- * Private messages. Friends Ignores
- */
- public void friendsLoggedIn() {
- for (Long friend : friends) {
- frames.sendFriend(this, friend, getWorld(friend));
- }
- long[] array = new long[ignores.size()];
- int i = 0;
- for (Long ignore : ignores) {
- if (ignore != null)
- array[i++] = ignore;
- }
- frames.sendIgnores(this, array);
- long me = Misc.stringToLong(username);
- for (Player p : Engine.players) {
- if (p == null)
- continue;
- if (p.friends.contains(me)) {
- p.frames.sendFriend(p, me, 66);
- }
- }
- }
- public int getWorld(long friend) {
- for (Player p : Engine.players) {
- if (p != null && p.online) {
- if (Misc.stringToLong(p.username) == friend) {
- return 66;
- }
- }
- }
- return 0;
- }
- /**
- * reqWalkQueue & reqWalkQueueBack method.
- */
- public void reqWalkQueue(int x, int y) {
- int firstX = x - (mapRegionX - 6) * 8;
- int firstY = y - (mapRegionY - 6) * 8;
- Engine.playerMovement.resetWalkingQueue(this);
- Engine.playerMovement.addStepToWalkingQueue(firstX, firstY, this);
- Engine.playerMovement.addStepToWalkingQueue(firstX, firstY + 1, this);
- Engine.playerMovement.addStepToWalkingQueue(firstX, firstY + 2, this);
- }
- public void reqWalkQueueBack(int x, int y) {
- int firstX = x - (mapRegionX - 6) * 8;
- int firstY = y - (mapRegionY - 6) * 8;
- Engine.playerMovement.resetWalkingQueue(this);
- Engine.playerMovement.addStepToWalkingQueue(firstX, firstY, this);
- Engine.playerMovement.addStepToWalkingQueue(firstX, firstY - 1, this);
- Engine.playerMovement.addStepToWalkingQueue(firstX, firstY - 2, this);
- }
- /**
- * Working Flared trousers method.
- */
- public boolean FlaredEquiped() {
- if (equipment[7] == 10394) {
- return true;
- }
- return false;
- }
- /**
- * canAttackPlayer method.
- */
- public boolean canAttackPlayer(Player p) {
- @SuppressWarnings("unused")
- Player p2 = Engine.players[p.attackPlayer];
- if (p == null || p.isDead) {
- return false;
- } else if (p.attackPlayer < 1
- || p.attackPlayer >= Engine.players.length
- || Engine.players[p.attackPlayer] == null) {
- return false;
- }
- if (absX >= 3093 && absY >= 3920 && absX <= 3120 && absY <= 3950) {
- return false;
- }
- return true;
- }
- /**
- * Restore tabs, hide tabs, used for trading fix bug and equipment bonus.
- */
- public void restoreTabs(Player p) {
- for (int b = 16; b <= 21; b++) {
- p.frames.setInterfaceConfig(p, 548, b, false);
- }
- for (int a = 32; a <= 38; a++) {
- p.frames.setInterfaceConfig(p, 548, a, false);
- }
- p.calculateEquipmentBonus();
- p.frames.setInterfaceConfig(p, 548, 14, false);
- p.frames.setInterfaceConfig(p, 548, 31, false);
- p.frames.setInterfaceConfig(p, 548, 63, false);
- p.frames.setInterfaceConfig(p, 548, 72, false);
- }
- public void hideTabs(Player p) {
- for (int b = 16; b <= 21; b++) {
- p.frames.setInterfaceConfig(p, 548, b, true);
- }
- for (int a = 32; a <= 38; a++) {
- p.frames.setInterfaceConfig(p, 548, a, true);
- }
- p.calculateEquipmentBonus();
- p.frames.setInterfaceConfig(p, 548, 14, true);
- p.frames.setInterfaceConfig(p, 548, 31, true);
- p.frames.setInterfaceConfig(p, 548, 63, true);
- p.frames.setInterfaceConfig(p, 548, 72, true);
- }
- public void noMapdata() {
- setCoords(3211, 3422, 0);
- Engine.playerMovement.getNextPlayerMovement(this);
- this.frames.setMapRegion(this);
- this.frames.sendMessage(this,
- "This region of cs508 is not open to the public.\n");
- this.frames.sendMessage(this,
- "You have been teleported back to Varrock.");
- }
- public LinkedList<Integer> getRegion() {
- LinkedList<Integer> regions = new LinkedList<Integer>();
- boolean forceSend = true;
- if ((((mapRegionX / 8) == 48) || ((mapRegionX / 8) == 49))
- && ((mapRegionY / 8) == 48)) {
- forceSend = false;
- }
- if (((mapRegionX / 8) == 48) && ((mapRegionY / 8) == 148)) {
- forceSend = false;
- }
- for (int xCalc = (mapRegionX - 6) / 8; xCalc <= ((mapRegionX + 6) / 8); xCalc++) {
- for (int yCalc = (mapRegionY - 6) / 8; yCalc <= ((mapRegionY + 6) / 8); yCalc++) {
- if (forceSend
- || ((yCalc != 49) && (yCalc != 149) && (yCalc != 147)
- && (xCalc != 50) && ((xCalc != 49) || (yCalc != 47)))) {
- regions.add(yCalc + (xCalc << 1786653352));
- }
- }
- }
- return regions;
- }
- public void appendIPBan() {
- BufferedWriter bw = null;
- @SuppressWarnings("unused")
- Socket socket = null;
- try {
- bw = new BufferedWriter(new FileWriter(
- "./data/banned/bannedhosts.dat", true));
- bw.write(SocketListener.getAddress(this.socket.socket));
- bw.newLine();
- bw.flush();
- } catch (IOException ioe) {
- } finally {
- if (bw != null) {
- try {
- bw.close();
- } catch (IOException ioe2) {
- }
- }
- }
- }
- public void appendBan() {
- BufferedWriter bw = null;
- @SuppressWarnings("unused")
- Socket socket = null;
- try {
- bw = new BufferedWriter(new FileWriter(
- "./data/banned/bannedusers.dat", true));
- bw.write(SocketListener.getAddress(this.socket.socket));
- bw.newLine();
- bw.flush();
- } catch (IOException ioe) {
- } finally {
- if (bw != null) {
- try {
- bw.close();
- } catch (IOException ioe2) {
- }
- }
- }
- }
- public void crossDitch() {
- clickDelay = 5;
- int firstX = 0, firstY = 0;
- if (Engine.wildernessArea(absX, absY)) {
- frames.removeOverlay(this);
- firstX = absX - (mapRegionX - 6) * 8;
- firstY = absY - 3 - (mapRegionY - 6) * 8;
- } else {
- frames.setString(this, "Level: " + getWildernessLevel(), 381, 1);
- frames.setOverlay(this, 381);
- firstX = absX - (mapRegionX - 6) * 8;
- firstY = absY + 3 - (mapRegionY - 6) * 8;
- }
- Engine.playerMovement.resetWalkingQueue(this);
- Engine.playerMovement.addToWalkingQueue(this, firstX, firstY);
- walkEmote = 2750;
- appearanceUpdateReq = true;
- updateReq = true;
- }
- /**
- * Calculates wilderness Levels.
- */
- public int getWildernessLevel() {
- wildLevel = (absY - 3520) / 8 + 1;
- if (wildLevel < 1)
- wildLevel = 1;
- return wildLevel;
- }
- /**
- * Wilderness level
- */
- public int wildLevel;
- /**
- * The wilderness area.
- */
- public boolean wildernessArea(int absX, int absY) {
- @SuppressWarnings("unused")
- Player p2 = Engine.players[enemyIndex];
- if (absX >= 2949 && absX <= 3400 && absY >= 3525 && absY <= 4462) {
- }
- return true;
- }
- public boolean wildy() {
- if ((absX >= 2949 && absX <= 3400 && absY >= 3525 && absY <= 4462))
- return true;
- else
- return false;
- }
- public boolean updateFaceCoords = false;
- public int faceX = -1;
- public int faceY = -1;
- public void faceCoords(int x, int y) {
- faceX = 2 * x + 1;
- faceY = 2 * y + 1;
- updateFaceCoords = true;
- updateReq = true;
- }
- void addWildernessUpdating() {
- frames.setString(this, "Level: " + getWildernessLevel(), 381, 1);
- if (updatedLevel != Engine.wildernessArea(absX, absY)) {
- updatedLevel = Engine.wildernessArea(absX, absY);
- if (updatedLevel) {
- frames.setOverlay(this, 381);
- } else {
- wildyLevel = 0;
- frames.removeOverlay(this);
- }
- }
- }
- public Player(Socket socket, int id) {
- this.socket = new PlayerSocket(this, socket);
- playerId = id;
- look[1] = 10;
- look[2] = 18;
- look[3] = 26;
- look[4] = 33;
- look[5] = 36;
- look[6] = 42;
- for (int i = 0; i < skillLvl.length; i++) {
- skillLvl[i] = 1;
- skillXP[i] = 0;
- skillLvl[3] = 10;
- skillXP[3] = 1154;
- }
- for (int i = 0; i < items.length; i++) {
- items[i] = -1;
- }
- for (int i = 0; i < equipment.length; i++) {
- equipment[i] = -1;
- }
- for (int i = 0; i < bankItems.length; i++) {
- bankItems[i] = -1;
- }
- trade = new Trade(this);
- }
- /**
- * This method is called every 600 milliseconds. While this is good for for
- * changing integers, this should not be abused. Things that can be handled
- * else where should be done in that way, such as clicking the accept button
- * in trade should update in the ActionsButton class rather than requiring
- * an update for the process to handle.
- */
- public void process() {
- if (disconnected[0]) {
- if (trade.getPartner() != null) {
- trade.declineTrade();
- }
- disconnected[1] = true;
- }
- if (Misc.random(20) == 11) {
- Iterator itr = mini.rocks.iterator();
- Iterator itr2 = mini.rNames.iterator();
- while (itr.hasNext() && (itr2.hasNext())) {
- Point nx = (Point) itr.next();
- String s = (String) itr2.next();
- int id = 11554;
- if (s.contains("copper"))
- id = 11960;
- if (s.contains("tin"))
- id = 11959;
- if (s.contains("iron"))
- id = 37307;
- if (s.contains("silver"))
- id = 37306;
- if (s.contains("gold"))
- id = 11185;
- if (s.contains("coal"))
- id = 11930;
- if (s.contains("mith"))
- id = 11942;
- if (s.contains("adam"))
- id = 11939;
- if (s.contains("rune"))
- id = 2107;
- if (s.contains("lime"))
- id = 4029;
- if (s.contains("element"))
- id = 6670;
- frames.createGlobalObject(id, 0, nx.x, nx.y, 0, 10);
- }
- }
- if (combatTimer > 0)
- {
- combatTimer--;
- }
- if (Server.engine.wildernessArea(this.absX, this.absY))
- {
- frames.setPlayerOption(this, "Attack", 1);
- } else
- {
- frames.setPlayerOption(this, "Trade", 2);
- frames.setPlayerOption(this, "Follow", 3);
- }
- if (mini.mining) {
- mini.mineTimer--;
- System.out.println("Mining and the time left till fish for "
- + this.username + " is " + mini.mineTimer + " : Mining : "
- + mini.mining);
- this.requestAnim(mini.mineEmote, 0);
- if (mini.mineTimer == 0) {
- System.out.println("mine");
- mini.mine(this, mini.mineXP, mini.mineGet, mini.mineEmote,
- mini.mineName);
- }
- }
- if (skullDelay > 0) {
- skullDelay--;
- }
- if (prayTimer > 0)
- {
- prayTimer--;
- }
- if (newPlayerTimer > 0)
- {
- newPlayerTimer--;
- }
- if (hasSkull && skullDelay == 0) {
- pkIcon = -1;
- hasSkull = false;
- skullDelay = -1;
- appearanceUpdateReq = true;
- updateReq = true;
- }
- if (fishy.fishing) {
- fishy.fishTimer--;
- System.out.println("Fishing and the time left till fish for "
- + this.username + " is " + fishy.fishTimer);
- if (Misc.random(38) > 35) {
- fishy.resetFishing();
- } else {
- requestAnim(fishy.fishEmote, 0);
- if (fishy.fishTimer == 0) {
- System.out.println("fish");
- fishy.Fish(this, fishy.fishXP, fishy.fishGet,
- fishy.fishEmote, fishy.fishName);
- }
- }
- }
- if (poisonDelay > 0) {
- poisonDelay--;
- }
- if (isPoisoned && poisonDelay == 0) {
- appendHit(Misc.random(6), 1);
- if (posionHit1 == 0) {
- posionHit1 = 4;
- }
- poisonHitCount++;
- poisonDelay = 45;
- }
- if (isPoisoned && poisonHitCount >= 7) {
- isPoisoned = false;
- poisonHitCount = 0;
- frames.sendMessage(this, "After time, the poison has worn off.");
- }
- if (statRestoreDelay > 0) {
- statRestoreDelay--;
- }
- if (drinkDelay > 0) {
- drinkDelay--;
- }
- if (magicDelay > 0) {
- magicDelay--;
- }
- if (homeTeleDelay > 0) {
- homeTeleDelay--;
- }
- if (playerPKDelay > 0)
- {
- playerPKDelay--;
- }
- if (homeTele > 0 && homeTeleDelay <= 0 && normalHomeTele) {
- homeTeleport(3221, 3221);
- homeTele--;
- }
- if (freezeDelay > 0) {
- freezeDelay--;
- stopMovement(this);
- } else if (freezeDelay == 0) {
- }
- if (followingPlayer) {
- Engine.playerFollow.followPlayer(this);
- }
- if (eatDelay > 0) {
- eatDelay--;
- }
- if (flaxTimer > 0) {
- flaxTimer--;
- }
- if (jumpDelay > 0) {
- jumpDelay--;
- jumpUpdateReq = true;
- }
- if (jumpUpdateReq) {
- if (jumpDelay >= 1) {
- runEmote = walkEmote = 2750;
- updateReq = appearanceUpdateReq = true;
- }
- if (jumpDelay <= 0) {
- playerWeapon.setWeapon();
- jumpDelay = 0;
- updateReq = appearanceUpdateReq = true;
- }
- jumpUpdateReq = false;
- }
- if (muteTimer > 0) {
- muteTimer--;
- muted = 2;
- }
- if (clickDelay > 0) {
- clickDelay--;
- }
- if (specialAmountDelay > 0) {
- specialAmountDelay--;
- } else {
- if (specialAmount < 100) {
- specialAmount++;
- specialAmountUpdateReq = true;
- }
- specialAmountDelay = 2;
- }
- if (isDead) {
- attackingPlayer = false;
- deathDelay--;
- applyDead();
- }
- if (combatDelay > 0) {
- combatDelay--;
- }
- if (attackingNPC) {
- Engine.playerNPCCombat.attackNPC(this);
- }
- if (teleDelay > 0) {
- teleDelay--;
- }
- if (runEnergyDelay > 0) {
- runEnergyDelay--;
- } else {
- if (rights >= 2) {
- runEnergy = 100;
- }
- if (runEnergy < 100) {
- runEnergy++;
- runEnergyUpdateReq = true;
- }
- if (runEnergy <= 0) {
- isRunning = false;
- frames.setConfig(this, 173, 0);
- }
- runEnergyDelay = 4;
- }
- if (itemPickup) {
- Engine.packets.pickupItem.handlePacket(this, 0, 0);
- }
- if (playerOption1) {
- Engine.packets.playerOption1.handlePacket(this, 0, 0);
- }
- if (playerOption2) {
- Engine.packets.playerOption2.handlePacket(this, 0, 0);
- }
- if (playerOption3) {
- Engine.packets.playerOption3.handlePacket(this, 0, 0);
- }
- if (npcOption1) {
- Engine.packets.npcOption1.handlePacket(this, 0, 0);
- }
- if (npcOption2) {
- Engine.packets.npcOption2.handlePacket(this, 0, 0);
- }
- if (objectOption1) {
- Engine.packets.objectOption1.handlePacket(this, 0, 0);
- }
- if (objectOption2) {
- Engine.packets.objectOption2.handlePacket(this, 0, 0);
- }
- if (attackingPlayer) {
- Engine.playerCombat.attackPlayer(this);
- }
- if (runEnergyUpdateReq) {
- frames.setEnergy(this);
- runEnergyUpdateReq = false;
- }
- if (specialAmountUpdateReq) {
- checkAmount(this);
- specialAmountUpdateReq = false;
- }
- if (afterDeathUpdateReq) {
- for (int i = 0; i < skillLvl.length; i++) {
- skillLvl[i] = getLevelForXP(i);
- frames.setSkillLvl(this, i);
- }
- Prayer pr = new Prayer();
- pr.resetPrayers(this);
- runEnergy = 100;
- specialAmount = 100;
- deathDelay = 8;
- runEnergyUpdateReq = true;
- specialAmountUpdateReq = true;
- isDead = false;
- afterDeathUpdateReq = false;
- }
- if (statRestoreDelay <= 0) {
- for (int i1 = 0; i1 < skillLvl.length; i1++) {
- int xpLvl = getLevelForXP(i1);
- if (skillLvl[i1] < xpLvl) {
- skillLvl[i1]++;
- frames.setSkillLvl(this, i1);
- } else if (skillLvl[i1] > xpLvl) {
- skillLvl[i1]--;
- frames.setSkillLvl(this, i1);
- }
- }
- statRestoreDelay = 75;
- }
- addWildernessUpdating();
- prayerDrain -= drainRate;
- if (prayerDrain <= 0 && skillLvl[5] > 0) {
- skillLvl[5]--;
- frames.setSkillLvl(this, 5);
- if (skillLvl[5] <= 0) {
- Prayer pr = new Prayer();
- pr.resetPrayers(this);
- frames.sendMessage(this, "You have run out of prayer points.");
- }
- prayerDrain = 100;
- }
- if (teleDelay == 0) {
- teleDelay = -1;
- setCoords(teleX, teleY, heightLevel);
- requestAnim(teleFinishAnim, 0);
- requestGFX(teleFinishGFX, teleFinishGFXHeight);
- teleX = teleY = -1;
- }
- if (clickDelay == 0) {
- clickDelay = -1;
- }
- }
- public void stopMovement(Player p) {
- if (p == null) {
- return;
- }
- if (p.teleportToX == -1 && p.teleportToY == -1) {
- p.teleportToX = p.absX;
- p.teleportToY = p.absY;
- }
- p.walkingQueueX[0] = 0;
- p.walkingQueueY[0] = 0;
- p.walkingQueue[0] = 0;
- }
- public void dropAllItems(Player p) {
- Player p2 = Engine.players[p.attackPlayer];
- if (p2 == null) {
- return;
- }
- for (int i = 0; i < items.length; i++) {
- if (items[i] > 0) {
- if (Engine.items.isUntradable(items[i])) {
- Engine.items.createGroundItem(items[i], itemsN[i], absX,
- absY, heightLevel, username);
- } else {
- Engine.items.createGroundItem(items[i], itemsN[i], absX,
- absY, heightLevel, p2.username);
- }
- items[i] = -1;
- itemsN[i] = 0;
- }
- }
- for (int i = 0; i < equipment.length; i++) {
- if (equipment[i] > 0) {
- if (Engine.items.isUntradable(equipment[i])) {
- Engine.items.createGroundItem(equipment[i], equipmentN[i],
- absX, absY, heightLevel, username);
- } else {
- Engine.items.createGroundItem(equipment[i], equipmentN[i],
- absX, absY, heightLevel, p2.username);
- }
- equipment[i] = -1;
- equipmentN[i] = 0;
- }
- }
- Engine.items.createGroundItem(526, 1, absX, absY, heightLevel,
- p2.username); // drop bones
- deathMessage = Misc.random(8);
- if (deathMessage == 0) {
- p.frames.sendMessage(p2, "With a crushing blow, you defeat "
- + username + ".");
- } else if (deathMessage == 1) {
- p.frames.sendMessage(p2, "It's a humiliating defeat for "
- + username + ".");
- } else if (deathMessage == 2) {
- p.frames.sendMessage(p2, username
- + " didn't stand a chance against you.");
- } else if (deathMessage == 3) {
- p.frames.sendMessage(p2, "You have defeated " + username + ".");
- } else if (deathMessage == 4) {
- p.frames.sendMessage(p2, username
- + " regrets the day they met you in combat.");
- } else if (deathMessage == 5) {
- p.frames.sendMessage(p2, "It's all over for " + username + ".");
- } else if (deathMessage == 6) {
- p.frames.sendMessage(p2, username + " falls before your might.");
- } else if (deathMessage == 7) {
- p.frames.sendMessage(p2, "Can anyone defeat you? Certainly not "
- + username + ".");
- } else if (deathMessage == 8) {
- p.frames.sendMessage(p2, "You were clearly a better fighter than "
- + username + ".");
- }
- frames.setItems(this, 149, 0, 93, items, itemsN);
- frames.setItems(this, 387, 28, 94, equipment, equipmentN);
- playerWeapon.setWeapon();
- calculateEquipmentBonus();
- }
- /**
- * Get XP based on your level.
- *
- * @param skillId
- * The skill level to get the level based off XP for
- * @return Returns the level based on the amount of XP the specified skill
- * has
- */
- public int getLevelForXP(int skillId) {
- int exp = skillXP[skillId];
- int points = 0;
- int output = 0;
- for (int lvl = 1; lvl < 100; lvl++) {
- points += Math.floor((double) lvl + 300.0
- * Math.pow(2.0, (double) lvl / 7.0));
- output = (int) Math.floor(points / 4);
- if ((output - 1) >= exp) {
- return lvl;
- }
- }
- return 99;
- }
- public void applyDead() {
- if (prayerIcon == 3 && deathDelay == 1) {
- for (Player ps : Engine.players) {
- if (ps != null) {
- if (ps.absX < absX + 5 && ps.absY < absY + 5
- && ps.absX > absX - 5 && ps.absY > absY - 5
- && ps.playerId != playerId) {
- ps.requestGFX(437, 0);
- ps.appendHit(5 + Misc.random(15), 0);
- }
- }
- }
- }
- requestAnim(7197, 0);
- if (deathDelay <= 0) {
- dropAllItems(this);
- frames.sendMessage(this, "Oh dear, you have died!");
- if (combatLevel <= 50) {
- frames.showInterface(this, 153);
- }
- isDead = false;
- afterDeathUpdateReq = true;
- attackingPlayer = false;
- requestFaceTo(65535);
- @SuppressWarnings("unused")
- Player en = Engine.players[this.enemyIndex];
- pkIcon = -1;
- teleportToX = 3222 + Misc.random(2);
- teleportToY = 3219 + Misc.random(2);
- pkIcon = -1;
- hasSkull = false;
- skullDelay = -1;
- for (int i = 0; i < skillLvl.length; i++) {
- skillLvl[i] = getLevelForXP(i);
- frames.setSkillLvl(this, i);
- }
- requestAnim(-1, 0);
- updateReq = true;
- appearanceUpdateReq = true;
- faceToUpdateReq = true;
- }
- }
- public boolean[] leveledUp = new boolean[24];
- public int leveledUpSkill = 0;
- public void addSkillXP(double amount, int skill) {
- if (skill > skillXP.length || skill < 0) {
- return;
- }
- int oldLevel = getLevelForXP(skill);
- skillXP[skill] += amount;
- int newLevel = getLevelForXP(skill);
- if (oldLevel < newLevel) {
- if (skill == 3) {
- updateHP(newLevel - oldLevel, true);
- } else {
- skillLvl[skill] += (newLevel - oldLevel);
- }
- frames.setSkillLvl(this, skill);
- @SuppressWarnings("unused")
- LevelUp levelup = new LevelUp(this, skill);
- appearanceUpdateReq = true;
- updateReq = true;
- levelup = null;
- }
- frames.setSkillLvl(this, skill);
- }
- public void calculateEquipmentBonus() {
- for (int i = 0; i < equipmentBonus.length; i++) {
- equipmentBonus[i] = 0;
- }
- for (int i = 0; i < equipment.length; i++) {
- if (equipment[i] > -1) {
- for (int j = 0; j < Engine.items.maxListedItems; j++) {
- if (Engine.items.itemLists[j] != null) {
- if (Engine.items.itemLists[j].itemId == equipment[i]) {
- for (int k = 0; k < equipmentBonus.length; k++) {
- equipmentBonus[k] += Engine.items.itemLists[j].bonuses[k];
- }
- break;
- }
- }
- }
- }
- }
- }
- public void setEquipmentBonus() {
- String[] bonusNames = Misc.bonusNames;
- int id = 35;
- for (int i = 0; i < equipmentBonus.length; i++) {
- frames.setString(this, bonusNames[i] + ": "
- + (equipmentBonus[i] >= 0 ? "+" : "") + equipmentBonus[i],
- 667, id++);
- if (id == 45) {
- id = 47;
- }
- }
- frames.setString(this, "Summoning: +0", 667, 45);
- }
- public void openBank() {
- frames.setConfig2(this, 563, 4194304);
- frames.setConfig2(this, 1248, -2013265920);
- frames.setConfig(this, 115, withdrawNote ? 1 : 0);
- frames.setConfig(this, 305, insertMode ? 1 : 0);
- Engine.playerBank.sendTabConfig(this);
- frames.showInterface(this, 762);
- frames.setInventory(this, 763);
- frames.setBankOptions(this);
- frames.setItems(this, -1, 64207, 95, bankItems, bankItemsN);
- frames.setItems(this, -1, 64209, 93, items, itemsN);
- viewingBankTab = 10;
- frames.setString(this, "" + Engine.playerBank.getFreeBankSlot(this),
- 762, 97);
- frames.setString(this, "" + Engine.playerBank.SIZE, 762, 98);
- }
- public void updateHP(int chHp, boolean heal) {
- if (heal) {
- skillLvl[3] += chHp;
- if (skillLvl[3] > getLevelForXP(3)) {
- skillLvl[3] = getLevelForXP(3);
- }
- } else if (!heal) {
- skillLvl[3] -= chHp;
- if (skillLvl[3] <= 0) {
- skillLvl[3] = 0;
- isDead = true;
- Engine.playerMovement.resetWalkingQueue(this);
- }
- }
- frames.setSkillLvl(this, 3);
- }
- public void updatePRAY(int chPR, boolean pray) {
- if (pray) {
- skillLvl[5] += chPR;
- if (skillLvl[5] > getLevelForXP(5)) {
- skillLvl[5] = getLevelForXP(5);
- }
- }
- frames.setSkillLvl(this, 5);
- }
- /**
- * Teleports a player.
- *
- * @param x
- * The x coordinate to teleport to.
- * @param y
- * The y coordinate to teleport to.
- * @param height
- * The height level to teleport to.
- * @param delay
- * The delay before the teleport is done.
- * @param distance
- * The offset you can teleport to, such as 1 for a max offset of
- * x +/- 1 and y +/- 1.
- * @param emoteStart
- * The emote to do right away.
- * @param emoteEnd
- * The emote to do after teleporting.
- * @param gfxStart
- * The graphic to do right away.
- * @param gfxStartH
- * The height level to create the start graphic at.
- * @param gfxEnd
- * The graphic to do after the teleport is done.
- * @param gfxEndH
- * The finish graphic height.
- */
- public void teleportTo(int x, int y, int height, int delay, int distance,
- int emoteStart, int emoteEnd, int gfxStart, int gfxStartH,
- int gfxEnd, int gfxEndH) {
- itemPickup = false;
- playerOption1 = false;
- playerOption2 = false;
- playerOption3 = false;
- npcOption1 = false;
- npcOption2 = false;
- objectOption1 = false;
- objectOption2 = false;
- attackingPlayer = false;
- clickDelay = delay + 2;
- teleDelay = delay;
- mini.resetMining();
- woody.resetWoodcutting();
- fishy.resetFishing();
- if (distance > 0) {
- int xType = Misc.random(1);
- int yType = Misc.random(1);
- int xOffset = Misc.random(distance);
- int yOffset = Misc.random(distance);
- if (xType == 1)
- x += -xOffset;
- else
- x += xOffset;
- if (yType == 1)
- y += -yOffset;
- else
- y += yOffset;
- }
- teleX = x;
- teleY = y;
- heightLevel = height;
- Engine.playerMovement.resetWalkingQueue(this);
- requestAnim(emoteStart, 0);
- requestGFX(gfxStart, gfxStartH);
- teleFinishGFX = gfxEnd;
- teleFinishGFXHeight = gfxEndH;
- teleFinishAnim = emoteEnd;
- }
- /**
- * Set the player's coordinates.
- *
- * @param x
- * The x coordinate to teleport to.
- * @param y
- * The y coordinate to teleport to.
- */
- public void setCoords(int x, int y, int height) {
- teleportToX = x;
- teleportToY = y;
- heightLevel = height;
- didTeleport = true;
- mini.resetMining();
- woody.resetWoodcutting();
- fishy.resetFishing();
- }
- /**
- * Require an animation for this player.
- *
- * @param animId
- * The animation to perform.
- * @param animD
- * The delay before doing the animation.
- */
- public void requestAnim(int animId, int animD) {
- animReq = animId;
- animDelay = animD;
- animUpdateReq = true;
- updateReq = true;
- }
- /**
- * Require an graphic for this player.
- *
- * @param gfxId
- * The graphic to perform.
- * @param gfxD
- * The delay or height or the GFX depending on the value.
- */
- public void requestGFX(int gfxId, int gfxD) {
- if (gfxD >= 100) {
- gfxD += 6553500;
- }
- gfxReq = gfxId;
- gfxDelay = gfxD;
- gfxUpdateReq = true;
- updateReq = true;
- }
- /**
- * Require this player faces NPC or player.
- *
- * @param faceId
- * The target to face.
- */
- public void requestFaceTo(int faceId) {
- faceToReq = faceId;
- faceToUpdateReq = true;
- updateReq = true;
- }
- /**
- * Append damage.
- */
- public void appendHit(int damage, int posion) {
- boolean useBow = false;
- int wepId = equipment[3];
- if (wepId >= 841 && wepId <= 861 || wepId >= 4212 && wepId <= 4223
- || wepId == 4734 || wepId == 6724 || wepId == 9185) {
- useBow = true;
- }
- if (damage > skillLvl[3]) {
- damage = skillLvl[3];
- }
- updateHP(damage, false);
- if (!hit1UpdateReq) {
- hitDiff1 = damage;
- posionHit1 = posion;
- hit1UpdateReq = true;
- } else {
- hitDiff2 = damage;
- posionHit2 = posion;
- hit2UpdateReq = true;
- }
- updateReq = true;
- }
- /**
- * Force chat text.
- */
- public void requestForceChat(String s) {
- forceChat = s;
- forceChatUpdateReq = true;
- updateReq = true;
- }
- /**
- * Checks special amount and gets configuration.
- */
- public void checkAmount(Player p) {
- int amount = p.specialAmount;
- if (amount == 100) {
- p.frames.setConfig(p, 300, 1000);
- } else if (amount >= 80) {
- p.frames.setConfig(p, 300, 800);
- } else if (amount >= 60) {
- p.frames.setConfig(p, 300, 600);
- } else if (amount >= 50) {
- p.frames.setConfig(p, 300, 500);
- } else if (amount >= 40) {
- p.frames.setConfig(p, 300, 400);
- } else if (amount >= 20) {
- p.frames.setConfig(p, 300, 200);
- } else if (amount >= 0) {
- p.frames.setConfig(p, 300, 0);
- } else {
- // nothing
- }
- }
- /**
- * Prepare player for removal.
- */
- public void destruct() {
- stream = null;
- long me = Misc.stringToLong(username);
- for (Player p : Engine.players) {
- if (p == null)
- continue;
- if (p.friends.contains(me)) {
- p.frames.sendFriend(p, me, 0);
- }
- }
- try {
- socket.input.close();
- socket.output.close();
- socket.socket.close();
- } catch (Exception e) {
- }
- socket.input = null;
- socket.output = null;
- socket.socket = null;
- socket = null;
- absX = absY = mapRegionX = mapRegionY = -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement