Advertisement
musaad-sa

Untitled

Apr 16th, 2021
2,219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var _____WB$wombat$assign$function_____ = function(name) {return (self._wb_wombat && self._wb_wombat.local_init && self._wb_wombat.local_init(name)) || self[name]; };
  2. if (!self.__WB_pmw) { self.__WB_pmw = function(obj) { this.__WB_source = obj; return this; } }
  3. {
  4.   let window = _____WB$wombat$assign$function_____("window");
  5.   let self = _____WB$wombat$assign$function_____("self");
  6.   let document = _____WB$wombat$assign$function_____("document");
  7.   let location = _____WB$wombat$assign$function_____("location");
  8.   let top = _____WB$wombat$assign$function_____("top");
  9.   let parent = _____WB$wombat$assign$function_____("parent");
  10.   let frames = _____WB$wombat$assign$function_____("frames");
  11.   let opener = _____WB$wombat$assign$function_____("opener");
  12.  
  13. javascript:
  14. var warehouseCapacity = [];
  15. var allWoodTotals = [];
  16. var allClayTotals = [];
  17. var allIronTotals = [];
  18. var availableMerchants = [];
  19. var totalMerchants = [];
  20. var farmSpaceUsed = [];
  21. var farmSpaceTotal = [];
  22. var villagesData = [];
  23. var allWoodObjects, allClayObjects, allIronObjects, allVillages;
  24. var totalsAndAverages = "";
  25. var data, totalWood = 0, totalStone = 0, totalIron = 0, resLimit = 0;
  26. var sendBack;
  27. var totalWoodSent = 0; totalStoneSent = 0; totalIronSent = 0;
  28. var backgroundColor = "#36393f";
  29. var borderColor = "#3e4147";
  30. var headerColor = "#202225";
  31. var titleColor = "#ffffdf";
  32. var langShinko = [
  33.     "Resource sender for flag boost minting",
  34.     "Enter coordinate to send to",
  35.     "Save",
  36.     "Creator",
  37.     "Player",
  38.     "Village",
  39.     "Points",
  40.     "Coordinate to send to",
  41.     "Keep WH% behind",
  42.     "Recalculate res/change",
  43.     "Res sender",
  44.     "Source village",
  45.     "Target village",
  46.     "Distance",
  47.     "Wood",
  48.     "Clay",
  49.     "Iron",
  50.     "Send resources",
  51.     "Created by Sophie 'Shinko to Kuma'"
  52. ]
  53. if (game_data.locale == "en_DK") {
  54.     langShinko = [
  55.         "Resource sender for flag boost minting",
  56.         "Enter coordinate to send to",
  57.         "Save",
  58.         "Creator",
  59.         "Player",
  60.         "Village",
  61.         "Points",
  62.         "Coordinate to send to",
  63.         "Keep WH% behind",
  64.         "Recalculate res/change",
  65.         "Res sender",
  66.         "Source village",
  67.         "Target village",
  68.         "Distance",
  69.         "Wood",
  70.         "Clay",
  71.         "Iron",
  72.         "Send resources",
  73.         "Created by Sophie 'Shinko to Kuma'"
  74.     ]
  75. }
  76. if (game_data.locale == "el_GR") {
  77.     langShinko = [
  78.         "Αποστολή πόρων",
  79.         "Εισάγετε τις συντεταγμένες - στόχο",
  80.         "Αποθήκευση",
  81.         "Δημιουργός",
  82.         "Παίκτης",
  83.         "Χωριό",
  84.         "Πόντοι",
  85.         "Στόχος",
  86.         "Διατήρησε το % Αποθήκης κάτω από",
  87.         "Υπολογισμός πόρων/αλλαγή στόχου",
  88.         "Αποστολή πόρων",
  89.         "Προέλευση",
  90.         "Χωριό στόχος",
  91.         "Απόσταση",
  92.         "Ξύλο",
  93.         "Πηλός",
  94.         "Σίδερο",
  95.         "Αποστολή πόρων",
  96.         "Δημιουργήθηκε από την Sophie 'Shinko to Kuma'"
  97.     ]
  98. }
  99. /*if (game_data.locale == "nl_NL") {
  100.     langShinko = [
  101.         "Resource sender for flag boost minting",
  102.         "Enter coordinate to send to",
  103.         "Save",
  104.         "Creator",
  105.         "Player",
  106.         "Village",
  107.         "Points",
  108.         "Coordinate to send to",
  109.         "Keep WH% behind",
  110.         "Recalculate res/change",
  111.         "Res sender",
  112.         "Source village",
  113.         "Target village",
  114.         "Distance",
  115.         "Wood",
  116.         "Clay",
  117.         "Iron",
  118.         "Send resources",
  119.         "Created by Sophie 'Shinko to Kuma'"
  120.     ]
  121. }*/
  122. cssClassesSophie = `
  123. <style>
  124. .sophRowA {
  125. background-color: #32353b;
  126. color: white;
  127. }
  128. .sophRowB {
  129. background-color: #36393f;
  130. color: white;
  131. }
  132. .sophHeader {
  133. background-color: #202225;
  134. font-weight: bold;
  135. color: white;
  136. }
  137. </style>`
  138.  
  139. $("#contentContainer").eq(0).prepend(cssClassesSophie);
  140. $("#mobileHeader").eq(0).prepend(cssClassesSophie);
  141. /*var console = {
  142.     log: function(msg) { alert(msg); }
  143. };*/
  144.  
  145. //check if we have a limit set for the res we want to keep in the villages
  146. if ("resLimit" in sessionStorage) {
  147.     //found resLimit in storage, get it
  148.     console.log('ok');
  149.     resLimit = parseInt(sessionStorage.getItem("resLimit", resLimit));
  150. }
  151. else {
  152.     //create resLimit for first time in sessionstorage
  153.     sessionStorage.setItem("resLimit", resLimit);
  154.     console.log('not found');
  155. }
  156.  
  157. //collect overview so we can get all the information necessary from all villages
  158. if (game_data.player.sitter > 0) {
  159.     URLReq = `game.php?t=${game_data.player.id}&screen=overview_villages&mode=prod&page=-1&`;
  160. }
  161. else {
  162.     URLReq = "game.php?&screen=overview_villages&mode=prod&page=-1&";
  163. }
  164. $.get(URLReq, function () {
  165.     console.log("Managed to grab the page");
  166. })
  167.     .done(function (page) {
  168.  
  169.         //different HTML for mobile devices, so have to seperate
  170.         if ($("#mobileHeader")[0]) {
  171.             console.log("mobile");
  172.             allWoodObjects = $(page).find(".res.mwood,.warn_90.mwood,.warn.mwood");
  173.             allClayObjects = $(page).find(".res.mstone,.warn_90.mstone,.warn.mstone");
  174.             allIronObjects = $(page).find(".res.miron,.warn_90.miron,.warn.miron");
  175.             allWarehouses = $(page).find(".mheader.ressources");
  176.             allVillages = $(page).find(".quickedit-vn");
  177.             allFarms = $(page).find(".header.population");
  178.             allMerchants = $(page).find('a[href*="market"]');
  179.             //grabbing wood amounts
  180.             for (var i = 0; i < allWoodObjects.length; i++) {
  181.                 n = allWoodObjects[i].textContent;
  182.                 n = n.replace(/\./g, '').replace(',', '');
  183.                 allWoodTotals.push(n);
  184.             };
  185.  
  186.  
  187.             //grabbing clay amounts
  188.             for (var i = 0; i < allClayObjects.length; i++) {
  189.                 n = allClayObjects[i].textContent;
  190.                 n = n.replace(/\./g, '').replace(',', '');
  191.                 allClayTotals.push(n);
  192.             };
  193.  
  194.  
  195.             //grabbing iron amounts
  196.             for (var i = 0; i < allIronObjects.length; i++) {
  197.                 n = allIronObjects[i].textContent;
  198.                 n = n.replace(/\./g, '').replace(',', '');
  199.                 allIronTotals.push(n);
  200.             };
  201.  
  202.             //grabbing warehouse capacity
  203.             for (var i = 0; i < allVillages.length; i++) {
  204.                 warehouseCapacity.push(allWarehouses[i].parentElement.innerText);
  205.             };
  206.  
  207.             //grabbing available merchants and total merchants
  208.             for (var i = 0; i < allVillages.length; i++) {
  209.                 for (var j = 1; j < allMerchants.length; j++) {
  210.                     availableMerchants.push(allMerchants[j].innerText);
  211.                 }
  212.                 totalMerchants.push("999");
  213.             };
  214.  
  215.             //grabbing used farmspace and total farmspace
  216.             for (var i = 0; i < allVillages.length; i++) {
  217.                 farmSpaceUsed.push(allFarms[i].parentElement.innerText.match(/(\d*)\/(\d*)/)[1]);
  218.                 farmSpaceTotal.push(allFarms[i].parentElement.innerText.match(/(\d*)\/(\d*)/)[2]);
  219.             };
  220.  
  221.         }
  222.         else {
  223.             console.log("desktop");
  224.             allWoodObjects = $(page).find(".res.wood,.warn_90.wood,.warn.wood");
  225.             allClayObjects = $(page).find(".res.stone,.warn_90.stone,.warn.stone");
  226.             allIronObjects = $(page).find(".res.iron,.warn_90.iron,.warn.iron")
  227.             allVillages = $(page).find(".quickedit-vn");
  228.             //grabbing wood amounts
  229.             for (var i = 0; i < allWoodObjects.length; i++) {
  230.                 n = allWoodObjects[i].textContent;
  231.                 n = n.replace(/\./g, '').replace(',', '');
  232.                 allWoodTotals.push(n);
  233.             };
  234.  
  235.  
  236.             //grabbing clay amounts
  237.             for (var i = 0; i < allClayObjects.length; i++) {
  238.                 n = allClayObjects[i].textContent;
  239.                 n = n.replace(/\./g, '').replace(',', '');
  240.                 allClayTotals.push(n);
  241.             };
  242.  
  243.  
  244.             //grabbing iron amounts
  245.             for (var i = 0; i < allIronObjects.length; i++) {
  246.                 n = allIronObjects[i].textContent;
  247.                 n = n.replace(/\./g, '').replace(',', '');
  248.                 allIronTotals.push(n);
  249.             };
  250.  
  251.  
  252.             //grabbing warehouse capacity
  253.             for (var i = 0; i < allVillages.length; i++) {
  254.                 warehouseCapacity.push(allIronObjects[i].parentElement.nextElementSibling.innerHTML);
  255.             };
  256.  
  257.             //grabbing available merchants and total merchants
  258.             for (var i = 0; i < allVillages.length; i++) {
  259.                 availableMerchants.push(allIronObjects[i].parentElement.nextElementSibling.nextElementSibling.innerText.match(/(\d*)\/(\d*)/)[1]);
  260.                 totalMerchants.push(allIronObjects[i].parentElement.nextElementSibling.nextElementSibling.innerText.match(/(\d*)\/(\d*)/)[2]);
  261.             };
  262.  
  263.             //grabbing used farmspace and total farmspace
  264.             for (var i = 0; i < allVillages.length; i++) {
  265.                 farmSpaceUsed.push(allIronObjects[i].parentElement.nextElementSibling.nextElementSibling.nextElementSibling.innerText.match(/(\d*)\/(\d*)/)[1]);
  266.                 farmSpaceTotal.push(allIronObjects[i].parentElement.nextElementSibling.nextElementSibling.nextElementSibling.innerText.match(/(\d*)\/(\d*)/)[2]);
  267.             };
  268.         }
  269.  
  270.  
  271.         //making one big array to work with
  272.         for (var i = 0; i < allVillages.length; i++) {
  273.             villagesData.push({
  274.                 "id": allVillages[i].dataset.id,
  275.                 "url": allVillages[i].children[0].children[0].href,
  276.                 "coord": allVillages[i].innerText.trim().match(/\d+\|\d+/)[0],
  277.                 "name": allVillages[i].innerText.trim(),
  278.                 "wood": allWoodTotals[i],
  279.                 "stone": allClayTotals[i],
  280.                 "iron": allIronTotals[i],
  281.                 "availableMerchants": availableMerchants[i],
  282.                 "totalMerchants": totalMerchants[i],
  283.                 "warehouseCapacity": warehouseCapacity[i],
  284.                 "farmSpaceUsed": farmSpaceUsed[i],
  285.                 "farmSpaceTotal": farmSpaceTotal[i]
  286.             });
  287.         };
  288.  
  289.     });
  290.  
  291.  
  292. //ask user what coordinate they want to send resources to
  293. askCoordinate();
  294.  
  295. function createList() {
  296.     //if list is already made, delete both the older(possibly out of date list), with new one and readd the target and WH limit
  297.     if ($("#sendResources")[0]) {
  298.         $("#sendResources")[0].remove();
  299.         $("#resourceSender")[0].remove();
  300.  
  301.     }
  302.     //UI creation of the list
  303.     var htmlString = `
  304.                 <div id="resourceSender">
  305.                     <table id="Settings" width="600">
  306.                         <thead>
  307.                             <tr>
  308.                                 <td class="sophHeader">${langShinko[7]}</td>
  309.                                 <td class="sophHeader">${langShinko[8]}</td>
  310.                                 <td class="sophHeader"></td>
  311.                                 <td class="sophHeader"></td>
  312.                             </tr>
  313.                         </tdead>
  314.                         <tbody>
  315.                         <tr >
  316.                             <td class="sophRowA">
  317.                                 <input type="text" ID="coordinateTarget" name="coordinateTarget" size="20" margin="5" align=left>
  318.                             </td>
  319.                             <td class="sophRowA" align="right">
  320.                                 <input type="text" ID="resPercent" name="resPercent" size="1" align=right>%
  321.                             </td>
  322.                             <td class="sophRowA" margin="5">
  323.                                 <button type="button" ID="button" class="btn-confirm-yes" >${langShinko[2]}</button>
  324.                             </td>
  325.                             <td class="sophRowA">
  326.                                 <button type="button" ID="sendRes" class="btn" name="sendRes" onclick=reDo()> ${langShinko[9]}</button>
  327.                             </td>
  328.                             </tr>
  329.                         </tbody>
  330.                     </table>
  331.                     </br>
  332.                 </div>`.trim();
  333.     //adding the target and WH limit DIV to the page
  334.     uiDiv = document.createElement('div');
  335.     uiDiv.innerHTML = htmlString;
  336.  
  337.     //creating header for the actual list of sends
  338.     htmlCode = `
  339.             <div id="sendResources" border=0>
  340.                 <table id="tableSend" width="100%">
  341.                     <tbody id="appendHere">
  342.                         <tr>
  343.                             <td class="sophHeader" colspan=7 width=550” style="text-align:center" >${langShinko[10]}</td>
  344.                         </tr>
  345.                         <tr>
  346.                             <td class="sophHeader" width="25%" style="text-align:center">${langShinko[11]}</td>
  347.                             <td class="sophHeader" width="25%" style="text-align:center">${langShinko[12]}</td>
  348.                             <td class="sophHeader" width="5%" style="text-align:center">${langShinko[13]}</td>
  349.                             <td class="sophHeader" width="10%" style="text-align:center">${langShinko[14]}</td>
  350.                             <td class="sophHeader" width="10%" style="text-align:center">${langShinko[15]}</td>
  351.                             <td class="sophHeader" width="10%" style="text-align:center">${langShinko[16]}</td>
  352.                             <td class="sophHeader" width="15%">
  353.                                 <font size="1">${langShinko[18]}</font>
  354.                             </td>
  355.                         </tr>
  356.                     </tbody>
  357.                 </table>
  358.             </div>
  359.             `;
  360.  
  361.     //append the page, mobileHeader will only work on mobile devices, and contentContainer won't, and vice versa, no need to add code to seperate
  362.     $("#mobileHeader").eq(0).append(htmlCode);
  363.     $("#contentContainer").eq(0).prepend(htmlCode);
  364.     $("#mobileHeader").prepend(uiDiv.firstChild);
  365.     $("#contentContainer").prepend(uiDiv.firstChild);
  366.     $("#resPercent")[0].value = resLimit;
  367.     $("#coordinateTarget")[0].value = coordinate;
  368.  
  369.     // save coordinate and reslimit functionality
  370.     $('#button').click(function () {
  371.         coordinate = $("#coordinateTarget")[0].value.match(/\d+\|\d+/)[0];
  372.         sessionStorage.setItem("coordinate", coordinate);
  373.         resLimit = $("#resPercent")[0].value;
  374.         sessionStorage.setItem("resLimit", resLimit);
  375.     });
  376.     listHTML = ``;
  377.  
  378.  
  379.     //adding sent so far
  380.  
  381.     $("#resourceSender").eq(0).prepend(`<table id="playerTarget" width="600">
  382.     <tbody>
  383.         <tr>
  384.             <td class="sophHeader" rowspan="3"><img src="`+ sendBack[2] + `"></td>
  385.             <td class="sophHeader">${langShinko[4]}:</td>
  386.             <td class="sophRowA">`+ sendBack[3] + `</td>
  387.             <td class="sophHeader"><span class="icon header wood"> </span></td>
  388.             <td class="sophRowB" id="woodSent"></td>
  389.         </tr>
  390.         <tr>
  391.             <td class="sophHeader">${langShinko[5]}:</td>
  392.             <td class="sophRowB">`+ sendBack[1] + `</td>
  393.             <td class="sophHeader"><span class="icon header stone"> </span></td>
  394.             <td class="sophRowA" id="stoneSent"></td>
  395.         </tr>
  396.         <tr>
  397.             <td class="sophHeader">${langShinko[6]}: </td>
  398.             <td class="sophRowA">`+ sendBack[4] + `</td>
  399.             <td class="sophHeader"><span class="icon header iron"> </span></td>
  400.             <td class="sophRowB" id="ironSent"></td>
  401.         </tr>
  402.     </tbody>
  403. </table>`);
  404.  
  405.  
  406.     //creating table rows
  407.     for (var i = 0; i < villagesData.length; i++) {
  408.         if (i % 2 == 0) {
  409.             tempRow = " id='" + i + "' class='sophRowB'";
  410.         }
  411.         else {
  412.             tempRow = " id='" + i + "' class='sophRowA'";
  413.         }
  414.         res = calculateResAmounts(villagesData[i].wood, villagesData[i].stone, villagesData[i].iron, villagesData[i].warehouseCapacity, villagesData[i].availableMerchants);
  415.         if (res.wood + res.stone + res.iron != 0 && villagesData[i].id != sendBack[0]) {
  416.             listHTML += `
  417.         <tr ${tempRow} height="40">
  418.             <td><a href="${villagesData[i].url}" style="color:#40D0E0;">${villagesData[i].name} </a></td>
  419.             <td> <a href="" style="color:#40D0E0;">${sendBack[1]}</a> </td>
  420.             <td>${checkDistance(sendBack[5], sendBack[6], villagesData[i].coord.substring(0, 3), villagesData[i].coord.substring(4, 7))}</td>
  421.             <td width="50" style="text-align:center">${res.wood}<span class="icon header wood"> </span></td>
  422.             <td width="50" style="text-align:center">${res.stone}<span class="icon header stone"> </span></td>
  423.             <td width="50" style="text-align:center">${res.iron}<span class="icon header iron"> </span></td>
  424.             <td style="text-align:center"><input type="button" class="btn evt-confirm-btn btn-confirm-yes" id="sendResources" value="${langShinko[17]}" onclick=sendResource(${villagesData[i].id},${sendBack[0]},${res.wood},${res.stone},${res.iron},${i})></td>
  425.         </tr>`
  426.         }
  427.     }
  428.     $("#appendHere").eq(0).append(listHTML);
  429.     //      redo the rows appearances cause some are ommited
  430.     //      (if you target yourself, you dont want to have the option to send to your own village from that same village,
  431.     //      wont work and breaks script, or if you would have to send 0 res, breaks script too)
  432.     sortTableTest(2);
  433.     formatTable();
  434.  
  435.     //put the focus on the first button in the list so the user can start cycling through them
  436.     $(":button,#sendResources")[3].focus();
  437. }
  438.  
  439. function sendResource(sourceID, targetID, woodAmount, stoneAmount, ironAmount, rowNr) {
  440.     $(':button[id^="sendResources"]').prop('disabled', true);
  441.     setTimeout(function () { $("#" + rowNr)[0].remove(); $(':button[id^="sendResources"]').prop('disabled', false); $(":button,#sendResources")[3].focus(); }, 200);
  442.     var e = { "target_id": targetID, "wood": woodAmount, "stone": stoneAmount, "iron": ironAmount };
  443.     TribalWars.post("market", {
  444.         ajaxaction: "map_send", village: sourceID
  445.     }, e, function (e) {
  446.         Dialog.close(),
  447.             UI.SuccessMessage(e.message)
  448.         console.log(e.message)
  449.         totalWoodSent += woodAmount;
  450.         totalStoneSent += stoneAmount;
  451.         totalIronSent += ironAmount;
  452.         $("#woodSent").eq(0).text(`${numberWithCommas(totalWoodSent)}`);
  453.         $("#stoneSent").eq(0).text(`${numberWithCommas(totalStoneSent)}`);
  454.         $("#ironSent").eq(0).text(`${numberWithCommas(totalIronSent)}`);
  455.     },
  456.         !1
  457.     );
  458. }
  459.  
  460. function numberWithCommas(x) {
  461.     // add . to make numbers more readable
  462.     x = x.toString();
  463.     var pattern = /(-?\d+)(\d{3})/;
  464.     while (pattern.test(x))
  465.         x = x.replace(pattern, "$1.$2");
  466.     return x;
  467. }
  468.  
  469. function checkDistance(x1, y1, x2, y2) {
  470.     //calculate distance from current village
  471.     var a = x1 - x2;
  472.     var b = y1 - y2;
  473.     var distance = Math.round(Math.hypot(a, b));
  474.     return distance;
  475. }
  476.  
  477. function askCoordinate() {
  478.     //ask for coordinate
  479.     var content = `<div style=max-width:1000px;>
  480.     <h2 class="popup_box_header">
  481.        <center><u>
  482.           <font color="darkgreen">${langShinko[0]}</font>
  483.           </u>
  484.        </center>
  485.     </h2>
  486.     <hr>
  487.     <p>
  488.     <center>
  489.        <font color=maroon><b>${langShinko[1]}</b>
  490.        </font>
  491.     </center>
  492.     </p>
  493.     <center> <table><tr><td><center>
  494.     <input type="text" ID="coordinateTargetFirstTime" name="coordinateTargetFirstTime" size="20" margin="5" align=left></center></td></tr>
  495.        <tr></tr>
  496.        <tr><td><center><input type="button"
  497.           class="btn evt-cancel-btn btn-confirm-yes" id="saveCoord"
  498.           value="${langShinko[2]}">&emsp;</center></td></tr>
  499.           <tr></tr>
  500.           </table>
  501.     </center>
  502.     <br>
  503.     <hr>
  504.     <center><img class="tooltip-delayed"
  505.        title="<font color=darkgreen>Sophie -Shinko to Kuma-</font>"
  506.        src="https://web.archive.org/web/20200419212440/https://dl.dropboxusercontent.com/s/0do4be4rzef4j30/sophie2.gif"
  507.        style="cursor:help; position: relative"></center>
  508.     <br>
  509.     <center>
  510.        <p>${langShinko[3]}: <a
  511.           href="https://web.archive.org/web/20200419212440/https://forum.tribalwars.net/index.php?members/shinko-to-kuma.121220/"
  512.           title="Sophie profile" target="_blank">Sophie "Shinko
  513.          to Kuma"</a>
  514.        </p>
  515.     </center>
  516.  </div>`;
  517.     Dialog.show('Supportfilter', content);
  518.     $("#saveCoord").click(function () {
  519.         coordinate = $("#coordinateTargetFirstTime")[0].value.match(/\d+\|\d+/)[0];
  520.         sessionStorage.setItem("coordinate", coordinate);
  521.         var close_this = document.getElementsByClassName(
  522.             'popup_box_close');
  523.         close_this[0].click();
  524.         targetID = coordToId(coordinate);
  525.     });
  526. }
  527.  
  528.  
  529.  
  530.  
  531. function calculateResAmounts(wood, stone, iron, warehouse, merchants) {
  532.     var merchantCarry = merchants * 1000;
  533.     //available to use resources in village and substracting what we wanna leave behind
  534.     leaveBehindRes = Math.floor(warehouse / 100 * resLimit);
  535.     var localWood = wood - leaveBehindRes;
  536.     var localStone = stone - leaveBehindRes;
  537.     var localIron = iron - leaveBehindRes;
  538.     localWood = Math.max(0, localWood);
  539.     localStone = Math.max(0, localStone);
  540.     localIron = Math.max(0, localIron);
  541.  
  542.     // percentages for coins, 83000 is how much all 3 is combined
  543.     woodPercentage = 28000 / 83000;
  544.     stonePercentage = 30000 / 83000;
  545.     ironPercentage = 25000 / 83000;
  546.  
  547.     //recalculate how much can be sent according to how much is available
  548.     //how much the merchant can take maximum
  549.     merchantWood = (merchantCarry * woodPercentage);
  550.     merchantStone = (merchantCarry * stonePercentage);
  551.     merchantIron = (merchantCarry * ironPercentage);
  552.  
  553.     //check each type if we have enough available
  554.     var perc = 1;
  555.     if (merchantWood > localWood) {
  556.         perc = localWood / merchantWood;
  557.         merchantWood = merchantWood * perc;
  558.         merchantStone = merchantStone * perc;
  559.         merchantIron = merchantIron * perc;
  560.     }
  561.     if (merchantStone > localStone) {
  562.         perc = localStone / merchantStone;
  563.         merchantWood = merchantWood * perc;
  564.         merchantStone = merchantStone * perc;
  565.         merchantIron = merchantIron * perc;
  566.     }
  567.     if (merchantIron > localIron) {
  568.         perc = localIron / merchantIron;
  569.         merchantWood = merchantWood * perc;
  570.         merchantStone = merchantStone * perc;
  571.         merchantIron = merchantIron * perc;
  572.     }
  573.     thisVillaData = { "wood": Math.floor(merchantWood), "stone": Math.floor(merchantStone), "iron": Math.floor(merchantIron) }
  574.     return thisVillaData;
  575.  
  576. }
  577.  
  578. function compareDates(x) {
  579.     var start = x,
  580.         end = new Date(),
  581.         diff = new Date(end - start),
  582.         hours = diff / 1000 / 60 / 60;
  583.     console.log("checked " + hours + " ago for village list");
  584.     return hours;
  585. }
  586. function coordToId(coordinate) {
  587.     //get village data from the coordinate we gained from the user
  588.     if (game_data.player.sitter > 0) {
  589.         sitterID = `game.php?t=${game_data.player.id}&screen=api&ajax=target_selection&input=${coordinate}&type=coord`;
  590.     }
  591.     else {
  592.         sitterID = '/game.php?&screen=api&ajax=target_selection&input=' + coordinate + '+&type=coord';
  593.     }
  594.     $.get(sitterID, function (json) {
  595.         data = JSON.parse(json);
  596.         sendBack = [data.villages[0].id, data.villages[0].name, data.villages[0].image, data.villages[0].player_name, data.villages[0].points, data.villages[0].x, data.villages[0].y]
  597.         createList();
  598.     })
  599. }
  600.  
  601. function reDo() {
  602.     coordToId(coordinate);
  603. }
  604.  
  605. function formatTable() {
  606.     //reformat the rows so they are clean
  607.     var tableRows = $("#table tr");
  608.     for (var i = 1; i < tableRows.length; i++) {
  609.         if (i % 2 == 0) {
  610.             $("#table tr")[i].className = "sophRowB";
  611.         }
  612.         else {
  613.             $("#table tr")[i].className = "sophRowA";
  614.         }
  615.     }
  616. }
  617.  
  618. function sortTableTest(n) {
  619.     var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
  620.     table = document.getElementById("tableSend");
  621.     switching = true;
  622.     // Set the sorting direction to ascending:
  623.     dir = "asc";
  624.     /* Make a loop that will continue until
  625.     no switching has been done: */
  626.     while (switching) {
  627.         // Start by saying: no switching is done:
  628.         switching = false;
  629.         rows = table.rows;
  630.         /* Loop through all table rows (except the
  631.         first, which contains table headers): */
  632.         for (i = 2; i < (rows.length - 1); i++) {
  633.             // Start by saying there should be no switching:
  634.             shouldSwitch = false;
  635.             /* Get the two elements you want to compare,
  636.             one from current row and one from the next: */
  637.             x = rows[i].getElementsByTagName("td")[n];
  638.             y = rows[i + 1].getElementsByTagName("td")[n];
  639.             /* Check if the two rows should switch place,
  640.             based on the direction, asc or desc: */
  641.             if (dir == "asc") {
  642.                 if (Number(x.innerHTML) > Number(y.innerHTML)) {
  643.                     // If so, mark as a switch and break the loop:
  644.                     shouldSwitch = true;
  645.                     break;
  646.                 }
  647.             } else if (dir == "desc") {
  648.                 if (Number(x.innerHTML) < Number(y.innerHTML)) {
  649.                     // If so, mark as a switch and break the loop:
  650.                     shouldSwitch = true;
  651.                     break;
  652.                 }
  653.             }
  654.         }
  655.         if (shouldSwitch) {
  656.             /* If a switch has been marked, make the switch
  657.             and mark that a switch has been done: */
  658.             rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
  659.             switching = true;
  660.             // Each time a switch is done, increase this count by 1:
  661.             switchcount++;
  662.         } else {
  663.             /* If no switching has been done AND the direction is "asc",
  664.             set the direction to "desc" and run the while loop again. */
  665.             if (switchcount == 0 && dir == "asc") {
  666.                 dir = "desc";
  667.                 switching = true;
  668.             }
  669.         }
  670.     }
  671. }
  672.  
  673. }
  674. /*
  675.      FILE ARCHIVED ON 21:24:40 Apr 19, 2020 AND RETRIEVED FROM THE
  676.      INTERNET ARCHIVE ON 20:25:39 Apr 16, 2021.
  677.      JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE.
  678.  
  679.      ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C.
  680.      SECTION 108(a)(3)).
  681. */
  682. /*
  683. playback timings (ms):
  684.   esindex: 0.037
  685.   PetaboxLoader3.resolve: 55.896
  686.   exclusion.robots: 0.391
  687.   exclusion.robots.policy: 0.363
  688.   LoadShardBlock: 486.039 (3)
  689.   PetaboxLoader3.datanode: 814.305 (4)
  690.   load_resource: 494.048
  691.   CDXLines.iter: 44.028 (3)
  692.   RedisCDXSource: 40.169
  693.   captures_list: 581.249
  694. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement