From 866b768e96b07f67e4068e4040f9393049825b16 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Fri, 3 Nov 2023 09:45:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=B6=E9=97=B4=E9=87=8C=E8=AE=A1=E6=97=B6?= =?UTF-8?q?=E5=99=A8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/entertainment/room.go | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/modules/entertainment/room.go b/modules/entertainment/room.go index 686b86f5b..d2e94315d 100644 --- a/modules/entertainment/room.go +++ b/modules/entertainment/room.go @@ -40,7 +40,9 @@ type Room struct { func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) { fmt.Printf("超时+++++%d\n", time.Now().Unix()) - + if this.operatetimer != nil { + this.operatetimer = nil + } if this.player1.Userinfo.Uid == this.curPower { // 给玩家2 this.NexPower = this.player2.Userinfo.Uid this.player2.Ps = MaxPs // 恢复体力 @@ -83,10 +85,6 @@ func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) { // 二号玩家是机器人 if len(this.szSession) == 1 { this.AiOperator() - } else { - // if this.operatetimer != nil { - // this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut) // 开启新的定时器 - // } } } @@ -156,10 +154,6 @@ func (this *Room) AiOperator() { this.NexPower = this.player1.Userinfo.Uid this.player1.Ps = MaxPs this.round++ - if this.operatetimer != nil { // 开启新的定时器 - timewheel.Remove(this.operatetimer) - } - //this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut) } // 校验下次是不是消除 if !this.chessboard.CheckAndRefreshPlat() { @@ -418,12 +412,12 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr } return } - if this.operatetimer != nil { - timewheel.Remove(this.operatetimer) - this.operatetimer = nil - } - if this.curPower != this.NexPower && len(this.szSession) > 1 { - //this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut) // 开启新的定时器 + + if this.curPower != this.NexPower { // 下一次操作不是自己 清除定时器 + if this.operatetimer != nil { + timewheel.Remove(this.operatetimer) + this.operatetimer = nil + } } // 变更权限 this.curPower = this.NexPower @@ -486,7 +480,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr this.module.Errorln(err) } // 游戏开始开启一个定时器 - this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut) + //this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut) } case "reconnect": // 重连 @@ -529,8 +523,10 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr case "operatorover": // 操作完成 开启一个定时器 if this.operatetimer != nil { timewheel.Remove(this.operatetimer) - this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut) + this.operatetimer = nil } + this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut) + if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "startimer", &pb.EntertainStarTimerPush{ Time: this.MaxTime, }, this.szSession...); err != nil { @@ -554,6 +550,7 @@ func (this *Room) GameOver() (errdata *pb.ErrorData) { ) if this.operatetimer != nil { timewheel.Remove(this.operatetimer) + this.operatetimer = nil } winner = this.player1 bReward = true