The West - Skills Calc

Calculates sum of skills obtained from items

当前为 2015-06-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @namespace https://gf.qytechs.cn/users/8637
  3. // @name The West - Skills Calc
  4. // @author neversleep1911
  5. // @description Calculates sum of skills obtained from items
  6. // @include http://*.the-west.*/game.php*
  7. // @include https://*.the-west.*/game.php*
  8. // @grant none
  9. // @version 2.1.2
  10. // @copyright Copyright (c) 2015 neversleep1911 (full list of contributors/translators see here: https://gf.qytechs.cn/scripts/7829)
  11. // @license MIT (http://opensource.org/licenses/MIT)
  12. // ==/UserScript==
  13.  
  14. (function(func) {
  15. var script;
  16. script = document.createElement("script");
  17. script.setAttribute("type", "text/javascript");
  18. script.textContent = "(" + func.toString() + ")();";
  19. document.body.appendChild(script);
  20. document.body.removeChild(script);
  21. })(function() {
  22. var Gui, I18n, SkillsCalc;
  23. I18n = function() {
  24. function I18n() {}
  25. var DEFAULT_LANGUAGE, STRINGS, language;
  26. DEFAULT_LANGUAGE = "en_US";
  27. STRINGS = {
  28. en_US: {
  29. dialogs: {
  30. add_item: "Add item",
  31. add_character_items: "Character's items"
  32. },
  33. groups: {
  34. skills: "Skills",
  35. items: "Items"
  36. },
  37. buttons: {
  38. character: "Character",
  39. add: "Add",
  40. reset: "Reset"
  41. },
  42. checkboxes: {
  43. show_bonus: "Show bonus",
  44. show_skills: "Show my skills"
  45. },
  46. labels: {
  47. level: "Level",
  48. item_id: "Item ID",
  49. character_name: "Character's name",
  50. health: "Health"
  51. },
  52. tooltip: {
  53. health: "Normal / Solder / Solder with bonus"
  54. },
  55. errors: {
  56. player_not_found: "Player not found!"
  57. }
  58. },
  59. pl_PL: {
  60. dialogs: {
  61. add_item: "Dodaj przedmiot",
  62. add_character_items: "Przedmioty gracza"
  63. },
  64. groups: {
  65. skills: "Umiejętności",
  66. items: "Przedmioty"
  67. },
  68. buttons: {
  69. character: "Gracz",
  70. add: "Dodaj",
  71. reset: "Reset"
  72. },
  73. checkboxes: {
  74. show_bonus: "Pokaż bonus",
  75. show_skills: "Pokaż moje umiejętności"
  76. },
  77. labels: {
  78. level: "Level",
  79. item_id: "ID przedmiotu",
  80. character_name: "Nazwa gracza",
  81. health: "Życie"
  82. },
  83. tooltip: {
  84. health: "Normalny / Żołnierz / Żołnierz z bonusem"
  85. },
  86. errors: {
  87. player_not_found: "Gracz nie znaleziony!"
  88. }
  89. },
  90. ru_RU: {
  91. dialogs: {
  92. add_item: "Добавить предмет",
  93. add_character_items: "Предметы персонажа"
  94. },
  95. groups: {
  96. skills: "Навыки",
  97. items: "Предметы"
  98. },
  99. buttons: {
  100. character: "Персонаж",
  101. add: "Добавить",
  102. reset: "Сбросить"
  103. },
  104. checkboxes: {
  105. show_bonus: "Показывать бонусы",
  106. show_skills: "Показывать мои навыки"
  107. },
  108. labels: {
  109. level: "Уровень",
  110. item_id: "ID предмета",
  111. character_name: "Имя персонажа",
  112. health: "Здоровье"
  113. },
  114. tooltip: {
  115. health: "Минимум / Солдат / Солдат с бонусом"
  116. },
  117. errors: {
  118. player_not_found: "Игрок не найден!"
  119. }
  120. }
  121. };
  122. language = DEFAULT_LANGUAGE;
  123. I18n.language = function() {
  124. return language;
  125. };
  126. I18n.setLanguage = function(lang) {
  127. return language = STRINGS[lang] ? lang : DEFAULT_LANGUAGE;
  128. };
  129. I18n.tr = function(id) {
  130. var string;
  131. string = STRINGS[language];
  132. $(id.split(".")).each(function(k, v) {
  133. return (string = string[v]) !== void 0;
  134. });
  135. return string || id;
  136. };
  137. return I18n;
  138. }();
  139. Gui = function() {
  140. function Gui() {}
  141. Gui.createMenuButton = function(options) {
  142. var button;
  143. if (options == null) {
  144. options = {};
  145. }
  146. button = $("<div class='menulink' title='" + options.title + "' />");
  147. if (options.image) {
  148. button.css("background-image", "url(" + options.image + ")");
  149. }
  150. button.hover(function() {
  151. $(this).css("background-position", "-25px 0px");
  152. return true;
  153. }, function() {
  154. $(this).css("background-position", "0px 0px");
  155. return true;
  156. }).on("click", options.onclick);
  157. $("div#ui_menubar").append($('<div class="ui_menucontainer" />').append(button).append('<div class="menucontainer_bottom" />'));
  158. return button;
  159. };
  160. Gui.createGroup = function(options) {
  161. var content, group, scrollPane;
  162. if (options == null) {
  163. options = {};
  164. }
  165. group = new west.gui.Groupframe("", "<div />");
  166. if (options.css) {
  167. $(group.getMainDiv()).css(options.css);
  168. }
  169. content = $(".tw2gui_groupframe_content_pane div", group.getMainDiv()).first();
  170. if (options.title) {
  171. content.append($("<h2>" + options.title + "</h2><hr style='margin-top: 2px; margin-bottom: 4px;' />"));
  172. }
  173. if (options.scrollPane) {
  174. scrollPane = new west.gui.Scrollpane;
  175. if (options.scrollPane.css) {
  176. $(scrollPane.getMainDiv()).css(options.scrollPane.css);
  177. }
  178. content.append(scrollPane.getMainDiv());
  179. group.scrollPane = scrollPane;
  180. group.appendToScrollContentPane = function(content) {
  181. scrollPane.appendContent(content);
  182. return group;
  183. };
  184. }
  185. return group;
  186. };
  187. Gui.createButton = function(options) {
  188. var button;
  189. if (options == null) {
  190. options = {};
  191. }
  192. button = new west.gui.Button(options.text);
  193. button.click(options.onclick);
  194. $(button.getMainDiv()).css(options.css);
  195. return button;
  196. };
  197. Gui.createCheckbox = function(options) {
  198. var checkbox;
  199. if (options == null) {
  200. options = {};
  201. }
  202. checkbox = new west.gui.Checkbox(options.text, "", options.onclick);
  203. $(checkbox.getMainDiv()).css(options.css);
  204. return checkbox;
  205. };
  206. Gui.createTextfield = function(options) {
  207. var field;
  208. if (options == null) {
  209. options = {};
  210. }
  211. field = new west.gui.Textfield;
  212. field.setSize(options.size);
  213. field.setLabel($("<span>" + options.label + "</span>"));
  214. if (options.value) {
  215. field.setValue(options.value);
  216. }
  217. if (options.css) {
  218. $(field.getMainDiv()).css(options.css);
  219. }
  220. return field;
  221. };
  222. return Gui;
  223. }();
  224. SkillsCalc = function() {
  225. function SkillsCalc() {
  226. var self;
  227. self = this;
  228. I18n.setLanguage(Game.locale);
  229. Gui.createMenuButton({
  230. title: SkillsCalc.NAME,
  231. image: this.MENU_BUTTON_IMAGE,
  232. onclick: function(e) {
  233. self.createWindow();
  234. e.preventDefault();
  235. return false;
  236. }
  237. });
  238. }
  239. var ItemCalculator, Window;
  240. SkillsCalc.ID = "tw_skills_calc";
  241. SkillsCalc.NAME = "Skills Calc";
  242. SkillsCalc.AUTHOR = "neversleep1911";
  243. SkillsCalc.WEB_SITE = "https://gf.qytechs.cn/scripts/7829";
  244. SkillsCalc.MIN_GAME_VERSION = "2.21";
  245. SkillsCalc.MAX_GAME_VERSION = Game.version.toString();
  246. SkillsCalc.prototype.MENU_BUTTON_IMAGE = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAZCAIAAAD8NuoTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QQICBgbVC0rcwAACI5JREFUSMel10tvXFcBAODzuq+5987MHY/nYTvx24lj13k0KQ5NmjR90ELVVoIKSitARWxAFSyqskKskLphwQKJFUKilUCIBVIXFVSN0tKmTVPbbdwkjhOPXzPjGd953vc9557Dgp8wf+Dbf/A3PzpZr9m5wum7ew+E45maEau+nphaOgwYzBqWE0WdXldLWF/iFiCAiYyebXa9nUbbjkNAcN5IJ0FUzmpL87l6LcyXypW9Wux76WzOdblhcaIBHqpZM+X73O32uBwyCrmaGJTIKb1l9xpdp+VTpCADK0Qkw2kF/vZ7p48tnH7zrb/UEw4ZAAQxLrCQhJA4DIlIEoAEEjLHMUSKSMW4iwAWPOECaUSlLBhJg1+/8dPmyodYTY3PnF+7vd6MXAFBwmIFmgD0w5BIipaoLosQEZCRSIksriYgcaFAnKMEJJIkYRhnFfPM4kJl5WP42hNz9zYas6cnVQP2Omx/rxNxIKeU9HCxnNYuP/aYnskW86n1O41/vvv+5pc3MUYSQQFLKBcYAiBAkoiTJyZ//tz8v95fWbtvLywNRH3n/MnnL5Tga08c+2Tl3ty5b2ZzOe53GaVKSpcVOUlY1G712n2Js8jxy4Y6kTc5Rm7IXInU7P6n24c84UVDVQjad9pvv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Gg9dWFaTrpr2xZ1SYaA7S7dPTwYGRn1YlFttnuURf12TtUky8i5sJghHg7KukZ0nM7+/zsAkbGuvSM1e5OPphNjaGd3/38JylRK90rXAwAAAABJRU5ErkJggg==";
  247. SkillsCalc.prototype.windows = {};
  248. SkillsCalc.prototype.createWindow = function() {
  249. var self, wndId;
  250. self = this;
  251. while (true) {
  252. wndId = Math.ceil(Math.random() * 1024);
  253. if (!this.windows[wndId]) {
  254. break;
  255. }
  256. }
  257. this.windows[wndId] = new Window({
  258. id: wndId,
  259. title: SkillsCalc.NAME,
  260. miniTitle: SkillsCalc.NAME
  261. });
  262. this.windows[wndId].onDestroy = function(wnd) {
  263. delete self.windows[wnd.id];
  264. return true;
  265. };
  266. return true;
  267. };
  268. Window = function() {
  269. function Window(options) {
  270. var self;
  271. self = this;
  272. this.images = {};
  273. this.items = {};
  274. this.calculator = new ItemCalculator;
  275. this.calculator.level = Character.level;
  276. this.id = options.id;
  277. this.wnd = wman.open("skills-calc-window-" + options.id, null, "noreload");
  278. this.wnd.setTitle(options.title);
  279. this.wnd.setMiniTitle(options.miniTitle);
  280. this.wnd.addEventListener("WINDOW_DESTROY", function() {
  281. if (self.onDestroy) {
  282. return self.onDestroy(self);
  283. } else {
  284. return true;
  285. }
  286. });
  287. this.wnd.appendToContentPane((this.groupSkills = Gui.createGroup({
  288. id: "skills",
  289. title: I18n.tr("groups.skills"),
  290. css: {
  291. width: 402,
  292. position: "absolute"
  293. },
  294. scrollPane: {
  295. css: {
  296. height: 264
  297. }
  298. }
  299. })).getMainDiv());
  300. this.wnd.appendToContentPane((this.groupItems = Gui.createGroup({
  301. id: "items",
  302. title: I18n.tr("groups.items"),
  303. css: {
  304. left: 400,
  305. width: 294
  306. },
  307. scrollPane: {
  308. css: {
  309. height: 264
  310. }
  311. }
  312. })).getMainDiv());
  313. this.wnd.appendToContentPane(Gui.createButton({
  314. text: I18n.tr("buttons.reset"),
  315. css: {
  316. left: 592,
  317. top: 342,
  318. position: "absolute"
  319. },
  320. onclick: function(button, data) {
  321. return self.onButtonResetClick(button, data);
  322. }
  323. }).getMainDiv());
  324. this.wnd.appendToContentPane(Gui.createButton({
  325. text: I18n.tr("buttons.add"),
  326. css: {
  327. left: 490,
  328. top: 342,
  329. position: "absolute"
  330. },
  331. onclick: function(button, data) {
  332. return self.onButtonAddClick(button, data);
  333. }
  334. }).getMainDiv());
  335. this.wnd.appendToContentPane(Gui.createButton({
  336. text: I18n.tr("buttons.character"),
  337. css: {
  338. left: 388,
  339. top: 342,
  340. position: "absolute"
  341. },
  342. onclick: function(button, data) {
  343. return self.onButtonCharacterClick(button, data);
  344. }
  345. }).getMainDiv());
  346. this.wnd.appendToContentPane((this.checkboxBonus = Gui.createCheckbox({
  347. text: I18n.tr("checkboxes.show_bonus"),
  348. css: {
  349. left: 2,
  350. top: 324,
  351. position: "absolute"
  352. },
  353. onclick: function(state) {
  354. return self.onCheckboxBonusClick(state);
  355. }
  356. })).getMainDiv());
  357. this.wnd.appendToContentPane((this.checkboxSkills = Gui.createCheckbox({
  358. text: I18n.tr("checkboxes.show_skills"),
  359. css: {
  360. left: 2,
  361. top: 350,
  362. position: "absolute"
  363. },
  364. onclick: function(state) {
  365. return self.onCheckboxSkillsClick(state);
  366. }
  367. })).getMainDiv());
  368. this.wnd.appendToContentPane((this.textfieldLevel = Gui.createTextfield({
  369. size: 6,
  370. label: I18n.tr("labels.level"),
  371. value: this.calculator.level,
  372. css: {
  373. left: 180,
  374. top: 320,
  375. position: "absolute"
  376. }
  377. })).getMainDiv());
  378. this.wnd.appendToContentPane(this.labelHealth = $("<span />").css({
  379. position: "absolute",
  380. left: 180,
  381. top: 352
  382. }).attr("title", I18n.tr("tooltip.health")));
  383. this.textfieldLevel.onlyNumeric().getField().keyup(function(e) {
  384. var level;
  385. level = parseInt(self.textfieldLevel.getValue());
  386. if (!isNaN(level) && level > 0) {
  387. self.calculator.level = level;
  388. self.recalc();
  389. self.repaint();
  390. }
  391. return true;
  392. });
  393. this.initGroupSkills();
  394. this.initGroupItems();
  395. }
  396. Window.prototype.initGroupSkills = function() {
  397. var attr, attrs, div, img, j, l, len, len1, skill, skillType, skills;
  398. attrs = CharacterSkills.allAttrKeys;
  399. for (j = 0, len = attrs.length; j < len; j++) {
  400. attr = attrs[j];
  401. div = $('<div style="height: 41px;" />');
  402. skills = CharacterSkills.skillKeys4Attr[attr];
  403. for (l = 0, len1 = skills.length; l < len1; l++) {
  404. skillType = skills[l];
  405. skill = new Skill(skillType);
  406. img = skill.getSkillImage();
  407. img.removeAttr("class").css({
  408. width: 72,
  409. display: "inline-block",
  410. "text-align": "center",
  411. "font-weight": "bold",
  412. "margin-left": 2
  413. });
  414. $("img.skillicon", img).removeAttr("class").css({
  415. width: "100%"
  416. });
  417. $("span.skillpoints_label", img).attr("class", "skills-calc-skillpoints_label").css({
  418. display: "inline-block",
  419. position: "relative",
  420. top: -16,
  421. width: "100%",
  422. height: 12,
  423. color: "#ffffff",
  424. "text-align": "center",
  425. "font-size": "9pt",
  426. "text-shadow": "1px 1px 1px rgb(0, 0, 0)",
  427. "background-image": "url('/images/tw2gui/plusminus/plusminus_display_bg2.png')"
  428. });
  429. div.append(img);
  430. this.images[skillType] = img.get(0);
  431. }
  432. this.groupSkills.appendToScrollContentPane(div);
  433. this.groupSkills.appendToScrollContentPane($('<hr style="margin: 12px 0;" />'));
  434. }
  435. return true;
  436. };
  437. Window.prototype.initGroupItems = function() {
  438. var items, j, len, ref, slot;
  439. items = [];
  440. ref = Wear.slots;
  441. for (j = 0, len = ref.length; j < len; j++) {
  442. slot = ref[j];
  443. if (Wear.wear[slot]) {
  444. items.push(Wear.wear[slot].obj);
  445. }
  446. }
  447. this.addItems(items);
  448. return this.repaint();
  449. };
  450. Window.prototype.onButtonCharacterClick = function() {
  451. var content, dlg, ok, self, textfieldName;
  452. self = this;
  453. dlg = new west.gui.Dialog(I18n.tr("dialogs.add_character_items"));
  454. content = $("<div style='margin-top: 10px; text-align: center;'></div>");
  455. content.append((textfieldName = Gui.createTextfield({
  456. size: 25,
  457. label: I18n.tr("labels.character_name")
  458. })).getMainDiv());
  459. ok = function() {
  460. var name;
  461. if (!(name = $.trim(textfieldName.getValue()))) {
  462. return false;
  463. }
  464. self.wnd.showLoader();
  465. return Ajax.remoteCallMode("ranking", "get_data", {
  466. rank: NaN,
  467. search: name = name.toLowerCase(),
  468. tab: "duels"
  469. }, function(json) {
  470. var found, j, len, player, ref;
  471. if (json.error) {
  472. self.wnd.hideLoader();
  473. return (new UserMessage(json.msg, UserMessage.TYPE_ERROR)).show();
  474. }
  475. found = false;
  476. ref = json.ranking;
  477. for (j = 0, len = ref.length; j < len; j++) {
  478. player = ref[j];
  479. found = player.name.toLowerCase() === name;
  480. if (found) {
  481. Ajax.remoteCallMode("profile", "init", {
  482. name: player.name,
  483. playerId: player.id
  484. }, function(resp) {
  485. var items, l, len1, ref1, slot;
  486. if (resp.error) {
  487. self.wnd.hideLoader();
  488. return (new UserMessage(resp.message, UserMessage.TYPE_ERROR)).show();
  489. } else {
  490. items = [];
  491. ref1 = Wear.slots;
  492. for (l = 0, len1 = ref1.length; l < len1; l++) {
  493. slot = ref1[l];
  494. if (resp.wear[slot]) {
  495. items.push(ItemManager.get(resp.wear[slot]));
  496. }
  497. }
  498. self.reset();
  499. self.calculator.level = resp.level;
  500. self.textfieldLevel.setValue(resp.level);
  501. self.addItems(items);
  502. self.repaint();
  503. self.wnd.hideLoader();
  504. }
  505. return true;
  506. });
  507. break;
  508. }
  509. }
  510. if (!found) {
  511. self.wnd.hideLoader();
  512. (new UserMessage(I18n.tr("errors.player_not_found"), UserMessage.TYPE_ERROR)).show();
  513. }
  514. return true;
  515. });
  516. };
  517. textfieldName.getField().keypress(function(e) {
  518. if (e.which === 13 && ok()) {
  519. dlg.hide();
  520. }
  521. return true;
  522. });
  523. dlg.setText(content).addButton("ok", ok).addButton("cancel").show();
  524. textfieldName.getField().focus();
  525. return true;
  526. };
  527. Window.prototype.onButtonAddClick = function() {
  528. var content, dlg, ok, self, textfieldId;
  529. self = this;
  530. dlg = new west.gui.Dialog(I18n.tr("dialogs.add_item"));
  531. content = $('<div style="margin-top: 10px; text-align: center;"><div id="skills-calc-preview-item" style="height: 60px; width: 60px; float: right; border: 1px solid black; border-radius: 4px;" /></div>');
  532. content.append((textfieldId = Gui.createTextfield({
  533. size: 25,
  534. label: I18n.tr("labels.item_id")
  535. })).maxlength(8).getMainDiv());
  536. textfieldId.getItem = function() {
  537. var id;
  538. id = parseInt(this.getValue());
  539. if (isNaN(id)) {
  540. return void 0;
  541. } else {
  542. return ItemManager.get(id);
  543. }
  544. };
  545. ok = function() {
  546. var item;
  547. if (item = textfieldId.getItem()) {
  548. self.addItems([ item ]);
  549. self.repaint();
  550. return true;
  551. } else {
  552. return false;
  553. }
  554. };
  555. dlg.setText(content).addButton("ok", ok).addButton("cancel").show();
  556. textfieldId.getField().keypress(function(e) {
  557. if (e.which === 13 && ok()) {
  558. dlg.hide();
  559. }
  560. return true;
  561. }).keyup(function(e) {
  562. var item, preview;
  563. preview = $("#skills-calc-preview-item", content).empty();
  564. if (item = textfieldId.getItem()) {
  565. item = new tw2widget.InventoryItem(item);
  566. preview.append($(item.getMainDiv()).css({
  567. "float": "none"
  568. }));
  569. }
  570. return true;
  571. }).focus();
  572. return true;
  573. };
  574. Window.prototype.onButtonResetClick = function() {
  575. return this.reset();
  576. };
  577. Window.prototype.onCheckboxBonusClick = function(state) {
  578. return this.repaint();
  579. };
  580. Window.prototype.onCheckboxSkillsClick = function(state) {
  581. this.recalc();
  582. return this.repaint();
  583. };
  584. Window.prototype.addItems = function(items) {
  585. var item, j, len, self;
  586. self = this;
  587. for (j = 0, len = items.length; j < len; j++) {
  588. item = items[j];
  589. this.removeItem(item);
  590. this.items[item.type] = new tw2widget.InventoryItem(item);
  591. $(this.items[item.type].getMainDiv()).css({
  592. "float": "none",
  593. display: "inline-block"
  594. }).on("click", function(e) {
  595. if (!e.shiftKey) {
  596. item = ItemManager.get($(e.target).data("itemId"));
  597. if (item && self.removeItem(item)) {
  598. self.repaint();
  599. }
  600. }
  601. return true;
  602. });
  603. this.calculator.sumItem(item);
  604. this.groupItems.appendToScrollContentPane($(this.items[item.type].getMainDiv()));
  605. }
  606. return true;
  607. };
  608. Window.prototype.removeItem = function(item) {
  609. if (this.items[item.type]) {
  610. this.calculator.subItem(this.items[item.type].obj);
  611. $(this.items[item.type].getMainDiv()).remove();
  612. delete this.items[item.type];
  613. return true;
  614. } else {
  615. return false;
  616. }
  617. };
  618. Window.prototype.recalc = function() {
  619. var item, ref, ref1, skill, type, value;
  620. this.calculator.reset();
  621. ref = this.items;
  622. for (type in ref) {
  623. item = ref[type];
  624. this.calculator.sumItem(item.obj);
  625. }
  626. if (this.checkboxSkills.isSelected()) {
  627. ref1 = CharacterSkills.skills;
  628. for (skill in ref1) {
  629. value = ref1[skill];
  630. this.calculator.calcSkill(skill, value.points, ItemCalculator.SUM_OP);
  631. }
  632. }
  633. return true;
  634. };
  635. Window.prototype.repaint = function() {
  636. var health, min_health, result, skill, value;
  637. result = this.checkboxBonus.isSelected() ? this.calculator.resultWithBonus() : this.calculator.result;
  638. for (skill in result) {
  639. value = result[skill];
  640. if (this.images[skill]) {
  641. $("span.skills-calc-skillpoints_label", this.images[skill]).text(value);
  642. }
  643. }
  644. min_health = this.calculator.level * 10 + 90;
  645. health = {
  646. normal: format_number(min_health + result.health * 10),
  647. solder: format_number(min_health + result.health * 15),
  648. solderBonus: format_number(min_health + result.health * 20),
  649. toString: function() {
  650. return this.normal + " / " + this.solder + " / " + this.solderBonus;
  651. }
  652. };
  653. this.labelHealth.text(I18n.tr("labels.health") + ": " + health.toString());
  654. return true;
  655. };
  656. Window.prototype.reset = function() {
  657. var item, ref, type;
  658. ref = this.items;
  659. for (type in ref) {
  660. item = ref[type];
  661. $(item.getMainDiv()).remove();
  662. }
  663. $("span.skills-calc-skillpoints_label", this.groupSkills.getMainDiv()).text("0");
  664. this.items = {};
  665. this.calculator.reset();
  666. this.calculator.level = Character.level;
  667. this.textfieldLevel.setValue(Character.level);
  668. this.labelHealth.text(I18n.tr("labels.health") + ": 0 / 0 / 0");
  669. this.checkboxBonus.setSelected(false, true);
  670. this.checkboxSkills.setSelected(false, true);
  671. return true;
  672. };
  673. return Window;
  674. }();
  675. ItemCalculator = function() {
  676. function ItemCalculator() {
  677. this.level = 1;
  678. this._bonusExtractor = new west.item.BonusExtractor({
  679. level: this.level
  680. });
  681. this._resultStack = [];
  682. this.reset();
  683. }
  684. ItemCalculator.SUM_OP = "sum";
  685. ItemCalculator.SUB_OP = "sub";
  686. ItemCalculator.prototype.sum = function(skill, value) {
  687. return this.result[skill] += value;
  688. };
  689. ItemCalculator.prototype.sub = function(skill, value) {
  690. return this.result[skill] -= value;
  691. };
  692. ItemCalculator.prototype.sumItem = function(item) {
  693. return this.calcItem(item, ItemCalculator.SUM_OP);
  694. };
  695. ItemCalculator.prototype.subItem = function(item) {
  696. return this.calcItem(item, ItemCalculator.SUB_OP);
  697. };
  698. ItemCalculator.prototype.calcItem = function(item, operator) {
  699. if (item.bonus.attributes) {
  700. this.calcAttributes(item.bonus.attributes, operator);
  701. }
  702. if (item.bonus.skills) {
  703. this.calcSkills(item.bonus.skills, operator);
  704. }
  705. if (item.bonus.item) {
  706. this.calcBonuses(item.bonus.item, operator);
  707. }
  708. if (item.item_level > 0) {
  709. this.calcDifference(item.bonus.item, item.item_level, operator);
  710. }
  711. if (item.set) {
  712. this.calcSet(item.set, operator);
  713. }
  714. return this.result;
  715. };
  716. ItemCalculator.prototype.calcAttribute = function(attr, value, operator) {
  717. var j, len, skill, skills;
  718. skills = CharacterSkills.skillKeys4Attr[attr];
  719. for (j = 0, len = skills.length; j < len; j++) {
  720. skill = skills[j];
  721. this[operator](skill, value);
  722. }
  723. return this.result;
  724. };
  725. ItemCalculator.prototype.calcAttributes = function(attrs, operator) {
  726. var attr, value;
  727. for (attr in attrs) {
  728. value = attrs[attr];
  729. if (this.isAttribute(attr)) {
  730. this.calcAttribute(attr, value, operator);
  731. }
  732. }
  733. return this.result;
  734. };
  735. ItemCalculator.prototype.calcSkill = function(skill, value, operator) {
  736. return this[operator](skill, value);
  737. };
  738. ItemCalculator.prototype.calcSkills = function(skills, operator) {
  739. var skill, value;
  740. for (skill in skills) {
  741. value = skills[skill];
  742. if (this.isSkill(skill)) {
  743. this.calcSkill(skill, value, operator);
  744. }
  745. }
  746. return this.result;
  747. };
  748. ItemCalculator.prototype.calcDifference = function(bonuses, itemLevel, operator) {
  749. var bonus, diff, j, len;
  750. for (j = 0, len = bonuses.length; j < len; j++) {
  751. bonus = bonuses[j];
  752. diff = this._bonusExtractor.getCharacterItemValueDifferenceToItemLevel(bonus, 0, itemLevel);
  753. if (diff <= 0) {
  754. continue;
  755. }
  756. switch (bonus.bonus.type) {
  757. case "attribute":
  758. this.calcAttribute(bonus.bonus.name, diff, operator);
  759. break;
  760. case "skill":
  761. this.calcSkill(bonus.bonus.name, diff, operator);
  762. }
  763. }
  764. return this.result;
  765. };
  766. ItemCalculator.prototype.calcBonuses = function(bonuses, operator) {
  767. var bonus, j, len;
  768. this._bonusExtractor.character.level = this.level;
  769. for (j = 0, len = bonuses.length; j < len; j++) {
  770. bonus = bonuses[j];
  771. this.calcSkills(this._bonusExtractor.getAffectedSkills(bonus), operator);
  772. }
  773. return this.result;
  774. };
  775. ItemCalculator.prototype.calcSet = function(set, operator) {
  776. switch (operator) {
  777. case ItemCalculator.SUM_OP:
  778. this.itemSets[set] = (this.itemSets[set] || 0) + 1;
  779. break;
  780. case ItemCalculator.SUB_OP:
  781. if (this.itemSets[set] && (this.itemSets[set] -= 1) <= 0) {
  782. delete this.itemSets[set];
  783. }
  784. }
  785. return this.result;
  786. };
  787. ItemCalculator.prototype.isAttribute = function(attr) {
  788. return CharacterSkills.allAttrKeys.indexOf(attr) !== -1;
  789. };
  790. ItemCalculator.prototype.isSkill = function(skill) {
  791. return CharacterSkills.allSkillKeys.indexOf(skill) !== -1;
  792. };
  793. ItemCalculator.prototype.reset = function() {
  794. var j, len, ref, skill;
  795. this.itemSets = {};
  796. this.result = {};
  797. ref = CharacterSkills.allSkillKeys;
  798. for (j = 0, len = ref.length; j < len; j++) {
  799. skill = ref[j];
  800. this.result[skill] = 0;
  801. }
  802. return this.result;
  803. };
  804. ItemCalculator.prototype.resultWithBonus = function() {
  805. var b, bonus, cb, found, i, itemCount, itemSet, j, l, len, len1, len2, m, n, name1, name2, ref, ref1, ref2, ref3, result, setId, stage, value;
  806. this.pushResult();
  807. this._bonusExtractor.level = this.level;
  808. bonus = {};
  809. ref = this.itemSets;
  810. for (setId in ref) {
  811. itemCount = ref[setId];
  812. itemSet = west.storage.ItemSetManager.get(setId);
  813. for (i = j = 1, ref1 = itemCount; 1 <= ref1 ? j <= ref1 : j >= ref1; i = 1 <= ref1 ? ++j : --j) {
  814. stage = itemSet.bonus[i];
  815. if (stage) {
  816. for (l = 0, len = stage.length; l < len; l++) {
  817. b = stage[l];
  818. switch (b.type) {
  819. case "attribute":
  820. case "skill":
  821. bonus[name1 = b.type] || (bonus[name1] = {});
  822. bonus[b.type][b.name] = (bonus[b.type][b.name] || 0) + b.value;
  823. break;
  824. case "character":
  825. bonus[name2 = b.type] || (bonus[name2] = []);
  826. found = false;
  827. ref2 = bonus[b.type];
  828. for (i = m = 0, len1 = ref2.length; m < len1; i = ++m) {
  829. cb = ref2[i];
  830. found = cb.type === b.bonus.type && cb.name === b.bonus.name && cb.key === b.key && cb.roundingMethod === b.roundingMethod;
  831. if (found) {
  832. bonus[b.type][i].value += b.bonus.value;
  833. break;
  834. }
  835. }
  836. if (!found) {
  837. bonus[b.type].push({
  838. type: b.bonus.type,
  839. name: b.bonus.name,
  840. value: b.bonus.value,
  841. key: b.key,
  842. roundingMethod: b.roundingMethod
  843. });
  844. }
  845. }
  846. }
  847. }
  848. }
  849. }
  850. if (bonus.attribute) {
  851. this.calcAttributes(bonus.attribute, ItemCalculator.SUM_OP);
  852. }
  853. if (bonus.skill) {
  854. this.calcSkills(bonus.skill, ItemCalculator.SUM_OP);
  855. }
  856. if (bonus.character) {
  857. ref3 = bonus.character;
  858. for (n = 0, len2 = ref3.length; n < len2; n++) {
  859. b = ref3[n];
  860. if (b.key === "level") {
  861. value = this._bonusExtractor.getRoundedValue(b.value * this.level, b.roundingMethod);
  862. switch (b.type) {
  863. case "attribute":
  864. this.calcAttribute(b.name, value, ItemCalculator.SUM_OP);
  865. break;
  866. case "skill":
  867. this.calcSkill(b.name, value, ItemCalculator.SUM_OP);
  868. }
  869. }
  870. }
  871. }
  872. result = this.result;
  873. this.popResult();
  874. return result;
  875. };
  876. ItemCalculator.prototype.pushResult = function() {
  877. return this._resultStack.push($.extend(true, {}, this.result));
  878. };
  879. ItemCalculator.prototype.popResult = function() {
  880. return this.result = this._resultStack.pop();
  881. };
  882. return ItemCalculator;
  883. }();
  884. return SkillsCalc;
  885. }();
  886. $(document).ready(function() {
  887. var api, calc;
  888. api = TheWestApi.register(SkillsCalc.ID, SkillsCalc.NAME, SkillsCalc.MIN_GAME_VERSION, SkillsCalc.MAX_GAME_VERSION, SkillsCalc.AUTHOR, SkillsCalc.WEB_SITE);
  889. api.setGui("Copyrights, changelog and other details see <a href='" + SkillsCalc.WEB_SITE + "' target='_blank'>here</a>.");
  890. calc = null;
  891. EventHandler.listen([ "itemmanager_loaded", "itemsetmanager_loaded" ], function() {
  892. if (calc === null && ItemManager.isLoaded() && west.storage.ItemSetManager.isLoaded()) {
  893. calc = new SkillsCalc;
  894. }
  895. return EventHandler.ONE_TIME_EVENT;
  896. });
  897. return true;
  898. });
  899. return true;
  900. });

QingJ © 2025

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