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.
 
 
 

57 regels
1.4 KiB

  1. //Prebound Methods
  2. const max = Math.max.bind(Math);
  3. const pow = Math.pow.bind(Math);
  4. //Helpers
  5. const mitigateResistances = ({ elementName, noMitigate, tgtValues }, result) => {
  6. //Don't mitigate physical damage
  7. if (!elementName)
  8. return;
  9. const resist = tgtValues[elementName + 'Resist'] || 0;
  10. const resistanceMultiplier = max(0.5 + max((1 - (resist / 100)) / 2, -0.5), 0.5);
  11. result.amount *= resistanceMultiplier;
  12. };
  13. const mitigateArmor = ({ element, tgtValues, srcValues }, result) => {
  14. //Don't mitigate elemental damage
  15. if (element)
  16. return;
  17. const armorMultiplier = max(0.5 + max((1 - ((tgtValues.armor || 0) / (srcValues.level * 50))) / 2, -0.5), 0.5);
  18. result.amount *= armorMultiplier;
  19. };
  20. const mitigatePvp = ({ source, target, srcValues }, result) => {
  21. const isPvp = (
  22. (source.player || (source.follower && source.follower.master && source.follower.master.player)) &&
  23. (target.player || (target.follower && target.follower.master && target.follower.master.player))
  24. );
  25. if (!isPvp)
  26. return;
  27. const multiplier = 1 / pow(2, srcValues.level / 5);
  28. result.amount *= multiplier;
  29. };
  30. //Method
  31. const mitigate = (config, result) => {
  32. const { blocked, dodged } = result;
  33. //Heals, among other things, should not be mitigated
  34. if (blocked || dodged || config.noMitigate)
  35. return;
  36. mitigateResistances(config, result);
  37. mitigateArmor(config, result);
  38. mitigatePvp(config, result);
  39. };
  40. //Exports
  41. module.exports = mitigate;