Greasy Fork镜像 支持简体中文。

The West - Skills Calc

Calculates sum of skills obtained from items

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

QingJ © 2025

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