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

Commit

Permalink
adjusting tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Idrinth committed May 31, 2018
1 parent 22e3b76 commit 6ba513f
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 139 deletions.
74 changes: 0 additions & 74 deletions karma.conf.js

This file was deleted.

29 changes: 14 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,35 @@
"description": "A script for dawn of the dragons, that works based on data provided to https://dotd.idrinth.de via UgUp",
"main": "src/stable.js",
"directories": {
"test": "test"
"lib": "./src",
"test": "./test"
},
"scripts": {
"test": "./node_modules/karma/bin/karma start karma.conf.js",
"test-watch": "./node_modules/karma/bin/karma start karma.conf.js --auto-watch"
"test": "./node_modules/moch/bin/mocha -R test/**/*.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Idrinth/IDotD.git"
"url": "git+https://github.com/IDotD/Userscript.git"
},
"keywords": [
"dotd",
"idrinth",
"script",
"userscript",
"dotd"
"dawn of the dragons"
],
"author": "Björn Büttner",
"author": {
"name": "Björn Büttner",
"url": "https://github.com/Idrinth"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/Idrinth/IDotD/issues"
"url": "https://github.com/IDotD/Userscript/issues"
},
"homepage": "https://github.com/Idrinth/IDotD#idotd",
"homepage": "https://idotd.github.io",
"devDependencies": {
"jasmine": "^2.5.3",
"jasmine-core": "^2.5.2",
"karma": "^1.3.0",
"karma-coverage": "^1.1.1",
"karma-jasmine": "^1.1.0",
"karma-phantomjs-launcher": "^1.0.2",
"karma-spec-reporter": "0.0.26"
"mocha": "^5",
"chai": "^4.1",
"rewire": "^4"
}
}
161 changes: 117 additions & 44 deletions src/workers/stats.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
/**
* @param {Object} data
* @return {Object}
*/
function work ( data ) {
return idrinth.calculate (
new idrinth.StatSet ( data.attack, data.defense, data.perception, data.level, data.stats ),
new idrinth.PremiumSet ( data.utym, data.mirele, data.kraken ),
new idrinth.MultiplierSet ( data.legion, data.mount, data.critchance )
);
}
/**
* @type {Object}
*/
var idrinth = {
/**
* @param {Object} data
* @return {Object}
*/
work: function ( data ) {
let calc = new idrinth.Calculator (
new idrinth.StatSet ( data.attack, data.defense, data.perception, data.level, data.stats ),
new idrinth.PremiumSet ( data.utym, data.mirele, data.kraken ),
new idrinth.MultiplierSet ( data.legion, data.mount, data.critchance )
);
return calc.calculate ();
},
/**
* @class Container for premium
* @constructs {idrinth.PremiumSet}
Expand All @@ -30,20 +31,6 @@ var idrinth = {
this.mirele = mirele;
this.kraken = kraken;
}
/**
* @param {Number} damage
* @param {String} stat
* @param {idrinth.StatSet} stats
* @return {Number}
*/
modifyBase ( damage, stat, stats ) {}
/**
* @param {Number} damage
* @param {String} stat
* @param {idrinth.StatSet} stats
* @return {Number}
*/
modifyTotal ( damage, stat, stats ) {}
},
/**
* @class Container for damage multipliers
Expand All @@ -62,14 +49,6 @@ var idrinth = {
this.mount = mount;
this.critchance = critchance;
}
/**
* @param {Number} base
* @param {String} stat
* @param {idrinth.StatSet} stats
* @param {idrinth.PremiumSet} premiums
* @return {idrinth.StatSet}
*/
modifyTotal ( base, stat, stats, premiums ) {}
},
/**
* @class Container for attributes
Expand All @@ -92,6 +71,10 @@ var idrinth = {
this.stats = stats;
this.level = level;
}
increase (property) {
this.stats -= this.getCost (this[property]);
this[property]++;
}
/**
* @param {Number} value
* @return {Number}
Expand All @@ -105,7 +88,7 @@ var idrinth = {
return Math.max ( number, 0 );
};
let modifier = 10000 + Math.floor ( toPositive ( this.level / 500 - 2 ) ) * 1500;
return 1 + Math.ceil (toPositive (value - modifier) / 1500);
return 1 + Math.ceil ( toPositive ( value - modifier ) / 1500 );
}
/**
* @return {Array}
Expand All @@ -125,16 +108,106 @@ var idrinth = {
}
},
/**
* @param {StatSet} stat
* @param {PremiumSet} premium
* @param {MultiplierSet} multiplier
* @return {StatSet}
* @class Actual logic for stat calculation
* @constructs {idrinth.Calculator}
*/
calculate ( stat, premium, multiplier ) {
let modified = false;
do {
stat.getIncreaseableStats ().forEach ();
} while ( modified )
return stat;
Calculator: class Calculator {
/**
* @constructor
* @param {idrinth.StatSet} stat
* @param {idrinth.PremiumSet} premium
* @param {idrinth.MultiplierSet} multiplier
* @return {StatSet}
*/
construct ( stat, premium, multiplier ) {
this.stat = stat;
this.premium = premium;
this.multiplier = multiplier;
}
/**
* @returns {Number}
*/
addOnePerc () {
if (! this.premium.mirele ) {
return 0;
}
return 1.8 * ( this.stats.perception <= 10000 ? 10 : 35 ) * this.multipliers.legion;
}
/**
* @returns {Number}
*/
addOneAttack () {
let base = 4;
if ( this.premium.utym ) {
base += ( this.stats.attack <= 10000 ? 0.1 : 1 / 35 ) * 1.8 * this.multiplier.legion;
}
return base;
}
/**
* @returns {Number}
*/
addOneDefense () {
let base = 1;
if ( this.premium.utym ) {
base += ( this.stats.defense <= 10000 ? 0.1 : 1 / 35 ) * 1.8 * this.multiplier.legion;
}
if ( this.premium.kraken ) {
base += ( this.stats.defense <= 10000 ? 0.2 : 0.01 ) * 1.8 * this.multiplier.legion;
}
return base;
}
/**
* @param {Number} value
* @param {string} added
* @returns {Number}
*/
addProcs ( value ) {
let perc = this.stats.perception + 1;
return value * ( 1 + this.multiplier.mount + this.multiplier.critchance * 0.01 * Math.floor ( perc < 500000 ? perc / 5000 : 50 + perc / 10000 ) );
}
/**
* @param {Number} value
* @param {string} added
* @returns {Number}
*/
addPercProcs ( value ) {
if ( this.premium.utym ) {
value += this.stat.perception <= 10000 ? 0.4 : 0.2;
}
if ( this.premium.kraken ) {
value += this.stat.perception <= 10000 ? 1 : 0.1;
}
return value;
}
/**
* @return {Boolean} was modified
*/
increase () {
let perc = this.addPercProcs(this.addProcs ( this.addOnePerc ())) / this.stat.getCost ( this.stat.perception );
let defense = this.addProcs ( this.addOneDefense ()) / this.stat.getCost ( this.stat.defense );
let attack = this.addProcs ( this.addOneAttack ()) / this.stat.getCost ( this.stat.attack );
let stat = null;
if (perc >= attack && perc >= defense && this.stats.getCost(this.stats.perception) < this.stats.stats) {
stat = "perception";
} else if (attack >= perc && attack >= defense && this.stats.getCost(this.stats.attack) < this.stats.stats) {
stat = "attack";
} else if (defense >= attack && defense >= perc && this.stats.getCost(this.stats.defense) < this.stats.stats) {
stat = "defense";
} else {
return false;
}
this.stats.increase(stat);
return true;
}
/**
* @return {StatSet}
*/
calculate ( ) {
let modified = false;
do {
modified = this.increase();
} while ( modified )
return stat;
}
}
};
4 changes: 2 additions & 2 deletions tests/mods/land.spec.js → test/mods/land.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe ( 'Land.js tests', function () {
/*describe ( 'Land.js tests', function () {
it ( 'should have a idrinth variable in scope', function () {
expect ( idrinth ).toBeDefined ();
Expand Down Expand Up @@ -81,4 +81,4 @@ describe ( 'Land.js tests', function () {
} );
} );
} );*/
4 changes: 2 additions & 2 deletions tests/mods/names.spec.js → test/mods/names.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe ( 'Names.js tests', function () {
/*describe ( 'Names.js tests', function () {
it ( 'should have a idrinth variable in scope', function () {
expect ( idrinth ).toBeDefined ();
Expand Down Expand Up @@ -106,4 +106,4 @@ describe ( 'Names.js tests', function () {
});
} );
} );
} );*/
4 changes: 2 additions & 2 deletions tests/mods/settingsSpec.js → test/mods/settings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe ( 'Settings.js tests', function () {
/*describe ( 'Settings.js tests', function () {
it ( 'should have a idrinth variable in scope', function () {
expect ( idrinth ).toBeDefined ();
Expand Down Expand Up @@ -58,4 +58,4 @@ describe ( 'Settings.js tests', function () {
expect ( copySettings ).toEqual ( defaults );
} );
} );
} );*/
Loading

0 comments on commit 6ba513f

Please sign in to comment.