Skip to content

Commit

Permalink
No Campground in WereProfessor. Improved Fulminate warning (#2233)
Browse files Browse the repository at this point in the history
* No Campground in WereProfessor. Improved Fulminate warning

* Protect against other tests leaking turns played
  • Loading branch information
Veracity0 committed Mar 11, 2024
1 parent 8c743a5 commit 1b21d0c
Show file tree
Hide file tree
Showing 6 changed files with 239 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/net/sourceforge/kolmafia/KoLmafia.java
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,8 @@ private static void refreshSessionData() {
if (!KoLCharacter.getLimitMode().limitCampground()
&& !KoLCharacter.isEd()
&& !KoLCharacter.inNuclearAutumn()
&& !KoLCharacter.inRobocore()) {
&& !KoLCharacter.inRobocore()
&& !KoLCharacter.inWereProfessor()) {
KoLmafia.updateDisplay("Retrieving campground data...");
if (!KoLCharacter.isVampyre()) {
RequestThread.postRequest(new CampgroundRequest("inspectdwelling"));
Expand Down
10 changes: 10 additions & 0 deletions src/net/sourceforge/kolmafia/objectpool/Concoction.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.sourceforge.kolmafia.request.PurchaseRequest;
import net.sourceforge.kolmafia.request.StillSuitRequest;
import net.sourceforge.kolmafia.request.TinkeringBenchRequest;
import net.sourceforge.kolmafia.session.InventoryManager;
import net.sourceforge.kolmafia.utilities.StringUtilities;

/**
Expand Down Expand Up @@ -630,6 +631,15 @@ public void setPurchaseRequest(final PurchaseRequest purchaseRequest) {
this.purchaseRequest = purchaseRequest;
}

public boolean hasIngredients() {
for (AdventureResult ingredient : this.ingredientArray) {
if (InventoryManager.getCount(ingredient) == 0) {
return false;
}
}
return true;
}

public boolean hasIngredients(final AdventureResult[] ingredients) {
AdventureResult[] ingredientTest = this.ingredientArray;
if (ingredientTest.length != ingredients.length) {
Expand Down
1 change: 1 addition & 0 deletions src/net/sourceforge/kolmafia/objectpool/ItemPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -2391,6 +2391,7 @@ public class ItemPool {
public static final int DETARTRATED_ANHYDROUS_SUBLICALC = 7489;
public static final int TRIATOMACEOUS_DUST = 7490;
public static final int BOTTLE_OF_CHATEAU_DE_VINEGAR = 7491;
public static final int BLASTING_SODA = 7492;
public static final int UNSTABLE_FULMINATE = 7493;
public static final int WINE_BOMB = 7494;
public static final int MORTAR_DISSOLVING_RECIPE = 7495;
Expand Down
73 changes: 67 additions & 6 deletions src/net/sourceforge/kolmafia/request/RelayRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import net.sourceforge.kolmafia.moods.MoodManager;
import net.sourceforge.kolmafia.moods.RecoveryManager;
import net.sourceforge.kolmafia.objectpool.AdventurePool;
import net.sourceforge.kolmafia.objectpool.Concoction;
import net.sourceforge.kolmafia.objectpool.ConcoctionPool;
import net.sourceforge.kolmafia.objectpool.EffectPool;
import net.sourceforge.kolmafia.objectpool.FamiliarPool;
import net.sourceforge.kolmafia.objectpool.ItemPool;
Expand Down Expand Up @@ -135,6 +137,7 @@ public enum Confirm {
MOHAWK_WIG,
CELLAR,
BOILER,
BOILER2,
DIARY,
BORING_DOORS,
SPELUNKY,
Expand Down Expand Up @@ -2119,8 +2122,8 @@ private boolean sendZeppelinWarning() {
return true;
}

private boolean sendBoilerWarning() {
// If it's already confirmed, then track that for the session
public boolean sendBoilerWarning() {
// If it's already confirmed, then allow it this time.
if (this.getFormField(Confirm.BOILER) != null) {
return false;
}
Expand Down Expand Up @@ -2156,12 +2159,70 @@ private boolean sendBoilerWarning() {
return false;
}

String message;
if (!InventoryManager.hasItem(ItemPool.UNSTABLE_FULMINATE)) {
// They don't have it, but perhaps they can make it.

message =
"You are about to adventure in the Haunted Boiler Room, but do not have Unstable Fulminate equipped. If you are sure you want to do this, click on the image to proceed.";
// If they don't have the ingredients for unstable fulminate, it's a
// problem, but there's nothing we can do about it.
Concoction recipe = ConcoctionPool.get(ItemPool.UNSTABLE_FULMINATE);
if (!recipe.hasIngredients()) {
return false;
}

// Since unstable fulminate is a fancy concoction, in addition to
// the ingredients, they need a dramatic range to create it.
if (!KoLCharacter.hasRange()) {
return false;
}

// It is possible to make the fulminate, although it will probably
// take a turn to do so. Calling InventoryManager.retrieveItem()
// will create it and will prompt you that it will take a turn

StringBuilder buf = new StringBuilder();
buf.append(
"You are about to adventure in the Haunted Boiler Room, but do not have unstable fulminate equipped.");
buf.append(" You don't have that item, but you have the ingredients and could make it.");
buf.append(" If you don't want to bother doing this, click the icon on the left to proceed.");
buf.append(" If you want to make the fulminate now, click the icon on the right.");

this.sendOptionalWarning(
Confirm.BOILER2,
buf.toString(),
"hand.gif",
"wine2.gif",
"\"#\" onClick=\"singleUse('craft.php','action=craft&mode=cook&a="
+ ItemPool.BOTTLE_OF_CHATEAU_DE_VINEGAR
+ "&b="
+ ItemPool.BLASTING_SODA
+ "&qty=1&pwd="
+ GenericRequest.passwordHash
+ "&ajax=1');void(0);\"",
null,
null);

return true;
}

this.sendGeneralWarning("wine2.gif", message, Confirm.BOILER);
// If we get here, unstable fulminate is in inventory.
StringBuilder buf = new StringBuilder();
buf.append(
"You are about to adventure in the Haunted Boiler Room, but do not have unstable fulminate equipped.");
buf.append(" If you are sure you want to do this, click the icon on the left to proceed.");
buf.append(" If you want to equip the fulminate first, click the icon on the right.");

this.sendOptionalWarning(
Confirm.BOILER,
buf.toString(),
"hand.gif",
"wine2.gif",
"\"#\" onClick=\"singleUse('inv_equip.php','which=2&action=equip&whichitem="
+ ItemPool.UNSTABLE_FULMINATE
+ "&pwd="
+ GenericRequest.passwordHash
+ "&ajax=1');void(0);\"",
null,
null);

return true;
}
Expand Down
4 changes: 3 additions & 1 deletion src/net/sourceforge/kolmafia/session/LightsOutManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public static void checkCounter() {

public static boolean lightsOutNow() {
int totalTurns = KoLCharacter.getTurnsPlayed();
return totalTurns % 37 == 0 && Preferences.getInteger("lastLightsOutTurn") != totalTurns;
return totalTurns > 0
&& totalTurns % 37 == 0
&& Preferences.getInteger("lastLightsOutTurn") != totalTurns;
}

public static void report() {
Expand Down
156 changes: 156 additions & 0 deletions test/net/sourceforge/kolmafia/request/RelayRequestWarningsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import static internal.helpers.Player.withPath;
import static internal.helpers.Player.withProperty;
import static internal.helpers.Player.withQuestProgress;
import static internal.helpers.Player.withRange;
import static internal.helpers.Player.withStats;
import static internal.helpers.Player.withTurnsPlayed;
import static internal.helpers.Player.withUnequipped;
import static org.junit.jupiter.api.Assertions.*;

Expand Down Expand Up @@ -538,6 +540,160 @@ public void warningIfEquippableSpringShoes() {
}
}

@Nested
class UnstableFulminate {
private static final KoLAdventure A_BOO_PEAK =
AdventureDatabase.getAdventureByName("A-Boo Peak");
private static final KoLAdventure BOILER_ROOM =
AdventureDatabase.getAdventureByName("The Haunted Boiler Room");

private static final Confirm confirm = Confirm.BOILER;
private static final AdventureResult UNSTABLE_FULMINATE =
ItemPool.get(ItemPool.UNSTABLE_FULMINATE);
private static final AdventureResult BOTTLE_OF_CHATEAU_DE_VINEGAR =
ItemPool.get(ItemPool.BOTTLE_OF_CHATEAU_DE_VINEGAR);
private static final AdventureResult BLASTING_SODA = ItemPool.get(ItemPool.BLASTING_SODA);
private static final AdventureResult WINE_BOMB = ItemPool.get(ItemPool.WINE_BOMB);

@Test
public void noWarningIfNotInBoilerRoom() {
var cleanups = new Cleanups(withTurnsPlayed(3));
try (cleanups) {
RelayRequest request = new RelayRequest(false);
request.constructURLString(adventureURL(A_BOO_PEAK, null), false);
// No warning needed if you are not in the Haunted Boiler Room
assertFalse(request.sendBoilerWarning());
}
}

@Test
public void noWarningIfSummoningChamberOpen() {
var cleanups = new Cleanups(withTurnsPlayed(2), withQuestProgress(Quest.MANOR, "step3"));
try (cleanups) {
RelayRequest request = new RelayRequest(false);
request.constructURLString(adventureURL(BOILER_ROOM, null), false);
// No warning needed if Summoning Chamber already open
assertFalse(request.sendBoilerWarning());
}
}

@Test
public void noWarningIfLightsOutDue() {
var cleanups = new Cleanups(withTurnsPlayed(74), withProperty("lastLightsOutTurn", 37));
try (cleanups) {
RelayRequest request = new RelayRequest(false);
request.constructURLString(adventureURL(BOILER_ROOM, null), false);
// No warning needed if Lights Out is about to trigger
assertFalse(request.sendBoilerWarning());
}
}

@Test
public void noWarningIfVoteMonsterDue() {
var cleanups = new Cleanups(withTurnsPlayed(23), withProperty("lastVoteMonsterTurn", 12));
try (cleanups) {
RelayRequest request = new RelayRequest(false);
request.constructURLString(adventureURL(BOILER_ROOM, null), false);
// No warning needed if a Vote Monster is about to appear
assertFalse(request.sendBoilerWarning());
}
}

@Test
public void noWarningWithWineBombInInventory() {
var cleanups = new Cleanups(withTurnsPlayed(2), withItem(ItemPool.WINE_BOMB));
try (cleanups) {
RelayRequest request = new RelayRequest(false);
request.constructURLString(adventureURL(BOILER_ROOM, null), false);
// If already made a wine bomb, no warning
assertFalse(request.sendBoilerWarning());
}
}

@Test
public void noWarningIfConfirmed() {
var cleanups = new Cleanups(withTurnsPlayed(2));
try (cleanups) {
RelayRequest request = new RelayRequest(false);
request.constructURLString(adventureURL(BOILER_ROOM, confirm), false);
// No warning needed if this a resubmission with confirmation
assertFalse(request.sendBoilerWarning());
}
}

@Test
public void noWarningIfUnstableFulminateEquipped() {
var cleanups =
new Cleanups(withTurnsPlayed(2), withEquipped(Slot.OFFHAND, UNSTABLE_FULMINATE));
try (cleanups) {
RelayRequest request = new RelayRequest(false);
request.constructURLString(adventureURL(BOILER_ROOM, null), false);
// No warning needed if unstable fulminate already equipped
assertFalse(request.sendBoilerWarning());
}
}

@Test
public void noWarningIfNoFulminateAndMissingIngredients() {
var cleanups = new Cleanups(withTurnsPlayed(2));
try (cleanups) {
RelayRequest request = new RelayRequest(false);
request.constructURLString(adventureURL(BOILER_ROOM, null), false);
// No warning needed if unstable fulminate already equipped
assertFalse(request.sendBoilerWarning());
}
}

@Test
public void noWarningIfNoFulminateAndNoRange() {
var cleanups =
new Cleanups(
withTurnsPlayed(2), withItem(BOTTLE_OF_CHATEAU_DE_VINEGAR), withItem(BLASTING_SODA));
try (cleanups) {
RelayRequest request = new RelayRequest(false);
request.constructURLString(adventureURL(BOILER_ROOM, null), false);
// No warning needed if unstable fulminate already equipped
assertFalse(request.sendBoilerWarning());
}
}

@Test
public void warningIfCanMakeFulminate() {
var cleanups =
new Cleanups(
withTurnsPlayed(2),
withRange(),
withItem(BOTTLE_OF_CHATEAU_DE_VINEGAR),
withItem(BLASTING_SODA));
try (cleanups) {
RelayRequest request = new RelayRequest(false);
request.constructURLString(adventureURL(BOILER_ROOM, null), false);
assertTrue(request.sendBoilerWarning());
String expected =
"You are about to adventure in the Haunted Boiler Room, but do not have unstable fulminate equipped."
+ " You don't have that item, but you have the ingredients and could make it."
+ " If you don't want to bother doing this, click the icon on the left to proceed."
+ " If you want to make the fulminate now, click the icon on the right.";
assertEquals(expected, request.lastWarning);
}
}

@Test
public void warningIfEquippableUnstableFulminate() {
var cleanups = new Cleanups(withTurnsPlayed(2), withEquippableItem(UNSTABLE_FULMINATE));
try (cleanups) {
RelayRequest request = new RelayRequest(false);
request.constructURLString(adventureURL(BOILER_ROOM, null), false);
assertTrue(request.sendBoilerWarning());
String expected =
"You are about to adventure in the Haunted Boiler Room, but do not have unstable fulminate equipped."
+ " If you are sure you want to do this, click the icon on the left to proceed."
+ " If you want to equip the fulminate first, click the icon on the right.";
assertEquals(expected, request.lastWarning);
}
}
}

@Nested
class SurvivalKnife {
private static final KoLAdventure A_BOO_PEAK =
Expand Down

0 comments on commit 1b21d0c

Please sign in to comment.