MouseGameFrame.ts 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. import { qp } from "../../../SubGamePublic/PG_Public/Script/lib/define2";
  2. import AudioPlayer from "../../../SubGamePublic/PG_Public/Script/lib/manager/AudioPlayer";
  3. import { TimeUtils } from "../../../SubGamePublic/PG_Public/Script/lib/utils/TimeUtils";
  4. import Global from "../../../SubGamePublic/PG_Public/src/GlobalScript";
  5. import HttpUtils from "../../../SubGamePublic/PG_Public/src/net/HttpUtils";
  6. import { MouseConst } from "./MouseConst";
  7. import MouseGameFrameView from "./MouseGameFrameView";
  8. import getTestData from "./MouseTestData";
  9. var ProtocolLoginServer = require("ProtocolLoginServer");
  10. var GameBase = require("GameBase");
  11. var ScenceManager = require("HNScenceManager");
  12. const { ccclass, menu } = cc._decorator;
  13. enum MSG_C2S {
  14. USER_BALANCE_REQ = 109,
  15. Mouse_STATE_REQ = 12101,
  16. Mouse_GAMESTART_REQ = 12103,
  17. Mouse_BLOCK_REQ = 12105
  18. };
  19. enum MSG_S2C {
  20. SLOTS2_STATE_REPLY = 10202,
  21. GAME_BALANCE_EVENT = 302,
  22. USER_BALANCE_EVENT = 104,
  23. Mouse_STATE_RESP = 12102,
  24. Mouse_GAMESTART_RESP = 12104,
  25. Mouse_BLOCK_RESP = 12106
  26. };
  27. const HttpAddress = {
  28. // apiPathBlock: "/sapi/game/commongame/NMouse/bottom",
  29. // apiPathGameStart: "/sapi/game/commongame/NMouse/start",
  30. apiPathBlock: "/commongame/NMouse/bottom",
  31. apiPathGameStart: "/commongame/NMouse/start?username=mouse",
  32. apiPathSync: "/commongame/NMouse/balance?username=mouse",
  33. // apiPathSync: "/japi/user/balance/querySimpleBalance",
  34. apiHistorySync: "/prod-api/playGame/queryUserGameRecord",
  35. apiHistoryRecordSumSync: "/prod-api/playGame/queryUserGameRecordSum"
  36. };
  37. @ccclass
  38. @menu("Game/Mouse/MouseGameFrame")
  39. export default class MouseGameFrame extends GameBase {//AbstractGameFrame<MouseGameFrameView> implements MessageImpl
  40. static testDanji:boolean = false
  41. /**获取类名 */
  42. static get CLSName(): string { return "MouseGameFrame"; }
  43. get CLSName(): string { return MouseGameFrame.CLSName; }
  44. _view: MouseGameFrameView = null; //游戏视图
  45. _gameStatus: number = qp.GAME_STATUS_FREE; //游戏状态
  46. private _loginCb: Function = null;
  47. // 超级转
  48. superResult: NSlots.ICommonResult[] = [];
  49. leftSuperTimes: number = 0; // 超级转剩余免费次数
  50. _kind: number = 0;
  51. _qujian: number = 0;
  52. _buff: number = 0;
  53. _gameStartData = null;
  54. _gameMoneyData = null;
  55. _receiveCnt: number = 0;
  56. _hasReceiveResult: boolean = false;
  57. _needRefreshGold: boolean = false;
  58. get view(): MouseGameFrameView {
  59. return this._view;
  60. }
  61. roomData = null;
  62. _gameScene
  63. onLoad() {
  64. this._gameScene = ScenceManager.Instance().getGameComponent();
  65. this.roomData = cc.vv.serverListData.getCurRoomData();
  66. if(MouseGameFrame.testDanji)
  67. {this.testConfig()}
  68. else{
  69. let player = this.getSelfPlayer();
  70. if(player)
  71. this._lastScore = player.getUserScore();
  72. cc.log("初始化用户金币",this._lastScore,cc.vv.globalUserInfo.getUserScore())
  73. Global.getInstance().balanceTotal = cc.vv.globalUserInfo.getUserScore()
  74. }
  75. my.ICON_MUTIPLE = 0.01;
  76. Global.getInstance().setSceneId(3);
  77. this._view = this.node.getComponent(MouseGameFrameView);
  78. if (!this._view) {
  79. cc.error("获取游戏视图组件失败,请检查!");
  80. return;
  81. }
  82. this._view._frame = this;
  83. this.initServerEvent(true);
  84. this.addMsgListener();
  85. }
  86. testConfig(){
  87. Global.getInstance().balanceTotal = 10000
  88. }
  89. start() {
  90. cc.warn("============ MouseGameFrame Start ============");
  91. this.preload();
  92. AudioPlayer.setBundle(window.nowBundle);
  93. // 背景音乐
  94. // Global.getInstance().playBgAudio(this.view.normalBgm);
  95. AudioPlayer.playMusic(MouseConst.Sound.normalBgm, true, 0.5);
  96. // 开始的状态消息&档位信息
  97. this.sendBlockReq();
  98. }
  99. addMsgListener(){
  100. cc.vv.netSocket.registerEvent(ProtocolLoginServer.CMD_C2S_Game_RollMouse,this.onRollEndInfo,this);
  101. cc.vv.netSocket.registerEvent(ProtocolLoginServer.CMD_S2C_DEBUG_INFO, this.onDebugInfo, this);
  102. }
  103. removeMsgListener(){
  104. cc.vv.netSocket.removeEvent(ProtocolLoginServer.CMD_C2S_Game_RollMouse,this.onRollEndInfo,this);
  105. cc.vv.netSocket.removeEvent(ProtocolLoginServer.CMD_S2C_DEBUG_INFO, this.onDebugInfo, this);
  106. }
  107. preload() {
  108. window.nowBundle.loadDir("texture/", cc.Asset, (err, assets) => {
  109. window.nowBundle.preloadDir("sound/", cc.Asset, (err, assets) => {
  110. try {
  111. if (this._loginCb) {
  112. this._loginCb();
  113. this._loginCb = null;
  114. }
  115. // ui.Loading.hide();
  116. } catch (error) {
  117. cc.error("preload", JSON.stringify(error));
  118. }
  119. });
  120. });
  121. }
  122. loadResource(onFinishCb: Function) {
  123. // cc.log("加载场景后进入场景后加载资源", onFinishCb);
  124. this._loginCb = onFinishCb;
  125. }
  126. // 初始函数
  127. initGameFrame(serverAttrib: IServerAttribute): boolean {
  128. // super.initGameFrame(serverAttrib);
  129. return true;
  130. }
  131. // 重置框架
  132. // resetGameFrame(): void { super.resetGameFrame(); }
  133. // ============================ ServerEvent Start =============================
  134. protected initServerEvent(bAdd: boolean): void {
  135. // let func: Function = EventManager.addEventListener;
  136. // if (!bAdd) {
  137. // func = EventManager.removeEventListener;
  138. // }
  139. // func(EventNames.UPDATE_STARTGAMEID, this.updateStartGameID.bind(this), this);
  140. }
  141. updateStartGameID(gameOverRes: any) {
  142. cc.warn(gameOverRes.amount, "同步钱updateStartGameID==========>", gameOverRes);
  143. this._gameMoneyData = gameOverRes;
  144. // this.meUserItem.coin = Number(gameOverRes.amount);
  145. this.checkStartGame();
  146. }
  147. //检测是否开始转动游戏
  148. checkStartGame() {
  149. this._receiveCnt++;
  150. cc.warn(`"收到checkStartGame this._receiveCnt=${this._receiveCnt}"`);
  151. if (this._receiveCnt > 2) {
  152. cc.error("大厅金币和游戏金币不同步====>");
  153. }
  154. if (this._gameStartData && this._gameMoneyData && this._gameStartData.gameID && this._gameMoneyData.playGameId) {
  155. if (this._gameStartData.gameID == this._gameMoneyData.playGameId) {
  156. this.doRealGameStart();
  157. }
  158. }
  159. }
  160. // ============================ ServerEvent End =============================
  161. // ============================ Protocol Start =============================
  162. // 协议簇
  163. protoIds(): number[] {
  164. return [
  165. MSG_C2S.USER_BALANCE_REQ,
  166. MSG_S2C.SLOTS2_STATE_REPLY,
  167. MSG_S2C.GAME_BALANCE_EVENT,
  168. MSG_C2S.Mouse_STATE_REQ,
  169. MSG_C2S.Mouse_GAMESTART_REQ,
  170. MSG_C2S.Mouse_BLOCK_REQ,
  171. MSG_S2C.Mouse_STATE_RESP,
  172. MSG_S2C.Mouse_GAMESTART_RESP,
  173. MSG_S2C.Mouse_BLOCK_RESP,
  174. MSG_S2C.USER_BALANCE_EVENT
  175. ];
  176. }
  177. // 编码
  178. protoEncode(protoid: number, data: Object): Uint8Array {
  179. switch (protoid) {
  180. case MSG_C2S.Mouse_BLOCK_REQ:
  181. return (<any>window).protobuf.mini.ProtoNMouseBlockReq.encode((<any>window).protobuf.mini.ProtoNMouseBlockReq.create(data)).finish();
  182. case MSG_C2S.Mouse_GAMESTART_REQ:
  183. return (<any>window).protobuf.mini.ProtoNMouseGameStartReq.encode((<any>window).protobuf.mini.ProtoNMouseGameStartReq.create(data)).finish();
  184. case MSG_C2S.Mouse_STATE_REQ:
  185. return new Uint8Array(0);
  186. default:
  187. break;
  188. }
  189. return new Uint8Array(0);
  190. }
  191. // 解码
  192. protoDecode(protoid: number, buffer: Uint8Array): Object {
  193. switch (protoid) {
  194. case MSG_S2C.USER_BALANCE_EVENT:
  195. return (<any>window).protobuf.base.PlayerBalanceEvent.decode(buffer);
  196. case MSG_S2C.SLOTS2_STATE_REPLY:
  197. return (<any>window).protobuf.mini.Slots2StateReply.decode(buffer);
  198. case MSG_S2C.Mouse_STATE_RESP:
  199. return (<any>window).protobuf.mini.ProtoSlotStateResp.decode(buffer);
  200. case MSG_S2C.GAME_BALANCE_EVENT:
  201. return (<any>window).protobuf.base.GameBalanceEvent.decode(buffer);
  202. case MSG_S2C.Mouse_GAMESTART_RESP:
  203. return (<any>window).protobuf.mini.ProtoNMouseGameStartResp.decode(buffer);
  204. case MSG_S2C.Mouse_BLOCK_RESP:
  205. return (<any>window).protobuf.mini.ProtoNMouseBlockResp.decode(buffer);
  206. default:
  207. break;
  208. }
  209. return null;
  210. }
  211. onProtoMessage(message: Object): void {
  212. let data = message["data"];
  213. switch (message["protoid"]) {
  214. case MSG_S2C.GAME_BALANCE_EVENT:
  215. cc.error("余额同步====>", data?.balance);
  216. //同步真实余额
  217. this.view.bottomView.realBalance = data?.balance || 0;
  218. return;
  219. case MSG_S2C.Mouse_STATE_RESP:
  220. cc.error("状态消息====>", data);
  221. return;
  222. case MSG_S2C.Mouse_GAMESTART_RESP: //游戏开始结果
  223. this.onReceiveGameStart(data);
  224. return;
  225. case MSG_S2C.Mouse_BLOCK_RESP: // 档位信息
  226. // this.onReceiveBlock(data);
  227. // this.onMouseBlock(data);
  228. return;
  229. case MSG_S2C.USER_BALANCE_EVENT://104
  230. cc.log("Balance Event====>", data);
  231. if (this._needRefreshGold) {
  232. Global.getInstance().hideShowLoading("waitMapData");
  233. this.view.updateMyScore(data["availableBalance"]);
  234. this._needRefreshGold = false;
  235. }
  236. Global.getInstance().setBalance(data);
  237. return;
  238. case MSG_S2C.SLOTS2_STATE_REPLY:
  239. (<any>window).Global.getInstance().hideShowLoading("waitMapData");
  240. let gameBalance = data["availableBalance"];
  241. this.view.updateMyScore(gameBalance);
  242. return;
  243. default:
  244. break;
  245. }
  246. }
  247. onRollEndInfo(data){
  248. console.log("老鼠抽奖结果",data);
  249. let message = null;
  250. let currentBalance = data.currentBalance;
  251. if (data.currentBalance == null || data.currentBalance == "null") {
  252. currentBalance = Global.getInstance().balanceTotal;
  253. }
  254. message = { data: { balance: currentBalance }, protoid: MSG_S2C.GAME_BALANCE_EVENT };
  255. this.onProtoMessage(message);
  256. message = { data: { balances: [{ type: 2, amount: currentBalance }], availableBalance: currentBalance }, protoid: MSG_S2C.USER_BALANCE_EVENT };
  257. this.onProtoMessage(message);
  258. // let tempData = JSON.parse(JSON.stringify(response.data.data));
  259. // this.recur_awardTotalTimes(tempData, response.data.bottomScore, response.data.percent, response.data.goldPercent);
  260. message = { data: data, protoid: MSG_S2C.Mouse_GAMESTART_RESP };
  261. this.onProtoMessage(message);
  262. //更新玩家金币
  263. cc.vv.globalUserInfo.setUserScore(currentBalance);
  264. }
  265. /**
  266. * 游戏档位
  267. */
  268. // onReceiveBlock(data: any): boolean {
  269. // cc.error("============ onReceiveBlock ============>", JSON.stringify(data));
  270. // this.view.updateBetScore(data?.block);
  271. // return true;
  272. // }
  273. /**
  274. * 游戏档位
  275. * New
  276. */
  277. onMouseBlock(blockArr: number[], data: NSlots.I_BetResp) {
  278. this.view.updateBetScore(blockArr, data);
  279. }
  280. // 收到游戏结果
  281. onReceiveGameStart(gameStartResp: NSlots.ICommonResult) {
  282. cc.error("============ onReceiveGameStart ============");
  283. cc.error("gameStartResp==>", JSON.stringify(gameStartResp));
  284. cc.error("BUFF==>", this.tipBuff[gameStartResp.buff]);
  285. cc.error("AREA==>", JSON.stringify(gameStartResp.area));
  286. this._hasReceiveResult = true;
  287. Global.getInstance().hideShowLoading("waitResult");
  288. this.unschedule(this.gameStartDelay);
  289. this.unschedule(this.gameStartOutTime);
  290. if (gameStartResp.errorCode) {
  291. cc.error("数据错误======>", gameStartResp.errorCode);
  292. // ui.Toast.show("Atraso na rede, tente novamente", false);
  293. this.sendBalanceReq();
  294. return;
  295. }
  296. // 有超级转
  297. if (gameStartResp.superResult?.length) {
  298. this.superResult = gameStartResp.superResult;
  299. this.leftSuperTimes = this.superResult.length;
  300. } else {
  301. this.leftSuperTimes = 0;
  302. }
  303. this._gameStartData = gameStartResp;
  304. this.doRealGameStart();
  305. }
  306. // 收到两个协议后开始游戏
  307. doRealGameStart() {
  308. let temp = JSON.parse(JSON.stringify(this._gameStartData));
  309. // ui.Loading.hide();
  310. if (this.leftSuperTimes > 0) {
  311. this.onSuperSpin(true);
  312. } else {
  313. this.onCommonResult(temp);
  314. }
  315. }
  316. onCommonResult(gameStartResp: NSlots.ICommonResult, hasSuperSpin?: boolean) {
  317. this.view.onSpinStart(gameStartResp, hasSuperSpin);
  318. }
  319. // ============================ Protocol End =============================
  320. // ============================ Request Start =============================
  321. /**
  322. *
  323. * @param dayMax 结束时间
  324. * @param dayMin 开始时间
  325. * @param pageNum 页数
  326. * @param callback
  327. */
  328. sendHistoryRequest(dayMin: string, dayMax: string, pageNum: number, successCallback: Function, errorCallback: Function) {
  329. if (Global.getInstance().httpAdress) {
  330. let finalDayMin = this.formatBxDate(dayMin);
  331. let finalDayMax = this.formatBxDate(dayMax);
  332. HttpUtils.getInstance().post(1, 0, this, HttpAddress.apiHistorySync, {//"/p"+G51_SUB_C.NCOW_GAMESTART_REQ
  333. dayMax: finalDayMax,
  334. dayMin: finalDayMin,
  335. game_id: 66,
  336. pageNum: pageNum,
  337. pageSize: 20,
  338. token: Global.getInstance().token
  339. }, (response) => {
  340. successCallback.call(this, response.total, response.rows);
  341. }, (err) => {
  342. errorCallback.call(this);
  343. cc.error(HttpAddress.apiHistorySync, err);
  344. });
  345. }
  346. }
  347. /**
  348. *
  349. * @param dayMax 结束时间
  350. * @param dayMin 开始时间
  351. * @param pageNum 页数
  352. * @param callback
  353. */
  354. sendHistoryRecordSumRequest(dayMin: string, dayMax: string, pageNum: number, successCallback: Function, errorCallback: Function) {
  355. if (Global.getInstance().httpAdress) {
  356. let finalDayMin = this.formatBxDate(dayMin);
  357. let finalDayMax = this.formatBxDate(dayMax);
  358. HttpUtils.getInstance().post(1, 0, this, HttpAddress.apiHistoryRecordSumSync, {//"/p"+G51_SUB_C.NCOW_GAMESTART_REQ
  359. dayMax: finalDayMax,
  360. dayMin: finalDayMin,
  361. game_id: 66,
  362. pageNum: pageNum,
  363. pageSize: 20,
  364. token: Global.getInstance().token
  365. }, (response) => {
  366. if (response.data) {
  367. successCallback.call(this, response.data.bet, response.data.win);
  368. } else {
  369. errorCallback.call(this);
  370. }
  371. }, (err) => {
  372. errorCallback.call(this);
  373. cc.error(HttpAddress.apiHistoryRecordSumSync, err);
  374. });
  375. }
  376. }
  377. /**
  378. * 根据当前时区 格式化为巴西时区
  379. * @param dateStr
  380. * @returns
  381. */
  382. formatBxDate(dateStr: string): string {
  383. let currentTimeZone = (0 - new Date().getTimezoneOffset() / 60);
  384. let serverTimeZone = currentTimeZone - (Global.getInstance().serverTimeZone); // serverTimeZone
  385. let diffTimeZoneMills = serverTimeZone * 60 * 60 * 1000;
  386. let dateTimeMills = Number(new Date(dateStr));
  387. let todayDateStr = TimeUtils.format(TimeUtils.getCurrentTime(), 'yyyy/MM/dd');
  388. if (todayDateStr == dateStr) { // 选择的是今天的话 需要根据当前时间来转换
  389. dateTimeMills = TimeUtils.getCurrentTime();
  390. }
  391. let currentServerTime = dateTimeMills - diffTimeZoneMills;
  392. let timeStr = TimeUtils.format(currentServerTime, 'yyyy/MM/dd').replace(new RegExp("/", "gm"), "");
  393. return timeStr;
  394. }
  395. // 发送状态请求
  396. // 发送档位请求
  397. sendBlockReq() {
  398. if (MouseGameFrame.testDanji) {
  399. let response:any = {"code":200,"msg":"","data":{percent:5,"bottomScore":[8,80,300,1000],"bottomTimes":[1,2,3,4,5,6,7,8,9,10],"simplyBottom":[0,0,0,1,0,2,0,4,1,0,1,2,2,0,1,4,1,9,3,0,2,4,2,9,3,4,3,9]}}
  400. let blockArr = [];
  401. for (let i = 0; i < response.data.simplyBottom.length; i++) {
  402. if (i % 2 == 0) {
  403. let botScoreIdx = response.data.simplyBottom[i];
  404. let botTimesIdx = response.data.simplyBottom[i + 1];
  405. let v = response.data.bottomScore[botScoreIdx] * response.data.bottomTimes[botTimesIdx];
  406. blockArr.push(v);
  407. }
  408. }
  409. console.error('底注------', response.data.bottomScore);
  410. console.error('翻倍等级', response.data.bottomTimes);
  411. console.error('底注和翻倍相乘的所有分数', blockArr);
  412. this.onMouseBlock(blockArr, response);
  413. // this.view.isRespBlockData = true;
  414. return
  415. }else{
  416. let response:any = {"code":200,"msg":"","data":{percent:5,"bottomScore":this.roomData.Bet2[0],"bottomTimes":this.roomData.Bet2[1],"simplyBottom":this.roomData.Bet2[2]}}
  417. let blockArr = [];
  418. for (let i = 0; i < response.data.simplyBottom.length; i++) {
  419. if (i % 2 == 0) {
  420. let botScoreIdx = response.data.simplyBottom[i];
  421. let botTimesIdx = response.data.simplyBottom[i + 1];
  422. let v = response.data.bottomScore[botScoreIdx] * response.data.bottomTimes[botTimesIdx];
  423. blockArr.push(v);
  424. }
  425. }
  426. console.error('底注------', response.data.bottomScore);
  427. console.error('翻倍等级', response.data.bottomTimes);
  428. console.error('底注和翻倍相乘的所有分数', blockArr);
  429. this.onMouseBlock(blockArr, response);
  430. return
  431. }
  432. if (Global.getInstance().httpAdress) {
  433. // HttpUtils.getInstance().post(1, 0, this, HttpAddress.apiPathBlock, {
  434. // gameType: 0
  435. // }, (response: NSlots.I_BetResp) => {
  436. // console.error('response', response);
  437. // if (response.code == 200) {
  438. // let blockArr = [];
  439. // for (let i = 0; i < response.data.simplyBottom.length; i++) {
  440. // if (i % 2 == 0) {
  441. // let botScoreIdx = response.data.simplyBottom[i];
  442. // let botTimesIdx = response.data.simplyBottom[i + 1];
  443. // let v = response.data.bottomScore[botScoreIdx] * response.data.bottomTimes[botTimesIdx];
  444. // blockArr.push(v);
  445. // }
  446. // }
  447. // console.error('底注------', response.data.bottomScore);
  448. // console.error('翻倍等级', response.data.bottomTimes);
  449. // console.error('底注和翻倍相乘的所有分数', blockArr);
  450. // this.onMouseBlock(blockArr, response);
  451. // }
  452. // }, (err) => {
  453. // cc.error("请求bottom出错", err);
  454. // });
  455. UserApi.bottom((response) => {
  456. console.error('response', response);
  457. response.data.percent = 5
  458. if (response.code == 200) {
  459. let blockArr = [];
  460. for (let i = 0; i < response.data.simplyBottom.length; i++) {
  461. if (i % 2 == 0) {
  462. let botScoreIdx = response.data.simplyBottom[i];
  463. let botTimesIdx = response.data.simplyBottom[i + 1];
  464. let v = response.data.bottomScore[botScoreIdx] * response.data.bottomTimes[botTimesIdx];
  465. blockArr.push(v);
  466. }
  467. }
  468. console.error('底注------', response.data.bottomScore);
  469. console.error('翻倍等级', response.data.bottomTimes);
  470. console.error('底注和翻倍相乘的所有分数', blockArr);
  471. this.onMouseBlock(blockArr, response);
  472. }
  473. }, (err) => {
  474. cc.error("请求bottom出错", err);
  475. })
  476. } else {
  477. SocketUtils.getInstance().send(MSG_C2S.Mouse_BLOCK_REQ, {});
  478. }
  479. }
  480. // 发送余额同步请求
  481. sendBalanceReq() {
  482. this._needRefreshGold = true;
  483. Global.getInstance().showLoading("waitMapData");
  484. if (Global.getInstance().httpAdress) {
  485. UserApi.syncBalance((response) => {
  486. if (response.code == 200) {
  487. let balanceInfo = { balances: [{ type: 2, amount: response.data.amount }], availableBalance: response.data.amount };
  488. let message = { data: balanceInfo, protoid: MSG_S2C.USER_BALANCE_EVENT };
  489. this.onProtoMessage(message);
  490. } else {
  491. cc.error("Mouse/querySimpleBalance", response.msg);
  492. }
  493. Global.getInstance().hideShowLoading("waitMapData");
  494. }, (err) => {
  495. cc.error("Mouse/querySimpleBalance", err);
  496. Global.getInstance().hideShowLoading("waitMapData");
  497. });
  498. } else {
  499. // SocketUtils.getInstance().send(109, {});
  500. }
  501. }
  502. // 发送游戏开始请求
  503. sendGameStartReq(curDiZhuIdx: number, curMultipleIdx: number) {
  504. console.error('sendGameStartReq:', curDiZhuIdx, curMultipleIdx);
  505. this._hasReceiveResult = false;
  506. this._needRefreshGold = false;
  507. //单机测试用的
  508. if (MouseGameFrame.testDanji) {
  509. this.scheduleOnce(this.testLocal,0.5)
  510. }else{
  511. let _data = {"CMD":ProtocolLoginServer.CMD_C2S_Game_RollMouse, "RoomID":this.roomData.ServerID, BottomScore:curDiZhuIdx, BottomTimes:curMultipleIdx}
  512. // {'CMD':ProtocolLoginServer.CMD_C2S_Game_Roll9X,
  513. // 'Value':this.gameConfig.nJetton[this.curBetIndex],
  514. // 'RoomID':this.roomData.ServerID
  515. // }
  516. cc.vv.netSocket.send(JSON.stringify(_data));
  517. }
  518. if (Global.getInstance().httpAdress) {
  519. HttpUtils.getInstance().post(1, 0, this, HttpAddress.apiPathGameStart, {//"/p"+G51_SUB_C.Mouse_GAMESTART_REQ
  520. // score: scoreLevel,
  521. bottomScore: curDiZhuIdx,
  522. bottomTimes: curMultipleIdx,
  523. area: this._qujian,
  524. type: this._kind,
  525. buff: this._buff
  526. }, (response) => {
  527. let message = null;
  528. let currentBalance = response.data.data.currentBalance;
  529. if (response.data.data.currentBalance == null || response.data.data.currentBalance == "null") {
  530. currentBalance = Global.getInstance().balanceTotal;
  531. }
  532. message = { data: { balance: currentBalance }, protoid: MSG_S2C.GAME_BALANCE_EVENT };
  533. this.onProtoMessage(message);
  534. message = { data: { balances: [{ type: 2, amount: currentBalance }], availableBalance: currentBalance }, protoid: MSG_S2C.USER_BALANCE_EVENT };
  535. this.onProtoMessage(message);
  536. let tempData = JSON.parse(JSON.stringify(response.data.data));
  537. this.recur_awardTotalTimes(tempData, response.data.bottomScore, response.data.percent, response.data.goldPercent);
  538. message = { data: tempData, protoid: MSG_S2C.Mouse_GAMESTART_RESP };
  539. this.onProtoMessage(message);
  540. }, (err) => {
  541. cc.error("Mouse/SkullGameReq", err);
  542. });
  543. } else {
  544. // SocketUtils.getInstance().send(MSG_C2S.Mouse_GAMESTART_REQ, {
  545. // score: scoreLevel,
  546. // area: this._qujian,
  547. // type: this._kind,
  548. // buff: this._buff
  549. // });
  550. }
  551. this.scheduleOnce(this.gameStartDelay, 1);
  552. }
  553. /**
  554. * 根据 底分,线数计算得分
  555. * @param selmsg
  556. * @param bottomScore 底分
  557. * @param percent 线数
  558. */
  559. recur_awardTotalTimes(selmsg: any, bottomScore: number, percent: number, goldPercent: number) {
  560. cc.error("awTimes:" + selmsg.awTimes);
  561. selmsg.awardTotalTimes = Math.floor(bottomScore * selmsg.awardTotalTimes / percent);
  562. selmsg.goldValue = Math.floor(bottomScore * selmsg.goldValue / goldPercent);
  563. // ========= 中奖线金额 added by hmy on 2023/9/28 ========
  564. selmsg.awTimes = Math.floor(bottomScore * selmsg.awTimes / percent);
  565. if (selmsg.hasOwnProperty("lineItem")) {
  566. for (const key in selmsg.lineItem) {
  567. if (Object.prototype.hasOwnProperty.call(selmsg.lineItem, key)) {
  568. this.recur_awardTotalTimes(selmsg.lineItem[key], bottomScore, percent, goldPercent);
  569. }
  570. }
  571. }
  572. // =================
  573. if (selmsg.hasOwnProperty('normalResult')) {
  574. for (const key in selmsg.normalResult) {
  575. if (Object.prototype.hasOwnProperty.call(selmsg.normalResult, key)) {
  576. const element = selmsg.normalResult[key];
  577. this.recur_awardTotalTimes(element, bottomScore, percent, goldPercent);
  578. }
  579. }
  580. }
  581. if (selmsg.hasOwnProperty('superResult')) {
  582. for (const key in selmsg.superResult) {
  583. if (Object.prototype.hasOwnProperty.call(selmsg.superResult, key)) {
  584. const element = selmsg.superResult[key];
  585. this.recur_awardTotalTimes(element, bottomScore, percent, goldPercent);
  586. }
  587. }
  588. }
  589. if (selmsg.hasOwnProperty('freeResult')) {
  590. for (const key in selmsg.freeResult) {
  591. if (Object.prototype.hasOwnProperty.call(selmsg.freeResult, key)) {
  592. const element = selmsg.freeResult[key];
  593. this.recur_awardTotalTimes(element, bottomScore, percent, goldPercent);
  594. }
  595. }
  596. }
  597. }
  598. gameStartDelay() {
  599. cc.warn("发送开始延迟=========");
  600. if (!this._hasReceiveResult) {
  601. cc.error("加载中...");
  602. // Global.getInstance().showLoading("waitResult");
  603. this.scheduleOnce(this.gameStartOutTime, 5);
  604. }
  605. }
  606. gameStartOutTime() {
  607. // Global.getInstance().hideShowLoading("waitResult");
  608. cc.error("没有结算消息返回==");
  609. // ui.Toast.show("A ligação à rede expirou o tempo!", false);
  610. // ui.Toast.show(i18nMgr._getLabel("time_out_tip", []), false);
  611. this.sendBalanceReq();
  612. }
  613. // ============================ Request End =============================
  614. /**
  615. * 超级转
  616. */
  617. onSuperSpin(first?: boolean) {
  618. let data = this.superResult[this.superResult.length - this.leftSuperTimes];
  619. this.leftSuperTimes--;
  620. this.onCommonResult(data, first);
  621. }
  622. resetGameData() {
  623. this._gameStartData = null;
  624. this._gameMoneyData = null;
  625. this._receiveCnt = 0;
  626. }
  627. // ============================ Test Start =============================
  628. tipBuff = {
  629. NEW_USER_BUFFER: "新手概率", RECHARGE_STIMULATE_BUFFER: "充值刺激", RECHARGE_PROTECT_BUFFER: "充值保障", SLOT_PUMPING: "库存抽水", HAND_CTRL_WIN: "手动控放",
  630. HAND_CTRL_LOST: "手动控杀", SLOT_COMMON: "库存常规", PERSON_LOW: "个人低返奖", SLOT_RELEASE: "库存放水", MUST_LOST: "个人必输", BACK_BUFFER: "回本"
  631. };
  632. testLocal() {
  633. this.onReceiveGameStart(getTestData());
  634. }
  635. // ============================ Test End =============================
  636. onDestroy() {
  637. this.initServerEvent(false); // 解绑事件
  638. this.removeMsgListener();
  639. cc.Tween.stopAll(); // 结束动画
  640. cc.audioEngine.stopMusic(); // 关闭声音
  641. AudioPlayer.setBundle(cc.resources);
  642. }
  643. // 退出游戏
  644. exitRoomClick() {
  645. // if (Global.getInstance().isWeb) {
  646. // my.MainBackground.getInstance().notifyWeb(4);
  647. // return;
  648. // }
  649. if (Global.getInstance().isSingle) {
  650. Global.getInstance().showCommonTip("Confirm to Log Out?", this, false, function () {//cancel
  651. (<any>window).SocketUtils.getInstance().unregisterMessages(this);
  652. SocketUtils.getInstance().close();//关闭socket
  653. Global.getInstance().clearToken();
  654. if (Global.getInstance().getStoreageData(Global.GLOBAL_STORAGE_KEY.LOGIN_TYPE + Global.getInstance().userdata.user_id, 0) == 0) {
  655. if (cc.sys.OS_ANDROID === cc.sys.os) {
  656. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "WXLogoutReq", "()V");
  657. } else if (cc.sys.os == cc.sys.OS_IOS) {
  658. jsb.reflection.callStaticMethod("FacebookUtils", "logout");
  659. }
  660. }
  661. Global.getInstance().mgm = null;
  662. Global.getInstance().userdata = null;
  663. Global.getInstance().activityData = null;
  664. Global.getInstance().rechargeConfig = null;
  665. Global.getInstance().giftConfig = null;
  666. Global.getInstance().withdrawBalance = 0;
  667. Global.getInstance().balanceTotal = 0;
  668. Global.getInstance().bonusTotal = 0;
  669. Global.getInstance().nextluckyShotTime = 0;
  670. Global.getInstance().luckyshotRemainTimes = 0;
  671. Global.getInstance().redAndBlackRemainTimes = 0;
  672. Global.getInstance().redAndBlackRltData = null;
  673. cc.director.loadScene('loginScene');
  674. });
  675. } else {
  676. Global.getInstance().gameToHall({ exitReason: 203 }, this);
  677. }
  678. }
  679. //退出游戏
  680. onClickExit() {
  681. // this._gameScene.exitGameWhenPlaying();
  682. // if(!this._gameEnd || this._nFreeCount > 0) {
  683. // topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.not_exit_game"));
  684. // return;
  685. // }
  686. if(cc.vv.config.ReviewApk) {
  687. cc.game.end();
  688. return;
  689. }
  690. this._backHome = true;
  691. cc.sys.localStorage.setItem("InGameServerID", -1);
  692. this.removeMsgListener();
  693. ScenceManager.Instance().gameBackScence();
  694. }
  695. // =============== Useless ============
  696. // 用户离开
  697. onSocketPlayerQuitGameResp(data: any): boolean { return true; }
  698. // 用户进入
  699. onSocketPlayerJoinGameResp(data: any): boolean { return true; }
  700. // 发送逃跑
  701. sendEscape(): boolean { return true; }
  702. sendJoinGame(): boolean { return true; }
  703. // 游戏场景
  704. onEventGameScene(data: any): boolean { return true; }
  705. // 游戏消息
  706. onEventGameMessage(scmd: number, data: any): boolean { return false; }
  707. }