Feature - Rejected clean up UseItemEnqueuePanel buttons

roippi

Developer
Since we're graying-out buttons on the food, booze, and spleen item manager panels now, it seems like we can clean up more buttons.

-Set "feed ghost" and "feed hobo" visibility = 0 if we do not own the appropriate familiars
-Set "cast ode" visibility = 0 if we do not know ode
-Set "cast ode" availability = 0 if max mp < 50
-Set "flush mojo" availability = 0 if either:
  • we're in ronin and we don't have a filter
  • we're out of ronin, don't have a filter, and buying from mall is disabled
  • whenever we've already flushed 3 times

Thoughts?
 

Theraze

Active member
Disabling milk if:
we're in ronin and creatable_amount for milk < 1 and available_amount < 1
we're out of ronin, ronin rules are currently in effect, and mallbuy is disabled.

In the case of both flush mojo and use milk, it should be disabled if you need the mall and mall_price > current meat.
 

Theraze

Active member
Ah, maybe with historic_price then. My thought was that if you only have 500 meat, don't taunt with a button that isn't going to work. If we can reduce a server hit that we know isn't going to work, great.
 

fronobulax

Developer
Staff member
Ah, maybe with historic_price then. My thought was that if you only have 500 meat, don't taunt with a button that isn't going to work. If we can reduce a server hit that we know isn't going to work, great.

That's not a taunt. It's a reminder to check my closet for meat I had forgotten was there.
 

Theraze

Active member
If the button is greyed out, but you know that you should be able to afford it, then you can go to retrieve the meat from your closet before you do the combined server hits of having it check mall_price and see if possibly there's a cheaper somehow that it's missing...

Eh, I'm just trying to save hits when they're never going to work. :)
 

roippi

Developer
Okay:

Code:
Index: src/net/sourceforge/kolmafia/swingui/panel/UseItemEnqueuePanel.java

===================================================================

--- src/net/sourceforge/kolmafia/swingui/panel/UseItemEnqueuePanel.java	(revision 9423)

+++ src/net/sourceforge/kolmafia/swingui/panel/UseItemEnqueuePanel.java	(working copy)

@@ -55,6 +55,7 @@

 import net.sourceforge.kolmafia.persistence.ItemDatabase;
 import net.sourceforge.kolmafia.preferences.PreferenceListenerRegistry;
 import net.sourceforge.kolmafia.preferences.Preferences;
+import net.sourceforge.kolmafia.request.CreateItemRequest;
 import net.sourceforge.kolmafia.request.UseItemRequest;
 import net.sourceforge.kolmafia.request.UseSkillRequest;
 import net.sourceforge.kolmafia.session.InventoryManager;
@@ -88,13 +89,20 @@

 
 		listeners.add( new ExecuteListener() );
 
-		if ( this.food || this.booze )
+		boolean hg = KoLCharacter.findFamiliar( FamiliarPool.GHOST ) != null;
+		boolean hh = KoLCharacter.findFamiliar( FamiliarPool.HOBO ) != null;
+		
+		if ( food && hg || booze && hh )
 		{
 			listeners.add( new FamiliarFeedListener() );
+		}
+
+		if ( food || booze )
+		{	
 			listeners.add( new BuffUpListener() );
 		}
 
-		if ( this.booze || this.spleen )
+		if ( booze || spleen )
 		{
 			listeners.add( new FlushListener() );
 		}
@@ -150,17 +158,67 @@

 	{
 		super.setEnabled( isEnabled );
 		
-		// We gray out the dog hair button unless we have drunkenness,
-		// have a pill, and haven't used one today.
-		if ( isEnabled && this.booze )
+		if ( isEnabled )
 		{
-			// The "flush" listener is the last button
-			int flushIndex = this.buttons.length - 1;
-			boolean havedrunk = KoLCharacter.getInebriety() > 0;
-			boolean havepill = InventoryManager.getCount( ItemPool.SYNTHETIC_DOG_HAIR_PILL ) > 0;
-			boolean usedpill = Preferences.getBoolean( "_syntheticDogHairPillUsed" );
-			boolean canFlush = havedrunk && ( havepill && !usedpill );
-			this.buttons[ flushIndex ].setEnabled( canFlush );
+		boolean ro = KoLCharacter.inRonin();
+		boolean haveMall = Preferences.getBoolean( "autoSatisfyWithMall" );
+
+			if ( this.food )
+			{
+				int milkIndex = this.buttons.length - 1;
+				boolean haveMilk = InventoryManager.getAccessibleCount( ItemPool.MILK_OF_MAGNESIUM ) > 0;
+
+				CreateItemRequest creator = CreateItemRequest.getInstance( ItemPool.MILK_OF_MAGNESIUM );
+				
+				boolean canMake = false;
+				if (creator != null)
+				{
+					canMake = creator.getQuantityPossible() > 0;
+				}
+				
+				//it's milktime if !haveMall and we have one/can make one 
+				//OR if haveMall.  Also check that we haven't hit maxUses.
+				
+				boolean availMilk = ro || !haveMall ? haveMilk || canMake : true;
+				boolean canUse = UseItemRequest.maximumUses( ItemPool.MILK_OF_MAGNESIUM ) > 0;
+
+				boolean milkTime = canUse && availMilk;
+
+				this.buttons[ milkIndex ].setEnabled( milkTime );
+			}
+			
+			else if ( this.booze )
+			{
+				// The "flush" listener is the last button
+				int flushIndex = this.buttons.length - 1;
+				
+				boolean havePill = InventoryManager.getCount( ItemPool.SYNTHETIC_DOG_HAIR_PILL ) > 0;
+				boolean canUse = UseItemRequest.maximumUses( ItemPool.SYNTHETIC_DOG_HAIR_PILL ) > 0;
+				
+				boolean canFlush = canUse && havePill;
+				
+				//we gray out the dog hair button unless we have drunkenness,
+				//have a pill, and haven't used one today.
+				this.buttons[ flushIndex ].setEnabled( canFlush );
+
+				int odeIndex = this.buttons.length - 2;	
+				boolean canOde = KoLCharacter.hasSkill( "The Ode to Booze" ) && KoLCharacter.getMaximumMP() > 49;
+
+				this.buttons[ odeIndex ].setEnabled( canOde );
+			}
+
+			else if (this.spleen )
+			{
+				int mojoIndex = this.buttons.length - 1;
+
+				boolean haveMojo = InventoryManager.getCount( ItemPool.MOJO_FILTER ) > 0;
+				boolean canUse = UseItemRequest.maximumUses( ItemPool.SYNTHETIC_DOG_HAIR_PILL ) > 0;
+
+				boolean isMojoTime = !canUse ? false : ro && !haveMojo ? false 
+						: !ro && (!haveMojo && !haveMall) ? false : true;
+
+				this.buttons[ mojoIndex ].setEnabled( isMojoTime );
+			}
 		}
 	}

Gray out milk if we're in ronin or have mall disabled and we don't have && can't make a milk. Also gray out if maximumUses = 0.

Gray out flush mojo if we're in ronin or have mall disabled and don't have a filter.

Gray out ode if we don't know the skill or have less than 50 max mp. We could technically not start the booze BuffUpListener if we don't know ode, but meh.

Do not start the food/booze FamiliarFeedListener if we do not have the according familiars (i.e. those buttons will not be there). I have neither of those familiars, so that bit is untested. In-Ronin behavior also untested, but disabling the mall seems to work correctly.
 

roippi

Developer
I've been using this in my local copy for a while now with no problems. If nobody objects I will commit it.
 

Nifft

Member
Would Use Milk disappear in-ronin if I have pullable ones but don't happen to have a budget set so something else doesn't accidently get pulled until I'm ready to use it / set the budget? Out of sight/out of mind... I'd manage to forget to pull it.
 

roippi

Developer
Would Use Milk disappear in-ronin if I have pullable ones but don't happen to have a budget set so something else doesn't accidently get pulled until I'm ready to use it / set the budget? Out of sight/out of mind... I'd manage to forget to pull it.

I am a hardcore player so I cannot answer that definitively. Oh and Use Milk never disappears, the button is just disabled.

Salient line in the code: canMake = creator.getQuantityPossible() > 0;

I don't know if getQuantityPossible considers pulls, though I'll guess 'no.' But is that really undesirable behavior? It's pretty trivial to change that line to include getQuantityPullable.
 

Nifft

Member
Greyed would be fine. I'd see it and know what to do. I *cough* assumed hidden if it was going to work the same as Ode which was explicitly stated as visibability = 0 which sounds hidden. Does it really mean greyed, for those fields as well?
 
Top