GameOverMediator.ts 7.4 KB

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