Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

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