Outside Dump Calculator (Fata)

Outside Dump Calculator for Fata Morgana and MyHordes

当前为 2021-04-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Outside Dump Calculator (Fata)
  3. // @namespace -
  4. // @description Outside Dump Calculator for Fata Morgana and MyHordes
  5. // @include https://fatamorgana.md26.eu/*
  6. // @version 1.00
  7. // @grant none
  8. // ==/UserScript==
  9. var delimiter = "<hr></hr>";
  10. var end = "</form>";
  11. var allD = "<form><div style = \"background-color: #AEB7AF\"><input type = \"checkbox\" id = \"allDumptypes\"> All types of Dump</input></div>";
  12. var animaldump = "<div style = \"background-color: #BEB7AF\" ; \"font-size: 10px\" >--<input type = \"checkbox\" id = \"animaldump\" > Animal Dump </input></div>";
  13. var defencedump = "<div style = \"background-color: #BEB7AF\" ; \"font-size: 10px\">--<input type = \"checkbox\" id = \"defencedump\"> Defence Dump </input></div>";
  14. var fooddump = "<div style = \"background-color: #BEB7AF\" ; \"font-size: 10px\">--<input type = \"checkbox\" id = \"fooddump\"> Food Dump </input></div>";
  15. var metaldump = "<div style = \"background-color: #BEB7AF\" ; \"font-size: 10px\">--<input type = \"checkbox\" id = \"metalldump\"> Metal Dump </input></div>";
  16. var weaponsdump = "<div style = \"background-color: #BEB7AF\" ; \"font-size: 10px\">--<input type = \"checkbox\" id = \"weaponsdump\"> Weapons Dump </input></div>";
  17. var wooddump = "<div style = \"background-color: #BEB7AF\" ; \"font-size: 10px\">--<input type = \"checkbox\" id = \"wooddump\"> Wood Dump </input></div>";
  18. var dumpupgrade = "<div style = \"background-color: #BEB7AF\" ; \"font-size: 10px ; color: #0FF\">--<input type = \"checkbox\" id = \"dumpupgrade\"> Dump Upgrade </input></div>";
  19. var plasticdump = "<div style = \"background-color: #CEB7AF\" ; \"font-size: 8px\">---<input type = \"checkbox\" id = \"plasticdump\"> Count empty plastic bags? </input></div>";
  20. var launcherdump = "<div style = \"background-color: #CEB7AF\" ; \"font-size: 8px\">---<input type = \"checkbox\" id = \"launcherdump\"> Count empty batt launchers? </input></div>";
  21. var button = "<a class=\"uact\" id=\"botcalc\"><img src=\"https://zombvival.de/myhordes/build/images/item/item_radius_mk2.25c2c535.gif\" alt=\"\"> Calculate!</a>";
  22.  
  23. $("head").append($('<link rel="stylesheet" type="text/css"><style type="text/css">.uact{margin:0px ;padding : 0px;display:block;margin-top:3px;padding-left:7px;padding-right:7px;width:250px;height:20px;padding-bottom:1px;color:#f0d79e;font-size:10pt;font-weight:bold;font-family:Arial;letter-spacing:0pt;text-align:left;font-variant:small-caps;text-decoration:none;background-image:url("https://www.zombvival.de/myhordes/build/images/assets/img/background/bg_button.dbfda3a1.gif");background-color:#b37c4a;border:1px solid black;border-bottom-width:2px;outline:1px solid #784323;cursor:pointer;}.uactOff{margin:0px ;padding : 0px;display:block;margin-top:3px;padding-left:7px;padding-right:7px;width:250px;height:20px;padding-bottom:1px;color:#f0d79e;font-size:10pt;font-weight:bold;font-family:Arial;letter-spacing:0pt;text-align:left;font-variant:small-caps;text-decoration:none;background-image:url("http://www.die2nite.com/gfx/design/button_off.gif");background-color:#b37c4a;border:1px solid black;border-bottom-width:2px;outline:1px solid #784323;cursor:pointer;}</style>'));
  24.  
  25. $("#box").append($('<a id="test"><img src="https://zombvival.de/myhordes/build/images/item/item_radius_mk2.25c2c535.gif"> Outside Dump Calculator</a>'));
  26. $("#test").append($(delimiter+allD+animaldump+defencedump+fooddump+metaldump+weaponsdump+wooddump+dumpupgrade+plasticdump+launcherdump+end+delimiter+button));
  27.  
  28. document.getElementById("allDumptypes").onclick = function() {
  29. if (!this.checked){
  30. document.getElementById('animaldump').checked = false;
  31. document.getElementById('defencedump').checked = false;
  32. document.getElementById('fooddump').checked = false;
  33. document.getElementById('metalldump').checked = false;
  34. document.getElementById('weaponsdump').checked = false;
  35. document.getElementById('wooddump').checked = false;
  36. document.getElementById('dumpupgrade').checked = false;
  37. document.getElementById('plasticdump').checked = false;
  38. document.getElementById('launcherdump').checked = false;
  39. } else {
  40. document.getElementById('animaldump').checked = true;
  41. document.getElementById('defencedump').checked = true;
  42. document.getElementById('fooddump').checked = true;
  43. document.getElementById('metalldump').checked = true;
  44. document.getElementById('weaponsdump').checked = true;
  45. document.getElementById('wooddump').checked = true;
  46. document.getElementById('dumpupgrade').checked = true;
  47. document.getElementById('plasticdump').checked = true;
  48. document.getElementById('launcherdump').checked = true;
  49. }
  50.  
  51. };
  52. document.getElementById('animaldump').onclick = function() {if ( this.checked ) {} else {document.getElementById('allDumptypes').checked = false;}};
  53. document.getElementById('defencedump').onclick = function() {if ( this.checked ) {} else {document.getElementById('allDumptypes').checked = false;}};
  54. document.getElementById('fooddump').onclick = function() {if ( this.checked ) {} else {document.getElementById('allDumptypes').checked = false;}};
  55. document.getElementById('metalldump').onclick = function() {if ( this.checked ) {} else {document.getElementById('allDumptypes').checked = false;}};
  56. document.getElementById('weaponsdump').onclick = function() {if ( this.checked ) {} else {document.getElementById('allDumptypes').checked = false;}};
  57. document.getElementById('wooddump').onclick = function() {if ( this.checked ) {} else {document.getElementById('allDumptypes').checked = false;}};
  58. document.getElementById('dumpupgrade').onclick = function() {if ( this.checked ) {} else {document.getElementById('allDumptypes').checked = false;}};
  59. document.getElementById('plasticdump').onclick = function() {if ( this.checked ) {} else {document.getElementById('allDumptypes').checked = false;}};
  60. document.getElementById('launcherdump').onclick = function() {if ( this.checked ) {} else {document.getElementById('allDumptypes').checked = false;}};
  61.  
  62. var animalid = [39,36,37,38,41];//403 Fat Serpent]; ???
  63. var defid = [26,52,88,146,154];
  64. var foodid = [4,44,45,59,89,119,120,121,122,123,124,125,126,127,129,134,149,171,172,199,204,219,225,245,246,269,297];
  65. var metalid = [50,138];
  66. var weaponsid = [201,40,108,161,162,163,205,282,5,6,7,8,9,10,11,12,13,14,15,16,17,18,20,51,56,61,62,92,93,94,95,96,97,98,99,102,103,107,135,170,179,180,181,182,183,186,187,202,230,247,354,271,272,278,283];
  67. var woodid = [49,139];
  68. var plasticid = 60;
  69. var battlauncherid = 98;
  70.  
  71. var allids = [39,36,37,38,41,26,52,88,146,154,4,44,45,59,89,119,120,121,122,123,124,125,126,127,129,134,149,171,172,199,204,219,225,245,246,269,297,50,138,201,40,108,161,162,163,205,282,5,6,7,8,9,10,11,12,13,14,15,16,17,18,20,51,56,61,62,92,93,94,95,96,97,98,99,102,103,107,135,170,179,180,181,182,183,186,187,202,230,247,354,271,272,278,283,49,139,60,98];
  72.  
  73. var ids = [];
  74. var multidef =[];
  75. var subtotal= 0;
  76.  
  77. document.getElementById('botcalc').onclick = function yo() {
  78. document.getElementById('botcalc').className = 'uactOff';
  79. $("#botcalc").removeAttr('onclick');
  80. document.getElementById('botcalc').onclick = function yo () {
  81. alert("Better refresh the Fata page to get more accurate data!")};
  82. calculateDump();};
  83.  
  84.  
  85. function desirable_ids (){
  86. ids = [];
  87. if (document.getElementById('animaldump').checked) {ids = ids.concat(animalid);}
  88. if (document.getElementById('defencedump').checked) {ids = ids.concat(defid);}
  89. if (document.getElementById('fooddump').checked) {ids = ids.concat(foodid);}
  90. if (document.getElementById('metalldump').checked) {ids = ids.concat(metalid);}
  91. if (document.getElementById('wooddump').checked) {ids = ids.concat(woodid);}
  92. if (document.getElementById('weaponsdump').checked) {ids = ids.concat(weaponsid);}
  93. if (document.getElementById('plasticdump').checked) {ids.push(plasticid);}
  94. if (document.getElementById('launcherdump').checked) {ids.push(battlauncherid);}
  95. ids.sort();
  96. //todo: separate ids array into general dumps id and special ids from checkboxes
  97.  
  98. };
  99. function calculateDump (){
  100. subtotal = 0;
  101. desirable_ids();
  102. var zonas = document.getElementsByClassName("mapzone");
  103. for(var i = 0;i<zonas.length;i++){
  104. //var xey = coordenadas(zonas[i]);
  105. var xxx = zonas[i].getAttribute("rx");
  106. var yyy = zonas[i].getAttribute("ry");
  107. var apfromhome = zonas[i].getAttribute("ap");
  108.  
  109. var range = 16 //AP RANGE defalt to 15AP zones
  110.  
  111. if (apfromhome<range){
  112. var azona = data.map["y"+zonas[i].getAttribute("ay")]["x"+zonas[i].getAttribute("ax")];//["items"];
  113. try {
  114. azona = azona["items"]
  115. //if (typeof (azona["items"]) == "undefined"){//azona["items"]===undefined){ //azona.length == 0||
  116. // console.log('yada'); }
  117. //else {
  118. // azona = azona["items"];
  119. var tempdef = 0;
  120. for (var j = 0; j<azona.length;j++){
  121. if (allids.includes(azona[j].id)){
  122. //definir tipo de dumpable
  123. subtotal = subtotal +( tipifyitem(azona[j].id)*azona[j].count);
  124. tempdef += ( tipifyitem(azona[j].id)*azona[j].count);
  125. }
  126. }
  127. var apdef;
  128. if (apfromhome>3&&xxx==0||apfromhome>3&&yyy==0){
  129. apdef = tempdef/Math.floor(Math.sqrt(Math.pow(xxx,2)+Math.pow(yyy,2))+(Math.sqrt(Math.pow(xxx,2)+Math.pow(yyy,2))-2));
  130. } else if (apfromhome>3){
  131. apdef = tempdef/Math.floor(Math.sqrt(Math.pow(xxx,2)+Math.pow(yyy,2))+(Math.sqrt(Math.pow(xxx,2)+Math.pow(yyy,2))-3));
  132. }
  133. else {
  134. apdef = 0;
  135. }
  136. multidef.push([apdef.toFixed(2),tempdef,xxx+"/"+yyy]);
  137. }
  138. catch { }
  139.  
  140. } else {}
  141. }
  142.  
  143. alert("We can get a total of "+subtotal+" defense with dumpables from outside ("+(range-1)+"AP range).\n\n"+bestzones());
  144.  
  145. }
  146. function bestzones(){
  147. multidef.sort( function (a, b) {return b[0] - a[0]});
  148.  
  149. var thebestzones = "The closest zones with the most defenses are:\n\n";
  150. for (var k = 0; k<10;k++){
  151. thebestzones += "#"+(k+1)+"- There's "+multidef[k][1]+" defense points worth on "+multidef[k][2]+" ("+multidef[k][0]+" DF/AP).\n";
  152. }
  153. return thebestzones;
  154.  
  155. }
  156.  
  157. function tipifyitem (itemid) {
  158. var nweapons = [];
  159. nweapons.concat(weaponsid);
  160. nweapons.push(plasticid);
  161. nweapons.push(battlauncherid);
  162. var valor = 1;
  163.  
  164. if (animalid.includes(itemid)&&document.getElementById('animaldump').checked){
  165. valor +=6;
  166. }
  167. else if (defid.includes(itemid)&&document.getElementById('defencedump').checked){
  168. valor +=2;
  169. }
  170. else if (foodid.includes(itemid)&&document.getElementById('fooddump').checked){
  171. valor +=3;
  172. }
  173. else if (metalid.includes(itemid)&&document.getElementById('metalldump').checked){
  174. valor +=1;
  175. }
  176. else if (nweapons.includes(itemid)&&document.getElementById('weaponsdump').checked){
  177. valor +=5;
  178. }
  179. else if (woodid.includes(itemid)&&document.getElementById('wooddump').checked){
  180. valor +=1;
  181. }
  182. if(document.getElementById('dumpupgrade').checked) {
  183. valor +=1;
  184. }
  185.  
  186. return valor;
  187.  
  188. }
  189. function includes(a, obj) {
  190. var i = a.length;
  191. while (i--) {
  192. if (a[i] === obj) {
  193. return true;
  194. }
  195. }
  196. return false;
  197. }