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