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.
 
 
 

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