Bug - Fixed Maximizer reduces score with combat chance at soft limit (failing test included)

Ryo_Sangnoir

Developer
Staff member
The test (also attached) displays the problem reproducibly: I'm looking to maximize "-combat, cold res" (for this current PvP season). I'm already at -25% combat, at least some of which comes from equipment (I wanted to do a test for it all coming from effects, but couldn't figure out the code). Maximizer favours adding more -combat over adding cold res. If I remove the pants, it drops from 23 to 22. I'd like to see what equipment it thinks is best, but I don't know the code for that again. I'll look into it more.
Code:
@Test
public void modificationShouldImproveScore()
{
   // space trip safety headphones, red shoe
   loadInventory("{\"4639\": \"1\", \"7241\": \"1\"}");
   // get ourselves to -25 combat
   EquipmentManager.setEquipment(EquipmentManager.HAT, AdventureResult.parseResult("Xiblaxian stealth cowl"));
   EquipmentManager.setEquipment(EquipmentManager.SHIRT, AdventureResult.parseResult("Xiblaxian stealth vest"));
   EquipmentManager.setEquipment(EquipmentManager.PANTS, AdventureResult.parseResult("Xiblaxian stealth trousers"));
   EquipmentManager.setEquipment(EquipmentManager.CONTAINER, AdventureResult.parseResult("protonic accelerator pack"));
   EquipmentManager.setEquipment(EquipmentManager.ACCESSORY1, AdventureResult.parseResult("Fuzzy Slippers of Hatred"));
   // add 3 cold res
   EquipmentManager.setEquipment(EquipmentManager.ACCESSORY2, AdventureResult.parseResult("Krampus Horn"));
   EquipmentManager.setEquipment(EquipmentManager.ACCESSORY3, AdventureResult.parseResult("ghost of a necklace"));
   // check we can equip everything
   KoLCharacter.setStatPoints( 0, 0, 40, 1600, 0, 0 );
   assertTrue( "Cannot equip space trip safety headphones", EquipmentManager.canEquip(4639) );
   assertTrue( "Cannot equip red shoe", EquipmentManager.canEquip(7241) );
   assertTrue( Maximizer.maximize( "cold res,-combat -hat -weapon -offhand -back -shirt -pants -familiar -acc1 -acc2 -acc3",
            0, 0, true ) );
   assertEquals( "Base score is 28",
         28, Modifiers.getNumericModifier( "Generated", "_spec", "Cold Resistance" )
         - Modifiers.getNumericModifier( "Generated", "_spec", "Combat Rate" ), 0.01 );
   assertTrue( Maximizer.maximize( "cold res,-combat",
         0, 0, true ) );
   assertEquals( "Maximizing should not reduce score",
         28, Modifiers.getNumericModifier( "Generated", "_spec", "Cold Resistance" )
               - Modifiers.getNumericModifier( "Generated", "_spec", "Combat Rate" ), 0.01 );
}
 

Attachments

Last edited:
I should have set moxie to 125 or you can hit another issue where it seems to simulate taking the fuzzy slippers off and then can't put them back on again, but this still happens even with that change.

That is, if I start with the slippers, horn and ghost of a necklace equipped and maximize "-combat, cold res" I expect my score to be 15 but actually it's 12, while "-combat, cold res, -acc1" gives 15 as expected.

This can happen if you put on a stat restricter (or encounter an adventure with a stat restricter), for example
 
I got the test wrong. There are two bugs here, but neither are that important I think.

First, if you run maximizer before KoLCharacter.recalculateAdjustments() runs for the first time, you'll get every effect recommended with a bonus of whatever your current score is. This definitely happens on ascension, and I think happens when you first log in for the day. You can get around this by doing any one of a whole lot of actions: on ascension I fold my garbage tote, otherwise I think I just equip something.

Second, maximizer recommends you remove any bit of equipment you no longer have the ability to equip. You can fall into this by gaining a stat limiter, e.g. The Bubblin' Caldera's intro adventure. The workaround is just to maximize outside this case.
 

Attachments

Missed this before. Post #3 has a test and installing it as a patch and running tests fails. This makes me happy. Thank you.

Now to figure out what it tells us and how to fix :-)
 
Ah, that's because I don't clean up properly between tests. Here's a fixed patch with no failing tests.

Tomorrow I plan to create tests for and fix the two issues I identified in post 3. Well, the latter one at least.
 

Attachments

The first bug is odd, I've attached an example of it happening. I think a fix would be to call KoLCharacter.recalculateAdjustments() at the start of every maximization. Somehow the current score is put at 0, so Mafia thinks that every action it can do will increase the score by whatever the current score is. Very strange.
 

Attachments

  • maximizer_bug_1.png
    maximizer_bug_1.png
    22.8 KB · Views: 1
Here's a fix for the second issue (plus tests proving it): when determining possible equipment, include equipment you've currently equipped in addition to equipment you can equip.
 

Attachments

Here's a fix for the second issue (plus tests proving it): when determining possible equipment, include equipment you've currently equipped in addition to equipment you can equip.
r20562

Edit: The maximizer test was included in the patch I applied, in case someone is checking.

Also, I have lost the bubble on the problem and solution so I won't declare this Fixed until someone else tells me it is Fixed.

Thanks for the test. It was fun patching the test, getting a failure, batching the code and getting test success.
 
I've fixed the first bug as well in the attached patch. The issue here is that sometimes what the Maximizer gets for the "current modifiers" is actually zero, not the current modifiers. I don't know what causes this (I know ascending causes it, but I've also seen it happen at other times, though extremely rarely), but this patch recalculates before getting them just in case. It includes a test, and I've also refactored some of the existing tests to use common methods for common functionality.

Yes, this thread went off the rails a bit. Essentially:
  1. I encountered a bug in maximizer where it recommended two pairs of sets of gear in sequence, to flip between, and one was strictly lower than the other. I thought it was to do with being at -25% combat, so I wrote a test to prove that, and it failed.
  2. But the failure was caused by writing the test incorrectly, rather than by the code being wrong. While debugging the test failure, though, I noticed some other bugs, and remembered seeing them in-game.
  3. I provided patches to fix those bugs.
To prove the first in-game:
  1. Ascend Platypus (or some sign that affects something you're maximizing: I think "exp" should work for them all but the calculation is more complicated)
  2. Before doing anything, maximize "familiar weight" (or the relevant thing)
  3. Is "monorail buff" recommended (it shouldn't be)
To prove the second:
  1. Clear your inventory somehow (or test with an item that's best-in-class. Maybe one of the Dread ones?)
  2. Equip something with a requirement > 100 (e.g. Fuzzy Slippers of Hatred)
  3. Equip a stat limiter (e.g. FantasyRealm G. E. M.)
  4. Maximize -combat (or whatever is relevant to your item)
  5. Maximizer shouldn't recommend that you remove your slippers
 

Attachments

Nice!

I’m partway through making a JUnit 5 conversio, which should give some more options for testing. I’m glad to have more tests.
 
Back
Top