Advertisement
Podeszwa

Tabalugatoja

Jan 19th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. javascript:
  2.  
  3. var gd = game_data;
  4. /* CONFIG: ustawić na 0.00 na światach bez ograniczonego fejkowania */
  5. var perc = 0.01;
  6. var v = gd.village;
  7. var u = {
  8. "spear": 1,
  9. "sword": 1,
  10. "axe": 1,
  11. "archer": 1,
  12. "spy": 2,
  13. "light": 4,
  14. "marcher": 5,
  15. "heavy": 6,
  16. "ram": 5,
  17. "catapult": 8,
  18. "knight": 10,
  19. "snob": 100
  20. }
  21. var left;
  22. try {
  23. if (document.URL.indexOf('try=confirm') != -1 && document.URL.indexOf('target=') == -1);
  24. else if (document.URL.indexOf('screen=place') == -1 || (document.URL.indexOf('mode') != -1 && document.URL.indexOf('mode=command') == -1)) {
  25. location = gd.link_base_pure + "place&mode=command";
  26. } else {
  27. if ($('.jump_link')[0] !== undefined) {
  28. location = $('#village_switch_right')[0].href;
  29. } else {
  30. var ul = $('.unit_link');
  31. for (var i = 0; i < ul.length; i++)
  32. $('#unit_input_' + $(ul[i]).attr('data-unit'))[0].value = "";
  33. /* CONFIG: wpisz koordynaty do losowania */
  34. /* np. var coords = "504|617 505|617".split(" "); */
  35. var coords = "446|469 434|462 450|470 434|460 447|469 432|463 439|456 450|469 442|457 444|468 437|461 450|442 444|444 442|443 441|446 434|458 445|438 440|440 444|435 433|462 439|434 433|440 440|434 444|432 428|437 440|435 444|445 439|459 437|460 440|446 446|440 445|441 438|446 438|440 433|441 447|442 448|446 438|461 443|434 439|436 429|436" .split(" ");
  36.  
  37. var selected = [];
  38. for (var i = 0; i < coords.length; ++i)
  39. if (isSelected(coords[i]))
  40. selected.push(coords[i]);
  41.  
  42. if (selected.length != 0) {
  43. left = Math.floor(v.points * perc);
  44. var index = Math.round(Math.random() * (selected.length - 1));
  45. $(".target-input-field")[0].value = selected[index];
  46. /* CONFIG: wybĂłr wojsk */
  47.  
  48. units("spy", 1);
  49. units("ram", 1) || units("catapult", 1);
  50. fill("spy:20,light,axe,heavy,spear,sword,archer");
  51.  
  52. if (left > 0)
  53. UI.ErrorMessage('Masz za malo wojska, aby wyslac atak. Do ' + perc * 100 + '% ludnosci\r\nbrakuje ' + left + ' mieszkancow', 5000);
  54. } else {
  55. UI.ErrorMessage('Nie mozna wybrac wioski, aby atak wchodzil‚ w podanych ramach czasowych', 5000);
  56. }
  57. }
  58. }
  59. } catch (err) {
  60. var message = "Wystapil nieoczekiwany blad. Sprawdz czy skrypt jest poprawnie skonfigurowany!";
  61. console.log(err.message);
  62. UI.ErrorMessage(message, 5000);
  63. }
  64.  
  65. function isSelected(coords) {
  66. /* CONFIG: ustaw ramy czasowe, które ci odpowiadają */
  67. var days = ["1-31"];
  68. var intervals = ["7:00-23:59"];
  69. var distance = Math.hypot(coords.split("|")[0] - v.x, coords.split("|")[1] - v.y);
  70. var destination = new Date(distance * 1800000 + gd.time_generated);
  71.  
  72. var isInInterval = (intervals, value, predicate) => {
  73. for (var i = 0; i < intervals.length; i++)
  74. if (predicate(value, intervals[i]))
  75. return true;
  76. return false;
  77. };
  78. if (!isInInterval(days, destination, (v, i) => {
  79. v = v.getDate();
  80. i = i.split('-');
  81. return parseInt(i[0]) <= v && v <= parseInt(i[1]);
  82. })) return false;
  83. if (isInInterval(intervals, destination, (v, i) => {
  84. var parseTimer = timer => parseInt(timer[0]) * 60 + parseInt(timer[1]);
  85. v = parseTimer([v.getHours(), v.getMinutes()]);
  86. i = i.split("-");
  87. return parseTimer(i[0].split(':')) <= v && v <= parseTimer(i[1].split(':'));
  88. })) return true;
  89. return false;
  90. }
  91.  
  92. function tryUnits(name, value) {
  93. var mv = $('a#units_entry_all_' + name)[0].innerText.match(/\d+/)[0];
  94. var sv = $('#unit_input_' + name)[0].value;
  95. return mv - sv - value >= 0;
  96. }
  97.  
  98. function units(name, value) {
  99. var mv = $('a#units_entry_all_' + name)[0].innerText.match(/\d+/)[0];
  100. var sv = $('#unit_input_' + name)[0].value;
  101. sv = sv == "" ? 0 : parseInt(sv);
  102. mv -= sv;
  103. if (value > mv)
  104. value = mv;
  105. left -= u[name] * value;
  106. $('#unit_input_' + name)[0].value = sv + value;
  107. return value > 0;
  108. }
  109.  
  110. function fill(names) {
  111. if (left <= 0) return;
  112. names = names.split(',');
  113. var name, quantity;
  114. for (var i = 0; i < names.length; ++i) {
  115. name = names[i];
  116. quantity = NaN;
  117. if (name.indexOf(':') != -1) {
  118. quantity = parseInt(name.split(':')[1]);
  119. name = name.split(':')[0];
  120. }
  121. units(name, Math.ceil((isNaN(quantity) ? left : (quantity * u[name] >= left ? left : quantity * u[name])) / u[name]));
  122. if (left <= 0) return;
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement