房间数据整理

This commit is contained in:
meixiongfeng 2023-11-07 16:03:12 +08:00
parent dcd4818cb1
commit 22442bfb79
2 changed files with 40 additions and 20 deletions

View File

@ -153,5 +153,12 @@ func (this *Entertainment) EventUserOffline(uid, sessionid string) {
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)
// 房间不在直接返回
if _, err = this.gameMgr.GetRoomInfo(req.Param1); err != nil {
return
}
this.gameMgr.RoomDistribute(req.Param1, nil, "offline", req)
return
}

View File

@ -25,25 +25,24 @@ type Room struct {
szSession []comm.IUserSession
player1 *pb.PlayerData // 玩家1
player2 *pb.PlayerData // 玩家2
chessboard *MapData
chessboard *MapData // 地图数据
module *Entertainment
round int32 // 轮数
round int32 // 当前轮数
closeRoomTimer *timewheel.Task //房间解散倒计时定时器
curPower string // 当前操作的玩家
NexPower string // 下一个操作的玩家
MaxRound int32
rd1 bool // 玩家1 是否准备
rd2 bool // 玩家2 是否准备
Status int32 //房间游戏状态 0未开始 1 已开始 2 已结束
RoomType int32 // 房间类型 1 是好友创房
MaxTime int32 // 操作时间
Playtype int32 //当前房间玩法
MaxRound int32 // 最大回合数
rd1 bool // 玩家1 是否准备
rd2 bool // 玩家2 是否准备
Status int32 //房间游戏状态 0未开始 1 已开始 2 已结束
RoomType int32 // 房间类型 1 是好友创房 0对战 2 AI 对战
MaxTime int32 // 操作时间
Playtype int32 //当前房间玩法
}
func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) {
func (this *Room) CloseRoomTimeOut(task *timewheel.Task, args ...interface{}) {
fmt.Printf("解散房间超时+++++%d\n", time.Now().Unix()) //倒计时结束还没结束基本是游戏异常 直接清理房间
this.ModifyUserRoomInfoData(false)
event.TriggerEvent(comm.EventCloseRoom, this.Id) // 释放房间
}
// 随机一个玩法
@ -78,6 +77,8 @@ func (this *Room) InitRoom(module *Entertainment, p1 *pb.PlayerData, p2 *pb.Play
} else {
this.szSession = append(this.szSession, s2.Clone())
}
} else {
this.RoomType = 2
}
this.MaxRound = module.ModuleTools.GetGlobalConf().ConsumeRounds
room = &Room{
@ -91,6 +92,7 @@ func (this *Room) InitRoom(module *Entertainment, p1 *pb.PlayerData, p2 *pb.Play
MaxRound: this.MaxRound,
Status: 0,
Playtype: this.Playtype,
RoomType: this.RoomType,
}
if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "enterroom", &pb.EntertainEnterRoomPush{
@ -451,7 +453,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
}
this.ModifyUserRoomInfoData(true)
// 游戏开始开启一个定时器 1小时如果还不结束 自动清理
this.closeRoomTimer = timewheel.Add(time.Hour, this.operateTimeOut)
this.closeRoomTimer = timewheel.Add(time.Hour, this.CloseRoomTimeOut)
}
case "reconnect": // 重连
@ -522,6 +524,14 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
}
}
//this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut)
case "offline":
req := msg.(*pb.RPCGeneralReqA2)
fmt.Printf("useroffline: %v\n", req)
if this.RoomType == 2 { // AI 对战直接结束
this.ModifyUserRoomInfoData(false)
return
}
}
return
}
@ -537,7 +547,6 @@ func (this *Room) GameOver() (errdata *pb.ErrorData) {
lostPlayer *pb.PlayerData // 输的玩家
box *pb.BoxData // 是否可以获得宝箱奖励
)
winner = this.player1
bReward = true
if this.player1.Score < this.player2.Score {
@ -591,7 +600,7 @@ func (this *Room) GameOver() (errdata *pb.ErrorData) {
Opentime: int64(c.Cd) + configure.Now().Unix(),
}
list.Box = append(list.Box, box)
// 写库
this.module.model.modifyEntertainmList(winner.Userinfo.Uid, map[string]interface{}{
"box": list.Box,
})
@ -600,6 +609,7 @@ func (this *Room) GameOver() (errdata *pb.ErrorData) {
}
}
// 修改房间状态
this.Status = 2
this.module.SendMsgSyncToSession(string(this.module.GetType()), "gameover", &pb.EntertainGameOverPush{
@ -615,7 +625,6 @@ func (this *Room) GameOver() (errdata *pb.ErrorData) {
Box: box,
}, this.szSession...)
this.ModifyUserRoomInfoData(false)
event.TriggerEvent(comm.EventCloseRoom, this.Id)
if this.closeRoomTimer != nil { // 游戏结束 清理定时器
timewheel.Remove(this.closeRoomTimer)
this.closeRoomTimer = nil
@ -677,14 +686,18 @@ func (this *Room) ModifyUserRoomInfoData(bStart bool) {
if bStart {
roomid = this.Id
path = fmt.Sprintf("%s/%s", this.module.service.GetType(), this.module.service.GetId())
} else {
event.TriggerEvent(comm.EventCloseRoom, this.Id) // 释放房间
}
// 修改房间记录信息
this.module.model.modifyEntertainmList(this.player1.Userinfo.Uid, map[string]interface{}{
"roomid": roomid,
"servicePath": path,
})
if this.player1 != nil && this.player1.Userinfo != nil {
this.module.model.modifyEntertainmList(this.player1.Userinfo.Uid, map[string]interface{}{
"roomid": roomid,
"servicePath": path,
})
}
if this.player2.Userinfo.Uid != "999" {
if this.RoomType != 2 && this.player2 != nil && this.player2.Userinfo != nil {
this.module.model.modifyEntertainmList(this.player2.Userinfo.Uid, map[string]interface{}{
"roomid": roomid,
"servicePath": path,