Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

192 строки
4.0 KiB

  1. define([
  2. 'config/spells/spellCallbacks',
  3. 'combat/combat'
  4. ], function (
  5. spellCallbacks,
  6. combat
  7. ) {
  8. return {
  9. cd: 0,
  10. cdMax: 0,
  11. manaCost: 1,
  12. threatMult: 1,
  13. needLos: false,
  14. pendingAttacks: [],
  15. castBase: function () {
  16. if (this.cd > 0)
  17. return false;
  18. else if (this.manaCost > this.obj.stats.values.mana)
  19. return false;
  20. else
  21. return true;
  22. },
  23. canCast: function (target) {
  24. if (this.cd > 0)
  25. return false;
  26. else if (this.manaCost > this.obj.stats.values.mana)
  27. return false;
  28. else if (!target)
  29. return true;
  30. else {
  31. var inRange = true;
  32. if (this.range != null) {
  33. var obj = this.obj;
  34. var distance = Math.max(Math.abs(target.x - obj.x), Math.abs(target.y - obj.y));
  35. inRange = (distance <= this.range);
  36. }
  37. return inRange;
  38. }
  39. },
  40. updateBase: function () {
  41. if (this.cd > 0)
  42. this.cd--;
  43. },
  44. calcDps: function (target, noSync) {
  45. if ((!this.values) || (this.spellType == 'buff'))
  46. return;
  47. if ((!this.damage) && (!this.healing))
  48. delete this.values.dps;
  49. else {
  50. var noMitigate = !target;
  51. var dmg = combat.getDamage({
  52. source: this.obj,
  53. target: (target || {
  54. stats: {
  55. values: {}
  56. }
  57. }),
  58. damage: (this.damage || this.healing) * (this.dmgMult || 1),
  59. cd: this.cdMax,
  60. element: this.element,
  61. statType: this.statType,
  62. statMult: this.statMult,
  63. noMitigate: noMitigate,
  64. noCrit: true
  65. }).amount;
  66. var critChance = this.obj.stats.values.critChance;
  67. var critMultiplier = this.obj.stats.values.critMultiplier;
  68. var attackSpeed = (this.obj.stats.values.attackSpeed / 100);
  69. attackSpeed += 1;
  70. dmg = (((dmg / 100) * (100 - critChance)) + (((dmg / 100) * critChance) * (critMultiplier / 100))) * attackSpeed;
  71. var duration = this.values.duration;
  72. if (duration) {
  73. dmg *= duration;
  74. }
  75. dmg /= this.cdMax;
  76. if (this.damage) {
  77. this.values.dmg = ~~(dmg * 100) / 100 + '/tick';
  78. } else
  79. this.values.heal = ~~(dmg * 100) / 100 + '/tick';
  80. if (!noSync)
  81. this.obj.syncer.setArray(true, 'spellbook', 'getSpells', this.simplify());
  82. }
  83. },
  84. sendAnimation: function (blueprint) {
  85. this.obj.instance.syncer.queue('onGetObject', blueprint);
  86. },
  87. sendBump: function (target) {
  88. var x = this.obj.x;
  89. var y = this.obj.y;
  90. var tx = target.x;
  91. var ty = target.y;
  92. var deltaX = 0;
  93. var deltaY = 0;
  94. if (tx < x)
  95. deltaX = -1;
  96. else if (tx > x)
  97. deltaX = 1;
  98. if (ty < y)
  99. deltaY = -1;
  100. else if (ty > y)
  101. deltaY = 1;
  102. var components = [{
  103. type: 'bumpAnimation',
  104. deltaX: deltaX,
  105. deltaY: deltaY
  106. }];
  107. if (this.animation) {
  108. components.push({
  109. type: 'animation',
  110. template: this.animation
  111. });
  112. }
  113. this.obj.instance.syncer.queue('onGetObject', {
  114. id: this.obj.id,
  115. components: components
  116. });
  117. },
  118. simplify: function (self) {
  119. var values = {};
  120. for (var p in this) {
  121. var value = this[p];
  122. if ((typeof (value) == 'function') || (p == 'obj'))
  123. continue;
  124. values[p] = value;
  125. }
  126. if (this.animation)
  127. values.animation = this.animation.name;
  128. if (this.values)
  129. values.values = this.values;
  130. if (this.onAfterSimplify)
  131. this.onAfterSimplify(values);
  132. return values;
  133. },
  134. getDamage: function (target, noMitigate) {
  135. var damage = {
  136. source: this.obj,
  137. target: target,
  138. damage: (this.damage || this.healing) * (this.dmgMult || 1),
  139. cd: this.cdMax,
  140. element: this.element,
  141. statType: this.statType,
  142. statMult: this.statMult,
  143. isAttack: (this.type == 'melee'),
  144. noMitigate: noMitigate
  145. };
  146. this.obj.fireEvent('onBeforeCalculateDamage', damage);
  147. var damage = combat.getDamage(damage);
  148. return damage;
  149. },
  150. queueCallback: function (callback, delay, destroyCallback, target, destroyOnRezone) {
  151. return this.obj.spellbook.registerCallback(this.obj.id, callback, delay, destroyCallback, target ? target.id : null, destroyOnRezone);
  152. },
  153. die: function () {
  154. this.obj.spellbook.unregisterCallback(this.obj.id);
  155. }
  156. };
  157. });