Mood triggers that depend on an item simple post a UseItemRequest.
UseItemRequest calls InventoryManager.retrieveItem to get the nasal spray.
That is the same method used by "acquire".
Travoltan trousers are automatically equipped in NPCPurchaseRequest.ensureProperAttire. This will make sure that if an NPC store requires a particular outfit - the Hippy Store, for example - you are wearing it. At the very end of that:
Code:
// Otherwise, maybe you can put on some Travoltan Trousers to decrease the cost of the
// purchase, but only if auto-recovery isn't running.
if ( !NPCPurchaseRequest.usingTrousers() && KoLConstants.inventory.contains( NPCPurchaseRequest.TROUSERS ) )
{
( new EquipmentRequest( NPCPurchaseRequest.TROUSERS, EquipmentManager.PANTS ) ).run();
}
So, what's this "auto-recovery isn't running" thing? Earlier:
Code:
// If the recovery manager is running, do not change equipment as this has the potential
// for an infinite loop.
if ( RecoveryManager.isRecoveryActive() )
{
if ( neededOutfit != OutfitPool.NONE )
{
KoLmafia.updateDisplay(
MafiaState.ERROR,
"Aborting implicit outfit change due to potential infinite loop in auto-recovery. Please buy the necessary " + getItemName() + " manually." );
return false;
}
return true;
}
What is that about? Does it apply to moods? I think not. There are numerous places where we check "if ( RecoveryManager.isRecoveryActive() || MoodManager.isExecuting() )". This is not one of them.
I transfered my Travoltan trousers to a character who has the dispensary open.
Code:
[color=green]> acquire nasal spray[/color]
Putting on Travoltan trousers...
Equipment changed.
Purchasing Knob Goblin nasal spray (1 @ 142)...
You spent 142 Meat
You acquire an item: Knob Goblin nasal spray
Purchases complete.
Putting on paperclip pants...
Equipment changed.
[color=green]> closet put * nasal spray[/color]
Placing items into closet...
Requests complete.
[color=green]> mood execute[/color]
Putting on Travoltan trousers...
Equipment changed.
Purchasing Knob Goblin nasal spray (1 @ 142)...
You spent 142 Meat
You acquire an item: Knob Goblin nasal spray
Purchases complete.
Using 1 Knob Goblin nasal spray...
You acquire an effect: Wasabi Sinuses (10)
Finished using 1 Knob Goblin nasal spray.
Putting on paperclip pants...
Equipment changed.
Mood swing complete.
As you can see, the fact that the acquisition is happening as part of a mood does not prevent using the Travoltan trousers.
The key is that moods are executed as part of RecoveryManager.runBetweenBattleChecks - which explicitly sets and resets RecoveryManager.isRecoveryActive.
I wish I remembered why we disallow outfit changes if isRecoveryActive. It is "to avoid infinite loops". Guess: if you are recovering HP or MP to 100% and changing equipment will lower your max value of such, when we restore your equipment, we'll notice you are not at 100% and will try again. Given that, looking at recovery:
Code:
RecoveryManager.recoveryActive = true;
if ( isScriptCheck )
{
KoLmafia.executeScript( Preferences.getString( "betweenBattleScript" ) );
}
SpecialOutfit.createImplicitCheckpoint();
// Now, run the built-in behavior to take care of
// any loose ends.
if ( isMoodCheck )
{
MoodManager.execute();
}
if ( isHealthCheck )
{
RecoveryManager.recoverHP();
}
if ( isMoodCheck )
{
ManaBurnManager.burnExtraMana( false );
}
if ( isManaCheck )
{
RecoveryManager.recoverMP();
}
SpecialOutfit.restoreImplicitCheckpoint();
...
RecoveryManager.recoveryActive = false;
Notice that it executes your mood before it recovers HP and MP.
Notice that it saves & restores your outfit before doing any of those things, which is why you can't change your gear in a mood, which people have asked about numerous times. It does that specifically to recover from automatic outfit switching, but as we've seen, that is disabled while recovering, any way.
Notice that a user-supplied betweenBattleScript script will run before any other "recovery" - and is outside of the outfit save/restore. Such a script can do any equipment switching it wants, but automatic outfit switching for NPC purchases will still be disabled, since it is doing "recovery".
A user-supplied recoveryScript will be called by recoverHP and recoverMP. That has the same "feature": if it wants to use knob goblin seltzer or something, no Travoltan discount - although it can do any equipment changes it wants. It's a script.
So, we now understand your observed behavior. It may or may not be a "bug" since it is behaving as intended. but if we wanted to "fix" it, we could do two things:
1) Change NPCPurchaseRequest as follows:
Code:
if ( RecoveryManager.isRecoveryActive() && !MoodManager.isExecuting() )
which will allow equipment changes during moods.
2) Change RecoverManager as follows:
Code:
// Now, run the built-in behavior to take care of
// any loose ends.
SpecialOutfit.createImplicitCheckpoint();
if ( isMoodCheck )
{
MoodManager.execute();
}
SpecialOutfit.restoreImplicitCheckpoint();
SpecialOutfit.createImplicitCheckpoint();
Which will save and restore your outfit around the mood execution, which will recover from said newly-allowed outfit switching, and will also save and restore your outfit around the rest of recovery, which will recover from Recovery Scripts.
