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.
 
 
 

66 line
1.8 KiB

  1. let configTypes = require('../config/types');
  2. let armorMaterials = require('../config/armorMaterials');
  3. module.exports = {
  4. generate: function (item, blueprint) {
  5. let type = blueprint.type;
  6. if (!type || !configTypes.types[item.slot][type]) {
  7. //Pick a material type first
  8. const types = configTypes.types[item.slot];
  9. const typeArray = Object
  10. .entries(types)
  11. .filter(t => t[1].noDrop !== true);
  12. const materials = Object.values(types)
  13. .map(t => {
  14. return t.material;
  15. })
  16. .filter((m, i) => i === typeArray.findIndex(t => t[1].material === m));
  17. const material = materials[~~(Math.random() * materials.length)];
  18. const possibleTypes = {};
  19. Object.entries(types)
  20. .forEach(t => {
  21. const [ typeName, typeConfig ] = t;
  22. if (typeConfig.material === material && typeConfig.noDrop !== true)
  23. possibleTypes[typeName] = typeConfig;
  24. });
  25. type = _.randomKey(possibleTypes);
  26. }
  27. let typeBlueprint = configTypes.types[item.slot][type] || {};
  28. if (!typeBlueprint)
  29. return;
  30. item.type = type;
  31. item.sprite = extend([], blueprint.sprite || typeBlueprint.sprite);
  32. if (typeBlueprint.spritesheet && !blueprint.spritesheet)
  33. item.spritesheet = typeBlueprint.spritesheet;
  34. if (typeBlueprint.spellName) {
  35. blueprint.spellName = typeBlueprint.spellName;
  36. blueprint.spellConfig = typeBlueprint.spellConfig;
  37. }
  38. if (typeBlueprint.range)
  39. item.range = typeBlueprint.range;
  40. if (typeBlueprint.material) {
  41. let material = armorMaterials[typeBlueprint.material];
  42. blueprint.attrRequire = material.attrRequire;
  43. }
  44. if (typeBlueprint.implicitStat && !blueprint.implicitStat)
  45. blueprint.implicitStat = typeBlueprint.implicitStat;
  46. if (typeBlueprint.attrRequire && !blueprint.attrRequire)
  47. blueprint.attrRequire = typeBlueprint.attrRequire;
  48. }
  49. };