123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684 |
- var GameBase = require("LBGameBase");
- var ProtocolGameServer = require("ProtocolGameServer");
- var GameProtocol = require("FruitGameProtocol");
- var AnalyzeXieYi = require("AnalyzeFruitXieYi");
- var MakeXieYi = require("MakeFruitXieYi");
- var Global = require("Global");
- var topTipMsg = require("topTipMsg");
- var UIHelper = require("UIHelper");
- var BaseDefine = require("BaseDefine");
- import { CServerItem } from 'CServerItem'
- import GameManagerBase from 'GameManagerBase'
- import ScenceManager from 'HNScenceManager'
- // const GAME_FREE = 0; //无
- // const GAME_PLAYING = 1; //游戏中
- // const GAME_END = 2; //游戏结束
- // const GAME_PLAYSCOREING = 3; //表现分数增加中
- // const GAME_GAMEEND = 4; //游戏真正结束
- cc.Class({
- extends: GameBase,
- editor: {
- menu: 'Game/Fruit/GameSence'
- },
- properties: {
- // rollNode: cc.Node,
- // playerScore: cc.Label,
- // recordPanel: cc.Node,
- // recordContent: cc.Node,
- // recordClone: cc.Node,
- // backPanel: cc.Node,
- // setPanel: cc.Node,
- // resultNode: cc.Node,
- // guideNode: cc.Node,
- freeLeftNode: cc.Node,
- winSpineData: [sp.SkeletonData],
- // _gameEnd: true,
- // _bQuickGame: false,
- // _bAutoGame: false,
- // _bFreeGame: false,
- // _nAutoCount: 0,
- // _nFreeCount: 0,
- // _nFreeTotal: 0,
- // _bFreeState: 0,
- // _nFreeWin: 0,
- // _currentScore: 0,
- // _lastScore: 0,
- // _nowBet: 0,
- // _playingAudioID: -1,
- // _bFirstIn: true,
- },
- onLoad () {
- this._super();
- this.LG_PATH_SC = "LB-Fruit/";
- this.homeBtn.active = !cc.vv.config.ReviewApk;
- },
- getRandomValue(i) {
- if(i == 0) {
- return this.rollPanel.getRandomValue();
- }
- let ddd = Math.floor(Math.random()*100);
- if(ddd > 90) {
- return 11;
- }
- return ddd % 8;
- },
- onEventSceneMessage(gameStatus,lookonUser,data) {
- Global.print("GameSence onEventSceneMessage 场景消息 ");
- var arr = new DataView(data.slice(0, 8));
- var dataView = new DataView(data.slice(8));
- var msgHead = { m: arr.getUint16(4, true), s: arr.getUint16(6, true), d: null };
- arr = null;
- this.gameConfig = AnalyzeXieYi.analyze_GameConfig(dataView);
- Global.print(this.gameConfig);
- this.bets = this.gameConfig.nJetton;
- this.refrushBet();
- },
- onEventGameMessage(data) {
- var arr = new DataView(data.slice(0, 8));
- var dataView = new DataView(data.slice(8));
- var msgHead = { m: arr.getUint16(4, true), s: arr.getUint16(6, true), d: null };
- arr = null;
- // Global.print(msgHead)
- var msg = AnalyzeXieYi.analyzeData(msgHead.m, msgHead.s, dataView);
- switch (msgHead.s) {
- case GameProtocol.SUB_S_REBACK_LOTTERY: { // 操作记录
- Global.print("SGLB::结果");
- this.onRollEndInfo(msg);
- }
- break;
- case GameProtocol.SUB_S_JACKPOT_RESET: { // 操作记录
- Global.print("JACKPOT");
- // this.showOperateRecordPanel(msg);
- }
- break;
- case GameProtocol.SUB_S_SEND_CONTROL_INFO: {
- Global.print("SUB_S_SEND_CONTROL_INFO");
- this.onSubSendControlInfo(msg);
- }
- break;
- default: {
- Global.print("SGLBGameSence onEventGameMessage error ");
- }
- break;
- }
- },
- showDebugRewardInfo() {
- let count = this.gameEndData.m_line_count;
- let lineid = this.gameEndData.m_line_id;
- let str = "中奖信息:" + count + "条线[";
- for(let i = 0; i < count; ++i) {
- str += (lineid[i]+1) + ',';
- }
- str += ']';
- str += this.gameEndData.m_kongming == 1 ? "\n中免费次数" : "";
- const infoNode = cc.find("ControlInfo/info", this.node);
- infoNode.getChildByName("reward").getComponent(cc.RichText).string = str;
- },
- onEventGameRecord(data) {
- let dd = AnalyzeXieYi.analyze_Record(data);
- this._gameRecords.push(dd);
- this.addOneRecord(dd);
- // if(this._gameRecords.length >= 60) {
- // this.showRecordsPanel();
- // }
- },
- backHome: function() {
- if (CServerItem.get()) {
- CServerItem.get().PerformStandUpAction(1);
- } else {
- this.exitGame();
- }
- this._backHome = true;
- ScenceManager.Instance().gameBackScence();
- GameManagerBase.Instance().setInGameServerID(-1);
- },
- onClickHome() {
- if(!this._gameEnd || this._nFreeCount > 0) {
- this.showBackTips();
- return;
- }
- this.backHome();
- this.exitGame();
- },
- onClickGoldBuy() {
- if(cc.vv.config.ReviewApk) return;
- // let FirstPay10State = cc.vv.GetHallScript().GetFirstPay10State();
- // let FirstPayState = cc.vv.GetHallScript().GetFirstPayState();
- // if(FirstPay10State){
- // cc.vv.GetHallScript().onClickFirstPay_10(null,true);
- // }else if(FirstPayState){
- // cc.vv.GetHallScript().onClickFirstPay(null,true);
- // }else{
- cc.vv.GetHallScript().showBuyGold();
- // }
- this.hideGuideNode();
- },
- showBackTips() {
- this.backPanel.active = true;
- },
- hideBackTips() {
- this.playEffect("button");
- this.backPanel.active = false;
- },
- onRollEndInfo(data) {
- Global.print(data);
- if(!this._bQuickGame)
- this.changeBtnState(true);
- this.gameEndData = data;
- if(this._nFreeCount > 0) {
- this.upFreeCount();
- }
- let endSp = data.cbFreeTime > 0;
- this._bFreeEnd = false;
- if(this._bSpecialGame || endSp) {
- this._bSpecialGame = endSp;
- this._nFreeWin += data.m_lottery_size;
- this._bFreeEnd = data.cbFreeTime == 0;
- }
- this._nFreeCount = data.cbFreeTime;
- this._nFreeTotal += data.cbFreeAdd;
- this._bFreeState = data.m_kongming;
- this._winTimes = Math.floor(data.m_lottery_size*5000 / data.m_chip_size);
- // setTimeout(()=>{
- this.rollPanel.setRollDatas(data);
- // this.rollPanel.openPrize(false, this._bQuickGame);
- this.rollPanel.openPrizes(false, this._bQuickGame);
- // }, 2000)
- // this.rollPanel.setRollDatas(data);
- // // this.rollPanel.openPrize(false, this._bQuickGame);
- // this.rollPanel.openPrizes(false, this._bQuickGame);
- this.showDebugRewardInfo();
- },
- makeXieYi(m,s,data) {
- if(m == ProtocolGameServer.MDM_GF_FRAME) {
- return //new DataView(arrayBuffer)
- }
- return MakeXieYi.makeRoll(data);
- },
- onClickRecord() {
- this.recordContent.removeAllChildren();
- this._gameRecords.splice(0);
- this.recordPanel.active = true;
- this.getGameRecord();
- },
- onSendRoll() {
- let t = {};
- t.nJetton = this.gameConfig.nJetton[this.curBetIndex];
- // Global.print(t);
- this.SendGameSocketData(GameProtocol.SUB_C_LOTTERY, t);
- },
- upLeftCount() {
- this.freeLeftNode.active = this._bSpecialGame;
- if(this._bSpecialGame) {
- this.freeLeftNode.getChildByName("left").getComponent(cc.Label).string = this._nFreeCount + '/' + this._nFreeTotal;
- }else{
- this._super();
- }
- },
- upFreeCount() {
- let funcNode = this.node.getChildByName("FuncBtnNode");
- let left = funcNode.getChildByName("btn_left");
- left.active = this._nFreeCount > 0;
- left.getChildByName("left").getComponent(cc.Label).string = (this._nFreeCount-1) + '/' + this._nFreeTotal;
- // this.upBtnInteractable(funcNode.getChildByName("btn_auto"), false);
- },
- // judgeAuto() {
- // let funcNode = this.node.getChildByName("FuncBtnNode");
- // if(this._nAutoCount == 0) {
- // this._bAutoGame = false;
- // }else{
- // this._bAutoGame = true;
- // }
- // funcNode.getChildByName("btn_left").active = this._bAutoGame;
- // let left = funcNode.getChildByName("btn_left");
- // left.active = this._bAutoGame;
- // left.getChildByName("left").active = this._nAutoCount > 0;
- // left.getChildByName("left2").active = this._nAutoCount < 0;
- // left.getChildByName("left").getComponent(cc.Label).string = this._nAutoCount;
- // },
- // onStartRoll() {
- // if(!this._gameEnd) return;
- // this.node.stopAllActions();
- // this.resetGameView();
- // cc.vv.audioMgr.stopSFX(this._playingAudioID);
- // //是否可以开始游戏
- // if(!this.judgeCannotRollGame()) {
- // return;
- // }
- // this._gameEnd = false;
- // this.changeGameState(1);
- // if(!cc.vv.audioMgr.resumeBackMusic()) {
- // cc.vv.audioMgr.playBGM(this.LG_PATH_SC + "bgm");
- // }
-
- // this.upLeftCount();
- // this.onSendRoll();
- // // this.testResult();
- // this.showCenterNormal();
- // this.onGameStart();
- // this.rollPanel.startRollActions();
- // },
- // resetGameView() {
- // this._super();
- // this.hideFreeWin();
- // },
- showGameEnd() {
- this._super();
- //获得免费次数
- if(this._bFreeState == 1) {
- cc.vv.audioMgr.pauseBackMusic();
- this.showGetFreeTimes(this.gameEndData.cbFreeAdd);
- }else if(this._bFreeEnd){
- //免费次数结束,自动游戏在其他地方判断
- }else if(this.winAniIdx < 0 || this._bSpecialGame){
- this.delayStartNextRoll(1);
- }
- },
- onClickSkip() {
- this.playButtonEffect();
- let scoreNode = this.resultNode.getChildByName("mask").getChildByName("scoreNode");
- this.skipScoreAdd(scoreNode.getChildByName("score").getComponent(cc.Label),scoreNode.getChildByName("score2").getComponent(cc.Label))
- },
- showResultPanel() {
- let ssNodeY = [-44,-103,-103,-150,-150];
- this.changeGameState(3);
- this.resultNode.active = true;
- let node = this.resultNode.getChildByName("mask");
- let goldNode = node.getChildByName("goldani");
- let ssNode = node.getChildByName("scoreNode");
- let sNode = ssNode.getChildByName("score");
- let sNode2 = ssNode.getChildByName("score2");
- let sLabel = sNode.getComponent(cc.Label);
- let sLabel2 = sNode2.getComponent(cc.Label);
- let aniNode1 = node.getChildByName("wani");
- aniNode1.active = true;
- goldNode.active = true;
- ssNode.active = false;
- let anii = aniNode1.getComponent(sp.Skeleton);
- anii.skeletonData = this.winSpineData[this.winAniIdx];
- if(this.winAniIdx > 0) {
- //金币动画
- let gAni = goldNode.getComponent(sp.Skeleton);
- gAni.clearTracks();
- gAni.setAnimation(0, 'a'+this.winAniIdx, true);
- }else{
- goldNode.active = false;
- }
-
- //win动画
- anii.clearTracks();
- anii.setAnimation(0, "a1", false);
- anii.addAnimation(0, "a2", true);
- this.resultNode.stopAllActions();
- cc.tween(this.resultNode)
- .delay(0.3)
- .call(()=>{
- if(this.winAniIdx>=0 && this.winAniIdx<ssNodeY.length)
- ssNode.y = ssNodeY[this.winAniIdx];
- ssNode.active = true;
- sLabel.string = '0';
- sLabel2.string = '.00';
- this.playScoreAddAni(sLabel, sLabel2);
- this.changeSkipBtnState(true);
- })
- .start()
- },
- hideResultPanel() {
- this.resultNode.active = false;
- },
- showGameWinScore() {
- this.winAniIdx = -1;
- this.needPlayinfScore = this.gameEndData.m_lottery_size;
-
- let score = this.gameEndData.m_lottery_size;
- //免费游戏中
- if(this._bSpecialGame) {
- if(this._bFreeState) {
- this.playEffect("freestart");
- }
- let nnode = this.node.getChildByName("RoomInfoNode").getChildByName("img_1");
- nnode.getChildByName("normalNode").active = false;
- nnode.getChildByName("winNode").active = true;
- nnode.getChildByName("winNode").getChildByName("score").getComponent(cc.Label).string = Global.formatString2Score(this._nFreeWin);
- return;
- }
- //免费游戏结束
- if(this.gameEndData.m_chip_size == 0) {
- cc.vv.audioMgr.playBGM("bgm");
- this.needPlayinfScore = this._nFreeWin;
- let timers = Math.floor(this._nFreeWin * 50 / this.gameConfig.nJetton[this.curBetIndex]);
- this._currentScore = this._lastScore;
- this.upPlayerScore(this._currentScore);
- // this.playSoundByTimes(timers);
- let nnode = this.node.getChildByName("RoomInfoNode").getChildByName("img_1");
- nnode.getChildByName("normalNode").active = false;
- nnode.getChildByName("winNode").active = true;
- nnode.getChildByName("winNode").getChildByName("score").getComponent(cc.Label).string = Global.formatString2Score(this._nFreeWin);
- this.showFreeWin();
- return;
- }
- let timers = Math.floor(score * 50 / this.gameConfig.nJetton[this.curBetIndex]);
- this._currentScore = this._lastScore;
- this.upPlayerScore(this._currentScore);
-
- if(score <= 0){
- return;
- }
- this.playSoundByTimes(timers);
- let nnode = this.node.getChildByName("RoomInfoNode").getChildByName("img_1");
- nnode.getChildByName("normalNode").active = false;
- nnode.getChildByName("winNode").active = true;
- nnode.getChildByName("winNode").getChildByName("score").getComponent(cc.Label).string = Global.formatString2Score(score);
-
- if(this.winAniIdx >= 0) {
- this.showResultPanel();
- }
- },
- delayStartNextRoll(delayTime) {
- if(!this._bSpecialGame) {
- this._nFreeTotal = 0;
- this.freeLeftNode.active = false;
- }
- this._super(delayTime);
- },
- showGetFreeTimes(times) {
- let freeNode = this.node.getChildByName("freeNode");
- let aniNode = freeNode.getChildByName("mask");
- // let ani = aniNode.getComponent(sp.Skeleton);
- // ani.clearTracks();
- // ani.setAnimation(0, "a1", false);
- freeNode.active = true;
- this._bSpecialGame = true;
- let sstr = aniNode.getChildByName("s");
- sstr.getComponent(cc.Label).string = times;
- sstr.stopAllActions();
- sstr.angle = 0;
- sstr.active = false;
- aniNode.stopAllActions();
- cc.tween(aniNode)
- .delay(0.4)
- .call(()=>{
- sstr.active = true;
- })
- .delay(0.2)
- .call(()=>{
- cc.tween(sstr)
- .to(1.4, {angle: -60})
- .start()
- })
- .delay(1.4)
- .call(()=>{
- freeNode.active = false;
- cc.vv.audioMgr.playBGM("freebgm");
- this.delayStartNextRoll(0.5);
- })
- .start()
- // cc.tween(freeNode.getChildByName("mark"))
- // .hide()
- // .delay(1+5)
- // .show()
- // .start()
- },
- showFreeWin() {
- if(this.gameEndData.m_kongming == 0) {
- this._nFreeWin = 0;
- }
- this.playEffect("freeend");
- let winNode = this.node.getChildByName("freeWin");
- winNode.active = true;
- let node = winNode.getChildByName("mask");
- let startBtn = node.getChildByName("btn_start");
- startBtn.active = false;
- let scoreNode = node.getChildByName("score1");
- scoreNode.stopAllActions();
- scoreNode.scale = 1;
- scoreNode.active = false;
- let ani = node.getComponent(sp.Skeleton);
- ani.clearTracks();
- ani.setAnimation(0, "b1", false);
- ani.setCompleteListener(()=>{
- ani.setCompleteListener(()=>{})
- ani.setAnimation(0, "b2", true);
- scoreNode.active = true;
- this.changeFreeWinBtn(true);
- this.playFreeWinAddAni(scoreNode.getComponent(cc.Label));
- })
- // winNode.stopAllActions();
- // cc.tween(winNode)
- // .delay(0.4)
- // .call(()=>{
- // // scoreNode.active = true;
- // // scoreNode.scale = 2;
- // // scoreNode.stopAllActions();
- // // cc.tween(scoreNode)
- // // .to(0.3, {scale: 1})
- // // .start()
- // })
- // .delay(2)
- // .call(()=>{
- // this.delayStartNextRoll(1);
- // })
- // .start()
- },
- hideFreeWin() {
- this.playButtonEffect();
- let winNode = this.node.getChildByName("freeWin");
- winNode.stopAllActions();
- if(!winNode.active){
- this.onStartRoll();
- return;
- }
-
- let node = winNode.getChildByName("mask");
- let ani = node.getComponent(sp.Skeleton);
- ani.clearTracks();
- ani.setAnimation(0, "b3", false);
- ani.setCompleteListener(()=>{
- ani.setCompleteListener(()=>{})
- winNode.active = false;
- this.onStartRoll();
- })
- },
- onClickSkipFreeWin() {
- this.playButtonEffect();
- let winNode = this.node.getChildByName("freeWin").getChildByName("mask");
- this.skipFreeWinAdd(winNode.getChildByName("score1").getComponent(cc.Label));
- },
- onClickFreeWinStart() {
- },
- playFreeWinAddAni(sLabel) {
- let start = 0;
- let bet = this.gameConfig.nJetton[this.curBetIndex];
- let endScore = Global.formatString2Score(this.needPlayinfScore);
- let add = parseFloat(bet/100/this.MAX_LINE);
- this.upFreeWinLabel = ()=>{
- start += add;
- if(start >= endScore) {
- this.skipFreeWinAdd(sLabel);
- }else{
- sLabel.string = parseFloat(start).toFixed(2);
- }
- }
- if(this.upFreeWinLabel) {
- this.unschedule(this.upFreeWinLabel);
- }
- this.schedule(this.upFreeWinLabel, 0.01);
- },
- skipFreeWinAdd(sLabel) {
- if(this.upFreeWinLabel) {
- this.unschedule(this.upFreeWinLabel);
- }
- let score = this.needPlayinfScore;
- sLabel.string = Global.formatString2Score(score);
- sLabel.node.stopAllActions();
- cc.tween(sLabel.node)
- .sequence(
- cc.tween().to(0.25, {scale: 0.9}),
- cc.tween().to(0.25, {scale: 1})
- )
- .repeatForever()
- .start()
-
- this.changeFreeWinBtn(false);
- let node = this.node.getChildByName("freeWin");
- node.stopAllActions();
- cc.tween(node)
- .delay(0.5)
- .call(()=>{
- if(this._bAutoGame)
- this.hideFreeWin();
- })
- .start()
- },
- changeFreeWinBtn(bSkip) {
- let winNode = this.node.getChildByName("freeWin").getChildByName("mask");
- winNode.getChildByName("btn_start").active = !bSkip;
- winNode.getChildByName("btn_skip").active = bSkip;
- },
-
- addOneRecord(info) {
- let item = cc.instantiate(this.recordClone);
- item.getChildByName("time").getComponent(cc.Label).string = Global.formatDate(new Date(info.nTime*1000));
- item.getChildByName("bet").getComponent(cc.Label).string = Global.formatString2Score(info.nBet);
- let win = info.nBet+info.nWinLost;
- // let col = new cc.Color(232, 232, 232);
- // if(win > 0) {
- // col = new cc.Color(248, 201, 39);
- // }
- // item.getChildByName("win").color = col;
- item.getChildByName("win").getComponent(cc.Label).string = Global.formatString2Score(win);
- item.active = true;
- item.parent = this.recordContent;
- },
- showRecordsPanel() {
- this.recordContent.removeAllChildren();
- for(let i = 0; i < this._gameRecords.length; ++i) {
- let info = this._gameRecords[i];
- let item = cc.instantiate(this.recordClone);
- item.getChildByName("time").getComponent(cc.Label).string = Global.formatDate(new Date(info.nTime*1000));
- item.getChildByName("bet").getComponent(cc.Label).string = Global.formatString2Score(info.nBet);
- let win = info.nBet+info.nWinLost;
- // let col = new cc.Color(232, 232, 232);
- // if(win > 0) {
- // col = new cc.Color(248, 201, 39);
- // }
- // item.getChildByName("win").color = col;
- item.getChildByName("win").getComponent(cc.Label).string = Global.formatString2Score(win);
- item.active = true;
- item.parent = this.recordContent;
- }
- this.recordPanel.active = true;
- },
- onClickSet() {
- this.playButtonEffect();
- this.setPanel.active = true;
- this.changeAudioBtnState();
- },
- showCenterNormal() {
- if(this._bSpecialGame) return;
- this.node.getChildByName("RoomInfoNode").getChildByName("img_1").getChildByName("normalNode").active = true;
- this.node.getChildByName("RoomInfoNode").getChildByName("img_1").getChildByName("winNode").active = false;
- },
- onClickRule() {
- this.playButtonEffect();
- UIHelper.loadRes('resourcesPrefab/ruleNode', cc.Prefab, (prefab)=>{
- if (!this._ruleNode) {
- this._ruleNode = cc.instantiate(prefab);
- this._ruleNode.parent = this.node;
- }
- this._ruleNode.getComponent("FruitRule").show();
- })
- },
- playSoundByTimes(_times) {
- if(_times <= 0) return;
- let id = 1;
- if(_times > 3000){
- id = 15;
- this.winAniIdx = 3;
- }else if(_times > 2500){
- id = 14;
- this.winAniIdx = 3;
- }else if(_times > 2000){
- id = 13;
- this.winAniIdx = 3;
- }else if(_times > 1600){
- id = 12;
- this.winAniIdx = 3;
- }else if(_times > 1200){
- id = 11;
- this.winAniIdx = 3;
- }else if(_times > 800){
- id = 10;
- this.winAniIdx = 3;
- }else if(_times > 500){
- id = 9;
- this.winAniIdx = 3;
- }else if(_times > 300){
- id = 8;
- this.winAniIdx = 2;
- }else if(_times > 200){
- id = 5;
- this.winAniIdx = 1;
- }else if(_times > 100){
- id = 4;
- this.winAniIdx = 0;
- }else if(_times > 50){
- id = 3;
- this.winAniIdx = -1;
- }else if(_times > 25){
- id = 2;
- this.winAniIdx = -1;
- }
- this.playEffect("Level"+id);
- },
- playButtonEffect(){
- this.playEffect("button");
- },
- });
|