Skip to content

Instantly share code, notes, and snippets.

@hikilaka
Created June 4, 2018 18:26
Show Gist options
  • Select an option

  • Save hikilaka/411363b20a579ba509551d03be18c0b8 to your computer and use it in GitHub Desktop.

Select an option

Save hikilaka/411363b20a579ba509551d03be18c0b8 to your computer and use it in GitHub Desktop.
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.util.Arrays;
import com.aposbot.Constants;
import com.aposbot.StandardCloseHandler;
public final class SpellCaster extends Script implements ActionListener {
private enum Spell {
wind_strike(0, "Wind Strike"),
water_strike(2, "Water Strike"),
earth_strike(4, "Earth Strike"),
fire_strike(6, "Fire Strike"),
wind_bolt(8, "Wind Bolt"),
water_bolt(11,"Water Bolt"),
earth_bolt(14, "Earth Bolt"),
fire_bolt(17, "Fire Bolt"),
crumble_undead(19, "Crumble Undead"),
wind_blast(20, "Wind Blast"),
water_blast(23, "Water Blast"),
iban_blast(25, "Iban Blast"),
earth_blast(27, "Earth Blast"),
fire_blast(32, "Fire Blast"),
wind_wave(37, "Wind Wave"),
water_wave(39, "Water Wave"),
earth_wave(43, "Earth Wave"),
fire_wave(45, "Fire Wave");
private final int id;
private final String name;
Spell(int id, String name) {
this.id = id;
this.name = name;
}
}
private Frame frame;
private TextField npc_id_field;
private Choice spell_choice;
private Spell spell;
private int[] npc_ids;
public SpellCaster(Extension ex) {
super(ex);
}
@Override
public void init(String params) {
if (frame == null) {
frame = new Frame(getClass().getSimpleName());
frame.setIconImages(Constants.ICONS);
frame.addWindowListener(new StandardCloseHandler(frame, StandardCloseHandler.HIDE));
npc_id_field = new TextField();
spell_choice = new Choice();
for (Spell spell : Spell.values()) {
spell_choice.add(spell.name);
}
Panel input_panel = new Panel();
input_panel.setLayout(new GridLayout(0, 2, 0, 2));
input_panel.add(new Label("Npc ID (comma separated):"));
input_panel.add(npc_id_field);
input_panel.add(new Label("Spell:"));
input_panel.add(spell_choice);
Panel btn_panel = new Panel();
Button ok = new Button("OK");
ok.addActionListener(this);
btn_panel.add(ok);
Button cancel = new Button("Cancel");
cancel.addActionListener(this);
btn_panel.add(cancel);
frame.add(input_panel, BorderLayout.NORTH);
frame.add(btn_panel, BorderLayout.SOUTH);
frame.setResizable(false);
frame.pack();
}
frame.setLocationRelativeTo(null);
frame.toFront();
frame.requestFocus();
frame.setVisible(true);
}
@Override
public int main() {
System.out.println("running");
if (getFatigue() >= 95) {
useSleepingBag();
return 0;
}
if (!canCastSpell(spell.id)) {
System.out.println("Out of runes!");
stopScript();
return 0;
}
int[] npc = getAllNpcById(npc_ids);
if (npc[0] == -1) {
System.out.println("Unable to locate npc[s]");
return 1000;
}
mageNpc(npc[0], spell.id);
return 2000;
}
@Override
public void actionPerformed(ActionEvent event) {
if (event.getActionCommand().equals("OK")) {
try {
String[] array = npc_id_field.getText().trim().split(",");
int array_sz = array.length;
npc_ids = new int[array_sz];
for (int i = 0; i < array_sz; i++) {
npc_ids[i] = Integer.parseInt(array[i]);
}
} catch (Throwable t) {
System.out.println("Couldn't parse npc ids");
npc_ids = new int[0];
}
try {
spell = Spell.values()[spell_choice.getSelectedIndex()];
} catch (Throwable t) {
System.out.println("Couldn't get spell");
spell = Spell.wind_strike;
}
}
frame.setVisible(false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment