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.
 
 
 

67 lines
1.6 KiB

  1. let prefixes = require('../config/prefixes');
  2. let suffixes = require('../config/suffixes');
  3. module.exports = {
  4. generators: [
  5. 'basic', ['basic'],
  6. ['gPrefix', 'gSuffix'],
  7. ['gPrefix', 'gSuffix'],
  8. ['gPrefix', 'gSuffix']
  9. ],
  10. generate: function (item, blueprint) {
  11. if (blueprint.name) {
  12. item.name = blueprint.name;
  13. return;
  14. } else if (blueprint.noName) {
  15. item.name = item.type;
  16. return;
  17. }
  18. let gen = this.generators[item.quality];
  19. if (!(gen instanceof Array))
  20. gen = [gen];
  21. gen.forEach(g => this.types[g].call(this, item, blueprint));
  22. },
  23. types: {
  24. basic: function (item, blueprint) {
  25. item.name = item.type;
  26. },
  27. gPrefix: function (item, blueprint) {
  28. let list = prefixes.generic.concat(prefixes.slots[item.slot] || []);
  29. if (item.stats.armor)
  30. list = list.concat(prefixes.armor);
  31. else if (item.slot === 'twoHanded')
  32. list = list.concat(prefixes.weapons);
  33. let pick = list[~~(Math.random() * list.length)];
  34. item.name = pick[0].toUpperCase() + pick.substr(1);
  35. if (item.name.indexOf('%') > -1) {
  36. let replacer = (Math.random() < 0.5) ? '\'s' : '';
  37. item.name = item.name.split('%').join(replacer);
  38. }
  39. },
  40. gSuffix: function (item, blueprint) {
  41. let list = null;
  42. if (item.slot === 'tool')
  43. list = suffixes.slots.tool;
  44. else {
  45. list = suffixes.generic.concat(suffixes.slots[item.slot] || []);
  46. if (item.stats.armor)
  47. list = list.concat(suffixes.armor);
  48. else if (item.slot === 'twoHanded')
  49. list = list.concat(suffixes.weapons);
  50. }
  51. let pick = list[~~(Math.random() * list.length)];
  52. item.name += ' ' + pick[0].toUpperCase() + pick.substr(1);
  53. }
  54. }
  55. };