Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

@PluginDescriptor(
name = "Quest Helper",
version = "1.0.8",
version = "1.0.13",
description = "Helps you with questing",
tags = { "quest", "helper", "overlay" }
)
Expand Down Expand Up @@ -265,6 +265,12 @@ public void onGameTick(GameTick event)
questManager.updateQuestState();
}

@Subscribe
public void onGraphicsObjectCreated(GraphicsObjectCreated event)
{
questScript.onGraphicsObjectCreated(event.getGraphicsObject());
}

@Subscribe
public void onItemContainerChanged(ItemContainerChanged event)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public class QuestScript extends Script {
private long interactionSequence;
private long targetReadyAt;
private QuestStep lastCustomStep;
private long nextCustomAttemptAt;
private volatile long nextCustomAttemptAt;
private boolean customActionPending;

private static WorldPoint scenePlayerLocation() {
Expand Down Expand Up @@ -185,7 +185,9 @@ public boolean run(QuestHelperConfig config, QuestHelperPlugin mQuestPlugin) {
}
}

if (!Rs2Dialogue.isInDialogue() && (pendingInteraction != null || Rs2Player.isAnimating())) return;
if (shouldPauseBeforeCustomLogic(
Rs2Dialogue.isInDialogue(), pendingInteraction != null, Rs2Player.isAnimating(),
customLogicRunsWhileAnimating())) return;

if (questStep != null && !questStep.getWidgetsToHighlight().isEmpty()) {
var visibleWidgetHighlights = questStep.getWidgetsToHighlight().stream()
Expand Down Expand Up @@ -309,10 +311,15 @@ public boolean run(QuestHelperConfig config, QuestHelperPlugin mQuestPlugin) {
}
}

if (pendingInteraction != null || Rs2Player.isAnimating()) return;
if (pendingInteraction != null) return;

boolean playerAnimating = Rs2Player.isAnimating();
if (playerAnimating && !customLogicRunsWhileAnimating()) return;

if (!runIdleCustomLogic(questStep)) return;

if (playerAnimating) return;

boolean isInCutscene = Microbot.getVarbitValue(4606) > 0;
if (isInCutscene) {
if (ShortestPathPlugin.getMarker() != null)
Expand Down Expand Up @@ -1391,15 +1398,45 @@ private boolean executeQuestCustomLogic() {
return questLogic == null || questLogic.executeCustomLogic();
}

public void onGraphicsObjectCreated(GraphicsObject graphicsObject) {
if (graphicsObject == null || getQuestHelperPlugin() == null
|| getQuestHelperPlugin().getSelectedQuest() == null) {
return;
}
var questLogic = QuestRegistry.getQuest(
getQuestHelperPlugin().getSelectedQuest().getQuest().getId());
if (questLogic != null && questLogic.onGraphicsObjectCreated(graphicsObject)) {
nextCustomAttemptAt = 0;
}
}

private boolean runIdleCustomLogic(QuestStep step) {
long now = System.nanoTime();
if (lastCustomStep == step && now - nextCustomAttemptAt < 0) return !customActionPending;
lastCustomStep = step;
nextCustomAttemptAt = now + 600_000_000L;
nextCustomAttemptAt = now + customLogicIntervalNanos();
customActionPending = !executeQuestCustomLogic();
return !customActionPending;
}

private long customLogicIntervalNanos() {
var questLogic = QuestRegistry.getQuest(
getQuestHelperPlugin().getSelectedQuest().getQuest().getId());
return questLogic == null ? 600_000_000L
: Math.max(0, questLogic.customLogicIntervalNanos());
}

private boolean customLogicRunsWhileAnimating() {
var questLogic = QuestRegistry.getQuest(
getQuestHelperPlugin().getSelectedQuest().getQuest().getId());
return questLogic != null && questLogic.customLogicRunsWhileAnimating();
}

static boolean shouldPauseBeforeCustomLogic(boolean inDialogue, boolean pending,
boolean animating, boolean allowWhileAnimating) {
return !inDialogue && (pending || (animating && !allowWhileAnimating));
}

private void clearInteractionState() {
pendingInteraction = null;
unreachableTarget = false;
Expand Down Expand Up @@ -1649,8 +1686,9 @@ private boolean dispatchNpcStep(NpcStep step) {
Rs2Walker.clearWalkingRoute("quest-helper:npc-step-visible-interact");

if (step.getText().stream().anyMatch(x -> x.toLowerCase().contains("kill"))) {
if (!Rs2Combat.inCombat() && npc.click("Attack")) {
beginInteraction(step, npc.getId(), npc.getIndex(), npc.getWorldLocation(), "Attack", -1, 0);
String action = chooseCombatNpcAction(getNpcActions(npc));
if (!Rs2Combat.inCombat() && npc.click(action)) {
beginInteraction(step, npc.getId(), npc.getIndex(), npc.getWorldLocation(), action, -1, 0);
return true;
}
return false;
Expand Down Expand Up @@ -1885,6 +1923,25 @@ private String chooseCorrectNPCOption(QuestStep step, Rs2NpcModel npc) {
}).orElse("");
}

private String[] getNpcActions(Rs2NpcModel npc) {
return Microbot.getClientThread().runOnClientThreadOptional(() -> {
NPCComposition composition = Microbot.getClient().getNpcDefinition(npc.getId());
if (composition != null && composition.getConfigs() != null) composition = composition.transform();
return composition == null ? null : composition.getActions();
}).orElse(null);
}

static String chooseCombatNpcAction(String[] actions) {
if (actions != null) {
for (String preferred : new String[]{"Attack", "Fight"}) {
for (String action : actions) {
if (preferred.equalsIgnoreCase(action)) return action;
}
}
}
return "Attack";
}

static String chooseNpcAction(List<String> stepText, String[] actions, boolean shopStep) {
if (actions == null) {
return "Talk-to";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
package net.runelite.client.plugins.microbot.questhelper.logic;

import net.runelite.api.GraphicsObject;

public interface IQuest {
boolean executeCustomLogic();

default long customLogicIntervalNanos() {
return 600_000_000L;
}

default boolean customLogicRunsWhileAnimating() {
return false;
}

default boolean onGraphicsObjectCreated(GraphicsObject graphicsObject) {
return false;
}

default void reset() {
}
}
Loading
Loading