-
-
Save Roflme/60f59b4d9a439a0a3cd2a84bdaf832da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.BorderLayout; | |
import java.awt.Color; | |
import java.awt.Dimension; | |
import java.awt.FlowLayout; | |
import java.awt.Font; | |
import java.awt.Graphics; | |
import java.awt.GridLayout; | |
import java.awt.Point; | |
import java.awt.Rectangle; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import javax.swing.JButton; | |
import javax.swing.JCheckBox; | |
import javax.swing.JComboBox; | |
import javax.swing.JFrame; | |
import javax.swing.JLabel; | |
import javax.swing.JPanel; | |
import org.dreambot.dinh.framework.price.PriceCheck; | |
import org.dreambot.dinh.framework.price.PriceType; | |
import org.dreambot.api.utilities.Timer; | |
import org.dreambot.api.methods.Calculations; | |
import org.dreambot.api.script.AbstractScript; | |
import org.dreambot.api.script.ScriptManifest; | |
import org.dreambot.api.script.Category; | |
import org.dreambot.api.wrappers.interactive.GameObject; | |
import org.dreambot.api.methods.map.Area; | |
import org.dreambot.api.methods.skills.Skill; | |
@ScriptManifest(author = "Roflme", name = "RoflmeOakR", version = 0.7, description = "Cuts+Banks Oaks anywhere around Port Sarim", category = Category.WOODCUTTING) | |
public class Main extends AbstractScript { | |
private Area treeArea; | |
private Area bankArea = getBank().getClosestBankLocation().getArea(8); | |
private Point p; | |
private Rectangle b; | |
private PriceCheck PriceCheck; | |
private String logType; | |
private boolean dropMode; | |
private boolean isRunning; | |
private int IDLog; | |
private int XPLog; | |
private long GP; | |
private long logCut = 0; | |
private long XP; | |
private Timer timer; | |
GameObject Oak; | |
GameObject Deposit; | |
@Override | |
public void onStart() { | |
createGUI(); | |
getSkillTracker().start(Skill.WOODCUTTING, true); | |
timer = new Timer(); | |
treeArea = Area.generateArea(20, getLocalPlayer().getTile()); | |
} | |
@Override | |
public void onPaint(Graphics g) { | |
g.setColor(Color.RED); | |
g.setFont(new Font("Arial", Font.BOLD, 15)); | |
g.drawString("Time Running: " + timer.formatTime(), 10, 20); | |
g.drawString( | |
"Logs Cut: " + logCut + " (" | |
+ (timer.getHourlyRate(Math.toIntExact(logCut))) + ")", | |
10, 40); | |
g.drawString( | |
"XP Gained: " + XP + " (" | |
+ (timer.getHourlyRate(Math.toIntExact(XP))) + ")", 10, | |
60); | |
g.drawString( | |
"GP earned: " + GP + " (" | |
+ (timer.getHourlyRate(Math.toIntExact(GP))), 10, 80); | |
} | |
private enum State { | |
CHOP, BANK, WAIT, RETURN | |
}; | |
private State getState() { | |
if (getInventory().isFull()) | |
return State.BANK; | |
else if (!treeArea.contains(getLocalPlayer().getTile())) | |
return State.RETURN; | |
else if (!getLocalPlayer().isAnimating()) | |
return State.CHOP; | |
else | |
return State.WAIT; | |
} | |
public void onExit() { | |
} | |
@Override | |
public int onLoop() { | |
if (isRunning) { | |
XP = getSkillTracker().getGainedExperience(Skill.WOODCUTTING); | |
logCut = Math.round(XP / XPLog); | |
GP = PriceCheck.getPrice(IDLog); | |
if (getDialogues().canContinue()) | |
getDialogues().spaceToContinue(); | |
switch (getState()) { | |
case CHOP: | |
while (getLocalPlayer().isMoving()) | |
sleep(Calculations.random(300, 400)); | |
sleep(Calculations.random(700, 1100)); | |
if (getSkills().getRealLevel(Skill.WOODCUTTING) < 15) { | |
Oak = getGameObjects().closest("Tree"); | |
} else { | |
Oak = getGameObjects().closest("Oak"); | |
} | |
if (Oak != null && !getLocalPlayer().isAnimating()) | |
if (Oak.getTile().distance(getLocalPlayer().getTile()) > 6) | |
getWalking().walk( | |
Oak.getSurroundingArea(2).getRandomTile()); | |
if (!Oak.isOnScreen()) | |
getCamera().mouseRotateToTile(Oak.getTile()); | |
if (Oak.interact("Chop down")) | |
sleep(Calculations.random(2000, 2500)); | |
break; | |
case BANK: | |
if (bankArea.contains(getLocalPlayer().getTile())) { | |
if (getDepositBox().isOpen()) { | |
for (int i = 2; i <= 28; i++) { | |
if (getInventory().isSlotFull(i)) { | |
getBank().depositAll( | |
getInventory().getNameForSlot(i)); | |
} | |
} | |
} else { | |
Deposit = getGameObjects().closest("Bank deposit box"); | |
if (Deposit.interact("Deposit")) | |
sleep(Calculations.random(300, 500)); | |
} | |
} else { | |
getWalking().walk(bankArea.getRandomTile()); | |
} | |
sleep(Calculations.random(500, 1800)); | |
break; | |
case RETURN: | |
getWalking().walk(treeArea.getRandomTile()); | |
int returnrand = (Calculations.random(1, 100)); | |
if (returnrand <= 98) { | |
sleep(Calculations.random(1500, 1800)); | |
} else { | |
int yaw = (getCamera().getYaw()); | |
if (yaw <= 1200) { | |
getCamera().mouseRotateToYaw( | |
getCamera().getYaw() | |
+ Calculations.random(300, 800)); | |
} else { | |
getCamera().mouseRotateToYaw( | |
getCamera().getYaw() | |
- Calculations.random(300, 800)); | |
} | |
} | |
case WAIT: | |
p = getLocalPlayer().getCenterPoint().getLocation(); | |
b = getGameObjects().closest("Oak").getBoundingBox(); | |
if (p != null && b != null && b.contains(p)) { | |
int yaw = (getCamera().getYaw()); | |
if (yaw <= 1200) { | |
getCamera().mouseRotateToYaw( | |
getCamera().getYaw() | |
+ Calculations.random(300, 800)); | |
} else { | |
getCamera().mouseRotateToYaw( | |
getCamera().getYaw() | |
- Calculations.random(300, 800)); | |
} | |
} | |
if (getCamera().getPitch() < 300) | |
getCamera().mouseRotateToPitch( | |
Calculations.random(300, 380)); | |
if (getMouse().isMouseInScreen()) | |
getMouse().moveMouseOutsideScreen(); | |
sleep(Calculations.random(3000, 5000)); | |
break; | |
} | |
} | |
return Calculations.random(420, 666); | |
} | |
private void createGUI() { | |
JFrame frame = new JFrame(); | |
frame.setTitle(""); | |
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); | |
frame.setLocationRelativeTo(getClient().getInstance().getCanvas()); | |
frame.setPreferredSize(new Dimension(300, 170)); | |
frame.getContentPane().setLayout(new BorderLayout()); | |
JPanel settingPanel = new JPanel(); | |
settingPanel.setLayout(new GridLayout(0, 1)); | |
JLabel label = new JLabel(); | |
label.setText("Log Type:"); | |
settingPanel.add(label); | |
final JComboBox<String> treeTypeBox = new JComboBox<>(new String[] { | |
"Trees", "Oaks", "Willows", "Maples", "Yews", "Magics", | |
"Teaks", "Mahogany" }); | |
settingPanel.add(treeTypeBox); | |
final JCheckBox powerChopBox = new JCheckBox(); | |
powerChopBox.setText("Powerchop?"); | |
settingPanel.add(powerChopBox); | |
frame.getContentPane().add(settingPanel, BorderLayout.CENTER); | |
JPanel buttonPanel = new JPanel(); | |
buttonPanel.setLayout(new FlowLayout()); | |
JButton button = new JButton(); | |
button.setText("Start Chopping"); | |
button.addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent arg0) { | |
logType = treeTypeBox.getSelectedItem().toString(); | |
dropMode = powerChopBox.isSelected(); | |
isRunning = true; | |
} | |
}); | |
buttonPanel.add(button); | |
frame.getContentPane().add(buttonPanel, BorderLayout.SOUTH); | |
frame.pack(); | |
frame.setVisible(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment