Move Hot/Cold message logic to HotColdClue
Instead of having giant chunk of logic related to only Hot/Cold clues, move this logic inside the HotColdClue class. Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -34,8 +34,6 @@ import java.time.Duration;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@@ -95,10 +93,6 @@ public class ClueScrollPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
private static final Duration WAIT_DURATION = Duration.ofMinutes(4);
|
private static final Duration WAIT_DURATION = Duration.ofMinutes(4);
|
||||||
|
|
||||||
private static final Pattern INITIAL_STRANGE_DEVICE_MESSAGE = Pattern.compile("The device is (.*)");
|
|
||||||
private static final Pattern STRANGE_DEVICE_MESSAGE = Pattern.compile("The device is (.*), (.*) last time\\.");
|
|
||||||
private static final Pattern FINAL_STRANGE_DEVICE_MESSAGE = Pattern.compile("The device is visibly shaking.*");
|
|
||||||
|
|
||||||
public static final BufferedImage CLUE_SCROLL_IMAGE;
|
public static final BufferedImage CLUE_SCROLL_IMAGE;
|
||||||
public static final BufferedImage MAP_ARROW;
|
public static final BufferedImage MAP_ARROW;
|
||||||
public static final BufferedImage EMOTE_IMAGE;
|
public static final BufferedImage EMOTE_IMAGE;
|
||||||
@@ -193,46 +187,9 @@ public class ClueScrollPlugin extends Plugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clue instanceof HotColdClue && event.getMessage().startsWith("The device is"))
|
if (clue instanceof HotColdClue)
|
||||||
{
|
{
|
||||||
HotColdClue hotColdClue = (HotColdClue) clue;
|
((HotColdClue)clue).update(event.getMessage(), this);
|
||||||
String message = event.getMessage();
|
|
||||||
Matcher m1 = FINAL_STRANGE_DEVICE_MESSAGE.matcher(message);
|
|
||||||
Matcher m2 = STRANGE_DEVICE_MESSAGE.matcher(message);
|
|
||||||
Matcher m3 = INITIAL_STRANGE_DEVICE_MESSAGE.matcher(message);
|
|
||||||
|
|
||||||
// the order that these pattern matchers are checked is important
|
|
||||||
if (m1.find())
|
|
||||||
{
|
|
||||||
// final location for hot cold clue has been found
|
|
||||||
WorldPoint localWorld = client.getLocalPlayer().getWorldLocation();
|
|
||||||
|
|
||||||
if (localWorld != null)
|
|
||||||
{
|
|
||||||
hotColdClue.markFinalSpot(localWorld);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (m2.find())
|
|
||||||
{
|
|
||||||
String temperature = m2.group(1);
|
|
||||||
String difference = m2.group(2);
|
|
||||||
WorldPoint localWorld = client.getLocalPlayer().getWorldLocation();
|
|
||||||
|
|
||||||
if (localWorld != null)
|
|
||||||
{
|
|
||||||
hotColdClue.updatePossibleArea(localWorld, temperature, difference);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (m3.find())
|
|
||||||
{
|
|
||||||
String temperature = m3.group(1);
|
|
||||||
WorldPoint localWorld = client.getLocalPlayer().getWorldLocation();
|
|
||||||
|
|
||||||
if (localWorld != null)
|
|
||||||
{
|
|
||||||
hotColdClue.updatePossibleArea(localWorld, temperature, "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!event.getMessage().equals("The strange device cools as you find your treasure.")
|
if (!event.getMessage().equals("The strange device cools as you find your treasure.")
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ import java.util.Arrays;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import net.runelite.api.NPC;
|
import net.runelite.api.NPC;
|
||||||
@@ -58,6 +60,9 @@ import net.runelite.client.ui.overlay.components.TitleComponent;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class HotColdClue extends ClueScroll implements TextClueScroll, NpcClueScroll
|
public class HotColdClue extends ClueScroll implements TextClueScroll, NpcClueScroll
|
||||||
{
|
{
|
||||||
|
private static final Pattern INITIAL_STRANGE_DEVICE_MESSAGE = Pattern.compile("The device is (.*)");
|
||||||
|
private static final Pattern STRANGE_DEVICE_MESSAGE = Pattern.compile("The device is (.*), (.*) last time\\.");
|
||||||
|
private static final Pattern FINAL_STRANGE_DEVICE_MESSAGE = Pattern.compile("The device is visibly shaking.*");
|
||||||
private static final HotColdClue CLUE =
|
private static final HotColdClue CLUE =
|
||||||
new HotColdClue("Buried beneath the ground, who knows where it's found. Lucky for you, A man called Jorral may have a clue.",
|
new HotColdClue("Buried beneath the ground, who knows where it's found. Lucky for you, A man called Jorral may have a clue.",
|
||||||
"Jorral",
|
"Jorral",
|
||||||
@@ -235,7 +240,52 @@ public class HotColdClue extends ClueScroll implements TextClueScroll, NpcClueSc
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePossibleArea(WorldPoint currentWp, String temperature, String difference)
|
public void update(final String message, final ClueScrollPlugin plugin)
|
||||||
|
{
|
||||||
|
if (!message.startsWith("The device is"))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Matcher m1 = FINAL_STRANGE_DEVICE_MESSAGE.matcher(message);
|
||||||
|
Matcher m2 = STRANGE_DEVICE_MESSAGE.matcher(message);
|
||||||
|
Matcher m3 = INITIAL_STRANGE_DEVICE_MESSAGE.matcher(message);
|
||||||
|
|
||||||
|
// the order that these pattern matchers are checked is important
|
||||||
|
if (m1.find())
|
||||||
|
{
|
||||||
|
// final location for hot cold clue has been found
|
||||||
|
WorldPoint localWorld = plugin.getClient().getLocalPlayer().getWorldLocation();
|
||||||
|
|
||||||
|
if (localWorld != null)
|
||||||
|
{
|
||||||
|
markFinalSpot(localWorld);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (m2.find())
|
||||||
|
{
|
||||||
|
String temperature = m2.group(1);
|
||||||
|
String difference = m2.group(2);
|
||||||
|
WorldPoint localWorld = plugin.getClient().getLocalPlayer().getWorldLocation();
|
||||||
|
|
||||||
|
if (localWorld != null)
|
||||||
|
{
|
||||||
|
updatePossibleArea(localWorld, temperature, difference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (m3.find())
|
||||||
|
{
|
||||||
|
String temperature = m3.group(1);
|
||||||
|
WorldPoint localWorld = plugin.getClient().getLocalPlayer().getWorldLocation();
|
||||||
|
|
||||||
|
if (localWorld != null)
|
||||||
|
{
|
||||||
|
updatePossibleArea(localWorld, temperature, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updatePossibleArea(WorldPoint currentWp, String temperature, String difference)
|
||||||
{
|
{
|
||||||
this.location = null;
|
this.location = null;
|
||||||
|
|
||||||
@@ -347,7 +397,7 @@ public class HotColdClue extends ClueScroll implements TextClueScroll, NpcClueSc
|
|||||||
return (firstDistance < secondDistance);
|
return (firstDistance < secondDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markFinalSpot(WorldPoint wp)
|
private void markFinalSpot(WorldPoint wp)
|
||||||
{
|
{
|
||||||
this.location = wp;
|
this.location = wp;
|
||||||
resetHotCold();
|
resetHotCold();
|
||||||
|
|||||||
Reference in New Issue
Block a user