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

Commit 6ba513f

Browse files
committed
adjusting tests
1 parent 22e3b76 commit 6ba513f

7 files changed

Lines changed: 195 additions & 139 deletions

File tree

karma.conf.js

Lines changed: 0 additions & 74 deletions
This file was deleted.

package.json

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,35 @@
44
"description": "A script for dawn of the dragons, that works based on data provided to https://dotd.idrinth.de via UgUp",
55
"main": "src/stable.js",
66
"directories": {
7-
"test": "test"
7+
"lib": "./src",
8+
"test": "./test"
89
},
910
"scripts": {
10-
"test": "./node_modules/karma/bin/karma start karma.conf.js",
11-
"test-watch": "./node_modules/karma/bin/karma start karma.conf.js --auto-watch"
11+
"test": "./node_modules/moch/bin/mocha -R test/**/*.js"
1212
},
1313
"repository": {
1414
"type": "git",
15-
"url": "git+https://github.com/Idrinth/IDotD.git"
15+
"url": "git+https://github.com/IDotD/Userscript.git"
1616
},
1717
"keywords": [
1818
"dotd",
1919
"idrinth",
2020
"script",
2121
"userscript",
22-
"dotd"
22+
"dawn of the dragons"
2323
],
24-
"author": "Björn Büttner",
24+
"author": {
25+
"name": "Björn Büttner",
26+
"url": "https://github.com/Idrinth"
27+
},
2528
"license": "MIT",
2629
"bugs": {
27-
"url": "https://github.com/Idrinth/IDotD/issues"
30+
"url": "https://github.com/IDotD/Userscript/issues"
2831
},
29-
"homepage": "https://github.com/Idrinth/IDotD#idotd",
32+
"homepage": "https://idotd.github.io",
3033
"devDependencies": {
31-
"jasmine": "^2.5.3",
32-
"jasmine-core": "^2.5.2",
33-
"karma": "^1.3.0",
34-
"karma-coverage": "^1.1.1",
35-
"karma-jasmine": "^1.1.0",
36-
"karma-phantomjs-launcher": "^1.0.2",
37-
"karma-spec-reporter": "0.0.26"
34+
"mocha": "^5",
35+
"chai": "^4.1",
36+
"rewire": "^4"
3837
}
3938
}

src/workers/stats.js

Lines changed: 117 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
/**
2-
* @param {Object} data
3-
* @return {Object}
4-
*/
5-
function work ( data ) {
6-
return idrinth.calculate (
7-
new idrinth.StatSet ( data.attack, data.defense, data.perception, data.level, data.stats ),
8-
new idrinth.PremiumSet ( data.utym, data.mirele, data.kraken ),
9-
new idrinth.MultiplierSet ( data.legion, data.mount, data.critchance )
10-
);
11-
}
121
/**
132
* @type {Object}
143
*/
154
var idrinth = {
5+
/**
6+
* @param {Object} data
7+
* @return {Object}
8+
*/
9+
work: function ( data ) {
10+
let calc = new idrinth.Calculator (
11+
new idrinth.StatSet ( data.attack, data.defense, data.perception, data.level, data.stats ),
12+
new idrinth.PremiumSet ( data.utym, data.mirele, data.kraken ),
13+
new idrinth.MultiplierSet ( data.legion, data.mount, data.critchance )
14+
);
15+
return calc.calculate ();
16+
},
1617
/**
1718
* @class Container for premium
1819
* @constructs {idrinth.PremiumSet}
@@ -30,20 +31,6 @@ var idrinth = {
3031
this.mirele = mirele;
3132
this.kraken = kraken;
3233
}
33-
/**
34-
* @param {Number} damage
35-
* @param {String} stat
36-
* @param {idrinth.StatSet} stats
37-
* @return {Number}
38-
*/
39-
modifyBase ( damage, stat, stats ) {}
40-
/**
41-
* @param {Number} damage
42-
* @param {String} stat
43-
* @param {idrinth.StatSet} stats
44-
* @return {Number}
45-
*/
46-
modifyTotal ( damage, stat, stats ) {}
4734
},
4835
/**
4936
* @class Container for damage multipliers
@@ -62,14 +49,6 @@ var idrinth = {
6249
this.mount = mount;
6350
this.critchance = critchance;
6451
}
65-
/**
66-
* @param {Number} base
67-
* @param {String} stat
68-
* @param {idrinth.StatSet} stats
69-
* @param {idrinth.PremiumSet} premiums
70-
* @return {idrinth.StatSet}
71-
*/
72-
modifyTotal ( base, stat, stats, premiums ) {}
7352
},
7453
/**
7554
* @class Container for attributes
@@ -92,6 +71,10 @@ var idrinth = {
9271
this.stats = stats;
9372
this.level = level;
9473
}
74+
increase (property) {
75+
this.stats -= this.getCost (this[property]);
76+
this[property]++;
77+
}
9578
/**
9679
* @param {Number} value
9780
* @return {Number}
@@ -105,7 +88,7 @@ var idrinth = {
10588
return Math.max ( number, 0 );
10689
};
10790
let modifier = 10000 + Math.floor ( toPositive ( this.level / 500 - 2 ) ) * 1500;
108-
return 1 + Math.ceil (toPositive (value - modifier) / 1500);
91+
return 1 + Math.ceil ( toPositive ( value - modifier ) / 1500 );
10992
}
11093
/**
11194
* @return {Array}
@@ -125,16 +108,106 @@ var idrinth = {
125108
}
126109
},
127110
/**
128-
* @param {StatSet} stat
129-
* @param {PremiumSet} premium
130-
* @param {MultiplierSet} multiplier
131-
* @return {StatSet}
111+
* @class Actual logic for stat calculation
112+
* @constructs {idrinth.Calculator}
132113
*/
133-
calculate ( stat, premium, multiplier ) {
134-
let modified = false;
135-
do {
136-
stat.getIncreaseableStats ().forEach ();
137-
} while ( modified )
138-
return stat;
114+
Calculator: class Calculator {
115+
/**
116+
* @constructor
117+
* @param {idrinth.StatSet} stat
118+
* @param {idrinth.PremiumSet} premium
119+
* @param {idrinth.MultiplierSet} multiplier
120+
* @return {StatSet}
121+
*/
122+
construct ( stat, premium, multiplier ) {
123+
this.stat = stat;
124+
this.premium = premium;
125+
this.multiplier = multiplier;
126+
}
127+
/**
128+
* @returns {Number}
129+
*/
130+
addOnePerc () {
131+
if (! this.premium.mirele ) {
132+
return 0;
133+
}
134+
return 1.8 * ( this.stats.perception <= 10000 ? 10 : 35 ) * this.multipliers.legion;
135+
}
136+
/**
137+
* @returns {Number}
138+
*/
139+
addOneAttack () {
140+
let base = 4;
141+
if ( this.premium.utym ) {
142+
base += ( this.stats.attack <= 10000 ? 0.1 : 1 / 35 ) * 1.8 * this.multiplier.legion;
143+
}
144+
return base;
145+
}
146+
/**
147+
* @returns {Number}
148+
*/
149+
addOneDefense () {
150+
let base = 1;
151+
if ( this.premium.utym ) {
152+
base += ( this.stats.defense <= 10000 ? 0.1 : 1 / 35 ) * 1.8 * this.multiplier.legion;
153+
}
154+
if ( this.premium.kraken ) {
155+
base += ( this.stats.defense <= 10000 ? 0.2 : 0.01 ) * 1.8 * this.multiplier.legion;
156+
}
157+
return base;
158+
}
159+
/**
160+
* @param {Number} value
161+
* @param {string} added
162+
* @returns {Number}
163+
*/
164+
addProcs ( value ) {
165+
let perc = this.stats.perception + 1;
166+
return value * ( 1 + this.multiplier.mount + this.multiplier.critchance * 0.01 * Math.floor ( perc < 500000 ? perc / 5000 : 50 + perc / 10000 ) );
167+
}
168+
/**
169+
* @param {Number} value
170+
* @param {string} added
171+
* @returns {Number}
172+
*/
173+
addPercProcs ( value ) {
174+
if ( this.premium.utym ) {
175+
value += this.stat.perception <= 10000 ? 0.4 : 0.2;
176+
}
177+
if ( this.premium.kraken ) {
178+
value += this.stat.perception <= 10000 ? 1 : 0.1;
179+
}
180+
return value;
181+
}
182+
/**
183+
* @return {Boolean} was modified
184+
*/
185+
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;
198+
}
199+
this.stats.increase(stat);
200+
return true;
201+
}
202+
/**
203+
* @return {StatSet}
204+
*/
205+
calculate ( ) {
206+
let modified = false;
207+
do {
208+
modified = this.increase();
209+
} while ( modified )
210+
return stat;
211+
}
139212
}
140213
};
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe ( 'Land.js tests', function () {
1+
/*describe ( 'Land.js tests', function () {
22
33
it ( 'should have a idrinth variable in scope', function () {
44
expect ( idrinth ).toBeDefined ();
@@ -81,4 +81,4 @@ describe ( 'Land.js tests', function () {
8181
8282
} );
8383
84-
} );
84+
} );*/
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe ( 'Names.js tests', function () {
1+
/*describe ( 'Names.js tests', function () {
22
33
it ( 'should have a idrinth variable in scope', function () {
44
expect ( idrinth ).toBeDefined ();
@@ -106,4 +106,4 @@ describe ( 'Names.js tests', function () {
106106
});
107107
108108
} );
109-
} );
109+
} );*/
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe ( 'Settings.js tests', function () {
1+
/*describe ( 'Settings.js tests', function () {
22
33
it ( 'should have a idrinth variable in scope', function () {
44
expect ( idrinth ).toBeDefined ();
@@ -58,4 +58,4 @@ describe ( 'Settings.js tests', function () {
5858
expect ( copySettings ).toEqual ( defaults );
5959
} );
6060
61-
} );
61+
} );*/

0 commit comments

Comments
 (0)