record buff {
string effectName;
string effectHTML;
string effectImage;
string effectType;
string effectMod;
int effectTurns;
boolean isIntrinsic;
};
buff parseBuff(string source) {
buff myBuff;
boolean doArrows = get_property("relayAddsUpArrowLinks").to_boolean();
boolean showIcons = (vars["chit.effects.showicons"]=="false" || isCompact)? false: true;
string columnIcon, columnTurns, columnArrow;
string spoiler, style;
matcher parse = create_matcher('(?:<td[^>]*>(.*?)</td>)?<td[^>]*>(<.*?itemimages/([^"]*).*?)</td><td[^>]*>[^>]*>(.*?) \\((?:(.*?), )?((?:<a[^>]*>)?(\\d+||∞)(?:</a>)?)\\)(?:(?:</font>)? (<a.*?</a>))?.*?</td>', source);
// The ? stuff at the end is because those arrows are a mafia option that might not be present
if(parse.find()) {
columnIcon = parse.group(2); // This is full html for the icon
myBuff.effectImage = parse.group(3);
myBuff.effectName = parse.group(4);
spoiler = parse.group(5); // This appears for "Form of...Bird!" and "On the Trail"
columnTurns = parse.group(6);
if(parse.group(7) == "∞") { // Is it intrinsic?
myBuff.effectTurns = -1;
myBuff.isIntrinsic = true;
} else
myBuff.effectTurns = parse.group(7).to_int();
// There are various problems with KoL's native uparrows. Only use them if KoL's uparrows are missing
if(parse.group(8) != "")
columnArrow = parse.group(8).replace_string("/images/", imagePath).replace_string("up.gif", "up.png");
else if(parse.group(1) != "" ) {
doArrows = true; // In case they were disabled in KoLmafia. Make a column for it.
columnArrow = parse.group(1);
}
}
string effectAlias = myBuff.effectName;
//ckb: Get effect modifier for current buff
myBuff.effectMod = string_modifier(myBuff.effectName,"modifiers");
//Apply any styling/renaming as specified in effects map
if(chitEffectsMap contains myBuff.effectName) {
matcher pattern = create_matcher('(type|alias|style|href|image):"([^"]*)', chitEffectsMap[myBuff.effectName]);
while(pattern.find()) {
switch(pattern.group(1)) {
case "type":
myBuff.effectType = pattern.group(2);
break;
case "alias":
// "href" might come before alias, so...
effectAlias = effectAlias.replace_string(myBuff.effectName, pattern.group(2));
break;
case "style":
style = pattern.group(2);
break;
case "href":
effectAlias = '<a href="'+pattern.group(2)+'" target=mainpane>' + effectAlias + "</a>";
break;
case "image":
if(vars["chit.effects.modicons"].to_boolean()) {
string image = pattern.group(2);
if(image == "corpsetini" && gameday_to_string() == "Boozember 7")
image = "turkeyleg";
columnIcon = columnIcon.replace_string(myBuff.effectImage, image);
myBuff.effectImage = image;
}
break;
}
}
}
// Flavour of Magic picker!
if($strings[Spirit of Cayenne, Spirit of Peppermint, Spirit of Garlic, Spirit of Wormwood, Spirit of Bacon Grease] contains myBuff.effectName) {
columnIcon = '<a class="chit_launcher" rel="chit_pickerflavour" href="#">' + columnIcon + '</a>';
columnTurns = '<a class="chit_launcher" rel="chit_pickerflavour" href="#">∞</a>';
pickerFlavour();
}
//Add spoiler info
if(length(spoiler) > 0)
effectAlias += " "+spoiler;
// Fix for blank "On the Trail" problem.
if(length(effectAlias) == 0)
effectAlias = myBuff.effectName;
//Replace effect icons, if enabled
string [string] classmap;
classmap["at"] = "accordion.gif";
classmap["sc"] = "club.gif";
classmap["tt"] = "turtle.gif";
classmap["sa"] = "saucepan.gif";
classmap["pm"] = "pastaspoon.gif";
classmap["db"] = "discoball.gif";
if ((index_of(vars["chit.effects.classicons"], myBuff.effectType) > -1) && (classmap contains myBuff.effectType)) {
columnIcon = columnIcon.replace_string(myBuff.effectImage, classmap[myBuff.effectType]);
myBuff.effectImage = classmap[myBuff.effectType];
}
buffer result;
result.append('<tr class="effect"');
if(length(style) > 0)
result.append(' style="' + style + '"');
result.append('>');
if(showIcons)
result.append('<td class="icon">' + columnIcon + '</td>');
result.append('<td class="info"');
if(doArrows && myBuff.isIntrinsic)
result.append(' colspan="2"');
result.append('>');
result.append(effectAlias);
//ckb: Add modification details for buffs and effects
if (length(myBuff.effectMod)>0) {
result.append('<br><small style="color:gray">');
result.append(myBuff.effectMod);
result.append('</small');
}
result.append('</td>');
if(myBuff.isIntrinsic) {
result.append('<td class="infinity');
if(!doArrows)
result.append(' right');
result.append('">');
} else {
if(!doArrows)
result.append('<td class="right">');
else if (columnTurns != "")
result.append('<td class="shrug">');
else
result.append('<td class="noshrug">');
}
result.append(columnTurns);
result.append('</td>');
if(doArrows && !myBuff.isIntrinsic) {
if(columnArrow == "")
result.append('<td> </td>');
else {
result.append('<td class="powerup">');
result.append(columnArrow);
result.append('</td>');
}
}
result.append('</tr>');
myBuff.effectHTML = result.to_string();
return myBuff;
}