From bd47ab6d74b8c610ff909d934cbae6f9aa1f25d4 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Thu, 30 Nov 2023 14:32:50 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A6=BB=E7=BA=BF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/entertainment/module.go | 4 ++- modules/entertainment/room.go | 56 +++++++++++++++++++++++---------- 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/modules/entertainment/module.go b/modules/entertainment/module.go index b86e27f26..32436b9a9 100644 --- a/modules/entertainment/module.go +++ b/modules/entertainment/module.go @@ -153,6 +153,7 @@ func (this *Entertainment) EventUserOffline(uid, sessionid string) { } } +// 参数1 房间id 参数2 玩家id func (this *Entertainment) useroffline(ctx context.Context, req *pb.RPCGeneralReqA2, resp *pb.RPCGeneralReqA2) (err error) { this.Debugf("user offline :%s,%s", req.Param1, req.Param2) @@ -235,6 +236,7 @@ func (this *Entertainment) CreateRoom(sessions []comm.IUserSession, rulesStr str func (this *Entertainment) UserOffline(roomid string, uid string) (err error) { return } -func (this *Entertainment) AdmitDefeat(sessions []comm.IUserSession, rulesStr string) (roomid string, err error) { + +func (this *Entertainment) AdmitDefeat(roomid string, uid string) (err error) { return } diff --git a/modules/entertainment/room.go b/modules/entertainment/room.go index 595c56f8f..ccb761138 100644 --- a/modules/entertainment/room.go +++ b/modules/entertainment/room.go @@ -38,12 +38,12 @@ type Room struct { RoomType int32 // 房间类型 1 是好友创房 0对战 2 AI 对战 MaxTime int32 // 操作时间 Playtype int32 //当前房间玩法 - + offline string // 谁离线 } func (this *Room) CloseRoomTimeOut(task *timewheel.Task, args ...interface{}) { - fmt.Printf("解散房间超时+++++%d\n", time.Now().Unix()) //倒计时结束还没结束基本是游戏异常 直接清理房间 - this.Status = 2 // 游戏解散 + this.module.Errorf("解散房间超时+++++%d\n", time.Now().Unix()) //倒计时结束还没结束基本是游戏异常 直接清理房间 + this.Status = 2 // 游戏解散 this.ModifyUserRoomInfoData() } @@ -187,7 +187,7 @@ func (this *Room) AiOperator() { this.curPower = this.NexPower if this.RoomType == 2 && this.curPower == this.player2.Userinfo.Uid { //this.AiOperator() - this.AutoOperator(this.player2) + this.AutoOperator(this.curPower) } } @@ -401,6 +401,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr } case "reconnect": // 重连 + this.offline = "" session.SendMsg(string(this.module.GetType()), "reconnect", &pb.EntertainReconnectResp{ Roomid: this.Id, Mpadata: &pb.MapData{ @@ -446,18 +447,20 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr } else if this.player2.Userinfo.Uid == session.GetUserId() { this.rd2 = true } - if this.RoomType == 2 { + if this.RoomType == 2 || this.offline != "" { if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "startimer", &pb.EntertainStarTimerPush{ Time: this.MaxTime, Power: this.curPower, }, this.szSession...); err != nil { this.module.Errorln(err) } - if this.curPower == this.player2.Userinfo.Uid { - //this.AiOperator() - this.AutoOperator(this.player2) + if this.offline != "" && this.curPower == this.offline { + this.AutoOperator(this.offline) // 托管 + } else { + if this.curPower == this.player2.Userinfo.Uid { + this.AutoOperator(this.curPower) + } } - } else { if this.rd1 && this.rd2 { // 两个玩家都准备好了 那么就开始游戏 this.rd1 = false @@ -480,7 +483,18 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr this.ModifyUserRoomInfoData() return } - + if this.offline == "" { + this.offline = req.Param2 + // 如果当前权限是自己开启托管 + if this.curPower == this.offline { + this.AutoOperator(this.offline) + } + } else { + if this.offline != req.Param2 { // 两个都离线 游戏直接结束 + this.Status = 2 // 解散 + this.ModifyUserRoomInfoData() + } + } } return } @@ -666,28 +680,36 @@ func (this *Room) ModifyUserRoomInfoData() { } // 自动操作 -func (this *Room) AutoOperator(p *pb.PlayerData) { +func (this *Room) AutoOperator(uid string) { var ( curScore int32 szMap []*pb.MapData bAddPs bool oid1 int32 oid2 int32 + p *pb.PlayerData ) - + if uid == this.player1.Userinfo.Uid { + p = this.player1 + } else if uid == this.player2.Userinfo.Uid { + p = this.player2 + } else { + this.module.Errorf("cant found user:%s", uid) + return + } // 交换元素 szMap, oid1, oid2, bAddPs = this.chessboard.AiSwapGirde() p.Ps-- - if p.Ps <= 0 { // 权限给下一个人 - this.ChangePower() - this.round++ - } if bAddPs { p.Ps++ if p.Ps > MaxPs { p.Ps = MaxPs } } + if p.Ps <= 0 { // 权限给下一个人 + this.ChangePower() + this.round++ + } // 校验下次是不是消除 if !this.chessboard.CheckAndRefreshPlat() { this.chessboard.RedsetPlatData() @@ -730,7 +752,7 @@ func (this *Room) AutoOperator(p *pb.PlayerData) { } this.curPower = this.NexPower if this.RoomType == 2 && this.curPower == p.Userinfo.Uid { - this.AutoOperator(p) + this.AutoOperator(this.curPower) } }