Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.Button;
- import java.awt.Choice;
- import java.awt.Frame;
- import java.awt.GridLayout;
- import java.awt.Label;
- import java.awt.Panel;
- import java.awt.TextField;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.text.DecimalFormat;
- import java.util.Arrays;
- import java.util.Map;
- import java.util.TreeMap;
- import java.util.Iterator;
- import java.util.Locale;
- import static java.lang.System.currentTimeMillis;
- import javax.swing.BoxLayout;
- import com.aposbot.Constants;
- import com.aposbot.StandardCloseHandler;
- //Made by Abyte0
- //Modified by Justin 4/13/2017
- /* What's Changed:
- - Script doesn't try to pick the chest to teleport if user isn't 72 thief.
- - Eat when your HP becomes < whatever your food heals
- - Fixed issue that's present in s_pickpocket; when you run out of food in bank if food is still in inventory continue until fully out.
- - Added GUI, code snippets from s_pickpocket/s_catherby/s_fighter
- - Loot stuff the paladins you kill drop, if drop is a DSQ & inv is full, eat food then loot.
- - Removed Abyte0_Script dependency & replaced use of parameters using frame code from s_fighter.
- */
- public class Abyte0_Paladin extends Script
- implements ActionListener {
- private final DecimalFormat iformat = new DecimalFormat("#,##0");
- private int[] start_xp = new int[SKILL.length];
- private static final int SKILL_HITS = 3;
- private static final int SKILL_THIEV = 17;
- private static final Map<String, int[]> map_food;
- static {
- map_food = new TreeMap<>();
- map_food.put("Swordfish", new int[] { 370 });
- map_food.put("Lobster", new int[] { 373 });
- map_food.put("Bass", new int[] { 555 });
- map_food.put("Shark", new int[] { 546 });
- map_food.put("Manta ray", new int[] { 1191 });
- map_food.put("Sea turtle", new int[] { 1193 });
- map_food.put("Cake", new int[] { 330, 333, 335 });
- map_food.put("Chocolate cake", new int[] { 332, 334, 336 });
- map_food.put("Meat pizza", new int[] { 326, 328 });
- map_food.put("Anchovy pizza", new int[] { 327, 329 });
- }
- private static final int[] ids_loot = {
- 21,619,170,171,173,72,67,109,10,160,159,158,157,526,527,1277
- };
- private static final int[] ids_bank = {
- 10,21,41,619,170,171,173,72,67,109,10,160,159,158,157,526,527,1277,427,545,160,154
- };
- private int last_combat_x;
- private int last_combat_y;
- private int[] ids_food;
- private int sleep_at;
- private long bank_time;
- private boolean init_path;
- private long move_time;
- private long menu_time;
- private int eat_at;
- private int[] bank_counts = new int[ids_bank.length];
- private boolean[] has_banked = new boolean[ids_bank.length];
- private Frame frame;
- private Choice ch_fm;
- private Choice ch_food;
- private TextField tf_food;
- private TextField tf_eat;
- private TextField tf_sleep;
- private long start_time;
- private int levels_gained;
- private int total_withdraw;
- private int paint_max_y;
- int fightMode = 3;
- boolean chestReady = true;
- boolean canLootChest = true;
- int[] npcID = new int[]
- {
- 323 //Paladin
- };
- public Abyte0_Paladin(Extension e) {super(e);}
- public static void main(String[] argv) {
- Abyte0_Paladin p = new Abyte0_Paladin(null);
- p.init(null);
- }
- public void init(String params)
- {
- for (int i = 0; i < start_xp.length; ++i) {
- start_xp[i] = getXpForLevel(i);
- }
- if(getLevel(SKILL_THIEV)<72) {
- canLootChest = false;
- }
- Arrays.fill(has_banked, false);
- Arrays.fill(bank_counts, 0);
- total_withdraw = 0;
- levels_gained = 0;
- move_time = -1L;
- bank_time = -1L;
- menu_time = -1L;
- start_time = -1L;
- init_path = false;
- if (frame == null) {
- ch_fm = new Choice();
- for (String str : FIGHTMODES) {
- ch_fm.add(str);
- }
- Iterator<String> sit;
- ch_food = new Choice();
- sit = map_food.keySet().iterator();
- while (sit.hasNext()) {
- ch_food.add(sit.next());
- }
- Panel pInput = new Panel(new GridLayout(0, 2, 2, 2));
- pInput.add(new Label("Combat style:"));
- pInput.add(ch_fm);
- pInput.add(new Label("Withdraw food:"));
- pInput.add(ch_food);
- pInput.add(new Label("What does food heal? Lobs: 12, Shark: 20"));
- pInput.add(tf_eat = new TextField("12"));
- pInput.add(new Label("Sleep at fatigue %:"));
- pInput.add(tf_sleep = new TextField("95"));
- ch_food.setEnabled(true);
- Button button;
- Panel pButtons = new Panel();
- button = new Button("OK");
- button.addActionListener(this);
- pButtons.add(button);
- button = new Button("Cancel");
- button.addActionListener(this);
- pButtons.add(button);
- frame = new Frame(getClass().getSimpleName());
- frame.setLayout(new BoxLayout(frame, BoxLayout.Y_AXIS));
- frame.addWindowListener(
- new StandardCloseHandler(frame, StandardCloseHandler.HIDE)
- );
- frame.setIconImages(Constants.ICONS);
- frame.add(pInput, BorderLayout.NORTH);
- frame.add(new Label(
- "Start this script in east bank or 2nd floor ardy castle.",
- Label.CENTER
- ), BorderLayout.SOUTH);
- frame.add(pButtons, BorderLayout.SOUTH);
- frame.setResizable(false);
- frame.pack();
- }
- frame.setLocationRelativeTo(null);
- frame.toFront();
- frame.requestFocus();
- frame.setVisible(true);
- }
- public int main()
- {
- if (start_time == -1L) {
- start_time = System.currentTimeMillis();
- }
- int ideal_fm = ch_fm.getSelectedIndex();
- if (getFightMode() != ideal_fm) {
- setFightMode(ideal_fm);
- return random(400, 600);
- }
- if(inCombat())
- {
- last_combat_x = getX();
- last_combat_y = getY();
- walkTo(getX(), getY());
- return random(400, 600);
- }
- //Current HP is less than max heal of your food
- if (getCurrentLevel(SKILL_HITS) <= eat_at) {
- int slot = getFoodSlot();
- if (slot != -1) {
- useItem(slot);
- return random(800, 1000);
- }
- }
- if (getFatigue() >= sleep_at) {
- useSleepingBag();
- return random(2000, 3000);
- }
- if (move_time != -1L && System.currentTimeMillis() >= move_time) {
- System.out.println("Moving for 5 min timer");
- walk_approx(getX(), getY(), 1);
- move_time = -1L;
- return random(1500, 2500);
- }
- if (isQuestMenu()) {
- answer(0);
- menu_time = -1L;
- bank_time = System.currentTimeMillis();
- return random(600, 800);
- } else if (menu_time != -1L) {
- if (System.currentTimeMillis() >= (menu_time + 8000L)) {
- menu_time = -1L;
- }
- return random(300, 400);
- }
- if(isBanking()) {
- bank_time = -1L;
- int array_sz = ids_bank.length;
- for (int i = 0; i < array_sz; ++i) {
- int count = getInventoryCount(ids_bank[i]);
- if (count > 0) {
- deposit(ids_bank[i], count);
- if (!has_banked[i]) {
- bank_counts[i] += count;
- has_banked[i] = true;
- }
- return random(1000, 2000);
- }
- }
- //Take out max food
- int food_count = getInventoryCount(ids_food);
- if (food_count < 28 - getInventoryCount()) {
- for (int id : ids_food) {
- int bank_count = bankCount(id);
- if (bank_count <= 0) continue;
- int w = 28 - getInventoryCount() - food_count;
- if (w > bank_count) w = bank_count;
- total_withdraw += w;
- withdraw(id, w);
- return random(1000, 2000);
- }
- // should not log out if there is still food in inventory
- if (getInventoryCount(ids_food) <= 0) {
- System.out.println("ERROR: Out of food!");
- stopScript(); setAutoLogin(false);
- return 0;
- }
- }
- Arrays.fill(has_banked, false);
- closeBank();
- return random(500, 600);
- } else if (bank_time != -1L) {
- if (System.currentTimeMillis() >= (bank_time + 8000L)) {
- bank_time = -1L;
- }
- return random(300, 400);
- }
- //Loot stuffs
- int[] item = getItemById(ids_loot);
- if ((item[1] == getX() && item[2] == getY()) ||
- (item[1] == last_combat_x && item[2] == last_combat_y)) {
- if (getInventoryCount() < MAX_INV_SIZE ||
- (getInventoryIndex(item[0]) != -1 &&
- isItemStackableId(item[0]))) {
- pickupItem(item[0], item[1], item[2]);
- return random(600, 1000);
- }
- if (item[0] == 1127) {
- int slot = getFoodSlot();
- if (slot != -1) {
- useItem(slot);
- return random(800, 1000);
- }
- }
- }
- if(getInventoryCount(ids_food) > 0) {
- if(getHpPercent() < 30)
- {
- System.out.println("hp is dangerously low with no food.");
- setAutoLogin(false);
- stopScript();
- return 0;
- }
- //are we near paladins
- if(getX() >= 602 && getX() <= 615 && getY() >= 1548)
- {
- int[] npc = getNpcById(npcID);
- if(npc[0] != -1)
- {
- thieveNpc(npc[0]);
- chestReady = true;
- return random(500, 1000);
- }
- }
- else
- {
- int[] doorObj;
- int[] stairs;
- if(getX() == 551 && getY() == 612)
- {
- stairs = getObjectById(64);
- if(stairs[0] != -1)
- {
- atObject(stairs[1], stairs[2]);
- return random(1000,1200);
- }
- walkTo(550,612);
- return random(600,800);
- }
- //behind steps to climb
- if(getX() == 613 && getY() == 601)
- {
- stairs = getObjectById(342);
- if(stairs[0] != -1)
- {
- atObject(stairs[1], stairs[2]);
- return random(1500,3200);
- }
- }
- //in bank
- if(getX() >= 551 && getX() <= 554 && getY() >= 609 && getY() <= 616)
- {
- walkTo(551,612);
- return random(600,800);
- }
- if(getX() >= 608 && getY() >= 597 && getY() <= 609)
- {
- walkTo(613,601);
- return random(400,1300);
- }
- //Top of steps
- if(getX() >= 602 && getX() <= 615 && getY() > 1500 && getY() < 1548)
- {
- int[] door = getWallObjectById(97);
- if(door[0] != -1 && isAtApproxCoords(door[1], door[2],5))
- {
- atWallObject2(door[1], door[2]);
- return random(1000, 1500);
- }
- }
- //On way to zoo
- if(getX() < 567)
- {
- walkTo(567,606);
- return random(500,1000);
- }
- //general store
- if(getX() < 580)
- {
- walkTo(580,606);
- return random(500,1000);
- }
- //to door
- if(getX() < 598)
- {
- walkTo(598,604);
- return random(500,1000);
- }
- if(getX() < 599)
- {
- //Passing the Metal Gate
- stairs = getObjectById(57);
- if(stairs[0] != -1 && isAtApproxCoords(stairs[1], stairs[2],10))
- {
- atObject(stairs[1], stairs[2]);
- return random(800,1000);
- }
- walkTo(599,604);
- return random(500,1000);
- }
- if(getX() < 608)
- {
- //Passing the Wooden Door
- stairs = getObjectById(64);
- if(stairs[0] != -1)
- {
- if(stairs[1] >= 605 && stairs[1] <= 610 && stairs[2] >= 600 && stairs[2] <= 608)
- {
- atObject(stairs[1], stairs[2]);
- return random(800,1000);
- }
- }
- walkTo(608,604);
- return random(500,1000);
- }
- }
- return 500;
- }
- else
- {
- int[] doorObj;
- int[] stairs;
- if(getX() >= 602 && getX() <= 615 && getY() >= 1548 && getY() <= 1648)
- {
- //If the chest is ready we go up and teleport
- if(chestReady && canLootChest)
- {
- stairs = getObjectById(5);
- if(stairs[0] != -1 && isAtApproxCoords(stairs[1], stairs[2],10))
- {
- atObject(stairs[1], stairs[2]);
- return random(1500,3200);
- }
- }
- else
- {
- doorObj = getWallObjectById(97);
- if(doorObj[0] != -1 && isAtApproxCoords(doorObj[1], doorObj[2],10))
- {
- atWallObject(doorObj[1], doorObj[2]);
- return random(1000,1200);
- }
- }
- return random(800,900);
- }
- //bank walk
- if(getX() == 550)
- {
- stairs = getObjectById(64);
- if(stairs[0] != -1 && isAtApproxCoords(stairs[1], stairs[2],5))
- {
- atObject(stairs[1], stairs[2]);
- return random(1000,1200);
- }
- walkTo(551,612);
- return random(600,800);
- }
- //in the bank
- if(getX() >= 551 && getX() <= 554 && getY() >= 609 && getY() <= 616)
- {
- int banker[] = getNpcByIdNotTalk(BANKERS);
- if(banker[0] != -1)
- {
- talkToNpc(banker[0]);
- return 1000;
- }
- }
- //-----
- //Walking To Bank Manualy
- //-----
- //We at chest
- if(isAtApproxCoords(611,2491,10))
- {
- int[] groundItem = getItemById(427);
- if(groundItem[0] != -1)
- {
- pickupItem(groundItem[0], groundItem[1], groundItem[2]);
- return random(1000, 1500);
- }
- //chest isn't ready for us
- if(getObjectIdFromCoords(610,2487) != 338)
- {
- chestReady = false;
- stairs = getObjectById(6);
- if(stairs[0] != -1)
- {
- atObject(stairs[1], stairs[2]);
- return random(1000,1200);
- }
- }
- else
- {
- System.out.println("loot the chest PLZ");
- atObject2(610,2487);
- return random(2000,3000);
- }
- }
- //Down the stairs we go
- if(getX() >= 602 && getX() <= 615 && getY() > 1500 && getY() < 1548)
- {
- stairs = getObjectById(44);
- if(stairs[0] != -1)
- {
- atObject(stairs[1], stairs[2]);
- return random(1000,1200);
- }
- }
- //Near stairs, exit castle
- if(getX() >= 608 && getY() >= 597 && getY() <= 609)
- {
- //Passing the Wooden Door
- stairs = getObjectById(64);
- if(stairs[0] != -1 && isAtApproxCoords(stairs[1], stairs[2],5))
- {
- atObject(stairs[1], stairs[2]);
- return random(800,1000);
- }
- walkTo(607,604);
- return random(500,1000);
- }
- //Near warriors
- if(getX() >= 599)
- {
- //Passing the Metal Gate
- stairs = getObjectById(57);
- if(stairs[0] != -1 && isAtApproxCoords(stairs[1], stairs[2],10))
- {
- atObject(stairs[1], stairs[2]);
- return random(800,1000);
- }
- walkTo(598,604);
- return random(500,1000);
- }
- //just keep walking
- if(getX() >= 585)
- {
- walkTo(584,606);
- return random(500,1000);
- }
- //see animals
- if(getX() >= 570)
- {
- walkTo(569,606);
- return random(500,1000);
- }
- //more animals
- if(getX() >= 551)
- {
- walkTo(550,608);
- return random(500,1000);
- }
- //-----
- //----- Walking to Bank By Teleport
- //-----
- //Si on est proche du Teleport
- if(isAtApproxCoords(523,606,5))
- {
- walkTo(528,615);
- return random(500,1000);
- }
- //Chickens spotted
- if(getX() <= 542)
- {
- walkTo(543,615);
- return random(500,1000);
- }
- //Boat spotted almost there.
- if(getX() <= 549)
- {
- walkTo(550,612);
- return random(500,1000);
- }
- return 500;
- }
- }
- private void walk_approx(int x, int y, int range) {
- int dx, dy;
- int loop = 0;
- do {
- dx = x + random(-range, range);
- dy = y + random(-range, range);
- if ((++loop) > 1000) return;
- } while ((dx == getX() && dy == getY()) ||
- !isReachable(dx, dy));
- walkTo(dx, dy);
- }
- @Override
- public void paint() {
- if (start_time == -1L) {
- return;
- }
- final int orangey = 0xFFD900;
- final int white = 0xFFFFFF;
- int x = (512 / 2) - 50;
- int y = 60;
- drawBoxAlphaFill(x - 8, y - 18, 300, paint_max_y - y, 120, 0x0);
- drawString("Abyte0 Paladin (Updated by Justin)", x, y, 1, orangey);
- y += 15;
- drawString("Runtime: " + get_time_since(start_time),
- x + 10, y, 1, white);
- y += 15;
- drawString(String.format("Current Level: %d (Gained: %d) ",getLevel(SKILL_THIEV),
- levels_gained),
- x, y, 1, orangey);
- y += 15;
- if (total_withdraw != 0) {
- drawString(String.format("%s food withdrawn",
- iformat.format(total_withdraw)),
- x + 10, y, 1, white);
- y += 15;
- }
- drawString("XP Gained:", x, y, 1, orangey);
- y += 15;
- for (int i = 0; i < start_xp.length; ++i) {
- int gained = getXpForLevel(i) - start_xp[i];
- if (gained == 0) continue;
- drawString(String.format("%s XP gained: %s (%s/h)",
- SKILL[i], iformat.format(gained), per_hour(gained)),
- x, y, 2, 0xFFFFFF);
- y += 15;
- }
- drawString("Items Banked:", x, y, 1, orangey);
- y += 15;
- for (int i = 0; i < ids_bank.length; ++i) {
- if (bank_counts[i] == 0) continue;
- drawString(String.format("%s banked: %s (%s/h)",
- getItemNameId(ids_bank[i]),
- iformat.format(bank_counts[i]),
- per_hour(bank_counts[i])),
- x, y, 2, 0xFFFFFF);
- y += 15;
- }
- paint_max_y = y + 15;
- }
- private String per_hour(int count) {
- double amount, secs;
- if (count == 0) return "0";
- amount = count * 60.0 * 60.0;
- secs = (currentTimeMillis() - start_time) / 1000.0;
- return iformat.format(amount / secs);
- }
- private static String get_time_since(long t) {
- long millis = (System.currentTimeMillis() - t) / 1000;
- long second = millis % 60;
- long minute = (millis / 60) % 60;
- long hour = (millis / (60 * 60)) % 24;
- long day = (millis / (60 * 60 * 24));
- if (day > 0L) {
- return String.format("%02d days, %02d hrs, %02d mins",
- day, hour, minute);
- }
- if (hour > 0L) {
- return String.format("%02d hours, %02d mins, %02d secs",
- hour, minute, second);
- }
- if (minute > 0L) {
- return String.format("%02d minutes, %02d seconds",
- minute, second);
- }
- return String.format("%02d seconds", second);
- }
- @Override
- public void onServerMessage(String str) {
- str = str.toLowerCase(Locale.ENGLISH);
- if (str.contains("standing here")) {
- move_time = (System.currentTimeMillis() + random(1500, 1800));
- } else if (str.contains("busy")) {
- menu_time = -1L;
- } else if (str.contains("advanced")) {
- System.out.println("You just advanced a level.");
- System.out.print("Runtime: ");
- System.out.println(get_time_since(start_time));
- ++levels_gained;
- }
- }
- private int getFoodSlot() {
- int count = getInventoryCount();
- for (int i = 0; i < count; i++) {
- if (getItemCommand(i).toLowerCase(Locale.ENGLISH).equals("eat")) {
- return i;
- }
- }
- return -1;
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- if (e.getActionCommand().equals("OK")) {
- eat_at = getLevel(SKILL_HITS) - Integer.parseInt(tf_eat.getText());
- sleep_at = Integer.parseInt(tf_sleep.getText());
- ids_food = map_food.get(ch_food.getSelectedItem());
- }
- frame.setVisible(false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement