超时走配置

This commit is contained in:
meixiongfeng 2023-11-01 14:51:02 +08:00
parent 4202883df2
commit 2a633f9256

View File

@ -15,8 +15,6 @@ import (
const ( const (
MaxPs = 2 // 最大体力 MaxPs = 2 // 最大体力
//MaxRound = 7 // 最大回合数
MaxTime = 1800 // 游戏操作时间
) )
//游戏房间 //游戏房间
@ -36,6 +34,7 @@ type Room struct {
rd2 bool // 玩家2 是否准备 rd2 bool // 玩家2 是否准备
Status int32 //房间游戏状态 0未开始 1 已开始 2 已结束 Status int32 //房间游戏状态 0未开始 1 已开始 2 已结束
RoomType int32 // 房间类型 1 是好友创房 RoomType int32 // 房间类型 1 是好友创房
MaxTime int32 // 操作时间
} }
func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) { func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) {
@ -56,7 +55,7 @@ func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) {
if this.operatetimer != nil { if this.operatetimer != nil {
timewheel.Remove(this.operatetimer) timewheel.Remove(this.operatetimer)
} // 回合+1 } // 回合+1
this.operatetimer = timewheel.Add(time.Second*MaxTime, this.operateTimeOut) // 开启新的定时器 this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut) // 开启新的定时器
} }
} }
@ -375,7 +374,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
this.round++ this.round++
if this.operatetimer != nil { if this.operatetimer != nil {
timewheel.Remove(this.operatetimer) timewheel.Remove(this.operatetimer)
this.operatetimer = timewheel.Add(time.Second*MaxTime, this.operateTimeOut) // 开启新的定时器 this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut) // 开启新的定时器
} }
} }
} }
@ -449,6 +448,12 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
} }
} }
if bStartGame { if bStartGame {
// 初始化规则相关
if len(this.szSession) == 1 {
this.MaxTime = this.module.ModuleTools.GetGlobalConf().ConsumePveTime
} else {
this.MaxTime = this.module.ModuleTools.GetGlobalConf().ConsumePvpTime
}
var weight []int32 // 权重 var weight []int32 // 权重
// 开始随机玩法 // 开始随机玩法
list := this.module.configure.GetGameConsumeIntegral() list := this.module.configure.GetGameConsumeIntegral()
@ -470,8 +475,9 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
}, this.szSession...); err != nil { }, this.szSession...); err != nil {
this.module.Errorln(err) this.module.Errorln(err)
} }
this.operatetimer = timewheel.Add(time.Second*MaxTime, this.operateTimeOut) this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut)
} }
case "reconnect": // 重连 case "reconnect": // 重连
session.SendMsg(string(this.module.GetType()), "reconnect", &pb.EntertainReconnectResp{ session.SendMsg(string(this.module.GetType()), "reconnect", &pb.EntertainReconnectResp{
Roomid: this.Id, Roomid: this.Id,