Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

151 lignes
4.1 KiB

  1. let spells = require('../../config/spells');
  2. let spellsConfig = require('../../config/spellsConfig');
  3. let configTypes = require('../config/types');
  4. const qualityGenerator = require('./quality');
  5. const qualityCount = qualityGenerator.qualities.length;
  6. const buildRolls = (item, blueprint, { random: spellProperties, negativeStats = [] }, quality) => {
  7. //We randomise the order so a random property gets to 'pick first'
  8. // otherwise it's easier for earlier properties to use more of the valuePool
  9. const propKeys = Object
  10. .keys(spellProperties)
  11. .sort((a, b) => Math.random() - Math.random());
  12. const propCount = propKeys.length;
  13. const maxRoll = (quality + 1) / qualityCount;
  14. const minSum = (quality / qualityCount) * propCount;
  15. let runningTotal = 0;
  16. const result = {};
  17. for (let i = 0; i < propCount; i++) {
  18. const minRoll = Math.max(0, minSum - runningTotal - ((propCount - (i + 1)) * maxRoll));
  19. let roll = minRoll + (Math.random() * (maxRoll - minRoll));
  20. runningTotal += roll;
  21. const prop = propKeys[i];
  22. const isNegative = negativeStats.includes(prop);
  23. if (isNegative)
  24. roll = 1 - roll;
  25. const scaledRoll = roll * (item.level / consts.maxLevel);
  26. result[prop] = scaledRoll;
  27. }
  28. return result;
  29. };
  30. module.exports = {
  31. generate: function (item, blueprint) {
  32. blueprint = blueprint || {};
  33. let spellQuality = blueprint ? blueprint.spellQuality : '';
  34. let spellName = blueprint.spellName;
  35. if (!spellName) {
  36. let spellList = Object.keys(spellsConfig.spells).filter(s => !spellsConfig.spells[s].auto && !spellsConfig.spells[s].noDrop);
  37. spellName = spellList[~~(Math.random() * spellList.length)];
  38. }
  39. let spell = extend({}, spellsConfig.spells[spellName], blueprint.spellConfig);
  40. let spellAesthetic = spells.spells.find(s => s.name.toLowerCase() === spellName) || {};
  41. if (!item.slot) {
  42. let sprite = [10, 0];
  43. let statType = spell.statType;
  44. if (statType === 'dex')
  45. sprite = [10, 1];
  46. else if (statType === 'str')
  47. sprite = [10, 2];
  48. else if (statType instanceof Array) {
  49. if ((statType.indexOf('dex') > -1) && (statType.indexOf('int') > -1))
  50. sprite = [10, 3];
  51. else if ((statType.indexOf('str') > -1) && (statType.indexOf('int') > -1))
  52. sprite = [10, 4];
  53. }
  54. item.name = 'Rune of ' + spellAesthetic.name;
  55. item.ability = true;
  56. item.sprite = sprite;
  57. } else if (spellQuality === 'basic')
  58. item.stats = {};
  59. if (blueprint.spellConfig)
  60. spellAesthetic = extend({}, spellAesthetic, blueprint.spellConfig);
  61. item.spell = {
  62. name: spellAesthetic.name || 'Weapon Damage',
  63. type: spellAesthetic.type || spellName,
  64. rolls: {},
  65. values: {}
  66. };
  67. if (blueprint.spellConfig)
  68. extend(item.spell, blueprint.spellConfig);
  69. if (item.type) {
  70. let typeConfig = configTypes.types[item.slot][item.type];
  71. if (typeConfig)
  72. extend(spell, typeConfig.spellConfig);
  73. }
  74. //If the item has a slot, we need to generate a new quality for the rune
  75. let quality = item.quality;
  76. if (item.slot) {
  77. const tempItem = {};
  78. const tempBlueprint = extend(blueprint);
  79. delete tempBlueprint.quality;
  80. tempBlueprint.quality = blueprint.spellQuality;
  81. qualityGenerator.generate(tempItem, tempBlueprint);
  82. quality = tempItem.quality;
  83. item.spell.quality = quality;
  84. }
  85. const rolls = buildRolls(item, blueprint, spell, quality);
  86. Object.entries(spell.random || {}).forEach(entry => {
  87. const [ property, range ] = entry;
  88. const roll = rolls[property];
  89. item.spell.rolls[property] = roll;
  90. const isInt = property.indexOf('i_') === 0;
  91. let useProperty = property;
  92. const minRange = range[0];
  93. const maxRange = range[1];
  94. let val = minRange + ((maxRange - minRange) * roll);
  95. if (isInt) {
  96. useProperty = property.substr(2);
  97. val = Math.round(val);
  98. } else
  99. val = ~~(val * 100) / 100;
  100. val = Math.max(range[0], Math.min(range[1], val));
  101. item.spell.values[useProperty] = val;
  102. });
  103. if (blueprint.spellProperties) {
  104. item.spell.properties = {};
  105. for (let p in blueprint.spellProperties)
  106. item.spell.properties[p] = blueprint.spellProperties[p];
  107. }
  108. if (item.range) {
  109. item.spell.properties = item.spell.properties || {};
  110. item.spell.properties.range = item.range;
  111. }
  112. }
  113. };