Skip to content

Commit

Permalink
clues: support dynamic locations
Browse files Browse the repository at this point in the history
Adds support for dynamically determining a clue's location, by passing the ClueScrollPlugin instance into the getLocation getter. This can be used for location assistance in clues where the location can vary per player, or based on quest completion.
  • Loading branch information
LlemonDuck authored and Nightfirecat committed Jul 13, 2023
1 parent b168597 commit 4007dd4
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ public void onGameTick(final GameTick event)

if (clue instanceof LocationsClueScroll)
{
final WorldPoint[] locations = ((LocationsClueScroll) clue).getLocations();
final WorldPoint[] locations = ((LocationsClueScroll) clue).getLocations(this);

if (locations.length > 0)
{
Expand All @@ -587,7 +587,7 @@ public void onGameTick(final GameTick event)

if (clue instanceof LocationClueScroll)
{
final WorldPoint[] locations = ((LocationClueScroll) clue).getLocations();
final WorldPoint[] locations = ((LocationClueScroll) clue).getLocations(this);
final boolean npcHintArrowMarked = client.getHintArrowNpc() != null && npcsToMark.contains(client.getHintArrowNpc());

if (!npcHintArrowMarked)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.awt.Graphics2D;
import java.util.List;
import javax.annotation.Nullable;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import net.runelite.api.NPC;
Expand Down Expand Up @@ -773,6 +774,7 @@ public class AnagramClue extends ClueScroll implements NpcClueScroll, ObjectClue

private final String text;
private final String npc;
@Getter(AccessLevel.PRIVATE)
private final WorldPoint location;
private final String area;
@Nullable
Expand All @@ -782,6 +784,12 @@ public class AnagramClue extends ClueScroll implements NpcClueScroll, ObjectClue
@Builder.Default
private final int objectId = -1;

@Override
public WorldPoint getLocation(ClueScrollPlugin plugin)
{
return location;
}

@Override
public void makeOverlayHint(PanelComponent panelComponent, ClueScrollPlugin plugin)
{
Expand Down Expand Up @@ -813,7 +821,7 @@ public void makeOverlayHint(PanelComponent panelComponent, ClueScrollPlugin plug
@Override
public void makeWorldOverlayHint(Graphics2D graphics, ClueScrollPlugin plugin)
{
if (!getLocation().isInScene(plugin.getClient()))
if (!getLocation(plugin).isInScene(plugin.getClient()))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.awt.Graphics2D;
import java.util.List;
import javax.annotation.Nullable;
import lombok.AccessLevel;
import lombok.Getter;
import net.runelite.api.NPC;
import net.runelite.api.NPCComposition;
Expand Down Expand Up @@ -67,6 +68,7 @@ public class CipherClue extends ClueScroll implements NpcClueScroll, LocationClu

private final String text;
private final int npcId;
@Getter(AccessLevel.PRIVATE)
private final WorldPoint location;
private final String area;
@Nullable
Expand Down Expand Up @@ -99,6 +101,12 @@ private CipherClue(String text, int npcId, WorldPoint location, String area, @Nu
this.answer = answer;
}

@Override
public WorldPoint getLocation(ClueScrollPlugin plugin)
{
return location;
}

@Override
public void makeOverlayHint(PanelComponent panelComponent, ClueScrollPlugin plugin)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.awt.Graphics2D;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NonNull;
import net.runelite.api.Varbits;
Expand Down Expand Up @@ -250,6 +251,7 @@ private CoordinateClueInfo(@Nonnull String directions, Enemy enemy, boolean ligh
.build();

private final String text;
@Getter(AccessLevel.PRIVATE)
private final WorldPoint location;
/**
* For regions which are mirrored, the location of the the clue in the mirrored region.
Expand All @@ -274,7 +276,13 @@ public CoordinateClue(String text, WorldPoint location, WorldPoint mirrorLocatio
}

@Override
public WorldPoint[] getLocations()
public WorldPoint getLocation(ClueScrollPlugin plugin)
{
return location;
}

@Override
public WorldPoint[] getLocations(ClueScrollPlugin plugin)
{
if (mirrorLocation != null)
{
Expand Down Expand Up @@ -311,7 +319,7 @@ public void makeOverlayHint(PanelComponent panelComponent, ClueScrollPlugin plug
@Override
public void makeWorldOverlayHint(Graphics2D graphics, ClueScrollPlugin plugin)
{
for (WorldPoint worldPoint : getLocations())
for (WorldPoint worldPoint : getLocations(plugin))
{
LocalPoint localLocation = LocalPoint.fromWorld(plugin.getClient(), worldPoint);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@
import java.awt.Color;
import java.awt.Graphics2D;
import java.util.List;
import java.util.function.Function;
import javax.annotation.Nullable;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.NPC;
import static net.runelite.api.NullObjectID.NULL_1293;
import net.runelite.api.ObjectComposition;
import static net.runelite.api.ObjectID.*;
import net.runelite.api.TileObject;
import net.runelite.api.Varbits;
import net.runelite.api.coords.LocalPoint;
import net.runelite.api.coords.WorldPoint;
import static net.runelite.client.plugins.cluescrolls.ClueScrollOverlay.TITLED_CONTENT_COLOR;
Expand All @@ -49,6 +53,7 @@
import net.runelite.client.ui.overlay.components.TitleComponent;

@Getter
@Slf4j
public class CrypticClue extends ClueScroll implements NpcClueScroll, ObjectClueScroll
{
static final List<CrypticClue> CLUES = ImmutableList.of(
Expand Down Expand Up @@ -334,12 +339,14 @@ public class CrypticClue extends ClueScroll implements NpcClueScroll, ObjectClue
private final String text;
private final String npc;
private final int objectId;
@Nullable
private final WorldPoint location;
private final String solution;
@Nullable
private final String questionText;

@Nullable
@Getter(AccessLevel.PRIVATE)
private final Function<ClueScrollPlugin, WorldPoint> locationProvider;

private CrypticClue(String text, WorldPoint location, String solution)
{
this(text, null, -1, location, solution);
Expand Down Expand Up @@ -376,15 +383,33 @@ private CrypticClue(String text, String npc, int objectId, WorldPoint location,
this(text, npc, objectId, location, solution, null);
}

private CrypticClue(String text, String npc, int objectId, @Nullable WorldPoint location, String solution, @Nullable String questionText)
private CrypticClue(String text, String npc, int objectId, @Nullable final WorldPoint location, String solution, @Nullable String questionText)
{
this(
text,
npc,
objectId,
location == null ? null : (_client) -> location,
solution,
questionText
);
}

private CrypticClue(String text, String npc, int objectId, @Nullable Function<ClueScrollPlugin, WorldPoint> locationProvider, String solution, @Nullable String questionText)
{
this.text = text;
this.npc = npc;
this.objectId = objectId;
this.location = location;
this.locationProvider = locationProvider;
this.solution = solution;
this.questionText = questionText;
setRequiresSpade(getLocation() != null && getNpc() == null && objectId == -1);
setRequiresSpade(locationProvider != null && getNpc() == null && objectId == -1);
}

@Nullable
public WorldPoint getLocation(ClueScrollPlugin plugin)
{
return locationProvider == null ? null : locationProvider.apply(plugin);
}

@Override
Expand Down Expand Up @@ -433,9 +458,10 @@ public void makeOverlayHint(PanelComponent panelComponent, ClueScrollPlugin plug
public void makeWorldOverlayHint(Graphics2D graphics, ClueScrollPlugin plugin)
{
// Mark dig location
if (getLocation() != null && getNpc() == null && objectId == -1)
WorldPoint location = getLocation(plugin);
if (location != null && getNpc() == null && objectId == -1)
{
LocalPoint localLocation = LocalPoint.fromWorld(plugin.getClient(), getLocation());
LocalPoint localLocation = LocalPoint.fromWorld(plugin.getClient(), location);

if (localLocation != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.stream.Stream;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import lombok.AccessLevel;
import lombok.Getter;
import net.runelite.api.Client;
import static net.runelite.api.EquipmentInventorySlot.AMMO;
Expand Down Expand Up @@ -230,6 +231,7 @@ public class EmoteClue extends ClueScroll implements LocationClueScroll
private final String locationName;
@Nullable
private final STASHUnit stashUnit;
@Getter(AccessLevel.PRIVATE)
private final WorldPoint location;
private final Emote firstEmote;
private final Emote secondEmote;
Expand Down Expand Up @@ -264,6 +266,12 @@ private EmoteClue(String text, String locationName, @Nullable STASHUnit stashUni
setFirePitVarbitId(firePitVarbitId);
}

@Override
public WorldPoint getLocation(ClueScrollPlugin plugin)
{
return location;
}

@Override
public void makeOverlayHint(PanelComponent panelComponent, ClueScrollPlugin plugin)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import net.runelite.client.ui.overlay.components.PanelComponent;
import net.runelite.client.ui.overlay.components.TitleComponent;

@Getter
public class FairyRingClue extends ClueScroll implements LocationClueScroll
{
static final List<FairyRingClue> CLUES = ImmutableList.of(
Expand All @@ -54,6 +53,7 @@ public class FairyRingClue extends ClueScroll implements LocationClueScroll
new FairyRingClue("D K S 2 3 1 0", new WorldPoint(2747, 3720, 0))
);

@Getter
private final String text;
private final WorldPoint location;

Expand All @@ -64,6 +64,12 @@ private FairyRingClue(String text, WorldPoint location)
setRequiresSpade(true);
}

@Override
public WorldPoint getLocation(ClueScrollPlugin plugin)
{
return location;
}

@Override
public void makeOverlayHint(PanelComponent panelComponent, ClueScrollPlugin plugin)
{
Expand All @@ -84,7 +90,7 @@ public void makeOverlayHint(PanelComponent panelComponent, ClueScrollPlugin plug
@Override
public void makeWorldOverlayHint(Graphics2D graphics, ClueScrollPlugin plugin)
{
LocalPoint localLocation = LocalPoint.fromWorld(plugin.getClient(), getLocation());
LocalPoint localLocation = LocalPoint.fromWorld(plugin.getClient(), getLocation(plugin));

if (localLocation == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -70,6 +71,7 @@ public class HotColdClue extends ClueScroll implements LocationClueScroll, Locat
private final String text;
private final String npc;
private final String solution;
@Getter(AccessLevel.PRIVATE)
private final WorldPoint npcLocation;
@Nullable
private HotColdSolver hotColdSolver;
Expand Down Expand Up @@ -102,7 +104,13 @@ private HotColdClue(String text, String npc, String solution, WorldPoint npcLoca
}

@Override
public WorldPoint[] getLocations()
public WorldPoint getLocation(ClueScrollPlugin plugin)
{
return location;
}

@Override
public WorldPoint[] getLocations(ClueScrollPlugin plugin)
{
if (hotColdSolver == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
package net.runelite.client.plugins.cluescrolls.clues;

import net.runelite.api.coords.WorldPoint;
import net.runelite.client.plugins.cluescrolls.ClueScrollPlugin;

public interface LocationClueScroll
{
WorldPoint getLocation();
WorldPoint getLocation(ClueScrollPlugin plugin);

default WorldPoint[] getLocations()
default WorldPoint[] getLocations(ClueScrollPlugin plugin)
{
WorldPoint location = getLocation();
WorldPoint location = getLocation(plugin);
return location == null ? new WorldPoint[0] : new WorldPoint[]{location};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
package net.runelite.client.plugins.cluescrolls.clues;

import net.runelite.api.coords.WorldPoint;
import net.runelite.client.plugins.cluescrolls.ClueScrollPlugin;

public interface LocationsClueScroll
{
void reset();

WorldPoint[] getLocations();
WorldPoint[] getLocations(ClueScrollPlugin plugin);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.awt.Color;
import java.awt.Graphics2D;
import java.util.List;
import lombok.AccessLevel;
import lombok.Getter;
import static net.runelite.api.ItemID.*;
import net.runelite.api.ObjectComposition;
Expand Down Expand Up @@ -95,6 +96,7 @@ public class MapClue extends ClueScroll implements ObjectClueScroll
);

private final int itemId;
@Getter(AccessLevel.PRIVATE)
private final WorldPoint location;
private final int objectId;
private final String description;
Expand All @@ -118,6 +120,12 @@ private MapClue(int itemId, WorldPoint location, int objectId, String descriptio
setRequiresSpade(objectId == -1);
}

@Override
public WorldPoint getLocation(ClueScrollPlugin plugin)
{
return location;
}

@Override
public void makeOverlayHint(PanelComponent panelComponent, ClueScrollPlugin plugin)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static MusicClue forText(String text)
}

@Override
public WorldPoint getLocation()
public WorldPoint getLocation(ClueScrollPlugin plugin)
{
return LOCATION;
}
Expand Down
Loading

0 comments on commit 4007dd4

Please sign in to comment.