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

137 строки
2.5 KiB

  1. define([
  2. 'js/rendering/renderer',
  3. 'js/system/events'
  4. ], function (
  5. renderer,
  6. events
  7. ) {
  8. const auras = {
  9. reflectDamage: 0,
  10. stealth: 1,
  11. regenHp: 9,
  12. regenMana: 10,
  13. swiftness: 11,
  14. holyVengeance: 8,
  15. rare: 16
  16. };
  17. const buffIcons = {
  18. regenHp: [3, 1],
  19. regenMana: [4, 1],
  20. swiftness: [5, 1],
  21. stealth: [7, 0],
  22. reflectDamage: [2, 1],
  23. holyVengeance: [4, 0]
  24. };
  25. let templates = {};
  26. Object.keys(auras).forEach(type => {
  27. let cell = auras[type];
  28. templates[type] = {
  29. sprite: null,
  30. alpha: 0,
  31. alphaDir: 0.0025,
  32. alphaMax: 0.6,
  33. alphaMin: 0.35,
  34. alphaCutoff: 0.4,
  35. init: function () {
  36. this.sprite = renderer.buildObject({
  37. layerName: 'effects',
  38. sheetName: 'auras',
  39. x: this.obj.x,
  40. y: this.obj.y + 1,
  41. w: scale * 3,
  42. h: scale * 3,
  43. cell: cell
  44. });
  45. this.defaultDamageText();
  46. if (this.self && buffIcons[type]) {
  47. events.emit('onGetEffectIcon', {
  48. id: this.id,
  49. icon: buffIcons[type]
  50. });
  51. }
  52. },
  53. getAlpha: function () {
  54. let listAuras = this.obj.effects.effects.filter(e => auras[e.type]);
  55. let first = listAuras[0];
  56. // The first aura in the list should do all the updating so that all auras pulse together
  57. if (first === this) {
  58. this.alpha += this.alphaDir;
  59. if ((this.alphaDir > 0) && (this.alpha >= this.alphaMax)) {
  60. this.alpha = this.alphaMax;
  61. this.alphaDir *= -1;
  62. } else if ((this.alphaDir < 0) && (this.alpha <= this.alphaMin)) {
  63. this.alpha = this.alphaMin;
  64. this.alphaDir *= -1;
  65. }
  66. } else {
  67. this.alpha = first.alpha;
  68. this.alphaDir = first.alphaDir;
  69. }
  70. let useAlpha = this.alpha;
  71. if (useAlpha < this.alphaCutoff)
  72. useAlpha = 0;
  73. else {
  74. useAlpha -= this.alphaCutoff;
  75. useAlpha /= (this.alphaMax - this.alphaCutoff);
  76. }
  77. return useAlpha;
  78. },
  79. update: function () {
  80. let useAlpha = this.getAlpha();
  81. let x = this.obj.x;
  82. let y = this.obj.y;
  83. renderer.setSpritePosition({
  84. x,
  85. y: y + 1,
  86. sprite: this.sprite
  87. });
  88. this.sprite.alpha = useAlpha;
  89. this.sprite.visible = this.obj.isVisible;
  90. },
  91. destroy: function () {
  92. renderer.destroyObject({
  93. layerName: 'effects',
  94. sprite: this.sprite
  95. });
  96. this.defaultDamageText(true);
  97. if (this.self && buffIcons[type]) {
  98. events.emit('onRemoveEffectIcon', {
  99. id: this.id
  100. });
  101. }
  102. },
  103. setVisible: function (visible) {
  104. this.sprite.visible = visible;
  105. }
  106. };
  107. });
  108. return {
  109. templates: {
  110. ...templates
  111. }
  112. };
  113. });