Bug - Fixed Fails to recognize breaking apart BRICKO equipment

Bale

Minion
I found this bug because I am trying to add new functionality to OCD. The three bricko equips are capable of being broken apart into their component brickos. (There's a break apart link.) However mafia won't subtract them from inventory.

Mafia will recognize the new bricko bricks that are added, but that is not surprising and obviously is not a problem.

Here's the html resulting from breaking apart a BRICKO hat:


Code:
> ash print(visit_url("inventory.php?action=breakbricko&whichitem=4471&ajax=1"))

You acquire BRICKO brick (3)
<script type="text/javascript">if (window.updateInv) updateInv({"4471":-1,"4469":3})</script><center><table width=95% cellspacing=0 cellpadding=0><tr><td style="color: white;" align=center bgcolor=blue><b>Results:</b></td></tr><tr><td style="padding: 5px; border: 1px solid blue;"><center><table><tr><td>You break apart your BRICKO hat.<center><table class="item" style="float: none" rel="id=4469&s=0&q=0&d=0&g=0&t=1&n=3&m=1&p=0&u=u"><tr><td><img src="http://images.kingdomofloathing.com/itemimages/brickobrick.gif" alt="BRICKO brick" title="BRICKO brick" class=hand onClick='descitem(261433979)'></td><td valign=center class=effect>You acquire <b>3 BRICKO bricks</b></td></tr></table></center></td></tr></table></center></td></tr><tr><td height=4></td></tr></table></center>
Returned: void
 
Last edited:

lostcalpolydude

Developer
Staff member
ResponseTextParser has
Code:
			else if ( location.indexOf( "action=message" ) != -1 || location.indexOf( "action=breakbricko" ) != -1 )
			{
				[b]UseItemRequest.parseConsumption( responseText, false );[/b]
				AWOLQuartermasterRequest.parseResponse( location, responseText );
				BURTRequest.parseResponse( location, responseText );
			}

UseItemRequest.parseConsumption() starts with
Code:
		if ( UseItemRequest.lastItemUsed == null )
		{
			return;
		}

In this case, UseItemRequest.lastItemUsed is null. I feel like a new function in UseItemRequest for ResponseTextParser to call might be the way to go, but there's a lot going on in UseItemRequest so I'm not really sure.

I put together
Code:
	private static final Pattern BRICKO_PATTERN =
		Pattern.compile( "You break apart your ([\\w\\s]*)." );
and
Code:
		if ( responseText.contains( "You break apart your" ) )
		{
			RequestLogger.printLine( "bricko breaking matched" );
			Matcher matcher = UseItemRequest.BRICKO_PATTERN.matcher( responseText );
			if ( matcher.find() )
			{
				AdventureResult brickoItem = new AdventureResult( matcher.group( 1 ), -1 );
				ResultProcessor.processResult( brickoItem );
			}
		}
to go somewhere.
 
I've been poking at this, and should have a patch later today. My approach basically matches what you suggested above, lostcalpolydude - I will add a UseItemRequest.parseBricko function to call when the uri matches breakbricko, that then looks basically like the code you put in above. This seems to line up with other useitem edge cases, like parseBinge. I debated about creating a whole new request/BreakBrickoRequest.java file, but that seemed like overkill for a fairly minor edge case, and this is a part of the inventory.php calls as well. Figured I'd post my approach before getting too far down the road to validate this makes sense - still have a ton to learn on how kolmafia works.
 

roippi

Developer
KoLMafia has lots of nested inner classes, which I generally find to be fine. Some schools of thought say that you should usually avoid that and create a new .java file for each type, but I think that reduces readability.
 
Well, I think this turned out to be super-easy, as lostcalpolydude did all the heavy lifting. At face value, everything seems to work - going back and forth between using bricko bricks and using the bricko items now correctly zeros out to no net change in item gain. I'm concerned I'm missing some subtlety, but hopefully not. As always, built against latest, r11205, and it builds/runs. I did leave the "bricko breaking matched" update line in, you may/may not want to delete that from the change.
 

Attachments

  • breakbricko.patch
    2.7 KB · Views: 40
Top