From e246b737b284934a6ebfcce725450118872cad11 Mon Sep 17 00:00:00 2001 From: ExitCode Date: Sat, 21 Apr 2018 23:53:02 +0200 Subject: [PATCH] reused random functionality as it worked better on percentage rolls between min/max --- src/app/utils/BlueprintFunctions.js | 35 +++++++++++------------------ 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/app/utils/BlueprintFunctions.js b/src/app/utils/BlueprintFunctions.js index 878c2af6..29a342f7 100644 --- a/src/app/utils/BlueprintFunctions.js +++ b/src/app/utils/BlueprintFunctions.js @@ -253,34 +253,15 @@ export function getBlueprint(name, module) { } /** - * Provide 'worst' primary modifications + * Provide 'percent' primary modifications * @param {Object} ship The ship for which to perform the modifications * @param {Object} m The module for which to perform the modifications * @param {Number} percent The percent to set values to of full. */ export function setPercent(ship, m, percent) { ship.clearModifications(m); - const features = m.blueprint.grades[m.blueprint.grade].features; - for (const featureName in features) { - const value = features[featureName][1]; - const featureIsBeneficial = isBeneficial(featureName, features[featureName]); - if (featureIsBeneficial === true) { - _setValue(ship, m, featureName, (percent / 100) * value); - } else { - _setValue(ship, m, featureName, value); - } - } -} - -/** - * Provide 'random' primary modifications - * @param {Object} ship The ship for which to perform the modifications - * @param {Object} m The module for which to perform the modifications - */ -export function setRandom(ship, m) { - ship.clearModifications(m); - // Pick a single value for our randomness - const mult = Math.random(); + // Pick given value as multiplier + const mult = percent / 100; const features = m.blueprint.grades[m.blueprint.grade].features; for (const featureName in features) { let value; @@ -304,6 +285,16 @@ export function setRandom(ship, m) { } } +/** + * Provide 'random' primary modifications + * @param {Object} ship The ship for which to perform the modifications + * @param {Object} m The module for which to perform the modifications + */ +export function setRandom(ship, m) { + // Pick a single value for our randomness + setPercent(ship, m, Math.random() * 100); +} + /** * Set a modification feature value * @param {Object} ship The ship for which to perform the modifications