123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463 |
- import { qp } from "../../../SubGamePublic/PG_Public/Script/lib/define2";
- import { theAudoConfig, theGlobalUserInfo } from "../../../SubGamePublic/PG_Public/Script/lib/global2";
- import MouseBottom from "./MouseBottom";
- import { MouseConst } from "./MouseConst";
- import MouseGameFrame from "./MouseGameFrame";
- import MouseIconView from "./MouseIconView";
- import MouseNotice from "./MouseNotice";
- import MouseWinView from "./MouseWinView";
- import MouseSpin from "./MouseSpin";
- import MouseAutoView from "./MouseAutoView";
- import MouseAutoModel from "./MouseAutoModel";
- const { ccclass, property, menu } = cc._decorator;
- const TWEEN_TIME = 1002;
- @ccclass
- @menu("Game/Mouse/MouseGameFrameView")
- export default class MouseGameFrameView extends cc.Component {//AbstractGameFrameView<MouseGameFrame>
- _frame: MouseGameFrame = null;
- get frame(): MouseGameFrame {
- return this._frame;
- }
- @property({ type: MouseBottom, tooltip: '底部' })
- bottomView: MouseBottom = null;
- @property({ type: MouseIconView, tooltip: '转动区' })
- iconView: MouseIconView = null;
- @property({ type: MouseWinView, tooltip: '中奖特效' })
- winView: MouseWinView = null;
- @property({ type: MouseNotice, tooltip: '通知栏' })
- noticeView: MouseNotice = null;
- @property(MouseSpin)
- mouseSpin: MouseSpin = null;
- @property(cc.Node)
- nodeTest: cc.Node = null;
- @property(cc.AudioClip)
- normalBgm: cc.AudioClip = null;
- // =============== AutoView Start ===================
- autoModel: MouseAutoModel = null;
- @property(cc.Prefab)
- autoView: cc.Prefab = null;
- @property({ type: cc.Node, tooltip: '弹窗承载节点' })
- popParent: cc.Node = null;
- addNode(node: cc.Node) { node.parent = this.popParent; }
- popAutoView() {
- //回调
- let autoFunc = (data: NSlots.IAutoData) => {
- this.autoModel.setAutoData(data);
- this.onDealAuto();
- };
- let view = cc.instantiate(this.autoView).getComponent(MouseAutoView);
- //这里的值根据自己的框架获取即可
- view.initData(this.bottomView.gameBalance, this.bottomView.curBetScore, this.bottomView.winScore, autoFunc);
- //这里直接加到场景上也可以,和paytable一样即可
- this.addNode(view.node);
- }
- onDealAuto() {
- if (!this.isAuto()) return;
- //auto的一些UI处理,这里根据自己的实际情况来写
- this.setBtnEnabled(false);
- //自动UI
- this.bottomView.updateAutoEnable();
- this.onSpinAuto();
- }
- /**@description auto spin */
- onSpinAuto() {
- this.scheduleOnce(() => {
- this.autoModel.updateRound();
- this.bottomView.updateAutoTimes();
- }, 0.3);
- this.scheduleOnce(() => this.spinNormal(), 0.4);
- }
- onExitAuto() {
- this.autoModel.clear();
- this.bottomView.updateAutoEnable();
- this.setBtnEnabled(!this.isGaming);
- }
- isAuto() {
- return this.autoModel.isAuto;
- }
- // =============== AutoView End ===================
- // =============== 时钟 Start===================
- @property(cc.Label)
- labTime: cc.Label = null;
- timer = null;
- _idleTime: number = 0; // 老鼠空闲
- protected start(): void {
- let time = new Date().getTime();
- this.labTime.string = this.formatTime(time);
- this.timer = setInterval(() => {
- let time = new Date().getTime();
- this.labTime.string = this.formatTime(time);
- if (this.isGaming) {
- this._idleTime = 0;
- } else {
- this._idleTime++;
- }
- if (this._idleTime > 1 * 60) { // 1分钟
- this.iconView.mouseAvatar.playIdleAnim();
- this._idleTime = 0;
- }
- }, 1000);
- }
- formatTime(timestamp): string {
- var date = new Date(timestamp);
- var hours: any = date.getHours();
- var minutes: any = date.getMinutes();
- var seconds: any = date.getSeconds();
- // 添加前导零,确保两位数的格式
- hours = (hours < 10) ? "0" + hours : hours;
- minutes = (minutes < 10) ? "0" + minutes : minutes;
- seconds = (seconds < 10) ? "0" + seconds : seconds;
- return hours + ":" + minutes + ":" + seconds;
- }
- protected onDestroy(): void {
- clearInterval(this.timer);
- }
- // =============== 时钟 End ===================
- private _isGaming: boolean = false; // 是否游戏中
- set isGaming(v: boolean) {
- this._isGaming = v;
- }
- get isGaming() {
- return this._isGaming;
- }
- private _isSuperSpin = false; // 是否开始超级转
- get isSuperSpin() {
- return this._isSuperSpin;
- }
- set isSuperSpin(v: boolean) {
- this._isSuperSpin = v;
- }
- onLoad() {
- // 声音控制
- theAudoConfig.enableMusic = Global.getInstance().ismusicon !== 0;
- theAudoConfig.enableEffect = Global.getInstance().issoundon !== 0;
- this.autoModel = new MouseAutoModel();
- }
- //初始化工作
- initGameView(frame: MouseGameFrame): void {
- // super.initGameView(frame);
- }
- //重置视图
- resetGameView(): void {
- if (this.isGaming) {
- cc.error("==================== MouseGameFrameView resetGameView 跳过,正在游戏中 ====================");
- return;
- }
- cc.error("==================== MouseGameFrameView resetGameView ====================");
- // super.resetGameView();
- // 重置
- this.unscheduleAllCallbacks();
- this.node.stopAllActions();
- cc.Tween.stopAllByTarget(this.iconView);
- this.isGaming = false;
- this.isSuperSpin = false;
- this.bottomView.resetView();
- this.iconView.resetView();
- this.winView.resetView();
- this.noticeView.resetView();
- }
- /**
- * 根据场景配置设置押分挡位
- */
- // updateBetScore(betlevelScore: number[]) {
- // if (betlevelScore instanceof Array) {
- // this.bottomView.betScoreArray = betlevelScore;
- // }
- // }
- /**
- * 根据场景配置设置押分挡位
- * @param betLevelScore
- * @param data
- */
- updateBetScore(betLevelScore: number[], data: NSlots.I_BetResp) {
- this.bottomView.updateBetScore(betLevelScore, data);
- this.bottomView.updateBetView(data);
- }
- /**
- * 更新用户余额
- */
- updateMyScore(score: number) {
- cc.error("更新自己的钱", score);
- this.bottomView.gameBalance = score;
- this.bottomView.realBalance = score;
- }
- // ========================= 游戏流程 ==========================
- onSpinPre() {
- this.isGaming = true;
- // 游戏开始音效
- // AudioPlayer.playEffect(MouseConst.Sound.spinStart, false);
- // Global.getInstance().hideShowLoading("waitResult");
- this.winView.resetView();
- this.noticeView.resetView();
- this.iconView.resetView();
- this.bottomView.resetView();
- this.iconView.onSpinPre();
- this.mouseSpin.spinStart();
- }
- /**
- * 接收游戏结果, 执行转动
- */
- onSpinStart(result: NSlots.ICommonResult, hasSuperSpin?: boolean) {
- cc.warn("==================> onSpinStart, hasSuperSpin:" + hasSuperSpin);
- if (this.isSuperSpin) {
- this.winView.resetView();
- this.noticeView.resetView();
- this.iconView.resetView();
- this.bottomView.resetView();
- }
- this.iconView.onSpinReady(result, () => this.onCheckWin(result), hasSuperSpin);
- // 转的过程中(开始1s后)执行Super动画
- if (hasSuperSpin) {
- this.scheduleOnce(() => {
- this.iconView.playSuperAnim(() => {
- this.noticeView.onEnterSuper();
- this.onSuperSpinStart();
- });
- }, 1);
- }
- }
- /**
- * 检查连线奖励
- */
- onCheckWin(result: NSlots.ICommonResult) {
- cc.warn("==================> onCheckWin");
- let winScore = result?.awardTotalTimes || 0; // 连线赢得
- if (winScore > 0) {
- this.mouseSpin.spinPause();
- }
- this.winView.showWinView(this.bottomView.curBetScore, winScore,
- (multiple) => {
- if (winScore > 0) {
- this.iconView.mouseAvatar.playWinAnim();
- }
- this.noticeView.showWin(winScore, multiple, () => {
- this.bottomView.addWinScore(winScore);
- this.scheduleOnce(() => this.onSpinOver(), winScore > 0 ? 1 : 0);
- });
- }
- );
- }
- /**
- * 一次转动流程结束
- */
- onSpinOver() {
- cc.warn("==================> onSpinOver");
- // 判断顺序 Super -> Normal
- if (this.frame.leftSuperTimes > 0) {
- this.onSuperSpinNext();
- } else if (this.isSuperSpin) {
- this.onSuperSpinEnd();
- } else {
- this.onNormalSpinNext();
- }
- }
- // ========================= 普通转 ======================
- onNormalSpinNext() {
- cc.warn('========== 游戏结束,准备下一局 =========');
- this.frame.resetGameData();
- // Global.getInstance().isWeb &&
- // my.MainBackground.getInstance().notifyWeb(1, { balances: this.bottomView.realBalance });
- this.mouseSpin.spinOver();
- this.bottomView.gameBalance = this.bottomView.realBalance;
- //处在自动模式下
- if (this.isAuto()) {
- cc.error("==========> winscore:" + this.bottomView.winScore);
- this.autoModel.addWinScore(this.bottomView.winScore); //添加本局的金钱
- //检测是否继续auto
- if (this.autoModel.checkAuto(this.bottomView.gameBalance)) {
- this.onSpinAuto();
- return; //这里返回,不往下走
- }
- let score = Global.getInstance().balanceTotal - this.bottomView.curBetScore;
- if (score < 0) {
- this.showInsufficientBalance();
- };
- this.onExitAuto();
- }
- // 非自动下的内容
- this.isGaming = false;
- this.setBtnEnabled(true);
- }
- // 普通转
- spinNormal() {
- let score = Global.getInstance().balanceTotal - this.bottomView.curBetScore;
- if (score < 0) {
- this.showInsufficientBalance();
- this.onExitAuto();
- return;
- }
- this.bottomView.gameBalance = score;
- this.frame.resetGameData();
- this.resetGameView();
- this.setBtnEnabled(false);
- this.onSpinPre();
- // this.frame.sendGameStartReq(this.bottomView.betScoreIndex);
- this.frame.sendGameStartReq(this.bottomView.curDiZhuIdx, this.bottomView.curMultipleIdx);
- Global.getInstance().setStoreageData(MouseConst.BetScoreTemp, this.bottomView.tempChooseBet);
- Global.getInstance().setStoreageData(MouseConst.BetScoreIdx, this.bottomView.betScoreIndex);
- // this.frame.testLocal();
- }
- showInsufficientBalance() {
- AudioPlayer.playEffect(MouseConst.Sound.coinNotEnough, false);//下注时金钱不足
- // ui.Toast.show("Fichas insuficientes para continuar o jogo", false);
- cc.director.emit("showNoMoneyTip");
- // this.setBtnEnabled(true);
- }
- // ========================= 超级转 ======================
- superEffectAuidioId: number;
- /**
- * 触发超级转
- */
- onSuperSpinStart() {
- this.isSuperSpin = true;
- this.mouseSpin.spinPause();
- // 超级转背景音乐
- AudioPlayer.playMusic(MouseConst.Sound.superBgm, true, 0.5);
- AudioPlayer.playEffect(MouseConst.Sound.superEffect, true, 0.5, false, (audioID: number) => {
- this.superEffectAuidioId = audioID;
- });
- this.iconView.onEnterSuper();
- }
- /**
- * 进行下一步超级转
- */
- onSuperSpinNext() {
- this.scheduleOnce(() => this.spinSuper(), 0.5);
- }
- /**
- * 超级转结束
- */
- onSuperSpinEnd() {
- this.isSuperSpin = false;
- // 切换背景音乐
- AudioPlayer.playMusic(MouseConst.Sound.normalBgm, true, 0.5);
- AudioPlayer.stopEffect(this.superEffectAuidioId);
- this.iconView.onExitSuper(() => {
- this.onNormalSpinNext();
- });
- }
- spinSuper() {
- this.setBtnEnabled(false);
- this.frame.onSuperSpin();
- }
- // =========================================
- //更新按钮状态
- setBtnEnabled(btnState: boolean) {
- this.bottomView.setBtnEnabled(btnState);
- }
- // ===================== Useless ===================
- //设置用户
- setUserItem(viewChairID: number, userItem: qp.IUserItem) {
- // super.setUserItem(viewChairID, userItem);
- cc.log("setUserItem");
- // ui.Loading.hide();
- if (userItem) {
- //自己的信息
- if (userItem.uid == theGlobalUserInfo.uid) {
- this.updateMyScore(userItem.coin);
- }
- } else {
- //...用户离开
- }
- }
- //分数变化
- onEventUserScore(viewChairID: number, userItem: qp.IUserItem) {
- // cc.log("onEventUserScore=====>", userItem.coin);
- if (userItem.uid == theGlobalUserInfo.uid) {
- this.updateMyScore(userItem.coin);
- }
- }
- //状态变化
- onEventUserStatus(viewChairID: number, userItem: qp.IUserItem) {
- cc.log("onEventUserStatus");
- }
- }
|