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.
 
 
 

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