时间里计时器处理

This commit is contained in:
meixiongfeng 2023-11-03 09:45:08 +08:00
parent aff72fa398
commit 866b768e96

View File

@ -40,7 +40,9 @@ type Room struct {
func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) { func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) {
fmt.Printf("超时+++++%d\n", time.Now().Unix()) fmt.Printf("超时+++++%d\n", time.Now().Unix())
if this.operatetimer != nil {
this.operatetimer = nil
}
if this.player1.Userinfo.Uid == this.curPower { // 给玩家2 if this.player1.Userinfo.Uid == this.curPower { // 给玩家2
this.NexPower = this.player2.Userinfo.Uid this.NexPower = this.player2.Userinfo.Uid
this.player2.Ps = MaxPs // 恢复体力 this.player2.Ps = MaxPs // 恢复体力
@ -83,10 +85,6 @@ func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) {
// 二号玩家是机器人 // 二号玩家是机器人
if len(this.szSession) == 1 { if len(this.szSession) == 1 {
this.AiOperator() 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.NexPower = this.player1.Userinfo.Uid
this.player1.Ps = MaxPs this.player1.Ps = MaxPs
this.round++ 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() { if !this.chessboard.CheckAndRefreshPlat() {
@ -418,12 +412,12 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
} }
return return
} }
if this.curPower != this.NexPower { // 下一次操作不是自己 清除定时器
if this.operatetimer != nil { if this.operatetimer != nil {
timewheel.Remove(this.operatetimer) timewheel.Remove(this.operatetimer)
this.operatetimer = nil this.operatetimer = nil
} }
if this.curPower != this.NexPower && len(this.szSession) > 1 {
//this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut) // 开启新的定时器
} }
// 变更权限 // 变更权限
this.curPower = this.NexPower this.curPower = this.NexPower
@ -486,7 +480,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
this.module.Errorln(err) 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": // 重连 case "reconnect": // 重连
@ -529,8 +523,10 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
case "operatorover": // 操作完成 开启一个定时器 case "operatorover": // 操作完成 开启一个定时器
if this.operatetimer != nil { if this.operatetimer != nil {
timewheel.Remove(this.operatetimer) 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{ if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "startimer", &pb.EntertainStarTimerPush{
Time: this.MaxTime, Time: this.MaxTime,
}, this.szSession...); err != nil { }, this.szSession...); err != nil {
@ -554,6 +550,7 @@ func (this *Room) GameOver() (errdata *pb.ErrorData) {
) )
if this.operatetimer != nil { if this.operatetimer != nil {
timewheel.Remove(this.operatetimer) timewheel.Remove(this.operatetimer)
this.operatetimer = nil
} }
winner = this.player1 winner = this.player1
bReward = true bReward = true