GameOverMediator.ts 7.6 KB

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