Greasy Fork is available in English.

The West - Skills Calc

Calculates and displays sum of skills obtained from items (including bonuses from sets and character's per-level attributes and skills)

Verzia zo dňa 07.03.2015. Pozri najnovšiu verziu.

// ==UserScript==
// @namespace		https://greasyfork.org/users/8637
// @name        	The West - Skills Calc
// @author      	neversleep1911
// @description		Calculates and displays sum of skills obtained from items (including bonuses from sets and character's per-level attributes and skills)
// @include     	http://*.the-west.*/game.php*
// @grant       	none
// @version     	2.0.1
// @copyright		Copyright (c) 2015 neversleep1911 (full list of contributors/translators see here: https://greasyfork.org/scripts/7829)
// @license			MIT (http://opensource.org/licenses/MIT)
// ==/UserScript==

(function(func) {
    var script;
    script = document.createElement("script");
    script.setAttribute("type", "text/javascript");
    script.textContent = "(" + func.toString() + ")();";
    document.body.appendChild(script);
    document.body.removeChild(script);
    return true;
})(function() {
    var I18n, TWSkillsCalc;
    I18n = function() {
        var DEFAULT_LANGUAGE, STRINGS, language;
        function I18n() {}
        DEFAULT_LANGUAGE = "en_US";
        STRINGS = {
            en_US: {
                dialogs: {
                    add_item: "Add item",
                    add_character_items: "Character's items"
                },
                groups: {
                    skills: "Skills",
                    items: "Items"
                },
                buttons: {
                    character: "Character",
                    add: "Add",
                    reset: "Reset"
                },
                checkboxes: {
                    show_bonus: "Show bonus",
                    show_skills: "Show my skills"
                },
                labels: {
                    level: "Level",
                    item_id: "Item ID",
                    character_name: "Character's name",
                    health: "Health"
                },
                tooltip: {
                    health: "Normal / Solder / Solder with bonus"
                },
                errors: {
                    player_not_found: "Player not found!"
                }
            },
            pl_PL: {
                dialogs: {
                    add_item: "Dodaj przedmiot",
                    add_character_items: "Przedmioty gracza"
                },
                groups: {
                    skills: "Umiejętności",
                    items: "Przedmioty"
                },
                buttons: {
                    character: "Gracz",
                    add: "Dodaj",
                    reset: "Reset"
                },
                checkboxes: {
                    show_bonus: "Pokaż bonus",
                    show_skills: "Pokaż moje umiejętności"
                },
                labels: {
                    level: "Level",
                    item_id: "ID przedmiotu",
                    character_name: "Nazwa gracza",
                    health: "Życie"
                },
                tooltip: {
                    health: "Normalny / Żołnierz / Żołnierz z bonusem"
                },
                errors: {
                    player_not_found: "Gracz nie znaleziony!"
                }
            },
            ru_RU: {
                dialogs: {
                    add_item: "Добавить предмет",
                    add_character_items: "Предметы персонажа"
                },
                groups: {
                    skills: "Навыки",
                    items: "Предметы"
                },
                buttons: {
                    character: "Персонаж",
                    add: "Добавить",
                    reset: "Сбросить"
                },
                checkboxes: {
                    show_bonus: "Показывать бонусы",
                    show_skills: "Показывать мои навыки"
                },
                labels: {
                    level: "Уровень",
                    item_id: "ID предмета",
                    character_name: "Имя персонажа",
                    health: "Здоровье"
                },
                tooltip: {
                    health: "Минимум / Солдат / Солдат с бонусом"
                },
                errors: {
                    player_not_found: "Игрок не найден!"
                }
            }
        };
        language = DEFAULT_LANGUAGE;
        I18n.language = function() {
            return language;
        };
        I18n.setLanguage = function(lang) {
            return language = STRINGS[lang] ? lang : DEFAULT_LANGUAGE;
        };
        I18n.tr = function(id) {
            var string;
            string = STRINGS[language];
            $(id.split(".")).each(function(k, v) {
                return (string = string[v]) !== void 0;
            });
            return string || id;
        };
        return I18n;
    }();
    TWSkillsCalc = function() {
        var ItemCalculator, Window;
        TWSkillsCalc.prototype.NAME = "Skills Calc";
        TWSkillsCalc.prototype.MENU_BUTTON_IMAGE = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAZCAIAAAD8NuoTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QQICBgbVC0rcwAACI5JREFUSMel10tvXFcBAODzuq+5987MHY/nYTvx24lj13k0KQ5NmjR90ELVVoIKSitARWxAFSyqskKskLphwQKJFUKilUCIBVIXFVSN0tKmTVPbbdwkjhOPXzPjGd953vc9557Dgp8wf+Dbf/A3PzpZr9m5wum7ew+E45maEau+nphaOgwYzBqWE0WdXldLWF/iFiCAiYyebXa9nUbbjkNAcN5IJ0FUzmpL87l6LcyXypW9Wux76WzOdblhcaIBHqpZM+X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EDwlxePTYxl9lf3s6M5WVc5hI1PbxwvFeauvPLFtfe3q3sCNLGob9r+5YI8CHXzrt30BXnh4kSvc6iloCYRjzFM0KyhDClS7NE2FRAIxrkI6epWK+qEw4WMbhGc0/lBzTzxjDR9KuSqXhrLl5TJscKl+VOxWB2QmpuckVUB//76+UOReevtf9u+NDWUcnicVlXap1wDQQB1whAGcSQ4QBzLUhxxCLR0yqUBTyK7z9OUT0zpjz991v16ZfmRea4u/fHP7+xGIiOritZXuc7jSFItGrbqkRg1VcejwsgYMQNy3Le5NGRmM1Jlx85IYqMVLS2P/mSpWK3uwN+9/EgaoY1Go+6y0VKx7UT1jud6Hog9azivQZ4GwJCArOB0SklZWJWBFwotV/Tttt13uGg9dWFaTrpr2xZ1SYaA7S7dPTwYGRn1YlFttnuURf12TtUky8i5sJghHg7KukZ0nM7+/zsAkbGuvSM1e5OPphNjaGd3/38JylRK90rXAwAAAABJRU5ErkJggg==";
        TWSkillsCalc.prototype.windows = {};
        function TWSkillsCalc() {
            var menuButton, self;
            self = this;
            I18n.setLanguage(Game.locale);
            TheWestApi.register("tw_skills_calc", this.NAME, "2.17", Game.version.toString(), "neversleep1911", "").setGui("Copyrights, changelog and other details see <a href='https://greasyfork.org/scripts/7829'>here</a>.");
            menuButton = $("<div class='menulink' title='" + this.NAME + "' />");
            menuButton.css("background-image", "url(" + this.MENU_BUTTON_IMAGE + ")");
            menuButton.hover(function() {
                $(this).css("background-position", "-25px 0px");
                return true;
            }, function() {
                $(this).css("background-position", "0px 0px");
                return true;
            }).on("click", function() {
                self.createWindow();
                return false;
            });
            $("div#ui_menubar").append($('<div class="ui_menucontainer" />').append(menuButton).append('<div class="menucontainer_bottom" />'));
        }
        TWSkillsCalc.prototype.createWindow = function() {
            var self, wndId;
            self = this;
            while (true) {
                wndId = Math.ceil(Math.random() * 1024);
                if (!this.windows[wndId]) {
                    break;
                }
            }
            this.windows[wndId] = new Window({
                id: wndId,
                title: this.NAME,
                miniTitle: this.NAME
            });
            this.windows[wndId].onDestroy = function(wnd) {
                delete self.windows[wnd.id];
                return true;
            };
            return true;
        };
        Window = function() {
            function Window(options) {
                var self;
                self = this;
                this.images = {};
                this.items = {};
                this.calculator = new ItemCalculator();
                this.calculator.level = Character.level;
                this.id = options.id;
                this.wnd = wman.open("skills-calc-window-" + options.id, null, "noreload");
                this.wnd.setTitle(options.title);
                this.wnd.setMiniTitle(options.miniTitle);
                this.wnd.addEventListener("WINDOW_DESTROY", function() {
                    if (self.onDestroy) {
                        return self.onDestroy(self);
                    } else {
                        return true;
                    }
                });
                this.wnd.appendToContentPane((this.groupSkills = this.createGroup({
                    id: "skills",
                    title: I18n.tr("groups.skills"),
                    css: {
                        width: 402,
                        position: "absolute"
                    },
                    scrollPane: {
                        css: {
                            height: 264
                        }
                    }
                })).getMainDiv());
                this.wnd.appendToContentPane((this.groupItems = this.createGroup({
                    id: "items",
                    title: I18n.tr("groups.items"),
                    css: {
                        left: 400,
                        width: 294
                    },
                    scrollPane: {
                        css: {
                            height: 264
                        }
                    }
                })).getMainDiv());
                this.wnd.appendToContentPane(this.createButton({
                    text: I18n.tr("buttons.reset"),
                    css: {
                        left: 592,
                        top: 342,
                        position: "absolute"
                    },
                    onclick: function(button, data) {
                        return self.onButtonResetClick(button, data);
                    }
                }).getMainDiv());
                this.wnd.appendToContentPane(this.createButton({
                    text: I18n.tr("buttons.add"),
                    css: {
                        left: 490,
                        top: 342,
                        position: "absolute"
                    },
                    onclick: function(button, data) {
                        return self.onButtonAddClick(button, data);
                    }
                }).getMainDiv());
                this.wnd.appendToContentPane(this.createButton({
                    text: I18n.tr("buttons.character"),
                    css: {
                        left: 388,
                        top: 342,
                        position: "absolute"
                    },
                    onclick: function(button, data) {
                        return self.onButtonCharacterClick(button, data);
                    }
                }).getMainDiv());
                this.wnd.appendToContentPane((this.checkboxBonus = this.createCheckbox({
                    text: I18n.tr("checkboxes.show_bonus"),
                    css: {
                        left: 2,
                        top: 324,
                        position: "absolute"
                    },
                    onclick: function(state) {
                        return self.onCheckboxBonusClick(state);
                    }
                })).getMainDiv());
                this.wnd.appendToContentPane((this.checkboxSkills = this.createCheckbox({
                    text: I18n.tr("checkboxes.show_skills"),
                    css: {
                        left: 2,
                        top: 350,
                        position: "absolute"
                    },
                    onclick: function(state) {
                        return self.onCheckboxSkillsClick(state);
                    }
                })).getMainDiv());
                this.wnd.appendToContentPane((this.textfieldLevel = this.createTextfield({
                    size: 6,
                    label: I18n.tr("labels.level"),
                    value: this.calculator.level,
                    css: {
                        left: 180,
                        top: 320,
                        position: "absolute"
                    }
                })).getMainDiv());
                this.wnd.appendToContentPane(this.labelHealth = $("<span />").css({
                    position: "absolute",
                    left: 180,
                    top: 352
                }).attr("title", I18n.tr("tooltip.health")));
                this.textfieldLevel.onlyNumeric().getField().keyup(function(e) {
                    var level;
                    level = parseInt(self.textfieldLevel.getValue());
                    if (!isNaN(level) && level > 0) {
                        self.calculator.level = level;
                        self.recalc();
                        self.repaint();
                    }
                    return true;
                });
                this.initGroupSkills();
                this.initGroupItems();
            }
            Window.prototype.createGroup = function(options) {
                var content, group, scrollPane;
                group = new west.gui.Groupframe("", "<div class='skills-calc-" + options.id + "'></div>");
                $(group.getMainDiv()).css(options.css);
                scrollPane = new west.gui.Scrollpane();
                $(scrollPane.getMainDiv()).css(options.scrollPane.css);
                content = $(".skills-calc-" + options.id, group.getMainDiv());
                if (options.title) {
                    content.append($("<h2>" + options.title + "</h2><hr style='margin-top: 2px; margin-bottom: 4px;' />"));
                }
                content.append(scrollPane.getMainDiv());
                group.scrollPane = scrollPane;
                group.appendToScrollContentPane = function(content) {
                    scrollPane.appendContent(content);
                    return group;
                };
                return group;
            };
            Window.prototype.createButton = function(options) {
                var button;
                button = new west.gui.Button(options.text);
                button.click(options.onclick);
                $(button.getMainDiv()).css(options.css);
                return button;
            };
            Window.prototype.createCheckbox = function(options) {
                var checkbox;
                checkbox = new west.gui.Checkbox(options.text, "", options.onclick);
                $(checkbox.getMainDiv()).css(options.css);
                return checkbox;
            };
            Window.prototype.createTextfield = function(options) {
                var field;
                field = new west.gui.Textfield();
                field.setSize(options.size);
                field.setLabel($("<span>" + options.label + "</span>"));
                if (options.value) {
                    field.setValue(options.value);
                }
                if (options.css) {
                    $(field.getMainDiv()).css(options.css);
                }
                return field;
            };
            Window.prototype.initGroupSkills = function() {
                var attr, attrs, div, img, skill, skillType, skills, _i, _j, _len, _len1;
                attrs = CharacterSkills.allAttrKeys;
                for (_i = 0, _len = attrs.length; _i < _len; _i++) {
                    attr = attrs[_i];
                    div = $('<div style="height: 41px;" />');
                    skills = CharacterSkills.skillKeys4Attr[attr];
                    for (_j = 0, _len1 = skills.length; _j < _len1; _j++) {
                        skillType = skills[_j];
                        skill = new Skill(skillType);
                        img = skill.getSkillImage();
                        img.removeAttr("class").css({
                            width: 72,
                            display: "inline-block",
                            "text-align": "center",
                            "font-weight": "bold",
                            "margin-left": 2
                        });
                        $("img.skillicon", img).removeAttr("class").css({
                            width: "100%"
                        });
                        $("span.skillpoints_label", img).attr("class", "skills-calc-skillpoints_label").css({
                            display: "inline-block",
                            position: "relative",
                            top: -16,
                            width: "100%",
                            height: 12,
                            color: "#ffffff",
                            "text-align": "center",
                            "font-size": "9pt",
                            "text-shadow": "1px 1px 1px rgb(0, 0, 0)",
                            "background-image": "url('http://westzz.innogamescdn.com/images/tw2gui/plusminus/plusminus_display_bg2.png')"
                        });
                        div.append(img);
                        this.images[skillType] = img.get(0);
                    }
                    this.groupSkills.appendToScrollContentPane(div);
                    this.groupSkills.appendToScrollContentPane($('<hr style="margin: 12px 0;" />'));
                }
                return true;
            };
            Window.prototype.initGroupItems = function() {
                var items, slot, _i, _len, _ref;
                items = [];
                _ref = Wear.slots;
                for (_i = 0, _len = _ref.length; _i < _len; _i++) {
                    slot = _ref[_i];
                    if (Wear.wear[slot]) {
                        items.push(Wear.wear[slot].obj);
                    }
                }
                this.addItems(items);
                return this.repaint();
            };
            Window.prototype.onButtonCharacterClick = function() {
                var content, dlg, ok, self, textfieldName;
                self = this;
                dlg = new west.gui.Dialog(I18n.tr("dialogs.add_character_items"));
                content = $("<div style='margin-top: 10px; text-align: center;'></div>");
                content.append((textfieldName = this.createTextfield({
                    size: 25,
                    label: I18n.tr("labels.character_name")
                })).getMainDiv());
                ok = function() {
                    var name;
                    if (!(name = $.trim(textfieldName.getValue()))) {
                        return false;
                    }
                    self.wnd.showLoader();
                    return Ajax.remoteCallMode("ranking", "get_data", {
                        rank: NaN,
                        search: name = name.toLowerCase(),
                        tab: "duels"
                    }, function(json) {
                        var found, player, _i, _len, _ref;
                        if (json.error) {
                            self.wnd.hideLoader();
                            return new UserMessage(json.msg, UserMessage.TYPE_ERROR).show();
                        }
                        found = false;
                        _ref = json.ranking;
                        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
                            player = _ref[_i];
                            found = player.name.toLowerCase() === name;
                            if (found) {
                                Ajax.remoteCallMode("profile", "init", {
                                    name: player.name,
                                    playerId: player.id
                                }, function(resp) {
                                    var items, slot, _j, _len1, _ref1;
                                    if (resp.error) {
                                        self.wnd.hideLoader();
                                        return new UserMessage(resp.message, UserMessage.TYPE_ERROR).show();
                                    } else {
                                        items = [];
                                        _ref1 = Wear.slots;
                                        for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
                                            slot = _ref1[_j];
                                            if (resp.wear[slot]) {
                                                items.push(ItemManager.get(resp.wear[slot]));
                                            }
                                        }
                                        self.reset();
                                        self.calculator.level = resp.level;
                                        self.textfieldLevel.setValue(resp.level);
                                        self.addItems(items);
                                        self.repaint();
                                        self.wnd.hideLoader();
                                    }
                                    return true;
                                });
                                break;
                            }
                        }
                        if (!found) {
                            self.wnd.hideLoader();
                            new UserMessage(I18n.tr("errors.player_not_found"), UserMessage.TYPE_ERROR).show();
                        }
                        return true;
                    });
                };
                textfieldName.getField().keypress(function(e) {
                    if (e.which === 13 && ok()) {
                        dlg.hide();
                    }
                    return true;
                });
                dlg.setText(content).addButton("ok", ok).addButton("cancel").show();
                textfieldName.getField().focus();
                return true;
            };
            Window.prototype.onButtonAddClick = function() {
                var content, dlg, ok, self, textfieldId;
                self = this;
                dlg = new west.gui.Dialog(I18n.tr("dialogs.add_item"));
                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>');
                content.append((textfieldId = this.createTextfield({
                    size: 25,
                    label: I18n.tr("labels.item_id")
                })).maxlength(8).getMainDiv());
                textfieldId.getItem = function() {
                    var id;
                    id = parseInt(this.getValue());
                    if (isNaN(id)) {
                        return void 0;
                    } else {
                        return ItemManager.get(id);
                    }
                };
                ok = function() {
                    var item;
                    if (item = textfieldId.getItem()) {
                        self.addItems([ item ]);
                        self.repaint();
                        return true;
                    } else {
                        return false;
                    }
                };
                dlg.setText(content).addButton("ok", ok).addButton("cancel").show();
                textfieldId.getField().keypress(function(e) {
                    if (e.which === 13 && ok()) {
                        dlg.hide();
                    }
                    return true;
                }).keyup(function(e) {
                    var item, preview;
                    preview = $("#skills-calc-preview-item", content).empty();
                    if (item = textfieldId.getItem()) {
                        item = new tw2widget.InventoryItem(item);
                        preview.append($(item.getMainDiv()).css({
                            "float": "none"
                        }));
                    }
                    return true;
                }).focus();
                return true;
            };
            Window.prototype.onButtonResetClick = function() {
                return this.reset();
            };
            Window.prototype.onCheckboxBonusClick = function(state) {
                return this.repaint();
            };
            Window.prototype.onCheckboxSkillsClick = function(state) {
                this.recalc();
                return this.repaint();
            };
            Window.prototype.addItems = function(items) {
                var item, self, _i, _len;
                self = this;
                for (_i = 0, _len = items.length; _i < _len; _i++) {
                    item = items[_i];
                    this.removeItem(item);
                    this.items[item.type] = new tw2widget.InventoryItem(item);
                    $(this.items[item.type].getMainDiv()).css({
                        "float": "none",
                        display: "inline-block"
                    }).on("click", function(e) {
                        if (!e.shiftKey) {
                            item = ItemManager.get($(e.target).data("itemId"));
                            if (item && self.removeItem(item)) {
                                self.repaint();
                            }
                        }
                        return true;
                    });
                    this.calculator.sumItem(item);
                    this.groupItems.appendToScrollContentPane($(this.items[item.type].getMainDiv()));
                }
                return true;
            };
            Window.prototype.removeItem = function(item) {
                if (this.items[item.type]) {
                    this.calculator.subItem(this.items[item.type].obj);
                    $(this.items[item.type].getMainDiv()).remove();
                    delete this.items[item.type];
                    return true;
                } else {
                    return false;
                }
            };
            Window.prototype.recalc = function() {
                var item, skill, type, value, _ref, _ref1;
                this.calculator.reset();
                _ref = this.items;
                for (type in _ref) {
                    item = _ref[type];
                    this.calculator.sumItem(item.obj);
                }
                if (this.checkboxSkills.isSelected()) {
                    _ref1 = CharacterSkills.skills;
                    for (skill in _ref1) {
                        value = _ref1[skill];
                        this.calculator.calcSkill(skill, value.points, ItemCalculator.SUM_OP);
                    }
                }
                return true;
            };
            Window.prototype.repaint = function() {
                var health, min_health, result, skill, value;
                result = this.checkboxBonus.isSelected() ? this.calculator.resultWithBonus() : this.calculator.result;
                for (skill in result) {
                    value = result[skill];
                    if (this.images[skill]) {
                        $("span.skills-calc-skillpoints_label", this.images[skill]).text(value);
                    }
                }
                min_health = this.calculator.level * 10 + 90;
                health = {
                    normal: format_number(min_health + result.health * 10),
                    solder: format_number(min_health + result.health * 15),
                    solderBonus: format_number(min_health + result.health * 20),
                    toString: function() {
                        return "" + this.normal + " / " + this.solder + " / " + this.solderBonus;
                    }
                };
                this.labelHealth.text("" + I18n.tr("labels.health") + ": " + health.toString());
                return true;
            };
            Window.prototype.reset = function() {
                var item, type, _ref;
                _ref = this.items;
                for (type in _ref) {
                    item = _ref[type];
                    $(item.getMainDiv()).remove();
                }
                $("span.skills-calc-skillpoints_label", this.groupSkills.getMainDiv()).text("0");
                this.items = {};
                this.calculator.reset();
                this.calculator.level = Character.level;
                this.textfieldLevel.setValue(Character.level);
                this.labelHealth.text("" + I18n.tr("labels.health") + ": 0 / 0 / 0");
                this.checkboxBonus.setSelected(false, true);
                this.checkboxSkills.setSelected(false, true);
                return true;
            };
            return Window;
        }();
        ItemCalculator = function() {
            ItemCalculator.SUM_OP = "sum";
            ItemCalculator.SUB_OP = "sub";
            function ItemCalculator() {
                this.level = 1;
                this._bonusExtractor = new west.item.BonusExtractor({
                    level: this.level
                });
                this._resultStack = [];
                this.reset();
            }
            ItemCalculator.prototype.sum = function(skill, value) {
                return this.result[skill] += value;
            };
            ItemCalculator.prototype.sub = function(skill, value) {
                return this.result[skill] -= value;
            };
            ItemCalculator.prototype.sumItem = function(item) {
                return this.calcItem(item, ItemCalculator.SUM_OP);
            };
            ItemCalculator.prototype.subItem = function(item) {
                return this.calcItem(item, ItemCalculator.SUB_OP);
            };
            ItemCalculator.prototype.calcItem = function(item, operator) {
                if (item.bonus.attributes) {
                    this.calcAttributes(item.bonus.attributes, operator);
                }
                if (item.bonus.skills) {
                    this.calcSkills(item.bonus.skills, operator);
                }
                if (item.bonus.item) {
                    this.calcBonuses(item.bonus.item, operator);
                }
                if (item.set) {
                    this.calcSet(item.set, operator);
                }
                return this.result;
            };
            ItemCalculator.prototype.calcAttribute = function(attr, value, operator) {
                var skill, skills, _i, _len;
                skills = CharacterSkills.skillKeys4Attr[attr];
                for (_i = 0, _len = skills.length; _i < _len; _i++) {
                    skill = skills[_i];
                    this[operator](skill, value);
                }
                return this.result;
            };
            ItemCalculator.prototype.calcAttributes = function(attrs, operator) {
                var attr, value;
                for (attr in attrs) {
                    value = attrs[attr];
                    if (this.isAttribute(attr)) {
                        this.calcAttribute(attr, value, operator);
                    }
                }
                return this.result;
            };
            ItemCalculator.prototype.calcSkill = function(skill, value, operator) {
                return this[operator](skill, value);
            };
            ItemCalculator.prototype.calcSkills = function(skills, operator) {
                var skill, value;
                for (skill in skills) {
                    value = skills[skill];
                    if (this.isSkill(skill)) {
                        this.calcSkill(skill, value, operator);
                    }
                }
                return this.result;
            };
            ItemCalculator.prototype.calcBonuses = function(bonuses, operator) {
                var bonus, _i, _len;
                this._bonusExtractor.character.level = this.level;
                for (_i = 0, _len = bonuses.length; _i < _len; _i++) {
                    bonus = bonuses[_i];
                    this.calcSkills(this._bonusExtractor.getAffectedSkills(bonus), operator);
                }
                return this.result;
            };
            ItemCalculator.prototype.calcSet = function(set, operator) {
                switch (operator) {
                  case ItemCalculator.SUM_OP:
                    this.itemSets[set] = (this.itemSets[set] || 0) + 1;
                    break;

                  case ItemCalculator.SUB_OP:
                    if (this.itemSets[set] && (this.itemSets[set] -= 1) <= 0) {
                        delete this.itemSets[set];
                    }
                }
                return this.result;
            };
            ItemCalculator.prototype.isAttribute = function(attr) {
                return CharacterSkills.allAttrKeys.indexOf(attr) !== -1;
            };
            ItemCalculator.prototype.isSkill = function(skill) {
                return CharacterSkills.allSkillKeys.indexOf(skill) !== -1;
            };
            ItemCalculator.prototype.reset = function() {
                var skill, _i, _len, _ref;
                this.itemSets = {};
                this.result = {};
                _ref = CharacterSkills.allSkillKeys;
                for (_i = 0, _len = _ref.length; _i < _len; _i++) {
                    skill = _ref[_i];
                    this.result[skill] = 0;
                }
                return this.result;
            };
            ItemCalculator.prototype.resultWithBonus = function() {
                var b, bonus, cb, found, i, itemCount, itemSet, result, setId, stage, value, _i, _j, _k, _l, _len, _len1, _len2, _name, _name1, _ref, _ref1, _ref2;
                this.pushResult();
                this._bonusExtractor.level = this.level;
                bonus = {};
                _ref = this.itemSets;
                for (setId in _ref) {
                    itemCount = _ref[setId];
                    itemSet = west.storage.ItemSetManager.get(setId);
                    for (i = _i = 1; 1 <= itemCount ? _i <= itemCount : _i >= itemCount; i = 1 <= itemCount ? ++_i : --_i) {
                        stage = itemSet.bonus[i];
                        if (stage) {
                            for (_j = 0, _len = stage.length; _j < _len; _j++) {
                                b = stage[_j];
                                switch (b.type) {
                                  case "attribute":
                                  case "skill":
                                    bonus[_name = b.type] || (bonus[_name] = {});
                                    bonus[b.type][b.name] = (bonus[b.type][b.name] || 0) + b.value;
                                    break;

                                  case "character":
                                    bonus[_name1 = b.type] || (bonus[_name1] = []);
                                    found = false;
                                    _ref1 = bonus[b.type];
                                    for (i = _k = 0, _len1 = _ref1.length; _k < _len1; i = ++_k) {
                                        cb = _ref1[i];
                                        found = cb.type === b.bonus.type && cb.name === b.bonus.name && cb.key === b.key && cb.roundingMethod === b.roundingMethod;
                                        if (found) {
                                            bonus[b.type][i].value += b.bonus.value;
                                            break;
                                        }
                                    }
                                    if (!found) {
                                        bonus[b.type].push({
                                            type: b.bonus.type,
                                            name: b.bonus.name,
                                            value: b.bonus.value,
                                            key: b.key,
                                            roundingMethod: b.roundingMethod
                                        });
                                    }
                                }
                            }
                        }
                    }
                }
                if (bonus.attribute) {
                    this.calcAttributes(bonus.attribute, ItemCalculator.SUM_OP);
                }
                if (bonus.skill) {
                    this.calcSkills(bonus.skill, ItemCalculator.SUM_OP);
                }
                if (bonus.character) {
                    _ref2 = bonus.character;
                    for (_l = 0, _len2 = _ref2.length; _l < _len2; _l++) {
                        b = _ref2[_l];
                        if (b.key === "level") {
                            value = this._bonusExtractor.getRoundedValue(b.value * this.level, b.roundingMethod);
                            switch (b.type) {
                              case "attribute":
                                this.calcAttribute(b.name, value, ItemCalculator.SUM_OP);
                                break;

                              case "skill":
                                this.calcSkill(b.name, value, ItemCalculator.SUM_OP);
                            }
                        }
                    }
                }
                result = this.result;
                this.popResult();
                return result;
            };
            ItemCalculator.prototype.pushResult = function() {
                return this._resultStack.push($.extend(true, {}, this.result));
            };
            ItemCalculator.prototype.popResult = function() {
                return this.result = this._resultStack.pop();
            };
            return ItemCalculator;
        }();
        return TWSkillsCalc;
    }();
    $(document).ready(function() {
        new TWSkillsCalc();
        return true;
    });
    return true;
});