Bug - Fixed Sometimes unable to buy limited items from Underground Fireworks Shop

Veracity

Developer
Staff member
doRetrieveItem has...
Java:
    if (shouldUseNPCStore || scriptSaysBuy) {
      if (sim) {
        return shouldUseNPCStore ? "buy from NPC" : "buy";
      }

      // If buying from the mall will leave the item in storage, use only NPCs
      AdventureResult instance = item.getInstance(missingCount);
      boolean onlyNPC = forceNoMall || !InventoryManager.canUseMall();
      List<PurchaseRequest> results =
          onlyNPC ? MallPriceManager.searchNPCs(item) : MallPriceManager.searchMall(instance);
      KoLmafia.makePurchases(
          results,
          results.toArray(new PurchaseRequest[0]),
          InventoryManager.getPurchaseCount(itemId, missingCount),
          isAutomated,
          0);

I'm not sure whether `instanceof NPCPurchaseRequest` is adequate, especially for items that you've already purchased up to the limit.
I looked at that and wondered how it knew that had to get make an NPC purchase from the fireworks shop.

Code:
  public static boolean canUseMall(final int itemId) {
    return ItemDatabase.isTradeable(itemId) && InventoryManager.canUseMall();
  }
This is the crux: the firework shop equipment is all "lasts until rollover" quest items. I.e., not tradable.

Therefore, MallPriceManager.searchNPCs will return an array with a single NPCPurchaseRequest in it.

The instanceof will pick that out fine. What what will the "count" be if you've already bought one? I.e., "_fireworksShopHatBought" is true? Where, exactly, is that property enforced? I'll write an additional test.

Edit: MallPriceManager.searcNPCs() calls NPCStoreDatabase.getPurchaseRequest() which call NPCStoreDataBase.canPurchase(), which will return false if you've already bought a firework shop limited it.

Which is to say, the array of potential PurchaseRequests will be empty.

I think the instanceof will do fine, since there will only be a PurchaseRequest in the array if you can actually use it.
 
Top