Bug mp restoration link not being added to charpane

AlbinoRhino

Active member
r12009. The preference is definitely enabled. Attached is the charpane html. The HP restoration link is added but the MP restoration link is not.
 

Attachments

  • charpane.php.htm.txt
    15.6 KB · Views: 51

lostcalpolydude

Developer
Staff member
This is the regex used:
Code:
private static final Pattern POINTS_PATTERN = Pattern.compile( "(doc\\(['\"](hp|mp)[^r]*r><span\\s+class=['\"]?(black|red)['\"]?>)(\\d+)" );
The problem is that, for muscle classes, MP is called Muscularity Points, so with a full charpane (rather than compact) it fails to match on this:
doc("mp");' title="Muscularity Points" alt="Muscularity Points"><br><span class=black>3 / 45</span>

If [^r] could be replaced with something that matches until "r>" is found instead of just until "r" is found, then it would work, but I don't know how to do that.

This has probably been broken for a long time, I'm surprised no one reported it.
 

Alhifar

Member
I might be wrong, but wouldn't
Code:
(doc\\(['\"](hp|mp).*?<br><span\\s+class=['\"]?(black|red)['\"]?>)(\\d+)
work?
 

xKiv

Active member
I am never completely sure how a particular regex dialect spells it, but a eager match like this should be good.
 

lostcalpolydude

Developer
Staff member
That looks like it should work. Since I'm not great with regex I often test things at http://www.regexplanet.com/advanced/java/index.html and I get the results I want when trying it there. When I actually test it in mafia, I get two matches, and both of them find "hp" (based on throwing in a debugging line) rather than one finding "hp" and one finding "mp" like I would expect.
 

roippi

Developer
I'm a fan of this one myself, as I am absolutely terrible with remembering syntax and it's handy to be able to easily look up things like positive lookbehind, or whatever.
 

lostcalpolydude

Developer
Staff member
I changed CharPaneDecorator.POINTS_PATTERN (line 191) with the minor suggested change. Then after
PHP:
String stat = matcher.group( 2 ).toUpperCase();
I added
PHP:
RequestLogger.printLine( stat + " " + hp );
to see what the result was, besides the result of MP not being a link.
 

xKiv

Active member
So ... was it matching HP twice with the old regex too?

Actually, addRestoreLink will be called twice - first time for hp (so the matcher will find HP and addRestoreLink will return), then form mp (and this call will run the matcher again from the start, so it will first find hp, then mp and return). That's probably not optimal use of regexes on some 20k of text, but whatever.

Well, the second call *should* find the mp ... unless you have no mp? Or your mp span class is not black/red? Or it's not "mp" but "Mp" "mP" or "MP"? Or you have documentation for MP somehow disabled??
 

xKiv

Active member
So I should have seen 4 lines of output instead of the 2 that I actually saw. As if it is using instead of

I think you should have seen 3 lines of output.
From addRestoreLink( buffer, true, ...):
HP // and then it goes in the if ( (stat.equals("HP") && hp) || ... ) { ... return; }
And then from addRestoreLink( buffer, false, ...):
HP // ignored, because hp==false, and stat.equals("MP")==false
MP // and then it goes inside if ( ... || (stat.equals("MP") && !hp ) { ... return; }

What's in your charpane html for that part (doc('hp')...doc('mp')...(your MP here)...) preferably both from what KOL sends you and what goes in the buffer parameter?
 

lostcalpolydude

Developer
Staff member
Right, there should be 3 lines of output, not 4. View source outside of mafia gives:
<td align=center><img src="http://images.kingdomofloathing.com/itemimages/hp.gif" class=hand onclick='doc("hp");' title="Hit Points" alt="Hit Points"><br><span class=black>821 / 840</span></td><td align=center><img src="http://images.kingdomofloathing.com/itemimages/mp.gif" class=hand onclick='doc("mp");' title="Mojo Points" alt="Mojo Points"><br><span class=black>748 / 858</span></td></tr><tr><td align=center>
Also, keep in mind that currently-used regex IS giving me an MP restore link (I am not a muscle class right now), basically ruling out anything having to do with the HTML being weird there as an explanation. We want the regex to catch
");' title="Hit Points" alt="Hit Points"><br>
but instead the suggested change is catching
");' title="Hit Points" alt="Hit Points"><br><span class=black>821 / 840</span></td><td align=center><img src="http://images.kingdomofloathing.com/itemimages/mp.gif" class=hand onclick='doc("mp");' title="Mojo Points" alt="Mojo Points"><br>
as far as I can tell.
 

xKiv

Active member
It appears to work correctly when I run this snippet against my java:
Code:
package xkiv;

import java.util.regex.Matcher;
import java.util.regex.Pattern;


public final class Main {

	private Main() {
		
	}

	public static void main(String[] args) throws Exception {
		Pattern pat = Pattern.compile("(doc\\(['\"](hp|mp).*?<br><span\\s+class=['\"]?(black|red)['\"]?>)(\\d+)");
		String text = "<td align=center><img src=\"http://images.kingdomofloathing.com/itemimages/hp.gif\" class=hand onclick='doc(\"hp\");' title=\"Hit Points\" alt=\"Hit Points\"><br><span class=black>821 / 840</span></td><td align=center><img src=\"http://images.kingdomofloathing.com/itemimages/mp.gif\" class=hand onclick='doc(\"mp\");' title=\"Mojo Points\" alt=\"Mojo Points\"><br><span class=black>748 / 858</span></td></tr><tr><td align=center>";
		
		Matcher m = pat.matcher(text);
		
		while (m.find()) {
			System.out.println(m.group(1));
		}
	}
}

/*
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b05)
Java HotSpot(TM) Client VM (build 20.6-b01, mixed mode, sharing)
*/
/*
Output:
doc("hp");' title="Hit Points" alt="Hit Points"><br><span class=black>
doc("mp");' title="Mojo Points" alt="Mojo Points"><br><span class=black>
*/
 
Top