import { _decorator, Component, Node, Label, geometry, find, Camera, PhysicsSystem, instantiate, Vec3, Button, debug } from 'cc'; import { clientEvent } from '../../framework/clientEvent'; import { playerData } from '../../framework/playerData'; import { uiManager } from '../../framework/uiManager'; import { gameConstants } from '../../game/gameConstants'; import * as i18n from '../../../../extensions/i18n/assets/LanguageData' import { AudioManager } from '../../framework/audioManager'; import { gameManager } from '../../game/gameManager'; import { HttpHelp } from '../../game/HttpHelp'; import { ResponseBase } from '../../game/pack/ResponseBase'; import { CoinFlipVo } from '../../game/pack/CoinsBatchAwardVo'; import { util } from '../../framework/util'; import { GetGoodPanel } from './GetGoodPanel'; import { GetAwardVo } from '../../game/pack/GetAwardVo'; const { ccclass, property } = _decorator; @ccclass('GamePanel') export class GamePanel extends Component { @property(Label) lbCountdownTime: Label = null!; //倒计时显示 @property(Button) btnTuiBi: Button = null!; @property(GetGoodPanel) goodsPanel:GetGoodPanel = null!; @property(Node) TimeOverPanel:Node = null!; private _countdownTime: number = 0; //倒计时 private _checkCanClick: Boolean = true; //可点击生成金币 private _checkCanClickTime: number = 0; //可点击时间间隔计算 private _time: number=0;//刷新闹钟时间间隔 static Instance: GamePanel; onEnable() { // this.node.on(Node.EventType.TOUCH_START, this._onTouchStart, this); } onDisable() { // this.node.off(Node.EventType.TOUCH_START, this._onTouchStart, this); } onLoad() { // this._comCamera = find('Main Camera')?.getComponent(Camera)!; GamePanel.Instance=this; } // private _onTouchStart(e: any) { // if (!this._checkCanClick) return; // //若显示新手引导 隐藏 // if (this._isFirstClick) { // this._isFirstClick = false; // clientEvent.dispatchEvent(gameConstants.EVENT_LIST.TOUCH_HIDE_TOUCHPLANE, false); // } // if (this._getPlayerGold() > 0) { // // const outRay = new geometry.Ray(); // // const touchPoint = e.touch._point; // // this._comCamera.screenPointToRay(touchPoint.x, touchPoint.y, outRay); // // if (PhysicsSystem.instance.raycast(outRay, gameConstants.GROUP_MASK_LIST.PUSH_TOUCH), 50) { // // //点击到推动台的位置 永远只会有一个 // // if (PhysicsSystem.instance.raycastResults.length <= 0) return; // // const hitPoint = PhysicsSystem.instance.raycastResults[0].hitPoint; // // this.createCoin(hitPoint); // // } // } else { // uiManager.instance.showTips(i18n.t('gamePanel.shortGold')); // } // } private createCoin(hitPoint: any) { this._checkCanClick = false; this._checkCanClickTime = 0; if (gameManager.Instance.golabMemory.Chagnci?.cost) { playerData.instance.updatePlayerInfo('gold', 0 - gameManager.Instance.golabMemory.Chagnci?.cost); } clientEvent.dispatchEvent(gameConstants.EVENT_LIST.GOLD_SHOW_UPDATE); clientEvent.dispatchEvent(gameConstants.EVENT_LIST.TOUCH_CREATE_GOLD, true, new Vec3(hitPoint.x, hitPoint.y, hitPoint.z - Math.random() * gameConstants.PUSH_RANGE_Z), new Vec3(0, 0, 0));//randomEul(), randomEul(), randomEul() } show() { clientEvent.dispatchEvent(gameConstants.EVENT_LIST.TOUCH_HIDE_TOUCHPLANE, true); if(gameManager.Instance.golabMemory.Chagnci?.endTime){ const newEndTime = gameManager.Instance.golabMemory.Chagnci?.endTime.replace(/-/g, '/') const enTime:number = Date.parse(newEndTime); const xx=(enTime-Date.now()) / 1000; if(xx<=0){ console.error("caonima:",xx); } console.log("time:", util.formatDate(new Date(),"yyyy-MM-dd hh:mm:ss")); this._countdownTime =xx; this._updateTime(); } // //存在离线时间 // if (playerData.instance.settings.hideTime) { // const subTime = Date.now() - playerData.instance.settings.hideTime; // const hour = Math.floor(subTime / 1000 / 60); // let addGold; // if (hour >= gameConstants.OFFLINE_MAX_GOLD * (gameConstants.OFFLINE_ADD_GOLD_TIME / 60)) { // //大于等于最大上限时间 // addGold = gameConstants.OFFLINE_MAX_GOLD; // } else { // addGold = Math.floor(hour / (gameConstants.OFFLINE_ADD_GOLD_TIME / 60)); // } // if (addGold > 0) { // uiManager.instance.showDialog(gameConstants.PANEL_PATH_LIST.OFFLINEREWARD, [addGold]); // } // } } /** * 获取玩家金币数量 */ private _getPlayerGold() { return playerData.instance.playerInfo['gold']; } /** * 更新时间显示 */ private _updateTime() { if(this._countdownTime<=0){ console.log("游戏结束"); this.TimeOverPanel.active=true; return; } this.lbCountdownTime.string=util.formatTimeForSecond(this._countdownTime); } public onBtnSetting() { AudioManager.instance.playSound(gameConstants.SOUND_NAME_LIST.CLICK); uiManager.instance.showDialog(gameConstants.PANEL_PATH_LIST.SETTING); } public onBtnVideoGetGold() { // AudioManager.instance.playSound(gameConstants.SOUND_NAME_LIST.COUNTDOWNGETGOLD); // gameManager.scriptsBondsdk.showRewardVideo(() => { // AudioManager.instance.playSound(gameConstants.SOUND_NAME_LIST.VIDEOGETGOLD); // playerData.instance.updatePlayerInfo('gold', gameConstants.GAMEPANEL_VIDEO_GET_GOLD); // clientEvent.dispatchEvent(gameConstants.EVENT_LIST.GOLD_SHOW_UPDATE); // }); } update(dt: number) { if(this._countdownTime>0){ this._countdownTime -= dt; this._time+=dt; if(this._time>=1||this._countdownTime<=0){ this._time=0; this._updateTime(); } } if (this._checkCanClick) return; this._checkCanClickTime += dt; if (this._checkCanClickTime >= gameConstants.GAMEPANEL_CAN_CLICK_INTERVAL) { this._checkCanClick = true; } } /** * 创建金币 */ public onCreatJinbi() { if (!this._checkCanClick) return; console.log("创建一个金币"); if (this._getPlayerGold() > 0) { this.HttpSendGold(); this.createCoin(new Vec3(-0.22, 1.33, -7.23)); this.btnTuiBi.interactable = false; } else { uiManager.instance.showTips(i18n.t('gamePanel.shortGold')); } } /** * 请求投币 */ HttpSendGold() { let url = "coins/manage/coinFlip"; HttpHelp.httpPost(url, null, this.HttpSendGoldBack, gameManager.Instance.golabMemory.Token, this); } HttpSendGoldBack(data: any) { try { if(data==-1){ // this.btnTuiBi.interactable = false; uiManager.instance.showTips('网络异常,请重新加载!'); // this.btnTuiBi.interactable = true; return; } // console.log('HttpSendGoldBack: ',data); var obj: ResponseBase = JSON.parse(data); if (obj.code != 1) { console.error("获取服务器信息出错", data); uiManager.instance.showTips('网络异常,请重新加载!'); // this.btnTuiBi.interactable = true; return; } let coin: CoinFlipVo = obj.data; if (!coin) { console.error("推币返回的数据有误", obj); return; } playerData.instance.setPlayMoney(coin.gameCurrcy); clientEvent.dispatchEvent(gameConstants.EVENT_LIST.GOLD_SHOW_UPDATE); if (coin.awardList && coin.awardList.length > 0) { let len=coin.awardList.length; if(len>gameConstants.MaxAwardCount){ len=gameConstants.MaxAwardCount; } for (let i = 0; i < len; i++) { let key = coin.awardList[i].uuid; if (!key) continue; gameManager.Instance._createPresent(coin.awardList[i]); //创建一个礼物 gameManager.Instance.golabMemory.AwardInfos?.set(key, coin.awardList[i]); } } this.btnTuiBi.interactable = true; } catch (errorx) { console.error("投币回包err:",errorx); this.btnTuiBi.interactable = true; } } /** * 创建礼物 */ public onCreateLiwu() { console.log("创建一个礼物 "); gameManager.Instance._createPresent(); //创建一个礼物 } public SetGoodsData(data:GetAwardVo){ if(!data){ console.error("打开领取界面数据有误,cao",data); return; } this.goodsPanel.node.active=true; this.goodsPanel.SetData(data); } public btnReLoad(){ window.location.reload(); } public btnZhongJiang(){ if(gameManager.Instance.golabMemory.isReplse){ window.location.href = "http://star.mstardance.com/starmini/winRecord.html"; }else{ window.location.href = "http://teststar.mstardance.com/starmini/winRecord.html"; } } public btnZhuanYouxiBi(){ if(gameManager.Instance.golabMemory.isReplse){ window.location.href = "http://star.mstardance.com/starmini/mall.html"; }else{ window.location.href = "http://teststar.mstardance.com/starmini/mall.html"; } } }