custom_edited

custom_edited library to use

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/18325/115901/custom_edited.js

  1. doLog = function() {
  2. };
  3. log("Logging killed.", "initialize");
  4.  
  5. animatedCoins.init = function(b, a, e, g) {
  6. if (isWeb()) {
  7. var c,
  8. d,
  9. f,
  10. h,
  11. k = { images: ["/images/animations/coin_flip.png"], animations: { all: [0, 32] }, frames: { regX: 0, height: 60, count: 33, regY: 0, width: 61 } },
  12. m = {
  13. images: ["/images/animations/coin_sparkle.png"],
  14. animations: { all: { frames: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] } },
  15. frames: [
  16. [0, 0, 128, 128, 0, 0, 0], [128, 0, 128, 128, 0, 0, 0], [256, 0, 128, 128, 0, 0, 0], [384, 0, 128, 128, 0, 0, 0], [512, 0, 128, 128, 0, 0, 0], [640, 0, 128, 128, 0, 0, 0], [768, 0, 128, 128, 0, 0, 0], [896, 0, 128, 128, 0, 0, 0], [0, 128, 128, 128, 0, 0, 0],
  17. [128, 128, 128, 128, 0, 0, 0], [256, 128, 128, 128, 0, 0, 0], [384, 128, 128, 128, 0, 0, 0], [512, 128, 128, 128, 0, 0, 0], [640, 128, 128, 128, 0, 0, 0], [768, 128, 128, 128, 0, 0, 0]
  18. ]
  19. },
  20. l,
  21. n,
  22. p = false;
  23.  
  24. //EXTENDER :: Modification, seriously?
  25. // bugfix: b.offset is undefined (offset from button to silver visually)
  26. if (null === b || void 0 === b || b.length == 0) {
  27. return;
  28. } else if (null === a || void 0 === a) {
  29. return;
  30. } else {
  31. if (null === e || void 0 === e)
  32. e = [
  33. 0,
  34. 0
  35. ];
  36. if (null === g || void 0 === g) g = [0, 0];
  37. d = $("<canvas>").attr({ id: "animatedCoins", "class": "coinCanvasAnimation", width: "130", height: "120" }).prependTo($("body"));
  38. c = d[0];
  39. h = $("<canvas>").attr({ id: "animatedCoinsSparkle", "class": "coinCanvasAnimation", width: "130", height: "120" }).prependTo($("body"));
  40. f = h[0];
  41. c = new createjs.Stage(c);
  42. f = new createjs.Stage(f);
  43. null === b.offset() ? (h.remove(), d.remove(), console.warn("animatedCoins: startingElement.offset() is null. Exiting script.")) : null === a.offset() ? (h.remove(), d.remove(),
  44. console.warn("animatedCoins: endingElement.offset() is null. Exiting script.")) : (d.offset({ left: b.offset().left + e[0], top: b.offset().top + e[1] }), h.offset({ left: b.offset().left + e[0], top: b.offset().top + e[1] }), e = new createjs.SpriteSheet(k), m = new createjs.SpriteSheet(m), l = new createjs.Sprite(e), l.x = 30, l.y = 25, n = new createjs.Sprite(m), l.on("animationend", function(c, f) {
  45. c.visible = false;
  46. doLog("animation end");
  47. null === b.offset() ? (h.remove(), d.remove(), console.error("animatedCoins: startingElement.offset() is null")) :
  48. null === a.offset() ? (h.remove(), d.remove(), console.error("animatedCoins: endingElement.offset() is null")) : (h.offset({ left: a.offset().left + g[0], top: a.offset().top + g[1] }), n.visible = true, n.gotoAndPlay("all"), l.stop(), p = true);
  49. }), n.on("animationend", function(a, b) {
  50. n.visible = false;
  51. p && (n.stop(), d.fadeOut(500, function(a) { d.remove(); }), h.remove());
  52. }), l.gotoAndPlay("all"), n.gotoAndPlay("all"), f.addChild(n), c.addChild(l), createjs.Ticker.setFPS(30), createjs.Ticker.addEventListener("tick", c), createjs.Ticker.addEventListener("tick",
  53. f), $(d).animate({ left: a.offset().left + g[0], top: a.offset().top + g[1] }, 1E3));
  54. }
  55. }
  56. };
  57. log("Animated coins fixed.", "initialize");
  58.  
  59. doInstantSpeedUp = function doInstantSpeedUp(c, a, callback) {
  60. var b = buildingById(c),
  61. d = getCurrentSpeedUpType(b.producing_archetype_id, b.recipe_symbol);
  62.  
  63. // EXTENDER :: Modification
  64. if (instantSpeedCost(b.build_remaining, d) > 0) {
  65. console.log('EXTENDER :: The instant speed up costs money. Exiting...');
  66. return false;
  67. }
  68.  
  69. if (false == hasGold(instantSpeedCost(b.build_remaining, d), function() {
  70. doInstantSpeedUp(c, true, callback);
  71. }, a) && true != a) return false;
  72. playSound("coins");
  73. return speedBuild(-1, c, callback);
  74. };
  75. log("Instant speed up returns if gold is required.", "initialize");
  76.  
  77. doFinishProduction = function doFinishProduction(b, callback) {
  78. var a = buildingByItemId(b), c = itemFromId(a.producing_archetype_id);
  79. userContext.lastFinish = a.symbol;
  80. doLog("doFinishProduction: building_id=" + b + " symbol=" + a.symbol + " producing=" + c.symbol);
  81. "Upgrade" !== c.slot && (analytics.track("Production Finish", { building_symbol: a.symbol, item_symbol: c.symbol, item_category: c.slot }), analytics.wizardtrack("Production Finish", { building_symbol: a.symbol, item_symbol: c.symbol, item_category: c.slot }));
  82. var d = "finish-" + b;
  83. userLock(d) && (playSound("build"),
  84. isWeb() && $("#collect_" + a.symbol).html(""), $.ajax({
  85. url: "/play/finish_production/" + b,
  86. dataType: "JSON",
  87. success: function(a) {
  88. //console.debug("Logging server response for doFinishProduction: ", a);
  89.  
  90. doLog("doFinishProduction: succeess ");
  91. freeLock(d);
  92. var c = buildingByItemId(b, a.building);
  93. userContext.playerData.character = a.character;
  94. userContext.playerData.user.money = a.user.money;
  95. userContext.playerData.stat.onboarding = a.stat.onboarding;
  96. userContext.playerData.stat.num_items_produced = a.stat.num_items_produced;
  97. userContext.playerData.stat.produced_stone = a.stat.produced_stone;
  98. userContext.playerData.stat.building_upgrades_finished =
  99. a.stat.building_upgrades_finished;
  100. c.producing_archetype_id = null;
  101. c.modifier = null;
  102. c.recipe_symbol = null;
  103. var f = extractItemBySymbol(playerInventory, c.symbol);
  104. f.effective_upgrade_level = a.building.effective_upgrade_level;
  105. f.producing_archetype_id = null;
  106. f.modifier = null;
  107. f.recipe_symbol = null;
  108.  
  109. // EXTENDER :: Modification, execute current code ONLY if there's a produced item returned!
  110. if (a.produced_item) {
  111. if (userContext.intCurrentRecipeIndex = null,
  112. doLog("doFinishProduction: data.produced_item.id=" + a.produced_item.id + " quantity=" + a.produced_item.quantity),
  113. insertInventoryFromItem(playerInventory, a.produced_item),
  114. theNewItem = extractItemById(playerInventory, a.produced_item.id), 1 == a.is_loot) {
  115. 0 < a.enhanced_loot_roll
  116. ? dialogAlert({
  117. style: "alert",
  118. text: "The result of your production (enhanced) is: " + a.produced_full_name,
  119. items: [theNewItem],
  120. heading: "You have produced...",
  121. button1: "Okay"
  122. }) : dialogAlert({
  123. style: "alert",
  124. text: "The result of your production is: " + a.produced_full_name,
  125. items: [theNewItem],
  126. heading: "You have produced...",
  127. button1: "Okay"
  128. });
  129. } else if (0 < a.affix_chance) {
  130. var m;
  131. m = "" + ("You have a " + a.affix_chance_from_stats +
  132. "% chance to produce a superior-quality item from your talents, equipment and buildings.");
  133. a.bonus_item_name && (m += " Your " + a.bonus_item_name + " adds another +" + a.affix_chance_from_bonus + "% chance to produce a superior-quality item from your talents, equipment and buildings.");
  134. m = a.affix_roll1 <= a.affix_chance && a.affix_roll2 <= a.affix_chance ? m + "<p/>Critical Success! You obtained a superb result!" : a.affix_roll1 > a.affix_chance && a.affix_roll2 > a.affix_chance ? m + "<p/>You obtained a normal result." : m + "<p/>Success! You obtained a good result.";
  135. dialogAlert({ style: "alert", text: m, items: [theNewItem], heading: a.produced_full_name, button1: "Okay" });
  136. }
  137.  
  138. userContext.newBldgOrUpgrade = true;
  139. var q;
  140.  
  141. "Upgrade" != theNewItem.slot ?
  142. (userContext.newProducedItem = theNewItem, isWeb()
  143. && $("#collect_" + f.symbol).html(renderUpgradeCollect(f)),
  144. isWeb() && $("#build_panel_action_" + f.id).html(renderBuildPanelAction(f)),
  145. isWeb() && $("#speed_button_" + f.id).hide())
  146. : q = theNewItem.symbol;
  147.  
  148. isWeb() ? (renderBuildingInventory(userContext.playerData),
  149. renderBuildingsOnScreen(userContext.playerData))
  150. : (f = null, f = null == q
  151. ? { symbol: c.symbol, status: "idle" }
  152. : { symbol: c.symbol, status: "idle", upgrade: q },
  153. iosSignal("finish_production", "update", f),
  154. isAndroid()
  155. && mobileCooldownDataSignal([{ mode: "building", symbol: c.symbol }]),
  156. refreshActiveBuildingPanel(),
  157. $("#building_tab_prod, .buildingupgradetree").fadeTo("slow", "1"));
  158.  
  159. uiEvent("do_finish_production");
  160. uiEvent("building_panel_" + userContext.activeBuildingPanel);
  161. a.produced_item && ("stacks_of_coins" == a.produced_item.symbol ? retrievePlayerData(!0, function (a) {
  162. userContext.playerData.quests = a.quests;
  163. reRenderQuestActionItems()
  164. }) : "stacks_of_coins" == a.produced_item.symbol && (userContext.playerData.stat.ftpe_decorative_blade = 1));
  165.  
  166. "Upgrade" == theNewItem.slot && (buildingUpgradePanel(c.symbol), userContext.playerData.stat[c.symbol + "_upgrades_finished"] = void 0 == userContext.playerData.stat[c.symbol + "_upgrades_finished"] ? 1 : userContext.playerData.stat[c.symbol +
  167. "_upgrades_finished"] + 1);
  168. updatePlayerInfo(userContext.playerData);
  169. updateAllStatus();
  170. } else {
  171.  
  172. // EXTENDER :: Modification ...
  173. console.debug("This building is still producing! Building: ", a.building);
  174. }
  175.  
  176. if (typeof callback == "function") {
  177. //console.debug("Calling callback... ");
  178. callback(a); // pass response
  179. }
  180. }
  181. }));
  182. };
  183. log("Finish production and call callback if any. Fix bug.", "initialize");
  184.  
  185. doProduction = function(c, a, b, d, g, callback) {
  186. userContext.lastFinish = null;
  187. null == b && (b = 1);
  188. doLog("doProduction: symbol=" + c + " producer=" + a + " quantity=" + b);
  189. var p = null, f = "", m = null, q = "", k = null, D = null;
  190. uiEvent("start_production");
  191. null == userContext.playerData.stat.num_shop_items_started && (userContext.playerData.stat.num_shop_items_started = 0);
  192. userContext.playerData.stat.num_shop_items_started += 1;
  193. for (var u = 0; u < userContext.recipeData.length; u++)
  194. if (console.log("DEBUG: n=" + userContext.recipeData[u].category + ", symbol: " +
  195. userContext.recipeData[u].output), g == userContext.recipeData[u].symbol || null == g && (userContext.recipeData[u].output == c || userContext.recipeData[u].output_loot == c) && userContext.recipeData[u].category == a) {
  196. p = userContext.recipeData[u];
  197. p.output == c ? (k = itemFromSymbol(c), q = k.full_name) : (p.output_loot == c && (m = c), q = p.name);
  198. D = u;
  199. components = userContext.recipeData[u].input.split(",");
  200. quantity_components = userContext.recipeData[u].input_quantity.split(",");
  201. var s = itemFromSymbol(userContext.recipeData[u].category);
  202. if (true ==
  203. userContext.recipeData[u].unlocked) {
  204. if (1 < userContext.recipeData[u].input.length)
  205. for (s = 0; s < components.length; s++) {
  206. var y = itemFromSymbol(components[s]), w = false;
  207. 0 == s && true == userContext.recipeData[u].evolution && (w = true);
  208. w = sumInventoryQuantity(y.symbol, w);
  209. if (parseInt(quantity_components[s]) * b > w) {
  210. "" == f && (f = "You need more of the following:<p/>");
  211. f += "<div>";
  212. if (4 <= userContext.playerData.character.level)
  213. switch (components[s]) {
  214. case "stone":
  215. case "iron":
  216. case "fur":
  217. case "ore":
  218. case "horse":
  219. case "riverways_fish_consumable":
  220. case "smallfolk":
  221. case "wood":
  222. case "cloth":
  223. case "grains":
  224. w =
  225. parseInt(quantity_components[s]) * b - w;
  226. if (cost_item = itemFromSymbol("pennyroyal")) var z = cost_item.price_perk_points * w;
  227. f += '<div id="basic_resource_' + components[s] + '">';
  228. f += itemMiniView(y, { extra_styles: "left:-70px", quantity_override: w });
  229. f += '<span style="position: relative; left: 250px; top: -88px" class="btnwrap btnmed btnprice" onclick="getBasicResource(\'' + components[s] + "'," + w + ',true);"><span class="btnedge"><a class="btngold">Get Now</a><em>for</em><strong>' + z + "</strong></span></span>";
  230. f += "</div>";
  231. break;
  232. default:
  233. f += itemMiniView(y);
  234. }
  235. f += "</div>";
  236. f += "<p>" + y.howto + "</p>";
  237. }
  238. }
  239. } else f = "You need <em>" + s.full_name + "</em> to produce that.";
  240. break;
  241. }
  242. if ("" != f) doAlert("Requirements: " + q, f), analytics.track("Production Blocked-Resources", { item_symbol: c }), analytics.wizardtrack("Production Blocked-Resources", { item_symbol: c });
  243. else if (p && hasMoney(p.craft_cost * b, function() { doProduction(c, a, b, d, g); })) {
  244. f = JSON.parse(JSON.stringify(userContext.playerData.inventory));
  245. u = [];
  246. p.output == c ? (k = itemFromSymbol(c), q = k.full_name) : (p.output_loot ==
  247. c && (m = c), q = p.name);
  248. components = p.input.split(",");
  249. quantity_components = p.input_quantity.split(",");
  250. s = itemFromSymbol(p.category);
  251. if (true == p.unlocked && (userContext.intCurrentRecipeIndex = D, 1 < p.input.length)) for (s = 0; s < components.length; s++) y = itemFromSymbol(components[s]), w = false, 0 == s && true == p.evolution && (w = true), depleteItems(y.symbol, parseInt(quantity_components[s]) * b, null, u, w);
  252. q = "";
  253. D = null;
  254. for (s = 0; s < u.length; s++)
  255. if (y = itemFromSymbol(u[s].symbol), u[s].full_name != y.full_name)
  256. D = JSON.parse(JSON.stringify(u[s])),
  257. q += "[" + u[s].full_name + "]";
  258. else if (itemHasSeals(u[s]) && (!u[s].preserve_attributes || false == u[s].preserve_attributes)) D = JSON.parse(JSON.stringify(u[s])), y = generateSealNameList(u[s]), q += "[" + u[s].full_name + " : " + y + "]";
  259.  
  260. // EXTENDER :: Modification
  261. if (true != d && null != D && !production.superiorMaterials) {
  262. return playerInventory = JSON.parse(JSON.stringify(f)), userContext.playerData.inventory = playerInventory, dialogAlert({
  263. style: "confirm",
  264. margin_top: 100,
  265. items: [D],
  266. button2: "Not Now",
  267. button2_action: function() { closeAlert(); },
  268. button1: "Confirm",
  269. button1_action: function() {
  270. closeAlert();
  271. return doProduction(c, a, b, true, g);
  272. },
  273. heading: "Confirm Superior Materials",
  274. text: "Producing this item now will consume superior versions of your materials: " + q + "<p/>Are you sure you want to contribute superior versions of materials to produce this item?"
  275. }), false;
  276. }
  277.  
  278. var I = buildingBySymbol(userContext.activeBuildingPanel);
  279. I.build_remaining = p.craft_duration * b;
  280. I.original_build_seconds = p.craft_duration * b;
  281. I.build_progress = 0;
  282. "" != p.output && (I.producing_archetype_id = itemFromSymbol(p.output).id);
  283. I.recipe_symbol = p.symbol;
  284. I.action_sub_id = b;
  285. f = renderBuildingConstruction(I);
  286. isWeb() && $("#bc_" + I.id).html(f);
  287. displayBuildingCooldown(I);
  288. "Upgrade" == itemFromId(I.producing_archetype_id).slot ? buildingUpgradePanel(userContext.activeBuildingPanel, true, false) : (buildingUpgradePanel(userContext.activeBuildingPanel, true, false, true), buildingTabProd(), isWeb() && $("#collect_" + I.symbol).html(renderUpgradeCollect(I)));
  289. p = "/play/set_production";
  290. p = (m ? p + ("?loot_symbol=" + m + "&producer_symbol=" + a) : k ? p + ("/" + c + "?producer_symbol=" + a) : p + ("?producer_symbol=" + a)) + ("&quantity=" + b);
  291. g && (p += "&recipe_symbol=" + g);
  292. //console.debug("Tampering with the url: ", p);
  293.  
  294. $.ajax({
  295. url: p,
  296. dataType: "JSON",
  297. success: function(a) {
  298. // EXTENDER :: Modification
  299. if (!a.num_shop_items_started && a.status) {
  300. //console.debug("Server responded with: ", a);
  301. return;
  302. }
  303.  
  304. userContext.prodProgressShow = null;
  305. userContext.playerData.stat.num_shop_items_started = a.num_shop_items_started;
  306. updateAllStatus();
  307. uiEvent("do_production");
  308. isWeb() || iosSignal("building", "cooldown", mobileCooldownData({ mode: "building", symbol: I.symbol, flag: "production_started" }));
  309.  
  310. // EXTENDER :: Modification
  311. if (typeof callback == "function") {
  312. callback();
  313. }
  314. }
  315. });
  316. }
  317. };
  318. log("Do production and call callback if any. Inject superior materials condition.", "initialize");
  319.  
  320. buildTimerUpdate = function(c, a, b) {
  321.  
  322. $("#timer-" + c).html(renderBuildTime(a));
  323. $("#timer-panel-" + c).html(renderBuildTime(a));
  324.  
  325. percent = 100 - 100 * (a / b);
  326. $("#progress-" + c).html('<span style="width:' + percent + '%;"></span>');
  327.  
  328. var d = buildingById(c);
  329. d.build_remaining = a;
  330. markup = renderBuildPanelAction(d);
  331.  
  332. //console.debug("Debugging building: " + d.symbol + ", " +
  333. //"build time remaining: " + a + " ms, " +
  334. //"original build seconds: " + b + " ms");
  335.  
  336. $("#speed_button_" + c).show();
  337. $("#build_panel_action_" + c).html(markup);
  338. $("#production_timer_" + c).html(renderBuildTime(d.build_remaining, true));
  339. $("#production_timer_upper_" +
  340. c).html(renderBuildTime(d.build_remaining));
  341. $("#production_progress_" + c).css({ width: percent + "%" });
  342. $("#duration_long_" + c).html(durationLong(buildTimerDescription(d), a, b));
  343. a--;
  344. userContext.doBuildId == c && (300 >= a ?
  345. ($("#speed_up_skip_block").hide(),
  346. $("#speed_up_skip_use").show()) :
  347. ($("#speed_up_skip_use").hide(),
  348. $("#speed_up_skip_block").show()),
  349. $(".speed_building_" + c).html() != renderSpeedUpButton(c) && $(".speed_building_" + c).html(renderSpeedUpButton(c)));
  350.  
  351. d.cooldown = a;
  352. d.original_cooldown_seconds = b;
  353. displayBuildingCooldown(d);
  354. 0 < a || (closeSpeedUp(), finalizeBuildingConstruction(d), clearBuildingTimer(d.symbol));
  355.  
  356. // EXTENDER :: Modification
  357. //production.speedUp(d, a);
  358. };
  359. log("Build custom timer update. Speed up and finish automatically, grab production item if any and execute.", "initialize");
  360.  
  361. doCollect = function(c) {
  362. lock_name = "collect-" + c;
  363. if (userLock(lock_name)) {
  364. var a = buildingByItemId(c);
  365. 0 < predictCollect(a) && (playSound("coins"), isWeb() && animatedCoins.init($("#collectbtn"), $("#silver"), [-10, -40], [-72, -44]));
  366. uiEvent("collect_" + buildingSymbolFromItemId(c), userContext.PlayerData);
  367. the_url = "/play/collect_building/" + c + "?client_seqnum=" + userContext.player_data_seqnum;
  368.  
  369. isWeb() || showSpinner();
  370. $.ajax({
  371. url: the_url,
  372. dataType: "JSON",
  373. success: function(b) {
  374. freeLock(lock_name);
  375. doLog("doCollect: building_id=" +
  376. c + " data.money=" + b.money);
  377. updateSilver(b.money);
  378. updateBaseTime(b.base_time);
  379. a.last_collected_at = b.last_collected_at;
  380. userContext.playerData.stat.buildings_collected = b.buildings_collected;
  381. userContext.playerData.stat.onboarding = b.onboarding;
  382. isWeb() || (iosSignal("building_collected"), hideSpinner());
  383. isWeb() && $("#collect_" + a.symbol).html(renderUpgradeCollect(a));
  384. buildingUpgradePanel(a.symbol);
  385. b = renderBuildingOwned(a);
  386. isWeb() && $("#bc_" + a.id).html(b);
  387. updateAllStatus();
  388. questListings();
  389.  
  390. // EXTENDER :: Modification
  391. closeModalLarge('modal_dialogs_top');
  392. }
  393. });
  394. }
  395. };
  396. log("Close dialog when silver is collected.", "initialize");
  397.  
  398. claimDaily = function() {
  399. showSpinner();
  400. $.ajax({
  401. url: "/play/advice_claim_daily",
  402. dataType: "JSON",
  403. success: function(c) {
  404. //console.debug("Logging response from the server: ", c);
  405. hideSpinner();
  406.  
  407. // EXTENDER :: Modification
  408. // bugfix: undefined silver and gold
  409. if (c.status && c.status == "OK") {
  410. return;
  411. }
  412.  
  413. $("#claimed_holder").html("<h5>Claimed</h5>");
  414. updateSilver(c.total_silver);
  415. updateGold(c.total_gold);
  416. $(".claimrewardchest").hide();
  417. $("#daily_reward_statview").html(itemStatViewFromSymbol(c.item, { produce: "Continue", produce_callback: "welcomeClaimed" }));
  418. $("#dailynewsbtn").removeClass("btnglow");
  419.  
  420. var a = buildingBySymbol("keep");
  421. userContext.playerData.stat.daily_streak_claimed = userContext.playerData.stat.daily_streak;
  422. a && $("#bc_" + a.id).html(renderBuildingOwned(a));
  423. isWeb() || iosSignal("daily_reward_claimed", null, c.item);
  424.  
  425. // EXTENDER :: Modification
  426. $(".welcomemodal").hide();
  427. //log("Daily reward claimed: " + c.item + ", gold: " + c.gold + ", silver: " + c.silver, "CLAIM_DAILY", true);
  428.  
  429. c.item && log({
  430. symbol: c.item,
  431. quantity: 1
  432. }, "DAILY");
  433.  
  434. c.gold && log({
  435. symbol: "gold_coins",
  436. quantity: c.gold
  437. }, "DAILY");
  438.  
  439. c.silver && log({
  440. symbol: "silver_coins",
  441. quantity: c.silver
  442. }, "DAILY");
  443. }
  444. });
  445.  
  446. return false;
  447. };
  448. log("Claim daily updates money only if claimed. Close when ready.", "initialize");
  449.  
  450. finishAll = function() {
  451. log("Checking buildings...");
  452.  
  453. var btn = $("#extender_finishBtn a");
  454. if (btn && btn.length > 0) btn.text("Finishing...");
  455.  
  456. for (var i = 0; i < userContext.buildingsData.length; i++) {
  457. var b = userContext.buildingsData[i];
  458. if(b.symbol === "keep"){
  459. continue;
  460. }
  461.  
  462. if (buildingFinished(b)) {
  463. log("Attempt to finish production on " + b.symbol);
  464. doFinishProduction(b.item_id, finishAll);
  465. return;
  466. }
  467. }
  468.  
  469. if (btn && btn.length > 0) btn.text("Finished");
  470. log("All buildings are now finished.");
  471. inform('Done');
  472. };
  473. log("Finish all buildings whole different way, make use of doFinish callback.", "initialize");
  474.  
  475. applySelectedUpgrade = function(c, a, callback) {
  476. lock_name = "upgrade-" + c.id;
  477. userContext.lastFinish = null;
  478.  
  479. var b;
  480.  
  481. if (0 < c.gold && null == a)
  482. doGoldUnlock(c.id, function() {
  483. applySelectedUpgrade(c, true, callback);
  484. });
  485. else if (hasMoney(c.silver, function() {
  486. applySelectedUpgrade(c, a, c.silver);
  487. }) && userLock(lock_name)) {
  488. var d = buildingUpgradeResourceCheck(c.building_id, c.id);
  489. if (isWeb()) {
  490. if (null != d.markup && "" != d.markup) {
  491. doAlert("Resources Required", "You need additional resources to construct that upgrade:<p/>" + d.markup);
  492. return false;
  493. }
  494. } else if (null !=
  495. d.strMissingComponentText) {
  496. if (isAndroid()) {
  497. iosSignal("building", "upgrade_fail", d);
  498. return false;
  499. }
  500. return d;
  501. }
  502. b = d.item;
  503. playSound("build");
  504. var g = buildingById(c.building_id);
  505. itemFromSymbol(g.symbol);
  506. d = extractItemBySymbol(userContext.playerData.inventory, g.symbol).upgrade_level - 1;
  507. 0 > d && (d = 0);
  508. userContext.buildIndex++;
  509. g.build_progress = 0;
  510. g.producing_archetype_id = b.id;
  511. $.ajax({
  512. url: "/play/apply_upgrade/" + c.id,
  513. dataType: "JSON",
  514. success: function(result) {
  515. freeLock(lock_name);
  516. if (result.resource_list)
  517. for (var i = 0; i < result.resource_list.length; i++) {
  518. var m =
  519. extractItemBySymbol(playerInventory, result.resource_list[i]);
  520. m && (m.quantity -= parseInt(result.resource_quantities[i]));
  521. }
  522. updateSilver(result.money);
  523. updateBaseTime(result.base_time);
  524. userContext.playerData.stat.onboarding = result.onboarding;
  525. userContext.playerData.stat.building_upgrades_added = result.building_upgrades_added;
  526. g.build_remaining = result.build_remaining;
  527. g.original_build_seconds = result.original_build_seconds;
  528. displayBuildingCooldown(g);
  529. isWeb() && buildingUpgradePanel(g.symbol);
  530. result = renderBuildingConstruction(g);
  531. $("#bc_" + g.id).html(result);
  532. uiEvent("add_" +
  533. userContext.activeBuildingPanel, userContext.PlayerData);
  534. selectedUpgrade = extractItemBySymbol(playerInventory, b.symbol);
  535. q_upgrade = 1;
  536. selectedUpgrade && (q_upgrade = selectedUpgrade.quantity + 1);
  537. $("#addbtn_container").html(addButtonUpgrade(b, false, q_upgrade));
  538. isWeb() ? selectUpgrade(userContext.activeUpgrade) : iosSignal("building", "cooldown", mobileCooldownData({ mode: "building", symbol: g.symbol, flag: "production_started" }));
  539. questListings();
  540. analytics.track("Building Apply-Upgrade", {
  541. building: userContext.activeBuildingPanel,
  542. upgrade: itemData[itemById[c.id]].symbol,
  543. cost: itemData[itemById[c.id]].cost
  544. });
  545. analytics.wizardtrack("Building Apply-Upgrade", { building: userContext.activeBuildingPanel, upgrade: itemData[itemById[c.id]].symbol, cost: itemData[itemById[c.id]].cost }); // EXTENDER :: Modification
  546.  
  547. // EXTENDER :: Modification
  548. if (typeof callback == "function") {
  549. callback();
  550. }
  551. }
  552. });
  553. }
  554.  
  555. return false;
  556. };
  557. log("Do upgrade and call callback function.", "initialize");
  558.  
  559. speedBuild = function speedBuild(c, a, callback) {
  560. $("#modal_dialogs_top2").hide();
  561. doLog("speedBuild: speed_item=" + c + " item_id=" + a);
  562. $.ajax({
  563. url: "/play/build_now/" + a + "?complete=" + c,
  564. dataType: "JSON",
  565. success: function(b) {
  566. //console.debug("Logging server response for speedBuild: ", b);
  567.  
  568. userContext.playerData.user.money = b.user.money;
  569. userContext.playerData.stat.onboarding = b.stat.onboarding;
  570. userContext.playerData.chapter = b.chapter;
  571. var d = buildingById(a, b.building);
  572. doLog("speedBuild: speed_item:");
  573. doLog(b.speed_item);
  574. b.speed_item && insertInventoryFromItem(userContext.playerData.inventory,
  575. b.speed_item);
  576. insertInventoryFromItem(userContext.playerData.inventory, b.produced_item);
  577. logLastItem("speedBuild:A");
  578. userContext.buildingsData && (userContext.playerData.buildings = userContext.buildingsData);
  579. playerInventory && (userContext.playerData.inventory = playerInventory);
  580. userContext.chapterData = b.chapter;
  581. d && (analytics.track("SpeedUp-Building", { building: d.symbol, speed_item: c }), analytics.wizardtrack("SpeedUp-Building", { building: d.symbol, speed_item: c }));
  582. userContext.buildIndex++;
  583. logLastItem("speedBuild:B");
  584. finalizeBuildingConstruction(d);
  585. isItemBuildingUpgrade(d) || null == d.producing_archetype_id && null == d.recipe_symbol ? (renderBuildingInventory(userContext.playerData, buildingUpgradePanel, userContext.activeBuildingPanel, true), isWeb() || iosSignal("building", "cooldown", mobileCooldownData({ mode: "building", symbol: d.symbol, flag: "speed_up" }))) : (userContext.craftingItemFinished = true, renderBuildingInventory(userContext.playerData, buildingUpgradePanelProd, userContext.activeBuildingPanel, true), $("#collect_" + d.symbol).html(renderUpgradeCollect(d)),
  586. $("#build_panel_action_" + d.id).html(renderBuildPanelAction(d)), $("#speed_button_" + d.id).hide());
  587. renderBuildingsOnScreen(userContext.playerData);
  588. d && uiEvent("building_panel_" + d.symbol);
  589.  
  590. // EXTENDER :: Modification
  591. if (typeof (callback) == "function") {
  592. callback();
  593. }
  594. }
  595. });
  596. };
  597. log("Speed build is what actually calls the callback (not doInstantSpeedUp).", "initialize");
  598.  
  599. doAdventure = function doAdventure(c, a, b, callback) {
  600. //console.debug("First passed parameter: ", c);
  601. // EXTENDER : Modfification
  602. if (userContext.setSwornSword && userContext.setSwornSword.damage && userContext.setSwornSword.damage == 4) {
  603. warn("Sworn sword has 4 wounds. Adventure will not continue.");
  604. return;
  605. }
  606.  
  607. //console.debug("Logging parameters of doAdventure: ", c, a, b);
  608.  
  609. if (void 0 != userContext.setSwornSword && void 0 != userContext.setSwornSword.batch_type && 0 != userContext.setSwornSword.batch_type)
  610. return 1 == userContext.setSwornSword.batch_type && (!1 == b && prepareAdvPartyTimeout(), $.ajax({
  611. url: "/play/batch_set_sworn_sword_target?batch_type=1&ss_id=" + userContext.setSwornSword.id + "&batch_action=" + a + "&target_symbol=" + c,
  612. dataType: "JSON",
  613. success: function(a) {
  614. questClose();
  615. showAdvPartyResponse(a);
  616. uiEvent("ss_adventure_party");
  617. return !0;
  618. },
  619. error: function(b) {
  620. 400 ==
  621. b.status ? advPartyFail() : 409 == b.status ? setTimeout(function() { doAdventure(c, a, !0); }, 5E3) : spinTimeout();
  622. }
  623. })), !1;
  624. $.ajaxQueue({
  625. url: "/play/adventure/" + userContext.setSwornSword.id + "?action_name=" + a + "&symbol=" + c,
  626. dataType: "JSON",
  627. success: function(b) {
  628. //analytics.track("Adventure Start", { adventure_region: b.location, adventure_action: a, adventure_swornsword_id: userContext.setSwornSword.id, adventure_swornsword_level: userContext.setSwornSword.ugprade_level });
  629. //analytics.wizardtrack("Adventure Start", {
  630. // adventure_region: b.location,
  631. // adventure_action: a,
  632. // adventure_swornsword_id: userContext.setSwornSword.id,
  633. // adventure_swornsword_level: userContext.setSwornSword.ugprade_level
  634. //});
  635.  
  636. if (b.symbol) {
  637. adventureProgress(userContext.setSwornSword.id, b);
  638. uiEvent("do_adventure");
  639. "1" == userContext.playerData.stat.onboarding_ftue && uiTelemetry("ss_adventure");
  640. }
  641.  
  642. // EXTENDER :: Modification
  643. if(b.reward_item != void 0 && b.duration_remaining === 0){
  644. //console.debug("Logging reward: ", b);
  645.  
  646. log({
  647. symbol: b.reward_item,
  648. quantity: 1
  649. }, "ADVENTURE");
  650.  
  651. b.reward_silver && log({
  652. symbol: "silver_coins",
  653. quantity: b.reward_silver
  654. }, "ADVENTURE");
  655.  
  656. b.prestige_awarded && log({
  657. symbol: "prestige_item",
  658. quantity: b.prestige_awarded
  659. }, "ADVENTURE");
  660.  
  661. // TODO: Decide fate of xp logging
  662. //b.reward_upgrade_points && log({
  663. // symbol: "XP",
  664. // quantity: b.reward_upgrade_points
  665. //}, "ADVENTURE");
  666. }
  667.  
  668. if (typeof callback == "function") {
  669. userContext.setSwornSword.not_on_adventure = !b.symbol;
  670.  
  671. callback(!b.symbol);
  672. }
  673. }
  674. });
  675. };
  676. log("Don't do adventure if sworn sword is about to die. Call callback when ready (bruting).", "initialize");
  677.  
  678. playSound = function playSound(a, d) {
  679. if (!1 != doSound())
  680. if ($.browser.msie || doLog("playSound [1]: " + a), !1 == soundEnabled) $.browser.msie || doLog("playSound [1]: sound disabled");
  681. else {
  682. void 0 == d && (d = 0);
  683. musicMuted = userContext.mute_music;
  684. soundMuted = userContext.mute_sound;
  685. try {
  686. if (-1 != a.indexOf("voice-") && ($.browser.msie || doLog("play voiceover"), soundMapChannel[a] = "voice"), theUrl = soundMap[a], void 0 == soundMapChannel[a] && (soundMapChannel[a] = "channel1"), isWeb()) {
  687. if ($.browser.msie || doLog("playSound[2]: " +
  688. a + " soundReady=" + soundReady), !0 == soundReady) {
  689. $.browser.msie || doLog("soundReady: " + soundMapChannel[a]);
  690. play_it = !0;
  691. if ("music" == soundMapChannel[a]) {
  692. if (0 == musicVolume || !0 == musicMuted) play_it = !1;
  693. vol = musicVolume;
  694. $.browser.msie || doLog("MUSIC vol=" + vol);
  695. } else {
  696. if (0 == soundVolume || !0 == soundMuted) play_it = !1;
  697. vol = soundVolume;
  698. $.browser.msie || doLog("SOUND vol=" + vol);
  699. }
  700. if ("channel1" == soundMapChannel[a] || "channel2" == soundMapChannel[a] || "channel3" == soundMapChannel[a] || "channel4" == soundMapChannel[a] ||
  701. "channel5" == soundMapChannel[a] || "music" == soundMapChannel[a] || "voice" == soundMapChannel[a] || "voice2" == soundMapChannel[a])
  702. if (!0 == soundChannel[soundMapChannel[a]]) $.browser.msie || doLog("Sound channel busy: " + soundMapChannel[a] + " playing=" + soundActive[a]), "music" == soundMapChannel[a] && currentMusic != a && (doLog("switch to new music"), soundCrossFade("music", vol, function() { playSound(a, d); }));
  703. else if (sound_url = assetUrl() + theUrl, $.browser.msie || doLog("SOUND: play_it=" + play_it), !0 != play_it)
  704. $.browser.msie ||
  705. doLog("SOUND: returning");
  706. else {
  707. "music" == soundMapChannel[a] && (doLog("currentMusic = " + currentMusic), currentMusic = a);
  708. $.browser.msie || doLog("SOUND: createSound");
  709. soundObject = soundManager.createSound({
  710. id: soundMapChannel[a],
  711. url: theUrl,
  712. volume: vol,
  713. onfinish: function() {
  714. $.browser.msie || doLog("soundObject.onfinish: id=" + a + " soundMapChannel=" + soundMapChannel[a]);
  715. soundChannel[soundMapChannel[a]] = !1;
  716. soundManager.destroySound(soundMapChannel[a]);
  717. "music" == soundMapChannel[a] && (0 < musicVolume && !0 !=
  718. userContext.mute_music) && playSound(a);
  719. }
  720. });
  721. if (null == soundObject || void 0 == soundObject) $.browser.msie || doLog("soundObject: invalid");
  722. !0 == play_it && (soundChannel[soundMapChannel[a]] = !0, soundActive[soundMapChannel[a]] = sound_url, soundManager.getSoundById(soundMapChannel[a]).setVolume(vol), 0 < d ? setTimeout(soundObject.play, d) : ($.browser.msie || doLog("soundObject.play: [" + soundMapChannel[a] + "] " + soundActive[soundMapChannel[a]]), soundObject.play()));
  723. }
  724. else
  725. 0 < vol && ($.browser.msie || doLog("playing [3]: [" +
  726. soundMapChannel[a] + "] vol=" + vol), soundManager.getSoundById(soundMapChannel[a]).setVolume(vol), soundManager.getSoundById(soundMapChannel[a]).volume = vol, soundManager.play(a));
  727. }
  728. } else iosSignal("playsound", soundMapChannel[a] + ":" + soundMap[a].substring(soundMap[a].lastIndexOf("/") + 1) + ":" + d);
  729. } catch (e) {
  730. $.browser.msie || doLog("playSound exception: " + e);
  731. }
  732. }
  733. };
  734. log("Cleared playSound from console logging.", "initialize");
  735.  
  736. submitWorldEventAction = function submitWorldEventAction(c, a, b) {
  737. console.debug("Logging parameters, " +
  738. "sworn sword id: " + c + ", order: " + a + ", weakness attack? " + b);
  739.  
  740. showSpinner();
  741. data = { sworn_sword_id: c, order: a };
  742. !0 == b && (data.weakness_attack = b);
  743. $.ajax({
  744. url: "/play/world_event_attack",
  745. data: data,
  746. complete: function() {
  747. hideSpinner();
  748. },
  749. success: function(a) {
  750.  
  751. hideSpinner();
  752. a.error && doAlert("Error Sending Swornsword", formatWorldEventError(a.error, a.error_code));
  753. a.swornsword && (insertInventoryFromItem(userContext.playerData.inventory, a.swornsword), doItemCooldown(a.swornsword));
  754.  
  755. // EXTENDER :: Modification
  756. // full loop implemented
  757. worldEvent.afterSubmit(a, c);
  758.  
  759. a.challenge && updateWorldEventChallenge(a.challenge);
  760. isWeb() && ($(".command_pts").contents().first()[0].textContent = userContext.playerData.stat.current_command + "/" + userContext.playerData.stat.command + " Command Points");
  761. !0 == a.show_outmaneuver_alert && dialogAlert({ style: "alert", text: "The order you just sent is guaranteed to critically hit and will have a bonus chance to find a weakness.", heading: "", button1: "Okay" });
  762. }
  763. });
  764. };
  765. log("Analyzing world event action.", "initialize");
  766.  
  767. getWorldEventAttackResults = function getWorldEventAttackResults(c, a) {
  768. console.debug("Logging parameters, " +
  769. "sworn sword id: " + c + ", refresh? " + a);
  770.  
  771. showSpinner();
  772. $.ajax({
  773. url: "/play/world_event_attack_results",
  774. data: { sworn_sword_id: c },
  775. complete: function() {
  776. hideSpinner();
  777. },
  778. success: function(b) {
  779. hideSpinner();
  780.  
  781. // EXTENDER :: Modification
  782. // full loop implemented
  783. worldEvent.afterGet(b, c);
  784.  
  785. b.error
  786. ? doAlert("Error Getting Results", formatWorldEventError(b.error, b.error_code))
  787. : (b.swornsword && (insertInventoryFromItem(userContext.playerData.inventory, b.swornsword), doItemCooldown(b.swornsword)),
  788. b.character && (userContext.playerData.stat.level_progress = b.xp_after, userContext.playerData.character = b.character,
  789. infoBar(userContext.playerData, userContext.playerData.inventory)), isWeb() ? (b = _.template('<div class="modalbg"></div><div class="contentframe1" style="top:44px; z-index:22;"><div class="contentframe2"><div class="contentframe3"><div class="contentframe4"><span class="corner tl"></span><span class="corner tr"></span><a class="closebtn" onclick="closeWorldEventAttackResults();">close</a> <h2 class="alertheader"><%= translateString(\'we_order_completed\') %></h2> <div class="alertcontents"> <div class="alertbox"> <div class="alertboxinner"> <div class="weinforow"> <%= itemMiniView(data.swornsword) %> <% if(data.wounds > 0) { %> <div class="orderwound">Wounded</div> <% } %> <div class="bossopttop"> <div class="bossoptbtn"> <span class="btnwrap btnlg"><span class="btnedge"><a class="btnbrown"> \x3c!-- Selected button is brown --\x3e <span><img src="<%= assetUrl() %>/images/content/talent/<%=data.action%>.png" /></span> <strong><%= translateString(data.action) %></strong> <em><%= data.label %></em> </a></span></span> <div class="challengebar"> <div class="challengeicon"></div> <div class="challenge-outer challengelose"> <div style="width:<%= data.cr %>%;" class="challenge-yours"></div> <div style="width:<%=100 - data.cr%>%;" class="challenge-target"></div> </div> </div> </div> </div> </div> <% if(data.outcome > 0) { %> <h3 class="challengerewardhead-success">Success!</h3> <% } else { %> <h3 class="challengerewardhead-lose">Failure!</h3> <% } %> <div class="weinforow orderresult"> <p><%= data.damage %> Damage Dealt</p> <% if(data.xp_after > data.xp_before) { %> <%= xpReward(data.xp_before, data.xp_after) %> <% } %> <div class="weinforow"> <div class="weinfo"><%= data.text %></div> </div> </div> </div> </div> </div> <div class="alertbtm"> <% if(data.can_repeat) { %> <span class="btnwrap btnlg" onclick="submitWorldEventAction(<%=data.swornsword.id%>,\'<%=data.action%>\');closeWorldEventAttackResults();"><span class="btnedge"><a class="btngold">Repeat</a></span></span> <% } %> <span class="btnwrap btnlg" onclick="closeWorldEventAttackResults();"><span class="btnedge"><a class="btngold">Close</a></span></span> </div></div></div></div></div>',
  790. { data: b }), $(".weordercomplete").html(b).show()) : iosSignal("we", "viewSSResult", b), a && refreshWorldEventChallenge());
  791. }
  792. });
  793. };
  794. log("Logging information from world event action.", "initialize");
  795.  
  796. var originalCharCharacterTab = window.charCharacterTab;
  797. window.charCharacterTab = function() {
  798. // hook before call
  799. var ret = originalCharCharacterTab.apply(this, arguments);
  800. afterCharCharacterTab(); // hook after call
  801. return ret;
  802. };
  803.  
  804. function afterCharCharacterTab(){
  805. $("#character_sheet_portrait").after(formatStats(playerData.got_battle, playerData.got_trade, playerData.got_intrigue, playerData.level));
  806. }
  807.  
  808. inventoryDisplayStatsWithTab = function inventoryDisplayStatsWithTab(c, symbol) {
  809. // EXTENDER :: Modification, useless junk,
  810. // use this function as it appears to work better
  811. c = extractItemById(playerInventory, c);
  812. if (c && c.id == 0 && typeof symbol != "undefined") {
  813. statViewFromMini(symbol);
  814. return;
  815. }
  816.  
  817. "unit" == c.slot
  818. ? inventorySubTab("companion")
  819. : inventorySubTab(c.slot);
  820.  
  821. inventoryDisplayStats(void 0, void 0, c, void 0, !0);
  822. };
  823. log("Use alternative function for item popup if the initial fails.", "initialize");
  824.  
  825. inventoryTab = function inventoryTab(b) {
  826. gLastInventoryTab = b;
  827. $("#statview_container_right").html("");
  828. $("#statview_container").html("");
  829. $(".characterview").hide();
  830. $("." + b + "view").show();
  831. $("#swornswordstab_inner").removeClass("active");
  832. $("#foodtab_inner").removeClass("active");
  833. $("#charactertab_inner").removeClass("active");
  834. $("#boonstab_inner").removeClass("active");
  835. $("#resourcestab_inner").removeClass("active");
  836. $("#sealtab_inner").removeClass("active");
  837. $("#gearinvtab_inner").removeClass("active");
  838. $("#companionsinvtab_inner").removeClass("active");
  839.  
  840. //EXTENDER :: Modification
  841. $("#permanentitemstab_inner").removeClass("active");
  842.  
  843. $("#inventorybtm").removeClass("character");
  844. $("#weapontab").hide();
  845. $("#armortab").hide();
  846. $("#companiontab").hide();
  847. $("#swordcompaniontab").hide();
  848. $("#inventory-listing").hide();
  849. var a = playerInventory;
  850. $("#character_inventory_modal_filter_container").hide();
  851. _.contains([
  852. "boons",
  853. "seal",
  854. "gearinv",
  855. "companionsinv"
  856. ], b) && ($("#character_inventory_modal_filter_container").show(), a = inventoryFilter.runFilterOnList(playerInventory));
  857. var c = [], d = void 0;
  858. "character" == b ? ($("#inventorybtm").addClass("character"), $("#weapontab").show(),
  859. $("#armortab").show(), $("#companiontab").show(), equipContextPrefix = equipContextTarget = "character", equipContextPosition = "right", $("#inventory_toolbar_Weapon").show()) : "swornswords" == b ? ($("#inventorybtm").addClass("character"), first_sworn = extractFirstSwornSword(a), inventoryDisplayStatsRight(void 0, void 0, first_sworn), $("#weapontab").show(), $("#armortab").show(), $("#swordcompaniontab").show(), equipContextPrefix = "item", $("#inventory_toolbar").show(), d = "Sworn Sword", c.push(d)) : "boons" == b ? ($("#character_inventory_modal_filter_container").show(),
  860. first_boon = extractFirstBoon(a), inventoryDisplayStatsRight(void 0, void 0, first_boon), $("#inventory_toolbar").hide(), d = "Boon", c.push(d)) : "food" == b ? (first_consumable = extractFirstConsumable(a), inventoryDisplayStatsRight(void 0, void 0, first_consumable), $("#inventory_toolbar").hide(), d = "Consumable", c.push(d)) : "seal" == b ? ($("#character_inventory_modal_filter_container").show(), first_seal = extractFirstSeal(a), inventoryDisplayStatsRight(void 0, void 0, first_seal), $("#inventory_toolbar").hide(), d = "Seal", c.push(d)) :
  861. "resources" == b ? (first_resource = extractFirstTreasure(a), inventoryDisplayStatsRight(void 0, void 0, first_resource), $("#inventory_toolbar").hide(), d = "Treasure", c.push(d)) : "gearinv" == b ? ($("#character_inventory_modal_filter_container").show(), first_gearinv = extractFirstGear(a), inventoryDisplayStatsRight(void 0, void 0, first_gearinv), $("#inventory_toolbar").hide(), d = "Weapon, Armor", c.push("Weapon"), c.push("Armor")) : "companionsinv" == b && ($("#character_inventory_modal_filter_container").show(), first_companionsinv =
  862. extractFirstCompanion(a), inventoryDisplayStatsRight(void 0, void 0, first_companionsinv), $("#inventory_toolbar").hide(), d = "Companion, Unit", c.push("Companion"), c.push("Unit"));
  863.  
  864. // EXTENDER :: Modification
  865. if ("permanentitems" == b) {
  866. d = "pass please";
  867. }
  868.  
  869. doLog("inventoryTab: category=" + b + " listing_slot=" + d);
  870. if (void 0 != d) {
  871. initPagination(b, 6);
  872. for (var g = !1, k = [], f = "", p = 0; p < a.length; p++){
  873. // EXTENDER :: Modification
  874. if (b === "permanentitems" && a[p].permanent_item) {
  875. k.push(playerInventory[p]);
  876. continue;
  877. }
  878.  
  879. for (var q = 0; q < c.length; q++){
  880. a[p].slot == c[q] && k.push(a[p]);
  881. }
  882. }
  883. 0 == k.length && (g = !0);
  884. f += "<div id='mv_container'></div>";
  885. "character" == b ? $("#inventory-listing").html(f).hide() : !0 == g ? "swornswords" == b ? $("#inventory-listing").html('You have no sworn swords. Visit the <a class="shop_link" href="#" onclick="return shopModal();">shop</a> to hire one.').show() :
  886. "food" == b ? $("#inventory-listing").html('You have no Food. Visit the <a class="shop_link" href="#" onclick="return shopModal();">shop</a> to purchase some.').show() : "boons" == b ? $("#inventory-listing").html('You have no Boons. Visit the <a class="shop_link" href="#" onclick="return shopModal();">shop</a> to purchase one.').show() : "seal" == b ? $("#inventory-listing").html("You have no Seals. Earn seals from PtP.").show() : "gearinv" == b ? $("#inventory-listing").html('You have no Gear. Visit the <a class="shop_link" href="#" onclick="return shopModal();">shop</a> to purchase some.').show() :
  887. "companionsinv" == b && $("#inventory-listing").html('You have no Companions. Visit the <a class="shop_link" href="#" onclick="return shopModal();">shop</a> to purchase some.').show() : $("#inventory-listing").html(f).show();
  888. g || ($.each(k, function (a, c) {
  889. addPageItem(b);
  890. itemMiniView(c, {
  891. callback: inventoryDisplayStatsRight,
  892. extra_styles: pageStyle(b),
  893. extra_class: pageClass(b)
  894. }, "#mv_container")
  895. }), $("#mv_container").append(bookPageNumbers(b)))
  896. }
  897. $("#" + b + "tab_inner").addClass("active");
  898. void 0 != d && pageBegin(b)
  899. };
  900. log("Render permanent items.", "initialize");
  901.  
  902. var originalInventoryModal = window.inventoryModal;
  903. window.inventoryModal = function() {
  904. // hook before call
  905. var ret = originalInventoryModal.apply(this, arguments);
  906. afterInventoryModal(); // hook after call
  907. return ret;
  908. };
  909.  
  910. function afterInventoryModal(){
  911.  
  912. // EXTENDER :: Modification, inject permanent tab
  913. var permanentsTab =
  914. '<span onclick="return clickInventoryTab(\'permanentitems\');" id="permanentitemstab" class="inventorytabwrap">' +
  915. '<span class="inventorytabedge">' +
  916. '<a id="permanentitemstab_inner" class="inventorytab">' +
  917. '<span></span>' +
  918. 'Permanent' +
  919. '<em></em>' +
  920. '</a></span></span>';
  921.  
  922. $("#companionsinvtab").after(permanentsTab);
  923. }
  924.  
  925. shopModal = function shopModal(b, a) {
  926. userContext.playerData.user.new_items = 0;
  927. updateAllStatus();
  928. doToolbar("shop");
  929. closeAlert();
  930. closeUpgradePanel();
  931. clearModalDialogs("modal_dialogs_top");
  932. doLog("shopModal");
  933. uiTelemetry("shop");
  934.  
  935. // EXTENDER :: Modification, default tab: troopsequip
  936. void 0 == a && (a = "troopsequip");
  937.  
  938. if (void 0 == b) {
  939. var c;
  940. c = "" + (shopModalHead() + shopModalFoot());
  941. isWeb() && displayModalDialog(c, void 0, void 0, "min-height: 692px; top: 0px; margin-top: 40px");
  942. showSpinner();
  943. $.ajaxQueue({
  944. url: "/play/shop/?view_direct=true",
  945. dataType: "JSON",
  946. complete: hideSpinner,
  947. success: function (b) {
  948. shopModal(b,
  949. a);
  950. }
  951. });
  952.  
  953. // EXTENDER :: Enwrap else - readability fixes bugs
  954. } else {
  955. hideSpinner(),
  956. updateSilver(b.money),
  957. updateGold(b.perk_points),
  958. c = sortShopItems(b.shop),
  959. userContext.filteredShopData = distrubuteShopItemsToFilteredLists(c),
  960.  
  961. // EXTENDER :: Modification, extender filter by default
  962. userContext.shopFilterIndex = userContext.shopFilterIndex || 4,
  963. console.debug("Sorting shop and putting it in the filteredShopData.");
  964.  
  965. // EXTENDER :: Load extender filter with filtered data
  966. userContext.filteredShopData[shopFilters.indexOf("extender")]
  967. = sortShop(userContext.filteredShopData[0].slice(0));
  968.  
  969. userContext.shopData = userContext.filteredShopData[userContext.shopFilterIndex],
  970. baseShopTime = parseInt((new Date).getTime() / 1E3),
  971. b.cost_refresh_shop = 2, b.userContext = userContext,
  972. b.open_tab = a, b.featuredTabLabel && (phraseText.featured_tab_label = b.featuredTabLabel),
  973. b.dealsData ? (b.overrideDealsData = [], b.dealsData.map(function (a) {
  974. b.overrideDealsData.push(a)
  975. }), b.dealsData = [], b.overrideDealsData.map(function (a) {
  976. b.dealsData.push(a.symbol);
  977. a.price_perk_points && (itemFromSymbol(a.symbol).price_perk_points = a.price_perk_points)
  978. }), userContext.defaultDeals_id = itemFromSymbol(b.dealsData[0]).id, userContext.defaultDeals_symbol = b.dealsData[0]) : b.dealsData = shopSetDealData("deals"), b.featuredItemPack ? (b.overridefeaturedItemPack = {}, b.overridefeaturedItemPack.symbol = b.featuredItemPack.symbol, b.overridefeaturedItemPack.price_perk_points =
  979. b.featuredItemPack.price_perk_points, b.featuredItemPack = b.overridefeaturedItemPack.symbol, b.overridefeaturedItemPack.price_perk_points && (itemFromSymbol(b.overridefeaturedItemPack.symbol).price_perk_points = b.overridefeaturedItemPack.price_perk_points), userContext.defaultFeaturedPack_id = itemFromSymbol(b.featuredItemPack).id, userContext.defaultFeaturedPack_symbol = b.featuredItemPack) : b.featuredItemPack = shopSetDealData("featured_item_pack"), b.featuredItem ? (b.overridefeaturedItem = [], b.featuredItem.map(function (a) {
  980. b.overridefeaturedItem.push(a)
  981. }),
  982. b.featuredItem = [], b.overridefeaturedItem.map(function (a) {
  983. b.featuredItem.push(a.symbol);
  984. a.price_perk_points && (itemFromSymbol(a.symbol).price_perk_points = a.price_perk_points)
  985. })) : b.featuredItem = shopSetDealData("featured_items"), userContext.shopMetadata = b, drawShopModal(userContext.shopMetadata)
  986. }
  987. };
  988. log("Sort shop.", "initialize");
  989.  
  990. function hasGold(b, a, c) {
  991. // EXTENDER :: Modification, the short answer is no
  992. if (b > 0 && extender.options.neverSpendGold) {
  993. return false;
  994. }
  995.  
  996. if (0 < b) {
  997. void 0 == c && (c = !1);
  998. doLog("hasGold: cost=" + b + " [player perk_points=" + userContext.playerData.user.perk_points + "]");
  999. if (b > userContext.playerData.user.perk_points) return currencyModal("gold"), iosSignal("purchase", "need_gold"), !1;
  1000. if (2 == (userContext.playerData.user.options_mask & 2) && !1 == c)
  1001. return dialogAlert({
  1002. style: "confirm",
  1003. button1: "Okay",
  1004. button1_action: function() {
  1005. closeAlert();
  1006. a();
  1007. },
  1008. button2: "Cancel",
  1009. heading: jsTranslate("Spend %{val} Gold", "val", numberWithDelimiter(b)),
  1010. text: jsTranslate("Please confirm that you wish to spend %{val} gold.",
  1011. "val", numberWithDelimiter(b)),
  1012. keep_previous: !0
  1013. }), !1;
  1014. }
  1015. return !0;
  1016. };
  1017. log("Never spend gold option.", "initialize");
  1018.  
  1019. function pvpLaunch(callback) {
  1020. json = { pvp: {} };
  1021. json.pvp.target_id = pvpForm.target_id;
  1022. json.pvp.sworn_sword_id = userContext.setSwornSword.id;
  1023. json.pvp.pvp_action_symbol = userContext.currentActionLabel;
  1024. json.pvp.region_symbol = fealtySymbol[pvpForm.target_faction_id];
  1025. pvpForm.sub_region_index = Math.floor(3 * Math.random());
  1026. var b = pvpForm.target_faction_id;
  1027. void 0 == b && (b = userContext.playerData.character.faction_id);
  1028. json.pvp.sub_region_symbol = fealtySubRegions[b][pvpForm.sub_region_index].symbol;
  1029. json.pvp.attack_value = userContext.currentQuest.action_type[userContext.currentActionLabel].attacker_strength;
  1030. json.pvp.defense_value = userContext.currentQuest.action_type[userContext.currentActionLabel].defender_strength;
  1031. false || (showSpinner(),
  1032. $.ajax({
  1033. type: "get",
  1034. url: "/pvps/create",
  1035. data: json,
  1036. dataType: "JSON",
  1037. complete: hideSpinner,
  1038. success: function(a) {
  1039. void 0 == a.error ?
  1040. (pvpForm = {},
  1041. userContext.pvp = a,
  1042. pvpRenderProgress(a),
  1043. insertInventoryFromItem(playerInventory, a.attacker.sworn_sword),
  1044. analytics.track("PvP Start", { pvp_context: "attack", pvp_action: json.pvp.pvp_action_symbol }),
  1045. analytics.wizardtrack("PvP Start", {
  1046. pvp_context: "attack",
  1047. pvp_action: json.pvp.pvp_action_symbol
  1048. }))
  1049. : handleSwornSwordError(a.error);
  1050.  
  1051. // EXTENDER :: Modification, call callback
  1052. // parameter indicates successfull sending
  1053. if (typeof callback == "function") {
  1054. if(a.error && a.error === "too_many_attacks") {
  1055. //inform("Too MANY ATTACKS! StAHP STAAAHP!");
  1056. pvpFormStore = null;
  1057. return;
  1058. }
  1059.  
  1060. callback(!a.error);
  1061. }
  1062. }
  1063. }));
  1064. }
  1065. log("Player vs player enhanced. Client pvpBan, hilarious.", "initialize");
  1066.  
  1067. function questSubmit(b, a, c, d, g, k, f) {
  1068. doLog("questSubmit: stage=" + a + " choice=" + c);
  1069. uiEvent("quest_submit_" + b + "_" + a + "_choice_" + c, userContext.playerData);
  1070. userContext.postQuestEvent = "quest_post_" + b + "_" + a + "_choice_" + c;
  1071. userContext.playerData;
  1072. userContext.questActionChoice = c;
  1073. b = void 0 != f ? "/play/quest?quest_id=" + f + "&stage=" + a + "&choice=" + c + "&chosen=" + escape(d) : "/play/quest?quest_symbol=" + b + "&stage=" + a + "&choice=" + c + "&chosen=" + escape(d);
  1074. void 0 != g ? (b = isWeb() ? b + ("&chat=" + escape($("#" + g).val())) : b + ("&chat=" + escape(g)),
  1075. userContext.hideWarParty = !0) : playSound("page-turn");
  1076. void 0 != k && (userContext.dialogIndex++, userContext.dialogHistory[userContext.dialogIndex] = unescape(k));
  1077. isIpad() && showSpinner();
  1078. $.ajax({
  1079. url: b,
  1080. dataType: "JSON",
  1081. success: function(a) {
  1082. isIpad() && hideSpinner();
  1083. questSubmitCallback(a);
  1084. questById(f).action_taken = !0;
  1085.  
  1086. // EXTENDER :: Modification, auto boss challenger
  1087. bossChallenger.fight(a, c);
  1088. }
  1089. });
  1090. return !1;
  1091. }
  1092. log("Boss challenge code injected.", "initialize");
  1093.  
  1094.  
  1095. function doCampAttack(b, a, callback) {
  1096. console.debug("Logging parameters, send camp attack: ", b, a, callback);
  1097. if (!1 == checkParticipation() || !1 == allowCampAttack())
  1098. return !1;
  1099.  
  1100. if (void 0 != userContext.targetAllianceStance && void 0 == a) {
  1101. var c = !1, d = userContext.currentActionLabel;
  1102.  
  1103. if ("fight" == d || "hoodwink" == d || "steal" == d || "sabotage" == d || "hoodwink" == d || "harass" == d) c = !0;
  1104.  
  1105. if (2 == userContext.targetAllianceStance.status && !0 == c)
  1106. return doLog("show alert if you really want to attack your friendly alliance alert"), dialogAlert({
  1107. style: "confirm",
  1108. margin_top: 100,
  1109. button1: "NO",
  1110. button1_action: function() { return closeAlert(); },
  1111. button2: "YES",
  1112. button2_action: function() { doCampAttack(b, !0); },
  1113. heading: "Action Confirmation",
  1114. text: "Remember, this alliance is your friend! Are you certain you want to attack them?"
  1115. }), !1;
  1116. }
  1117.  
  1118. $.ajax({
  1119. url: "/play/camp_attack_begin?id=" + b + "&item_id=" + itemCurrentSelection.id + "&ability=" + userContext.currentActionLabel,
  1120. dataType: "JSON",
  1121. success: function(a) {
  1122.  
  1123. if (a.error) {
  1124. a.swornsword &&
  1125. insertInventoryFromItem(playerInventory, a.swornsword),
  1126. doAlert("Error Attacking Camp", a.error), !1;
  1127.  
  1128. } else {
  1129. campAttackProgress(a.camp_attack.id);
  1130. }
  1131.  
  1132. // EXTENDER :: Modification, call callback
  1133. // parameter indicates successfull sending
  1134. if (typeof callback == "function") {
  1135. callback(a);
  1136. }
  1137. }
  1138. });
  1139. }
  1140. log("Camp attack now calls callback afterwards.", "initialize");