Advertisement
Guest User

Untitled

a guest
Dec 12th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.52 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 = "532|538 535|537".split(" "); */
  35. var coords = "529|532 536|533 528|539 536|538 537|538 536|540 535|540 535|540 535|541 534|542 532|541 535|544 532|549 530|557 526|556 524|554 517|561 518|559 518|558 513|553 547|547 552|549 557|546 557|545 555|542 549|538 562|539 556|535 561|550 561|549 561|548 562|549 568|549 569|549 568|548 567|548 566|548 565|555 576|553 585|537 585|539 585|540 587|540 588|540 589|539 589|538 585|532 587|530 588|530 581|535 578|534 578|536 577|537 577|538 580|538 580|539 581|540 580|541" .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", 10) || units("catapult", 1);
  50. fill("spy:8,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