Skip to content

Commit

Permalink
Merge branch 'main' into workflow-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gausie committed Sep 12, 2022
2 parents 3f683e7 + 20eb916 commit 06fa967
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
30 changes: 11 additions & 19 deletions src/net/sourceforge/kolmafia/session/CrystalBallManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public final class CrystalBallManager {
Pattern.compile("if you stick around here you're going to run into <b>an? (.*?)</b>")
};

private static final AdventureResult ORB = ItemPool.get(ItemPool.MINIATURE_CRYSTAL_BALL);

private CrystalBallManager() {}

public static class Prediction implements Comparable<Prediction> {
Expand Down Expand Up @@ -151,15 +153,13 @@ public static void updateCrystalBallPredictions() {
}

// EncounterManager methods
private static boolean isEquipped() {
return KoLCharacter.hasEquipped(ORB, EquipmentManager.FAMILIAR);
}

public static boolean isCrystalBallZone(final String zone) {
for (final Prediction prediction : CrystalBallManager.predictions.values()) {
if (prediction.location.equalsIgnoreCase(zone)) {
return true;
}
}

return false;
if (!isEquipped()) return false;
return predictions.values().stream().anyMatch(p -> p.location.equalsIgnoreCase(zone));
}

public static boolean isCrystalBallMonster() {
Expand All @@ -174,17 +174,9 @@ public static boolean isCrystalBallMonster(final MonsterData monster, final Stri
public static boolean isCrystalBallMonster(final String monster, final String zone) {
// There's no message to check for so assume the correct monster in the correct zone is from the
// crystal ball (if it is equipped)
AdventureResult ORB = ItemPool.get(ItemPool.MINIATURE_CRYSTAL_BALL, 1);
if (KoLCharacter.hasEquipped(ORB, EquipmentManager.FAMILIAR)) {
for (final Prediction prediction : CrystalBallManager.predictions.values()) {
if (prediction.monster.equalsIgnoreCase(monster)
&& prediction.location.equalsIgnoreCase(zone)) {
return true;
}
}
}

return false;
if (!isEquipped()) return false;
return predictions.values().stream()
.anyMatch(p -> p.monster.equalsIgnoreCase(monster) && p.location.equalsIgnoreCase(zone));
}

public static boolean own() {
Expand All @@ -198,7 +190,7 @@ public static void ponder() {
RequestThread.postRequest(new GenericRequest("inventory.php?ponder=1", false));
}

private static Pattern POSSIBLE_PREDICTION =
private static final Pattern POSSIBLE_PREDICTION =
Pattern.compile("<li> +(?:an?|the|some)? ?(.*?) in (.*?)</li>");

public static void parsePonder(final String responseText) {
Expand Down
13 changes: 10 additions & 3 deletions test/net/sourceforge/kolmafia/session/CrystalBallManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,16 @@ public void beforeEach() {

@Test
public void crystalBallZoneTest() {
assertTrue(CrystalBallManager.isCrystalBallZone("The Smut Orc Logging Camp"));
assertTrue(CrystalBallManager.isCrystalBallZone("The Defiled Nook"));
assertFalse(CrystalBallManager.isCrystalBallZone("The Defiled Niche"));
var cleanups =
new Cleanups(
withFamiliar(FamiliarPool.BADGER),
withEquipped(EquipmentManager.FAMILIAR, "miniature crystal ball"));

try (cleanups) {
assertTrue(CrystalBallManager.isCrystalBallZone("The Smut Orc Logging Camp"));
assertTrue(CrystalBallManager.isCrystalBallZone("The Defiled Nook"));
assertFalse(CrystalBallManager.isCrystalBallZone("The Defiled Niche"));
}
}

@ParameterizedTest
Expand Down

0 comments on commit 06fa967

Please sign in to comment.