Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

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