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.

74 lines
1.4 KiB

  1. define([
  2. 'js/system/client',
  3. 'js/system/events',
  4. 'js/misc/physics'
  5. ], function (
  6. client,
  7. events,
  8. physics
  9. ) {
  10. return {
  11. type: 'gatherer',
  12. effect: null,
  13. init: function () {
  14. this.obj.on('onKeyDown', this.onKeyDown.bind(this));
  15. },
  16. extend: function (msg) {
  17. if ((msg.width) && (msg.progress !== 100)) {
  18. if (this.effect)
  19. this.effect.destroyed = true;
  20. let x = 0;
  21. let y = 0;
  22. do {
  23. x = msg.x + ~~(Math.random() * msg.width);
  24. y = msg.y + ~~(Math.random() * msg.height);
  25. } while (!physics.isTileBlocking(x, y) || Math.max(Math.abs(x - this.obj.x), Math.abs(y - this.obj.y)) <= 2);
  26. this.obj.flipX = (x < this.obj.x);
  27. this.obj.setSpritePosition();
  28. this.effect = this.obj.addComponent('lightningEffect', {
  29. new: true,
  30. toX: x,
  31. toY: y,
  32. ttl: -1,
  33. divisions: 4,
  34. cdMax: 12,
  35. colors: [0xc0c3cf, 0xc0c3cf, 0x929398],
  36. maxDeviate: 5,
  37. lineGrow: true,
  38. lineShrink: true
  39. });
  40. } else {
  41. if ((msg.progress === 100) && (this.effect)) {
  42. this.effect.destroyed = true;
  43. this.effect = null;
  44. }
  45. events.emit('onShowProgress', (msg.action || 'Gathering') + '...', msg.progress);
  46. }
  47. },
  48. onKeyDown: function (key) {
  49. if (key !== 'g')
  50. return;
  51. client.request({
  52. cpn: 'player',
  53. method: 'performAction',
  54. data: {
  55. cpn: 'gatherer',
  56. method: 'gather'
  57. }
  58. });
  59. },
  60. destroy: function () {
  61. this.unhookEvents();
  62. }
  63. };
  64. });