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.
 
 
 

38 lines
1.1 KiB

  1. const spellBaseTemplate = require('../spells/spellTemplate');
  2. module.exports = {
  3. events: {
  4. onGetText: function (item) {
  5. const { rolls: { chance, spell, damage = 1 } } = item.effects.find(e => (e.type === 'castSpellOnHit'));
  6. return `${chance}% chance to cast a ${damage} damage ${spell} on hit`;
  7. },
  8. afterDealDamage: function (item, { damage, target }) {
  9. //Should only proc for attacks...this is kind of a hack
  10. const { element } = damage;
  11. if (element)
  12. return;
  13. const { rolls: { chance, spell, statType = 'dex', damage: spellDamage = 1 } } = item.effects.find(e => (e.type === 'castSpellOnHit'));
  14. const chanceRoll = Math.random() * 100;
  15. if (chanceRoll >= chance)
  16. return;
  17. const spellName = 'spell' + spell.replace(/./, spell.toUpperCase()[0]);
  18. const spellTemplate = require(`../spells/${spellName}`);
  19. const builtSpell = extend({ obj: this }, spellBaseTemplate, spellTemplate, {
  20. name: spellName,
  21. noEvents: true,
  22. statType,
  23. damage: spellDamage,
  24. duration: 5,
  25. radius: 1
  26. });
  27. builtSpell.cast();
  28. }
  29. }
  30. };