232 lines
6.2 KiB
Java
232 lines
6.2 KiB
Java
package io.reisub.openosrs.motherlodeminer;
|
|
|
|
import com.google.common.collect.ImmutableSet;
|
|
import com.google.inject.Provides;
|
|
|
|
import io.reisub.openosrs.motherlodeminer.tasks.*;
|
|
import io.reisub.openosrs.util.CScript;
|
|
import io.reisub.openosrs.util.Task;
|
|
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.Getter;
|
|
import lombok.Setter;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import net.runelite.api.*;
|
|
import net.runelite.api.coords.LocalPoint;
|
|
import net.runelite.api.events.*;
|
|
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.scene.Position;
|
|
import net.runelite.client.plugins.iutils.scripts.iScript;
|
|
import org.pf4j.Extension;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
import java.util.concurrent.Executors;
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
@Extension
|
|
@PluginDependency(Util.class)
|
|
@PluginDependency(iUtils.class)
|
|
@PluginDescriptor(
|
|
name = "Chaos Motherlode Miner",
|
|
description = "Diggy, diggy hole",
|
|
enabledByDefault = false
|
|
)
|
|
@Slf4j
|
|
public class MotherlodeMiner extends CScript {
|
|
@Provides
|
|
Config provideConfig(ConfigManager configManager) {
|
|
return configManager.getConfig(Config.class);
|
|
}
|
|
|
|
private static final Set<Integer> MOTHERLODE_MAP_REGIONS = ImmutableSet.of(14679, 14680, 14681, 14935, 14936, 14937, 15191, 15192, 15193);
|
|
private static final int UPPER_FLOOR_HEIGHT = -490;
|
|
private static final int SACK_LARGE_SIZE = 162;
|
|
private static final int SACK_SIZE = 81;
|
|
|
|
private int curSackSize, maxSackSize;
|
|
|
|
@Getter
|
|
@Setter
|
|
private boolean sackFull;
|
|
|
|
@Getter
|
|
private boolean inMlm;
|
|
|
|
@Getter
|
|
@Setter
|
|
private Position currentVeinPosition;
|
|
|
|
private ScheduledExecutorService executor;
|
|
|
|
@Override
|
|
protected void loop() {
|
|
game.tick();
|
|
}
|
|
|
|
@Override
|
|
protected void onStart() {
|
|
super.onStart();
|
|
|
|
inMlm = checkInMlm();
|
|
|
|
executor = Executors.newSingleThreadScheduledExecutor();
|
|
addTask(Mine.class);
|
|
addTask(GoDown.class);
|
|
addTask(Deposit.class);
|
|
addTask(FixWheel.class);
|
|
addTask(WithdrawSack.class);
|
|
addTask(HandleBank.class);
|
|
addTask(GoUp.class);
|
|
}
|
|
|
|
@Override
|
|
protected void onStop() {
|
|
executor.shutdownNow();
|
|
}
|
|
|
|
@Subscribe
|
|
private void onGameTick(GameTick event) {
|
|
if (currentVeinPosition != null && currentActivity == Activity.MINING) {
|
|
if (game.objects().withPosition(currentVeinPosition).withAction("Mine").first() == null) {
|
|
currentVeinPosition = null;
|
|
setActivity(Activity.IDLE);
|
|
}
|
|
}
|
|
|
|
if (executor != null) {
|
|
executor.schedule(() -> {
|
|
for (Task t : tasks) {
|
|
if (t.validate()) {
|
|
log.info(t.getStatus());
|
|
t.execute();
|
|
break;
|
|
}
|
|
}
|
|
|
|
checkActionTimeout();
|
|
}, 0, TimeUnit.MILLISECONDS);
|
|
}
|
|
}
|
|
|
|
@Subscribe
|
|
private void onAnimationChanged(AnimationChanged event) {
|
|
Actor actor = event.getActor();
|
|
if (actor == null || actor.getName() == null || !actor.getName().equals(game.localPlayer().name())) return;
|
|
|
|
int animId = game.localPlayer().animation();
|
|
switch (animId) {
|
|
case AnimationID.MINING_MOTHERLODE_BRONZE:
|
|
case AnimationID.MINING_MOTHERLODE_IRON:
|
|
case AnimationID.MINING_MOTHERLODE_STEEL:
|
|
case AnimationID.MINING_MOTHERLODE_BLACK:
|
|
case AnimationID.MINING_MOTHERLODE_MITHRIL:
|
|
case AnimationID.MINING_MOTHERLODE_ADAMANT:
|
|
case AnimationID.MINING_MOTHERLODE_RUNE:
|
|
case AnimationID.MINING_MOTHERLODE_DRAGON:
|
|
case AnimationID.MINING_MOTHERLODE_DRAGON_OR:
|
|
case AnimationID.MINING_MOTHERLODE_DRAGON_UPGRADED:
|
|
case AnimationID.MINING_MOTHERLODE_CRYSTAL:
|
|
case AnimationID.MINING_MOTHERLODE_GILDED:
|
|
case AnimationID.MINING_MOTHERLODE_INFERNAL:
|
|
case AnimationID.MINING_MOTHERLODE_3A:
|
|
setActivity(Activity.MINING);
|
|
break;
|
|
}
|
|
}
|
|
|
|
@Subscribe
|
|
private void onGameObjectDespawned(GameObjectDespawned event) {
|
|
if (currentActivity == Activity.REPAIRING && event.getGameObject().getName().equals("Broken strut")) {
|
|
setActivity(Activity.IDLE);
|
|
}
|
|
}
|
|
|
|
@Subscribe
|
|
private void onItemContainerChanged(ItemContainerChanged event) {
|
|
if (currentActivity == Activity.DEPOSITING) {
|
|
if (!game.inventory().withName("Pay-dirt").exists()) {
|
|
setActivity(Activity.IDLE);
|
|
}
|
|
} else if (currentActivity == Activity.WITHDRAWING) {
|
|
if (game.inventory().withId(
|
|
ItemID.RUNITE_ORE,
|
|
ItemID.ADAMANTITE_ORE,
|
|
ItemID.MITHRIL_ORE,
|
|
ItemID.GOLD_ORE,
|
|
ItemID.COAL,
|
|
ItemID.UNCUT_SAPPHIRE,
|
|
ItemID.UNCUT_EMERALD,
|
|
ItemID.UNCUT_RUBY,
|
|
ItemID.UNCUT_DIAMOND,
|
|
ItemID.UNCUT_DRAGONSTONE
|
|
).exists()) {
|
|
setActivity(Activity.IDLE);
|
|
}
|
|
} else if (currentActivity == Activity.MINING) {
|
|
if (game.inventory().full()) {
|
|
setActivity(Activity.IDLE);
|
|
currentVeinPosition = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
@Subscribe
|
|
private void onVarbitChanged(VarbitChanged event) {
|
|
if (inMlm) {
|
|
refreshSackValues();
|
|
if (curSackSize >= maxSackSize - 26) {
|
|
sackFull = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
@Subscribe
|
|
private void onGameStateChanged(GameStateChanged event) {
|
|
if (event.getGameState() == GameState.LOADING) {
|
|
inMlm = checkInMlm();
|
|
} else if (event.getGameState() == GameState.LOGIN_SCREEN) {
|
|
inMlm = false;
|
|
}
|
|
}
|
|
|
|
private boolean checkInMlm() {
|
|
GameState state = game.client.getGameState();
|
|
if (state != GameState.LOGGED_IN && state != GameState.LOADING) {
|
|
return false;
|
|
}
|
|
|
|
int[] currentMapRegions = game.client.getMapRegions();
|
|
|
|
for (int region : currentMapRegions) {
|
|
if (!MOTHERLODE_MAP_REGIONS.contains(region)) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private void refreshSackValues() {
|
|
curSackSize = game.client.getVar(Varbits.SACK_NUMBER);
|
|
boolean sackUpgraded = game.client.getVar(Varbits.SACK_UPGRADED) == 1;
|
|
maxSackSize = sackUpgraded ? SACK_LARGE_SIZE : SACK_SIZE;
|
|
|
|
if (curSackSize == 0) {
|
|
sackFull = false;
|
|
}
|
|
}
|
|
|
|
public boolean isUpstairs() {
|
|
return Perspective.getTileHeight(game.client, game.client.getLocalPlayer().getLocalLocation(), 0) < UPPER_FLOOR_HEIGHT;
|
|
}
|
|
} |