Updates and rework to use CScript
This commit is contained in:
@ -24,13 +24,50 @@
|
||||
*/
|
||||
package io.reisub.openosrs.masterthiever;
|
||||
|
||||
import io.reisub.openosrs.util.enums.Food;
|
||||
import net.runelite.client.config.Button;
|
||||
import net.runelite.client.config.ConfigGroup;
|
||||
import net.runelite.client.config.ConfigItem;
|
||||
|
||||
@ConfigGroup("ChaosMasterThieverConfig")
|
||||
@ConfigGroup("chaosmasterthiever")
|
||||
|
||||
public interface Config extends net.runelite.client.config.Config {
|
||||
@ConfigItem(
|
||||
keyName = "minEatHP",
|
||||
name = "Minimum Eat HP",
|
||||
description = "Minimum HP to eat or bank at.",
|
||||
position = 0
|
||||
)
|
||||
default int minEatHP() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "maxEatHP",
|
||||
name = "Maximum Eat HP",
|
||||
description = "Highest HP to potentially eat or bank at.",
|
||||
position = 1
|
||||
)
|
||||
default int maxEatHP() {
|
||||
return 20;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "food",
|
||||
name = "Food",
|
||||
description = "Choose what food to eat.",
|
||||
position = 2
|
||||
)
|
||||
default Food food() { return Food.SALMON; }
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "healAtBank",
|
||||
name = "Heal at bank",
|
||||
description = "Heal at bank and don't take food with us when thieving.",
|
||||
position = 3
|
||||
)
|
||||
default boolean healAtBank() { return true; }
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "startButton",
|
||||
name = "Start/Stop",
|
||||
|
@ -1,96 +1,81 @@
|
||||
package io.reisub.openosrs.masterthiever;
|
||||
|
||||
import com.google.inject.Provides;
|
||||
|
||||
import io.reisub.openosrs.masterthiever.tasks.HandleBank;
|
||||
import io.reisub.openosrs.masterthiever.tasks.Steal;
|
||||
import io.reisub.openosrs.util.Task;
|
||||
import io.reisub.openosrs.util.CScript;
|
||||
import io.reisub.openosrs.util.Util;
|
||||
import io.reisub.openosrs.util.enums.Activity;
|
||||
import io.reisub.openosrs.util.tasks.Eat;
|
||||
import io.reisub.openosrs.util.tasks.KittenTask;
|
||||
import io.reisub.openosrs.util.tasks.Run;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.api.events.ConfigButtonClicked;
|
||||
import net.runelite.api.Actor;
|
||||
import net.runelite.api.Skill;
|
||||
import net.runelite.api.events.AnimationChanged;
|
||||
import net.runelite.api.events.ItemContainerChanged;
|
||||
import net.runelite.api.events.StatChanged;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.plugins.PluginDependency;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.plugins.iutils.iUtils;
|
||||
import net.runelite.client.plugins.iutils.scripts.iScript;
|
||||
import org.pf4j.Extension;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
|
||||
@Extension
|
||||
@PluginDependency(Util.class)
|
||||
@PluginDependency(iUtils.class)
|
||||
@PluginDescriptor(
|
||||
name = "Chaos Master Thiever",
|
||||
description = "Steals seeds from master farmers.",
|
||||
description = "Cor blimey mate, what are ye doing in me pockets?",
|
||||
enabledByDefault = false
|
||||
)
|
||||
@Slf4j
|
||||
public class MasterThiever extends iScript {
|
||||
private List<Task> tasks;
|
||||
private KittenTask kittenTask;
|
||||
public class MasterThiever extends CScript {
|
||||
@Inject
|
||||
private Config config;
|
||||
|
||||
private Eat eatTask;
|
||||
|
||||
@Provides
|
||||
Config provideConfig(ConfigManager configManager) {
|
||||
return configManager.getConfig(Config.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loop() {
|
||||
for (Task t : tasks) {
|
||||
if (t.validate()) {
|
||||
log.info(t.getStatus());
|
||||
t.execute();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
game.sleepDelay();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
log.info("Starting Chaos Master Thiever");
|
||||
super.onStart();
|
||||
|
||||
Eat eatTask = injector.getInstance(Eat.class);
|
||||
eatTask.setInterval(14, 24);
|
||||
eatTask = injector.getInstance(Eat.class);
|
||||
eatTask.setInterval(config.minEatHP(), config.maxEatHP());
|
||||
|
||||
kittenTask = KittenTask.getInstance(injector);
|
||||
|
||||
tasks = new ArrayList<>();
|
||||
tasks.add(eatTask);
|
||||
tasks.add(kittenTask);
|
||||
tasks.add(injector.getInstance(HandleBank.class));
|
||||
tasks.add(injector.getInstance(Steal.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
log.info("Stopping Chaos Master Thiever");
|
||||
if (tasks != null) {
|
||||
tasks.clear();
|
||||
}
|
||||
|
||||
KittenTask.handleKitten = false;
|
||||
addTask(HandleBank.class);
|
||||
addTask(Steal.class);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
private void onConfigButtonPressed(ConfigButtonClicked configButtonClicked) {
|
||||
if (configButtonClicked.getKey().equals("startButton")) {
|
||||
execute();
|
||||
private void onAnimationChanged(AnimationChanged event) {
|
||||
Actor actor = event.getActor();
|
||||
if (actor == null || actor.getName() == null) return;
|
||||
|
||||
if (!actor.getName().equals(game.localPlayer().name())) return;
|
||||
|
||||
switch (game.localPlayer().animation()) {
|
||||
case 388:
|
||||
setActivity(Activity.IDLE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
private void onChatMessage(ChatMessage chatMessage) {
|
||||
if (kittenTask != null) {
|
||||
kittenTask.onChatMessage(chatMessage);
|
||||
private void onStatChanged(StatChanged event) {
|
||||
if (event.getSkill() == Skill.THIEVING) {
|
||||
setActivity(Activity.IDLE);
|
||||
}
|
||||
}
|
||||
|
||||
public int getEatThreshold() {
|
||||
return eatTask.getThreshold();
|
||||
}
|
||||
}
|
@ -1,15 +1,23 @@
|
||||
package io.reisub.openosrs.masterthiever.tasks;
|
||||
|
||||
import io.reisub.openosrs.masterthiever.Config;
|
||||
import io.reisub.openosrs.masterthiever.MasterThiever;
|
||||
import io.reisub.openosrs.util.Task;
|
||||
import net.runelite.api.ItemID;
|
||||
import net.runelite.api.Skill;
|
||||
import net.runelite.client.plugins.iutils.api.Interactable;
|
||||
import net.runelite.client.plugins.iutils.game.iNPC;
|
||||
import net.runelite.client.plugins.iutils.game.iObject;
|
||||
import net.runelite.client.plugins.iutils.scene.Position;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class HandleBank extends Task {
|
||||
@Inject
|
||||
private MasterThiever plugin;
|
||||
|
||||
@Inject
|
||||
private Config config;
|
||||
|
||||
@Override
|
||||
public String getStatus() {
|
||||
return "Banking";
|
||||
@ -19,21 +27,22 @@ public class HandleBank extends Task {
|
||||
public boolean validate() {
|
||||
return game.client().getLocalPlayer().getModelHeight() != 1000
|
||||
&& (game.inventory().full()
|
||||
|| (!game.inventory().withAction("Eat").exists() && game.modifiedLevel(Skill.HITPOINTS) <= 35));
|
||||
|| (!game.inventory().withAction("Eat").exists() && game.modifiedLevel(Skill.HITPOINTS) <= plugin.getEatThreshold()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
game.tick();
|
||||
if (!bank.isOpen()) {
|
||||
Interactable bankObj;
|
||||
if (calc.random(0, 1) == 0) {
|
||||
bankObj = game.objects().filter(obj -> obj.name().equals("Bank booth") && obj.position().equals(new Position(3091, 3245, 0))).first();
|
||||
} else {
|
||||
bankObj = game.npcs().filter(npc -> npc.name().equals("Banker") && npc.position().equals(new Position(3090, 3245, 0))).first();
|
||||
iObject bankObj = game.objects().withAction("Bank").withPosition(new Position(3091, 3245, 0)).first();
|
||||
if (bankObj == null) {
|
||||
bankObj = game.objects().withName("Bank chest", "Bank booth", "Bank Chest-wreck").withAction("Bank").nearest();
|
||||
}
|
||||
|
||||
if (bankObj == null) return;
|
||||
if (bankObj == null) {
|
||||
walking.walkTo(new Position(3090, 3248, 0).areaWithin(2));
|
||||
return;
|
||||
}
|
||||
|
||||
bankObj.interact("Bank");
|
||||
game.waitUntil(() -> bank.isOpen(), 15);
|
||||
@ -42,12 +51,21 @@ public class HandleBank extends Task {
|
||||
bank.depositInventory();
|
||||
game.tick();
|
||||
|
||||
int quantity = 5 + (game.baseLevel(Skill.HITPOINTS) - game.modifiedLevel(Skill.HITPOINTS)) / 9;
|
||||
int missingHp = game.baseLevel(Skill.HITPOINTS) - game.modifiedLevel(Skill.HITPOINTS);
|
||||
|
||||
int quantity = config.healAtBank() ? missingHp / config.food().getHp() : 5 + (missingHp / config.food().getHp());
|
||||
|
||||
bank.withdraw(ItemID.SALMON, quantity, false);
|
||||
game.waitUntil(() -> game.inventory().withAction("Eat", "Drink").count() > 1, 6);
|
||||
|
||||
bank.close();
|
||||
game.waitUntil(() -> !bank.isOpen(), 3);
|
||||
|
||||
if (config.healAtBank()) {
|
||||
game.inventory().withId(config.food().getId()).forEach((food) -> {
|
||||
food.interact(0);
|
||||
game.tick(3);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,19 @@
|
||||
package io.reisub.openosrs.masterthiever.tasks;
|
||||
|
||||
import io.reisub.openosrs.masterthiever.MasterThiever;
|
||||
import io.reisub.openosrs.util.Task;
|
||||
import io.reisub.openosrs.util.enums.Activity;
|
||||
import net.runelite.api.AnimationID;
|
||||
import net.runelite.api.NpcID;
|
||||
import net.runelite.api.Skill;
|
||||
import net.runelite.client.plugins.iutils.game.iNPC;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class Steal extends Task {
|
||||
@Inject
|
||||
private MasterThiever plugin;
|
||||
|
||||
@Override
|
||||
public String getStatus() {
|
||||
return "Pickpocketing";
|
||||
@ -14,8 +22,9 @@ public class Steal extends Task {
|
||||
@Override
|
||||
public boolean validate() {
|
||||
return !game.inventory().full()
|
||||
&& plugin.getCurrentActivity() == Activity.IDLE
|
||||
&& game.client().getLocalPlayer().getModelHeight() != 1000
|
||||
&& (game.inventory().withAction("Eat").exists() || game.modifiedLevel(Skill.HITPOINTS) > 35);
|
||||
&& (game.inventory().withAction("Eat").exists() || game.modifiedLevel(Skill.HITPOINTS) > plugin.getEatThreshold());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -24,8 +33,9 @@ public class Steal extends Task {
|
||||
|
||||
if (farmer == null) return;
|
||||
|
||||
|
||||
farmer.interact("Pickpocket");
|
||||
game.tick(calc.random(0, 2));
|
||||
game.sleepDelay();
|
||||
plugin.setActivity(Activity.THIEVING);
|
||||
game.tick();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user