|
|
@@ -1,3 +1,35 @@ |
|
|
|
const rollValues = (rollsDefinition, result) => { |
|
|
|
for (let p in rollsDefinition) { |
|
|
|
const entry = rollsDefinition[p]; |
|
|
|
|
|
|
|
if (typeof(entry) === 'object' && !Array.isArray(entry) && entry !== null) { |
|
|
|
const newResult = {}; |
|
|
|
|
|
|
|
result[p] = newResult; |
|
|
|
|
|
|
|
rollValues(entry, newResult); |
|
|
|
|
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
const range = entry; |
|
|
|
const isInt = (p.indexOf('i_') === 0); |
|
|
|
const fieldName = p.replace('i_', ''); |
|
|
|
|
|
|
|
if (!entry.push) { |
|
|
|
result[fieldName] = range; |
|
|
|
|
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
let value = range[0] + (Math.random() * (range[1] - range[0])); |
|
|
|
if (isInt) |
|
|
|
value = ~~value; |
|
|
|
|
|
|
|
result[fieldName] = value; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
module.exports = { |
|
|
|
generate: function (item, blueprint) { |
|
|
|
if (!blueprint.effects) |
|
|
@@ -6,22 +38,8 @@ module.exports = { |
|
|
|
item.effects = blueprint.effects.map(function (e) { |
|
|
|
let rolls = e.rolls; |
|
|
|
let newRolls = {}; |
|
|
|
for (let p in rolls) { |
|
|
|
let isInt = (p.indexOf('i_') === 0); |
|
|
|
let fieldName = p.replace('i_', ''); |
|
|
|
|
|
|
|
let range = rolls[p]; |
|
|
|
if (!range.push) { |
|
|
|
newRolls[fieldName] = range; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
let value = range[0] + (Math.random() * (range[1] - range[0])); |
|
|
|
if (isInt) |
|
|
|
value = ~~value; |
|
|
|
|
|
|
|
newRolls[fieldName] = value; |
|
|
|
} |
|
|
|
|
|
|
|
rollValues(rolls, newRolls); |
|
|
|
|
|
|
|
return { |
|
|
|
type: e.type, |
|
|
|