You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

23 lines
690 B

  1. let configSlots = require('../config/slots');
  2. let configTypes = require('../config/types');
  3. let chances = [];
  4. for (let c in configSlots.chance) {
  5. let rolls = configSlots.chance[c];
  6. for (let i = 0; i < rolls; i++)
  7. chances.push(c);
  8. }
  9. module.exports = {
  10. generate: function (item, blueprint) {
  11. if (blueprint.slot)
  12. item.slot = blueprint.slot;
  13. else if (blueprint.type)
  14. item.slot = Object.keys(configTypes.types).find(c => configTypes.types[c][blueprint.type]);
  15. //If the slot doesn't exist or the type doesn't exist in the slot, pick a random type
  16. if (!item.slot || !configSlots.slots.includes(item.slot))
  17. item.slot = chances[~~(Math.random() * chances.length)];
  18. }
  19. };