Skip to content

Instantly share code, notes, and snippets.

@MatoV
Last active Apr 3, 2021
Embed
What would you like to do?
package toma.giantslayer;
import org.powerbot.script.*;
import org.powerbot.script.rt4.*;
import org.powerbot.script.rt4.ClientContext;
import toma.giantslayer.utility.GUI;
import toma.giantslayer.utility.MessageClearer;
import toma.giantslayer.tasks.*;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
@Script.Manifest(
name = "GiantSlayer",
description = "Slays Hill Giants",
version = "1.0.0"
)
public class GiantSlayer extends PollingScript<ClientContext> implements PaintListener {
public boolean startScript = false;
public String foodName = "Tuna";
public int foodAmount = 5;
public int eatAtHealth = 15;
public int ammoId = 888;
public String targetName = "Hill Giant";
public Area giantsArea;
public boolean buryBones = true;
public int minItemPrice = 400;
// Tasks
public List<Task> taskList = new ArrayList<Task>();
// Vars for paint
public long sAttackXp, sStrengthXp, sDefenceXp, sHitpointsXp, sRangeXp, sMagicXp;
public long cAttackXp, cStrengthXp, cDefenceXp, cHitpointsXp, cRangeXp, cMagicXp;
private Thread cThread;
private MessageClearer messageClearer;
@Override
public void start() {
messageClearer = new MessageClearer(ctx);
// Init and start message clearer thread
cThread = new Thread(messageClearer, "MessageCleaner");
cThread.start();
// Start the GUI
SwingUtilities.invokeLater((() -> {
GUI gui = new GUI(ctx, this );
}));
// Initialize starting xp
sAttackXp = ctx.skills.experience(Constants.SKILLS_ATTACK);
sStrengthXp = ctx.skills.experience(Constants.SKILLS_STRENGTH);
sDefenceXp = ctx.skills.experience(Constants.SKILLS_DEFENSE);
sHitpointsXp = ctx.skills.experience(Constants.SKILLS_HITPOINTS);
sRangeXp = ctx.skills.experience(Constants.SKILLS_RANGE);
sMagicXp = ctx.skills.experience(Constants.SKILLS_MAGIC);
}
@Override
public void poll() {
if (startScript) {
for (Task t : taskList) {
if (t.activate()) {
t.execute();
break;
}
}
}
}
private final Font helveticaFont = new Font("Helvetica", 0, 12);
@Override
public void repaint(Graphics g) {
// Update xp gain
cAttackXp = ctx.skills.experience(Constants.SKILLS_ATTACK);
cStrengthXp = ctx.skills.experience(Constants.SKILLS_STRENGTH);
cDefenceXp = ctx.skills.experience(Constants.SKILLS_DEFENSE);
cRangeXp = ctx.skills.experience(Constants.SKILLS_RANGE);
cHitpointsXp = ctx.skills.experience(Constants.SKILLS_HITPOINTS);
cMagicXp = ctx.skills.experience(Constants.SKILLS_MAGIC);
long combatXpGained = (cAttackXp - sAttackXp) + (cStrengthXp - sStrengthXp) + (cDefenceXp - sDefenceXp)
+ (cRangeXp - sRangeXp) + (cHitpointsXp - sHitpointsXp) + (cMagicXp - sMagicXp);
// Paint window
g.setColor(new Color(0, 0, 0,255));
g.drawRect(5,5,250,100);
g.setColor(new Color(33, 33, 33, 230));
g.fillRect(5,5,250,100);
g.setFont(helveticaFont);
//Text
g.setColor(new Color(172, 172, 172,255));
g.drawString("Combat exp. gained: " + combatXpGained + " (" + getPerHour(combatXpGained, this.getRuntime()) +"/pH)", 8, 25);
g.drawString("Time running: " + formatTime((int)this.getRuntime()/1000), 8, 60);
g.setColor(new Color(0, 73, 239, 79));
}
private String formatTime(long time) {
return String.format("%d:%02d:%02d", time / 3600, (time % 3600) / 60, (time % 60));
}
private long getPerHour(long in, long time) {
return (int) ((in) * 3600000D / time);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment