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.
 
 
 

94 lines
2.2 KiB

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