You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
829 lines
30 KiB
829 lines
30 KiB
import { _decorator,Component, Node, Sprite, Vec3, instantiate, Button, sp, Tween, tween, Label, RichText, UITransform } from "cc";
|
|
import { Game20006Proxy } from "../proxy/Game20006Proxy";
|
|
import { AudioManager, GameUtils, I18Manager, Message, Sleep, SocketConst, UILayerIndex } from "../sdk/API";
|
|
import { UserData } from "../sdk/GameVO";
|
|
import { Game20006Res } from "./Game20006Res";
|
|
import { GameStatus } from "../proxy/Game20006Const";
|
|
import { GameTimeComp } from "../comp/GameTimeComp";
|
|
import { GameOptSubItemComp } from "../comp/sub/GameOptSubItemComp";
|
|
import { Game20006TimeTool } from "../units/Game20006TimeTool";
|
|
import { StartBet } from "../comp/bet/StartBet";
|
|
import { EndBet } from "../comp/bet/EndBet";
|
|
import { GoldFlyComp } from "../efct/GoldFlyComp";
|
|
import { GameRoleShowList } from "../comp/GameRoleShowList";
|
|
import { GameRecordPanel } from "../comp/recod/GameRecordPanel";
|
|
import { GameMenu } from "../comp/menu/GameMenu";
|
|
import { PlayerHeadInfoComp } from "../comp/PlayerHeadInfoComp";
|
|
import { Game20006RulePanelComp } from "../comp/rule/Game20006RulePanelComp";
|
|
import { GameSettingComp } from "../comp/setting/GameSettingComp";
|
|
import { GameObject } from "./GameObject";
|
|
import { SoundConst } from "../Game2006Const";
|
|
import { ReadyStart } from "../comp/bet/ReadyStart";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('GameController')
|
|
export class GameController extends Component{
|
|
private static _ins:GameController;
|
|
static getInstance():GameController{
|
|
// if(GameController._ins==null)GameController._ins=new GameController()
|
|
return GameController._ins
|
|
}
|
|
@property({type:Node})
|
|
goldPrefab:Node
|
|
|
|
@property({type:StartBet})
|
|
startBet:StartBet
|
|
@property({type:EndBet})
|
|
stopBet:EndBet
|
|
@property({type:ReadyStart})
|
|
readyStart:ReadyStart
|
|
@property({type:GameRecordPanel})
|
|
gameRecord:GameRecordPanel
|
|
|
|
@property({type:GameMenu})
|
|
menu:GameMenu
|
|
|
|
@property({type:Game20006RulePanelComp})
|
|
rule:Game20006RulePanelComp
|
|
|
|
@property({type:sp.Skeleton})
|
|
dice:sp.Skeleton
|
|
|
|
@property({type:GameSettingComp})
|
|
setting:GameSettingComp
|
|
|
|
@property({type:Node})
|
|
winNode:Node
|
|
|
|
|
|
private diceInfo:any={}//骰子信息
|
|
protected __preload(): void {
|
|
GameController._ins=this
|
|
this.init()
|
|
}
|
|
protected onLoad(): void {
|
|
if(this.startBet && this.startBet.isValid)this.startBet.show(false)
|
|
if(this.stopBet && this.stopBet.isValid)this.stopBet.show(false)
|
|
}
|
|
|
|
start(){
|
|
GameObject.getInstance().addObjToPool("gameGold",this.goldPrefab)
|
|
GameObject.getInstance().addObjToPool("winNode",this.winNode)
|
|
Message.add("Game_Authority_Success", this.Reconnect, this)
|
|
Message.add(SocketConst.CONNECTED,this.Reconnect, this)
|
|
this.showRecord(false)
|
|
this.showMenu(false)
|
|
|
|
|
|
if(this.dice && this.dice.isValid){
|
|
this.diceInfo={
|
|
position:this.dice.node.position,
|
|
scale:this.dice.node.scale
|
|
}
|
|
}
|
|
|
|
if(this.winNode && this.winNode.isValid){
|
|
this.winNode.active=false
|
|
}
|
|
|
|
|
|
}
|
|
protected onDestroy(): void {
|
|
if(this.proxy){
|
|
this.proxy.destroy()
|
|
}
|
|
this.removeMsg()
|
|
GameObject.getInstance().clear()
|
|
}
|
|
isRecoveryData:boolean=false
|
|
private _isInit:boolean=false
|
|
Reconnect(){
|
|
if(this._isInit){
|
|
this.isRecoveryData=true
|
|
}
|
|
this._isInit=true
|
|
this.playBetAreaHighlightEfctHide()
|
|
if(!this.proxy){
|
|
this.proxy=new Game20006Proxy()
|
|
}
|
|
this.proxy.sendEnterGameRequest(null)
|
|
this.clear()
|
|
}
|
|
|
|
|
|
private goldIndex:number=0;//选中下注金币item
|
|
|
|
proxy:Game20006Proxy
|
|
clock:GameTimeComp
|
|
/** 显示管理玩家组件 */
|
|
gameShow:GameRoleShowList
|
|
|
|
roomConfig:any;//房间配置
|
|
public chipsList:any[]
|
|
private _goldTableList:any={};
|
|
private _playerStagelist:any[];//上榜列表
|
|
private _betAreaList:GameOptSubItemComp[];//下注区域
|
|
private _recordPlayerOpt:any[];//记录玩家操作
|
|
private _tempOptData:any[];
|
|
|
|
private _gameOverData:any//游戏结算数据
|
|
public gameOverData():any{
|
|
return this._gameOverData
|
|
}
|
|
private _winBetAraelist:GameOptSubItemComp[]=[]
|
|
|
|
private _playerData:any;//初始玩家数据
|
|
/**
|
|
* 游戏房间状态
|
|
* 1 // 开始下注
|
|
* 2 // 下注结束
|
|
* 3 // 结算
|
|
*/
|
|
roomStatus:GameStatus
|
|
/** 玩家数据 */
|
|
roomData:any
|
|
/** 游戏记录数据 */
|
|
recordData:any[]
|
|
/** 桌子区域配置数据 */
|
|
areaAmount:any[]
|
|
/** 玩家UID */
|
|
mineUid:number=0;
|
|
|
|
/**当前是否下过注 */
|
|
public isCurrBet:boolean = false;
|
|
|
|
/** 添加玩家操作记录 */
|
|
addPlayerOpt(opt:any){
|
|
if(!this._recordPlayerOpt)this._recordPlayerOpt=[]
|
|
this._recordPlayerOpt=opt
|
|
}
|
|
/**下注错误时清理错误信息 */
|
|
clearPlayerOpt(){
|
|
if(!this._recordPlayerOpt || this._recordPlayerOpt.length <= 0) return;
|
|
this._recordPlayerOpt.pop();
|
|
}
|
|
getPlayerOptData():any[]{
|
|
if(this._recordPlayerOpt && this._recordPlayerOpt?.length <=0)return this._tempOptData || []
|
|
return this._recordPlayerOpt || []
|
|
}
|
|
getPlayerOptItem(betArea:number):any{
|
|
let opts:any[]=this.getPlayerOptData()
|
|
for(let i=0;i<opts?.length;i++){
|
|
if(opts[i].betArea == betArea){
|
|
return opts[i]
|
|
}
|
|
}
|
|
return null
|
|
}
|
|
private isBet:boolean=false
|
|
//重复下注操作
|
|
rebet(){
|
|
if(this.isBet){
|
|
this.showToast(Game20006Res.getInstance().getString("game.repeated.bet"))
|
|
return
|
|
}
|
|
|
|
let opts:any[]=this.getPlayerOptData()
|
|
let infos:any[]=[]
|
|
let gold:number=0
|
|
for(let i=0;i<opts?.length;i++){
|
|
gold+=opts[i].betAmount
|
|
infos.push({
|
|
betArea:opts[i].betArea,
|
|
betAmount:opts[i].betAmount,
|
|
areaTotalAmount:0
|
|
})
|
|
}
|
|
if(infos?.length <= 0){
|
|
this.showToast(Game20006Res.getInstance().getString("game.last.round"))
|
|
return
|
|
}
|
|
let ugold:number = parseFloat((UserData.gold/1000).toFixed(2))
|
|
gold=parseFloat((gold/1000).toFixed(2))
|
|
if(ugold < gold || ugold < 50){
|
|
const title = Game20006Res.getInstance().getString(`game.tips`);
|
|
let msg = Game20006Res.getInstance().getString(`game.balance`);
|
|
if(ugold < 50){
|
|
msg = Game20006Res.getInstance().getString(`game.balance2`);
|
|
}
|
|
msg=msg.replace("{0}",gold.toString());
|
|
const okName = Game20006Res.getInstance().getString(`game.click.add.cash`);
|
|
const cancelName =Game20006Res.getInstance().getString(`game.click.cancel`);
|
|
|
|
GameController.getInstance().showTips(title,msg,false,cancelName,okName,(isok:boolean)=>{
|
|
if(isok){
|
|
Message.send("OpenModel","shop","res/prefab/shop",false,UILayerIndex.TopLayer);
|
|
}
|
|
})
|
|
return
|
|
}
|
|
if(GameController.getInstance().checkPlayerRoomBetLimit(gold*1000)){
|
|
//房间限红
|
|
GameController.getInstance().showToast(Game20006Res.getInstance().getString("game.room.max"))
|
|
return
|
|
}
|
|
if(GameController.getInstance().checkPlayerBetLimit(gold*1000)){
|
|
//玩家下注限红
|
|
GameController.getInstance().showToast(Game20006Res.getInstance().getString("game.max.betting"))
|
|
return
|
|
}
|
|
if(GameController.getInstance().roomStatus != 2){
|
|
//游戏状态是否在下注阶段
|
|
GameController.getInstance().showToast(Game20006Res.getInstance().getString("game.wait.betting"))
|
|
return
|
|
}
|
|
GameController.getInstance().proxy.sendPlayerBetRequest(infos)
|
|
this.isBet=true
|
|
}
|
|
|
|
/** 将上榜玩家显示出来数据列表 */
|
|
addPlayerInfoToStage(list:any[]){
|
|
this._playerStagelist=[]
|
|
this._playerStagelist = this._playerStagelist.concat(list)
|
|
}
|
|
/**
|
|
* 验证玩家信息是否在上榜数据中
|
|
* @param chairId
|
|
* @returns
|
|
*/
|
|
checkPlayerInStagelist(chairId:number):boolean{
|
|
this._playerStagelist=this._playerStagelist || []
|
|
for(let i=0;i<this._playerStagelist?.length;i++){
|
|
if(this._playerStagelist[i].chairId == chairId){
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
/** 添加下注区域 */
|
|
addBetArea(item:GameOptSubItemComp){
|
|
this._betAreaList.push(item)
|
|
}
|
|
|
|
getBetArea(betArea:number):GameOptSubItemComp{
|
|
this._betAreaList=this._betAreaList || []
|
|
for(let i=0;i<this._betAreaList?.length;i++){
|
|
if(this._betAreaList[i].data?.betArea == betArea){
|
|
return this._betAreaList[i]
|
|
}
|
|
}
|
|
}
|
|
//显示历史记录
|
|
showRecord(status:boolean){
|
|
if(this.gameRecord && this.gameRecord.isValid){
|
|
this.gameRecord.show(status)
|
|
}
|
|
}
|
|
//游戏顶部菜单显示
|
|
showMenu(status:boolean){
|
|
if(this.menu && this.menu.isValid){
|
|
this.menu.onOpen(status)
|
|
}
|
|
}
|
|
//显示规则
|
|
showRule(status:boolean){
|
|
if(this.rule && this.rule.isValid){
|
|
this.rule.show(status)
|
|
}
|
|
}
|
|
//显示设置
|
|
showSetting(){
|
|
if(this.setting && this.setting.isValid){
|
|
this.setting.show()
|
|
}
|
|
}
|
|
/**
|
|
* 显示tips
|
|
* @param msg
|
|
*/
|
|
showToast(msg:string){
|
|
window["Toast"]?.getInstance().showToast(msg);//多语言
|
|
}
|
|
showLoading(status:boolean)
|
|
{
|
|
window["Toast"]?.getInstance().showLoading(status)
|
|
}
|
|
|
|
/**
|
|
* 显示公共提示
|
|
* @param status 提示显示状态
|
|
* @param title 显示标题
|
|
* @param msg 显示类容
|
|
* @param isRichTxt 是否html文本
|
|
* @param cancelName 左按钮上文本 单按钮用
|
|
* @param okName 右按钮上文本
|
|
* @param onClose 关闭回调 false 关闭 true 点击ok 左侧按钮cancelName回调
|
|
* @param onClose 关闭回调 false 关闭 true 点击ok 右侧按钮okName回调
|
|
* @param textEvent 文本回调事件
|
|
*/
|
|
showTips(title:string,msg:string,isRichTxt?:boolean,cancelName?:string,okName?:string,onClose?:(status:boolean)=>void,textEvent?:(label:Label|RichText)=>void){
|
|
window["Toast"]?.getInstance().showTips(title,msg,isRichTxt,cancelName,okName,onClose,textEvent)
|
|
}
|
|
|
|
|
|
init(){
|
|
this._goldTableList={}
|
|
this._playerStagelist=[]
|
|
this._betAreaList=[]
|
|
this._recordPlayerOpt=[]
|
|
this.proxy=new Game20006Proxy()
|
|
|
|
|
|
this.initMsg()
|
|
}
|
|
initMsg(){
|
|
Message.add("GoldOptItem",this.onGoldOptItem,this)//金币操作区 选中item
|
|
|
|
//req
|
|
Message.add("GetRoomInfos",this.onGetRoomInfos,this)
|
|
|
|
}
|
|
removeMsg(){
|
|
Message.remove("GoldOptItem",this.onGoldOptItem,this)//金币操作区 选中item
|
|
//req
|
|
Message.remove("GetRoomInfos",this.onGetRoomInfos,this)
|
|
Message.remove("Game_Authority_Success", this.Reconnect, this)
|
|
Message.remove(SocketConst.CONNECTED,this.Reconnect, this)
|
|
|
|
}
|
|
clear(){
|
|
this.removeAllStage()
|
|
this.playBetAreaHighlightEfctHide()
|
|
this.resetGameTableData()
|
|
this._gameOverData=null
|
|
GameObject.getInstance().hideGroup("gameGold")
|
|
if(this.gameShow && this.gameShow.isValid){
|
|
this.gameShow.clearChildren()
|
|
this.gameShow.clear()
|
|
}
|
|
if(this.dice && this.dice.isValid && this.dice.node){
|
|
this.dice.node.position=new Vec3(360,260,0)
|
|
this.dice.node.scale=new Vec3(0.2,0.2,0.2)
|
|
}
|
|
}
|
|
getGoldScale():Vec3{
|
|
return new Vec3(0.25,0.25,0.25)
|
|
}
|
|
|
|
/** 将金币添加到桌子中 */
|
|
addGoldToStage(araeId:number,gold:Node){
|
|
let list:any[] = this._goldTableList[araeId]
|
|
if(!list){
|
|
list=[]
|
|
this._goldTableList[araeId]=list
|
|
}
|
|
list.push(gold)
|
|
}
|
|
/** 将金币从桌子中删除 */
|
|
removeAllStage(){
|
|
let remove = async ()=>{
|
|
for(let key in this._goldTableList){
|
|
let list:any[]= this._goldTableList[key] || []
|
|
while(list?.length > 0){
|
|
// await Sleep(0.01)
|
|
let gold:Node=list.shift();
|
|
// if(gold && gold.isValid){
|
|
// gold.destroy()
|
|
// }
|
|
GameObject.getInstance().pushObj(gold)
|
|
}
|
|
}
|
|
this._goldTableList={}
|
|
}
|
|
remove()
|
|
}
|
|
/** 获取当前下注金额 */
|
|
getCurBetVal():number{
|
|
return parseFloat((this.getCurBetValue() / 1000).toFixed(2))
|
|
}
|
|
getCurBetValue():number{
|
|
return this.chipsList[this.goldIndex]
|
|
}
|
|
/** 克隆一个金币副本 */
|
|
cloneGold(betType?:number,isButton?:boolean):Node{
|
|
if(!isButton)isButton=false
|
|
if(!betType)betType=this.chipsList[this.goldIndex]
|
|
let newGold:Node=GameObject.getInstance().getObj("gameGold")
|
|
if(newGold && newGold.isValid){
|
|
newGold.active=true
|
|
newGold.position=Vec3.ZERO
|
|
newGold.worldPosition=Vec3.ZERO
|
|
let sp:Sprite =newGold.getComponent(Sprite)
|
|
if(sp && sp.isValid){
|
|
sp.spriteFrame=Game20006Res.getInstance().getChipSpriteFrame(betType.toString())
|
|
}
|
|
|
|
newGold.getComponent(Button).enabled=isButton
|
|
|
|
}
|
|
|
|
return newGold
|
|
}
|
|
getChipNumByTotal(total:number):any[]{
|
|
let chip:any[]=[]
|
|
this.chipsList=this.chipsList || []
|
|
for(let i=this.chipsList?.length-1;i > 0;i--){
|
|
let num:number = Math.floor(total / this.chipsList[i])
|
|
if(num > 0){
|
|
total -=num*this.chipsList[i]
|
|
chip.push({
|
|
value:this.chipsList[i],
|
|
num:num
|
|
})
|
|
if(total == 0)break
|
|
}
|
|
}
|
|
return chip
|
|
}
|
|
//是否正在结算
|
|
isGameOverRes:boolean=false
|
|
//结算消息回调
|
|
onNotifySettlementRes(val:any){
|
|
if(this.isGameOverRes)return
|
|
this.isGameOverRes=true
|
|
this.roomStatus = val.gameState
|
|
this._gameOverData=val
|
|
this.recordData=Object.assign([],val.record)
|
|
// let resultNum:number[]=val.resultNum
|
|
// let WinArea:number[]=val.winArea
|
|
this.playGameOverAction()
|
|
}
|
|
//播放结束动画
|
|
private playGameOverAction(){
|
|
let resultNum:number[]=this._gameOverData.resultNum || []
|
|
let windAnim:string="animation_"+resultNum[0].toString()+resultNum[1].toString()
|
|
if(this.dice && this.dice.isValid){
|
|
let moveTween:Tween<Node>=tween(this.dice.node)
|
|
.delay(2)
|
|
.to(0.3,{position:new Vec3(0,-30,0),scale:new Vec3(0.8,0.8,0.8)},{
|
|
onComplete:()=>{
|
|
moveTween.stop()
|
|
AudioManager.getInstance().playEffect(SoundConst.Dice)
|
|
this.dice.setAnimation(0,windAnim,false)
|
|
this.dice.setCompleteListener(this.diceMoveToOld.bind(this))
|
|
let atid=setTimeout(()=>{
|
|
clearTimeout(atid)
|
|
atid=null
|
|
AudioManager.getInstance().stopSound(SoundConst.Dice)
|
|
},1000)
|
|
}
|
|
}).start()
|
|
}
|
|
}
|
|
private diceMoveToOld(){
|
|
this.gameShow.clear()//在播筛子动画,停止播放吐金币效果
|
|
AudioManager.getInstance().stopSound(SoundConst.Dice)
|
|
let moveTween:Tween<Node>=tween(this.dice.node)
|
|
.delay(1.5)
|
|
.to(0.3,{position:new Vec3(360,260,0),scale:new Vec3(0.2,0.2,0.2)},{
|
|
onComplete:()=>{
|
|
moveTween.stop()
|
|
this.gameOverStatusComplete()
|
|
}
|
|
}).start()
|
|
}
|
|
//游戏结算状态显示显示完成
|
|
private gameOverStatusComplete(){
|
|
if(this._gameOverData){
|
|
|
|
this.playBetAreaHighlightEfct()
|
|
this.calculateFailToWin();
|
|
|
|
Message.send("ShowGameRecord",this.recordData)//刷新历史记录
|
|
}
|
|
}
|
|
private winList:Node[]=[]
|
|
//显示下注区域高亮
|
|
private playBetAreaHighlightEfct(){
|
|
if(!this.node || !this.node.isValid)return
|
|
let winArea:number[]=this._gameOverData.winArea || []
|
|
for(let i=0;i<winArea?.length;i++){
|
|
let area:GameOptSubItemComp=this.getBetArea(winArea[i])
|
|
if(area){
|
|
area.flicker()
|
|
this._winBetAraelist.push(area)
|
|
//显示胜利效果
|
|
let win:Node=GameObject.getInstance().getObj("winNode")
|
|
win.position=Vec3.ZERO
|
|
win.active=true
|
|
win.scale=new Vec3(0.8,0.8,0.8)
|
|
|
|
let uitf:UITransform = this.node.getComponent(UITransform)
|
|
let pos:Vec3 = uitf.convertToNodeSpaceAR(area.node.worldPosition)
|
|
win.worldPosition=pos
|
|
this.node.addChild(win)
|
|
win.setSiblingIndex(2)
|
|
this.winList.push(win)
|
|
}
|
|
console.log("开奖区域 》》》》》",winArea[i])
|
|
}
|
|
}
|
|
//隐藏下注区域高亮
|
|
private playBetAreaHighlightEfctHide(){
|
|
this._betAreaList=this._betAreaList || []
|
|
for(let i=0;i<this._betAreaList?.length;i++){
|
|
let area:GameOptSubItemComp=this._betAreaList[i]
|
|
if(area){
|
|
area.stopFlicker()
|
|
}
|
|
}
|
|
|
|
while(this.winList && this.winList.length > 0){
|
|
let itemNode:Node=this.winList.shift()
|
|
if(itemNode && itemNode.isValid){
|
|
GameObject.getInstance().pushObj(itemNode)
|
|
}
|
|
}
|
|
}
|
|
//计算失败的金币飞向胜利的区域
|
|
private calculateFailToWin(){
|
|
let WinArea:number[]=this._gameOverData.winArea
|
|
|
|
let failData:any={}//失败数据
|
|
for(let key in this._goldTableList){
|
|
if(WinArea.indexOf(parseInt(key)) >= 0){
|
|
continue
|
|
}
|
|
failData[key] = this._goldTableList[key]
|
|
}
|
|
let totalWeight:number=0
|
|
this._winBetAraelist=this._winBetAraelist || []
|
|
for(let i=0;i<this._winBetAraelist?.length;i++){
|
|
let area:GameOptSubItemComp=this._winBetAraelist[i]
|
|
totalWeight +=Math.round(area.data.areaPro)
|
|
}
|
|
let owner = this
|
|
let getOptItemByWeight=function(weight:number):GameOptSubItemComp{
|
|
let weightVal:number=0
|
|
for(let k:number=0;k<owner._winBetAraelist?.length;k++){
|
|
weightVal +=Math.round(owner._winBetAraelist[k].data.areaPro)
|
|
if(weight <= weightVal){
|
|
return owner._winBetAraelist[k]
|
|
}
|
|
}
|
|
return null
|
|
}
|
|
//计算金币飞到胜利区域
|
|
for(let key in failData){
|
|
let list:Node[] = failData[key] || []
|
|
for(let i=0;i<list?.length;i++){
|
|
let itemNode:Node=list[i]
|
|
let weight:number=GameUtils.randomRange(0,totalWeight)
|
|
let winArea:GameOptSubItemComp = getOptItemByWeight(weight)
|
|
if(winArea){
|
|
let fly:GoldFlyComp = itemNode.getComponent(GoldFlyComp)
|
|
if(!fly)fly=itemNode.addComponent(GoldFlyComp);
|
|
fly.fly(0.3,winArea.getWorldPos())
|
|
}
|
|
}
|
|
}
|
|
|
|
//查找的赢玩家总金额
|
|
let playerList:any[]=Object.assign([],this._gameOverData.playList) || []
|
|
let winPlayerList:any={}
|
|
let failList:any={}
|
|
let userGold:number=0
|
|
for(let i=0;i<playerList?.length;i++){
|
|
let winScore:number = (playerList[i].winScore - playerList[i].betScore)
|
|
let targetNode:Node=null
|
|
if(this.mineUid == playerList[i].uid){
|
|
targetNode=this.gameShow.player.node
|
|
userGold=playerList[i].gold
|
|
}else{
|
|
targetNode=this.gameShow.getPlayerNode(playerList[i].chairId)
|
|
}
|
|
if(winScore > 0){
|
|
winPlayerList[playerList[i].chairId]={
|
|
winScore:winScore,
|
|
node:targetNode,
|
|
tableWin:playerList[i].winScore,
|
|
gold:playerList[i].gold
|
|
}
|
|
}else{
|
|
if(targetNode && targetNode.isValid){
|
|
failList[playerList[i].chairId]={
|
|
winScore:winScore,
|
|
node:targetNode,
|
|
chairId:playerList[i].chairId,
|
|
gold:playerList[i].gold
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
let resCallback = async ()=>{
|
|
await Sleep(1000)
|
|
this.chipsList=this.chipsList || []
|
|
for(let key in winPlayerList){
|
|
let itemInfo:any=winPlayerList[key]
|
|
let info:PlayerHeadInfoComp = itemInfo.node.getComponent(PlayerHeadInfoComp)
|
|
let count:number = 10//GameUtils.randomRange(20,20)
|
|
if(info && info.isPlayer)info.playWinSound()
|
|
for(let i=0;i<count;i++){
|
|
let cindex:number=GameUtils.randomRange(0,this.chipsList?.length)
|
|
let item_prefab:Node = GameController.getInstance().cloneGold(this.chipsList[cindex],true)
|
|
item_prefab.scale=new Vec3(0.25,0.25,0.25)
|
|
if(itemInfo.node && item_prefab)itemInfo.node.addChild(item_prefab)
|
|
let weight:number=GameUtils.randomRange(0,totalWeight)
|
|
let winArea:GameOptSubItemComp = getOptItemByWeight(weight)
|
|
if(winArea){
|
|
item_prefab.worldPosition=winArea.getWorldPos()
|
|
let fly:GoldFlyComp = item_prefab.getComponent(GoldFlyComp)
|
|
if(!fly)fly=item_prefab.addComponent(GoldFlyComp);
|
|
fly.fly(0.3,itemInfo.node.worldPosition,null)
|
|
}
|
|
await Sleep(0.001)
|
|
}
|
|
if(info){
|
|
info.flyLab(itemInfo.winScore,0.6,true)
|
|
if(info.isPlayer)info.changedGold(itemInfo.gold)
|
|
else info.changedGold(itemInfo.tableWin)
|
|
}
|
|
}
|
|
for(let key in failList){
|
|
let itemInfo:any=failList[key]
|
|
let info:PlayerHeadInfoComp = itemInfo?.node?.getComponent(PlayerHeadInfoComp)
|
|
if(info && itemInfo.winScore != 0){
|
|
info.flyLab(itemInfo.winScore,1,false)
|
|
}
|
|
}
|
|
await Sleep(500)
|
|
this.removeAllStage()
|
|
this.playBetAreaHighlightEfctHide()
|
|
this.resetPlayerBetScore();
|
|
this.resetGameTableData()
|
|
GameObject.getInstance().hideGroup("gameGold")
|
|
if(userGold > 0){
|
|
Message.send("gameAddGold",userGold)
|
|
}
|
|
await Sleep(1000)
|
|
this.clear()
|
|
}
|
|
resCallback()
|
|
|
|
}
|
|
|
|
onNextStateTime(val:any){
|
|
this.roomStatus = val.nextState
|
|
let nextTime:number=val.nextTimestamp
|
|
switch(this.roomStatus){
|
|
case GameStatus.START_BET://准备下注
|
|
this.clear()
|
|
Message.send("StopTime")
|
|
this.isBet=false
|
|
this.isGameOverRes=false
|
|
this.isCurrBet = false;
|
|
// Game20006TimeTool.setServerTime(nextTime)
|
|
this.readyStart.startShow(nextTime);
|
|
break
|
|
case GameStatus.END_BET://开始下注
|
|
this.readyStart.show(false);
|
|
if(this.startBet && this.startBet.isValid)this.startBet.startShow()
|
|
Message.send("StatusChangeNextTimestamp",nextTime)
|
|
break
|
|
case GameStatus.SETTLEMENT://结算
|
|
// Game20006TimeTool.setServerTime(nextTime)
|
|
Message.send("ClearCurrentBet")
|
|
if(this.stopBet && this.stopBet.isValid)this.stopBet.startShow()
|
|
break
|
|
}
|
|
}
|
|
/**
|
|
* 获取房间玩家数据
|
|
* @param chairId 不填 默认取玩家数据
|
|
*/
|
|
getRoomPlayer(uid?:number):any{
|
|
let playerList:any[]=this.roomData.playerList || []
|
|
if(!uid)uid=this.roomData.mineUid
|
|
for(let i=0;i<playerList?.length;i++){
|
|
if(playerList[i].uid == uid){
|
|
return playerList[i]
|
|
}
|
|
}
|
|
return null
|
|
}
|
|
/**
|
|
* 玩家下注限红
|
|
* @returns
|
|
*/
|
|
checkPlayerBetLimit(val?:number):boolean{
|
|
let playerLimit:number = this.roomData.roomConfig.playerLimit
|
|
let gold:number = val || this.getCurBetValue()
|
|
if(this._playerData && this._playerData.betScore+gold > playerLimit){
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
/**
|
|
* 检查玩家房间限红
|
|
* @returns
|
|
*/
|
|
checkPlayerRoomBetLimit(val?:number){
|
|
let playerRoomLimit:number = this.roomData.roomConfig.roomLimit
|
|
let gold:number = val || this.getCurBetValue()
|
|
if(this._playerData && this._playerData.betScore+gold > playerRoomLimit){
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
/**
|
|
* 玩家充值限红
|
|
* @param val
|
|
* @returns
|
|
*/
|
|
checkPlayerRechargelimit(val:number):boolean{
|
|
val=val/1000
|
|
let playerLimit:number = this.roomData.roomConfig.rechargeLimit / 1000
|
|
if(val < playerLimit)return true
|
|
return false
|
|
}
|
|
/**
|
|
* 每轮结束后重置玩家当前下注额
|
|
*/
|
|
resetPlayerBetScore(){
|
|
if(this._playerData){
|
|
this._playerData.betScore=0
|
|
}
|
|
}
|
|
/**
|
|
* 设置玩家下注额
|
|
* @param val
|
|
*/
|
|
setPlayerBetScore(val:number){
|
|
if(this._playerData){
|
|
this._playerData.betScore +=val
|
|
}
|
|
}
|
|
|
|
private onGetRoomInfos(val:any){
|
|
this.roomData=val
|
|
this._playerData=this.getRoomPlayer()
|
|
this.mineUid=val.mineUid
|
|
this.resetGameTableData()
|
|
// UserData.roomID=val.roomId
|
|
this.roomStatus=val.roomStatus;//房间状态
|
|
this.recordData=Object.assign([],val.record)
|
|
Message.send("ShowGameRecord",val.record)//开奖历史记录
|
|
//优先对应关系
|
|
const len=val.roomConfig.areaConfig?.length || 0
|
|
for(let i=0;i<len;i++){
|
|
val.roomConfig.areaConfig[i]=Object.assign(val.roomConfig.areaConfig[i],val.areaAmount[i])
|
|
}
|
|
this.initRoomRoleInfo(val.playerList,val.mineUid,val.bigWinner,val.diviner)
|
|
this.initRoom(val.roomConfig,val.areaAmount)
|
|
// Game20006TimeTool.setServerTime(val.serverTimestamp)
|
|
Game20006TimeTool._ServerTimestampDiff(val.serverTimestamp)
|
|
if(this.roomStatus != 2){
|
|
this.readyStart.startShow(val.statusChangeTimestamp);
|
|
Message.send("StatusChangeNextTimestamp",val.serverTimestamp)
|
|
}else{
|
|
Message.send("StatusChangeNextTimestamp",val.statusChangeTimestamp)
|
|
}
|
|
|
|
|
|
}
|
|
|
|
//初始化房间
|
|
private initRoom(config:any,areaAmount:any[]){
|
|
this.roomConfig = config
|
|
this.chipsList=config.chipsList
|
|
|
|
if(config.chipsList)Message.send("initChipsOptAreaInfo",config.chipsList)//初始化筹码列表
|
|
if(config.areaConfig)Message.send("InitGameTableOptAreaInfo",config.areaConfig)//初始化区域配置
|
|
if(areaAmount && areaAmount.length>0)Message.send("InitGameTableOpetAreaData",areaAmount)//初始话区域下注
|
|
|
|
}
|
|
//重置游戏桌子数据
|
|
private resetGameTableData(){
|
|
this._betAreaList=this._betAreaList || []
|
|
for(let i=0;i<this._betAreaList?.length;i++){
|
|
this._betAreaList[i].reset()
|
|
}
|
|
//重置操作记录
|
|
if(this._recordPlayerOpt?.length > 0){
|
|
this._tempOptData=Object.assign([],this._recordPlayerOpt)
|
|
}
|
|
this._recordPlayerOpt=[]
|
|
if(this.gameShow && this.gameShow.isValid){
|
|
this.gameShow.grayscale=this.getPlayerOptData()?.length <= 0
|
|
this.gameShow.clear()
|
|
}
|
|
this._winBetAraelist=[]
|
|
|
|
|
|
if(this._gameOverData){
|
|
let playerList:any[]=Object.assign([],this._gameOverData.playList)
|
|
Message.send("ShowRoomPlayerInfo",playerList,this.mineUid,this._gameOverData.bigWinner,this._gameOverData.diviner,false)//重新刷新桌面玩家信息
|
|
}
|
|
}
|
|
//玩家信息
|
|
private initRoomRoleInfo(playerList:any[],uid:number,bigWinner:number,diviner:number){
|
|
Message.send("ShowRoomPlayerInfo",playerList,uid,bigWinner,diviner,true)
|
|
}
|
|
private onGoldOptItem(index:number){
|
|
this.goldIndex=index
|
|
|
|
}
|
|
}
|