Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 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 = "533|568 534|568 534|569 540|570 540|569 535|554 526|567 528|570 512|561 461|566 460|567 463|562 475|572 460|563 458|574 463|574 465|575 466|537 465|537 467|529 464|531 467|568 471|531 467|539 468|539 465|545 467|534 466|542 470|537 468|532 470|521 466|522 435|566 468|518 473|559 429|571 433|564 448|558 428|573 445|562 536|567 538|572 537|573 538|570 537|571 537|570 526|577 533|570 531|569 535|570 535|569 533|567 539|568 536|565 538|567 537|567 533|572 535|567 534|567 536|570 536|566 475|573 439|563 535|568 456|576 440|567 468|508 456|574 534|550 538|569 541|574 542|571 535|551 544|571 548|558 551|558 547|558 548|565 550|567 547|562 511|559 514|564 513|559 472|532 512|563 513|560 514|559 470|530 464|572 448|577 463|563 466|572 517|568 538|574 538|565 536|552 533|557 547|566 546|564 540|553 550|558 540|557 538|577 538|573 515|565 537|561 548|561 547|563 509|567 545|570 547|570 548|564 511|561 512|560 511|560 530|572 529|572 526|568 534|577 534|576 532|577 533|575 534|557 470|516 534|565 443|529 460|502 476|563 549|564 510|559 430|505 441|509 440|510 443|512 436|521 436|522 443|509 437|522 442|510 434|520 435|514 433|506 433|507 445|509 446|508 428|530 ".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", 5);
  49. units("ram", 1) || units("catapult", 1);
  50. fill("light,axe,spear,sword, heavy");
  51.  
  52. if (left > 0)
  53. UI.ErrorMessage('Za mała pula wojsk, aby atak składał się z ' + perc * 100 + '% ludności\r\nbrakuje ' + left + ' mieszkańców', 5000);
  54. } else {
  55. UI.ErrorMessage('Nie można wybrać wioski, aby atak wchodził w podanych ramach czasowych', 5000);
  56. }
  57. }
  58. }
  59. } catch (err) {
  60. var message = "Wystąpił nieoczekiwany błąd. Sprawdź 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 = ["19-19"];
  68. var intervals = ["07:00-10:00"];
  69. var distance = Math.hypot(coords.split("|")[0] - v.x, coords.split("|")[1] - v.y);
  70. var destination = new Date(distance * 1714000 + 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