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.
 
 
 

127 line
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(function (e) {
  26. return (auras[e] !== null);
  27. }, this)
  28. .map(function (e) {
  29. return {
  30. name: e,
  31. sprite: renderer.buildObject({
  32. layerName: 'effects',
  33. sheetName: 'auras',
  34. x: this.obj.x - 0.5,
  35. y: this.obj.y - 0.5,
  36. w: scale * 2,
  37. h: scale * 2,
  38. cell: auras[e]
  39. })
  40. };
  41. }, this);
  42. },
  43. extend: function (blueprint) {
  44. if (blueprint.addEffects) {
  45. blueprint.addEffects = blueprint.addEffects
  46. .filter(function (e) {
  47. return (auras[e] !== null);
  48. })
  49. .map(function (e) {
  50. return {
  51. name: e,
  52. sprite: renderer.buildObject({
  53. layerName: 'effects',
  54. sheetName: 'auras',
  55. x: this.obj.x - 0.5,
  56. y: this.obj.y - 0.5,
  57. w: scale * 2,
  58. h: scale * 2,
  59. cell: auras[e]
  60. })
  61. };
  62. }, this);
  63. this.effects.push.apply(this.effects, blueprint.addEffects || []);
  64. }
  65. if (blueprint.removeEffects) {
  66. blueprint.removeEffects.forEach(function (r) {
  67. let effect = this.effects.find(e => e.name === r);
  68. if (!effect)
  69. return;
  70. renderer.destroyObject({
  71. layerName: 'effects',
  72. sprite: effect.sprite
  73. });
  74. this.effects.spliceFirstWhere(e => e.name === r);
  75. }, this);
  76. }
  77. },
  78. update: function () {
  79. this.alpha += this.alphaDir;
  80. if ((this.alphaDir > 0) && (this.alpha >= this.alphaMax)) {
  81. this.alpha = this.alphaMax;
  82. this.alphaDir *= -1;
  83. } else if ((this.alphaDir < 0) && (this.alpha <= this.alphaMin)) {
  84. this.alpha = this.alphaMin;
  85. this.alphaDir *= -1;
  86. }
  87. let x = (this.obj.x - 0.5) * scale;
  88. let y = (this.obj.y - 0.5) * scale;
  89. let useAlpha = this.alpha;
  90. if (useAlpha < this.alphaCutoff)
  91. useAlpha = 0;
  92. else {
  93. useAlpha -= this.alphaCutoff;
  94. useAlpha /= (this.alphaMax - this.alphaCutoff);
  95. }
  96. this.effects.forEach(function (e) {
  97. e.sprite.alpha = useAlpha;
  98. e.sprite.x = x;
  99. e.sprite.y = y;
  100. }, this);
  101. },
  102. destroy: function () {
  103. this.effects.forEach(function (e) {
  104. renderer.destroyObject({
  105. layerName: 'effects',
  106. sprite: e.sprite
  107. });
  108. });
  109. }
  110. };
  111. });