Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow eating a glitch monster after using it #1317

Merged
merged 1 commit into from Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -238,7 +238,7 @@ public void run() {
int itemId = this.itemUsed.getItemId();
UseItemRequest.lastUpdate = "";

int maximumUses = UseItemRequest.maximumUses(itemId);
int maximumUses = UseItemRequest.maximumUses(itemId, this.consumptionType);
if (maximumUses < this.itemUsed.getCount()) {
KoLmafia.updateDisplay(
"(usable quantity of "
Expand Down
6 changes: 5 additions & 1 deletion src/net/sourceforge/kolmafia/request/EatItemRequest.java
Expand Up @@ -165,6 +165,10 @@ public static final int maximumUses(final int itemId, final String itemName, fin
UseItemRequest.limiter = "daily limit";
return 23 - Preferences.getInteger("_sausagesEaten");

case ItemPool.GLITCH_ITEM:
UseItemRequest.limiter = "daily limit";
return 1 - Preferences.getInteger("_glitchMonsterFights");

case ItemPool.PIRATE_FORK:
UseItemRequest.limiter = "daily limit";
return Preferences.getBoolean("_pirateForkUsed") ? 0 : 1;
Expand Down Expand Up @@ -225,7 +229,7 @@ public void run() {

UseItemRequest.lastUpdate = "";

int maximumUses = UseItemRequest.maximumUses(itemId);
int maximumUses = UseItemRequest.maximumUses(itemId, this.consumptionType);
if (maximumUses < count) {
KoLmafia.updateDisplay(
"(usable quantity of "
Expand Down
Expand Up @@ -81,7 +81,7 @@ public void run() {
int itemId = this.itemUsed.getItemId();
UseItemRequest.lastUpdate = "";

int maximumUses = UseItemRequest.maximumUses(itemId);
int maximumUses = UseItemRequest.maximumUses(itemId, this.consumptionType);
if (maximumUses < this.itemUsed.getCount()) {
KoLmafia.updateDisplay(
"(usable quantity of "
Expand Down
9 changes: 9 additions & 0 deletions src/net/sourceforge/kolmafia/request/UseItemRequest.java
Expand Up @@ -436,6 +436,15 @@ private static int maximumUses(
case PASTA_GUARDIAN:
UseItemRequest.limiter = "character class";
return KoLCharacter.isPastamancer() ? 1 : 0;
case EAT:
return EatItemRequest.maximumUses(
itemId, itemName, ConsumablesDatabase.getFullness(itemName));
case DRINK:
return DrinkItemRequest.maximumUses(
itemId, itemName, ConsumablesDatabase.getInebriety(itemName), allowOverDrink);
case SPLEEN:
return SpleenItemRequest.maximumUses(
itemId, itemName, ConsumablesDatabase.getSpleenHit(itemName));
}

// Delegate to specialized classes as appropriate
Expand Down
Expand Up @@ -4,6 +4,7 @@
import static internal.helpers.HttpClientWrapper.setupFakeClient;
import static internal.helpers.Networking.assertPostRequest;
import static internal.helpers.Player.withItem;
import static internal.helpers.Player.withProperty;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasSize;
Expand Down Expand Up @@ -43,5 +44,22 @@ public void canEatGlitchSeasonReward() {
assertPostRequest(requests.get(0), "/inv_eat.php", "whichitem=10207&ajax=1&quantity=1");
}
}

@Test
public void canEatGlitchSeasonRewardAfterImplementing() {
setupFakeClient();

var cleanups =
new Cleanups(
withItem(ItemPool.GLITCH_ITEM), withProperty("_glitchItemImplemented", true));

try (cleanups) {
String output = execute("glitch season");
var requests = getRequests();
assertThat(output, containsString("Eating 1 [glitch season reward name]..."));
assertThat(requests, hasSize(1));
assertPostRequest(requests.get(0), "/inv_eat.php", "whichitem=10207&ajax=1&quantity=1");
}
}
}
}
Expand Up @@ -4,6 +4,7 @@
import static internal.helpers.HttpClientWrapper.setupFakeClient;
import static internal.helpers.Networking.assertPostRequest;
import static internal.helpers.Player.withItem;
import static internal.helpers.Player.withProperty;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasSize;
Expand Down Expand Up @@ -43,5 +44,24 @@ public void canUseGlitchSeasonReward() {
assertPostRequest(requests.get(0), "/inv_use.php", "whichitem=10207&ajax=1");
}
}

@Test
public void cannotUseGlitchSeasonRewardAfterImplementing() {
setupFakeClient();

var cleanups =
new Cleanups(
withItem(ItemPool.GLITCH_ITEM), withProperty("_glitchItemImplemented", true));

try (cleanups) {
String output = execute("glitch season");
var requests = getRequests();
assertThat(
output,
containsString(
"(usable quantity of [glitch season reward name] is limited to 0 by daily limit)"));
assertThat(requests, hasSize(0));
}
}
}
}