Bug - Fixed Mafia believes a shield if equipped even after pre-req failure.

matt.chugg

Moderator
When mafia is asked to equip a shield without fulfilling the pre-requisites, (in this test case 85 base muscle) it reports it as a failure but updates its internal data and removes the item from inventory as if it was equipped when infact it isn't.

Sorry if that doesn't make sense, I couldn't think of a better way of explaining it!

Code:
> ash print(item_amount($item[eelskin shield]))

1
Returned: void

> equip eelskin shield

Holding eelskin shield...
You must have at least 85 base Muscle to equip that item.

> ash print(item_amount($item[eelskin shield]))

0
Returned: void

> ash print(equipped_item($slot[off-hand]))

eelskin shield
Returned: void
 

slyz

Developer
I guess that, even with a fix, it would be up to the user to check if an item can be equipped before equipping it, so I only tried to understand where the inventory is updated in EquipmentRequest.java, since that's the real bug.

I think something like this should be added to EquipmentRequest.parseEquipmentChange()
Code:
String text = responseText == null ? "" : responseText;
Matcher resultMatcher = EquipmentRequest.CELL_PATTERN.matcher( text );
if ( resultMatcher.find() )
{
	String result = resultMatcher.group( 1 ).replaceAll( "</?b>", "" );
	if ( result.indexOf( "You must have at least" ) != -1 )
	{
		// Stats requirements for equipping the item were not met
		return;
	}
}

Here is my first try at a patch. And the results:
Code:
> ash print(item_amount($item[eelskin shield]))

1
Returned: void

> equip eelskin shield

Holding eelskin shield...
You must have at least 85 base Muscle to equip that item.

> ash print(item_amount($item[eelskin shield]))

1
Returned: void

> ash print(equipped_item($slot[off-hand]))

moxie magnet
Returned: void

I tried attaching the resulting KoLmafia-8654M.jar but apparently I'm already using too much space ^^
 

Attachments

  • DetectRequirementFailure.patch
    908 bytes · Views: 32

holatuwol

Developer
Revision 8695 should address the problem with scripts / CLI commands by doing a check prior to a server request to save a server hit. Not sure how many possible ways equipment changes can fail if you issue outfit commands or relay browser requests since I haven't played the game in years, so I'll hold off on checks in the response processing.
 
Top