123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796 |
- import { qp } from "../../../SubGamePublic/PG_Public/Script/lib/define2";
- import AudioPlayer from "../../../SubGamePublic/PG_Public/Script/lib/manager/AudioPlayer";
- import { TimeUtils } from "../../../SubGamePublic/PG_Public/Script/lib/utils/TimeUtils";
- import Global from "../../../SubGamePublic/PG_Public/src/GlobalScript";
- import HttpUtils from "../../../SubGamePublic/PG_Public/src/net/HttpUtils";
- import { MouseConst } from "./MouseConst";
- import MouseGameFrameView from "./MouseGameFrameView";
- import getTestData from "./MouseTestData";
- var ProtocolLoginServer = require("ProtocolLoginServer");
- var GameBase = require("GameBase");
- var ScenceManager = require("HNScenceManager");
- const { ccclass, menu } = cc._decorator;
- enum MSG_C2S {
- USER_BALANCE_REQ = 109,
- Mouse_STATE_REQ = 12101,
- Mouse_GAMESTART_REQ = 12103,
- Mouse_BLOCK_REQ = 12105
- };
- enum MSG_S2C {
- SLOTS2_STATE_REPLY = 10202,
- GAME_BALANCE_EVENT = 302,
- USER_BALANCE_EVENT = 104,
- Mouse_STATE_RESP = 12102,
- Mouse_GAMESTART_RESP = 12104,
- Mouse_BLOCK_RESP = 12106
- };
- const HttpAddress = {
- // apiPathBlock: "/sapi/game/commongame/NMouse/bottom",
- // apiPathGameStart: "/sapi/game/commongame/NMouse/start",
- apiPathBlock: "/commongame/NMouse/bottom",
- apiPathGameStart: "/commongame/NMouse/start?username=mouse",
- apiPathSync: "/commongame/NMouse/balance?username=mouse",
- // apiPathSync: "/japi/user/balance/querySimpleBalance",
- apiHistorySync: "/prod-api/playGame/queryUserGameRecord",
- apiHistoryRecordSumSync: "/prod-api/playGame/queryUserGameRecordSum"
- };
- @ccclass
- @menu("Game/Mouse/MouseGameFrame")
- export default class MouseGameFrame extends GameBase {//AbstractGameFrame<MouseGameFrameView> implements MessageImpl
-
- static testDanji:boolean = false
- /**获取类名 */
- static get CLSName(): string { return "MouseGameFrame"; }
- get CLSName(): string { return MouseGameFrame.CLSName; }
- _view: MouseGameFrameView = null; //游戏视图
- _gameStatus: number = qp.GAME_STATUS_FREE; //游戏状态
-
- private _loginCb: Function = null;
- // 超级转
- superResult: NSlots.ICommonResult[] = [];
- leftSuperTimes: number = 0; // 超级转剩余免费次数
- _kind: number = 0;
- _qujian: number = 0;
- _buff: number = 0;
- _gameStartData = null;
- _gameMoneyData = null;
- _receiveCnt: number = 0;
- _hasReceiveResult: boolean = false;
- _needRefreshGold: boolean = false;
- get view(): MouseGameFrameView {
- return this._view;
- }
- roomData = null;
- _gameScene
- onLoad() {
- this._gameScene = ScenceManager.Instance().getGameComponent();
- this.roomData = cc.vv.serverListData.getCurRoomData();
- if(MouseGameFrame.testDanji)
- {this.testConfig()}
- else{
-
- let player = this.getSelfPlayer();
- if(player)
- this._lastScore = player.getUserScore();
- cc.log("初始化用户金币",this._lastScore,cc.vv.globalUserInfo.getUserScore())
- Global.getInstance().balanceTotal = cc.vv.globalUserInfo.getUserScore()
- }
- my.ICON_MUTIPLE = 0.01;
- Global.getInstance().setSceneId(3);
- this._view = this.node.getComponent(MouseGameFrameView);
- if (!this._view) {
- cc.error("获取游戏视图组件失败,请检查!");
- return;
- }
- this._view._frame = this;
- this.initServerEvent(true);
- this.addMsgListener();
- }
- testConfig(){
- Global.getInstance().balanceTotal = 10000
- }
- start() {
- cc.warn("============ MouseGameFrame Start ============");
- this.preload();
- AudioPlayer.setBundle(window.nowBundle);
- // 背景音乐
- // Global.getInstance().playBgAudio(this.view.normalBgm);
- AudioPlayer.playMusic(MouseConst.Sound.normalBgm, true, 0.5);
- // 开始的状态消息&档位信息
- this.sendBlockReq();
- }
- addMsgListener(){
- cc.vv.netSocket.registerEvent(ProtocolLoginServer.CMD_C2S_Game_RollMouse,this.onRollEndInfo,this);
- cc.vv.netSocket.registerEvent(ProtocolLoginServer.CMD_S2C_DEBUG_INFO, this.onDebugInfo, this);
- }
- removeMsgListener(){
- cc.vv.netSocket.removeEvent(ProtocolLoginServer.CMD_C2S_Game_RollMouse,this.onRollEndInfo,this);
- cc.vv.netSocket.removeEvent(ProtocolLoginServer.CMD_S2C_DEBUG_INFO, this.onDebugInfo, this);
- }
- preload() {
- window.nowBundle.loadDir("texture/", cc.Asset, (err, assets) => {
- window.nowBundle.preloadDir("sound/", cc.Asset, (err, assets) => {
- try {
- if (this._loginCb) {
- this._loginCb();
- this._loginCb = null;
- }
- // ui.Loading.hide();
- } catch (error) {
- cc.error("preload", JSON.stringify(error));
- }
- });
- });
- }
- loadResource(onFinishCb: Function) {
- // cc.log("加载场景后进入场景后加载资源", onFinishCb);
- this._loginCb = onFinishCb;
- }
- // 初始函数
- initGameFrame(serverAttrib: IServerAttribute): boolean {
- // super.initGameFrame(serverAttrib);
- return true;
- }
- // 重置框架
- // resetGameFrame(): void { super.resetGameFrame(); }
- // ============================ ServerEvent Start =============================
- protected initServerEvent(bAdd: boolean): void {
- // let func: Function = EventManager.addEventListener;
- // if (!bAdd) {
- // func = EventManager.removeEventListener;
- // }
- // func(EventNames.UPDATE_STARTGAMEID, this.updateStartGameID.bind(this), this);
- }
- updateStartGameID(gameOverRes: any) {
- cc.warn(gameOverRes.amount, "同步钱updateStartGameID==========>", gameOverRes);
- this._gameMoneyData = gameOverRes;
- // this.meUserItem.coin = Number(gameOverRes.amount);
- this.checkStartGame();
- }
- //检测是否开始转动游戏
- checkStartGame() {
- this._receiveCnt++;
- cc.warn(`"收到checkStartGame this._receiveCnt=${this._receiveCnt}"`);
- if (this._receiveCnt > 2) {
- cc.error("大厅金币和游戏金币不同步====>");
- }
- if (this._gameStartData && this._gameMoneyData && this._gameStartData.gameID && this._gameMoneyData.playGameId) {
- if (this._gameStartData.gameID == this._gameMoneyData.playGameId) {
- this.doRealGameStart();
- }
- }
- }
- // ============================ ServerEvent End =============================
- // ============================ Protocol Start =============================
- // 协议簇
- protoIds(): number[] {
- return [
- MSG_C2S.USER_BALANCE_REQ,
- MSG_S2C.SLOTS2_STATE_REPLY,
- MSG_S2C.GAME_BALANCE_EVENT,
- MSG_C2S.Mouse_STATE_REQ,
- MSG_C2S.Mouse_GAMESTART_REQ,
- MSG_C2S.Mouse_BLOCK_REQ,
- MSG_S2C.Mouse_STATE_RESP,
- MSG_S2C.Mouse_GAMESTART_RESP,
- MSG_S2C.Mouse_BLOCK_RESP,
- MSG_S2C.USER_BALANCE_EVENT
- ];
- }
- // 编码
- protoEncode(protoid: number, data: Object): Uint8Array {
- switch (protoid) {
- case MSG_C2S.Mouse_BLOCK_REQ:
- return (<any>window).protobuf.mini.ProtoNMouseBlockReq.encode((<any>window).protobuf.mini.ProtoNMouseBlockReq.create(data)).finish();
- case MSG_C2S.Mouse_GAMESTART_REQ:
- return (<any>window).protobuf.mini.ProtoNMouseGameStartReq.encode((<any>window).protobuf.mini.ProtoNMouseGameStartReq.create(data)).finish();
- case MSG_C2S.Mouse_STATE_REQ:
- return new Uint8Array(0);
- default:
- break;
- }
- return new Uint8Array(0);
- }
- // 解码
- protoDecode(protoid: number, buffer: Uint8Array): Object {
- switch (protoid) {
- case MSG_S2C.USER_BALANCE_EVENT:
- return (<any>window).protobuf.base.PlayerBalanceEvent.decode(buffer);
- case MSG_S2C.SLOTS2_STATE_REPLY:
- return (<any>window).protobuf.mini.Slots2StateReply.decode(buffer);
- case MSG_S2C.Mouse_STATE_RESP:
- return (<any>window).protobuf.mini.ProtoSlotStateResp.decode(buffer);
- case MSG_S2C.GAME_BALANCE_EVENT:
- return (<any>window).protobuf.base.GameBalanceEvent.decode(buffer);
- case MSG_S2C.Mouse_GAMESTART_RESP:
- return (<any>window).protobuf.mini.ProtoNMouseGameStartResp.decode(buffer);
- case MSG_S2C.Mouse_BLOCK_RESP:
- return (<any>window).protobuf.mini.ProtoNMouseBlockResp.decode(buffer);
- default:
- break;
- }
- return null;
- }
- onProtoMessage(message: Object): void {
- let data = message["data"];
- switch (message["protoid"]) {
- case MSG_S2C.GAME_BALANCE_EVENT:
- cc.error("余额同步====>", data?.balance);
- //同步真实余额
- this.view.bottomView.realBalance = data?.balance || 0;
- return;
- case MSG_S2C.Mouse_STATE_RESP:
- cc.error("状态消息====>", data);
- return;
- case MSG_S2C.Mouse_GAMESTART_RESP: //游戏开始结果
- this.onReceiveGameStart(data);
- return;
- case MSG_S2C.Mouse_BLOCK_RESP: // 档位信息
- // this.onReceiveBlock(data);
- // this.onMouseBlock(data);
- return;
- case MSG_S2C.USER_BALANCE_EVENT://104
- cc.log("Balance Event====>", data);
- if (this._needRefreshGold) {
- Global.getInstance().hideShowLoading("waitMapData");
- this.view.updateMyScore(data["availableBalance"]);
- this._needRefreshGold = false;
- }
- Global.getInstance().setBalance(data);
- return;
- case MSG_S2C.SLOTS2_STATE_REPLY:
- (<any>window).Global.getInstance().hideShowLoading("waitMapData");
- let gameBalance = data["availableBalance"];
- this.view.updateMyScore(gameBalance);
- return;
- default:
- break;
- }
- }
- onRollEndInfo(data){
- console.log("老鼠抽奖结果",data);
- let message = null;
- let currentBalance = data.currentBalance;
- if (data.currentBalance == null || data.currentBalance == "null") {
- currentBalance = Global.getInstance().balanceTotal;
- }
- message = { data: { balance: currentBalance }, protoid: MSG_S2C.GAME_BALANCE_EVENT };
- this.onProtoMessage(message);
- message = { data: { balances: [{ type: 2, amount: currentBalance }], availableBalance: currentBalance }, protoid: MSG_S2C.USER_BALANCE_EVENT };
- this.onProtoMessage(message);
- // let tempData = JSON.parse(JSON.stringify(response.data.data));
- // this.recur_awardTotalTimes(tempData, response.data.bottomScore, response.data.percent, response.data.goldPercent);
- message = { data: data, protoid: MSG_S2C.Mouse_GAMESTART_RESP };
- this.onProtoMessage(message);
- //更新玩家金币
- cc.vv.globalUserInfo.setUserScore(currentBalance);
- }
- /**
- * 游戏档位
- */
- // onReceiveBlock(data: any): boolean {
- // cc.error("============ onReceiveBlock ============>", JSON.stringify(data));
- // this.view.updateBetScore(data?.block);
- // return true;
- // }
- /**
- * 游戏档位
- * New
- */
- onMouseBlock(blockArr: number[], data: NSlots.I_BetResp) {
- this.view.updateBetScore(blockArr, data);
- }
- // 收到游戏结果
- onReceiveGameStart(gameStartResp: NSlots.ICommonResult) {
- cc.error("============ onReceiveGameStart ============");
- cc.error("gameStartResp==>", JSON.stringify(gameStartResp));
- cc.error("BUFF==>", this.tipBuff[gameStartResp.buff]);
- cc.error("AREA==>", JSON.stringify(gameStartResp.area));
- this._hasReceiveResult = true;
- Global.getInstance().hideShowLoading("waitResult");
- this.unschedule(this.gameStartDelay);
- this.unschedule(this.gameStartOutTime);
- if (gameStartResp.errorCode) {
- cc.error("数据错误======>", gameStartResp.errorCode);
- // ui.Toast.show("Atraso na rede, tente novamente", false);
- this.sendBalanceReq();
- return;
- }
- // 有超级转
- if (gameStartResp.superResult?.length) {
- this.superResult = gameStartResp.superResult;
- this.leftSuperTimes = this.superResult.length;
- } else {
- this.leftSuperTimes = 0;
- }
- this._gameStartData = gameStartResp;
- this.doRealGameStart();
- }
- // 收到两个协议后开始游戏
- doRealGameStart() {
- let temp = JSON.parse(JSON.stringify(this._gameStartData));
- // ui.Loading.hide();
- if (this.leftSuperTimes > 0) {
- this.onSuperSpin(true);
- } else {
- this.onCommonResult(temp);
- }
- }
- onCommonResult(gameStartResp: NSlots.ICommonResult, hasSuperSpin?: boolean) {
- this.view.onSpinStart(gameStartResp, hasSuperSpin);
- }
- // ============================ Protocol End =============================
- // ============================ Request Start =============================
- /**
- *
- * @param dayMax 结束时间
- * @param dayMin 开始时间
- * @param pageNum 页数
- * @param callback
- */
- sendHistoryRequest(dayMin: string, dayMax: string, pageNum: number, successCallback: Function, errorCallback: Function) {
- if (Global.getInstance().httpAdress) {
- let finalDayMin = this.formatBxDate(dayMin);
- let finalDayMax = this.formatBxDate(dayMax);
- HttpUtils.getInstance().post(1, 0, this, HttpAddress.apiHistorySync, {//"/p"+G51_SUB_C.NCOW_GAMESTART_REQ
- dayMax: finalDayMax,
- dayMin: finalDayMin,
- game_id: 66,
- pageNum: pageNum,
- pageSize: 20,
- token: Global.getInstance().token
- }, (response) => {
- successCallback.call(this, response.total, response.rows);
- }, (err) => {
- errorCallback.call(this);
- cc.error(HttpAddress.apiHistorySync, err);
- });
- }
- }
- /**
- *
- * @param dayMax 结束时间
- * @param dayMin 开始时间
- * @param pageNum 页数
- * @param callback
- */
- sendHistoryRecordSumRequest(dayMin: string, dayMax: string, pageNum: number, successCallback: Function, errorCallback: Function) {
- if (Global.getInstance().httpAdress) {
- let finalDayMin = this.formatBxDate(dayMin);
- let finalDayMax = this.formatBxDate(dayMax);
- HttpUtils.getInstance().post(1, 0, this, HttpAddress.apiHistoryRecordSumSync, {//"/p"+G51_SUB_C.NCOW_GAMESTART_REQ
- dayMax: finalDayMax,
- dayMin: finalDayMin,
- game_id: 66,
- pageNum: pageNum,
- pageSize: 20,
- token: Global.getInstance().token
- }, (response) => {
- if (response.data) {
- successCallback.call(this, response.data.bet, response.data.win);
- } else {
- errorCallback.call(this);
- }
- }, (err) => {
- errorCallback.call(this);
- cc.error(HttpAddress.apiHistoryRecordSumSync, err);
- });
- }
- }
- /**
- * 根据当前时区 格式化为巴西时区
- * @param dateStr
- * @returns
- */
- formatBxDate(dateStr: string): string {
- let currentTimeZone = (0 - new Date().getTimezoneOffset() / 60);
- let serverTimeZone = currentTimeZone - (Global.getInstance().serverTimeZone); // serverTimeZone
- let diffTimeZoneMills = serverTimeZone * 60 * 60 * 1000;
- let dateTimeMills = Number(new Date(dateStr));
- let todayDateStr = TimeUtils.format(TimeUtils.getCurrentTime(), 'yyyy/MM/dd');
- if (todayDateStr == dateStr) { // 选择的是今天的话 需要根据当前时间来转换
- dateTimeMills = TimeUtils.getCurrentTime();
- }
- let currentServerTime = dateTimeMills - diffTimeZoneMills;
- let timeStr = TimeUtils.format(currentServerTime, 'yyyy/MM/dd').replace(new RegExp("/", "gm"), "");
- return timeStr;
- }
- // 发送状态请求
- // 发送档位请求
- sendBlockReq() {
- if (MouseGameFrame.testDanji) {
- 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]}}
- let blockArr = [];
- for (let i = 0; i < response.data.simplyBottom.length; i++) {
- if (i % 2 == 0) {
- let botScoreIdx = response.data.simplyBottom[i];
- let botTimesIdx = response.data.simplyBottom[i + 1];
- let v = response.data.bottomScore[botScoreIdx] * response.data.bottomTimes[botTimesIdx];
- blockArr.push(v);
- }
- }
- console.error('底注------', response.data.bottomScore);
- console.error('翻倍等级', response.data.bottomTimes);
- console.error('底注和翻倍相乘的所有分数', blockArr);
- this.onMouseBlock(blockArr, response);
- // this.view.isRespBlockData = true;
- return
- }else{
- let response:any = {"code":200,"msg":"","data":{percent:5,"bottomScore":this.roomData.Bet2[0],"bottomTimes":this.roomData.Bet2[1],"simplyBottom":this.roomData.Bet2[2]}}
- let blockArr = [];
- for (let i = 0; i < response.data.simplyBottom.length; i++) {
- if (i % 2 == 0) {
- let botScoreIdx = response.data.simplyBottom[i];
- let botTimesIdx = response.data.simplyBottom[i + 1];
- let v = response.data.bottomScore[botScoreIdx] * response.data.bottomTimes[botTimesIdx];
- blockArr.push(v);
- }
- }
- console.error('底注------', response.data.bottomScore);
- console.error('翻倍等级', response.data.bottomTimes);
- console.error('底注和翻倍相乘的所有分数', blockArr);
- this.onMouseBlock(blockArr, response);
- return
- }
- if (Global.getInstance().httpAdress) {
- // HttpUtils.getInstance().post(1, 0, this, HttpAddress.apiPathBlock, {
- // gameType: 0
- // }, (response: NSlots.I_BetResp) => {
- // console.error('response', response);
- // if (response.code == 200) {
- // let blockArr = [];
- // for (let i = 0; i < response.data.simplyBottom.length; i++) {
- // if (i % 2 == 0) {
- // let botScoreIdx = response.data.simplyBottom[i];
- // let botTimesIdx = response.data.simplyBottom[i + 1];
- // let v = response.data.bottomScore[botScoreIdx] * response.data.bottomTimes[botTimesIdx];
- // blockArr.push(v);
- // }
- // }
- // console.error('底注------', response.data.bottomScore);
- // console.error('翻倍等级', response.data.bottomTimes);
- // console.error('底注和翻倍相乘的所有分数', blockArr);
- // this.onMouseBlock(blockArr, response);
- // }
- // }, (err) => {
- // cc.error("请求bottom出错", err);
- // });
-
- UserApi.bottom((response) => {
-
- console.error('response', response);
- response.data.percent = 5
- if (response.code == 200) {
- let blockArr = [];
- for (let i = 0; i < response.data.simplyBottom.length; i++) {
- if (i % 2 == 0) {
- let botScoreIdx = response.data.simplyBottom[i];
- let botTimesIdx = response.data.simplyBottom[i + 1];
- let v = response.data.bottomScore[botScoreIdx] * response.data.bottomTimes[botTimesIdx];
- blockArr.push(v);
- }
- }
- console.error('底注------', response.data.bottomScore);
- console.error('翻倍等级', response.data.bottomTimes);
- console.error('底注和翻倍相乘的所有分数', blockArr);
- this.onMouseBlock(blockArr, response);
- }
- }, (err) => {
- cc.error("请求bottom出错", err);
- })
- } else {
- SocketUtils.getInstance().send(MSG_C2S.Mouse_BLOCK_REQ, {});
- }
- }
- // 发送余额同步请求
- sendBalanceReq() {
- this._needRefreshGold = true;
- Global.getInstance().showLoading("waitMapData");
- if (Global.getInstance().httpAdress) {
- UserApi.syncBalance((response) => {
- if (response.code == 200) {
- let balanceInfo = { balances: [{ type: 2, amount: response.data.amount }], availableBalance: response.data.amount };
- let message = { data: balanceInfo, protoid: MSG_S2C.USER_BALANCE_EVENT };
- this.onProtoMessage(message);
- } else {
- cc.error("Mouse/querySimpleBalance", response.msg);
- }
- Global.getInstance().hideShowLoading("waitMapData");
- }, (err) => {
- cc.error("Mouse/querySimpleBalance", err);
- Global.getInstance().hideShowLoading("waitMapData");
- });
- } else {
- // SocketUtils.getInstance().send(109, {});
- }
- }
- // 发送游戏开始请求
- sendGameStartReq(curDiZhuIdx: number, curMultipleIdx: number) {
- console.error('sendGameStartReq:', curDiZhuIdx, curMultipleIdx);
- this._hasReceiveResult = false;
- this._needRefreshGold = false;
- //单机测试用的
- if (MouseGameFrame.testDanji) {
- this.scheduleOnce(this.testLocal,0.5)
- }else{
- let _data = {"CMD":ProtocolLoginServer.CMD_C2S_Game_RollMouse, "RoomID":this.roomData.ServerID, BottomScore:curDiZhuIdx, BottomTimes:curMultipleIdx}
- // {'CMD':ProtocolLoginServer.CMD_C2S_Game_Roll9X,
- // 'Value':this.gameConfig.nJetton[this.curBetIndex],
- // 'RoomID':this.roomData.ServerID
- // }
- cc.vv.netSocket.send(JSON.stringify(_data));
- }
- if (Global.getInstance().httpAdress) {
- HttpUtils.getInstance().post(1, 0, this, HttpAddress.apiPathGameStart, {//"/p"+G51_SUB_C.Mouse_GAMESTART_REQ
- // score: scoreLevel,
- bottomScore: curDiZhuIdx,
- bottomTimes: curMultipleIdx,
- area: this._qujian,
- type: this._kind,
- buff: this._buff
- }, (response) => {
- let message = null;
- let currentBalance = response.data.data.currentBalance;
- if (response.data.data.currentBalance == null || response.data.data.currentBalance == "null") {
- currentBalance = Global.getInstance().balanceTotal;
- }
- message = { data: { balance: currentBalance }, protoid: MSG_S2C.GAME_BALANCE_EVENT };
- this.onProtoMessage(message);
- message = { data: { balances: [{ type: 2, amount: currentBalance }], availableBalance: currentBalance }, protoid: MSG_S2C.USER_BALANCE_EVENT };
- this.onProtoMessage(message);
- let tempData = JSON.parse(JSON.stringify(response.data.data));
- this.recur_awardTotalTimes(tempData, response.data.bottomScore, response.data.percent, response.data.goldPercent);
- message = { data: tempData, protoid: MSG_S2C.Mouse_GAMESTART_RESP };
- this.onProtoMessage(message);
- }, (err) => {
- cc.error("Mouse/SkullGameReq", err);
- });
- } else {
- // SocketUtils.getInstance().send(MSG_C2S.Mouse_GAMESTART_REQ, {
- // score: scoreLevel,
- // area: this._qujian,
- // type: this._kind,
- // buff: this._buff
- // });
- }
- this.scheduleOnce(this.gameStartDelay, 1);
- }
- /**
- * 根据 底分,线数计算得分
- * @param selmsg
- * @param bottomScore 底分
- * @param percent 线数
- */
- recur_awardTotalTimes(selmsg: any, bottomScore: number, percent: number, goldPercent: number) {
- cc.error("awTimes:" + selmsg.awTimes);
- selmsg.awardTotalTimes = Math.floor(bottomScore * selmsg.awardTotalTimes / percent);
- selmsg.goldValue = Math.floor(bottomScore * selmsg.goldValue / goldPercent);
- // ========= 中奖线金额 added by hmy on 2023/9/28 ========
- selmsg.awTimes = Math.floor(bottomScore * selmsg.awTimes / percent);
- if (selmsg.hasOwnProperty("lineItem")) {
- for (const key in selmsg.lineItem) {
- if (Object.prototype.hasOwnProperty.call(selmsg.lineItem, key)) {
- this.recur_awardTotalTimes(selmsg.lineItem[key], bottomScore, percent, goldPercent);
- }
- }
- }
- // =================
- if (selmsg.hasOwnProperty('normalResult')) {
- for (const key in selmsg.normalResult) {
- if (Object.prototype.hasOwnProperty.call(selmsg.normalResult, key)) {
- const element = selmsg.normalResult[key];
- this.recur_awardTotalTimes(element, bottomScore, percent, goldPercent);
- }
- }
- }
- if (selmsg.hasOwnProperty('superResult')) {
- for (const key in selmsg.superResult) {
- if (Object.prototype.hasOwnProperty.call(selmsg.superResult, key)) {
- const element = selmsg.superResult[key];
- this.recur_awardTotalTimes(element, bottomScore, percent, goldPercent);
- }
- }
- }
- if (selmsg.hasOwnProperty('freeResult')) {
- for (const key in selmsg.freeResult) {
- if (Object.prototype.hasOwnProperty.call(selmsg.freeResult, key)) {
- const element = selmsg.freeResult[key];
- this.recur_awardTotalTimes(element, bottomScore, percent, goldPercent);
- }
- }
- }
- }
- gameStartDelay() {
- cc.warn("发送开始延迟=========");
- if (!this._hasReceiveResult) {
- cc.error("加载中...");
- // Global.getInstance().showLoading("waitResult");
- this.scheduleOnce(this.gameStartOutTime, 5);
- }
- }
- gameStartOutTime() {
- // Global.getInstance().hideShowLoading("waitResult");
- cc.error("没有结算消息返回==");
- // ui.Toast.show("A ligação à rede expirou o tempo!", false);
- // ui.Toast.show(i18nMgr._getLabel("time_out_tip", []), false);
- this.sendBalanceReq();
- }
- // ============================ Request End =============================
- /**
- * 超级转
- */
- onSuperSpin(first?: boolean) {
- let data = this.superResult[this.superResult.length - this.leftSuperTimes];
- this.leftSuperTimes--;
- this.onCommonResult(data, first);
- }
- resetGameData() {
- this._gameStartData = null;
- this._gameMoneyData = null;
- this._receiveCnt = 0;
- }
- // ============================ Test Start =============================
- tipBuff = {
- NEW_USER_BUFFER: "新手概率", RECHARGE_STIMULATE_BUFFER: "充值刺激", RECHARGE_PROTECT_BUFFER: "充值保障", SLOT_PUMPING: "库存抽水", HAND_CTRL_WIN: "手动控放",
- HAND_CTRL_LOST: "手动控杀", SLOT_COMMON: "库存常规", PERSON_LOW: "个人低返奖", SLOT_RELEASE: "库存放水", MUST_LOST: "个人必输", BACK_BUFFER: "回本"
- };
- testLocal() {
- this.onReceiveGameStart(getTestData());
- }
- // ============================ Test End =============================
- onDestroy() {
- this.initServerEvent(false); // 解绑事件
- this.removeMsgListener();
- cc.Tween.stopAll(); // 结束动画
- cc.audioEngine.stopMusic(); // 关闭声音
- AudioPlayer.setBundle(cc.resources);
- }
- // 退出游戏
- exitRoomClick() {
- // if (Global.getInstance().isWeb) {
- // my.MainBackground.getInstance().notifyWeb(4);
- // return;
- // }
- if (Global.getInstance().isSingle) {
- Global.getInstance().showCommonTip("Confirm to Log Out?", this, false, function () {//cancel
- (<any>window).SocketUtils.getInstance().unregisterMessages(this);
- SocketUtils.getInstance().close();//关闭socket
- Global.getInstance().clearToken();
- if (Global.getInstance().getStoreageData(Global.GLOBAL_STORAGE_KEY.LOGIN_TYPE + Global.getInstance().userdata.user_id, 0) == 0) {
- if (cc.sys.OS_ANDROID === cc.sys.os) {
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "WXLogoutReq", "()V");
- } else if (cc.sys.os == cc.sys.OS_IOS) {
- jsb.reflection.callStaticMethod("FacebookUtils", "logout");
- }
- }
- Global.getInstance().mgm = null;
- Global.getInstance().userdata = null;
- Global.getInstance().activityData = null;
- Global.getInstance().rechargeConfig = null;
- Global.getInstance().giftConfig = null;
- Global.getInstance().withdrawBalance = 0;
- Global.getInstance().balanceTotal = 0;
- Global.getInstance().bonusTotal = 0;
- Global.getInstance().nextluckyShotTime = 0;
- Global.getInstance().luckyshotRemainTimes = 0;
- Global.getInstance().redAndBlackRemainTimes = 0;
- Global.getInstance().redAndBlackRltData = null;
- cc.director.loadScene('loginScene');
- });
- } else {
- Global.getInstance().gameToHall({ exitReason: 203 }, this);
- }
- }
- //退出游戏
- onClickExit() {
- // this._gameScene.exitGameWhenPlaying();
-
- // if(!this._gameEnd || this._nFreeCount > 0) {
- // topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.not_exit_game"));
- // return;
- // }
- if(cc.vv.config.ReviewApk) {
- cc.game.end();
- return;
- }
- this._backHome = true;
- cc.sys.localStorage.setItem("InGameServerID", -1);
- this.removeMsgListener();
- ScenceManager.Instance().gameBackScence();
- }
- // =============== Useless ============
- // 用户离开
- onSocketPlayerQuitGameResp(data: any): boolean { return true; }
- // 用户进入
- onSocketPlayerJoinGameResp(data: any): boolean { return true; }
- // 发送逃跑
- sendEscape(): boolean { return true; }
- sendJoinGame(): boolean { return true; }
- // 游戏场景
- onEventGameScene(data: any): boolean { return true; }
- // 游戏消息
- onEventGameMessage(scmd: number, data: any): boolean { return false; }
- }
|