diff --git a/karma.conf.js b/karma.conf.js deleted file mode 100644 index b62d81f..0000000 --- a/karma.conf.js +++ /dev/null @@ -1,74 +0,0 @@ -// Karma configuration - -module.exports = function ( config ) { - config.set ( { - - // base path that will be used to resolve all patterns (eg. files, exclude) - basePath: '', - - - // frameworks to use - // available frameworks: https://npmjs.org/browse/keyword/karma-adapter - frameworks: [ 'jasmine' ], - - - // list of files / patterns to load in the browser - files: [ - //Starting point - 'src/stable.js', - - 'src/**/*.js', - 'tests/**/*.spec.js' - ], - - - // list of files to exclude - exclude: [ - 'src/libs/*.js' - ], - - - // preprocess matching files before serving them to the browser - // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor - preprocessors: { - 'src/**/*.js': [ 'coverage' ] - }, - - - // test results reporter to use - // possible values: 'dots', 'progress' - // available reporters: https://npmjs.org/browse/keyword/karma-reporter - reporters: [ 'spec', 'coverage' ], - - - // web server port - port: 9876, - - - // enable / disable colors in the output (reporters and logs) - colors: true, - - - // level of logging - // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG - logLevel: config.LOG_INFO, - - - // enable / disable watching file and executing tests whenever any file changes - autoWatch: false, - - - // start these browsers - // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher - browsers: [ 'PhantomJS' ], - - - // Continuous Integration mode - // if true, Karma captures browsers, runs the tests and exits - singleRun: true, - - // Concurrency level - // how many browser should be started simultaneous - concurrency: Infinity - } ) -}; diff --git a/package.json b/package.json index 7221c6b..38d5b66 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/workers/stats.js b/src/workers/stats.js index a415c2b..72b8496 100644 --- a/src/workers/stats.js +++ b/src/workers/stats.js @@ -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} @@ -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 @@ -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 @@ -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} @@ -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} @@ -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; + } } }; \ No newline at end of file diff --git a/tests/mods/land.spec.js b/test/mods/land.js similarity index 97% rename from tests/mods/land.spec.js rename to test/mods/land.js index ddc7966..c0405d7 100644 --- a/tests/mods/land.spec.js +++ b/test/mods/land.js @@ -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 (); @@ -81,4 +81,4 @@ describe ( 'Land.js tests', function () { } ); -} ); \ No newline at end of file +} );*/ \ No newline at end of file diff --git a/tests/mods/names.spec.js b/test/mods/names.js similarity index 98% rename from tests/mods/names.spec.js rename to test/mods/names.js index 21a29a0..badbfbb 100644 --- a/tests/mods/names.spec.js +++ b/test/mods/names.js @@ -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 (); @@ -106,4 +106,4 @@ describe ( 'Names.js tests', function () { }); } ); -} ); \ No newline at end of file +} );*/ \ No newline at end of file diff --git a/tests/mods/settingsSpec.js b/test/mods/settings.js similarity index 96% rename from tests/mods/settingsSpec.js rename to test/mods/settings.js index 7f1e11c..8f3ab5e 100644 --- a/tests/mods/settingsSpec.js +++ b/test/mods/settings.js @@ -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 (); @@ -58,4 +58,4 @@ describe ( 'Settings.js tests', function () { expect ( copySettings ).toEqual ( defaults ); } ); -} ); \ No newline at end of file +} );*/ \ No newline at end of file diff --git a/test/workers/stat.js b/test/workers/stat.js new file mode 100644 index 0000000..9f59e29 --- /dev/null +++ b/test/workers/stat.js @@ -0,0 +1,58 @@ +var should = require ( 'chai' ).should (); +var expect = require ( 'chai' ).expect; +describe ( 'worker/stat.js', function ( ) { + it ( 'should have a idrinth variable in scope', function ( ) { + var idrinth = require( 'rewire' ) ( "../../src/workers/stats" ).__get__( 'idrinth' ); + should.exist ( idrinth ); + idrinth.should.be.an ( 'object' ); + describe ( 'idrinth', function ( ) { + it ( 'should have a work property', function ( ) { + expect( idrinth ).to.have.property( 'work' ); + describe ( 'idrinth.work', function ( ) { + it ( 'work should be a function', function ( ) { + idrinth.work.should.be.a( 'function' ); + } ); + } ); + } ); + it ( 'should have a PremiumSet property', function ( ) { + expect( idrinth ).to.have.property( 'PremiumSet' ); + describe( 'idrinth.PremiumSet', function( ) { + it ( 'PremiumSet should be a function', function ( ) { + idrinth.PremiumSet.should.be.a( 'function' ); + describe ( 'idrinth.PremiumSet#Instance', function ( ) { + var premium = new idrinth.PremiumSet( ); + it ( 'PremiumSet should return an object', function ( ) { + should.exist( premium ); + premium.should.be.an( 'object' ); + } ); + } ); + } ); + } ); + } ); + it ( 'should have a MultiplierSet property', function ( ) { + expect( idrinth ).to.have.property( 'MultiplierSet' ); + describe ( 'idrinth.MultiplierSet', function ( ) { + it ( 'MultiplierSet should be a function', function ( ) { + idrinth.MultiplierSet.should.be.a( 'function' ); + } ); + } ); + } ); + it ( 'should have a StatSet property', function ( ) { + expect( idrinth ).to.have.property( 'StatSet' ); + describe ( 'idrinth.StatSet', function ( ) { + it ( 'StatSet should be a function', function ( ) { + idrinth.StatSet.should.be.a( 'function' ); + } ); + } ); + } ); + it ( 'should have a Calculator property', function ( ) { + expect( idrinth ).to.have.property( 'Calculator' ); + describe ( 'idrinth.Calculator', function ( ) { + it ( 'Calculator should be a function', function ( ) { + idrinth.Calculator.should.be.a( 'function' ); + } ); + } ); + } ); + } ); + } ); +} ); \ No newline at end of file