Guest User

Flingers JS

a guest
Nov 23rd, 2016
64
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var found      = [];
  2. var bait_pos   = ["Worm","Maggot","Cricket","Locust","GreenMoth","GreyMoth","Crayfish","Shrimp"];
  3. var hook_pos   = ["Standard","Slim","Large","Double","Bone","Wood"];
  4. var weight_pos = [1,2,3,4,5,6];
  5. var inner_reset = "";
  6. var previous = {'select_bait':[-1],'select_hook':[-1],'select_weight':[-1]};
  7. var sel1,sel2,sel3;
  8. valid=true;
  9.  
  10. function start() {/*
  11.     a1lib.identifyUrl("appconfig.json");
  12.     if (!window.alt1) { document.getElementById("mainTable").innerHTML = "You need to run Alt1 to for this app."; valid=false;}
  13.     else if (alt1.versionint < 8) { document.getElementById("mainTable").innerHTML = "You need at least Alt1 0.0.8 for this app";valid=false;}
  14.     */inner_reset=document.getElementById("mainTable").innerHTML;
  15.     populateOptions();
  16.     return;
  17. }
  18.  
  19. function clicksolve() {
  20.     /*if(valid){
  21.         var img;
  22.         try { img = a1lib.bindfullrs(); } catch (e) { }
  23.  
  24.         if (!img) {
  25.             var problem = "Failed to grab image from your screen. There is more information under Alt1 settings &gt; capture.";
  26.             if (alt1.permissionPixel == false) { problem = "Need 'view screen' permission to grab pixels from the screen. The app permissions can be found by clicking the spanner on the top right of this window."; }
  27.             if (alt1.rsLinked == false) { problem = "Can't find the Runescape window. There is more information under Alt1 settings &gt; capture."; }
  28.             document.getElementById("mainTable").innerHTML = problem;
  29.             return;
  30.         }*/
  31.         solve(); //solve(img);
  32.    
  33. }
  34.  
  35. function solve(img){
  36.     //TODO: IMAGE DETECT TO FIND ROW IN MINIGAME
  37.     //ASSUME FOLLOWING ROW(s) FOUND (IN CATCH HISTORY):
  38.     //
  39.     //Salmon | Docks | 29 | Crayfish | Large | 3 | 100      <--100% fish found
  40.     row={fish:"Salmon",loc:"Docks",bait:"Crayfish",hook:"Large",weight:3,percent:100} //(returned from image detect)
  41.     if(row['percent']==100 && found.indexOf(row['fish'])){ //if not already found
  42.         found.push(row['fish']);
  43.         var str = "<td>"+row['fish']+"</td><td>"+row['loc']+"</td><td>"+row['bait']+"</td><td>"+row['hook']+"</td><td>"+row['weight']+"</td>"
  44.         sel1=document.getElementById(row['fish']).getElementsByClassName("select_bait")[0].selectedIndex;
  45.         sel2=document.getElementById(row['fish']).getElementsByClassName("select_hook")[0].selectedIndex;
  46.         sel3=document.getElementById(row['fish']).getElementsByClassName("select_weight")[0].selectedIndex;
  47.         document.getElementById(row['fish']).innerHTML = str;
  48.           bait_pos.splice(  bait_pos.indexOf(  row['bait']),1);
  49.           hook_pos.splice(  hook_pos.indexOf(  row['hook']),1);
  50.         weight_pos.splice(weight_pos.indexOf(row['weight']),1);
  51.         removeOptions(row['bait'],row['hook'],row['weight']);
  52.         //TODO: overlay an X over removed value's to indicate they should not be used again.
  53.     }
  54. }
  55.  
  56. function removeOptions(bait,hook,weight){ //remove options for confirmed 100% fish
  57.     e1=document.getElementsByClassName("select_bait");
  58.     e2=document.getElementsByClassName("select_hook");
  59.     e3=document.getElementsByClassName("select_weight");
  60.     for(i=0; i<e1.length; i++){
  61.         for(j=0; j<e1[i].length; j++){
  62.             if(e1[i][j].value==bait){
  63.                 e1[i].remove(j);
  64.             }
  65.         }
  66.         for(j=0; j<e2[i].length; j++){
  67.             if(e2[i][j].value==hook){
  68.                 e2[i].remove(j);
  69.             }
  70.         }
  71.         for(j=0; j<e3[i].length; j++){
  72.             if(e3[i][j].value==weight){
  73.                 e3[i].remove(j);
  74.             }
  75.         }
  76.     }
  77.     e1=document.getElementsByClassName("select_bait");
  78.     e2=document.getElementsByClassName("select_hook");
  79.     e3=document.getElementsByClassName("select_weight");
  80.     for(i=0; i<e1.length;i++){
  81.         previous = {'select_bait':[-1],'select_hook':[-1],'select_weight':[-1]};
  82.         if(e1[i].selectedIndex!=0){
  83.             previous['select_bait'].push(e1[i].selectedIndex);
  84.         }
  85.         if(e2[i].selectedIndex!=0){
  86.             previous['select_hook'].push(e2[i].selectedIndex);
  87.         }
  88.         if(e3[i].selectedIndex!=0){
  89.             previous['select_weight'].push(e3[i].selectedIndex);
  90.         }
  91.     }
  92.     for(i=0; i<e1.length; i++){
  93.             e1[i][sel1].disabled = false;
  94.             e2[i][sel2].disabled = false;
  95.             e3[i][sel3].disabled = false;
  96.     }
  97. }
  98.  
  99. function cellChanged(){
  100.     e = document.getElementsByClassName(event.target.className);
  101.     var indexes = [-1];
  102.     for(i=0;i<e.length;i++){    //disable
  103.         if(e[i].selectedIndex!=0){
  104.             indexes.push(e[i].selectedIndex);
  105.         }
  106.         if(event.target.selectedIndex!=0&&e[i]!=event.target){
  107.             e[i][event.target.selectedIndex].disabled = true;
  108.         }
  109.     }
  110. //for values in previous not in current index
  111.     for(i=0;i<previous[event.target.className].length;i++){
  112.         if(indexes.indexOf(previous[event.target.className][i])==-1){
  113.             for(j=0;j<e.length;j++){
  114.                 e[j][previous[event.target.className][i]].disabled=false;
  115.             }
  116.         }
  117.     } previous[event.target.className] = indexes;
  118. }
  119.  
  120. function reset(){
  121.     found      = [];
  122.     bait_pos   = ["Worm","Maggot","Cricket","Locust","Crayfish","Shrimp","Grey Moth","Green Moth"];
  123.     hook_pos   = ["Standard","Slim","Large","Double","Bone","Wood"];
  124.     weight_pos = [1,2,3,4,5,6];
  125.     previous   = {'select_bait':[-1],'select_hook':[-1],'select_weight':[-1]};
  126.     document.getElementById("mainTable").innerHTML = inner_reset;
  127.     populateOptions();
  128. }
  129.  
  130. function populateOptions(){
  131.     var columns,column,z,output;
  132.     columns = ['location','bait','hook','weight'];
  133.     for(z=0;z<columns.length;z++){
  134.         column = columns[z];
  135.         if(column=="location"){s=["Docks","River","Lake","Beach"];}
  136.         else if(column=="bait"){s=bait_pos;}
  137.         else if(column=="hook"){s=hook_pos;}
  138.         else if(column=="weight"){s=weight_pos;}
  139.        
  140.         output = "<select class=select_"+column+"><option>-</option>"
  141.         for(i=0; i<s.length;i++){
  142.             output = output+ "<option>" + s[i] + "</option>";
  143.         } output = output + "</select>"
  144.         e = document.getElementsByClassName(column);
  145.         for(i=0; i<e.length;i++){
  146.             e[i].innerHTML = output;
  147.         }
  148.         if(!(column=='location')){
  149.             e = document.getElementsByClassName("select_"+column);
  150.             for(i=0;i<e.length;i++){
  151.                 e[i].addEventListener('change',cellChanged);
  152.             }
  153.         }
  154.     }
  155. }
RAW Paste Data