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

131 строка
2.5 KiB

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