GameOverMediator.ts 5.9 KB

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