GameOverMediator.ts 5.6 KB

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