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.
 
 
 

86 regels
2.0 KiB

  1. //Prebound Methods
  2. const mathRandom = Math.random.bind(Math);
  3. const max = Math.max.bind(Math);
  4. //Helpers
  5. const scaleStatType = (config, result) => {
  6. const { statType, statMult = 1, srcValues, scaleConfig } = config;
  7. if (!statType || scaleConfig?.statMult === false)
  8. return;
  9. let statValue = 0;
  10. if (!statType.push)
  11. statValue = srcValues[statType];
  12. else {
  13. statType.forEach(s => {
  14. statValue += srcValues[s];
  15. });
  16. }
  17. statValue = max(1, statValue);
  18. result.amount *= statValue * statMult;
  19. };
  20. const scalePercentMultipliers = ({ isAttack, elementName, srcValues, scaleConfig }, result) => {
  21. if (scaleConfig?.percentMult === false)
  22. return;
  23. const { dmgPercent = 0, physicalPercent = 0, spellPercent = 0 } = srcValues;
  24. let totalPercent = 100 + dmgPercent;
  25. if (isAttack)
  26. totalPercent += physicalPercent;
  27. else
  28. totalPercent += spellPercent;
  29. if (elementName)
  30. totalPercent += (srcValues[elementName + 'Percent'] || 0);
  31. result.amount *= (totalPercent / 100);
  32. };
  33. const scaleCrit = ({ noCrit, isAttack, crit: forceCrit, srcValues, scaleConfig }, result) => {
  34. if (noCrit || scaleConfig?.critMult === false)
  35. return;
  36. const { critChance, attackCritChance, spellCritChance } = srcValues;
  37. const { critMultiplier, attackCritMultiplier, spellCritMultiplier } = srcValues;
  38. let totalCritChance = critChance;
  39. let totalCritMultiplier = critMultiplier;
  40. if (isAttack) {
  41. totalCritChance += attackCritChance;
  42. totalCritMultiplier += attackCritMultiplier;
  43. } else {
  44. totalCritChance += spellCritChance;
  45. totalCritMultiplier += spellCritMultiplier;
  46. }
  47. const didCrit = forceCrit || mathRandom() * 100 < totalCritChance;
  48. if (didCrit) {
  49. result.crit = true;
  50. result.amount *= (totalCritMultiplier / 100);
  51. }
  52. };
  53. //Method
  54. const scale = (config, result) => {
  55. const { blocked, dodged } = result;
  56. if (blocked || dodged || config.noScale)
  57. return;
  58. scaleStatType(config, result);
  59. scalePercentMultipliers(config, result);
  60. scaleCrit(config, result);
  61. };
  62. //Exports
  63. module.exports = scale;