Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.trent;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.text.DecimalFormat;
- import org.osbot.script.Script;
- import org.osbot.script.ScriptManifest;
- import org.osbot.script.rs2.map.Position;
- import org.osbot.script.rs2.model.RS2Object;
- import org.osbot.script.rs2.skill.Skill;
- import org.osbot.script.rs2.ui.EquipmentSlot;
- @ScriptManifest(name = "TokenShielder", author = "Titan", version = 1.0, info = "Does the defensive style token collection in the Warriors Guild.")
- public class TokenShielder extends Script {
- long startTime;
- int startXp;
- int tokensGained;
- ProtectionType oldType = ProtectionType.SLASH;
- ProtectionType protType = ProtectionType.SLASH;
- Position target = new Position(2842, 3545, 1);
- enum ProtectionType {
- SLASH, MAGIC, STAB, BLUNT
- }
- @Override
- public void onStart() {
- startTime = System.currentTimeMillis();
- startXp = client.getSkills().getExperience(Skill.DEFENCE);
- }
- @Override
- public int onLoop() throws InterruptedException {
- if (!myPlayer().getPosition().equals(target)) {
- target.walkHere(bot);
- } else if (myPlayer().getPosition().equals(target) && !equipmentTab.isWearingItem(EquipmentSlot.SHIELD, 8856)) {
- if (client.getInventory().contains(8856)) {
- client.getInventory().interactWithId(8856, "Wield");
- } else {
- log("Stopping script. Does not have a shield.");
- stop();
- }
- } else {
- updateType();
- if (typeChanged()) {
- sleep(600);
- clickType();
- }
- }
- return random(200, 400);
- }
- public void updateType() throws InterruptedException {
- RS2Object magic = closestObject(6808);
- RS2Object slash = closestObject(6810);
- RS2Object blunt = closestObject(6809);
- RS2Object stab = closestObject(5554);
- if (magic != null && magic.getPosition().getX() == 2840 && magic.getPosition().getY() == 3552) {
- protType = ProtectionType.MAGIC;
- } else if (slash != null && slash.getPosition().getX() == 2840 && slash.getPosition().getY() == 3552) {
- protType = ProtectionType.SLASH;
- } else if (blunt != null && blunt.getPosition().getX() == 2840 && blunt.getPosition().getY() == 3552) {
- protType = ProtectionType.BLUNT;
- } else if (stab != null && stab.getPosition().getX() == 2840 && stab.getPosition().getY() == 3552) {
- protType = ProtectionType.STAB;
- }
- }
- public boolean typeChanged() throws InterruptedException {
- return oldType != protType;
- }
- public void clickType() throws InterruptedException {
- oldType = protType;
- if (client.getInterface(411) != null) {
- switch(protType) {
- case MAGIC:
- client.getInterface(411).getChild(4).interact();
- break;
- case BLUNT:
- client.getInterface(411).getChild(2).interact();
- break;
- case SLASH:
- client.getInterface(411).getChild(3).interact();
- break;
- case STAB:
- client.getInterface(411).getChild(1).interact();
- break;
- }
- }
- }
- @Override
- public void onMessage(String message) throws InterruptedException {
- if (message.contains("successfully"))
- tokensGained++;
- }
- @Override
- public void onPaint(Graphics g) {
- g.setFont(new Font("Arial", Font.PLAIN, 12));
- g.setColor(new Color(0, 0, 0, 150));
- g.fillRect(6, 260, 200, 75);
- g.setColor(Color.BLACK);
- g.drawRect(6, 260, 200, 75);
- g.setColor(Color.GREEN);
- g.drawString("TokenShielder By Titan", 8, 280);
- int xpGained = client.getSkills().getExperience(Skill.DEFENCE) - startXp;
- g.drawString("XP P/H: " + perHour(xpGained), 8, 290);
- g.drawString("XP Gained: " + xpGained, 8, 300);
- g.drawString("Tokens Gained: " + tokensGained, 8, 310);
- g.drawString("Tokens P/H: " + perHour(tokensGained), 8, 320);
- g.drawString("Protection Type: " + protType.name(), 8, 330);
- }
- public String perHour(int gained) {
- return formatNumber((int) ((gained) * 3600000D / (System.currentTimeMillis() - startTime)));
- }
- public String formatNumber(int start) {
- DecimalFormat nf = new DecimalFormat("0.0");
- double i = start;
- if (i >= 1000000) {
- return nf.format((i / 1000000)) + "m";
- }
- if (i >= 1000) {
- return nf.format((i / 1000)) + "k";
- }
- return "" + start;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment