diff --git a/test/common/fns/randomVal.js b/test/common/fns/randomVal.js index f58dd1ab06..82469c0e7f 100644 --- a/test/common/fns/randomVal.js +++ b/test/common/fns/randomVal.js @@ -1,9 +1,9 @@ -import randomVal from '../../../website/common/script/fns/randomVal'; +import randomVal from '../../../website/common/script/libs/randomVal'; import { generateUser, } from '../../helpers/common.helper'; -describe('shared.fns.randomVal', () => { +describe('randomVal', () => { let obj; beforeEach(() => { diff --git a/test/common/ops/buyGear.js b/test/common/ops/buyGear.js index 4740b38daf..8e19a90d49 100644 --- a/test/common/ops/buyGear.js +++ b/test/common/ops/buyGear.js @@ -29,12 +29,12 @@ describe('shared.ops.buyGear', () => { stats: { gp: 200 }, }); - sinon.stub(shared.fns, 'randomVal'); + sinon.stub(shared, 'randomVal'); sinon.stub(shared.fns, 'predictableRandom'); }); afterEach(() => { - shared.fns.randomVal.restore(); + shared.randomVal.restore(); shared.fns.predictableRandom.restore(); }); diff --git a/website/common/script/fns/index.js b/website/common/script/fns/index.js index e83cb0b6a1..15359bedd7 100644 --- a/website/common/script/fns/index.js +++ b/website/common/script/fns/index.js @@ -1,7 +1,6 @@ import handleTwoHanded from './handleTwoHanded'; import predictableRandom from './predictableRandom'; import crit from './crit'; -import randomVal from './randomVal'; import randomDrop from './randomDrop'; import autoAllocate from './autoAllocate'; import updateStats from './updateStats'; @@ -11,7 +10,6 @@ module.exports = { handleTwoHanded, predictableRandom, crit, - randomVal, randomDrop, autoAllocate, updateStats, diff --git a/website/common/script/fns/randomDrop.js b/website/common/script/fns/randomDrop.js index 0022bf09be..79e5a89dec 100644 --- a/website/common/script/fns/randomDrop.js +++ b/website/common/script/fns/randomDrop.js @@ -3,7 +3,7 @@ import content from '../content/index'; import i18n from '../i18n'; import { daysSince } from '../cron'; import { diminishingReturns } from '../statHelpers'; -import randomVal from './randomVal'; +import randomVal from '../libs/randomVal'; // TODO This is only used on the server // move to user model as an instance method? diff --git a/website/common/script/index.js b/website/common/script/index.js index b19736957e..b79fee6bab 100644 --- a/website/common/script/index.js +++ b/website/common/script/index.js @@ -91,12 +91,14 @@ api.statsComputed = statsComputed; import shops from './libs/shops'; api.shops = shops; +import randomVal from './libs/randomVal'; +api.randomVal = randomVal; + import autoAllocate from './fns/autoAllocate'; import crit from './fns/crit'; import handleTwoHanded from './fns/handleTwoHanded'; import predictableRandom from './fns/predictableRandom'; import randomDrop from './fns/randomDrop'; -import randomVal from './fns/randomVal'; import resetGear from './fns/resetGear'; import ultimateGear from './fns/ultimateGear'; import updateStats from './fns/updateStats'; @@ -107,7 +109,6 @@ api.fns = { handleTwoHanded, predictableRandom, randomDrop, - randomVal, resetGear, ultimateGear, updateStats, diff --git a/website/common/script/fns/randomVal.js b/website/common/script/libs/randomVal.js similarity index 99% rename from website/common/script/fns/randomVal.js rename to website/common/script/libs/randomVal.js index 3aab845393..dea1c32784 100644 --- a/website/common/script/fns/randomVal.js +++ b/website/common/script/libs/randomVal.js @@ -1,12 +1,11 @@ import _ from 'lodash'; -// Get a random property from an object -// returns random property (the value) - function trueRandom () { return Math.random(); } +// Get a random property from an object +// returns random property (the value) module.exports = function randomVal (obj, options = {}) { let array = options.key ? _.keys(obj) : _.values(obj); let random = (options.predictableRandom || trueRandom)(); diff --git a/website/common/script/ops/buyArmoire.js b/website/common/script/ops/buyArmoire.js index 653da03e50..12fa433d01 100644 --- a/website/common/script/ops/buyArmoire.js +++ b/website/common/script/ops/buyArmoire.js @@ -6,7 +6,7 @@ import splitWhitespace from '../libs/splitWhitespace'; import { NotAuthorized, } from '../libs/errors'; -import randomVal from '../fns/randomVal'; +import randomVal from '../libs/randomVal'; // TODO this is only used on the server // move out of common? diff --git a/website/common/script/ops/revive.js b/website/common/script/ops/revive.js index 6f07ec59e6..51872c49fd 100644 --- a/website/common/script/ops/revive.js +++ b/website/common/script/ops/revive.js @@ -4,7 +4,7 @@ import _ from 'lodash'; import { NotAuthorized, } from '../libs/errors'; -import randomVal from '../fns/randomVal'; +import randomVal from '../libs/randomVal'; // TODO this is only used on the server // move out of common? diff --git a/website/server/models/group.js b/website/server/models/group.js index 41419857b6..4c47c49598 100644 --- a/website/server/models/group.js +++ b/website/server/models/group.js @@ -609,7 +609,7 @@ schema.methods._processCollectionQuest = async function processCollectionQuest ( let itemsFound = {}; _.times(progress.collectedItems, () => { - let item = shared.fns.randomVal(quest.collect, {key: true}); + let item = shared.randomVal(quest.collect, {key: true}); if (!itemsFound[item]) { itemsFound[item] = 0;