Donnabot's GOTA_Extender_Auxiliary

GOTA_Extender_Auxiliary to go with my fork of GOTA_Extender

目前为 2015-02-03 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/7490/34970/Donnabot%27s%20GOTA_Extender_Auxiliary.js

  1. var extender = {
  2. command: function (name, args) {
  3. var cmd = { name: name, args: args };
  4. $("textarea#observable").attr("command", JSON.stringify(cmd));
  5. },
  6. lastcommand: function () {
  7. var observable = $("textarea#observable");
  8. var lcmd = observable.attr("command");
  9. observable.val(lcmd);
  10. return lcmd;
  11. },
  12. option: function (option, val) {
  13. if (typeof option == "string") {
  14. this.command("option", [option, val]);
  15. } else {
  16. error("Please specify name and value as parameters.", "COMMAND");
  17. }
  18. },
  19. collect: function(){
  20. this.command("collect");
  21. }
  22. };
  23. //
  24. //var productionQueue = [];
  25. //function attemptProduction(bSymbol) {
  26. //
  27. // if (!productionQueue || productionQueue.length == 0) {
  28. // log('Attempted production, but queue was missing or empty. Exiting...', "PRODUCTION");
  29. // return;
  30. // }
  31. //
  32. // if (typeof bSymbol != "undefined") {
  33. //
  34. // // Check this building for production
  35. // var b = buildingBySymbol(bSymbol);
  36. //
  37. // if (buildingProducing(b)) {
  38. // log("Building " + b.symbol + " is busy.", "PRODUCTION");
  39. // return;
  40. // }
  41. //
  42. // if (buildingFinished(b)) {
  43. // log("Building " + b.symbol + " finished production.", "PRODUCTION");
  44. //
  45. // doFinishProduction(b.item_id, function() {
  46. // setTimeout(function() {
  47. // attemptProduction(b.symbol);
  48. // }, extender_queueDelay * 1000);
  49. // });
  50. //
  51. // return;
  52. // }
  53. //
  54. // var element = getElement(b.symbol);
  55. // if (element) {
  56. // executeElement(element);
  57. // return;
  58. // }
  59. // } else {
  60. //
  61. // for (var i = 0; i < userContext.buildingsData.length; i++) {
  62. // var b = userContext.buildingsData[i];
  63. //
  64. // if (buildingProducing(b)) {
  65. // log("Building " + b.symbol + " is busy.", "PRODUCTION");
  66. // continue;
  67. // }
  68. //
  69. // if (buildingFinished(b)) {
  70. // log("Building " + b.symbol + " finished production.", "PRODUCTION");
  71. // doFinishProduction(b.item_id, function() {
  72. // setTimeout(function() {
  73. // attemptProduction(b.symbol);
  74. // }, extender_queueDelay * 1000);
  75. // });
  76. //
  77. // return;
  78. // }
  79. //
  80. // var element = getElement(b.symbol);
  81. // if (element) {
  82. // executeElement(element, function () {
  83. // attemptProduction();
  84. // });
  85. //
  86. // return;
  87. // }
  88. // }
  89. // }
  90. //};
  91. //
  92. //function getElement(buildingSymbol) {
  93. // if (!productionQueue || productionQueue.length == 0) {
  94. // log('Attempted to extract item from queue, but the production queue was missing or empty. Exiting...', "PRODUCTION");
  95. // return null;
  96. // }
  97. //
  98. // var element;
  99. //
  100. // for (var i = 0; i < productionQueue.length; i++) {
  101. //
  102. // if (productionQueue[i].activeBuildingPanel == buildingSymbol) {
  103. // element = productionQueue[i];
  104. // break;
  105. // }
  106. // }
  107. //
  108. // if (!element) {
  109. // log('No elements enqueued for building ' + buildingSymbol + '. Array size: ' + productionQueue.length, "PRODUCTION");
  110. // return null;
  111. // }
  112. //
  113. // return element;
  114. //};
  115. //
  116. //function executeElement(element, callback) {
  117. //
  118. // var index = productionQueue.indexOf(element);
  119. // log('Production of element ' + element.name + ' : ' + element.type + ' with index ' + index + ' initiated.', "PRODUCTION");
  120. //
  121. // if (element.type == "item") {
  122. // userContext.recipeData = element.recipeData;
  123. // userContext.activeBuildingPanel = element.activeBuildingPanel;
  124. //
  125. // doProduction(element.outputSymbol, element.recipeCategory, null, null, element.recipeName, callback);
  126. // productionQueue.splice(index, 1);
  127. // extender.save("productionQueue");
  128. //
  129. // log('Production details: ' + element.name + ' at ' + element.activeBuildingPanel + ', ' + element.outputSymbol + ', ' + element.recipeCategory + ', ' + element.recipeName + ';', "PRODUCTION");
  130. // } else {
  131. //
  132. // var buildingId = buildingBySymbol(element.activeBuildingPanel).id;
  133. //
  134. // applySelectedUpgrade({ building_id: buildingId, id: element.upgradeId, gold: 0, silver: 0 }, null, callback);
  135. // productionQueue.splice(index, 1);
  136. // extender.save("productionQueue");
  137. //
  138. // log('Production details: ' + element.name + ' : ' + element.type + ' at ' + element.activeBuildingPanel + ', ' + element.symbol + ';', "PRODUCTION");
  139. //
  140. // }
  141. //};
  142.  
  143. function buildingFinished(b) {
  144.  
  145. // DO NOT call this function for the keep: it has neither build_remaining nor producing_archetype_id
  146.  
  147. // When a building finished either producing or bonus archetype id's should be present along with
  148. // no build time remaining to safely determine that this building has produced the item (luck or not)
  149. // but has not finalized the production yet (that's clicking the finish button)
  150. // Note that upgrades also enlist with a producing_archetype_id here, so they behave similarly
  151. return (b.producing_archetype_id != void 0 || b.bonus_archetype_id != void 0) && b.build_remaining == void 0;
  152. }
  153.  
  154. function buildingProducing(b) {
  155.  
  156. // DO NOT call this function for the keep: it has neither build_remaining nor producing_archetype_id
  157.  
  158. // Luck-based recipes do not assign producing_archetype_id property
  159. // for all others this returns the remaining build
  160. //return b.producing_archetype_id && b.build_remaining;
  161.  
  162. // Simple and short, if this property is present and the value
  163. // is a positive number, then the building is still in production
  164. return b.build_remaining != void 0 && b.build_remaining > 0;
  165. }
  166.  
  167. function updateBuildingTimer(b){
  168. }
  169.  
  170. var bruteForceTimeout;
  171. function bruteForce(enabled, times) {
  172.  
  173. if (brutingImmediateTermination) {
  174. bruteForceTimeout = clearTimeout(bruteForceTimeout);
  175.  
  176. msg = "Bruting terminated immediately.";
  177. log(msg, "BRUTING");
  178. inform(msg);
  179. return;
  180. }
  181.  
  182. var msg;
  183. var container = $("#bruteBtn");
  184. if (!container || container.length == 0) {
  185. container = $(".challengerewardbox .rewarditem:last");
  186. }
  187.  
  188. if (!container || container.length == 0) {
  189. container = $(".challengerewards .challengerewarditems:first");
  190. }
  191.  
  192. if (!container || container.length == 0) {
  193. msg = "Cannot find appropriate container for messaging!";
  194. warn(msg);
  195. }
  196.  
  197. if (typeof enabled == "boolean" && !enabled) {
  198. bruteForceTimeout = clearTimeout(bruteForceTimeout);
  199.  
  200. msg = "Bruting terminated.";
  201. log(msg, "BRUTING");
  202.  
  203. // console.debug("Debuging message delivery: is there a container? " + (container) + ", " +
  204. // "what's his length: " + container.length + ", append message? " + (container && container.length > 0) + ", " +
  205. // "and what's the message: " + msg);
  206.  
  207. if (container.hasClass("btnwrap btnmed")) {
  208. container.find("a").text("Done!");
  209. }
  210.  
  211. container.after("<br />" + msg);
  212.  
  213. if (times === "all") {
  214. bruteSendAll();
  215. }
  216.  
  217. return;
  218. }
  219.  
  220. // Do not run if bruting is disabled (but can be viewed)
  221. if (extender_bruteWounds && extender_bruteWounds == 0) {
  222.  
  223. msg = "Disabled. Please set a positive number of max wounds from options to continue.";
  224. warn(msg, "BRUTING");
  225.  
  226. // console.debug("Debuging message delivery: is there a container? " + (container) + ", " +
  227. // "what's his length: " + container.length + ", append message? " + (container && container.length > 0) + ", " +
  228. // "and what's the message: " + msg);
  229.  
  230. container.after("<br />" + msg);
  231.  
  232. bruteForce(false, times);
  233. return;
  234. }
  235.  
  236. var s = userContext.setSwornSword;
  237.  
  238. //var sAsString = JSON.stringify(s);
  239. //log("GETTING S INFO" + sAsString + ".", "BRUTING");
  240.  
  241. if (!s) {
  242. msg = "Failed, no sworn sword set.";
  243. error(msg, "BRUTING");
  244.  
  245. container.after("<br />" + msg);
  246. bruteForce(false, times);
  247. return;
  248. }
  249.  
  250. // console.debug("Debuging sworn sword condition: s.damage: " + s.damage + ", " +
  251. // "extender_bruteWounds: " + extender_bruteWounds + ", do bruting? " + (s.damage < extender_bruteWounds));
  252.  
  253. if (s.damage < extender_bruteWounds) {
  254.  
  255. resolveModifier(s);
  256.  
  257. var attack =
  258. extender_sendAllAction === "selected" && !(!userContext.currentActionLabel)
  259. ? userContext.currentActionLabel : s.modifier;
  260.  
  261. // console.debug("Attack with: " + attack);
  262. if (times == "once") {
  263. doAdventure("", attack, false, function (failure) {
  264. bruteForce(false, times);
  265. });
  266. } else {
  267. doAdventure("", attack, false, function (failure) {
  268. bruteForce(!failure, times);
  269. });
  270. }
  271. var upgradetimes = s.upgrade_points;
  272. var lastdoness = GM_getValue("lastdoness");
  273. while(upgradetimes > 0 && s.id != lastdoness){
  274. if(extender_existTrain == "mod"){
  275. doTrain(s.modifier);
  276. log("Training " + s.full_name + " Modifier " + s.modifier + ": "+ upgradetimes +" points to go", "BRUTING");
  277. }else{
  278. var max = Math.max(s.calc_battle, s.calc_trade, s.calc_intrigue);
  279. if (max == s.calc_intrigue) {
  280. var StattoTrain="intrigue";
  281. } else if (max == s.calc_trade) {
  282. var StattoTrain="trade";
  283. } else {
  284. var StattoTrain="battle";
  285. }
  286. doTrain(StattoTrain);
  287. log("Training " + s.full_name + " Base Stat " + StattoTrain + ". " + upgradetimes +" points to go", "BRUTING");
  288. }
  289. upgradetimes--;
  290. }
  291. GM_setValue("lastdoness",s.id);
  292.  
  293.  
  294. return;
  295. }
  296.  
  297. if (times === "all" || extender_bruteSwitchOff) {
  298.  
  299. msg = "Sworn sword recieved " + extender_bruteWounds + " wounds! Brute timer will self terminate.";
  300. warn(msg, "BRUTING");
  301.  
  302. // console.debug("Debuging message delivery: is there a container? " + (container) + ", " +
  303. // "what's his length: " + container.length + ", append message? " + (container && container.length > 0) + ", " +
  304. // "and what's the message: " + msg);
  305.  
  306. container.after("<br />" + msg);
  307.  
  308. bruteForce(false, times);
  309.  
  310. } else {
  311.  
  312. // Add a minute to the cooldown, and then multiply by wounds
  313. var interval = extender_bruteWounds * (s.damage_cooldown + 60);
  314. msg = "Sworn sword recieved " + extender_bruteWounds + " wounds! " +
  315. "Brute timer will self adjust. Wait " + extender_bruteWounds + " * (" + s.damage_cooldown + " + 60) = " + interval + " seconds.";
  316.  
  317. warn(msg, "BRUTING");
  318.  
  319. bruteForceTimeout = setTimeout(function () {
  320. bruteForce(true, times);
  321. }, interval * 1000);
  322.  
  323. // console.debug("Debuging message delivery: is there a container? " + (container) + ", " +
  324. // "what's his length: " + container.length + ", append message? " + (container && container.length > 0) + ", " +
  325. // "and what's the message: " + msg);
  326.  
  327. container.after("<br />" + msg);
  328. }
  329. };
  330.  
  331. function bruteSendAll() {
  332. var sw = getSwornSwords(extender_sendAllAction);
  333. console.debug("Sworn swords retrieved successfully...");
  334.  
  335. for (var i = 0; i < sw.length; i++) {
  336. var ss = sw[i];
  337.  
  338. if (typeof ss.not_on_adventure == "boolean" && ss.not_on_adventure)
  339. continue;
  340.  
  341. if (ss.cooldown > 0 || ss.damage >= extender_bruteWounds)
  342. continue;
  343.  
  344. console.debug("Sending: " + ss.full_name);
  345.  
  346. setSwornSword(ss.id);
  347. bruteForce(true, "all");
  348. return;
  349. }
  350.  
  351. inform("All sworn swords have been bruted to maximum wounds.<br>Action: " + extender_sendAllAction);
  352.  
  353. }
  354.  
  355. var brutingImmediateTermination = false;
  356. $(document).on("keyup", function (e) {
  357. if (e.keyCode == 27) {
  358. e.preventDefault();
  359. e.stopPropagation();
  360.  
  361. brutingImmediateTermination = true;
  362. log("Attempting immediate bruting termination.");
  363. }
  364. });
  365.  
  366. function increment(me) {
  367. var opt = $(me);
  368.  
  369. var min = parseInt(opt.attr("min"));
  370. var max = parseInt(opt.attr("max"));
  371. var step = parseInt(opt.attr("step"));
  372. var val = parseInt(opt.text());
  373.  
  374. if (isNaN(min) || isNaN(max) || isNaN(step) || isNaN(val)) {
  375. error("Parsing of attributes failed!", "number option");
  376. return;
  377. }
  378.  
  379. var newVal = val + step > max ? min : val + step;
  380. opt.text(newVal);
  381. };
  382.  
  383. function check(me) {
  384. $(me).toggleClass('checked');
  385. };
  386.  
  387. function bruteSwitchToggle(me) {
  388. var bSwitch = $(me).find("a.btngold");
  389. bSwitch.text() == "switch off"
  390. ? bSwitch.text("adjust")
  391. : bSwitch.text("switch off");
  392. };
  393.  
  394. function inputIncrement(me) {
  395. var input = $(me).parent().find("input[name='quantity']");
  396. if (!input || input.length == 0) {
  397. return;
  398. }
  399.  
  400. var v = parseInt(input.val());
  401. var max = parseInt(input.attr("maxlength"));
  402. if (isNaN(v) || isNaN(max)) {
  403. return;
  404. }
  405.  
  406. if (me.id == "excountup") {
  407. (max == 3 ? max = 999 : max = 99);
  408. (v + 1 > max ? v = max : v = v + 1);
  409. } else if (me.id == "excountdown") {
  410. (v - 1 < 0 ? v = 0 : v = v - 1);
  411. }
  412.  
  413. input.val(v);
  414. }
  415.  
  416. function sort(arr) {
  417. if (typeof arr == "undefined") {
  418. arr = playerInventory;
  419. }
  420.  
  421. if (!(arr instanceof Array)) {
  422. error("Not an array! Sorting failed.");
  423. return arr;
  424. }
  425. // console.debug("Sorting of array initiated, check parameters: boons count: " + boons.length + ", " +
  426. // "sorting property: " + extender_boonsSortBy);
  427.  
  428. arr.sort(function (a, b) {
  429. return b[extender_boonsSortBy2] - a[extender_boonsSortBy2];
  430. });
  431.  
  432. arr.sort(function (a, b) {
  433. return b[extender_boonsSortBy] - a[extender_boonsSortBy];
  434. });
  435.  
  436. log("Array sorted by " + extender_boonsSortBy + " and then by " + extender_boonsSortBy2 + " successfully.", "PAGE");
  437. return arr;
  438.  
  439. }
  440.  
  441. function sortShop(arr) {
  442. if (typeof arr == "undefined" || !(arr instanceof Array)) {
  443. error("Not an array. Please pass an array to be sorted.");
  444. return arr;
  445. }
  446.  
  447. //console.debug("Sorting of array initiated, check array count: " + arr.length);
  448.  
  449. arr.sort(function(a, b) {
  450.  
  451. //console.debug("Init first sorting, condition 1, properties exist: ", a.hasOwnProperty(extender_shopSortBy2), b.hasOwnProperty(extender_shopSortBy2));
  452. if (!a.hasOwnProperty(extender_shopSortBy2) || !b.hasOwnProperty(extender_shopSortBy2)) {
  453. return false;
  454. }
  455.  
  456. var aVal = a[extender_shopSortBy2];
  457. var bVal = b[extender_shopSortBy2];
  458.  
  459. //console.debug("Logging property values: ", aVal, bVal);
  460.  
  461. if (typeof aVal != "number" || typeof bVal != "number") {
  462.  
  463. //console.debug("Values need parsing...");
  464.  
  465. aVal = parseInt(aVal);
  466. bVal = parseInt(bVal);
  467.  
  468. //console.debug("Parsed values: ", aVal, bVal);
  469. if (isNaN(aVal) || isNaN(bVal)) {
  470. return false;
  471. }
  472. }
  473.  
  474. //console.debug("Sorting descending...");
  475. return bVal - aVal;
  476. });
  477.  
  478. arr.sort(function (a, b) {
  479.  
  480. //console.debug("Init second sorting, condition 1, properties exist: ", a.hasOwnProperty(extender_shopSortBy2), b.hasOwnProperty(extender_shopSortBy2));
  481. if (!a.hasOwnProperty(extender_shopSortBy) || !b.hasOwnProperty(extender_shopSortBy)) {
  482. return false;
  483. }
  484. var aVal = a[extender_shopSortBy];
  485. var bVal = b[extender_shopSortBy];
  486.  
  487. //console.debug("Logging property values: ", aVal, bVal);
  488.  
  489. if (typeof aVal != "number" || typeof bVal != "number") {
  490.  
  491. //console.debug("Values need parsing...");
  492.  
  493. aVal = parseInt(aVal);
  494. bVal = parseInt(bVal);
  495.  
  496. //console.debug("Parsed values: ", aVal, bVal);
  497. if (isNaN(aVal) || isNaN(bVal)) {
  498. return false;
  499. }
  500. }
  501.  
  502. //console.debug("Sorting descending...");
  503. return bVal - aVal;
  504. });
  505.  
  506. // Array will always be sorted by gold, descending
  507. arr.sort(function (a, b) {
  508. return parseInt(a["price_perk_points"]) - parseInt(b["price_perk_points"]);
  509. });
  510.  
  511. //console.debug("Sorted by gold: ");
  512.  
  513. //arr.forEach(function (element) {
  514. // console.debug(element["price_perk_points"]);
  515. //});
  516.  
  517. log("Array sorted by " + extender_shopSortBy + " and then by " + extender_shopSortBy2 + " successfully.", "PAGE");
  518. return arr;
  519.  
  520. }
  521.  
  522. function formatStats(battle, trade, intrigue, level) {
  523. return '<div class="exstatbox">' +
  524. '<div id="plevel" class="statitem">' +
  525. '<div><span></span>' +
  526. '</div><var>' + level + '</var></div>' +
  527. '<div id="battle" class="statitem">' +
  528. '<div><span></span>' +
  529. '</div><var class="battle_val" id="battle_val">' + battle + '</var></div>' +
  530. '<div id="trade" class="statitem">' +
  531. '<div><span></span>' +
  532. '</div><var class="trade_val" id="trade_val">' + trade + '</var></div>' +
  533. '<div id="intrigue" class="statitem">' +
  534. '<div><span></span></div>' +
  535. '<var class="intrigue_val" id="intrigue_val">' + intrigue + '</var></div>' +
  536. '</div>';
  537. }
  538.  
  539. function getSwornSwords(filter, garrison_region, garrison_subregion) {
  540. var ss = [];
  541. var pi = playerInventory;
  542.  
  543. for (var i = 0; i < pi.length; i++) {
  544. var s = pi[i];
  545.  
  546. if (s.slot !== "Sworn Sword")
  547. continue;
  548.  
  549. if (!s.modifier) {
  550. resolveModifier(s);
  551. }
  552.  
  553. if (typeof filter == "number" && !isNaN(filter) && s.id === filter) {
  554. return s;
  555. }
  556.  
  557. if (typeof filter == "string" && !isNaN(parseInt(filter)) && s.id === parseInt(filter)) {
  558. return s;
  559. }
  560.  
  561. if (typeof garrison_region != "undefined" && typeof garrison_subregion != "undefined" &&
  562. !isNaN(garrison_region) && !isNaN(garrison_subregion) && !checkGarrison(s, garrison_region, garrison_subregion))
  563. continue;
  564.  
  565. if (typeof filter == "string") {
  566.  
  567. if (filter == "all" || filter == "selected") {
  568. ss.push(s);
  569. continue;
  570.  
  571. } else if (filter == "none"){
  572. continue;
  573. }
  574.  
  575. var friendlyActions = ["aid", "barter", "bribe"];
  576. var hostileActions = ["fight", "harass", "spy", "sabotage", "steal", "hoodwink"];
  577.  
  578. var battleActions = ["fight", "harass", "aid"];
  579. var tradeActions = ["barter", "hoodwink", "bribe"];
  580. var intrigueActions = ["spy", "sabotage", "steal"];
  581.  
  582. //if ((friendlyActions.indexOf(filter) > -1 || hostileActions.indexOf(filter) > -1) && s.modifier != filter) {
  583. // continue;
  584. //}
  585.  
  586. switch (filter) {
  587. case "battle":
  588. {
  589. if (battleActions.indexOf(s.modifier) == -1)
  590. continue;
  591. else
  592. break;
  593. }
  594. case "trade":
  595. {
  596. if (tradeActions.indexOf(s.modifier) == -1)
  597. continue;
  598. else
  599. break;
  600. }
  601. case "intrigue":
  602. {
  603. if (intrigueActions.indexOf(s.modifier) == -1)
  604. continue;
  605. else
  606. break;
  607. }
  608. case "friendly":
  609. {
  610. if (friendlyActions.indexOf(s.modifier) == -1)
  611. continue;
  612. else
  613. break;
  614. }
  615. case "hostile":
  616. {
  617. if (hostileActions.indexOf(s.modifier) == -1)
  618. continue;
  619. else
  620. break;
  621. }
  622. default:
  623. {
  624. if (s.modifier != filter)
  625. continue;
  626. else
  627. break;
  628. }
  629. }
  630. }
  631.  
  632. ss.push(s);
  633. }
  634.  
  635. return ss;
  636. }
  637.  
  638. function checkGarrison(s, region, subregion) {
  639. if (typeof s.garrison_region == "undefined" || typeof s.garrison_subregion == "undefined" ||
  640. isNaN(s.garrison_region) && isNaN(s.garrison_subregion)) {
  641. return false;
  642. }
  643.  
  644. if (s.garrison_region != region || s.garrison_subregion != subregion) {
  645. return false;
  646. }
  647.  
  648. return true;
  649. }
  650.  
  651. function setSwornSword(param) {
  652. if (typeof param == "undefined") {
  653. error("The function requires a sworn sword id as parameter.")
  654. return;
  655. }
  656. if (typeof param == "number") {
  657. var s = extractItemById(playerInventory, param);
  658. s && (userContext.setSwornSword = s);
  659. } else if (typeof param == "string") {
  660. var s = extractItemById(playerInventory, parseInt(param));
  661. s && (userContext.setSwornSword = s);
  662. } else if (typeof param == "object") {
  663. userContext.setSwornSword = param;
  664. }
  665. }
  666.  
  667. function checkCommandPoints() {
  668. if(!userContext || !userContext.playerData || !userContext.playerData.stat)
  669. return false;
  670.  
  671. var commandPoints = userContext.playerData.stat.command - userContext.playerData.stat.current_command;
  672.  
  673. log("Debugging check command points: command points: " + commandPoints + ", " +
  674. "continue then? " + (!isNaN(commandPoints) && commandPoints > 0));
  675.  
  676. return !isNaN(commandPoints) && commandPoints > 0;
  677. }
  678. function adventureSendAll(adventure, swornswords) {
  679.  
  680. if (extender_sendAllAction === "none") {
  681. inform("This function is disabled. Please enable it from options.");
  682. return;
  683. }
  684.  
  685. if(!checkCommandPoints()){
  686. inform("Not enough command points. <br>Action cannot execute.");
  687. return;
  688. }
  689.  
  690. if (typeof swornswords == "undefined" || !(swornswords instanceof window.Array)) {
  691. error("An array should be passed to the function. Sending failed.");
  692. return;
  693. }
  694.  
  695. if (typeof adventure != "string") {
  696. error("Adventure should be passed as a string. Sending failed.");
  697. return;
  698. }
  699.  
  700. if (swornswords.length == 0) {
  701. inform('All sworn swords send on ' + adventure + '.<br>Action: ' + extender_sendAllAction);
  702. return;
  703. }
  704.  
  705. var s = swornswords.pop();
  706.  
  707. log("Debuging send all: swornswords: " + swornswords.length + ", " +
  708. "current: " + s.full_name + ", " +
  709. "cooldown: " + s.cooldown + ", " +
  710. "damage: " + s.damage + ", " +
  711. "send? " + !(s.cooldown > 0 || s.damage >= extender_bruteWounds));
  712.  
  713. if(s.cooldown > 0 || s.damage >= extender_bruteWounds) {
  714. adventureSendAll(adventure, swornswords);
  715. return;
  716. }
  717.  
  718. setSwornSword(s.id);
  719.  
  720. if (!s.modifier) {
  721. resolveModifier(s);
  722. }
  723.  
  724. var attack =
  725. extender_sendAllAction === "selected" && !(!userContext.currentActionLabel)
  726. ? userContext.currentActionLabel : s.modifier;
  727.  
  728. doAdventure(adventure, attack, false, function (failure) {
  729. adventureSendAll(adventure, swornswords);
  730. });
  731.  
  732. }
  733.  
  734. var pvpFormStore;
  735. function pvpSendBatch(swornswords) {
  736. if (extender_sendAllAction === "none") {
  737. inform("This function is disabled. Please enable it from options.");
  738. return;
  739. }
  740.  
  741. if(!checkCommandPoints()){
  742. inform("Not enough command points. <br>Action cannot execute.");
  743. return;
  744. }
  745.  
  746. if (typeof swornswords == "undefined" || !(swornswords instanceof window.Array)) {
  747. error("An array should be passed to the function. Sending failed.");
  748. return;
  749. }
  750.  
  751. if (swornswords.length == 0) {
  752. inform("All sworn swords are now busy.<br>Action: " + extender_sendAllAction);
  753. pvpFormStore = {}; // clear the store for further use
  754. return;
  755. }
  756.  
  757. var s = swornswords.pop();
  758.  
  759. log("Debuging send all: swornswords: " + swornswords.length + ", " +
  760. "current: " + s.full_name + ", " +
  761. "cooldown: " + s.cooldown + ", " +
  762. "damage: " + s.damage + ", " +
  763. "send? " + !(s.cooldown > 0 || s.damage >= extender_bruteWounds));
  764.  
  765. if (s.cooldown > 0 || s.damage >= extender_bruteWounds) {
  766. pvpSendBatch(swornswords);
  767. return;
  768. }
  769.  
  770. // Store the pvp or replace it
  771. // if it is stored already
  772.  
  773. if (!pvpFormStore) {
  774. pvpFormStore = pvpForm;
  775. } else {
  776. pvpForm = pvpFormStore;
  777. }
  778.  
  779. setSwornSword(s.id);
  780.  
  781. if (!s.modifier) {
  782. resolveModifier(s);
  783. }
  784.  
  785. if (extender_sendAllAction !== "selected") {
  786. userContext.currentActionLabel = s.modifier;
  787. }
  788.  
  789. pvpLaunch(function(success) {
  790. pvpSendBatch(swornswords);
  791. });
  792. }
  793.  
  794. function resolveModifier(s) {
  795. if (s.modifier) {
  796. log("Modifier already set.");
  797. return;
  798. }
  799. // Calculate what attack shoild we use if there ain't any
  800. var max = Math.max(s.calc_battle, s.calc_trade, s.calc_intrigue);
  801. if (max == s.calc_intrigue) {
  802. if(extender_intrigueTrain && extender_intrigueTrain != "intrigue"){
  803. s.modifier = extender_intrigueTrain;
  804. }else{
  805. s.modifier = "spy";
  806. }
  807. } else if (max == s.calc_trade) {
  808. if(extender_tradeTrain && extender_tradeTrain != "trade"){
  809. s.modifier = extender_tradeTrain;
  810. }else{
  811. s.modifier = "barter";
  812. }
  813. } else {
  814. if(extender_battleTrain && extender_battleTrain != "battle"){
  815. s.modifier = extender_battleTrain;
  816. }else{
  817. s.modifier = "fight";
  818. }
  819. }
  820. }
  821.  
  822. function avaSendBatch(swornswords) {
  823. if (extender_sendAllAction === "none") {
  824. inform("This function is disabled. Please enable it from options.");
  825. return;
  826. }
  827.  
  828. if(!checkCommandPoints()){
  829. inform("Not enough command points. <br>Action cannot execute.");
  830. return;
  831. }
  832.  
  833.  
  834. if (typeof swornswords == "undefined" || !(swornswords instanceof window.Array)) {
  835. error("An array should be passed to the function. Sending failed.");
  836. return;
  837. }
  838.  
  839. if (swornswords.length == 0) {
  840. inform("All sworn swords are now busy.<br>Action: " + extender_sendAllAction);
  841. return;
  842. }
  843.  
  844. var s = swornswords.pop();
  845.  
  846. console.debug("Debuging send all: swornswords: " + swornswords.length + ", " +
  847. "current: " + s.full_name + ", " +
  848. "id: " + s.id + ", " +
  849. "cooldown: " + s.cooldown + ", " +
  850. "damage: " + s.damage + ", " +
  851. "region: " + s.garrison_region + ", " +
  852. "subregion: " + s.garrison_subregion + ", " +
  853. "send? " + !(s.damage >= extender_bruteWounds));
  854.  
  855. if (s.damage >= extender_bruteWounds) {
  856. avaSendBatch(swornswords);
  857. return;
  858. }
  859.  
  860. itemCurrentSelection = s;
  861.  
  862. if (extender_sendAllAction !== "selected") {
  863. userContext.currentActionLabel = s.modifier;
  864. }
  865.  
  866. doCampAttack(userContext.campAttackData.id, "skip", function (r) {
  867. console.debug("Anonymous function parameter: ", r);
  868.  
  869. if (r.error) {
  870. avaSendBatch(swornswords);
  871. return;
  872. }
  873.  
  874. if (!r.camp_attack) {
  875. error("Camp data is missing, cannot create new attack.");
  876. return;
  877. }
  878.  
  879. r = r.camp_attack;
  880.  
  881. $.ajax({
  882. url: "/play/camp_attack_create?alliance_id=" + r.target_alliance_id + "&region=" + r.region + "&subregion=" + r.subregion + "&acnew=" + userContext.playerData.ac,
  883. dataType: "JSON",
  884. success: function(a) {
  885. userContext.camp_battle = a.battle;
  886. userContext.camp_trade = a.trade;
  887. userContext.camp_intrigue = a.intrigue;
  888. userContext.campAttackData = a;
  889. startCampAttack(userContext.campAttackData);
  890.  
  891. avaSendBatch(swornswords);
  892. }
  893. });
  894. });
  895. }
  896.  
  897. window.addEventListener("message", receiveMessage, false);
  898. function receiveMessage(event) {
  899. // Do we trust the sender of this message?
  900. if (event.origin !== "https://games.disruptorbeam.com") {
  901. error("Message from untrusted source was rejected.");
  902. console.debug(event);
  903. return;
  904. }
  905.  
  906. //console.debug("Message recieved: ", event);
  907. console.log("Evaluated: ", eval(event.data));
  908.  
  909. }
  910.  
  911. function observable_onkeyup(e){
  912. //console.debug(e);
  913.  
  914. if(e.keyCode === 13 && !e.ctrlKey && !e.shiftKey) {
  915. var observable = $("textarea#observable");
  916. if (!observable) {
  917. error("The observable DOM element was not found in the page.");
  918. return false;
  919. }
  920.  
  921. try {
  922. var cmd = observable.val().split("\n")[0];
  923. eval("extender." + cmd);
  924. } catch (err) {
  925. var prefix = "COMMAND FAILED" + " | " + new Date().toLocaleTimeString() + " | ";
  926. observable.val(prefix + err);
  927. }
  928.  
  929. return false;
  930. }
  931.  
  932. if(e.keyCode === 46){
  933. var observable = $("textarea#observable");
  934. if (!observable) {
  935. error("The observable DOM element was not found in the page.");
  936. return false;
  937. }
  938.  
  939. observable.val("");
  940. return false;
  941. }
  942.  
  943. return true;
  944. }
  945.  
  946. function clearLog(){
  947. sessionStorage.set("clientEntries", []);
  948. log("The client log has been cleared successfully.");
  949.  
  950. $("#logTab").trigger("click");
  951. }
  952.  
  953. var bossChallenger = (function(log, error, questClose, questSubmit, localStorage){
  954.  
  955. var _this = {
  956. init: init,
  957. fight: fight,
  958. persist: persist,
  959. config: config,
  960. addQuest: addQuest,
  961. removeQuest: removeQuest,
  962.  
  963. enabled: true,
  964. bossQuests: []
  965. };
  966.  
  967. function init(o){
  968. try {
  969. _this.bossQuests = localStorage.get("bossQuests", []);
  970.  
  971. _this.config(o);
  972.  
  973. // Relaunch any quests pending...
  974. for (var i = 0; i < _this.bossQuests.length; i++) {
  975. var a = _this.bossQuests[i];
  976. questSubmit(a.quest, a.stage, a.attack, a.chosen, null, null, a.questId);
  977. }
  978. } catch(e) {
  979. error(e);
  980. }
  981. }
  982.  
  983. function config(o){
  984. //console.debug(o);
  985.  
  986. _this.enabled = o.autoBossChallenge;
  987. }
  988.  
  989. function persist(){
  990. localStorage.set("bossQuests", _this.bossQuests);
  991. }
  992.  
  993. // Response, attack
  994. function fight(a, c){
  995. if (a.actions_remaining == void 0 || isNaN(a.actions_remaining)){
  996. log("Not on boss challenge (no actions remaining). Exiting...", "BOSS");
  997. return;
  998. }
  999.  
  1000. if(!_this.enabled){
  1001. log("Boss challenge is not automated. Exiting...", "EXTENDER");
  1002. return;
  1003. }
  1004.  
  1005. log("Boss challenge automated. Actions remaining: " + a.actions_remaining + ", " +
  1006. "stage: " + a.stage, "BOSS");
  1007.  
  1008. if(a.stage && a.stage === 1000){
  1009. log("Boss challenge complete. Exiting...", "BOSS");
  1010.  
  1011. _this.removeQuest(a.id);
  1012. _this.persist();
  1013.  
  1014. // Close dialog and pop it from whenever necessary
  1015. questClose(a.symbol, a.id, true);
  1016. return;
  1017. }
  1018.  
  1019. if (a.actions_remaining > 0) {
  1020. questSubmit(a.symbol, a.stage, c, a.chosen, null, null, a.id);
  1021. } else {
  1022. log("No actions remaining! Adjusting...", "BOSS");
  1023.  
  1024. var bossQuest = {
  1025. "quest": a.symbol,
  1026. "stage": a.stage,
  1027. "attack": c,
  1028. "chosen": a.chosen,
  1029. "questId": a.id,
  1030. "timeout": setTimeout(function() {
  1031. questSubmit(a.symbol, a.stage, c, a.chosen, null, null, a.id);
  1032. }, 3 * 4 * 60 * 1000)
  1033. };
  1034.  
  1035.  
  1036. _this.addQuest(bossQuest);
  1037. _this.persist();
  1038.  
  1039. log("Timer running. Fire again in 12 minutes.", "BOSS");
  1040. }
  1041. }
  1042.  
  1043. function addQuest(quest){
  1044. if(quest == void 0){
  1045. error("No quest was passed to add function. Exiting...");
  1046. return;
  1047. }
  1048.  
  1049. var quests = _this.bossQuests;
  1050. for(var i = 0; i < quests.length; i++){
  1051. if(quests[i].questId == quest.questId){
  1052. log("Quest is already made persistable.");
  1053. return;
  1054. }
  1055. }
  1056.  
  1057. quests.push(quest);
  1058.  
  1059. }
  1060.  
  1061. function removeQuest(questId){
  1062.  
  1063. // Remove the quest from the array
  1064. _this.bossQuests = _this.bossQuests.filter(function (el) {
  1065. return el.questId !== questId;
  1066. });
  1067. }
  1068.  
  1069. return _this;
  1070.  
  1071. }(log, error, questClose, questSubmit, localStorage));
  1072.  
  1073. function exSendFavors(favor, characterList){
  1074.  
  1075. var json = {
  1076. favor: favor,
  1077. recipients: characterList
  1078. };
  1079.  
  1080. showSpinner();
  1081.  
  1082. $.ajax({
  1083. type: "POST",
  1084. url: "/play/send_mass_favors",
  1085. data: json,
  1086. dataType: "JSON",
  1087. complete: hideSpinner,
  1088. success: function (a) {
  1089. !0 == a.status
  1090. ? void 0 == a.exceptions ? (doAlert("Message Sent", "Your Raven has been sent."), isWeb() || iosSignal("favors_sent", a.count)) : doAlert("Message Sent", "Your Raven has been sent.<br/><br/>" + a.exceptions + " did not receive a favor as you have already sent them the maximum per day.") : !1 == a.status && ("invalid_favor" == a.reason ? doAlert("Message Center",
  1091. "The selected favor is invalid.") : "not_enough_favors" == a.reason ? doAlert("Message Center", "You have reached your daily favor-giving limit. Your raven was not sent.") : "favor_limit_all" == a.reason ? doAlert("Message Center", "You have already sent the favors daily maximum to these recipients.") : "select_min_player" == a.reason && doAlert("Message Center", "Please select at least one recipient."))
  1092. }
  1093. })
  1094. }
  1095.  
  1096. var worldEvent = (function ($, log, warn, error, submitWorldEventAction, getWorldEventAttackResults, userContext) {
  1097. var _this = {
  1098.  
  1099. delay: 4E3,
  1100. enabled: true,
  1101. timeouts: [],
  1102.  
  1103. get attackers() {
  1104. return localStorage.get("weAttackers", []);
  1105. },
  1106.  
  1107. set attackers(val) {
  1108. localStorage.set("weAttackers", val);
  1109. },
  1110.  
  1111. init: function (o) {
  1112. try {
  1113.  
  1114. this.config(o);
  1115. this.analyze();
  1116.  
  1117. log("World event initialized.", "WORLD EVENT");
  1118.  
  1119. } catch(err) {
  1120. error(err);
  1121. }
  1122. },
  1123.  
  1124. config: function (o) {
  1125. //console.debug(o);
  1126.  
  1127. this.delay = o.worldEventDelay * 1E3 || this.delay;
  1128. this.enabled = o.weManagerEnabled != void 0 ? o.weManagerEnabled : this.enabled;
  1129. },
  1130.  
  1131. dispatch: function () {
  1132. if (!this.enabled) {
  1133. log("This feature has been disabled. Exiting...", "WORLD EVENT");
  1134. return;
  1135. }
  1136.  
  1137. var attackers = this.attackers.filter(function(a){
  1138. return a != void 0;
  1139. });
  1140.  
  1141. for (var i = 0; i < attackers.length; i++) {
  1142.  
  1143. var ss = getSwornSwords(attackers[i]);
  1144. if (!ss) {
  1145. error("Failed to find the sworn sword. Request won't be sent.");
  1146. continue;
  1147. }
  1148.  
  1149. var order = $("#slot_" + i + "_orders").length
  1150. ? $("#slot_" + i + "_orders").val()
  1151. : ss.modifier;
  1152.  
  1153. submitWorldEventAction(ss.id, order, false);
  1154. }
  1155. },
  1156.  
  1157. retrieve: function (ss) {
  1158. if (!this.enabled) {
  1159. log("This feature has been disabled. Exiting...", "WORLD EVENT");
  1160. return;
  1161. }
  1162.  
  1163. if (ss != void 0) {
  1164.  
  1165. if (!ss.id || !ss.action || (ss.full_name == void 0 && ss.name == void 0) || (ss.cooldown == void 0 && ss.cooldown_seconds == void 0)) {
  1166. error("Incorrect object passed, lack of parameters.", "WORLD EVENT");
  1167. console.debug("Debug information, passed sworn sword: ", ss);
  1168. return;
  1169. }
  1170.  
  1171. var cooldown =
  1172. ss.cooldown != void 0 // defined as cooldown
  1173. ? (ss.cooldown !== 0
  1174. ? ss.cooldown // there is a cooldown
  1175. : false) // there ain't a cooldown
  1176.  
  1177. : ss.cooldown_seconds != void 0 // defined as cooldown_seconds
  1178. ? (ss.cooldown_seconds !== 0
  1179. ? ss.cooldown_seconds // there is a cooldown
  1180. : false) // there ain't a cooldown
  1181.  
  1182. : 36E2; // default cooldown of 1hour
  1183.  
  1184.  
  1185. if (!cooldown) {
  1186.  
  1187. getWorldEventAttackResults(ss.id, ss.action, true);
  1188.  
  1189. } else {
  1190.  
  1191. var timeout = {
  1192. id: ss.id,
  1193. name: ss.full_name || ss.name,
  1194. timeout: setTimeout(function () {
  1195.  
  1196. getWorldEventAttackResults(ss.id, ss.action, true);
  1197.  
  1198. }, (cooldown * 1E3) + _this.delay)
  1199. }
  1200.  
  1201. this.timeouts.push(timeout);
  1202. }
  1203.  
  1204. return;
  1205. }
  1206. },
  1207.  
  1208. analyze: function () {
  1209. if (!this.enabled) {
  1210. log("This feature has been disabled. Exiting...", "WORLD EVENT");
  1211. return;
  1212. }
  1213.  
  1214. // dummy data
  1215. var data = {
  1216. sworn_sword_id: 0,
  1217. order: "aid",
  1218. };
  1219.  
  1220. $.ajax({
  1221. url: "/play/world_event_attack",
  1222. data: data,
  1223. success: function (a) {
  1224. console.debug("Analyzing response from the server for the world event action: ", a);
  1225.  
  1226. if (a.challenge && a.challenge.active_swornswords) {
  1227. for (var i = 0; i < a.challenge.active_swornswords.length; i++) {
  1228. _this.retrieve(a.challenge.active_swornswords[i]);
  1229. }
  1230. }
  1231.  
  1232. }
  1233. });
  1234. },
  1235.  
  1236. afterSubmit: function (a, ssId) {
  1237. if (!this.enabled) {
  1238. log("This feature has been disabled. Exiting...", "WORLD EVENT");
  1239. return;
  1240. }
  1241.  
  1242. console.debug("Logging response from the server for sending the sworn sword: ", a);
  1243.  
  1244. if (a.swornsword && a.swornsword.cooldown) {
  1245.  
  1246. this.retrieve(a.swornsword);
  1247.  
  1248. } else if (a.challenge && a.challenge.active_swornswords && a.challenge.active_swornswords.length) {
  1249. var swornswords = a.challenge.active_swornswords;
  1250. for (var i = 0; i < swornswords.length; i++) {
  1251. if (swornswords[i].id !== ssId)
  1252. continue;
  1253.  
  1254. this.retrieve(swornswords[i]);
  1255.  
  1256. }
  1257. }
  1258. },
  1259.  
  1260. afterGet: function (b, ssId) {
  1261. if (!this.enabled) {
  1262. log("This feature has been disabled. Exiting...", "WORLD EVENT");
  1263. return;
  1264. }
  1265.  
  1266. console.debug("Logging response from the server from world event attack: ", b);
  1267.  
  1268. if (b.swornsword && b.action) {
  1269. submitWorldEventAction(b.swornsword.id, b.action, false);
  1270. }
  1271. },
  1272.  
  1273. enlistSS: function () {
  1274.  
  1275. try {
  1276. var attackArray = this.attackers;
  1277. var ss = userContext.setSwornSword;
  1278. if (ss == void 0) {
  1279.  
  1280. if (attackArray.length == 5) {
  1281. attackArray.pop();
  1282. }
  1283.  
  1284. attackArray.unshift(null);
  1285.  
  1286. } else {
  1287.  
  1288. if (attackArray.indexOf(ss.id) > -1) {
  1289. warn("Selected sworn sword is already enlisted for the world event. Exiting...", "WORLD EVENT");
  1290. return;
  1291. }
  1292.  
  1293. if (attackArray.length == 5) {
  1294. attackArray.pop();
  1295. attackArray.unshift(ss.id);
  1296. } else {
  1297. attackArray.push(ss.id);
  1298. }
  1299. }
  1300.  
  1301. this.attackers = attackArray;
  1302. $("#weTab").trigger('click');
  1303.  
  1304. } catch (e) {
  1305. error(e);
  1306. }
  1307.  
  1308. }
  1309. }
  1310.  
  1311. return _this;
  1312.  
  1313. }($, log, warn, error, submitWorldEventAction, getWorldEventAttackResults, userContext));
  1314.  
  1315. // TODO: Implement..
  1316. //var PERSISTABLE = {
  1317. //
  1318. // get queue() {
  1319. // return localStorage.get("productionQueue", []);
  1320. // },
  1321. //
  1322. // set queue(val) {
  1323. // localStorage.set("productionQueue", val);
  1324. // }
  1325. //};

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址