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.
 
 
 

63 lines
1.7 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.entries(types);
  10. const materials = Object.values(types)
  11. .map(t => {
  12. return t.material;
  13. })
  14. .filter((m, i) => i === typeArray.findIndex(t => t[1].material === m));
  15. const material = materials[~~(Math.random() * materials.length)];
  16. const possibleTypes = {};
  17. Object.entries(types)
  18. .forEach(t => {
  19. const [ typeName, typeConfig ] = t;
  20. if (typeConfig.material === material)
  21. possibleTypes[typeName] = typeConfig;
  22. });
  23. type = _.randomKey(possibleTypes);
  24. }
  25. let typeBlueprint = configTypes.types[item.slot][type] || {};
  26. if (!typeBlueprint)
  27. return;
  28. item.type = type;
  29. item.sprite = extend([], blueprint.sprite || typeBlueprint.sprite);
  30. if (typeBlueprint.spritesheet && !blueprint.spritesheet)
  31. item.spritesheet = typeBlueprint.spritesheet;
  32. if (typeBlueprint.spellName) {
  33. blueprint.spellName = typeBlueprint.spellName;
  34. blueprint.spellConfig = typeBlueprint.spellConfig;
  35. }
  36. if (typeBlueprint.range)
  37. item.range = typeBlueprint.range;
  38. if (typeBlueprint.material) {
  39. let material = armorMaterials[typeBlueprint.material];
  40. blueprint.attrRequire = material.attrRequire;
  41. }
  42. if (typeBlueprint.implicitStat && !blueprint.implicitStat)
  43. blueprint.implicitStat = typeBlueprint.implicitStat;
  44. if (typeBlueprint.attrRequire && !blueprint.attrRequire)
  45. blueprint.attrRequire = typeBlueprint.attrRequire;
  46. }
  47. };