Properly update 3 step cryptic clues on step completion
- Reset NPCs - Reset Object ids - Reset locations Closes #5923 Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -238,7 +238,12 @@ public class ClueScrollPlugin extends Plugin
|
|||||||
// if three step clue check for clue scroll pieces
|
// if three step clue check for clue scroll pieces
|
||||||
if (clue instanceof ThreeStepCrypticClue)
|
if (clue instanceof ThreeStepCrypticClue)
|
||||||
{
|
{
|
||||||
((ThreeStepCrypticClue) clue).checkForParts(client, event, itemManager);
|
if (((ThreeStepCrypticClue) clue).update(client, event, itemManager))
|
||||||
|
{
|
||||||
|
worldMapPointsSet = false;
|
||||||
|
npcsToMark.clear();
|
||||||
|
checkClueNPCs(clue, client.getCachedNPCs());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.InventoryID;
|
import net.runelite.api.InventoryID;
|
||||||
import net.runelite.api.Item;
|
import net.runelite.api.Item;
|
||||||
@@ -50,32 +51,42 @@ import net.runelite.client.ui.overlay.components.TitleComponent;
|
|||||||
import net.runelite.client.util.Text;
|
import net.runelite.client.util.Text;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class ThreeStepCrypticClue extends ClueScroll implements TextClueScroll, ObjectClueScroll, NpcClueScroll, LocationsClueScroll
|
public class ThreeStepCrypticClue extends ClueScroll implements TextClueScroll, ObjectClueScroll, NpcClueScroll, LocationsClueScroll
|
||||||
{
|
{
|
||||||
private final List<Map.Entry<CrypticClue, Boolean>> clueSteps;
|
public static ThreeStepCrypticClue forText(String plainText, String text)
|
||||||
private final int[] objectIds;
|
|
||||||
private final String[] npcs;
|
|
||||||
private final String text;
|
|
||||||
private WorldPoint[] locations;
|
|
||||||
|
|
||||||
private ThreeStepCrypticClue(List<Map.Entry<CrypticClue, Boolean>> steps, String text)
|
|
||||||
{
|
{
|
||||||
final int numClueSteps = steps.size();
|
final String[] split = text.split("<br>\\s*<br>");
|
||||||
this.clueSteps = steps;
|
final List<Map.Entry<CrypticClue, Boolean>> steps = new ArrayList<>(split.length);
|
||||||
this.text = text;
|
|
||||||
this.locations = new WorldPoint[numClueSteps];
|
|
||||||
this.npcs = new String[numClueSteps];
|
|
||||||
this.objectIds = new int[numClueSteps];
|
|
||||||
|
|
||||||
for (int i = 0; i < numClueSteps; i++)
|
for (String part : split)
|
||||||
{
|
{
|
||||||
final CrypticClue c = clueSteps.get(i).getKey();
|
boolean isDone = part.contains("<str>");
|
||||||
locations[i] = c.getLocation();
|
final String rawText = Text.sanitizeMultilineText(part);
|
||||||
npcs[i] = c.getNpc();
|
|
||||||
objectIds[i] = c.getObjectId();
|
for (CrypticClue clue : CrypticClue.CLUES)
|
||||||
|
{
|
||||||
|
if (!rawText.equalsIgnoreCase(clue.getText()))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
steps.add(new AbstractMap.SimpleEntry<>(clue, isDone));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (steps.isEmpty() || steps.size() < 3)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ThreeStepCrypticClue(steps, plainText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final List<Map.Entry<CrypticClue, Boolean>> clueSteps;
|
||||||
|
private final String text;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void makeOverlayHint(PanelComponent panelComponent, ClueScrollPlugin plugin)
|
public void makeOverlayHint(PanelComponent panelComponent, ClueScrollPlugin plugin)
|
||||||
{
|
{
|
||||||
@@ -111,61 +122,46 @@ public class ThreeStepCrypticClue extends ClueScroll implements TextClueScroll,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkForParts(Client client, final ItemContainerChanged event, ItemManager itemManager)
|
public boolean update(Client client, final ItemContainerChanged event, ItemManager itemManager)
|
||||||
{
|
{
|
||||||
if (event.getItemContainer() == client.getItemContainer(InventoryID.INVENTORY))
|
if (event.getItemContainer() == client.getItemContainer(InventoryID.INVENTORY))
|
||||||
{
|
{
|
||||||
checkForPart(event, itemManager, TORN_CLUE_SCROLL_PART_1, 0);
|
boolean success = false;
|
||||||
checkForPart(event, itemManager, TORN_CLUE_SCROLL_PART_2, 1);
|
success |= checkForPart(event, itemManager, TORN_CLUE_SCROLL_PART_1, 0);
|
||||||
checkForPart(event, itemManager, TORN_CLUE_SCROLL_PART_3, 2);
|
success |= checkForPart(event, itemManager, TORN_CLUE_SCROLL_PART_2, 1);
|
||||||
|
success |= checkForPart(event, itemManager, TORN_CLUE_SCROLL_PART_3, 2);
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkForPart(final ItemContainerChanged event, ItemManager itemManager, int clueScrollPart, int index)
|
private boolean checkForPart(final ItemContainerChanged event, ItemManager itemManager, int clueScrollPart, int index)
|
||||||
{
|
{
|
||||||
final Stream<Item> items = Arrays.stream(event.getItemContainer().getItems());
|
final Stream<Item> items = Arrays.stream(event.getItemContainer().getItems());
|
||||||
|
|
||||||
// If we have the part then that step is done
|
// If we have the part then that step is done
|
||||||
if (items.anyMatch(item -> itemManager.getItemComposition(item.getId()).getId() == clueScrollPart))
|
if (items.anyMatch(item -> itemManager.getItemComposition(item.getId()).getId() == clueScrollPart))
|
||||||
{
|
{
|
||||||
clueSteps.get(index).setValue(true);
|
final Map.Entry<CrypticClue, Boolean> entry = clueSteps.get(index);
|
||||||
|
|
||||||
|
if (!entry.getValue())
|
||||||
|
{
|
||||||
|
entry.setValue(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reset()
|
public void reset()
|
||||||
{
|
{
|
||||||
this.locations = new WorldPoint[] {};
|
for (Map.Entry<CrypticClue, Boolean> clueStep : clueSteps)
|
||||||
}
|
|
||||||
|
|
||||||
public static ThreeStepCrypticClue forText(String plainText, String text)
|
|
||||||
{
|
|
||||||
final String[] split = text.split("<br>\\s*<br>");
|
|
||||||
final List<Map.Entry<CrypticClue, Boolean>> steps = new ArrayList<>(split.length);
|
|
||||||
|
|
||||||
for (String part : split)
|
|
||||||
{
|
{
|
||||||
boolean isDone = part.contains("<str>");
|
clueStep.setValue(false);
|
||||||
final String rawText = Text.sanitizeMultilineText(part);
|
|
||||||
|
|
||||||
for (CrypticClue clue : CrypticClue.CLUES)
|
|
||||||
{
|
|
||||||
if (!rawText.equalsIgnoreCase(clue.getText()))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
steps.add(new AbstractMap.SimpleEntry<>(clue, isDone));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (steps.isEmpty() || steps.size() < 3)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ThreeStepCrypticClue(steps, plainText);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -173,4 +169,31 @@ public class ThreeStepCrypticClue extends ClueScroll implements TextClueScroll,
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WorldPoint[] getLocations()
|
||||||
|
{
|
||||||
|
return clueSteps.stream()
|
||||||
|
.filter(s -> !s.getValue())
|
||||||
|
.map(s -> s.getKey().getLocation())
|
||||||
|
.toArray(WorldPoint[]::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getNpcs()
|
||||||
|
{
|
||||||
|
return clueSteps.stream()
|
||||||
|
.filter(s -> !s.getValue())
|
||||||
|
.map(s -> s.getKey().getNpc())
|
||||||
|
.toArray(String[]::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int[] getObjectIds()
|
||||||
|
{
|
||||||
|
return clueSteps.stream()
|
||||||
|
.filter(s -> !s.getValue())
|
||||||
|
.mapToInt(s -> s.getKey().getObjectId())
|
||||||
|
.toArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user