LevelHomeAward.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. const HomeApi = require("../net/HomeApi");
  2. const GameNotificationKey = require("../utils/GameEnum").GameNotificationKey;
  3. const GameModule = require("../utils/GameModule");
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. },
  8. // LIFE-CYCLE CALLBACKS:
  9. onLoad () {
  10. this.isGetting = false;
  11. this.isPlaying = false;
  12. let self = this;
  13. this.node.on(cc.Node.EventType.TOUCH_END, () => {
  14. self.getAward();
  15. });
  16. GameModule.homeGuide.on('Fire_state26', this.getAward, this);
  17. },
  18. start () {
  19. },
  20. init(roomId, pickupCallback) {
  21. this.roomId = roomId;
  22. this.pickupCallback = pickupCallback;
  23. },
  24. getAward() {
  25. if (this.isGetting || this.isPlaying) { return }
  26. this.isGetting = true;
  27. HomeApi.getRoomAward(this.roomId, (responseData) => {
  28. this.isGetting = false;
  29. GameModule.audioMng.playGetAward();
  30. this.pickupCallback(responseData.awardCount);
  31. GameEvent.fire(GameNotificationKey.GetRoomAward,responseData);
  32. let roomName = GameGlobal.BuildingManager.getRoomName(this.roomId);
  33. GameEvent.fire(GameNotificationKey.GameShowAdditionTips,roomName,1);
  34. let objct = {'cdTime': -6 * 1000, 'desc': roomName + ' 提升2倍的金币产出', 'icon': 900001};
  35. GameGlobal._fixInformations.push(objct);
  36. GameEvent.fire(GameNotificationKey.GameUpdateMessageList, 1, false);
  37. },(errCode, errMsg) => {
  38. this.isGetting = false;
  39. GameGlobal.commonAlert.showCommonErrorAlert("领取奖励失败");
  40. });
  41. if (!GameModule.homeGuide.getComponent('HomeGuide').isPassGuideState('state27')) {
  42. GameModule.homeGuide.getComponent('HomeGuide').handleGuideStateNext('state26', 'state27');
  43. }
  44. },
  45. showAnimation() {
  46. if (this.isPlaying) { return; }
  47. this.node.stopAllActions();
  48. this.node.active = true;
  49. this.isPlaying = true;
  50. let jumpHeight = 100;
  51. let duration = 0.3;
  52. let animationArray = [];
  53. let moveAction1 = cc.moveBy(duration, 0, jumpHeight).easing(cc.easeCubicActionOut());
  54. let moveAction2 = cc.moveBy(duration, 0, -110).easing(cc.easeCubicActionIn());
  55. animationArray.push(moveAction1);
  56. animationArray.push(moveAction2);
  57. while(jumpHeight > 0.1) {
  58. jumpHeight = jumpHeight - (jumpHeight / 3);
  59. duration = duration - (duration / 3);
  60. let upAction = cc.moveBy(duration, 0, jumpHeight).easing(cc.easeCubicActionOut());
  61. let downAction = cc.moveBy(duration, 0, -jumpHeight).easing(cc.easeCubicActionIn());
  62. animationArray.push(upAction);
  63. animationArray.push(downAction);
  64. }
  65. let callback = cc.callFunc(() => {
  66. this.isPlaying = false;
  67. GameModule.homeGuide.getComponent('HomeGuide').handleGuideStateNext('state24', 'state26');
  68. });
  69. animationArray.push(callback);
  70. this.node.runAction(cc.sequence(animationArray));
  71. },
  72. updateAnimation() {
  73. if (this.isPlaying) { return; }
  74. this.node.active = true;
  75. this.node.stopAllActions();
  76. this.isPlaying = true;
  77. let jumpHeight = 100;
  78. let duration = 0.3;
  79. let animationArray = [];
  80. let moveAction1 = cc.moveBy(duration, 0, jumpHeight).easing(cc.easeCubicActionOut());
  81. let moveAction2 = cc.moveBy(duration, 0, -100).easing(cc.easeCubicActionIn());
  82. animationArray.push(moveAction1);
  83. animationArray.push(moveAction2);
  84. while(jumpHeight > 0.1) {
  85. jumpHeight = jumpHeight - (jumpHeight / 3);
  86. duration = duration - (duration / 3);
  87. let upAction = cc.moveBy(duration, 0, jumpHeight).easing(cc.easeCubicActionOut());
  88. let downAction = cc.moveBy(duration, 0, -jumpHeight).easing(cc.easeCubicActionIn());
  89. animationArray.push(upAction);
  90. animationArray.push(downAction);
  91. }
  92. let callback = cc.callFunc(() => {
  93. this.isPlaying = false;
  94. });
  95. animationArray.push(callback);
  96. this.node.runAction(cc.sequence(animationArray));
  97. },
  98. // update (dt) {},
  99. });