Skip to content

Commit

Permalink
refactor: Clean up OwnerStep usage
Browse files Browse the repository at this point in the history
A few helpers made direct use of the OwnerStep, when they were better suited to make use of the DetailedOwnerStep which implements much of the boilerplate already.

This shifts those steps to DetailedOwnerStep.
  • Loading branch information
Zoinkwiz committed Oct 2, 2024
1 parent 0927242 commit c42f142
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 550 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.questhelper.requirements.item.ItemRequirement;
import com.questhelper.questhelpers.QuestHelper;
import com.questhelper.steps.DetailedOwnerStep;
import com.questhelper.steps.DetailedQuestStep;
import com.questhelper.steps.NpcStep;
import com.questhelper.steps.PuzzleWrapperStep;
import com.questhelper.steps.QuestStep;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import net.runelite.api.ObjectID;
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.VarbitChanged;
import net.runelite.client.eventbus.Subscribe;

public class MemoryPuzzle extends DetailedOwnerStep
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.questhelper.questhelpers.QuestHelper;
import com.questhelper.questhelpers.QuestUtil;
import com.questhelper.requirements.Requirement;
import com.questhelper.requirements.zone.ZoneRequirement;
import com.questhelper.requirements.item.ItemRequirement;
import com.questhelper.steps.DetailedOwnerStep;
import com.questhelper.steps.DetailedQuestStep;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.util.Arrays;
import java.util.Collection;
import net.runelite.api.events.VarbitChanged;
import net.runelite.client.eventbus.Subscribe;

public class TaverleyBalloonFlight extends DetailedOwnerStep
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import net.runelite.api.NpcID;
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.VarbitChanged;
import net.runelite.client.eventbus.Subscribe;

public class MimicChallenge extends DetailedOwnerStep
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import net.runelite.api.ObjectID;
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.VarbitChanged;
import net.runelite.client.eventbus.Subscribe;

public class NumberChallenge extends DetailedOwnerStep
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import net.runelite.api.ObjectID;
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.VarbitChanged;
import net.runelite.client.eventbus.Subscribe;

public class LadyTableStep extends DetailedOwnerStep
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,16 @@

import com.google.inject.Inject;
import com.questhelper.requirements.item.ItemRequirement;
import com.questhelper.QuestHelperPlugin;
import com.questhelper.questhelpers.QuestHelper;
import com.questhelper.requirements.Requirement;
import com.questhelper.steps.ObjectStep;
import com.questhelper.steps.QuestStep;
import com.questhelper.steps.*;
import com.questhelper.steps.widget.WidgetDetails;
import com.questhelper.steps.WidgetStep;
import com.questhelper.steps.OwnerStep;
import java.awt.Graphics2D;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import lombok.NonNull;
import net.runelite.api.Client;
import net.runelite.api.InventoryID;
import net.runelite.api.Item;
Expand All @@ -54,9 +48,8 @@
import net.runelite.api.widgets.Widget;
import net.runelite.client.eventbus.EventBus;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.ui.overlay.components.PanelComponent;

public class PuzzleStep extends QuestStep implements OwnerStep
public class PuzzleStep extends DetailedOwnerStep
{
@Inject
protected EventBus eventBus;
Expand Down Expand Up @@ -123,19 +116,13 @@ public void startUp()
updateSteps();
}

@Override
public void shutDown()
{
shutDownStep();
currentStep = null;
}

@Subscribe
public void onGameTick(GameTick event)
{
updateSteps();
}

@Override
public void updateSteps()
{
if (client.getVarbitValue(2502) == 2)
Expand Down Expand Up @@ -635,21 +622,16 @@ public void setupShapes()

protected void startUpStep(QuestStep step)
{
if (currentStep == null)
{
currentStep = step;
eventBus.register(currentStep);
currentStep.startUp();
return;
}
if (step.equals(currentStep)) return;

if (!step.equals(currentStep))
if (currentStep != null)
{
shutDownStep();
eventBus.register(step);
step.startUp();
currentStep = step;
}

eventBus.register(step);
step.startUp();
currentStep = step;
}

protected void shutDownStep()
Expand All @@ -662,42 +644,6 @@ protected void shutDownStep()
}
}

@Override
public void makeOverlayHint(PanelComponent panelComponent, QuestHelperPlugin plugin, @NonNull List<String> additionalText, @NonNull List<Requirement> requirements)
{
if (currentStep != null)
{
currentStep.makeOverlayHint(panelComponent, plugin, additionalText, requirements);
}
}

@Override
public void makeWorldOverlayHint(Graphics2D graphics, QuestHelperPlugin plugin)
{
if (currentStep != null)
{
currentStep.makeWorldOverlayHint(graphics, plugin);
}
}

@Override
public void makeWorldArrowOverlayHint(Graphics2D graphics, QuestHelperPlugin plugin)
{
if (currentStep != null)
{
currentStep.makeWorldArrowOverlayHint(graphics, plugin);
}
}

@Override
public void makeWorldLineOverlayHint(Graphics2D graphics, QuestHelperPlugin plugin)
{
if (currentStep != null)
{
currentStep.makeWorldLineOverlayHint(graphics, plugin);
}
}

@Override
public QuestStep getActiveStep()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,18 @@
package com.questhelper.helpers.quests.theforsakentower;

import com.google.inject.Inject;
import com.questhelper.QuestHelperPlugin;
import com.questhelper.requirements.zone.Zone;
import com.questhelper.panel.PanelDetails;
import com.questhelper.questhelpers.QuestHelper;
import com.questhelper.requirements.item.ItemRequirement;
import com.questhelper.requirements.Requirement;
import com.questhelper.requirements.zone.ZoneRequirement;
import com.questhelper.steps.DetailedQuestStep;
import com.questhelper.steps.ObjectStep;
import com.questhelper.steps.OwnerStep;
import com.questhelper.steps.PuzzleWrapperStep;
import com.questhelper.steps.QuestStep;
import java.awt.Graphics2D;
import com.questhelper.steps.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import lombok.NonNull;
import net.runelite.api.Client;
import net.runelite.api.ItemID;
import net.runelite.api.NullObjectID;
Expand All @@ -51,9 +45,8 @@
import net.runelite.api.events.GameTick;
import net.runelite.client.eventbus.EventBus;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.ui.overlay.components.PanelComponent;

public class AltarPuzzle extends QuestStep implements OwnerStep
public class AltarPuzzle extends DetailedOwnerStep
{
@Inject
protected EventBus eventBus;
Expand Down Expand Up @@ -86,25 +79,13 @@ public AltarPuzzle(QuestHelper questHelper)
setupSteps();
}

@Override
public void startUp()
{
updateSteps();
}

@Override
public void shutDown()
{
shutDownStep();
currentStep = null;
}

@Subscribe
public void onGameTick(GameTick event)
{
updateSteps();
}

@Override
protected void updateSteps()
{
if (inBasement.check(client))
Expand Down Expand Up @@ -282,91 +263,12 @@ else if (currentW == 0 && currentC == 14 && currentE == 0)
}
}

protected void startUpStep(QuestStep step)
{
if (currentStep == null)
{
currentStep = step;
eventBus.register(currentStep);
currentStep.startUp();
return;
}

if (!step.equals(currentStep))
{
shutDownStep();
eventBus.register(step);
step.startUp();
currentStep = step;
}
}

protected void shutDownStep()
{
if (currentStep != this)
{
eventBus.unregister(currentStep);
currentStep.shutDown();
currentStep = null;
}
}

@Override
public void makeOverlayHint(PanelComponent panelComponent, QuestHelperPlugin plugin, @NonNull List<String> additionalText, @NonNull List<Requirement> requirements)
{
if (currentStep != null)
{
currentStep.makeOverlayHint(panelComponent, plugin, additionalText, requirements);
}
}

@Override
public void makeWorldOverlayHint(Graphics2D graphics, QuestHelperPlugin plugin)
{
if (currentStep != null)
{
currentStep.makeWorldOverlayHint(graphics, plugin);
}
}

@Override
public void makeWorldArrowOverlayHint(Graphics2D graphics, QuestHelperPlugin plugin)
{
if (currentStep != null)
{
currentStep.makeWorldArrowOverlayHint(graphics, plugin);
}
}

@Override
public void makeWorldLineOverlayHint(Graphics2D graphics, QuestHelperPlugin plugin)
{
if (currentStep != null)
{
currentStep.makeWorldLineOverlayHint(graphics, plugin);
}
}

@Override
public QuestStep getActiveStep()
{
if (currentStep != this)
{
return currentStep.getActiveStep();
}
else
{
return this;
}
}

private void setupItemRequirements()
{
ring1 = new ItemRequirement("Energy disk (level 1)", ItemID.ENERGY_DISK_LEVEL_1);
ring2 = new ItemRequirement("Energy disk (level 2)", ItemID.ENERGY_DISK_LEVEL_2);
ring3 = new ItemRequirement("Energy disk (level 3)", ItemID.ENERGY_DISK_LEVEL_3);
ring4 = new ItemRequirement("Energy disk (level 4)", ItemID.ENERGY_DISK_LEVEL_4);

}

private void setupConditions()
Expand All @@ -383,7 +285,8 @@ private void setupZones()
basement = new Zone(new WorldPoint(1374, 10217, 0), new WorldPoint(1389, 10231, 0));
}

private void setupSteps()
@Override
protected void setupSteps()
{
goUpLadder = new ObjectStep(getQuestHelper(), ObjectID.LADDER_33484, new WorldPoint(1382, 10229, 0), "Leave the tower's basement.");
goUpStairs = new ObjectStep(getQuestHelper(), ObjectID.STAIRCASE_33550, new WorldPoint(1378, 3825, 0), "Climb up the staircase to the tower's 1st floor.");
Expand Down
Loading

0 comments on commit c42f142

Please sign in to comment.