Check if last adventure was non-combat

Xt8

New member
Is there a way to check if the last adventure was a non-combat and what non-combat it was?
 

Grotfang

Developer
Is there a way to check if the last adventure was a non-combat and what non-combat it was?

I think so. This is the best I could do:

Code:
string lastEncounter = get_property("lastEncounter");

if(to_monster(lastEncounter) == last_monster()) {
    print("True");
    # lastEncounter was a combat
}
else {
    print("False");
    # lastEncounter was a non-combat
}

I haven't worked through every instance this might present. Are there any combats that might not evaluate to monsters? Are there any non-combats that would?
 

lostcalpolydude

Developer
Staff member
I started typing up a response earlier, but my first test happened to fail with that code.
"the X-32-F Combat Training Snowman" does not evaluate to the monster "X-32-F Combat Training Snowman".

Possibly the same with anything that starts with "the"?
 

Grotfang

Developer
I started typing up a response earlier, but my first test happened to fail with that code.
"the X-32-F Combat Training Snowman" does not evaluate to the monster "X-32-F Combat Training Snowman".

Possibly the same with anything that starts with "the"?

Maybe. Though it seems as though this function ought to work if possible. As far as I can tell the name is taken from the HTML via regex when stored in lastEncounter, but by the time it gets stored in MonsterStatusTracker (where last_monster() gets its info from) the name has been canonicalised to match mafia's internal data.

Honestly, I'm struggling to follow all the parsing and handling between the request coming back and it ending up in MonsterStatusTracker. Is this worth submitting as a bug or is this likely to be unimportant?
 
I wanted to do a very similar thing discussed in this thread: http://kolmafia.us/showthread.php?18136-Was-the-last-encounter-a-combat

I ended up rejecting the method of matching monster names because of those kind of issues (also problems with Hobopolis hobos, Dread monsters and other stuff where procedural names dont match the canonical monster name).

Instead I ended up parsing the last adventure from the session logs using this code snippet:
Code:
	string LastAdvTxt() {
		string lastlog = session_logs(1)[0];
		int nowmark = max(last_index_of(lastlog,"["+my_turncount()+"]"),last_index_of(lastlog,"["+(my_turncount()+1)+"]"));
		return substring(lastlog,nowmark);
	}

But I'm not really sure how you'd go from that to recognising that it was a noncombat.
 

ckb

Minion
Staff member
The thought I has was to check get_property("lastEncounter") and compare that to a lists of know non-combats.
No ideal, but it would be true if you knew what adventures you were looking for.

or maybe this, using that amazing code snippet:

Code:
if (!contains_text(LastAdvTxt(),"Round 1")) {
   //this is not a combat
}
 
Last edited:

Xt8

New member
Ah, this is all good, thanks. I was having trouble finding this kind of thing on the wiki.
 
Top