Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts.moneymaking.iplankfarmer.equipment;
- import org.tribot.api.General;
- import org.tribot.api.Timing;
- import org.tribot.api2007.Banking;
- import org.tribot.api2007.Camera;
- import org.tribot.api2007.Equipment;
- import org.tribot.api2007.GroundItems;
- import org.tribot.api2007.Inventory;
- import org.tribot.api2007.NPCChat;
- import org.tribot.api2007.Player;
- import org.tribot.api2007.Skills;
- import org.tribot.api2007.Skills.SKILLS;
- import org.tribot.api2007.WebWalking;
- import org.tribot.api2007.types.RSGroundItem;
- import org.tribot.api2007.types.RSItem;
- import org.tribot.api2007.types.RSNPC;
- import scripts.methods.Methods;
- import scripts.moneymaking.iplankfarmer.Script;
- import scripts.moneymaking.iplankfarmer.types.Plank;
- import scripts.moneymaking.iplankfarmer.types.ScriptTask;
- import scripts.moneymaking.iplankfarmer.types.State;
- import scripts.moneymaking.iplankfarmer.utils.Constants;
- import scripts.moneymaking.iplankfarmer.utils.Locations;
- public class Axe {
- private Script script;
- public Axe(Script script) {
- setScript(script);
- switch(getScript().getTask()) {
- case CHOP_LOGS:
- case CHOP_AND_PLANK:
- setAxe();
- break;
- }
- }
- public boolean setAxe() {
- return hasBrokenAxe() || hasBestAxe() || hasOtherAxe();
- }
- public boolean isEquippable() {
- int wcLevel = Skills.getActualLevel(SKILLS.WOODCUTTING);
- int attackLevel = Skills.getActualLevel(SKILLS.ATTACK);
- int wcReq = getScript().getData().getAxeRequirement()[0];
- int attackReq = getScript().getData().getAxeRequirement()[1];
- if(wcLevel >= wcReq) {
- if(attackLevel >= attackReq) {
- return true;
- }
- }
- return false;
- }
- public boolean hasBrokenAxe() {
- int[][] data = Constants.AXE_DATA;
- int broken = Constants.AXE_BROKEN_ID;
- for(int i = 0; i < data.length; i++) {
- int brokenId = data[i][broken];
- if(Equipment.isEquipped(brokenId)) {
- setAxeData(data[i]);
- return true;
- }
- RSItem[] item = Inventory.find(brokenId);
- if(item != null && item.length > 0) {
- setAxeData(data[i]);
- return true;
- }
- }
- return false;
- }
- public boolean hasAxe() {
- if(isAxeBroken()) {
- getScript().setState(State.WALKING_TO_BOB);
- return false;
- }
- RSItem[] axe = Inventory.find(getScript().getData().getAxeId());
- if(!wearing() && (axe == null || axe.length <= 0)) {
- return false;
- }
- return true;
- }
- public boolean wearing() {
- if(isAxeBroken()) {
- getScript().setState(State.WALKING_TO_BOB);
- return false;
- }
- if(Equipment.isEquipped(getScript().getData().getAxeId())) {
- return true;
- }
- return false;
- }
- public void walkToShop() {
- if(Locations.isInsideAxeShop()) {
- getScript().setState(State.REPAIRING_AXE);
- return;
- }
- WebWalking.walkTo(Locations.AXE_SHOP_TILE);
- if(isInAxeShop(3000)) {
- getScript().setState(State.REPAIRING_AXE);
- }
- }
- public boolean isAxeBroken() {
- int brokenId = getScript().getData().getBrokenAxeId();
- if(Equipment.isEquipped(brokenId)) {
- return true;
- }
- RSItem[] i = Inventory.find(brokenId);
- if(i != null && i.length > 0) {
- return true;
- }
- return false;
- }
- public boolean isHeadOnGround() {
- RSGroundItem[] head = GroundItems.find(getScript().getData().getAxeHeadId());
- if(head != null && head.length > 0) {
- return true;
- }
- return false;
- }
- public void pickupHead() {
- RSGroundItem[] head = GroundItems.find(getScript().getData().getAxeHeadId());
- if(head != null && head.length > 0) {
- head[0].click("Take");
- }
- }
- public void attachHead() {
- RSItem[] head = Inventory.find(getScript().getData().getAxeHeadId());
- RSItem[] handle = Inventory.find(Constants.AXE_HANDLE);
- if(head != null && head.length > 0
- && handle != null && handle.length > 0) {
- if(head[0].click("Use")) {
- if(handle[0].click("Use")){
- }
- }
- }
- }
- public void repairAxe() {
- if(Locations.isInsideAxeShop()) {
- RSNPC bob = Methods.findNPCByModelPoints(new int[]{Constants.BOB});
- if(bob != null) {
- if(Inventory.isFull()) {
- switch(getScript().getPlank()) {
- case REGULAR:
- Inventory.drop(Constants.REG_LOGS);
- break;
- case OAK:
- Inventory.drop(Constants.OAK_LOGS);
- break;
- }
- }
- Camera.turnToTile(bob);
- int brokenId = getScript().getData().getBrokenAxeId();
- if(Equipment.isEquipped(brokenId)) {
- Equipment.remove(brokenId);
- }
- RSItem[] i = Inventory.find(brokenId);
- if(i != null && i.length > 0) {
- if(i[0].click("Use")) {
- if(bob.click("Use")) {
- if(bobInterface(1000)) {
- NPCChat.clickContinue(true);
- NPCChat.selectOption("Yes, please.", true);
- if(!isAxeBroken()) {
- int axesRepaired = getScript().getData().getAxesRepaired();
- getScript().getData().setAxesRepaired(axesRepaired + 1);
- getScript().setState(State.WALKING_TO_BANK);
- }
- }
- }
- }
- }
- }
- }
- }
- private int getBestAxeIndex() {
- int miningLevel = Skills.getActualLevel(Skills.SKILLS.WOODCUTTING);
- int[][] axes = Constants.AXE_DATA;
- for(int i = 0; i < axes.length; i++) {
- if(i == axes.length - 1) {
- if(miningLevel >= axes[i][1])
- return i;
- } else if(miningLevel > axes[i][1] && miningLevel >= axes[i + 1][1]) {
- continue;
- } else if(miningLevel >= axes[i][1] && i != axes.length - 1 && miningLevel < axes[i + 1][1]) {
- return i;
- }
- }
- return -1;
- }
- private void equip(RSItem item) {
- getScript().getData().setTimeout(System.currentTimeMillis());
- while(!Equipment.isEquipped(item.getID()) && !getScript().getData().isTimedOut(7000, 8000)) {
- item.click("Wield");
- isWieldingAxe(3000);
- }
- }
- private void withdraw(RSItem item) {
- if(getScript().getBanking().openBankScreen()) {
- getScript().getData().setTimeout(System.currentTimeMillis());
- while(Inventory.getCount(item.getID()) <= 0 && !getScript().getData().isTimedOut(7000, 8000)) {
- item.click("Withdraw-1");
- isAxeWithdrawn(2000);
- }
- Banking.close();
- }
- }
- private void setAxeData(int[] data) {
- getScript().getData().setAxeId(data[Constants.AXE_ID]);
- getScript().getData().setAxeHeadId(data[Constants.AXE_HEAD_ID]);
- getScript().getData().setBrokenAxeId(data[Constants.AXE_BROKEN_ID]);
- getScript().getData().setAxeRequirement(new int[]{
- data[Constants.AXE_WOODCUT_REQ],
- data[Constants.AXE_ATTACK_REQ]});
- }
- private boolean isInInventory(int index) {
- int[] data = Constants.AXE_DATA[index];
- if(Equipment.isEquipped(data[Constants.AXE_ID])) {
- setAxeData(data);
- return true;
- }
- int attackLevelRequired = data[1];
- RSItem[] axe = Inventory.find(data[0]);
- if(axe != null && axe.length > 0) {
- setAxeData(data);
- if(Skills.getActualLevel(Skills.SKILLS.ATTACK) >= attackLevelRequired) {
- if(Banking.isBankScreenOpen()) {
- Banking.close();
- }
- equip(axe[0]);
- }
- return true;
- }
- return false;
- }
- private boolean isInBank(int index) {
- int[] data = Constants.AXE_DATA[index];
- if(Locations.isInsideBank() || Locations.isInsideCastleWars()) {
- if(getScript().getBanking().openBankScreen()) {
- RSItem[] axe = Banking.find(data[0]);
- if(axe != null && axe.length > 0) {
- setAxeData(data);
- final ScriptTask TASK = getScript().getTask();
- final Plank PLANK = getScript().getPlank();
- if(TASK.equals(ScriptTask.CHOP_AND_PLANK)) {
- if(Locations.isInsideBank() && !PLANK.equals(Plank.TEAK) ||
- (Locations.isInsideCastleWars() && PLANK.equals(Plank.TEAK))) {
- withdraw(axe[0]);
- if(Banking.isBankScreenOpen()) {
- Banking.close();
- }
- if(isEquippable()) {
- equip(axe[0]);
- }
- return true;
- }
- }
- }
- }
- }
- return false;
- }
- private boolean isWearing(int index) {
- if(Equipment.isEquipped(Constants.AXE_DATA[index][0])) {
- setAxeData(Constants.AXE_DATA[index]);
- return true;
- }
- return false;
- }
- private boolean hasBestAxe() {
- int index = getBestAxeIndex();
- if(isWearing(index) || isInInventory(index) || isInBank(index)) {
- return true;
- }
- return false;
- }
- private boolean hasOtherAxe() {
- for(int i = getBestAxeIndex(); i >= 0; i--) {
- if(isWearing(i) || isInInventory(i) || isInBank(i)) {
- return true;
- }
- }
- return false;
- }
- private boolean bobInterface(int i) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < i + General.random(100, 200)) {
- if(NPCChat.getClickContinueInterface() != null) {
- return true;
- }
- getScript().sleep(50, 150);
- }
- return false;
- }
- private boolean isInAxeShop(int time) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < time + General.random(100, 200)) {
- if(Locations.isInsideAxeShop()) {
- return true;
- }
- if(!Player.isMoving()) {
- return false;
- }
- getScript().sleep(50, 150);
- }
- return false;
- }
- private boolean isWieldingAxe(int time) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < time + General.random(100, 200)) {
- if(Equipment.isEquipped(getScript().getData().getAxeId())) {
- return true;
- }
- getScript().sleep(50, 150);
- }
- return false;
- }
- private boolean isAxeWithdrawn(int time) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < time + General.random(100, 200)) {
- RSItem[] axe = Inventory.find(getScript().getData().getAxeId());
- if(axe != null && axe.length > 0) {
- return true;
- }
- getScript().sleep(50, 150);
- }
- return false;
- }
- public void setScript(Script script) {
- this.script = script;
- }
- public Script getScript() {
- return script;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment