Skip to content

Commit

Permalink
Detect whether crimbo23 locations are available and recheck when thin…
Browse files Browse the repository at this point in the history
…gs change (#2108)

Co-authored-by: Chris Midgley <chris.midgley@dunecomputers.co.uk>
  • Loading branch information
gausie and midgleyc committed Dec 17, 2023
1 parent 9957d20 commit 168c3cd
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/data/defaults.txt
Expand Up @@ -508,6 +508,11 @@ user crimbo16NippleChakraCleanliness 0
user crimbo16NoseChakraCleanliness 0
user crimbo16ReindeerChakraCleanliness 0
user crimbo16SackChakraCleanliness 0
user crimbo23ArmoryAtWar false
user crimbo23BarAtWar false
user crimbo23CafeAtWar false
user crimbo23CottageAtWar false
user crimbo23FoundryAtWar false
user crimboTrainingSkill 0
user crimboTreeDays 7
user crimbotChassis
Expand Down
22 changes: 21 additions & 1 deletion src/net/sourceforge/kolmafia/KoLAdventure.java
Expand Up @@ -1891,6 +1891,20 @@ public boolean canAdventure() {
return true;
}

if (this.zone.equals("Crimbo23")) {
return Preferences.getBoolean(
"crimbo23"
+ switch (this.adventureNumber) {
case AdventurePool.CRIMBO23_ARMORY -> "Armory";
case AdventurePool.CRIMBO23_BAR -> "Bar";
case AdventurePool.CRIMBO23_CAFE -> "Cafe";
case AdventurePool.CRIMBO23_COTTAGE -> "Cottage";
case AdventurePool.CRIMBO23_FOUNDRY -> "Foundry";
default -> "Unknown";
}
+ "AtWar");
}

// The rest of this method validates item-generated zones.
// We have already rejected items restricted by Standard.

Expand Down Expand Up @@ -4144,6 +4158,10 @@ public AdventureFailure(String responseText, String message) {
"You've already defeated the Trainbot boss.",
"Nothing more to do here.",
MafiaState.PENDING),
new AdventureFailure(
"Looks like peace has broken out in this area",
"The balance of power has shifted, you can no longer fight here",
MafiaState.PENDING)
};

private static final Pattern CRIMBO21_COLD_RES =
Expand All @@ -4152,7 +4170,7 @@ public AdventureFailure(String responseText, String message) {
public static int findAdventureFailure(String responseText) {
// KoL is known to sometimes simply return a blank page as a
// failure to adventure.
if (responseText.length() == 0) {
if (responseText.isEmpty()) {
return 0;
}

Expand All @@ -4175,6 +4193,8 @@ public static int findAdventureFailure(String responseText) {
int required = Integer.parseInt(matcher.group(1));
Preferences.setInteger("_crimbo21ColdResistance", required);
}
} else if (responseText.contains("Looks like peace has broken out in this area.")) {
RequestThread.postRequest(new GenericRequest("place.php?whichplace=crimbo23"));
}

for (int i = 1; i < ADVENTURE_FAILURES.length; ++i) {
Expand Down
5 changes: 5 additions & 0 deletions src/net/sourceforge/kolmafia/objectpool/AdventurePool.java
Expand Up @@ -295,6 +295,11 @@ public class AdventurePool {
public static final int VANYAS_CASTLE = 565;
public static final int MEGALO_CITY = 566;
public static final int SHADOW_RIFT = 567;
public static final int CRIMBO23_COTTAGE = 575;
public static final int CRIMBO23_FOUNDRY = 576;
public static final int CRIMBO23_BAR = 577;
public static final int CRIMBO23_CAFE = 578;
public static final int CRIMBO23_ARMORY = 579;

private AdventurePool() {}
}
7 changes: 7 additions & 0 deletions src/net/sourceforge/kolmafia/request/PlaceRequest.java
Expand Up @@ -172,6 +172,13 @@ public static void parseResponse(final String urlString, final String responseTe
Preferences.setBoolean("superconductorDefeated", true);
}
}
case "crimbo23" -> {
Preferences.setBoolean("crimbo23ArmoryAtWar", responseText.contains("armory_war.gif"));
Preferences.setBoolean("crimbo23BarAtWar", responseText.contains("bar_war.gif"));
Preferences.setBoolean("crimbo23CafeAtWar", responseText.contains("cafe_war.gif"));
Preferences.setBoolean("crimbo23CottageAtWar", responseText.contains("abuela_war.gif"));
Preferences.setBoolean("crimbo23FoundryAtWar", responseText.contains("factory_war.gif"));
}
case "desertbeach" -> {
if ("db_nukehouse".equals(action)) {
if (responseText.contains("anticheese")) {
Expand Down
28 changes: 28 additions & 0 deletions test/net/sourceforge/kolmafia/KoLAdventureValidationTest.java
Expand Up @@ -7523,4 +7523,32 @@ public void canOnlyAdventureInDirtWhenSmall(boolean inRun) {
}
}
}

@Nested
class Crimbo23 {
@Test
void checksTownAfterWarChange() {
var builder = new FakeHttpClientBuilder();
var cleanups =
new Cleanups(
withHttpClientBuilder(builder),
withProperty("crimbo23ArmoryAtWar", false),
withProperty("crimbo23BarAtWar", false),
withProperty("crimbo23CafeAtWar", false),
withProperty("crimbo23CottageAtWar", false),
withProperty("crimbo23FoundryAtWar", false));
try (cleanups) {
builder.client.addResponse(200, html("request/test_place_crimbo23_1.html"));

var failure =
KoLAdventure.findAdventureFailure(html("request/test_adventure_crimbo23_peace.html"));
assertThat(failure, greaterThan(0));
assertThat("crimbo23ArmoryAtWar", isSetTo(false));
assertThat("crimbo23BarAtWar", isSetTo(true));
assertThat("crimbo23CafeAtWar", isSetTo(false));
assertThat("crimbo23CottageAtWar", isSetTo(true));
assertThat("crimbo23FoundryAtWar", isSetTo(false));
}
}
}
}
28 changes: 28 additions & 0 deletions test/net/sourceforge/kolmafia/request/PlaceRequestTest.java
Expand Up @@ -245,4 +245,32 @@ public void getawayRemainsUnchangedAfterVisitingLockedDistantWoods() {
}
}
}

@Nested
class Crimbo23 {
@Test
void parsesWarState() {
var builder = new FakeHttpClientBuilder();
var cleanups =
new Cleanups(
withHttpClientBuilder(builder),
withProperty("crimbo23ArmoryAtWar", false),
withProperty("crimbo23BarAtWar", false),
withProperty("crimbo23CafeAtWar", false),
withProperty("crimbo23CottageAtWar", false),
withProperty("crimbo23FoundryAtWar", false));
try (cleanups) {
builder.client.addResponse(200, html("request/test_place_crimbo23_1.html"));

var request = new PlaceRequest("crimbo23");
request.run();

assertThat("crimbo23ArmoryAtWar", isSetTo(false));
assertThat("crimbo23BarAtWar", isSetTo(true));
assertThat("crimbo23CafeAtWar", isSetTo(false));
assertThat("crimbo23CottageAtWar", isSetTo(true));
assertThat("crimbo23FoundryAtWar", isSetTo(false));
}
}
}
}
1 change: 1 addition & 0 deletions test/root/request/test_adventure_crimbo23_peace.html
@@ -0,0 +1 @@
<html><head><script language=Javascript><!--if (parent.frames.length == 0) location.href="game.php";top.charpane.location.href="charpane.php";//--></script><script language=Javascript src="https://d2uyhvukfffg5a.cloudfront.net/scripts/keybinds.min.2.js"></script><script language=Javascript src="https://d2uyhvukfffg5a.cloudfront.net/scripts/window.20111231.js"></script><script language="javascript">function chatFocus(){if(top.chatpane.document.chatform.graf) top.chatpane.document.chatform.graf.focus();}if (typeof defaultBind != 'undefined') { defaultBind(47, 2, chatFocus); defaultBind(190, 2, chatFocus);defaultBind(191, 2, chatFocus); defaultBind(47, 8, chatFocus);defaultBind(190, 8, chatFocus); defaultBind(191, 8, chatFocus); }</script><script>function switchFocus(){if (top.chatpane.document.chatform.graf.focus)top.chatpane.document.chatform.graf.focus();return false;}function repeat(){var linx = document.getElementsByTagName("A");for (var i = 0; i < linx.length; i++){if (typeof timersfunc != 'undefined') {if (!timersfunc()) {return;}timersfunc = null;}var link = linx[i];if (link.innerHTML.match(/Adventure Again/) || link.innerHTML.match(/Do it again/))location.href = link.href;}}defaultBind(47, CTRL, switchFocus);defaultBind(191, CTRL, switchFocus);defaultBind(47, META, switchFocus);defaultBind(191, META, switchFocus);defaultBind(192, NONE, repeat);defaultBind(220, NONE, repeat);</script><script language="javascript">function updateParseItem(iid, field, info) {var tbl = $('#ic'+iid);var data = parseItem(tbl);if (!data) return;data[field] = info;var out = [];for (i in data) {if (!data.hasOwnProperty(i)) continue;out.push(i+'='+data[i]);}tbl.attr('rel', out.join('&'));}function parseItem(tbl) {tbl = $(tbl);var rel = tbl.attr('rel');var data = {};if (!rel) return data;var parts = rel.split('&');for (i in parts) {if (!parts.hasOwnProperty(i)) continue;var kv = parts[i].split('=');tbl.data(kv[0], kv[1]);data[kv[0]] = kv[1];}return data;}</script><script language=Javascript src="https://d2uyhvukfffg5a.cloudfront.net/scripts/jquery-1.3.1.min.js"></script><script type="text/javascript" src="https://d2uyhvukfffg5a.cloudfront.net/scripts/pop_query.20230713.js"></script><script type="text/javascript"> function pop_ircm(clicked) { return false; } </script> <link rel="stylesheet" type="text/css" href="https://d2uyhvukfffg5a.cloudfront.net/styles.20230117d.css"><style type='text/css'>.faded {zoom: 1;filter: alpha(opacity=35);opacity: 0.35;-khtml-opacity: 0.35;-moz-opacity: 0.35;}</style></head><body><centeR><!--faaaaaaart--><table width=95% cellspacing=0 cellpadding=0><tr><td style="color: white;" align=center bgcolor=blue><b>Adventure Results:</b></td></tr><tr><td style="padding: 5px; border: 1px solid blue;"><center><table><tr><td>Looks like peace has broken out in this area.<p><center><a href='place.php?whichplace=crimbo23'>Back to Crimbo Town</a></center><center><center></center><!--skipagainmenu--></center></td></tr></table></center></td></tr><tr><td height=4></td></tr></table><!--faaaaaaart--></centeR></body></html>
1 change: 1 addition & 0 deletions test/root/request/test_place_crimbo23_1.html
@@ -0,0 +1 @@
<html><head><script language=Javascript><!--if (parent.frames.length == 0) location.href="game.php";//--></script><script language=Javascript src="https://d2uyhvukfffg5a.cloudfront.net/scripts/keybinds.min.2.js"></script><script language=Javascript src="https://d2uyhvukfffg5a.cloudfront.net/scripts/window.20111231.js"></script><script language="javascript">function chatFocus(){if(top.chatpane.document.chatform.graf) top.chatpane.document.chatform.graf.focus();}if (typeof defaultBind != 'undefined') { defaultBind(47, 2, chatFocus); defaultBind(190, 2, chatFocus);defaultBind(191, 2, chatFocus); defaultBind(47, 8, chatFocus);defaultBind(190, 8, chatFocus); defaultBind(191, 8, chatFocus); }</script><script language="javascript">function updateParseItem(iid, field, info) {var tbl = $('#ic'+iid);var data = parseItem(tbl);if (!data) return;data[field] = info;var out = [];for (i in data) {if (!data.hasOwnProperty(i)) continue;out.push(i+'='+data[i]);}tbl.attr('rel', out.join('&'));}function parseItem(tbl) {tbl = $(tbl);var rel = tbl.attr('rel');var data = {};if (!rel) return data;var parts = rel.split('&');for (i in parts) {if (!parts.hasOwnProperty(i)) continue;var kv = parts[i].split('=');tbl.data(kv[0], kv[1]);data[kv[0]] = kv[1];}return data;}</script><script language=Javascript src="https://d2uyhvukfffg5a.cloudfront.net/scripts/jquery-1.3.1.min.js"></script><script type="text/javascript" src="https://d2uyhvukfffg5a.cloudfront.net/scripts/pop_query.20230713.js"></script><script type="text/javascript"> function pop_ircm(clicked) { return false; } </script> <link rel="stylesheet" type="text/css" href="https://d2uyhvukfffg5a.cloudfront.net/styles.20230117d.css"><style type='text/css'>.faded {zoom: 1;filter: alpha(opacity=35);opacity: 0.35;-khtml-opacity: 0.35;-moz-opacity: 0.35;}</style></head><body><centeR><table width=95% cellspacing=0 cellpadding=0><tr><td style="color: white;" align=center bgcolor=blue><b>Crimbo Town</b></td></tr><tr><td style="padding: 5px; border: 1px solid blue;"><center><table><tr><td><center><div id=background style='position: relative; width:600px;height:500px' ><img id="place_bg" src="https://d2uyhvukfffg5a.cloudfront.net/otherimages/crimbo23/ctownbg.gif" width=600 height=500 border=0><div id=crimbo23_armory_elf class="element" style=' position: absolute; top: 110; left: 444; height: 100; width: 100;'><a href=shop.php?whichshop=crimbo23_elf_armory><img src="https://d2uyhvukfffg5a.cloudfront.net/otherimages/crimbo23/armory_elf.gif" width=100 height=100 border=0 alt="Elf Guard Armory" title="Elf Guard Armory"></a></div><div id=crimbo23_aubela_war class="element" style=' position: absolute; top: 0; left: 217; height: 108; width: 100;'><a href=adventure.php?snarfblat=575><img src="https://d2uyhvukfffg5a.cloudfront.net/otherimages/crimbo23/abuela_war.gif" width=100 height=108 border=0 alt="Abuela's Cottage (Contested) (1)" title="Abuela's Cottage (Contested) (1)"></a></div><div id=crimbo23_bar_war class="element" style=' position: absolute; top: 310; left: 120; height: 120; width: 100;'><a href=adventure.php?snarfblat=577><img src="https://d2uyhvukfffg5a.cloudfront.net/otherimages/crimbo23/bar_war.gif" width=100 height=120 border=0 alt="The Bar At War (1)" title="The Bar At War (1)"></a></div><div id=crimbo23_bigtree class="element" style=' position: absolute; top: 152; left: 252; height: 200; width: 106;'><img src="https://d2uyhvukfffg5a.cloudfront.net/otherimages/crimbo23/bigtree.gif" width=106 height=200 border=0 alt="" title=""></div><div id=crimbo23_cafe_elf class="element" style=' position: absolute; top: 112; left: 100; height: 125; width: 100;'><a href=shop.php?whichshop=crimbo23_elf_cafe><img src="https://d2uyhvukfffg5a.cloudfront.net/otherimages/crimbo23/cafe_elf.gif" width=100 height=125 border=0 alt="Elf Guard Mess Hall" title="Elf Guard Mess Hall"></a></div><div id=crimbo23_factory_pirate class="element" style=' position: absolute; top: 278; left: 380; height: 175; width: 150;'><a href=shop.php?whichshop=crimbo23_pirate_factory><img src="https://d2uyhvukfffg5a.cloudfront.net/otherimages/crimbo23/factory_pirate.gif" width=150 height=175 border=0 alt="Pirate Foundry" title="Pirate Foundry"></a></div><div id=crimbo23_xammy class="element" style=' position: absolute; top: 6; left: 372; height: 85; width: 96;'><a href=place.php?whichplace=crimbo23&action=crimbo23_xammy><img src="https://d2uyhvukfffg5a.cloudfront.net/otherimages/crimbo23/commandtent.gif" width=96 height=85 border=0 alt="Elf Guard Command Tent" title="Elf Guard Command Tent"></a></div></div><p><a href=place.php?whichplace=mountains>Back to the Big Mountains</a></center></td></tr></table></center></td></tr><tr><td height=4></td></tr></table></center></body></html>

0 comments on commit 168c3cd

Please sign in to comment.