Results 1 to 7 of 7

Thread: Check if last adventure was non-combat

  1. #1
    Junior Member
    Join Date
    Aug 2017
    Posts
    6

    Default Check if last adventure was non-combat

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

  2. #2
    Developer Grotfang's Avatar
    Join Date
    Jun 2009
    Location
    United Kingdom
    Posts
    591

    Default

    Is there a way to check if the last adventure was a non-combat and what non-combat it was?
    Originally Posted by Xt8 View Post
    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?

  3. #3

    Default

    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"?

  4. #4
    Developer Grotfang's Avatar
    Join Date
    Jun 2009
    Location
    United Kingdom
    Posts
    591

    Default

    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"?
    Originally Posted by lostcalpolydude View Post
    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?

  5. #5

    Default

    I wanted to do a very similar thing discussed in this thread: http://kolmafia.us/showthread.php?18...unter-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.

  6. #6
    Senior Member ckb's Avatar
    Join Date
    Mar 2006
    Posts
    752

    Default

    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 by ckb; 08-17-2017 at 01:29 AM.

  7. #7
    Junior Member
    Join Date
    Aug 2017
    Posts
    6

    Default

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •