KoLMafia Scripting Contest: Repair the Elves' Shield Generator

Winterbay

Active member
Copied below is the source of "main.php" as it shows up when I load the big-time generator in the relay browser.
Code:
<html><head>
<script language=Javascript>
<!--
if (parent.frames.length == -1) location.href="game.php";
//-->
</script>
<script language=Javascript src="/images/scripts/jquery-1.5.1.js"></script>
<script language=Javascript src="/images/scripts/keybinds.min.2.js"></script>
<script language=Javascript src="/images/scripts/window.20090915.js"></script>
<script language="javascript">function chatFocus(){if(top.chatpane.document.chatform.graf) top.chatpane.document.chatform.graf.focus();}
defaultBind(47, CTRL, chatFocus); defaultBind(190, CTRL, chatFocus);defaultBind(191, CTRL, chatFocus); defaultBind(47, META, chatFocus);defaultBind(190, META, chatFocus); defaultBind(191, META, chatFocus);</script><script>
function switchFocus()
{
	if (top.chatpane.document.chatform.graf.focus) 
		top.chatpane.document.chatform.graf.focus(); 
	return false;
}
function repeat()
{
	var linx = document.getElementsByTagName("A");
	for (var i = 0; i < linx.length; i++)
	{
		var link = linx[i];
		if (link.innerHTML.match(/Adventure Again/) || link.innerHTML.match(/Do it again/))
			location.href = link.href;
	}
}

defaultBind(47, CTRL, switchFocus);
defaultBind(191, CTRL, switchFocus);
defaultBind(47, META, switchFocus);
defaultBind(191, META, switchFocus);
defaultBind(192, NONE, repeat);
defaultBind(220, NONE, repeat);
</script><script language="javascript">
	function updateParseItem(iid, field, info) {
		var tbl = $('#ic'+iid);
		var data = parseItem(tbl);
		if (!data) return;
		data[field] = info;
		var out = [];
		for (i in data) {
			if (!data.hasOwnProperty(i)) continue;
			out.push(i+'='+data[i]);
		}
		tbl.attr('rel', out.join('&'));
	}
	function parseItem(tbl) {
		tbl = $(tbl);
		var rel = tbl.attr('rel');
		var data = {};
		if (!rel) return data;
		var parts = rel.split('&');
		for (i in parts) {
			if (!parts.hasOwnProperty(i)) continue;
			var kv = parts[i].split('=');
			tbl.data(kv[0], kv[1]);
			data[kv[0]] = kv[1];
		}
		return data;
	}
</script><script type="text/javascript" src="/images/scripts/pop_query.20090915.js"></script>
<script type="text/javascript" src="/images/scripts/ircm.20090928.js"></script>
<script type="text/javascript">
function pop_ircm_contents(i, some) {
	var contents = '',
		shown = 0,
		da = ' <a href="#" rel="?" class="small dojaxy">[some]</a> <a href="#" rel="',
		db = '" class="small dojaxy">[all]</a>',
		dc = '<div style="width:100%; padding-bottom: 3px;" rel="',
		dd = '<a href="#" rel="1" class="small dojaxy">[';
	one = 'one'; ss=some;
if (i.d==1 && i.s>0) { shown++; 
contents += dc + 'sellstuff.php?action=sell&ajax=1&type=quant&whichitem%5B%5D=IID&howmany=NUM&pwd=c4bbdc709b5e16f7c5bae0a512b62c07" id="pircm_'+i.id+'"><b>Auto-Sell ('+i.s+' meat):</b> '+dd+one+']</a>';
if (ss) { contents += da + i.n + db;}
contents += '</div>';
}
one = 'one'; ss=some;
if (i.q==0) { shown++; 
contents += dc + 'inventory.php?action=closetpush&ajax=1&whichitem=IID&qty=NUM&pwd=c4bbdc709b5e16f7c5bae0a512b62c07" id="pircm_'+i.id+'"><b>Closet:</b> '+dd+one+']</a>';
if (ss) { contents += da + i.n + db;}
contents += '</div>';
}
one = 'one'; ss=some;
if (i.q==0 && i.g==0 && i.t==1) { shown++; 
contents += dc + 'managestore.php?action=additem&qty1=NUM&item1=IID&price1=&limit1=&ajax=1&pwd=c4bbdc709b5e16f7c5bae0a512b62c07" id="pircm_'+i.id+'"><b>Stock in Mall:</b> '+dd+one+']</a>';
if (ss) { contents += da + i.n + db;}
contents += '</div>';
}
one = 'one'; ss=some;
if (i.q==0) { shown++; 
contents += dc + 'managecollection.php?action=put&ajax=1&whichitem1=IID&howmany1=NUM&pwd=c4bbdc709b5e16f7c5bae0a512b62c07" id="pircm_'+i.id+'"><b>Add to Display Case:</b> '+dd+one+']</a>';
if (ss) { contents += da + i.n + db;}
contents += '</div>';
}
one = 'one'; ss=some;
if (i.q==0 && i.t==1) { shown++; 
contents += dc + 'clan_stash.php?action=addgoodies&ajax=1&item1=IID&qty1=NUM&pwd=c4bbdc709b5e16f7c5bae0a512b62c07" id="pircm_'+i.id+'"><b>Contribute to Clan:</b> '+dd+one+']</a>';
if (ss) { contents += da + i.n + db;}
contents += '</div>';
}
one = 'one'; ss=some;
if (i.q==0 && i.p==0 && i.u=="q" && i.d==1 && i.t==1) { shown++; 
contents += dc + 'craft.php?action=pulverize&ajax=1&smashitem=IID&qty=NUM&pwd=c4bbdc709b5e16f7c5bae0a512b62c07" id="pircm_'+i.id+'"><b>Pulverize:</b> '+dd+one+']</a>';
if (ss) { contents += da + i.n + db;}
contents += '</div>';
}
one = 'one'; ss=some;
if (i.u && i.u != ".") { shown++; 
contents += dc + 'inv_'+(i.u=="a"?"redir":(lab=(i.u=="u"?"use":(i.u=="e"?"eat":(i.u=="b"?"booze":"equip")))))+'.php?ajax=1&whichitem=IID&itemquantity=NUM&quantity=NUM'+(i.u=="q"?"&action=equip":"")+'&pwd=c4bbdc709b5e16f7c5bae0a512b62c07" id="pircm_'+i.id+'"><b>'+ucfirst(unescape(i.ou ? i.ou : (lab=="booze"?"drink":lab)))+':</b> '+dd+one+']</a>';
if (ss && i.u != 'q' && !(i.u=='u' && i.m==0)) { contents += da + i.n + db;}
contents += '</div>';
}

	return [contents, shown];
}
var todo = [];
function nextAction() {
	var next_todo = todo.shift();
	if (next_todo) {
		eval(next_todo);
	}
}
function dojax(dourl, afterFunc, hoverCaller, failureFunc) {
	$.ajax({
		type: 'GET', url: dourl, cache: false,
		global: false,
		success: function (out) {
			nextAction();
			if (out.match(/no\|/)) {
				var parts = out.split(/\|/);
				if (failureFunc) failureFunc(parts[1]);
				else $('#ChatWindow').append('<font color="green">Oops!  Sorry, Dave, you appear to be ' + parts[1] + '.</font><br />' + "\n");
				return;
			}

			if (hoverCaller)  {
				float_results(hoverCaller, out);
				if (afterFunc) { afterFunc(); }
				return;
			}
$(top.mainpane.document).find("#effdiv").remove(); if(!window.dontscroll || (window.dontscroll && dontscroll==0)) { window.scroll(0,0);}
			var $eff = $(top.mainpane.document).find('#effdiv');
			if ($eff.length == 0) {
				var d = top.mainpane.document.createElement('DIV');
				d.id = 'effdiv';
				var b = top.mainpane.document.body;
				if ($('#content_').length > 0) {
					b = $('#content_ div:first')[0];
				}
				b.insertBefore(d, b.firstChild);
				$eff = $(d);
			}
			$eff.find('a[name="effdivtop"]').remove().end()
				.prepend('<a name="effdivtop"></a><center>' + out + '</center>').css('display','block');
			if (!window.dontscroll || (window.dontscroll && dontscroll==0)) {
				top.mainpane.document.location = top.mainpane.document.location + "#effdivtop";
			}
			if (afterFunc) { afterFunc(); }
		}
	});
}</script><script>

var currentkey = 49;
$(document).ready(function () {
	$('form').each(function () {
		var form = this;
		defaultBind(currentkey++, NONE, function () { form.submit(); });
		return currentkey < 58;
	});
});


</script><link rel="stylesheet" type="text/css" href="http://images.kingdomofloathing.com/styles.css">

<script language="Javascript" src="/basics.js"></script><link rel="stylesheet" href="/basics.css" /><link rel='stylesheet' type='text/css' href='http://images.kingdomofloathing.com/actionbar.6.css'><!--[if IE]><link rel='stylesheet' type='text/css' href='http://images.kingdomofloathing.com/actionbar.ie.4.css'><![endif]--></head>

<body><img src='http://images.kingdomofloathing.com/itemimages/blank.gif' id='dragged'><div id='debug'></div><div class=contextmenu id='skillmenu'></div><div class=contextmenu id='itemsmenu'></div><div id=topbar><center><table class=actionbar cellpadding=0 cellspacing=1><tbody><tr class=label><td> </td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr class=blueback><td><a href='choice.php?action=auto'><img src='http://images.kingdomofloathing.com/itemimages/plexpock.gif'></td><td class=spacer></td><td><img src='http://images.kingdomofloathing.com/itemimages/blank.gif' id='skills'></td><td class=spacer></td><td><img src='http://images.kingdomofloathing.com/itemimages/blank.gif'></td><td><img src='http://images.kingdomofloathing.com/itemimages/blank.gif'></td><td><img src='http://images.kingdomofloathing.com/itemimages/blank.gif'></td><td><img src='http://images.kingdomofloathing.com/itemimages/blank.gif'></td><td><img src='http://images.kingdomofloathing.com/itemimages/blank.gif'></td><td><img src='http://images.kingdomofloathing.com/itemimages/blank.gif'></td><td><img src='http://images.kingdomofloathing.com/itemimages/blank.gif'></td><td><img src='http://images.kingdomofloathing.com/itemimages/blank.gif'></td><td><img src='http://images.kingdomofloathing.com/itemimages/blank.gif'></td><td><img src='http://images.kingdomofloathing.com/itemimages/blank.gif'></td><td><img src='http://images.kingdomofloathing.com/itemimages/blank.gif'></td><td><img src='http://images.kingdomofloathing.com/itemimages/blank.gif'></td><td class=spacer></td><td class=spacer></td><td><img src='http://images.kingdomofloathing.com/itemimages/blank.gif'></td></tr><tr class=label><td>auto</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr></tbody></table></center></div><div class='content' id='content_'><div id='effdiv' style='display: none;'></div><div style='overflow: auto;'>
<Center><centeR><table  width=95%  cellspacing=0 cellpadding=0><tr><td style="color: white;" align=center bgcolor=blue><b>Big-Time Generator</b></td></tr><tr><td style="padding: 5px; border: 1px solid blue;"><center><table><tr><td><center><img src="http://images.kingdomofloathing.com/adventureimages/emuhelm.gif" width=100 height=100></center><p>You finally maneuver your E.M.U. over the shield generator. As the rules of sci-fi architecture decree, it's a near-bottomless well with wires, beams, and random protrusions sticking out of the sides at odd angles.<p>Your HUD lights up with a sonar map of the generator well, which takes all that awesome architecture and makes it look kind of like -- well, kind of like a game board, if we're being honest. It looks like it'll be too close quarters to fire your thrusters down there, but if you position yourself at the right spot, you can freefall down to where you need to be. Probably. C'mon, what haven't you got to lose? <p><center><form name=choiceform1 action=choice.php method=post><input type=hidden name=pwd value='c4bbdc709b5e16f7c5bae0a512b62c07'><input type=hidden name=whichchoice value=538><input type=hidden name=option value=1><input class=button type=submit value="See what you have to lose"></form></center></td></tr></table></center></td></tr><tr><td height=4></td></tr></table></center></div></div></body><script src="/onfocus.js"></script></html>

It was linked from this code which was what I got first.
Code:
<html><head><title>The Kingdom of Loathing</title><script language="Javascript" src="/basics.js"></script><link rel="stylesheet" href="/basics.css" /></head><frameset id=rootset cols="4*,*"><frameset id=menuset rows="30,*"><frame name=menupane src="topmenu.php" scrolling=no></frame><frameset id=mainset cols="200,*"><frame name=charpane src="charpane.php"></frame><frame name=mainpane src="main.php"></frame></frameset></frameset><frame name=chatpane src="chatlaunch.php"></frame></frameset><script src="/onfocus.js"></script></html>
 

slyz

Developer
When you automate a choice adventure, Mafia's ChoiceManager will keep picking options according to its internal logic and/or the choiceAdventureXXX preferences. When it faces a choice for which either manual control is set (choiceAdventureXXX = "0" ) or no setting exists (choiceAdventureXXX = "" ), it aborts with the appropriate message. In your case, no choice is pre-set for the Porko board.

We could eventually add automatic handling of the Porko game in Hamburglaris, since Veracity has already implemented all the necessary logic, or maybe you can catch the abort with something like
PHP:
if ( adventure( 1, $location[Hamburglaris] ) ) {}
and determine afterwards if the abort was caused by the choice adventure or by something else.
 

stannius

Member
I have a similar problem. My script plays porko, except with the previous game's probabilities. That is, somehow in the ways I do everything, lastPorkoExpected doesn't get set. I didn't notice for so long because Porko is so easy - as far as I've seen, a random choice has better than even odds of success. In fact, losing on purpose can be difficult. Which is making diagnosing this problem a challenge.

EDIT: Ascended casual so I could test it. I looked at bumpork and saw
Code:
// Redirects to choice.php. Visit it to get the board
		text = visit_url("choice.php");
I added that to my script and it seems happy now. Yay :)
 
Last edited:
Slyz, would you prefer that I use lastPorkoExpected for the porko section, or would you be interested in seeing my own solution for porko that I cobbled together before I realized mafia had it built in?
 

slyz

Developer
Yeah, sorry about that, I just had a rough couple of months. I'm starting to get back to my day to day life, and I'll be going through the scripts soon.
 
Top