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.
 
 
 

114 lines
3.0 KiB

  1. let spells = require('../../config/spells');
  2. let spellsConfig = require('../../config/spellsConfig');
  3. let configTypes = require('../config/types');
  4. let maxQuality = 5;
  5. module.exports = {
  6. generate: function (item, blueprint) {
  7. blueprint = blueprint || {};
  8. let spellQuality = blueprint ? blueprint.spellQuality : '';
  9. let spellName = blueprint.spellName;
  10. if (!spellName) {
  11. let spellList = Object.keys(spellsConfig.spells).filter(s => ((!spellsConfig.spells[s].auto) && (!s.noDrop)));
  12. spellName = spellList[~~(Math.random() * spellList.length)];
  13. }
  14. let spell = spellsConfig.spells[spellName];
  15. let spellAesthetic = spells.spells.find(s => s.name.toLowerCase() === spellName) || {};
  16. if (!item.slot) {
  17. let sprite = [10, 0];
  18. let statType = spell.statType;
  19. if (statType === 'dex')
  20. sprite = [10, 1];
  21. else if (statType === 'str')
  22. sprite = [10, 2];
  23. else if (statType instanceof Array) {
  24. if ((statType.indexOf('dex') > -1) && (statType.indexOf('int') > -1))
  25. sprite = [10, 3];
  26. else if ((statType.indexOf('str') > -1) && (statType.indexOf('int') > -1))
  27. sprite = [10, 4];
  28. }
  29. item.name = 'Rune of ' + spellAesthetic.name;
  30. item.ability = true;
  31. item.sprite = sprite;
  32. } else if (spellQuality === 'basic')
  33. item.stats = {};
  34. if (blueprint.spellConfig)
  35. spellAesthetic = extend(true, {}, spellAesthetic, blueprint.spellConfig);
  36. item.spell = {
  37. name: spellAesthetic.name || 'Weapon Damage',
  38. type: spellAesthetic.type || spellName,
  39. rolls: {},
  40. values: {}
  41. };
  42. if (blueprint.spellConfig)
  43. extend(true, item.spell, blueprint.spellConfig);
  44. if (item.type) {
  45. let typeConfig = configTypes.types[item.slot][item.type];
  46. if (typeConfig)
  47. spell = extend(true, {}, spell, typeConfig.spellConfig);
  48. }
  49. let propertyPerfection = [];
  50. let randomProperties = spell.random || {};
  51. let negativeStats = spell.negativeStats || [];
  52. for (let r in randomProperties) {
  53. let negativeStat = (negativeStats.indexOf(r) > -1);
  54. let range = randomProperties[r];
  55. let max = Math.min(20, item.level) / 20;
  56. let roll = random.expNorm(0, max);
  57. if (spellQuality === 'basic')
  58. roll = 0;
  59. else if (spellQuality === 'mid')
  60. roll = 0.5;
  61. item.spell.rolls[r] = roll;
  62. let int = r.indexOf('i_') === 0;
  63. let val = range[0] + ((range[1] - range[0]) * roll);
  64. if (int) {
  65. val = ~~val;
  66. r = r.replace('i_', '');
  67. } else
  68. val = ~~(val * 100) / 100;
  69. item.spell.values[r] = val;
  70. if (negativeStat)
  71. propertyPerfection.push(1 - roll);
  72. else
  73. propertyPerfection.push(roll);
  74. }
  75. if (blueprint.spellProperties) {
  76. item.spell.properties = {};
  77. for (let p in blueprint.spellProperties)
  78. item.spell.properties[p] = blueprint.spellProperties[p];
  79. }
  80. if (item.range) {
  81. item.spell.properties = item.spell.properties || {};
  82. item.spell.properties.range = item.range;
  83. }
  84. let per = propertyPerfection.reduce((p, n) => p + n, 0);
  85. let perfection = ~~((per / propertyPerfection.length) * 4);
  86. if (!item.slot)
  87. item.quality = perfection;
  88. else
  89. item.spell.quality = perfection;
  90. }
  91. };