GameOverMediator.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import { _decorator, Component, Node, LabelComponent, Vec2, Vec3, view } from 'cc';
  2. import { GUIManager } from '../../../engines/gui/GUIManager';
  3. import { GUIMediator } from '../../../engines/gui/GUIMediator';
  4. import { NoticeManager } from '../../../engines/notices/NoticeManager';
  5. import { SceneManager } from '../../../engines/scenes/SceneManager';
  6. import { LiangLiangSDK } from '../../../libs/liangliangSDK';
  7. import { PlatformManager } from '../../../Platform/PlatformManager';
  8. import { WeChatPlatform } from '../../../Platform/WeChat/WeChatPlatform';
  9. import GameConfigManager from '../../models/GameConfigManager';
  10. import { GameModel } from '../../models/GameModel';
  11. import { GameController } from '../fightings/GameController';
  12. import { UIConst } from '../UIConst';
  13. const { ccclass, property } = _decorator;
  14. @ccclass('GameOverMediator')
  15. export class GameOverMediator extends GUIMediator {
  16. @property(Node)
  17. WinGroup: Node = null;
  18. @property({
  19. type: LabelComponent
  20. })
  21. WinAwardLabel: LabelComponent = null;
  22. @property(Node)
  23. DefeatedGroup: Node = null;
  24. @property(Node)
  25. WinBackButton: Node = null;
  26. @property(Node)
  27. DefeatedBackButton: Node = null;
  28. private isWin: boolean;
  29. private award: number;
  30. onLoad() {
  31. // PlatformManager.showBanner()
  32. }
  33. OnShow(data?: any): void {
  34. super.OnShow(data);
  35. this.isWin = data;
  36. this.WinGroup.active = this.isWin;
  37. this.DefeatedGroup.active = !this.isWin;
  38. //胜利
  39. if (this.isWin == true) {
  40. this.WinGroup.active = true;
  41. this.DefeatedGroup.active = false;
  42. let levelConfig: any = GameConfigManager.GetLevelConfig(GameModel.single.currentLevel - 1);
  43. //关卡基础奖励
  44. this.award = levelConfig.awards + levelConfig.killAward * GameModel.single.killCount;
  45. this.WinAwardLabel.string = this.award.toString();
  46. let weChat = PlatformManager.impl as WeChatPlatform;
  47. if(weChat instanceof WeChatPlatform){
  48. weChat.successBranchAnalytics(String(GameModel.single.currentLevel));
  49. }
  50. } else {//失败
  51. //失败不算奖励
  52. this.WinGroup.active = false;
  53. this.DefeatedGroup.active = true;
  54. let weChat = PlatformManager.impl as WeChatPlatform;
  55. if(weChat instanceof WeChatPlatform){
  56. weChat.failBranchAnalytics(String(GameModel.single.currentLevel));
  57. }
  58. }
  59. this.backButtonHandle();
  60. }
  61. /**
  62. * 返回按钮误触
  63. */
  64. backButtonHandle(): void {
  65. if (LiangLiangSDK.CanWuChu() == true) {
  66. this.WinBackButton.position = new Vec3(0, -(view.getVisibleSize().height / 2 - 50), 0);
  67. this.DefeatedBackButton.position = new Vec3(0, -(view.getVisibleSize().height / 2 - 50), 0);
  68. this.scheduleOnce(() => {
  69. PlatformManager.showBanner();
  70. this.WinBackButton.position = new Vec3(0, -375, 0);
  71. this.DefeatedBackButton.position = new Vec3(0, -358, 0);
  72. }, 3)
  73. } else {
  74. PlatformManager.showBanner();
  75. }
  76. }
  77. /**
  78. * 开始下一关
  79. */
  80. PlayNextLevel(): void {
  81. this.AddAward();
  82. this.HideSelf();
  83. GameController.single.PlayNextLevel();
  84. }
  85. /**
  86. * 重玩
  87. */
  88. Replay(): void {
  89. PlatformManager.showRewardedVideo(() => {
  90. PlatformManager.hideBanner();
  91. this.AddAward();
  92. this.HideSelf();
  93. GameController.single.Replay();
  94. }, () => {
  95. NoticeManager.ShowPrompt("复活失败");
  96. })
  97. }
  98. /**
  99. * 返回主界面
  100. */
  101. BackToMain(): void {
  102. this.AddAward();
  103. SceneManager.single.Swicth("PrepareScene");
  104. GUIManager.single.Hide(UIConst.FIGHTING_UI);
  105. //关闭自身
  106. this.HideSelf();
  107. }
  108. /**
  109. * 去全屏幕界面
  110. */
  111. GoToFullOutput(): void {
  112. this.AddAward();
  113. GUIManager.single.Show(UIConst.FULL_OUTPUT_UI);
  114. this.HideSelf();
  115. }
  116. /**
  117. * 十倍之后去全屏界面
  118. */
  119. getTenAward(): void {
  120. this.AddAdAward(10, () => {
  121. GUIManager.single.Show(UIConst.FULL_OUTPUT_UI);
  122. this.HideSelf();
  123. });
  124. }
  125. /**
  126. * 十倍奖励
  127. * @param value
  128. */
  129. private AddAdAward(value: number = 1, success): void {
  130. if (this.isWin) {
  131. PlatformManager.showRewardedVideo(() => {
  132. GameModel.single.gold += this.award * value;
  133. success();
  134. }, () => {
  135. NoticeManager.ShowPrompt("领取失败");
  136. })
  137. }
  138. }
  139. /**
  140. * 获取奖励
  141. */
  142. private AddAward(value: number = 1): void {
  143. if (this.isWin) {
  144. GameModel.single.gold += this.award * value;
  145. }
  146. }
  147. OnHide(): void {
  148. }
  149. }