From 96d06af6059128f64cc522dcda67b423f6d1ee91 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Fri, 3 Nov 2023 18:05:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=89=E6=B6=88=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/entertainment/room.go | 235 +++++++++++++++++++------------ modules/entertainment/xxlPlat.go | 7 +- pb/entertain_msg.pb.go | 17 ++- 3 files changed, 161 insertions(+), 98 deletions(-) diff --git a/modules/entertainment/room.go b/modules/entertainment/room.go index d2e94315d..4fcc09ae3 100644 --- a/modules/entertainment/room.go +++ b/modules/entertainment/room.go @@ -36,6 +36,7 @@ type Room struct { Status int32 //房间游戏状态 0未开始 1 已开始 2 已结束 RoomType int32 // 房间类型 1 是好友创房 MaxTime int32 // 操作时间 + Playtype int32 //当前房间玩法 } func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) { @@ -46,27 +47,29 @@ func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) { if this.player1.Userinfo.Uid == this.curPower { // 给玩家2 this.NexPower = this.player2.Userinfo.Uid this.player2.Ps = MaxPs // 恢复体力 - + this.player1.Ps = 0 } else { // 权限给1号玩家 - this.curPower = this.player1.Userinfo.Uid + this.NexPower = this.player1.Userinfo.Uid this.player1.Ps = MaxPs // 恢复体力 + this.player2.Ps = 0 this.round++ - } var szMap []*pb.MapData szMap = append(szMap, &pb.MapData{ - Data: this.chessboard.Plat, + Data: this.chessboard.GetPalatData(), }) + fmt.Printf("===超时棋盘=============\n") + this.chessboard.Debugf() if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{ - Mpadata: szMap, + //Mpadata: szMap, Power: this.NexPower, Curpower: this.curPower, Score: 0, Round: this.round, User1: this.player1, User2: this.player2, - Itype: 0, + Itype: 9999, Curid: 0, Targetid: 0, }, this.szSession...); err != nil { @@ -88,10 +91,23 @@ func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) { } } +// 随机一个玩法 +func (this *Room) RandomPlayType() { + var weight []int32 // 权重 + // 开始随机玩法 + list := this.module.configure.GetGameConsumeIntegral() + for _, v := range list { + weight = append(weight, v.Weight) + } + + this.Playtype = list[comm.GetRandW(weight)].Key +} + func (this *Room) InitRoom(module *Entertainment, p1 *pb.PlayerData, p2 *pb.PlayerData) *Room { var room *Room this.module = module this.chessboard = new(MapData) + this.RandomPlayType() this.chessboard.InitMap(module) // 初始化棋盘 if s1, ok := this.module.GetUserSession(p1.Userinfo.Uid); !ok { this.module.PutUserSession(s1) @@ -308,85 +324,101 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr } return } - oid1 = this.chessboard.Plat[req.Curid].Oid - oid2 = this.chessboard.Plat[req.Targetid].Oid - // 交换元素 - if b := this.chessboard.SwapGirde(req.Curid, req.Targetid); !b { // 交换格子 - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_EntertainCantSwap, // 不能交换 直接返回 - Title: pb.ErrorCode_EntertainCantSwap.ToString(), - } - return - } - - if m, b := this.chessboard.CheckMap(color, true); len(m) > 0 { - // curScore += score - szMap = append(szMap, m...) - bAddPs = b - } else { // 不能消除 - this.chessboard.SwapGirde(req.Targetid, req.Curid) // 换到原来的位置 - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_EntertainCantSwap, // 不能交换 直接返回 - Title: pb.ErrorCode_EntertainCantSwap.ToString(), - } - return - } - - // 校验下次是不是消除 - if !this.chessboard.CheckAndRefreshPlat() { - this.chessboard.RedsetPlatData() - szMap = append(szMap, &pb.MapData{ - Data: this.chessboard.GetPalatData(), - ChangeType: 1, - }) - } - if this.curPower == this.player1.Userinfo.Uid { //权限校验 - this.player1.Score += curScore - this.player1.Ps-- - if bAddPs { - this.player1.Ps++ - if this.player1.Ps > MaxPs { - this.player1.Ps = MaxPs - } - } - - if this.player1.Ps <= 0 { + if req.Itype == 0 && req.Curid == 0 && req.Targetid == 0 { + if this.curPower == this.player1.Userinfo.Uid { this.NexPower = this.player2.Userinfo.Uid - if len(this.szSession) == 1 { // 校验2号玩家是不是AI - AIOperator = true + this.player2.Ps = 2 + this.player1.Ps = 0 + } + if this.curPower == this.player2.Userinfo.Uid { + this.NexPower = this.player1.Userinfo.Uid + this.player1.Ps = 2 + this.player2.Ps = 0 + } + } else { + oid1 = this.chessboard.Plat[req.Curid].Oid + oid2 = this.chessboard.Plat[req.Targetid].Oid + // 交换元素 + if b := this.chessboard.SwapGirde(req.Curid, req.Targetid); !b { // 交换格子 + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_EntertainCantSwap, // 不能交换 直接返回 + Title: pb.ErrorCode_EntertainCantSwap.ToString(), } - this.player2.Ps = MaxPs + return } - } else { // this.curPower == this.player2.Uid - this.player2.Score += curScore - this.player2.Ps-- - if bAddPs { - this.player2.Ps++ - if this.player2.Ps > MaxPs { + if m, b := this.chessboard.CheckMap(color, true); len(m) > 0 { + // curScore += score + szMap = append(szMap, m...) + bAddPs = b + } else { // 不能消除 + this.chessboard.SwapGirde(req.Targetid, req.Curid) // 换到原来的位置 + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_EntertainCantSwap, // 不能交换 直接返回 + Title: pb.ErrorCode_EntertainCantSwap.ToString(), + } + return + } + + // 校验下次是不是消除 + if !this.chessboard.CheckAndRefreshPlat() { + this.chessboard.RedsetPlatData() + szMap = append(szMap, &pb.MapData{ + Data: this.chessboard.GetPalatData(), + ChangeType: 1, + }) + } + if this.curPower == this.player1.Userinfo.Uid { //权限校验 + this.player1.Score += curScore + this.player1.Ps-- + if bAddPs { + this.player1.Ps++ + if this.player1.Ps > MaxPs { + this.player1.Ps = MaxPs + } + } + + if this.player1.Ps <= 0 { + this.NexPower = this.player2.Userinfo.Uid + if len(this.szSession) == 1 { // 校验2号玩家是不是AI + AIOperator = true + } this.player2.Ps = MaxPs } - } - if this.player2.Ps <= 0 { - this.NexPower = this.player1.Userinfo.Uid - this.player1.Ps = MaxPs - this.round++ + } else { // this.curPower == this.player2.Uid + this.player2.Score += curScore + this.player2.Ps-- + if bAddPs { + this.player2.Ps++ + if this.player2.Ps > MaxPs { + this.player2.Ps = MaxPs + } + } + if this.player2.Ps <= 0 { + this.NexPower = this.player1.Userinfo.Uid + this.player1.Ps = MaxPs + // this.round++ + } + } + for _, v := range szMap { // + curScore += v.CurSocre + if color == 1 { + this.player1.Score += v.CurSocre + v.CurSocre = this.player1.Score + this.player1.Energy += v.CurEnergy + v.CurEnergy = this.player1.Energy + } else { + this.player2.Score += v.CurSocre + v.CurSocre = this.player2.Score + this.player2.Energy += v.CurEnergy + v.CurEnergy = this.player2.Energy + } } } - for _, v := range szMap { // - curScore += v.CurSocre - if color == 1 { - this.player1.Score += v.CurSocre - v.CurSocre = this.player1.Score - this.player1.Energy += v.CurEnergy - v.CurEnergy = this.player1.Energy - } else { - this.player2.Score += v.CurSocre - v.CurSocre = this.player2.Score - this.player2.Energy += v.CurEnergy - v.CurEnergy = this.player2.Energy - } + + if this.NexPower == this.player1.Userinfo.Uid && this.NexPower != this.curPower { + this.round++ } // 广播消息 @@ -448,6 +480,8 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr } if this.rd1 && this.rd2 { // 两个玩家都准备好了 那么就开始游戏 bStartGame = true + this.rd1 = false + this.rd2 = false } } if bStartGame { @@ -457,13 +491,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr } else { this.MaxTime = this.module.ModuleTools.GetGlobalConf().ConsumePvpTime } - //this.MaxTime = 5 - var weight []int32 // 权重 - // 开始随机玩法 - list := this.module.configure.GetGameConsumeIntegral() - for _, v := range list { - weight = append(weight, v.Weight) - } + this.MaxTime = 10 this.Status = 1 this.round = 1 @@ -474,8 +502,8 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr Mpadata: &pb.MapData{Data: this.chessboard.Plat}, Power: this.NexPower, Round: this.round, - Roomid: this.Id, // 房间ID - Playtype: list[comm.GetRandW(weight)].Key, // 通过权重随机一个玩法 + Roomid: this.Id, // 房间ID + Playtype: this.Playtype, // 通过权重随机一个玩法 }, this.szSession...); err != nil { this.module.Errorln(err) } @@ -525,13 +553,35 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr timewheel.Remove(this.operatetimer) 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 { - this.module.Errorln(err) + if this.player1.Userinfo.Uid == session.GetUserId() { + this.rd1 = true + } else if this.player2.Userinfo.Uid == session.GetUserId() { + this.rd2 = true } + if len(this.szSession) == 1 { + 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() + } + } else { + if this.rd1 && this.rd2 { // 两个玩家都准备好了 那么就开始游戏 + this.rd1 = false + this.rd2 = false + 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) + } + } + } + //this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut) + } return @@ -596,7 +646,7 @@ func (this *Room) GameOver() (errdata *pb.ErrorData) { } // 查看能不能获得箱子 if list, err := this.module.model.getEntertainmList(winner.Userinfo.Uid); err == nil { - if len(list.Box) <= 3 { // 可以获得一个宝箱 + if len(list.Box) < 3 { // 可以获得一个宝箱 if c, err := this.module.configure.GetGameRandomConsumeBoxConf(); err == nil { if c.Color != 0 { box = &pb.BoxData{ @@ -638,6 +688,7 @@ func (this *Room) JoinRoom(module *Entertainment, p *pb.PlayerData) (room *Room, this.player1 = p this.module = module this.chessboard = new(MapData) + this.RandomPlayType() this.chessboard.InitMap(module) // 初始化棋盘 if s1, ok := this.module.GetUserSession(p.Userinfo.Uid); !ok { this.module.PutUserSession(s1) diff --git a/modules/entertainment/xxlPlat.go b/modules/entertainment/xxlPlat.go index 4c49882bc..580ba6f73 100644 --- a/modules/entertainment/xxlPlat.go +++ b/modules/entertainment/xxlPlat.go @@ -44,7 +44,6 @@ func GetRandType() int32 { func (this *MapData) CreateGride(index int32) *pb.GirdeData { t := GetRandType() - //fmt.Printf("create=====index: %d, color:%d \n", index, t) this.oid++ return &pb.GirdeData{ Oid: this.oid, @@ -65,7 +64,7 @@ func (this *MapData) InitMap(module *Entertainment) { this.Plat[i] = this.CreateGride(int32(i)) } this.SetIndelibilityPlat() - this.SetMap() // 方便测试固定地图 + //this.SetMap() // 方便测试固定地图 } // 交换2个元素(参数 oid ) @@ -896,6 +895,10 @@ func (this *MapData) SetIndelibilityPlat() { } } } + if b, _ := this.Check3X(); b { + fmt.Printf("plat init\n") + this.CheckMap(0, false) + } } // 重新洗牌 diff --git a/pb/entertain_msg.pb.go b/pb/entertain_msg.pb.go index 626f50c88..b57911dcb 100644 --- a/pb/entertain_msg.pb.go +++ b/pb/entertain_msg.pb.go @@ -2082,7 +2082,8 @@ type EntertainStarTimerPush struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Time int32 `protobuf:"varint,1,opt,name=time,proto3" json:"time"` + Time int32 `protobuf:"varint,1,opt,name=time,proto3" json:"time"` // 定时时间 单位s + Power string `protobuf:"bytes,2,opt,name=power,proto3" json:"power"` // 当前谁操作 } func (x *EntertainStarTimerPush) Reset() { @@ -2124,6 +2125,13 @@ func (x *EntertainStarTimerPush) GetTime() int32 { return 0 } +func (x *EntertainStarTimerPush) GetPower() string { + if x != nil { + return x.Power + } + return "" +} + var File_entertain_entertain_msg_proto protoreflect.FileDescriptor var file_entertain_entertain_msg_proto_rawDesc = []byte{ @@ -2323,11 +2331,12 @@ var file_entertain_entertain_msg_proto_rawDesc = []byte{ 0x12, 0x16, 0x0a, 0x06, 0x72, 0x6f, 0x6f, 0x6d, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x6f, 0x6f, 0x6d, 0x69, 0x64, 0x22, 0x1b, 0x0a, 0x19, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x74, 0x61, 0x69, 0x6e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x4f, 0x76, 0x65, - 0x72, 0x52, 0x65, 0x73, 0x70, 0x22, 0x2c, 0x0a, 0x16, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x74, 0x61, + 0x72, 0x52, 0x65, 0x73, 0x70, 0x22, 0x42, 0x0a, 0x16, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x74, 0x61, 0x69, 0x6e, 0x53, 0x74, 0x61, 0x72, 0x54, 0x69, 0x6d, 0x65, 0x72, 0x50, 0x75, 0x73, 0x68, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x74, - 0x69, 0x6d, 0x65, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x69, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x05, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, + 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var (