Bug - Fixed Combat Filter weirdness with Funkslinging

I was going through my logs recently and noticed that in some combats when I wanted to use a single item, I actually used 2 of that item (if I had it) via a combat filter, even though I did not use the format for funkslinging.

I wrote a script that verifies the situation by getting 2 gauze garters, going into combat, trying to use 1 but ultimately using both in combat:

Code:
Visit to Manor1: The Haunted Pantry in progress...

[482] The Haunted Pantry
Encounter: fiendish can of asparagus
Round 0: cheesecookie wins initiative!
Round 1: You lose 1 hit point
You have 2 gauze garters.

Round 1: cheesecookie uses the gauze garter and uses the gauze garter!
Round 2: You gain 95 hit points
Round 2: You gain 81 hit points
Round 2: Casablanca Jones whips your opponent in the arm, dealing 36 damage.
Round 2: fiendish can of asparagus takes 36 damage.
Sorry, I can't figure out what "gauze garter" means. Perhaps you have 0.

Used Gauze Garter for testing, done

The script that generates this:
Code:
script "filtertest.ash"

string combatTest(int round, string opp, string text)
{
    static int didGauze = 0;
    if(didGauze == 1)
    {
        cli_execute("/count gauze garter");
        didGauze = 0;
        abort("Used Gauze Garter for testing, done");
    }

    cli_execute("/count gauze garter");
    if(item_amount($item[Gauze Garter]) > 0)
    {
        didGauze = 1;
        return "item gauze garter";
    }

    return "fail";
}

void main()
{
    take_storage(2 - item_amount($item[Gauze Garter]), $item[Gauze Garter]);
    take_closet(2 - item_amount($item[Gauze Garter]), $item[Gauze Garter]);

    print("Gauze garters: " + item_amount($item[Gauze Garter]), "blue");
    cli_execute("/count gauze garter");

    adv1($location[The Haunted Pantry], 1, "combatTest");
}

The actual combat result I am getting is as if I returned "item gauze garter, gauze garter", which is the funkslinging usage format for combat filters.
 

xKiv

Active member
I think the correct format for using only 1 of an item, even if you have 2+ and funkslinging, is
Code:
item gauze garter,
(note the extra comma)
 
I think the correct format for using only 1 of an item, even if you have 2+ and funkslinging, is
Code:
item gauze garter,
(note the extra comma)

I thought that would probably work and was about to ask if that was safe to use if you don't have funkslinging. It didn't work though. I tried "item gauze garter," and "item gauze garter, " (with a trailing space) and still used both of them.
 

xKiv

Active member
OK, parsing FightRequest.getCurrentKey() (I think - it's a long method ...) leads me to suggest to also try "item ,gauze garter" (leave out the *first* item, not the second).
 
OK, parsing FightRequest.getCurrentKey() (I think - it's a long method ...) leads me to suggest to also try "item ,gauze garter" (leave out the *first* item, not the second).

Nope again. The ambiguity, or rather unexpected behavior, is the major issue. I can always wrap item usage up with funkslinging checks and seal teeth. There is just something wrong here.
 

lostcalpolydude

Developer
Staff member
I feel like this behavior is intentional (to save server hits, I guess), but I have no idea where the thread I'm thinking of would be at (from years ago).
 
An update on this:

When using an item that ends the combat, such as Louder Than Bomb, this causes Mafia to think it used 2 of them up even though it only used up one (assuming you have at least 2, of course). refresh inv fixes this but it is not ideal (in terms of server hits) to do so after every combat.
 

lostcalpolydude

Developer
Staff member
1: Mafia doesn't have any good way of knowing that the second item isn't actually used. However, it checks KoL's combat item list in combat to update those values. I don't really remember how that is handled at end of combat (probably exactly how it should be, I'm just not sure), but the start of the next combat should update things regardless.

2: If things are getting that far out of sync, then KoL isn't updating that list properly for some reason, and that is a KoL bug. Maybe it's based on how mafia is submitting the macro, I really wouldn't know where to start with checking on that though.
 

Darzil

Developer
KoL isn't updating that list properly, for some things at any rate. I think it updates during the combat based on what is used, not at the start of combat rounds. It is why when using red buttons, which actually use more, the number is wrong in the next round/fight. It is why when you hand back the military grade nailtrimmers outside combat, they are shown in the item dropdown in the next combat. Have reported it for those two examples, months ago.
 

Veracity

Developer
Staff member
Considering that Jick just said on the podcast that "he's hoping to put in one full day of working on KoL per week" - as if that is an increase - I doubt whether there are any resources available these days to fix bugs in KoL, as opposed to adding enough new content to keep the subscribers content.
 
I've narrowed down the issue to the following code snippet in src/net/sourceforge/kolmafia/request/FightRequest.java

Code:
	else if ( itemCount >= 2 && !soloUseCombatItem( item1 ))
	{
		FightRequest.nextAction += "," + FightRequest.nextAction;
		this.addFormField( "whichitem2", String.valueOf( item1 ) );
	}

I have no idea what this code is for but simply removing it has resolved it on my end for several ascensions now. Some iteration of this code goes all the way back to r1 so there isn't a note about the initial inclusion of this snippet.
 

Theraze

Active member
Lines 1143-1147 in my r17119.

Looks like what it says is to try to use 2 of any item you have multiple of that doesn't have the ATTR_SOLO flag in the item database. Removing that should force it to only funksling if you actually tell it to and probably would make most people happier.
 

xKiv

Active member
IIRC the thinking behind it had something to do with a single css working "best" for both characters with and without funkslinging.

Also, the block preceding the quoted code will add toy mercenary/miniborg/sealthooth/spices if item1 has ATTR_SOLO. That would have the same reasoning, and similar problems (especially for people who want to precisely control damage output for whatever reason).

And the start of the !"skill" branch will turn item A,B into item B if you have no A. I am sure that can be undesirable in some situations too.


And while I am looking at that code, I am also not sure why there is a check for itemCount < 1 in the DICTIONARY subbranch, since that comes almost right after if (itemCount==0) {...; return; }
 

Veracity

Developer
Staff member
If the purpose is to make a single CSS work for funkslingers and non-funkslingers, seems like we should just ignore a second item if you don't have the skill. We may already do that.

There are certainly monsters that have different (better) strategies if you can funksling. The rampaging adding machine, for example.
 

Crowther

Active member
I tried to have one CCS for characters with and without funksling. At first I had it set to funksling a flaregun and blue balls. On my non-funkslinging character, that worked great until I ran out of flareguns and it simply switched to blue balls. I wanted it to abort when I accidentally ran out of flareguns. So, I removed the second item. That worked. However, when I switch back to a character with fucksling, mafia started using two of them per combat instead of the one I asked for. Of course that was only a problem because of the special event. Plenty of times someone might prefer that.
 
I tried to have one CCS for characters with and without funksling. At first I had it set to funksling a flaregun and blue balls. On my non-funkslinging character, that worked great until I ran out of flareguns and it simply switched to blue balls. I wanted it to abort when I accidentally ran out of flareguns. So, I removed the second item. That worked. However, when I switch back to a character with fucksling, mafia started using two of them per combat instead of the one I asked for. Of course that was only a problem because of the special event. Plenty of times someone might prefer that.

I thought it only affected combat filters but neat, it affects CCS.
 
Since it looks like the consensus is that the current behavior (if can funksling and have two of the asked for item, use both) is most desired, I'd like to suggest something else:

When you want to specifically only use one of an item, supply a blank or "" or something in the ccs like such

[eldritch tentacle]
use flare gun, ""
consult WHAM.ash
 

Veracity

Developer
Staff member
Still pondering this.

We have two flags in items.txt:

single = use only one of this item in combat, but feel free to funksling something else with it
solo = use only one of this item and don't funksling.

single items:

all bang potions
anti-anti-antidote
odor extractor
Spooky Putty sheet
4-d camera

solo items:

tattered scrap of paper
divine champaign popper

Now, that's not exactly right. It is reasonable to funksling 2 tatters, since if the first one fails, the second might succeed, and if the first one succeeds, you don't lose the second. But, yes - you should not funksling anything along with a banisher.

The various abstractions should be marked "single", since you can only use one of them per combat.

Regardless, as coded, even were we to pass in $item[none] (or "", in a CCS action) for the second item, the code will proceed to choose ... something else ... for the second item. The selection of items is hardcoded:

toy mercenary
miniborg destroy-o-bot
miniborg laser
miniborg stomper
seal tooth
spices

I think the solution will be to detect that if the second item is explicitly -1, don't Funksling.

Except, now I am wondering how we Macrofy item use.

Code:
		else if ( KoLConstants.activeEffects.contains( FightRequest.BIRDFORM ) )
		{ // can't use items in Birdform
		}
		else
		// must be an item use
		{
			macro.append( "call mafiaround; use " + action + "\n" );
			// TODO
		}
"action" can be either

XXX

or XXX,YYY

where XXX and YYY are item numbers.

Which is to say, I think that if you have "item X" or "use X" in your CCS, we will macrofy it into a single item use, but if you pass that back via a Combat Filter, we don't macrofy it it and, as the original post noted, go through the action handling which will auto-funksling. That code was written before we translated CCS into KoL macros before submitting to KoL.

So, this really is only an issue for combat filters, at the moment.

Which my Deep Machine Tunnels combat filter is noticing, what with trying to sling two abstractions and having KoLmafia log that it is updating the combat item count, since the second one was not used.
 
Last edited:

Veracity

Developer
Staff member
Revision 17506 sill let you specifically say "none" in a CCS or Combat Filter for your second item and, if so, will not funksling.
 
Top