MouseGameFrameView.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. import { qp } from "../../../SubGamePublic/PG_Public/Script/lib/define2";
  2. import { theAudoConfig, theGlobalUserInfo } from "../../../SubGamePublic/PG_Public/Script/lib/global2";
  3. import MouseBottom from "./MouseBottom";
  4. import { MouseConst } from "./MouseConst";
  5. import MouseGameFrame from "./MouseGameFrame";
  6. import MouseIconView from "./MouseIconView";
  7. import MouseNotice from "./MouseNotice";
  8. import MouseWinView from "./MouseWinView";
  9. import MouseSpin from "./MouseSpin";
  10. import MouseAutoView from "./MouseAutoView";
  11. import MouseAutoModel from "./MouseAutoModel";
  12. const { ccclass, property, menu } = cc._decorator;
  13. const TWEEN_TIME = 1002;
  14. @ccclass
  15. @menu("Game/Mouse/MouseGameFrameView")
  16. export default class MouseGameFrameView extends cc.Component {//AbstractGameFrameView<MouseGameFrame>
  17. _frame: MouseGameFrame = null;
  18. get frame(): MouseGameFrame {
  19. return this._frame;
  20. }
  21. @property({ type: MouseBottom, tooltip: '底部' })
  22. bottomView: MouseBottom = null;
  23. @property({ type: MouseIconView, tooltip: '转动区' })
  24. iconView: MouseIconView = null;
  25. @property({ type: MouseWinView, tooltip: '中奖特效' })
  26. winView: MouseWinView = null;
  27. @property({ type: MouseNotice, tooltip: '通知栏' })
  28. noticeView: MouseNotice = null;
  29. @property(MouseSpin)
  30. mouseSpin: MouseSpin = null;
  31. @property(cc.Node)
  32. nodeTest: cc.Node = null;
  33. @property(cc.AudioClip)
  34. normalBgm: cc.AudioClip = null;
  35. // =============== AutoView Start ===================
  36. autoModel: MouseAutoModel = null;
  37. @property(cc.Prefab)
  38. autoView: cc.Prefab = null;
  39. @property({ type: cc.Node, tooltip: '弹窗承载节点' })
  40. popParent: cc.Node = null;
  41. addNode(node: cc.Node) { node.parent = this.popParent; }
  42. popAutoView() {
  43. //回调
  44. let autoFunc = (data: NSlots.IAutoData) => {
  45. this.autoModel.setAutoData(data);
  46. this.onDealAuto();
  47. };
  48. let view = cc.instantiate(this.autoView).getComponent(MouseAutoView);
  49. //这里的值根据自己的框架获取即可
  50. view.initData(this.bottomView.gameBalance, this.bottomView.curBetScore, this.bottomView.winScore, autoFunc);
  51. //这里直接加到场景上也可以,和paytable一样即可
  52. this.addNode(view.node);
  53. }
  54. onDealAuto() {
  55. if (!this.isAuto()) return;
  56. //auto的一些UI处理,这里根据自己的实际情况来写
  57. this.setBtnEnabled(false);
  58. //自动UI
  59. this.bottomView.updateAutoEnable();
  60. this.onSpinAuto();
  61. }
  62. /**@description auto spin */
  63. onSpinAuto() {
  64. this.scheduleOnce(() => {
  65. this.autoModel.updateRound();
  66. this.bottomView.updateAutoTimes();
  67. }, 0.3);
  68. this.scheduleOnce(() => this.spinNormal(), 0.4);
  69. }
  70. onExitAuto() {
  71. this.autoModel.clear();
  72. this.bottomView.updateAutoEnable();
  73. this.setBtnEnabled(!this.isGaming);
  74. }
  75. isAuto() {
  76. return this.autoModel.isAuto;
  77. }
  78. // =============== AutoView End ===================
  79. // =============== 时钟 Start===================
  80. @property(cc.Label)
  81. labTime: cc.Label = null;
  82. timer = null;
  83. _idleTime: number = 0; // 老鼠空闲
  84. protected start(): void {
  85. let time = new Date().getTime();
  86. this.labTime.string = this.formatTime(time);
  87. this.timer = setInterval(() => {
  88. let time = new Date().getTime();
  89. this.labTime.string = this.formatTime(time);
  90. if (this.isGaming) {
  91. this._idleTime = 0;
  92. } else {
  93. this._idleTime++;
  94. }
  95. if (this._idleTime > 1 * 60) { // 1分钟
  96. this.iconView.mouseAvatar.playIdleAnim();
  97. this._idleTime = 0;
  98. }
  99. }, 1000);
  100. }
  101. formatTime(timestamp): string {
  102. var date = new Date(timestamp);
  103. var hours: any = date.getHours();
  104. var minutes: any = date.getMinutes();
  105. var seconds: any = date.getSeconds();
  106. // 添加前导零,确保两位数的格式
  107. hours = (hours < 10) ? "0" + hours : hours;
  108. minutes = (minutes < 10) ? "0" + minutes : minutes;
  109. seconds = (seconds < 10) ? "0" + seconds : seconds;
  110. return hours + ":" + minutes + ":" + seconds;
  111. }
  112. protected onDestroy(): void {
  113. clearInterval(this.timer);
  114. }
  115. // =============== 时钟 End ===================
  116. private _isGaming: boolean = false; // 是否游戏中
  117. set isGaming(v: boolean) {
  118. this._isGaming = v;
  119. }
  120. get isGaming() {
  121. return this._isGaming;
  122. }
  123. private _isSuperSpin = false; // 是否开始超级转
  124. get isSuperSpin() {
  125. return this._isSuperSpin;
  126. }
  127. set isSuperSpin(v: boolean) {
  128. this._isSuperSpin = v;
  129. }
  130. onLoad() {
  131. // 声音控制
  132. theAudoConfig.enableMusic = Global.getInstance().ismusicon !== 0;
  133. theAudoConfig.enableEffect = Global.getInstance().issoundon !== 0;
  134. this.autoModel = new MouseAutoModel();
  135. }
  136. //初始化工作
  137. initGameView(frame: MouseGameFrame): void {
  138. // super.initGameView(frame);
  139. }
  140. //重置视图
  141. resetGameView(): void {
  142. if (this.isGaming) {
  143. cc.error("==================== MouseGameFrameView resetGameView 跳过,正在游戏中 ====================");
  144. return;
  145. }
  146. cc.error("==================== MouseGameFrameView resetGameView ====================");
  147. // super.resetGameView();
  148. // 重置
  149. this.unscheduleAllCallbacks();
  150. this.node.stopAllActions();
  151. cc.Tween.stopAllByTarget(this.iconView);
  152. this.isGaming = false;
  153. this.isSuperSpin = false;
  154. this.bottomView.resetView();
  155. this.iconView.resetView();
  156. this.winView.resetView();
  157. this.noticeView.resetView();
  158. }
  159. /**
  160. * 根据场景配置设置押分挡位
  161. */
  162. // updateBetScore(betlevelScore: number[]) {
  163. // if (betlevelScore instanceof Array) {
  164. // this.bottomView.betScoreArray = betlevelScore;
  165. // }
  166. // }
  167. /**
  168. * 根据场景配置设置押分挡位
  169. * @param betLevelScore
  170. * @param data
  171. */
  172. updateBetScore(betLevelScore: number[], data: NSlots.I_BetResp) {
  173. this.bottomView.updateBetScore(betLevelScore, data);
  174. this.bottomView.updateBetView(data);
  175. }
  176. /**
  177. * 更新用户余额
  178. */
  179. updateMyScore(score: number) {
  180. cc.error("更新自己的钱", score);
  181. this.bottomView.gameBalance = score;
  182. this.bottomView.realBalance = score;
  183. }
  184. // ========================= 游戏流程 ==========================
  185. onSpinPre() {
  186. this.isGaming = true;
  187. // 游戏开始音效
  188. // AudioPlayer.playEffect(MouseConst.Sound.spinStart, false);
  189. // Global.getInstance().hideShowLoading("waitResult");
  190. this.winView.resetView();
  191. this.noticeView.resetView();
  192. this.iconView.resetView();
  193. this.bottomView.resetView();
  194. this.iconView.onSpinPre();
  195. this.mouseSpin.spinStart();
  196. }
  197. /**
  198. * 接收游戏结果, 执行转动
  199. */
  200. onSpinStart(result: NSlots.ICommonResult, hasSuperSpin?: boolean) {
  201. cc.warn("==================> onSpinStart, hasSuperSpin:" + hasSuperSpin);
  202. if (this.isSuperSpin) {
  203. this.winView.resetView();
  204. this.noticeView.resetView();
  205. this.iconView.resetView();
  206. this.bottomView.resetView();
  207. }
  208. this.iconView.onSpinReady(result, () => this.onCheckWin(result), hasSuperSpin);
  209. // 转的过程中(开始1s后)执行Super动画
  210. if (hasSuperSpin) {
  211. this.scheduleOnce(() => {
  212. this.iconView.playSuperAnim(() => {
  213. this.noticeView.onEnterSuper();
  214. this.onSuperSpinStart();
  215. });
  216. }, 1);
  217. }
  218. }
  219. /**
  220. * 检查连线奖励
  221. */
  222. onCheckWin(result: NSlots.ICommonResult) {
  223. cc.warn("==================> onCheckWin");
  224. let winScore = result?.awardTotalTimes || 0; // 连线赢得
  225. if (winScore > 0) {
  226. this.mouseSpin.spinPause();
  227. }
  228. this.winView.showWinView(this.bottomView.curBetScore, winScore,
  229. (multiple) => {
  230. if (winScore > 0) {
  231. this.iconView.mouseAvatar.playWinAnim();
  232. }
  233. this.noticeView.showWin(winScore, multiple, () => {
  234. this.bottomView.addWinScore(winScore);
  235. this.scheduleOnce(() => this.onSpinOver(), winScore > 0 ? 1 : 0);
  236. });
  237. }
  238. );
  239. }
  240. /**
  241. * 一次转动流程结束
  242. */
  243. onSpinOver() {
  244. cc.warn("==================> onSpinOver");
  245. // 判断顺序 Super -> Normal
  246. if (this.frame.leftSuperTimes > 0) {
  247. this.onSuperSpinNext();
  248. } else if (this.isSuperSpin) {
  249. this.onSuperSpinEnd();
  250. } else {
  251. this.onNormalSpinNext();
  252. }
  253. }
  254. // ========================= 普通转 ======================
  255. onNormalSpinNext() {
  256. cc.warn('========== 游戏结束,准备下一局 =========');
  257. this.frame.resetGameData();
  258. // Global.getInstance().isWeb &&
  259. // my.MainBackground.getInstance().notifyWeb(1, { balances: this.bottomView.realBalance });
  260. this.mouseSpin.spinOver();
  261. this.bottomView.gameBalance = this.bottomView.realBalance;
  262. //处在自动模式下
  263. if (this.isAuto()) {
  264. cc.error("==========> winscore:" + this.bottomView.winScore);
  265. this.autoModel.addWinScore(this.bottomView.winScore); //添加本局的金钱
  266. //检测是否继续auto
  267. if (this.autoModel.checkAuto(this.bottomView.gameBalance)) {
  268. this.onSpinAuto();
  269. return; //这里返回,不往下走
  270. }
  271. let score = Global.getInstance().balanceTotal - this.bottomView.curBetScore;
  272. if (score < 0) {
  273. this.showInsufficientBalance();
  274. };
  275. this.onExitAuto();
  276. }
  277. // 非自动下的内容
  278. this.isGaming = false;
  279. this.setBtnEnabled(true);
  280. }
  281. // 普通转
  282. spinNormal() {
  283. let score = Global.getInstance().balanceTotal - this.bottomView.curBetScore;
  284. if (score < 0) {
  285. this.showInsufficientBalance();
  286. this.onExitAuto();
  287. return;
  288. }
  289. this.bottomView.gameBalance = score;
  290. this.frame.resetGameData();
  291. this.resetGameView();
  292. this.setBtnEnabled(false);
  293. this.onSpinPre();
  294. // this.frame.sendGameStartReq(this.bottomView.betScoreIndex);
  295. this.frame.sendGameStartReq(this.bottomView.curDiZhuIdx, this.bottomView.curMultipleIdx);
  296. Global.getInstance().setStoreageData(MouseConst.BetScoreTemp, this.bottomView.tempChooseBet);
  297. Global.getInstance().setStoreageData(MouseConst.BetScoreIdx, this.bottomView.betScoreIndex);
  298. // this.frame.testLocal();
  299. }
  300. showInsufficientBalance() {
  301. AudioPlayer.playEffect(MouseConst.Sound.coinNotEnough, false);//下注时金钱不足
  302. // ui.Toast.show("Fichas insuficientes para continuar o jogo", false);
  303. cc.director.emit("showNoMoneyTip");
  304. // this.setBtnEnabled(true);
  305. }
  306. // ========================= 超级转 ======================
  307. superEffectAuidioId: number;
  308. /**
  309. * 触发超级转
  310. */
  311. onSuperSpinStart() {
  312. this.isSuperSpin = true;
  313. this.mouseSpin.spinPause();
  314. // 超级转背景音乐
  315. AudioPlayer.playMusic(MouseConst.Sound.superBgm, true, 0.5);
  316. AudioPlayer.playEffect(MouseConst.Sound.superEffect, true, 0.5, false, (audioID: number) => {
  317. this.superEffectAuidioId = audioID;
  318. });
  319. this.iconView.onEnterSuper();
  320. }
  321. /**
  322. * 进行下一步超级转
  323. */
  324. onSuperSpinNext() {
  325. this.scheduleOnce(() => this.spinSuper(), 0.5);
  326. }
  327. /**
  328. * 超级转结束
  329. */
  330. onSuperSpinEnd() {
  331. this.isSuperSpin = false;
  332. // 切换背景音乐
  333. AudioPlayer.playMusic(MouseConst.Sound.normalBgm, true, 0.5);
  334. AudioPlayer.stopEffect(this.superEffectAuidioId);
  335. this.iconView.onExitSuper(() => {
  336. this.onNormalSpinNext();
  337. });
  338. }
  339. spinSuper() {
  340. this.setBtnEnabled(false);
  341. this.frame.onSuperSpin();
  342. }
  343. // =========================================
  344. //更新按钮状态
  345. setBtnEnabled(btnState: boolean) {
  346. this.bottomView.setBtnEnabled(btnState);
  347. }
  348. // ===================== Useless ===================
  349. //设置用户
  350. setUserItem(viewChairID: number, userItem: qp.IUserItem) {
  351. // super.setUserItem(viewChairID, userItem);
  352. cc.log("setUserItem");
  353. // ui.Loading.hide();
  354. if (userItem) {
  355. //自己的信息
  356. if (userItem.uid == theGlobalUserInfo.uid) {
  357. this.updateMyScore(userItem.coin);
  358. }
  359. } else {
  360. //...用户离开
  361. }
  362. }
  363. //分数变化
  364. onEventUserScore(viewChairID: number, userItem: qp.IUserItem) {
  365. // cc.log("onEventUserScore=====>", userItem.coin);
  366. if (userItem.uid == theGlobalUserInfo.uid) {
  367. this.updateMyScore(userItem.coin);
  368. }
  369. }
  370. //状态变化
  371. onEventUserStatus(viewChairID: number, userItem: qp.IUserItem) {
  372. cc.log("onEventUserStatus");
  373. }
  374. }