Updates and rework to use CScript
This commit is contained in:
@ -3,15 +3,15 @@ package io.reisub.openosrs.util;
|
||||
import io.reisub.openosrs.util.enums.Activity;
|
||||
import io.reisub.openosrs.util.tasks.KittenTask;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.ChatMessageType;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.api.InventoryID;
|
||||
import net.runelite.api.Skill;
|
||||
import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.api.events.ConfigButtonClicked;
|
||||
import net.runelite.api.events.GameStateChanged;
|
||||
import net.runelite.api.events.StatChanged;
|
||||
import net.runelite.api.events.*;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.plugins.iutils.game.iPlayer;
|
||||
import net.runelite.client.plugins.iutils.scripts.iScript;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -30,12 +30,22 @@ public abstract class CScript extends iScript {
|
||||
protected KittenTask kittenTask;
|
||||
|
||||
@Getter
|
||||
protected Activity currentActivity = Activity.IDLE;
|
||||
protected Activity currentActivity;
|
||||
|
||||
@Getter
|
||||
protected Activity previousActivity;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private Instant lastHop;
|
||||
|
||||
protected Instant lastLogin = Instant.EPOCH;
|
||||
protected Instant lastActionTime = Instant.EPOCH;
|
||||
protected Duration lastActionTimeout = Duration.ofSeconds(3);
|
||||
protected Instant lastExperience = Instant.EPOCH;
|
||||
protected Instant lastInventoryChange = Instant.EPOCH;
|
||||
protected final Map<Skill, Activity> idleCheckSkills = new HashMap<>();
|
||||
protected boolean idleCheckInventoryChange = false;
|
||||
|
||||
@Override
|
||||
protected void loop() {
|
||||
@ -54,6 +64,10 @@ public abstract class CScript extends iScript {
|
||||
@Override
|
||||
protected void onStart() {
|
||||
log.info("Starting " + this.getName());
|
||||
|
||||
previousActivity = Activity.IDLE;
|
||||
currentActivity = Activity.IDLE;
|
||||
|
||||
kittenTask = KittenTask.getInstance(injector);
|
||||
}
|
||||
|
||||
@ -62,6 +76,9 @@ public abstract class CScript extends iScript {
|
||||
log.info("Stopping " + this.getName());
|
||||
tasks.clear();
|
||||
|
||||
previousActivity = Activity.IDLE;
|
||||
currentActivity = Activity.IDLE;
|
||||
|
||||
KittenTask.handleKitten = false;
|
||||
}
|
||||
|
||||
@ -103,6 +120,15 @@ public abstract class CScript extends iScript {
|
||||
}
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("unused")
|
||||
@Subscribe
|
||||
private void onItemContainerChanged(ItemContainerChanged event) {
|
||||
if (!isLoggedIn() || event.getItemContainer() != game.client().getItemContainer(InventoryID.INVENTORY)) return;
|
||||
|
||||
if (idleCheckInventoryChange) {
|
||||
lastInventoryChange = Instant.now();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@SuppressWarnings("unused")
|
||||
@ -112,7 +138,11 @@ public abstract class CScript extends iScript {
|
||||
}
|
||||
}
|
||||
|
||||
protected void setActivity(Activity action) {
|
||||
public void setActivity(Activity action) {
|
||||
if (action == Activity.IDLE && currentActivity != Activity.IDLE) {
|
||||
previousActivity = currentActivity;
|
||||
}
|
||||
|
||||
currentActivity = action;
|
||||
|
||||
if (action != Activity.IDLE) {
|
||||
@ -123,15 +153,16 @@ public abstract class CScript extends iScript {
|
||||
protected void checkActionTimeout() {
|
||||
if (currentActivity == Activity.IDLE) return;
|
||||
|
||||
if (Duration.between(lastExperience, Instant.now()).getSeconds() < 5) return;
|
||||
if (Duration.between(lastExperience, Instant.now()).compareTo(lastActionTimeout) < 0) return;
|
||||
|
||||
if (Duration.between(lastInventoryChange, Instant.now()).compareTo(lastActionTimeout) < 0) return;
|
||||
|
||||
int animId = game.localPlayer().animation();
|
||||
if (animId != IDLE || lastActionTime == null) return;
|
||||
|
||||
Duration timeout = Duration.ofSeconds(5);
|
||||
Duration sinceAction = Duration.between(lastActionTime, Instant.now());
|
||||
|
||||
if (sinceAction.compareTo(timeout) >= 0) {
|
||||
if (sinceAction.compareTo(lastActionTimeout) >= 0) {
|
||||
setActivity(Activity.IDLE);
|
||||
}
|
||||
}
|
||||
@ -140,7 +171,18 @@ public abstract class CScript extends iScript {
|
||||
return game.client() != null && game.client().getGameState() == GameState.LOGGED_IN;
|
||||
}
|
||||
|
||||
public final boolean isLoggedInForLongerThan(int seconds) {
|
||||
return Duration.between(lastLogin, Instant.now()).getSeconds() >= seconds;
|
||||
public final boolean isLoggedInForLongerThan(Duration duration) {
|
||||
return Duration.between(lastLogin, Instant.now()).compareTo(duration) >= 0;
|
||||
}
|
||||
|
||||
public final boolean isInRegion(int regionId) {
|
||||
iPlayer player = game.localPlayer();
|
||||
return player != null
|
||||
&& player.position().regionID() == regionId;
|
||||
}
|
||||
|
||||
public final void stop(String message) {
|
||||
game.utils.sendGameMessage(message);
|
||||
this.execute();
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package io.reisub.openosrs.util;
|
||||
|
||||
import net.runelite.client.config.*;
|
||||
import net.runelite.client.config.ConfigGroup;
|
||||
|
||||
@ConfigGroup("ChaosUtilConfig")
|
||||
@ConfigGroup("chaosutil")
|
||||
public interface Config extends net.runelite.client.config.Config {
|
||||
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import net.runelite.client.plugins.iutils.ui.Equipment;
|
||||
import net.runelite.client.plugins.iutils.walking.Walking;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
public abstract class Task {
|
||||
|
@ -2,5 +2,18 @@ package io.reisub.openosrs.util.enums;
|
||||
|
||||
public enum Activity {
|
||||
IDLE,
|
||||
GLASSBLOWING;
|
||||
COOKING,
|
||||
GLASSBLOWING,
|
||||
SMELTING,
|
||||
WOODCUTTING(),
|
||||
FLETCHING(),
|
||||
FEEDING_BRAZIER(),
|
||||
FIXING_BRAZIER(),
|
||||
LIGHTING_BRAZIER(),
|
||||
THIEVING(),
|
||||
MINING(),
|
||||
CLEANING_HERBS(),
|
||||
CREATING_UNFINISHED_POTIONS(),
|
||||
CREATING_POTIONS(),
|
||||
SMITHING();
|
||||
}
|
||||
|
17
util/src/main/java/io/reisub/openosrs/util/enums/Food.java
Normal file
17
util/src/main/java/io/reisub/openosrs/util/enums/Food.java
Normal file
@ -0,0 +1,17 @@
|
||||
package io.reisub.openosrs.util.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import net.runelite.api.ItemID;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum Food {
|
||||
TROUT(ItemID.TROUT, 7, 1),
|
||||
SALMON(ItemID.SALMON, 9, 1),
|
||||
LOBSTER(ItemID.LOBSTER, 12, 1);
|
||||
|
||||
private final int id;
|
||||
private final int hp;
|
||||
private final int bites;
|
||||
}
|
@ -1,26 +1,31 @@
|
||||
package io.reisub.openosrs.util.tasks;
|
||||
|
||||
import io.reisub.openosrs.util.Task;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.runelite.api.Skill;
|
||||
|
||||
public class Eat extends Task {
|
||||
private long last = 0;
|
||||
private int min = 5;
|
||||
private int max = 10;
|
||||
|
||||
@Setter
|
||||
private boolean wait = true;
|
||||
|
||||
@Getter
|
||||
private int threshold = 5;
|
||||
private int mean = 5;
|
||||
private int sigma = 1;
|
||||
|
||||
public void setInterval(int min, int max) {
|
||||
mean = (min + max) / 2;
|
||||
sigma = mean - min;
|
||||
|
||||
if (sigma <= 0) threshold = min;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
|
||||
threshold = getNewThreshold();
|
||||
}
|
||||
|
||||
public void setWait(boolean wait) {
|
||||
this.wait = wait;
|
||||
@Override
|
||||
public String getStatus() {
|
||||
return "Eating";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -50,15 +55,6 @@ public class Eat extends Task {
|
||||
}
|
||||
|
||||
private int getNewThreshold() {
|
||||
if (sigma <= 0) {
|
||||
return threshold;
|
||||
}
|
||||
|
||||
return calc.randomGauss(1, 99, sigma, mean, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStatus() {
|
||||
return "Eating";
|
||||
return calc.random(min, max + 1);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user