Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.64 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 = "645|560 645|560".split(" "); */
  35. var coords = "645|560 650|505 655|503 663|520 653|505 647|555 645|555 646|558 654|505 646|560 654|506 654|501 651|544 648|561 645|558 649|561 650|560 651|553 661|516 652|552 653|549 652|550 651|560 660|521 655|538 646|562 648|563 652|559 650|556 658|527 661|518 647|561 664|517 654|562 665|506 653|559 663|521 663|517 648|560 655|564 659|556 649|560 660|546 653|563 656|553 658|543 666|494 656|548 661|521 658|545 660|543 662|519 669|521 668|504 651|563 667|523 662|548 655|552 657|564 655|559 664|552 665|517 666|495 656|563 664|547 654|565 655|565 664|564 669|519 653|565 654|561 658|558 661|564 670|506 670|530 657|559 652|563 667|513 657|558 660|563 670|540 664|559 669|539 671|530 673|528 663|564 662|565 662|563 661|566 657|562 663|559 675|522 674|529 664|558 658|564 667|551 662|549 671|527 674|499 671|526 713|541 713|540 700|541 706|538 718|549 703|544 717|550 709|553 711|554 707|550 704|545 712|554 714|550 714|538 711|533 710|548 704|544 702|544 705|543 705|521 702|546 706|520 709|543 705|519 712|549 719|552 710|549 711|532 712|540 715|539 706|522 707|521 712|551 705|555 702|548 700|527 716|528 721|529 723|524 718|528 722|532 707|517 710|542 721|541 706|499 721|540 718|540 717|542 718|551 715|543 673|429 674|433 675|429 665|446 708|500 708|504 711|503 709|502 710|504 711|506 711|500 712|499 707|501 707|502 710|500 714|508 713|508 707|507 711|507 721|507 724|505 723|504 727|502 725|514 730|509 725|519 720|510 726|507 725|517 717|504 722|507 722|508 723|510 724|510 708|510 727|521 729|515 719|519 710|511 724|517 725|516 715|510 719|518 728|517 710|510 710|506 709|506 712|505 714|500 754|473 " .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", 10);
  50. fill("spy:20,light,axe,heavy,spear,sword,archer,catapult:20");
  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 = ["8: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