Skip to content
This repository was archived by the owner on Mar 29, 2021. It is now read-only.

Commit e1c0f10

Browse files
committed
reworking comparison to duplicate less code
1 parent b6683db commit e1c0f10

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

src/workers/stats.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ var idrinth = {
127127
/**
128128
* @returns {Number}
129129
*/
130-
addOnePerc () {
130+
addOnePerception () {
131131
if (! this.premium.mirele ) {
132132
return 0;
133133
}
@@ -179,25 +179,33 @@ var idrinth = {
179179
}
180180
return value;
181181
}
182+
_getSet() {
183+
return {
184+
perception: this.addPercProcs(this.addProcs ( this.addOnePerception ())) / this.stat.getCost ( this.stat.perception ),
185+
defense: this.addProcs ( this.addOneDefense ()) / this.stat.getCost ( this.stat.defense ),
186+
attack: this.addProcs ( this.addOneAttack ()) / this.stat.getCost ( this.stat.attack )
187+
};
188+
}
182189
/**
183190
* @return {Boolean} was modified
184191
*/
185192
increase () {
186-
let perc = this.addPercProcs(this.addProcs ( this.addOnePerc ())) / this.stat.getCost ( this.stat.perception );
187-
let defense = this.addProcs ( this.addOneDefense ()) / this.stat.getCost ( this.stat.defense );
188-
let attack = this.addProcs ( this.addOneAttack ()) / this.stat.getCost ( this.stat.attack );
189-
let stat = null;
190-
if (perc >= attack && perc >= defense && this.stats.getCost(this.stats.perception) < this.stats.stats) {
191-
stat = "perception";
192-
} else if (attack >= perc && attack >= defense && this.stats.getCost(this.stats.attack) < this.stats.stats) {
193-
stat = "attack";
194-
} else if (defense >= attack && defense >= perc && this.stats.getCost(this.stats.defense) < this.stats.stats) {
195-
stat = "defense";
196-
} else {
197-
return false;
193+
let data = this._getSet();
194+
let isBiggest = function(key, data) {
195+
for (let prop in data) {
196+
if(data[prop] > data[key]) {
197+
return false;
198+
}
199+
}
200+
return true;
201+
};
202+
for (let key in data) {
203+
if (isBiggest(key, data) && this.stats.getCost(this.stats[key]) < this.stats.stats) {
204+
this.stats.increase(key);
205+
return true;
206+
}
198207
}
199-
this.stats.increase(stat);
200-
return true;
208+
return false;
201209
}
202210
/**
203211
* @return {StatSet}

0 commit comments

Comments
 (0)