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.
 
 
 

137 lines
2.5 KiB

  1. define([
  2. 'js/rendering/renderer'
  3. ], function (
  4. renderer
  5. ) {
  6. let auras = {
  7. reflectDamage: 0,
  8. stealth: 1,
  9. regenHp: 9,
  10. regenMana: 10,
  11. swiftness: 11,
  12. holyVengeance: 8,
  13. rare: 16
  14. };
  15. return {
  16. type: 'effects',
  17. alpha: 0,
  18. alphaDir: 0.0025,
  19. alphaMax: 0.6,
  20. alphaMin: 0.35,
  21. alphaCutoff: 0.4,
  22. effects: [],
  23. init: function (blueprint) {
  24. this.effects = this.effects
  25. .filter(e => auras[e] !== null)
  26. .map(e => {
  27. return {
  28. name: e,
  29. sprite: renderer.buildObject({
  30. layerName: 'effects',
  31. sheetName: 'auras',
  32. x: this.obj.x,
  33. y: this.obj.y + 1,
  34. w: scale * 3,
  35. h: scale * 3,
  36. cell: auras[e]
  37. })
  38. };
  39. });
  40. },
  41. extend: function (blueprint) {
  42. if (blueprint.addEffects) {
  43. blueprint.addEffects = blueprint.addEffects
  44. .filter(e => {
  45. return (auras[e] !== null);
  46. })
  47. .map(e => {
  48. return {
  49. name: e,
  50. sprite: renderer.buildObject({
  51. layerName: 'effects',
  52. sheetName: 'auras',
  53. x: this.obj.x,
  54. y: this.obj.y + 1,
  55. w: scale * 3,
  56. h: scale * 3,
  57. cell: auras[e]
  58. })
  59. };
  60. });
  61. this.effects.push.apply(this.effects, blueprint.addEffects || []);
  62. }
  63. if (blueprint.removeEffects) {
  64. blueprint.removeEffects.forEach(r => {
  65. let effect = this.effects.find(e => e.name === r);
  66. if (!effect)
  67. return;
  68. renderer.destroyObject({
  69. layerName: 'effects',
  70. sprite: effect.sprite
  71. });
  72. this.effects.spliceFirstWhere(e => e.name === r);
  73. });
  74. }
  75. },
  76. update: function () {
  77. this.alpha += this.alphaDir;
  78. if ((this.alphaDir > 0) && (this.alpha >= this.alphaMax)) {
  79. this.alpha = this.alphaMax;
  80. this.alphaDir *= -1;
  81. } else if ((this.alphaDir < 0) && (this.alpha <= this.alphaMin)) {
  82. this.alpha = this.alphaMin;
  83. this.alphaDir *= -1;
  84. }
  85. let x = this.obj.x;
  86. let y = this.obj.y;
  87. let useAlpha = this.alpha;
  88. if (useAlpha < this.alphaCutoff)
  89. useAlpha = 0;
  90. else {
  91. useAlpha -= this.alphaCutoff;
  92. useAlpha /= (this.alphaMax - this.alphaCutoff);
  93. }
  94. this.effects.forEach(e => {
  95. renderer.setSpritePosition({
  96. x,
  97. y: y + 1,
  98. sprite: e.sprite
  99. });
  100. e.sprite.alpha = useAlpha;
  101. e.sprite.visible = this.obj.isVisible;
  102. });
  103. },
  104. setVisible: function (visible) {
  105. this.effects.forEach(e => {
  106. e.sprite.visible = visible;
  107. });
  108. },
  109. destroy: function () {
  110. this.effects.forEach(e => {
  111. renderer.destroyObject({
  112. layerName: 'effects',
  113. sprite: e.sprite
  114. });
  115. });
  116. }
  117. };
  118. });