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.
 
 
 

117 lines
2.0 KiB

  1. module.exports = {
  2. type: 'aura',
  3. cdMax: 0,
  4. manaCost: 0,
  5. duration: 10,
  6. aura: true,
  7. active: false,
  8. effects: {},
  9. cast: function (action) {
  10. this.active = !this.active;
  11. return true;
  12. },
  13. update: function () {
  14. let active = this.active;
  15. if (active)
  16. this.updateActive();
  17. else
  18. this.updateInactive();
  19. },
  20. unlearn: function () {
  21. this.updateInactive();
  22. },
  23. onAfterSimplify: function (values) {
  24. delete values.effects;
  25. },
  26. die: function () {
  27. if (this.active)
  28. this.cast();
  29. },
  30. updateActive: function () {
  31. let o = this.obj;
  32. let amount = 0;
  33. if (this.name === 'Innervation')
  34. amount = ~~((o.stats.values.hpMax / 100) * this.values.regenPercentage);
  35. else
  36. amount = this.values.regenPercentage || this.values.chance;
  37. let party = (o.social || {}).party || [];
  38. let members = [o.serverId, ...party];
  39. let effects = this.effects;
  40. let objects = o.instance.objects.objects;
  41. let range = this.auraRange;
  42. members.forEach(function (m) {
  43. let effect = effects[m];
  44. let obj = objects.find(o => (o.serverId === m));
  45. if (!obj) {
  46. if (effect)
  47. delete effects[m];
  48. return;
  49. }
  50. let distance = Math.max(Math.abs(o.x - obj.x), Math.abs(o.y - obj.y));
  51. if (distance > range) {
  52. if (effect) {
  53. delete effects[m];
  54. obj.effects.removeEffect(effect);
  55. }
  56. return;
  57. }
  58. if (effect)
  59. return;
  60. if (!obj.effects) {
  61. console.log('No Effects ', obj.name);
  62. return;
  63. }
  64. effects[obj.serverId] = obj.effects.addEffect({
  65. type: this.effect,
  66. amount: amount,
  67. caster: this.obj,
  68. ttl: -1,
  69. new: true
  70. });
  71. }, this);
  72. },
  73. updateInactive: function () {
  74. let o = this.obj;
  75. let effects = this.effects;
  76. let objects = o.instance.objects.objects;
  77. Object.keys(effects).forEach(function (m) {
  78. let effect = effects[m];
  79. if (!effect)
  80. return;
  81. let obj = objects.find(o => (o.serverId === m));
  82. if (!obj) {
  83. delete effects[m];
  84. return;
  85. }
  86. obj.effects.removeEffect(effect);
  87. delete effects[m];
  88. }, this);
  89. }
  90. };