Eternity Tower Enemy Target Button

Adds a target button to enemies in battle

目前为 2018-01-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Eternity Tower Enemy Target Button
  3. // @icon https://www.eternitytower.net/favicon.png
  4. // @namespace http://mean.cloud/
  5. // @version 1.00
  6. // @description Adds a target button to enemies in battle
  7. // @match http*://*.eternitytower.net/*
  8. // @copyright 2017-2018, MeanCloud
  9. // @run-at document-end
  10. // ==/UserScript==
  11.  
  12.  
  13. ////////////////////////////////////////////////////////////////
  14. ////////////// ** SCRIPT GLOBAL INITIALIZATION ** //////////////
  15. function startup() { ET_EnemyTargetButtonMod(); }
  16. ////////////////////////////////////////////////////////////////
  17.  
  18.  
  19. ET_EnemyTargetButtonMod = function()
  20. {
  21. ET.MCMF.Ready(function()
  22. {
  23. jQ("head").append
  24. (
  25. "<style type=\"text/css\">\r\n" +
  26. ".MCETMod_EnemyTarget_imgdisabled {\r\n" +
  27. " background-color: #fff7f7;\r\n" +
  28. "}\r\n" +
  29. ".MCETMod_EnemyTarget_btndisabled {\r\n" +
  30. " background-color: #ffe3e3; width: 96px; font-size: 9pt;\r\n" +
  31. "}\r\n" +
  32. ".MCETMod_EnemyTarget_imgenabled {\r\n" +
  33. " background-color: #f7fff7;\r\n" +
  34. "}\r\n" +
  35. ".MCETMod_EnemyTarget_btnenabled {\r\n" +
  36. " background-color: #e3ffe3; width: 80px; font-size: 9pt;\r\n" +
  37. "}\r\n"
  38. );
  39. Meteor.connection._stream.on('message', function(sMeteorRawData)
  40. {
  41. try
  42. {
  43. var oMeteorData = JSON.parse(sMeteorRawData);
  44.  
  45. if ((oMeteorData.id !== undefined) && (oMeteorData.collection === "battlesList") && (oMeteorData.msg === "added"))
  46. MCETMod_CurrentBattleListID = oMeteorData.id;
  47. if (oMeteorData.id.toString().startsWith("battles-"))
  48. {
  49. battleData = JSON.parse(oMeteorData.fields.value);
  50.  
  51. MCETMod_CurrentTargetID = "";
  52. MCETMod_FirstEnemyID = ""; // auto-targets first enemy if the currently-targeted enemy is dead
  53. jQ.makeArray(battleData.units).forEach(function(currentPlayer, index, array) {
  54. if (currentPlayer.name === ET.MCMF.UserName)
  55. MCETMod_CurrentTargetID = currentPlayer.target; });
  56. MCETMod_TargetIsDead = false;
  57. MCETMod_TargetIsFound = false;
  58. jQ.makeArray(battleData.enemies).forEach(function(currentMonster, index, array) {
  59. if (currentMonster.id === MCETMod_CurrentTargetID) {
  60. MCETMod_TargetIsFound = true;
  61. if (currentMonster.health <= 0)
  62. MCETMod_TargetIsDead = true; } });
  63. try { MCETMod_FirstEnemyID = jQ.makeArray(battleData.enemies)[0].id; } catch (err) { }
  64. if ((MCETMod_TargetIsDead) || (!MCETMod_TargetIsFound) || (MCETMod_CurrentTargetID === ""))
  65. MCETMod_CurrentTargetID = MCETMod_FirstEnemyID;
  66. jQ.makeArray(battleData.enemies).forEach(function(currentMonster, index, array)
  67. {
  68. //console.log(currentMonster);
  69.  
  70. sThisMonsterID = currentMonster.id;
  71. dThisMonsterArmor = parseFloat(currentMonster.stats.armor);
  72. if (dThisMonsterArmor < parseFloat(0))
  73. dThisMonsterArmor = parseFloat(0);
  74.  
  75. jQ("div.battle-unit-container").each(function()
  76. {
  77. try
  78. {
  79. sMonsterID = jQ(this).find("img.enemy-icon")[0].id;
  80.  
  81. if (sThisMonsterID === sMonsterID)
  82. {
  83. jQ(this).parent().find(".MCETMod_EnemyTarget").remove();
  84. if (MCETMod_CurrentTargetID === sThisMonsterID)
  85. {
  86. jQ(this).parent().find("img.enemy-icon").removeClass("MCETMod_EnemyTarget_imgenabled").addClass("MCETMod_EnemyTarget_imgdisabled").after(
  87. "<div class=\"MCETMod_EnemyTarget\">" +
  88. "<button class=\"MCETMod_EnemyTarget_btndisabled\" type=\"button\" disabled>Target</button>" +
  89. "</div>");
  90. }
  91. else
  92. {
  93. jQ(this).parent().find("img.enemy-icon").removeClass("MCETMod_EnemyTarget_imgdisabled").addClass("MCETMod_EnemyTarget_imgenabled").after(
  94. "<div class=\"MCETMod_EnemyTarget\">" +
  95. "<img src=\"/icons/accuracy.svg\" style=\"width: 16px; height: 16px;\" /><button class=\"MCETMod_EnemyTarget_btnenabled\" type=\"button\" onclick=\"javascript:ET_EnemyTargetButtonMod_TargetCreature('" + sThisMonsterID + "');\">Target</button>" +
  96. "</div>");
  97. }
  98. }
  99. }
  100. catch (err) { }
  101. });
  102. });
  103. }
  104. }
  105. catch (err) { }
  106. });
  107. });
  108. };
  109.  
  110. ET_EnemyTargetButtonMod_TargetCreature = function(which_id)
  111. {
  112. Meteor.connection._send({"msg":"method","method":"battles.castAbility","params":[MCETMod_CurrentBattleListID,"changeTarget",{"targets":[which_id],"caster":ET.MCMF.UserID}],"id":"MCETModRetarget"});
  113. };
  114.  
  115.  
  116. ////////////////////////////////////////////////////////////////
  117. /////////////// ** common.js -- DO NOT MODIFY ** ///////////////
  118. time_val = function()
  119. {
  120. return CDbl(Math.floor(Date.now() / 1000));
  121. };
  122.  
  123. IsValid = function(oObject)
  124. {
  125. if (oObject === undefined) return false;
  126. if (oObject === null) return false;
  127. return true;
  128. };
  129.  
  130. Random = function(iMin, iMax)
  131. {
  132. return parseInt(iMin + Math.floor(Math.random() * iMax));
  133. };
  134.  
  135. ShiftClick = function(oEl)
  136. {
  137. if (oEl === undefined)
  138. {
  139. var shiftclick = jQ.Event("click");
  140. shiftclick.shiftKey = true;
  141.  
  142. var shiftclickOrig = jQ.Event("click");
  143. shiftclickOrig.shiftKey = true;
  144.  
  145. shiftclick.originalEvent = shiftclick;
  146. return shiftclick;
  147. }
  148.  
  149. jQ(oEl).trigger(ShiftClick());
  150. };
  151.  
  152. if (!String.prototype.replaceAll)
  153. String.prototype.replaceAll = function(search, replace) { return ((replace === undefined) ? this.toString() : this.replace(new RegExp('[' + search + ']', 'g'), replace)); };
  154.  
  155. if (!String.prototype.startsWith)
  156. String.prototype.startsWith = function(search, pos) { return this.substr(((!pos) || (pos < 0)) ? 0 : +pos, search.length) === search; };
  157.  
  158. CInt = function(v)
  159. {
  160. try
  161. {
  162. if (!isNaN(v)) return Math.floor(v);
  163. if (typeof v === 'undefined') return parseInt(0);
  164. if (v === null) return parseInt(0);
  165. var t = parseInt(v);
  166. if (isNaN(t)) return parseInt(0);
  167. return Math.floor(t);
  168. }
  169. catch (err) { }
  170.  
  171. return parseInt(0);
  172. };
  173.  
  174. CDbl = function(v)
  175. {
  176. try
  177. {
  178. if (!isNaN(v)) return parseFloat(v);
  179. if (typeof v === 'undefined') return parseFloat(0.0);
  180. if (v === null) return parseFloat(0.0);
  181. var t = parseFloat(v);
  182. if (isNaN(t)) return parseFloat(0.0);
  183. return t;
  184. }
  185. catch (err) { }
  186.  
  187. return parseFloat(0.0);
  188. };
  189.  
  190. // dup of String.prototype.startsWith, but uses indexOf() instead of substr()
  191. startsWith = function (haystack, needle) { return (needle === "") || (haystack.indexOf(needle) === 0); };
  192. endsWith = function (haystack, needle) { return (needle === "") || (haystack.substring(haystack.length - needle.length) === needle); };
  193.  
  194. ChopperBlank = function (sText, sSearch, sEnd)
  195. {
  196. var sIntermediate = "";
  197.  
  198. if (sSearch === "")
  199. sIntermediate = sText.substring(0, sText.length);
  200. else
  201. {
  202. var iIndexStart = sText.indexOf(sSearch);
  203. if (iIndexStart === -1)
  204. return "";
  205.  
  206. sIntermediate = sText.substring(iIndexStart + sSearch.length);
  207. }
  208.  
  209. if (sEnd === "")
  210. return sIntermediate;
  211.  
  212. var iIndexEnd = sIntermediate.indexOf(sEnd);
  213.  
  214. return (iIndexEnd === -1) ? sIntermediate : sIntermediate.substring(0, iIndexEnd);
  215. };
  216.  
  217. CondenseSpacing = function(text)
  218. {
  219. while (text.indexOf(" ") !== -1)
  220. text = text.replace(" ", " ");
  221. return text;
  222. };
  223.  
  224. pad = function(sText, iWidth, sChar)
  225. {
  226. sChar = ((sChar !== undefined) ? sChar : ('0'));
  227. sText = sText.toString();
  228. return ((sText.length >= iWidth) ? (sText) : (new Array(iWidth - sText.length + 1).join(sChar) + sText));
  229. };
  230.  
  231. is_visible = (function () {
  232. var x = window.pageXOffset ? window.pageXOffset + window.innerWidth - 1 : 0,
  233. y = window.pageYOffset ? window.pageYOffset + window.innerHeight - 1 : 0,
  234. relative = !!((!x && !y) || !elementFromPoint(x, y));
  235. function inside(child, parent) {
  236. while(child){
  237. if (child === parent) return true;
  238. child = child.parentNode;
  239. }
  240. return false;
  241. };
  242. return function (elem) {
  243. if (
  244. hidden ||
  245. elem.offsetWidth==0 ||
  246. elem.offsetHeight==0 ||
  247. elem.style.visibility=='hidden' ||
  248. elem.style.display=='none' ||
  249. elem.style.opacity===0
  250. ) return false;
  251. var rect = elem.getBoundingClientRect();
  252. if (relative) {
  253. if (!inside(elementFromPoint(rect.left + elem.offsetWidth/2, rect.top + elem.offsetHeight/2),elem)) return false;
  254. } else if (
  255. !inside(elementFromPoint(rect.left + elem.offsetWidth/2 + window.pageXOffset, rect.top + elem.offsetHeight/2 + window.pageYOffset), elem) ||
  256. (
  257. rect.top + elem.offsetHeight/2 < 0 ||
  258. rect.left + elem.offsetWidth/2 < 0 ||
  259. rect.bottom - elem.offsetHeight/2 > (window.innerHeight || documentElement.clientHeight) ||
  260. rect.right - elem.offsetWidth/2 > (window.innerWidth || documentElement.clientWidth)
  261. )
  262. ) return false;
  263. if (window.getComputedStyle || elem.currentStyle) {
  264. var el = elem,
  265. comp = null;
  266. while (el) {
  267. if (el === document) {break;} else if(!el.parentNode) return false;
  268. comp = window.getComputedStyle ? window.getComputedStyle(el, null) : el.currentStyle;
  269. if (comp && (comp.visibility=='hidden' || comp.display == 'none' || (typeof comp.opacity !=='undefined' && comp.opacity != 1))) return false;
  270. el = el.parentNode;
  271. }
  272. }
  273. return true;
  274. };
  275. })();
  276. ////////////////////////////////////////////////////////////////
  277.  
  278.  
  279. ////////////////////////////////////////////////////////////////
  280. ////////////// ** common_ET.js -- DO NOT MODIFY ** /////////////
  281.  
  282. if (window.ET === undefined) window.ET = { };
  283. if (window.ET.MCMF === undefined) // MeanCloud mod framework
  284. {
  285. window.ET.MCMF =
  286. {
  287. TryingToLoad: false,
  288. WantDebug: false,
  289. WantFasterAbilityCDs: false,
  290.  
  291. InBattle: false,
  292. FinishedLoading: false,
  293. Initialized: false,
  294. AbilitiesReady: false,
  295. InitialAbilityCheck: true,
  296. TimeLeftOnCD: 9999,
  297. TimeLastFight: 0,
  298.  
  299. CombatID: undefined, // technically not required
  300.  
  301. ToastMessageSuccess: function(msg)
  302. {
  303. toastr.success(msg);
  304. },
  305.  
  306. ToastMessageWarning: function(msg)
  307. {
  308. toastr.warning(msg);
  309. },
  310.  
  311. EventSubscribe: function(sEventName, fnCallback, sNote)
  312. {
  313. if (window.ET.MCMF.EventSubscribe_events === undefined)
  314. window.ET.MCMF.EventSubscribe_events = [];
  315.  
  316. var newEvtData = {};
  317. newEvtData.name = ((!sEventName.startsWith("ET:")) ? ("ET:" + sEventName) : (sEventName));
  318. newEvtData.callback = fnCallback;
  319. newEvtData.note = sNote;
  320.  
  321. window.ET.MCMF.EventSubscribe_events.push(newEvtData);
  322.  
  323. /*
  324. jQ("div#ET_meancloud_bootstrap").off("ET:" + sEventName.trim()).on("ET:" + sEventName.trim(), function()
  325. {
  326. window.ET.MCMF.EventSubscribe_events.forEach(function(oThisEvent, index, array)
  327. {
  328. if (sEventName === oThisEvent.name)
  329. {
  330. if (window.ET.MCMF.WantDebug) console.log("FIRING '" + oThisEvent.name + "'!" + ((oThisEvent.note === undefined) ? "" : " (" + oThisEvent.note + ")"));
  331. oThisEvent.callback();
  332. }
  333. });
  334. });
  335. */
  336.  
  337. if (window.ET.MCMF.WantDebug) console.log("Added event subscription '" + sEventName + "'!" + ((sNote === undefined) ? "" : " (" + sNote + ")"));
  338. },
  339.  
  340. EventTrigger: function(sEventName)
  341. {
  342. //jQ("div#ET_meancloud_bootstrap").trigger(sEventName);
  343.  
  344. if (window.ET.MCMF.EventSubscribe_events === undefined) return;
  345.  
  346. window.ET.MCMF.EventSubscribe_events.forEach(function(oThisEvent, index, array)
  347. {
  348. if (sEventName === oThisEvent.name)
  349. {
  350. if (window.ET.MCMF.WantDebug) console.log("FIRING '" + oThisEvent.name + "'!" + ((oThisEvent.note === undefined) ? "" : " (" + oThisEvent.note + ")"));
  351. try { oThisEvent.callback(); } catch (err) { if (window.ET.MCMF.WantDebug) console.log("Exception: " + err); }
  352. }
  353. });
  354. },
  355.  
  356. MeteorCall: function(sMethod, oParam1, oParam2, sMsgSuccess, sMsgFailure)
  357. {
  358. Package.meteor.Meteor.call("crafting.craftItem", sRecipeID, iBatchAmt, function(errResp)
  359. {
  360. if (errResp)
  361. window.ET.MCMF.ToastMessageWarning(sMsgFailure);
  362. else
  363. window.ET.MCMF.ToastMessageSuccess(sMsgSuccess);
  364. });
  365. },
  366.  
  367. FasterAbilityUpdates: function()
  368. {
  369. try
  370. {
  371. if ((window.ET.MCMF.WantFasterAbilityCDs) && (window.ET.MCMF.FinishedLoading) && (!window.ET.MCMF.InBattle) && (!window.ET.MCMF.AbilitiesReady))
  372. Meteor.call("abilities.gameUpdate", function(e, t) { });
  373. }
  374. catch (err) { }
  375.  
  376. setTimeout(window.ET.MCMF.FasterAbilityUpdates, 2000);
  377. },
  378.  
  379. AbilityCDTrigger: function()
  380. {
  381. try
  382. {
  383. bStillInCombat = window.ET.MCMF.InBattle || ((time_val() - window.ET.MCMF.TimeLastFight) < 3);
  384.  
  385. if ((window.ET.MCMF.FinishedLoading) && (!bStillInCombat))
  386. {
  387. iTotalCD = 0;
  388. iTotalCDTest = 0;
  389. iHighestCD = 0;
  390.  
  391. window.ET.MCMF.GetAbilities().forEach(function(oThisAbility, index, array)
  392. {
  393. if (oThisAbility.equipped)
  394. {
  395. if (parseInt(oThisAbility.currentCooldown) > 0)
  396. {
  397. iTotalCD += parseInt(oThisAbility.currentCooldown);
  398. if (iHighestCD < parseInt(oThisAbility.currentCooldown))
  399. iHighestCD = parseInt(oThisAbility.currentCooldown);
  400. }
  401. }
  402.  
  403. iTotalCDTest += parseInt(oThisAbility.cooldown);
  404. });
  405.  
  406. if ((iTotalCDTest > 0) && (iTotalCD === 0))
  407. {
  408. if (!window.ET.MCMF.AbilitiesReady)
  409. {
  410. if (!window.ET.MCMF.InitialAbilityCheck)
  411. {
  412. if (window.ET.MCMF.WantDebug) console.log("<-- triggering ET:abilitiesReady -->");
  413. window.ET.MCMF.EventTrigger("ET:abilitiesReady");
  414. //jQ("div#ET_meancloud_bootstrap").trigger("ET:abilitiesReady");
  415. }
  416. }
  417.  
  418. window.ET.MCMF.AbilitiesReady = true;
  419. window.ET.MCMF.TimeLeftOnCD = 0;
  420. }
  421. else
  422. {
  423. window.ET.MCMF.AbilitiesReady = false;
  424. window.ET.MCMF.TimeLeftOnCD = iHighestCD;
  425. }
  426.  
  427. window.ET.MCMF.InitialAbilityCheck = false;
  428. }
  429. else
  430. {
  431. window.ET.MCMF.AbilitiesReady = false;
  432. window.ET.MCMF.TimeLeftOnCD = 9999;
  433. }
  434. }
  435. catch (err) { }
  436.  
  437. setTimeout(window.ET.MCMF.AbilityCDTrigger, 500);
  438. },
  439.  
  440. InitMeteorTriggers: function()
  441. {
  442. if ((Package.meteor.Meteor === undefined) || (Package.meteor.Meteor.connection === undefined) || (Package.meteor.Meteor.connection._stream === undefined))
  443. {
  444. setTimeout(window.ET.MCMF.InitMeteorTriggers, 100);
  445. return;
  446. }
  447.  
  448. Package.meteor.Meteor.connection._stream.on('message', function(sMeteorRawData)
  449. {
  450. if (window.ET.MCMF.CombatID === undefined)
  451. {
  452. try
  453. {
  454. oDataTemp = Package.meteor.global.Accounts.connection._stores.combat._getCollection()._collection._docs._map;
  455. window.ET.MCMF.CombatID = oDataTemp[Object.keys(oDataTemp)[0]]._id;
  456. }
  457. catch (err) { }
  458. }
  459.  
  460. try
  461. {
  462. oMeteorData = JSON.parse(sMeteorRawData);
  463.  
  464. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  465. //
  466. // BACKUP TO RETRIEVE USER AND COMBAT IDS
  467. //
  468. if (oMeteorData.collection === "users")
  469. if ((window.ET.MCMF.UserID === undefined) || (window.ET.MCMF.UserID.length !== 17))
  470. window.ET.MCMF.UserID = oMeteorData.id;
  471.  
  472. if (oMeteorData.collection === "combat")
  473. if ((window.ET.MCMF.T_CombatID === undefined) || (window.ET.MCMF.CombatID.length !== 17))
  474. if (oMeteorData.fields.owner === window.ET.MCMF.UserID)
  475. window.ET.MCMF.CombatID = oMeteorData.id;
  476. //
  477. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  478.  
  479. if (window.ET.MCMF.FinishedLoading)
  480. {
  481. if (oMeteorData.collection === "battlesList")
  482. {
  483. window.ET.MCMF.IsDemon = false;
  484. window.ET.MCMF.AbilitiesReady = false;
  485.  
  486. if ((oMeteorData.msg === "added") || (oMeteorData.msg === "removed"))
  487. {
  488. window.ET.MCMF.InBattle = (oMeteorData.msg === "added");
  489. if (window.ET.MCMF.WantDebug) console.log("<-- triggering ET:combat" + (((oMeteorData.msg === "added")) ? ("Start") : ("End")) + " -->");
  490. window.ET.MCMF.EventTrigger("ET:combat" + (((oMeteorData.msg === "added")) ? ("Start") : ("End")));
  491. //jQ("div#ET_meancloud_bootstrap").trigger("ET:combat" + (((oMeteorData.msg === "added")) ? ("Start") : ("End")));
  492. }
  493. }
  494.  
  495. if ((oMeteorData.collection === "battles") && (oMeteorData.msg === "added"))
  496. {
  497. if (oMeteorData.fields.finished)
  498. {
  499. window.ET.MCMF.WonLast = oMeteorData.fields.win;
  500. window.ET.MCMF.TimeLastFight = time_val();
  501.  
  502. if (!oMeteorData.fields.win)
  503. window.ET.MCMF.HP = 0;
  504.  
  505. if (window.ET.MCMF.WantDebug) console.log("<-- triggering ET:combat" + ((oMeteorData.fields.win) ? ("Won") : ("Lost")) + " -->");
  506. window.ET.MCMF.EventTrigger("ET:combat" + ((oMeteorData.fields.win) ? ("Won") : ("Lost")));
  507. //jQ("div#ET_meancloud_bootstrap").trigger("ET:combat" + ((oMeteorData.fields.win) ? ("Won") : ("Lost")));
  508. }
  509. }
  510. }
  511.  
  512. try
  513. {
  514. if (window.ET.MCMF.FinishedLoading)
  515. {
  516. if (oMeteorData.id)
  517. {
  518. if (oMeteorData.id.startsWith("battles-"))
  519. {
  520. if (oMeteorData.msg !== "removed")
  521. {
  522. battleData = JSON.parse(oMeteorData.fields.value);
  523.  
  524. jQ.makeArray(battleData.units).forEach(function(currentPlayer, index, array)
  525. {
  526. try
  527. {
  528. if (currentPlayer.name === window.ET.MCMF.UserName)
  529. {
  530. jQ.makeArray(currentPlayer.buffs).forEach(function(currentBuff, index2, array2)
  531. {
  532. try
  533. {
  534. if (currentBuff.id === "demons_heart")
  535. {
  536. if (currentBuff.data.active)
  537. {
  538. if (!window.ET.MCMF.IsDemon)
  539. {
  540. window.ET.MCMF.IsDemon = true;
  541.  
  542. if (window.ET.MCMF.WantDebug) console.log("<-- triggering ET:combat:buffDemon -->");
  543. window.ET.MCMF.EventTrigger("ET:combat:buffDemon");
  544. //jQ("div#ET_meancloud_bootstrap").trigger("ET:combat:buffDemon");
  545. }
  546. }
  547. }
  548. }
  549. catch (err) { }
  550. });
  551.  
  552. return true; // break out of forEach()
  553. }
  554. }
  555. catch (err) { }
  556. });
  557. }
  558. }
  559. }
  560. }
  561. }
  562. catch (err) { }
  563. }
  564. catch (err) { }
  565.  
  566. try
  567. {
  568. //todo: use life data from Meteor vs captured meteor response data
  569. oMeteorData = JSON.parse(sMeteorRawData);
  570.  
  571. if (oMeteorData.collection === "combat")
  572. {
  573. if ((oMeteorData.fields.owner === window.ET.MCMF.UserID) || (oMeteorData.id === window.ET.MCMF.CombatID))
  574. {
  575. window.ET.MCMF.HP = oMeteorData.fields.stats.health;
  576. window.ET.MCMF.NRG = oMeteorData.fields.stats.energy;
  577. }
  578. }
  579. }
  580. catch (err) { }
  581. });
  582. },
  583.  
  584. AbilityCDCalc: function()
  585. {
  586. iTotalCD = 0;
  587. iTotalCDTest = 0;
  588. iHighestCD = 0;
  589.  
  590. window.ET.MCMF.GetAbilities().forEach(function(oThisAbility, index, array)
  591. {
  592. if (oThisAbility.equipped)
  593. {
  594. if (parseInt(oThisAbility.currentCooldown) > 0)
  595. {
  596. iTotalCD += parseInt(oThisAbility.currentCooldown);
  597. if (iHighestCD < parseInt(oThisAbility.currentCooldown))
  598. iHighestCD = parseInt(oThisAbility.currentCooldown);
  599. }
  600. }
  601.  
  602. iTotalCDTest += parseInt(oThisAbility.cooldown);
  603. });
  604.  
  605. if ((iTotalCDTest > 0) && (iTotalCD === 0))
  606. {
  607. if (!window.ET.MCMF.AbilitiesReady)
  608. {
  609. if (!window.ET.MCMF.InitialAbilityCheck)
  610. {
  611. if (window.ET.MCMF.WantDebug) console.log("<-- triggering ET:abilitiesReady -->");
  612. window.ET.MCMF.EventTrigger("ET:abilitiesReady");
  613. //jQ("div#ET_meancloud_bootstrap").trigger("ET:abilitiesReady");
  614. }
  615. }
  616.  
  617. window.ET.MCMF.AbilitiesReady = true;
  618. window.ET.MCMF.TimeLeftOnCD = 0;
  619. }
  620. else
  621. {
  622. window.ET.MCMF.AbilitiesReady = false;
  623. window.ET.MCMF.TimeLeftOnCD = iHighestCD;
  624. }
  625.  
  626. window.ET.MCMF.InitialAbilityCheck = false;
  627. },
  628.  
  629. GetAbilities: function()
  630. {
  631. return Object.keys(window.ET.MCMF.AbilityManager._collection._docs._map).map(key => window.ET.MCMF.AbilityManager._collection._docs._map[key])[0].learntAbilities;
  632. },
  633.  
  634. GetAdventures: function()
  635. {
  636. return Object.keys(window.ET.MCMF.AdventureManager._collection._docs._map).map(key => window.ET.MCMF.AdventureManager._collection._docs._map[key])[0].adventures;
  637. },
  638.  
  639. GetChats: function()
  640. {
  641. return Object.keys(window.ET.MCMF.ChatManager._collection._docs._map).map(key => window.ET.MCMF.ChatManager._collection._docs._map[key]);
  642. },
  643.  
  644. GetItems: function()
  645. {
  646. return Object.keys(window.ET.MCMF.ItemManager._collection._docs._map).map(key => window.ET.MCMF.ItemManager._collection._docs._map[key]);
  647. },
  648.  
  649. // need a better way to check if the game has loaded basic data, but this is fine for now
  650. Setup: function()
  651. {
  652. if ((!window.ET.MCMF.TryingToLoad) && (!window.ET.MCMF.FinishedLoading))
  653. {
  654. // use whatever version of jQuery available to us
  655. $("body").append("<div id=\"ET_meancloud_bootstrap\" style=\"visibility: hidden; display: none;\"></div>");
  656. window.ET.MCMF.TryingToLoad = true;
  657. window.ET.MCMF.Setup_Initializer();
  658. }
  659. },
  660.  
  661. Setup_Initializer: function()
  662. {
  663. // wait for Meteor availability
  664. if ((Package === undefined) || (Package.meteor === undefined) || (Package.meteor.Meteor === undefined) || (Package.meteor.Meteor.connection === undefined) || (Package.meteor.Meteor.connection._stream === undefined))
  665. {
  666. setTimeout(window.ET.MCMF.Setup_Initializer, 10);
  667. return;
  668. }
  669.  
  670. if (!window.ET.MCMF.Initialized)
  671. {
  672. window.ET.MCMF.Initialized = true;
  673. window.ET.MCMF.Setup_SendDelayedInitializer();
  674. window.ET.MCMF.InitMeteorTriggers();
  675. window.ET.MCMF.Setup_remaining();
  676. }
  677. },
  678.  
  679. Setup_SendDelayedInitializer: function()
  680. {
  681. try
  682. {
  683. jQ("div#ET_meancloud_bootstrap").trigger("ET:initialized");
  684. window.ET.MCMF.EventTrigger("ET:initialized");
  685. //if (window.ET.MCMF.WantDebug) console.log("<-- triggering ET:initialized -->");
  686. }
  687. catch (err)
  688. {
  689. setTimeout(window.ET.MCMF.Setup_SendDelayedInitializer, 100);
  690. }
  691. },
  692.  
  693. Setup_remaining: function()
  694. {
  695. try
  696. {
  697. window.ET.MCMF.UserID = Package.meteor.global.Accounts.connection._userId;
  698. window.ET.MCMF.UserName = Package.meteor.global.Accounts.connection._stores.users._getCollection()._collection._docs._map[Package.meteor.global.Accounts.connection._userId].username;
  699. try
  700. {
  701. oDataTemp = Package.meteor.global.Accounts.connection._stores.combat._getCollection()._collection._docs._map;
  702. window.ET.MCMF.CombatID = oDataTemp[Object.keys(oDataTemp)[0]]._id;
  703. }
  704. catch (err) { }
  705.  
  706. window.ET.MCMF.AbilityManager = Package.meteor.global.Accounts.connection._stores.abilities._getCollection();
  707. window.ET.MCMF.AdventureManager = Package.meteor.global.Accounts.connection._stores.adventures._getCollection();
  708. window.ET.MCMF.ChatManager = Package.meteor.global.Accounts.connection._stores.simpleChats._getCollection();
  709. window.ET.MCMF.ItemManager = Package.meteor.global.Accounts.connection._stores.items._getCollection();
  710.  
  711. if (window.ET.MCMF.GetAbilities().length < 0) throw "Not loaded yet: no abilities";
  712. if (window.ET.MCMF.GetItems().length < 0) throw "Not loaded yet: no items";
  713. if (window.ET.MCMF.GetChats().length < 0) throw "Not loaded yet: no chats";
  714.  
  715. // if the above is all good, then this should be no problem:
  716.  
  717. window.ET.MCMF.AbilityCDTrigger(); // set up ability CD trigger
  718. window.ET.MCMF.AbilityCDCalc();
  719. window.ET.MCMF.FasterAbilityUpdates(); // set up faster ability updates (do not disable, this is controlled via configurable setting)
  720.  
  721. // trigger finished-loading event
  722. if (!window.ET.MCMF.FinishedLoading)
  723. {
  724. if (window.ET.MCMF.WantDebug) console.log("<-- triggering ET:loaded -->");
  725. window.ET.MCMF.EventTrigger("ET:loaded");
  726. //jQ("div#ET_meancloud_bootstrap").trigger("ET:loaded");
  727. window.ET.MCMF.FinishedLoading = true;
  728. }
  729. }
  730. catch (err)
  731. {
  732. // any errors and we retry setup
  733. setTimeout(window.ET.MCMF.Setup_remaining, 500);
  734. }
  735. },
  736.  
  737. Loaded: function(fnCallback, sNote)
  738. {
  739. if (!window.ET.MCMF.FinishedLoading)
  740. window.ET.MCMF.EventSubscribe("loaded", fnCallback, sNote);
  741. else
  742. fnCallback();
  743. },
  744.  
  745. Ready: function(fnCallback, sNote)
  746. {
  747. if (!window.ET.MCMF.Initialized)
  748. window.ET.MCMF.EventSubscribe("initialized", fnCallback, sNote);
  749. else
  750. fnCallback();
  751. }
  752. };
  753.  
  754. window.ET.MCMF.Setup();
  755. }
  756. ////////////////////////////////////////////////////////////////
  757.  
  758.  
  759. ////////////////////////////////////////////////////////////////
  760. ////////// ** CORE SCRIPT STARTUP -- DO NOT MODIFY ** //////////
  761. function LoadJQ(callback) {
  762. if (window.jQ === undefined) { var script=document.createElement("script");script.setAttribute("src","//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js");script.addEventListener('load',function() {
  763. var subscript=document.createElement("script");subscript.textContent="window.jQ=jQuery.noConflict(true);("+callback.toString()+")();";document.body.appendChild(subscript); },
  764. !1);document.body.appendChild(script); } else callback(); } LoadJQ(startup);
  765. ////////////////////////////////////////////////////////////////