mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
drops are randomly selected, not based on user values fixes #7929
This commit is contained in:
committed by
Blade Barringer
parent
b54441a637
commit
4d5b6992be
@@ -1,12 +1,19 @@
|
||||
import _ from 'lodash';
|
||||
import predictableRandom from './predictableRandom';
|
||||
|
||||
// Get a random property from an object
|
||||
// returns random property (the value)
|
||||
|
||||
function randomGenerator (user, seed, providedRandom) {
|
||||
return providedRandom ? providedRandom(user, seed) : Math.random();
|
||||
}
|
||||
|
||||
module.exports = function randomVal (user, obj, options = {}) {
|
||||
let array = options.key ? _.keys(obj) : _.values(obj);
|
||||
let rand = predictableRandom(user, options.seed);
|
||||
let rand = randomGenerator(user, options.seed, options.randomFunc);
|
||||
|
||||
array.sort();
|
||||
return array[Math.floor(rand * array.length)];
|
||||
|
||||
let randomIndex = Math.floor(rand * array.length);
|
||||
|
||||
return array[randomIndex];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user