GameOverMediator.ts 5.5 KB

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