Outside Dump Calculator

Outside Dump Calculator for FDTD

当前为 2020-05-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Outside Dump Calculator
  3. // @namespace -
  4. // @description Outside Dump Calculator for FDTD
  5. // @include http://d2n.duskdawn.net/*
  6. // @version 1.05
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10.  
  11. var delimiter = "<hr></hr>";
  12. var end = "</form>";
  13. var allD = "<form><div><input type = \"checkbox\" id = \"allDumptypes\"> All types of Dump</input></div>";
  14. var animaldump = "<div style = \"font-size: 10px\">--<input type = \"checkbox\" id = \"animaldump\" > Animal Dump </input></div>";
  15. var defencedump = "<div style = \"font-size: 10px\">--<input type = \"checkbox\" id = \"defencedump\"> Defence Dump </input></div>";
  16. var fooddump = "<div style = \"font-size: 10px\">--<input type = \"checkbox\" id = \"fooddump\"> Food Dump </input></div>";
  17. var metaldump = "<div style = \"font-size: 10px\">--<input type = \"checkbox\" id = \"metalldump\"> Metal Dump </input></div>";
  18. var weaponsdump = "<div style = \"font-size: 10px\">--<input type = \"checkbox\" id = \"weaponsdump\"> Weapons Dump </input></div>";
  19. var wooddump = "<div style = \"font-size: 10px\">--<input type = \"checkbox\" id = \"wooddump\"> Wood Dump </input></div>";
  20. var dumpupgrade = "<div style = \"font-size: 10px ; color: #0FF\">--<input type = \"checkbox\" id = \"dumpupgrade\"> Dump Upgrade </input></div>";
  21. var plasticdump = "<div style = \"font-size: 10px\">---<input type = \"checkbox\" id = \"plasticdump\"> Count empty plastic bags? </input></div>";
  22. var launcherdump = "<div style = \"font-size: 10px\">---<input type = \"checkbox\" id = \"launcherdump\"> Count empty batt launchers? </input></div>";
  23. var button = "<a class=\"uact\" id=\"botcalc\"><img src=\"http://d2nwiki.com/images/f/f8/Item_radius_mk2.gif\" alt=\"\"> Calculate!</a>";
  24.  
  25. $("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("http://www.die2nite.com/gfx/design/button.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>'));
  26.  
  27. $("#information_panel").append($('<a id="test" ><img src="http://d2nwiki.com/images/f/f8/Item_radius_mk2.gif"> Outside Dump Calculator</a>'));
  28. $("#test").append($(delimiter+allD+animaldump+defencedump+fooddump+metaldump+weaponsdump+wooddump+dumpupgrade+plasticdump+launcherdump+end+delimiter+button));
  29.  
  30. document.getElementById("allDumptypes").onclick = function() {
  31. if (!this.checked){
  32. document.getElementById('animaldump').checked = false;
  33. document.getElementById('defencedump').checked = false;
  34. document.getElementById('fooddump').checked = false;
  35. document.getElementById('metalldump').checked = false;
  36. document.getElementById('weaponsdump').checked = false;
  37. document.getElementById('wooddump').checked = false;
  38. document.getElementById('dumpupgrade').checked = false;
  39. document.getElementById('plasticdump').checked = false;
  40. document.getElementById('launcherdump').checked = false;
  41. } else {
  42. document.getElementById('animaldump').checked = true;
  43. document.getElementById('defencedump').checked = true;
  44. document.getElementById('fooddump').checked = true;
  45. document.getElementById('metalldump').checked = true;
  46. document.getElementById('weaponsdump').checked = true;
  47. document.getElementById('wooddump').checked = true;
  48. document.getElementById('dumpupgrade').checked = true;
  49. document.getElementById('plasticdump').checked = true;
  50. document.getElementById('launcherdump').checked = true;
  51. }
  52.  
  53. };
  54. document.getElementById('animaldump').onclick = function() {if ( this.checked ) {} else {document.getElementById('allDumptypes').checked = false;}};
  55. document.getElementById('defencedump').onclick = function() {if ( this.checked ) {} else {document.getElementById('allDumptypes').checked = false;}};
  56. document.getElementById('fooddump').onclick = function() {if ( this.checked ) {} else {document.getElementById('allDumptypes').checked = false;}};
  57. document.getElementById('metalldump').onclick = function() {if ( this.checked ) {} else {document.getElementById('allDumptypes').checked = false;}};
  58. document.getElementById('weaponsdump').onclick = function() {if ( this.checked ) {} else {document.getElementById('allDumptypes').checked = false;}};
  59. document.getElementById('wooddump').onclick = function() {if ( this.checked ) {} else {document.getElementById('allDumptypes').checked = false;}};
  60. document.getElementById('dumpupgrade').onclick = function() {if ( this.checked ) {} else {document.getElementById('allDumptypes').checked = false;}};
  61. document.getElementById('plasticdump').onclick = function() {if ( this.checked ) {} else {document.getElementById('allDumptypes').checked = false;}};
  62. document.getElementById('launcherdump').onclick = function() {if ( this.checked ) {} else {document.getElementById('allDumptypes').checked = false;}};
  63.  
  64. var animalid = [45,42,43,44,47,403];
  65. var defid = [31,64,107,169,179];
  66. var foodid = [4,52,53,74,108,140,141,142,143,144,145,146,147,148,150,157,172,197,198,224,230,236,260,261,262,281,311,312,391];
  67. var metalid = [60,161];
  68. var weaponsid = [233,46,128,186,187,188,242,373,5,7,8,9,10,11,13,14,15,16,17,18,19,20,23,62,70,76,77,78,111,112,113,114,115,116,117,118,122,123,127,158,196,205,206,207,208,209,212,213,234,286,313,340,357,358,366,374]
  69. var woodid = [59,162];
  70. var plasticid = 76;
  71. var battlauncherid = 117;
  72. //var fatsnakeid = 403;
  73.  
  74. var allids = [45,42,43,44,47,403,31,64,107,169,179,4,52,53,74,108,140,141,142,143,144,145,146,147,148,150,157,172,197,198,224,230,236,260,261,262,281,311,312,391,60,161,233,46,128,186,187,188,242,373,5,7,8,9,10,11,13,14,15,16,17,18,19,20,23,62,70,76,77,78,111,112,113,114,115,116,117,118,122,123,127,158,196,205,206,207,208,209,212,213,234,286,313,340,357,358,366,374,59,162,403];
  75.  
  76. var ids = [];
  77. var multidef =[];
  78. var subtotal= 0;
  79.  
  80. document.getElementById('botcalc').onclick = function yo() {
  81. document.getElementById('botcalc').className = 'uactOff';
  82. $("#botcalc").removeAttr('onclick');
  83. document.getElementById('botcalc').onclick = function yo () {
  84. alert("Better refresh the FDTD page to get more accurate data!")};
  85. calculateDump();};
  86.  
  87.  
  88. function desirable_ids (){
  89. ids = [];
  90. if (document.getElementById('animaldump').checked) {ids = ids.concat(animalid);}
  91. if (document.getElementById('defencedump').checked) {ids = ids.concat(defid);}
  92. if (document.getElementById('fooddump').checked) {ids = ids.concat(foodid);}
  93. if (document.getElementById('metalldump').checked) {ids = ids.concat(metalid);}
  94. if (document.getElementById('wooddump').checked) {ids = ids.concat(woodid);}
  95. if (document.getElementById('weaponsdump').checked) {ids = ids.concat(weaponsid);}
  96. if (document.getElementById('plasticdump').checked) {ids.push(plasticid);}
  97. if (document.getElementById('launcherdump').checked) {ids.push(battlauncherid);}
  98. ids.sort();
  99. //todo: separate ids array into general dumps id and special ids from checkboxes
  100.  
  101. };
  102. function calculateDump (){
  103. subtotal = 0;
  104. desirable_ids();
  105. var zonas = document.getElementsByClassName("zone");
  106. for(var i = 0;i<zonas.length;i++){
  107. var xey = coordenadas(zonas[i]);
  108. var xxx = xey[0];
  109. var yyy = xey[1];
  110.  
  111. if (apFromHome(xxx,yyy)<12){ //AP RANGE defalt to 11AP zones
  112. var azona = zoneMap[xxx][yyy];
  113. if (azona.items.length == 0){
  114. }
  115. else {
  116. var tempdef = 0;
  117. for (var j = 0; j<azona.items.length;j++){
  118. if (allids.includes(azona.items[j].d2nItemId)){
  119. //definir tipo de dumpable
  120. subtotal = subtotal +( tipifyitem(azona.items[j].d2nItemId)*azona.items[j].amount);
  121. tempdef += ( tipifyitem(azona.items[j].d2nItemId)*azona.items[j].amount);
  122. }
  123. }
  124. var apdef;
  125. if (apFromHome(xxx,yyy)>3&&xxx==0||apFromHome(xxx,yyy)>3&&yyy==0){
  126. 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));
  127. } else if (apFromHome(xxx,yyy)>3){
  128. 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));
  129. }
  130. else {
  131. apdef = 0;
  132. }
  133.  
  134. multidef.push([apdef.toFixed(2),tempdef,xxx+"/"+yyy]);
  135. }
  136. }else {
  137. }
  138. }
  139.  
  140. alert("We can get a total of "+subtotal+" defense with dumpables from outside (11AP range).\n\n"+bestzones());
  141.  
  142. }
  143. function bestzones(){
  144. multidef.sort( function (a, b) {return b[0] - a[0]});
  145.  
  146. var thebestzones = "The closest zones with the most defenses are:\n\n";
  147. for (var k = 0; k<10;k++){
  148. thebestzones += "#"+(k+1)+"- There's "+multidef[k][1]+" defense points worth on "+multidef[k][2]+" ("+multidef[k][0]+" DF/AP).\n";
  149. }
  150. return thebestzones;
  151.  
  152. }
  153. function coordenadas (zona){
  154. var coo = [];
  155. var matches = zona.id.match(/^zone_([\-0-9]+)_([\-0-9]+)$/);
  156. coo.push(parseInt(matches[1]));
  157. coo.push(parseInt(matches[2]));
  158. return coo;
  159. }
  160. function tipifyitem (itemid) {
  161. var nweapons = [];
  162. nweapons.concat(weaponsid);
  163. nweapons.push(plasticid);
  164. nweapons.push(battlauncherid);
  165. var valor = 1;
  166.  
  167. if (animalid.includes(itemid)&&document.getElementById('animaldump').checked){
  168. valor +=6;
  169. }
  170. else if (defid.includes(itemid)&&document.getElementById('defencedump').checked){
  171. valor +=2;
  172. }
  173. else if (foodid.includes(itemid)&&document.getElementById('fooddump').checked){
  174. valor +=3;
  175. }
  176. else if (metalid.includes(itemid)&&document.getElementById('metalldump').checked){
  177. valor +=1;
  178. }
  179. else if (nweapons.includes(itemid)&&document.getElementById('weaponsdump').checked){
  180. valor +=5;
  181. }
  182. else if (woodid.includes(itemid)&&document.getElementById('wooddump').checked){
  183. valor +=1;
  184. }
  185. if(document.getElementById('dumpupgrade').checked) {
  186. valor +=1;
  187. }
  188.  
  189. return valor;
  190.  
  191. }
  192. function includes(a, obj) {
  193. var i = a.length;
  194. while (i--) {
  195. if (a[i] === obj) {
  196. return true;
  197. }
  198. }
  199. return false;
  200. }
  201.  
  202. //posTown
  203. //yPosTown
  204. //apFromHome (x,y)
  205. //calculateZoneId(1, 1)
  206.  
  207.