Skip to content

Commit

Permalink
Fix detecting start of Untinker quest (#1106)
Browse files Browse the repository at this point in the history
* Fix detecting start of Untinker quest

* canAdventure and prepareForAdventure handle Degrassi Knoll

* fix typo
  • Loading branch information
Veracity0 committed Sep 21, 2022
1 parent 7453ea7 commit 647a252
Show file tree
Hide file tree
Showing 10 changed files with 964 additions and 732 deletions.
25 changes: 24 additions & 1 deletion src/net/sourceforge/kolmafia/KoLAdventure.java
Expand Up @@ -1348,7 +1348,14 @@ public boolean canAdventure() {
}

if (this.zone.equals("Degrassi Knoll")) {
return KoLCharacter.getSignZone() != ZodiacZone.KNOLL;
if (KoLCharacter.getSignZone() == ZodiacZone.KNOLL) {
return false;
}
// Either Paco or the Untinker will open the Knoll
// We can accept the Untinker's quest if the woods are open
return QuestDatabase.isQuestStarted(Quest.MEATCAR)
|| QuestDatabase.isQuestStarted(Quest.UNTINKER)
|| QuestDatabase.isQuestStarted(Quest.LARVA);
}

if (this.zone.equals("MusSign")) {
Expand Down Expand Up @@ -1923,6 +1930,22 @@ public boolean prepareForAdventure() {
return true;
}

if (this.zone.equals("Degrassi Knoll")) {
// Either Paco or the Untinker open the Knoll
if (QuestDatabase.isQuestStarted(Quest.MEATCAR)
|| QuestDatabase.isQuestStarted(Quest.UNTINKER)) {
return true;
}

// We can accept the Untinker's quest if the woods are open.
if (QuestDatabase.isQuestStarted(Quest.LARVA)) {
var request = new PlaceRequest("forestvillage", "fv_untinker_quest", true);
request.addFormField("preaction", "screwquest");
request.run();
}
return QuestDatabase.isQuestStarted(Quest.UNTINKER);
}

// Fighting the Goblin King requires effects
if (this.formSource.equals("cobbsknob.php")) {
if (EquipmentManager.isWearingOutfit(OutfitPool.HAREM_OUTFIT)) {
Expand Down
3 changes: 2 additions & 1 deletion src/net/sourceforge/kolmafia/request/GenericRequest.java
Expand Up @@ -87,7 +87,8 @@

public class GenericRequest implements Runnable {
// Used in many requests. Here for convenience and non-duplication
public static final Pattern ACTION_PATTERN = Pattern.compile("action=([^&]*)");
public static final Pattern PREACTION_PATTERN = Pattern.compile("preaction=([^&]*)");
public static final Pattern ACTION_PATTERN = Pattern.compile("(?<!pre)action=([^&]*)");
public static final Pattern PLACE_PATTERN = Pattern.compile("place=([^&]*)");
public static final Pattern WHICHITEM_PATTERN = Pattern.compile("whichitem=(\\d+)");
public static final Pattern HOWMANY_PATTERN = Pattern.compile("howmany=(\\d+)");
Expand Down
2 changes: 1 addition & 1 deletion src/net/sourceforge/kolmafia/request/PlaceRequest.java
Expand Up @@ -117,7 +117,7 @@ public static void parseResponse(final String urlString, final String responseTe
} else if (place.equals("falloutshelter")) {
FalloutShelterRequest.parseResponse(urlString, responseText);
} else if (place.equals("forestvillage")) {
if (action.equals("fv_untinker")) {
if (action.startsWith("fv_untinker")) {
UntinkerRequest.parseResponse(urlString, responseText);
}
} else if (place.startsWith("junggate")) {
Expand Down
11 changes: 6 additions & 5 deletions src/net/sourceforge/kolmafia/request/UntinkerRequest.java
Expand Up @@ -119,19 +119,20 @@ public void run() {
}

public static final void parseResponse(final String location, final String responseText) {
if (!location.contains("fv_untinker") && !location.contains("screwquest")) {
if (!location.contains("fv_untinker")) {
return;
}

// "Thanks! I'll tell ya, I'm just lost without my screwdriver. Here, lemme mark the Knoll on
// your map."
if (responseText.contains("I'm just lost without my screwdriver")
|| responseText.contains("I'll go find your screwdriver for you") // Zombie Slayer
) {
if (location.contains("screwquest")
&& (responseText.contains("I'm just lost without my screwdriver")
|| responseText.contains("I'll go find your screwdriver for you") // Zombie Slayer
)) {
QuestDatabase.setQuestProgress(Quest.UNTINKER, QuestDatabase.STARTED);
}

// If the quest is still in progross, no need to check anything else
// If the quest is still in progress, no need to check anything else
if (location.contains("fv_untinker_quest")) {
return;
}
Expand Down
78 changes: 78 additions & 0 deletions test/net/sourceforge/kolmafia/KoLAdventureValidationTest.java
Expand Up @@ -23,6 +23,7 @@
import static internal.helpers.Player.withRestricted;
import static internal.helpers.Player.withSign;
import static internal.matchers.Preference.isSetTo;
import static internal.matchers.Quest.isStarted;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasSize;
Expand Down Expand Up @@ -1148,6 +1149,83 @@ public void hauntedCellarNotAvailableWithOutQuest() {
}
}

@Nested
class DegrassiKnoll {
private static final KoLAdventure GARAGE =
AdventureDatabase.getAdventureByName("The Degrassi Knoll Garage");

@Test
public void hostileKnollNotAvailableInMuscleSign() {
var cleanups =
new Cleanups(
withSign(ZodiacSign.VOLE), withQuestProgress(Quest.UNTINKER, QuestDatabase.STARTED));
try (cleanups) {
assertFalse(GARAGE.canAdventure());
}
}

@Test
public void hostileKnollNotAvailableIfNotUnlocked() {
var cleanups =
new Cleanups(
withSign(ZodiacSign.PACKRAT),
withQuestProgress(Quest.UNTINKER, QuestDatabase.UNSTARTED),
withQuestProgress(Quest.MEATCAR, QuestDatabase.UNSTARTED),
withQuestProgress(Quest.LARVA, QuestDatabase.UNSTARTED));
try (cleanups) {
assertFalse(GARAGE.canAdventure());
}
}

@Test
public void hostileKnollAvailableIfUntinkerUnlocked() {
var cleanups =
new Cleanups(
withSign(ZodiacSign.PACKRAT),
withQuestProgress(Quest.UNTINKER, QuestDatabase.STARTED));
try (cleanups) {
assertTrue(GARAGE.canAdventure());
}
}

@Test
public void hostileKnollAvailableIfPacoUnlocked() {
var cleanups =
new Cleanups(
withSign(ZodiacSign.PACKRAT),
withQuestProgress(Quest.MEATCAR, QuestDatabase.STARTED));
try (cleanups) {
assertTrue(GARAGE.canAdventure());
}
}

@Test
public void willAcceptUntinkerQuestToUnlockHostileKnoll() {
var builder = new FakeHttpClientBuilder();
var cleanups =
new Cleanups(
withHttpClientBuilder(builder),
withSign(ZodiacSign.PACKRAT),
withQuestProgress(Quest.UNTINKER, QuestDatabase.UNSTARTED),
withQuestProgress(Quest.LARVA, QuestDatabase.STARTED));
try (cleanups) {
builder.client.addResponse(200, html("request/test_visit_untinker_accept_quest.html"));
builder.client.addResponse(200, ""); // api.php
assertTrue(GARAGE.canAdventure());
assertTrue(GARAGE.prepareForAdventure());
assertThat(Quest.UNTINKER, isStarted());

var requests = builder.client.getRequests();
assertThat(requests, hasSize(2));
assertPostRequest(
requests.get(0),
"/place.php",
"whichplace=forestvillage&action=fv_untinker_quest&preaction=screwquest");
assertPostRequest(requests.get(1), "/api.php", "what=status&for=KoLmafia");
}
}
}

@Nested
class Portal {
private static final KoLAdventure EL_VIBRATO =
Expand Down

0 comments on commit 647a252

Please sign in to comment.