Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var collector = {
- units: [
- {'spear': 520},
- {'sword': 0},
- {'axe': 0},
- {'archer': 0},
- {'light': 0},
- {'marcher': 0},
- {'heavy': 0},
- {'knight': 0}
- ],
- times: 0,
- percents: [0.576923077, 0.230769231, 0.115384615, 0.0769230769],
- options: document.getElementsByClassName("options-container")[0].children,
- setUnitAmount(name, amount) {
- const element = document.getElementsByName(name)[0];
- if (element === undefined)
- return;
- element.value = amount;
- element.dispatchEvent(new Event('change'));
- },
- unitAvailable: function (name) {
- const field = document.getElementsByName(name)[0];
- if (field === undefined)
- return 0;
- const text = field.parentNode.lastChild.innerHTML;
- return +(text.substr(1, text.length - 2));
- },
- calculateAndSetUnits: function (level) {
- const percent = this.percents[level];
- for (let i = 0; i < this.units.length; i++) {
- const current = this.units[i];
- const name = Object.keys(current);
- const amount = Math.floor(current[name] * percent);
- const available = this.unitAvailable(name);
- this.setUnitAmount(name, Math.min(amount, available));
- }
- },
- select: function () {
- for (let i = 0; i < this.options.length; i++) {
- const element = this.options[i].lastChild.lastChild;
- if (element.classList.contains("inactive-view")) {
- if (element.firstChild === null)
- continue;
- this.calculateAndSetUnits(i);
- element.lastChild.firstChild.click();
- break;
- }
- }
- }
- };
- collector.select();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement