Feature choice Relay Overrides

ckb

Minion
Staff member
As the number of choice.php locations increases and grows and the game grows in complexity, I find myself writing more and more little scripts to tweak choice pages. And so does Bale.

It would be sweet to be able to have choice.###.ash relay scripts so we could release them to svn and not step on each other's toes.
This is an expansion of the work done here.
 

Bale

Minion
It's been most of a year since this request was posted. In that time the usefulness of this potential feature has only increased. I'd like to be able to have my Rainy Fax Choice override and lostcalpolydude's deck of every card spoiler both, without having to put them into the same script. having to chain them together makes scripting support more difficult than I would like.

Right now my choice.ash override has four different purposes. It works for me, but the feature would be convenient since it would be a PITA to modify my old Rainy Fax filter for the new Tower to help other people who would want to download only the Rainy Fax script. I suppose I could separate them and have a master choice script that imports them all. Sigh. It would just be easier and tidier if this was implemented.

I suppose I could at least simplify the problem if I remove the Crimbot Factory filter remover and image stabilizer portion of that script since we can no longer adventure in the Crimbot Factory... That would bring my choice script down to only three purposes.
 
Last edited:

ckb

Minion
Staff member
I am still excited about this possibility. I have a half-dozen useful overrides I have made for myself, that I have never released because they are all mashed together in one choice.ash script. Making this request so would solve issues with these.
Thanks.
 

lostcalpolydude

Developer
Staff member
I did think back to this feature request when making my latest choice override. It still seems hard enough to implement that I'm not likely to tackle it any time soon.
 

lostcalpolydude

Developer
Staff member
So I'm working on some stuff, and I might be close to having this working (or it might not be close at all, I haven't made it to the point where there are results to see yet). Would anyone have a problem with masterRelayOverride scripts no longer being supported? I don't think anyone is actually using that feature, and I likely wouldn't support it for choice.php if I'm adding any of this functionality.
 

Bale

Minion
I believe that bumcheekcity's master override was split up into its components after the svn update functionality was added.
 

Theraze

Active member
Yeah, mRO scripts were great 3 years ago, but I believe the people who requested it originally have figured out newer and better ways to do things with improved functionality. :)
 

PeKaJe

Member
In a similar request, would it be possible to make fight.php overrides depending on zone and/or monster ID? I've got an override for The Fun-Guy Mansion that analyzes the 'shroom and suggests combat strategies. And a different one for The Mansion of Dr. Weirdeaux (which mainly realigns Monster Manuel data for extremely high level monsters). Would be handy if they could somehow be kept in separate relay overrides.
 

lostcalpolydude

Developer
Staff member
My attempt at making this work got me nothing but a NPE, and I have my doubts about having actually accomplished anything, so I don't know if or when I'll actually have anything working.
 

xKiv

Active member
In a similar request, would it be possible to make fight.php overrides depending on zone and/or monster ID?

You don't necessarily know what those are (teleportitis [1], blindness).

[1] I am not sure if location in charpane gets updated during the fight, or after it - but it won't have been updated when the first combat page is processed. I think. Unless mafia requests it then.
 

zarqon

Well-known member
I saw some discussion on this elsewhere, believe it was a dev saying something about how this is unlikely to be implementable due to being unable to know the choice number until after the page loads.

Having a wee bit of experience with these sorts of things with BatMan RE, I suggest that mafia include a little JavaScript/jQuery by default for choice.php. On document.ready, it would:

  1. Detect the choice number and AJAX the entire contents of the html to choice.XXXX.ash (XXXX being the choice number).
  2. If the result is empty, either the specific choice file doesn't exist or it returned an empty string. Do nothing. Otherwise:
  3. Completely replace the html with the returned content.

This means that specific choice.php override scripts would work slightly differently to normal relay overrides -- rather than calling visit_url() you would check in form_fields() for the page data. Also there's some slight inelegance with the page load, as the original content will load first before being replaced by the overridden/enhanced content.

Still, it would serve the purpose of allowing specific override scripts for specific choices. In fact, it could be done right now without any changes to mafia by making a choice.php override that injects this single AJAX command.

Thoughts?
 

zarqon

Well-known member
Had a little time to work this up today. Since KoL already includes jQuery, we can use that, though the version they use is quite old so we have to be careful about which functions we use. The following jQuery is tested working:

PHP:
var loaded = false;
jQuery(function($){
   var which = parseInt($("input[name='whichchoice']").val());
   if (!loaded && which && which > 0) jQuery.ajax({
      url: 'choice.'+which+'.ash',
      data: {whichchoice: which, page: $('body').html()},
      dataType: 'html',
      success: function(newcont) {
         if (newcont) $('body').html(newcont);
         loaded = true;
      },
   });
});

I ran across an issue which introduces a limitation to this functionality: some browsers will strip the html and body tags when replacing content (which makes perfect sense, really), so this script only sends/replaces everything in the body tag, not the entire page. However, I can't see this being a major issue. Even if you need to import additional scripts, that can be done in the body tag as well.

Below is what I put together to test it out. The choice number is for The Shore, Inc., since the choice there was free to test. If I were going to properly release this, I'd just write the JavaScript into the page rather than including a separate file, but it was easier to test this way.

EDIT: I guess the next decision is: does this belong in mafia or should it just be released as a script? I'm happy with either and will spin it into a proper release if so desired. The benefit of including it in mafia is that users could still use their own choice.ash override if they like without losing the functionality this provides.

EDIT: Another nifty feature we could add to this is break out the shopkeepers, so you could have things like choice.The Dinsey Company Store.ash and so forth.

NOTE: choice.ash and choice.js removed because they are merged in the following post.
 

Attachments

  • choice.793.ash
    316 bytes · Views: 27
Last edited:

zarqon

Well-known member
Any feedback on this?

Today I merged the .js file into the .ash file, and also made a basic spoilers helper for Maint Misbehavin' (the maintenance tunnels at Dinseyland) to continue testing. Attached for your pleasure.

I also discovered another difference from the normal relay script behavior with this method: if you click "View Source" in your browser you get the unaltered source, because the page content is modified by a script after it loads rather than before it is served to the browser. This could be helpful or unhelpful depending on what you are looking for.
 

Attachments

  • choice.1067.ash
    1.6 KB · Views: 35
  • choice.ash
    943 bytes · Views: 39
Last edited:

lostcalpolydude

Developer
Staff member
I got that javascript added to choice.php with
Code:
		String js = "\n<script>var loaded = false;\n" +
		"jQuery(function($){\n" +
		"  var which = parseInt($(\"input[name='whichchoice']\").val());\n" +
		"  if (!loaded && which && which > 0) jQuery.ajax({\n" +
		"    url: 'choice.'+which+'.ash',\n" +
		"    data: {whichchoice: which, page: $('body').html()},\n" +
		"    dataType: 'html',\n" +
		"    success: function(newcont) {\n" +
		"      if (newcont) $('body').html(newcont);\n" +
		"      loaded = true;\n" +
		"    },\n" +
		"  });\n" +
		"}); </script>";
		StringUtilities.singleStringReplace( buffer, "</head>", js + "</head>" );
added to the start of ChoiceManager.decorateChoice(). I grabbed your choice.1067.ash to test with. At first I thought nothing was happening, but then I added a print() statement to the top of main() and saw the CLI output. I don't know what is supposed to be in "page" so I can't really troubleshoot further.
 

zarqon

Well-known member
It ought to display helpful spoilers underneath each choice button, as in the screenshot:

screen-choice1067.png

Did those not show up for you? It works for me in both Chrome and IE. When using this script, form_fields()["page"] ought to contain the entire HTML of the page between the <body></body> tags.
 

lostcalpolydude

Developer
Staff member
It may be a difference between loading that javascript from an ash script and in the base page source. None of that showed up for me.
 

zarqon

Well-known member
Hmmm. Possibly the \n's at the end of each line aren't being changed to line breaks? Try removing them, as they are purely cosmetic.

Also you could throw an alert('the script runs!'); in there to debug whether or not the jQuery is executing. If it's not, major browsers also have a Java console where you can see any errors that are generated by JavaScript that runs on web pages. In Chrome, you can hit CTRL+SHIFT+I and it's available in the lowermost window. In IE, it's under Development Tools.
 

lostcalpolydude

Developer
Staff member
The line breaks were working properly, and the JavaScript console was empty. I can try adding an alert() to see if anything happens.
 

zarqon

Well-known member
Did the alert() work? If so, I suspect you're coming across another peculiarity of this method of doing things, which puts a slightly higher burden on the scripters: various browsers "clean up" the HTML they are given, and when jQuery fetches said HTML, it gets the browser-altered version. For the most part, the only difference is in quotes added around attributes that originally lacked them. Easy enough to work around with a matcher, but can cause some head-scratching. Which browser did you test in?
 
Top