Skip to content

Commit

Permalink
Fix UseSkillRequest bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Veracity0 committed Nov 9, 2022
1 parent 4409975 commit e320d24
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 11 deletions.
17 changes: 10 additions & 7 deletions src/net/sourceforge/kolmafia/persistence/SkillDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -701,13 +701,16 @@ public static final boolean hasVariableMpCost(final int skillId) {
* @return true if it comes from a Libram
*/
public static final boolean isLibramSkill(final int skillId) {
return skillId == SkillPool.CANDY_HEART
|| skillId == SkillPool.PARTY_FAVOR
|| skillId == SkillPool.LOVE_SONG
|| skillId == SkillPool.BRICKOS
|| skillId == SkillPool.DICE
|| skillId == SkillPool.RESOLUTIONS
|| skillId == SkillPool.TAFFY;
return switch (skillId) {
case SkillPool.CANDY_HEART,
SkillPool.PARTY_FAVOR,
SkillPool.LOVE_SONG,
SkillPool.BRICKOS,
SkillPool.DICE,
SkillPool.RESOLUTIONS,
SkillPool.TAFFY -> true;
default -> false;
};
}

/**
Expand Down
7 changes: 3 additions & 4 deletions src/net/sourceforge/kolmafia/request/UseSkillRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -832,8 +832,7 @@ public static final void optimizeEquipment(final int skillId) {
}
}
}
case SkillPool.SWEAT_OUT_BOOZE,
SkillPool.MAKE_SWEATADE,
case SkillPool.MAKE_SWEATADE,
SkillPool.DRENCH_YOURSELF_IN_SWEAT,
SkillPool.SIP_SOME_SWEAT -> {
AdventureResult item = UseSkillRequest.DESIGNER_SWEATPANTS;
Expand Down Expand Up @@ -1775,8 +1774,8 @@ private static SkillStatus responseStatus(final String responseText, int skillId
if (limitedMatcher.find()) {
// parse the number of casts remaining and set the appropriate preference.
int casts = Integer.parseInt(limitedMatcher.group(1));

limit.set(casts);
// We will increment this later. For now, just synch with KoL.
limit.set(casts - count);
}
}

Expand Down
39 changes: 39 additions & 0 deletions test/net/sourceforge/kolmafia/request/UseSkillRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class UseSkillRequestTest {
@BeforeAll
static void beforeAll() {
KoLCharacter.reset("UseSkillRequestTest");
}

@BeforeEach
void beforeEach() {
Preferences.reset("UseSkillRequestTest");
}

Expand Down Expand Up @@ -153,6 +157,23 @@ void canOnlyCastBenettonsInRightState(String className, int level, boolean canCa
}
}

@Test
void incrementsUsageForLimitedSkills() {
var cleanups =
new Cleanups(
withMP(1000, 1000, 1000),
withSkill(SkillPool.DONHOS),
withProperty("_donhosCasts", 1),
withClass(AscensionClass.ACCORDION_THIEF),
withLevel(15),
withNextResponse(200, html("request/test_cast_donhos_bubbly_ballad.html")));
try (cleanups) {
UseSkillRequest req = UseSkillRequest.getInstance(SkillPool.DONHOS, "me", 5);
req.run();
assertThat("_donhosCasts", isSetTo(6));
}
}

@Nested
class DesignerSweatpants {
@BeforeEach
Expand Down Expand Up @@ -192,6 +213,24 @@ void wearDesignerSweatpantsForCastingSweatSkills() {
requests.get(0), "/inv_equip.php", "which=2&ajax=1&action=equip&whichitem=10929");
assertGetRequest(
requests.get(1), "/runskillz.php", "action=Skillz&whichskill=7419&ajax=1&quantity=1");
assertPostRequest(requests.get(2), "/api.php", "what=status&for=KoLmafia");
}
}

@Test
void dontWearDesignerSweatpantsForSweatingOutBooze() {
var cleanups = new Cleanups(withEquippableItem("designer sweatpants"));
InventoryManager.checkDesignerSweatpants();

try (cleanups) {
var req = UseSkillRequest.getInstance("Sweat Out Some Booze", 1);
req.run();

var requests = getRequests();
assertThat(requests, hasSize(2));
assertGetRequest(
requests.get(0), "/runskillz.php", "action=Skillz&whichskill=7414&ajax=1&quantity=1");
assertPostRequest(requests.get(1), "/api.php", "what=status&for=KoLmafia");
}
}

Expand Down
1 change: 1 addition & 0 deletions test/root/request/test_cast_donhos_bubbly_ballad.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<script type="text/javascript">top.charpane.location.href="charpane.php";</script><script type="text/javascript">if (window.updateInv) updateInv([])</script><script type="text/javascript">if (!window.updateInv && parent.mainpane.updateInv) parent.mainpane.updateInv([])</script><center><table width=95% cellspacing=0 cellpadding=0><tr><td style="color: white;" align=center bgcolor=blue><b>Results:</b></td></tr><tr><td style="padding: 5px; border: 1px solid blue;"><center><table><tr><td>You grab your The Trickster's Trikitixa and play a tropical ballad for yourself.<center><table><tr><td><img class=hand src="https://d2uyhvukfffg5a.cloudfront.net/itemimages/bubblyballad.gif" onClick='eff("3337ba138b0e4d48f070bca9711139b5");' width=30 height=30 alt="Donho's Bubbly Ballad" title="Donho's Bubbly Ballad"></td><td valign=center class=effect>You acquire an effect: <b>Donho's Bubbly Ballad</b><br>(duration: 100 Adventures)</td></tr></table></center><p>6 / 50 casts used today.</td></tr></table></center></td></tr><tr><td height=4></td></tr></table></center>

0 comments on commit e320d24

Please sign in to comment.