From dcd4818cb11c117f57385cf9b39435856591c090 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Tue, 7 Nov 2023 15:11:36 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=88=BF=E9=97=B4=E5=9B=9E=E6=94=B6=20?= =?UTF-8?q?=E7=A6=BB=E7=BA=BF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/entertainment/module.go | 50 +++++------ modules/entertainment/room.go | 142 +++++++++++++------------------- 2 files changed, 82 insertions(+), 110 deletions(-) diff --git a/modules/entertainment/module.go b/modules/entertainment/module.go index b63a3562c..34dfbc7e6 100644 --- a/modules/entertainment/module.go +++ b/modules/entertainment/module.go @@ -2,6 +2,7 @@ package entertainment import ( "context" + "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/event" @@ -124,32 +125,33 @@ func (this *Entertainment) ConsumXxlCard(session comm.IUserSession, card string) // 用户离线处理 func (this *Entertainment) EventUserOffline(uid, sessionid string) { this.Debugf("user offline: %s", uid) - // if list, err := this.model.getEntertainmList(uid); err == nil { - // var ( - // serverPath string = fmt.Sprintf("%s/%s", this.service.GetType(), this.service.GetId()) - // ) - // if serverPath != list.ServicePath { // RPC 通知房间所在的服务器 - // _, err = this.service.RpcGo( - // context.Background(), - // list.ServicePath, - // string(comm.RPC_XXLOffLine), - // &pb.RPCGeneralReqA2{ - // Param1: list.Roomid, - // Param2: list.Uid, - // }, - // nil) - // if err != nil { - // this.Errorln(err) - // return - // } - // } else { - // this.useroffline(context.Background(), &pb.RPCGeneralReqA2{Param1: list.Roomid, Param2: list.Uid}, nil) - // } - // return - // } + if list, err := this.model.getEntertainmList(uid); err == nil { + if list.Roomid == "" { // 不在房间不处理 + return + } + serverPath := fmt.Sprintf("%s/%s", this.service.GetType(), this.service.GetId()) + if serverPath != list.ServicePath { // RPC 通知房间所在的服务器 + _, err = this.service.RpcGo( + context.Background(), + list.ServicePath, + string(comm.RPC_XXLOffLine), + &pb.RPCGeneralReqA2{ + Param1: list.Roomid, + Param2: list.Uid, + }, + nil) + if err != nil { + this.Errorln(err) + return + } + } else { + this.useroffline(context.Background(), &pb.RPCGeneralReqA2{Param1: list.Roomid, Param2: list.Uid}, nil) + } + return + } } 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) return } diff --git a/modules/entertainment/room.go b/modules/entertainment/room.go index 24f7a57ad..2b08c1926 100644 --- a/modules/entertainment/room.go +++ b/modules/entertainment/room.go @@ -21,75 +21,29 @@ const ( //游戏房间 type Room struct { - Id string // 房间id - szSession []comm.IUserSession - player1 *pb.PlayerData // 玩家1 - player2 *pb.PlayerData // 玩家2 - chessboard *MapData - module *Entertainment - round int32 // 轮数 - operatetimer *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 //当前房间玩法 + Id string // 房间id + szSession []comm.IUserSession + player1 *pb.PlayerData // 玩家1 + player2 *pb.PlayerData // 玩家2 + chessboard *MapData + module *Entertainment + 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 //当前房间玩法 } 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 // 恢复体力 - this.player1.Ps = 0 - } else { // 权限给1号玩家 - 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.GetPalatData(), - }) - fmt.Printf("===超时棋盘=============\n") - //this.chessboard.Debugf() - if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{ - //Mpadata: szMap, - Power: this.NexPower, - Curpower: this.curPower, - Score: 0, - Round: this.round, - User1: this.player1, - User2: this.player2, - Itype: 9999, - Curid: 0, - Targetid: 0, - }, this.szSession...); err != nil { - this.module.Errorln(err) - } - // 变更权限 - this.curPower = this.NexPower - if this.round > this.MaxRound { // 游戏结束 - if this.player1.Score == this.player2.Score { - this.MaxRound += 1 // 增加一回合 - } else { - this.GameOver() - } - return - } - // 二号玩家是机器人 - if len(this.szSession) == 1 { - this.AiOperator() - } + fmt.Printf("解散房间超时+++++%d\n", time.Now().Unix()) //倒计时结束还没结束基本是游戏异常 直接清理房间 + this.ModifyUserRoomInfoData(false) + event.TriggerEvent(comm.EventCloseRoom, this.Id) // 释放房间 } // 随机一个玩法 @@ -442,13 +396,6 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr } return } - - if this.curPower != this.NexPower { // 下一次操作不是自己 清除定时器 - if this.operatetimer != nil { - timewheel.Remove(this.operatetimer) - this.operatetimer = nil - } - } // 变更权限 this.curPower = this.NexPower @@ -487,7 +434,6 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr } else { this.MaxTime = this.module.ModuleTools.GetGlobalConf().ConsumePvpTime } - this.MaxTime = 30 // 测试用 后面走配置 this.Status = 1 this.round = 1 @@ -503,8 +449,9 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr }, this.szSession...); err != nil { this.module.Errorln(err) } - // 游戏开始开启一个定时器 - //this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut) + this.ModifyUserRoomInfoData(true) + // 游戏开始开启一个定时器 1小时如果还不结束 自动清理 + this.closeRoomTimer = timewheel.Add(time.Hour, this.operateTimeOut) } case "reconnect": // 重连 @@ -544,11 +491,9 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr }, this.szSession...); err != nil { this.module.Errorln(err) } + this.ModifyUserRoomInfoData(false) case "operatorover": // 操作完成 开启一个定时器 - if this.operatetimer != nil { - timewheel.Remove(this.operatetimer) - this.operatetimer = nil - } + if this.player1.Userinfo.Uid == session.GetUserId() { this.rd1 = true } else if this.player2.Userinfo.Uid == session.GetUserId() { @@ -578,7 +523,6 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr } //this.operatetimer = timewheel.Add(time.Second*time.Duration(this.MaxTime), this.operateTimeOut) } - return } @@ -593,10 +537,7 @@ func (this *Room) GameOver() (errdata *pb.ErrorData) { lostPlayer *pb.PlayerData // 输的玩家 box *pb.BoxData // 是否可以获得宝箱奖励 ) - if this.operatetimer != nil { - timewheel.Remove(this.operatetimer) - this.operatetimer = nil - } + winner = this.player1 bReward = true if this.player1.Score < this.player2.Score { @@ -673,8 +614,12 @@ func (this *Room) GameOver() (errdata *pb.ErrorData) { Reward: atno, Box: box, }, this.szSession...) - + this.ModifyUserRoomInfoData(false) event.TriggerEvent(comm.EventCloseRoom, this.Id) + if this.closeRoomTimer != nil { // 游戏结束 清理定时器 + timewheel.Remove(this.closeRoomTimer) + this.closeRoomTimer = nil + } return } @@ -722,3 +667,28 @@ func (this *Room) JoinRoom(module *Entertainment, p *pb.PlayerData) (room *Room, } return } + +// 修改玩家的房间信息 +func (this *Room) ModifyUserRoomInfoData(bStart bool) { + var ( + roomid string + path string + ) + if bStart { + roomid = this.Id + path = fmt.Sprintf("%s/%s", this.module.service.GetType(), this.module.service.GetId()) + } + // 修改房间记录信息 + this.module.model.modifyEntertainmList(this.player1.Userinfo.Uid, map[string]interface{}{ + "roomid": roomid, + "servicePath": path, + }) + + if this.player2.Userinfo.Uid != "999" { + this.module.model.modifyEntertainmList(this.player2.Userinfo.Uid, map[string]interface{}{ + "roomid": roomid, + "servicePath": path, + }) + } + return +} From 22442bfb79f18d9677aad83a97a1ab942cde2e4b Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Tue, 7 Nov 2023 16:03:12 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=88=BF=E9=97=B4=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/entertainment/module.go | 7 +++++ modules/entertainment/room.go | 53 ++++++++++++++++++++------------- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/modules/entertainment/module.go b/modules/entertainment/module.go index 34dfbc7e6..c1c7354de 100644 --- a/modules/entertainment/module.go +++ b/modules/entertainment/module.go @@ -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 } diff --git a/modules/entertainment/room.go b/modules/entertainment/room.go index 2b08c1926..199003d2b 100644 --- a/modules/entertainment/room.go +++ b/modules/entertainment/room.go @@ -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, From 86acb03ad9955d47238e0e8c64c0fabc82c06895 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Tue, 7 Nov 2023 17:48:48 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=B8=A4=E4=B8=AA=E7=89=B9=E6=AE=8A?= =?UTF-8?q?=E5=85=83=E7=B4=A0=E5=9C=A8=E4=B8=80=E8=B5=B7=E4=B9=9F=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E6=B6=88=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/entertainment/room.go | 24 ++-- modules/entertainment/xxlPlat.go | 216 +++++++++++++++++++------------ 2 files changed, 150 insertions(+), 90 deletions(-) diff --git a/modules/entertainment/room.go b/modules/entertainment/room.go index 199003d2b..a19b1726a 100644 --- a/modules/entertainment/room.go +++ b/modules/entertainment/room.go @@ -295,22 +295,28 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr this.player2.Ps = 0 } } else { + bCanChange := false 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(), + if b, m := this.chessboard.CheckSpecialElemChange(req.Curid, req.Targetid, color); !b { + // 交换元素 + if b = this.chessboard.SwapGirde(req.Curid, req.Targetid); !b { // 交换格子 + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_EntertainCantSwap, // 不能交换 直接返回 + Title: pb.ErrorCode_EntertainCantSwap.ToString(), + } + return } - return + } else { + bCanChange = true + szMap = append(szMap, m...) } - if m, b := this.chessboard.CheckMap(color, true); len(m) > 0 { - // curScore += score szMap = append(szMap, m...) bAddPs = b - } else { // 不能消除 + bCanChange = true + } + if !bCanChange { // 不能消除 this.chessboard.SwapGirde(req.Targetid, req.Curid) // 换到原来的位置 errdata = &pb.ErrorData{ Code: pb.ErrorCode_EntertainCantSwap, // 不能交换 直接返回 diff --git a/modules/entertainment/xxlPlat.go b/modules/entertainment/xxlPlat.go index 0359d353c..6f9f02ed1 100644 --- a/modules/entertainment/xxlPlat.go +++ b/modules/entertainment/xxlPlat.go @@ -51,73 +51,32 @@ func (this *MapData) GetRandType() int32 { } // 玩法带入 -func (this *MapData) CreateGride(index int32, bDrop bool) (girde *pb.GirdeData) { +func (this *MapData) CreateGride(count int) (girdes []*pb.GirdeData) { var ( id int32 conf *cfg.GameBlockData err error ) // 权重带入 - this.oid++ - girde = &pb.GirdeData{ // 默认值 - Oid: this.oid, - Color: 1, - Cid: 1, - Score: 1, - Special: 0, - } - if this.iType == 4 && bDrop { - var count int32 - for _, v := range this.Plat { - if v.Special == 5 || v.Special == 6 || - v.Special == 7 || v.Special == 8 { - count++ - if count >= 2 { - break - } - } - } - if count < 2 { - n, _ := rand.Int(rand.Reader, big.NewInt(6)) // 随机一个颜色 - n1, _ := rand.Int(rand.Reader, big.NewInt(4)) // 随机一个消除类型 - if conf, err := this.module.configure.GetGameBlock(int32(n.Int64()+1), int32(n1.Int64()+5)); err == nil { - id = conf.Key - } - } else { - id = this.GetRandType() + for i := 0; i < count; i++ { + this.oid++ + girde := &pb.GirdeData{ // 默认值 + Oid: this.oid, + Color: 1, + Cid: 1, + Score: 1, + Special: 0, } - } else if this.iType == 3 && bDrop { // 创建棋盘的时候此玩法类型执行效率低下 稍后采用同颜色替换模式处理 - // 最多2个 - var count int32 - for _, v := range this.Plat { - if v.Special == 4 { - count++ - if count >= 2 { - break - } - } - } - if count < 2 { - n, _ := rand.Int(rand.Reader, big.NewInt(6)) // 随机一个颜色 - if conf, err := this.module.configure.GetGameBlock(int32(n.Int64()+1), 4); err == nil { - id = conf.Key - } - } else { - id = this.GetRandType() - } - - } else { id = this.GetRandType() + conf, err = this.module.configure.GetGameBlockByKey(id) + if err == nil { + girde.Color = conf.Color + girde.Cid = conf.Key + girde.Special = conf.Type + girde.Score = conf.Score + girdes = append(girdes, girde) + } } - conf, err = this.module.configure.GetGameBlockByKey(id) - if err != nil { - return - } - - girde.Color = conf.Color - girde.Cid = conf.Key - girde.Special = conf.Type - girde.Score = conf.Score return } @@ -127,8 +86,8 @@ func (this *MapData) InitMap(module *Entertainment, iType int32) { this.iType = iType this.oid = 1000 // 方便观察 从1000开始 this.Plat = make([]*pb.GirdeData, Width*Height) - for i := 0; i < Width*Height; i++ { - this.Plat[i] = this.CreateGride(int32(i), false) + for i, v := range this.CreateGride(Total) { + this.Plat[i] = v } if iType > 1 { var sp int32 @@ -161,6 +120,60 @@ func (this *MapData) InitMap(module *Entertainment, iType int32) { //this.SetMap() // 方便测试固定地图 } +// 交换之前先判断是不是特殊元素的交换 +func (this *MapData) CheckSpecialElemChange(oldId, newId int32, color int32) (bSwap bool, szMap []*pb.MapData) { + this.operElem = []int32{} // 初始化 + if (oldId%Height+1 < Total && oldId+1 == newId) || + (oldId%Height > 0 && oldId-1 == newId) || + (oldId+Width < Total && oldId+Width == newId) || + (oldId-Width >= 0 && oldId-Width == newId) { + bSwap = true + x := make(map[int]struct{}) + if this.Plat[newId].Special != 0 && this.Plat[oldId].Special != 0 { // 都不为0 + tmp := new(pb.GirdeData) + *tmp = *this.Plat[newId] + this.Plat[newId] = this.Plat[oldId] + this.Plat[oldId] = tmp + this.operElem = append(this.operElem, newId) + this.operElem = append(this.operElem, oldId) + x = this.SpecialElem(int(oldId), this.Plat[oldId].Special) + xc := this.SpecialElem(int(newId), this.Plat[newId].Special) + for k := range xc { + x[k] = struct{}{} + } + var energy int32 + var curScore int32 + for id := range x { + if this.Plat[id].Color == color { + energy++ + } + curScore += this.Plat[id].Score + this.Plat[id] = &pb.GirdeData{} + this.operElem = append(this.operElem, int32(id)) + } + for id := range x { + if this.Plat[id].Color == color { + energy++ + } + curScore += this.Plat[id].Score + this.Plat[id] = &pb.GirdeData{} + this.operElem = append(this.operElem, int32(id)) + } + if this.DropGirde() { + + szMap = append(szMap, &pb.MapData{ + Data: this.GetPalatData(), + CurSocre: curScore, + CurEnergy: energy, + }) + } + } else { + bSwap = false + } + } + return +} + // 交换2个元素(参数 oid ) func (this *MapData) SwapGirde(oldId, newId int32) (bSwap bool) { this.operElem = []int32{} // 初始化 @@ -198,13 +211,7 @@ func (this *MapData) Check5X() (bEliminate bool, xiaochu []int, s map[int]int) { //var xiaochu []int // 即将消除的key s = make(map[int]int) for k, v := range this.Plat { - // b := false - // for _, e := range this.operElem { - // if e == int32(k) { - // b = true - // break - // } - // } + if v.Cid == 0 { continue } @@ -256,15 +263,8 @@ func (this *MapData) Check4X() (bEliminate bool, xiaochu []int, s map[int]int) { ) s = make(map[int]int) - //var xiaochu []int // 即将消除的key for k, v := range this.Plat { - // b := false - // for _, e := range this.operElem { - // if e == int32(k) { - // b = true - // break - // } - // } + if v.Cid == 0 { continue } @@ -478,8 +478,6 @@ func (this *MapData) CheckMap(color int32, bSkill bool) (szMap []*pb.MapData, xc CurSocre: curScore, CurEnergy: energy, }) - //this.Debugf() - } // 检查掉落 @@ -493,6 +491,8 @@ func (this *MapData) CheckMap(color int32, bSkill bool) (szMap []*pb.MapData, xc // 下落 生成新的格子 (返回掉落所获得的分数) func (this *MapData) DropGirde() bool { + // 需要填充的格子 + var fill []int bDrop := false for i := 0; i < Width; i++ { for j := 0; j < Height; j++ { @@ -510,12 +510,66 @@ func (this *MapData) DropGirde() bool { } for m := j + add; m < Height; m++ { k1 := i*Width + m - this.Plat[k1] = this.CreateGride(int32(k1), true) + fill = append(fill, k1) + //this.Plat[k1] = this.CreateGride(true) } break } } } + sz := this.CreateGride(len(fill)) + for pos, id := range fill { + this.Plat[id] = sz[pos] + } + if this.iType > 1 { + var sp int32 + var mp map[int]struct{} + mp = make(map[int]struct{}, 0) + var count int32 + + for pos, v := range this.Plat { + if this.iType == 4 { + if v.Special == 5 || v.Special == 6 || + v.Special == 7 || v.Special == 8 { + mp[pos] = struct{}{} + count++ + if count >= 2 { + break + } + } + } else if this.iType == 3 { + if v.Special == 4 { + mp[pos] = struct{}{} + count++ + if count >= 2 { + break + } + } + } + } + if len(mp) < 2 { + for { + n1, _ := rand.Int(rand.Reader, big.NewInt(int64(len(fill)))) + mp[fill[n1.Int64()]] = struct{}{} + if len(mp) >= 2 { + break + } + } + if this.iType == 3 { + sp = 4 + } else if this.iType == 4 { + n1, _ := rand.Int(rand.Reader, big.NewInt(4)) // 随机一个消除类型 + sp = int32(n1.Int64()) + 5 + } + for key := range mp { + if conf, err := this.module.configure.GetGameBlock(this.Plat[key].Color, sp); err == nil { + this.Plat[key].Cid = conf.Key + this.Plat[key].Special = conf.Type + this.Plat[key].Score = conf.Score + } + } + } + } return bDrop } @@ -690,9 +744,9 @@ func (this *MapData) SetMap() { 5, 1, 2, 3, 1, 2, 2, 3, 4, 3, 5, 6, 1, 6, 1, 4, 1, 4, 2, 3, 6, - 1, 5, 1, 5, 6, 1, 4, - 6, 6, 4, 6, 4, 3, 3, - 3, 3, 1, 2, 1, 2, 5, + 1, 5, 6, 5, 6, 1, 4, + 6, 6, 3, 6, 4, 3, 3, + 3, 3, 1, 3, 1, 2, 5, // 1, 4, 2, 5, 4, 5, 2, // 3, 2, 3, 5, 2, 1, 4, // 2, 5, 5, 4, 5, 4, 1, From 3b549fe732baebd32c9e96ce951e06cfc4f5f6c0 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Tue, 7 Nov 2023 18:25:06 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=95=A3=E5=BC=B9?= =?UTF-8?q?=E6=96=B9=E5=9D=97=20=E9=9A=8F=E6=9C=BA=E5=B8=A6=E8=B5=B0?= =?UTF-8?q?=E5=85=83=E7=B4=A0=E4=BD=8D=E7=BD=AE=E4=B8=8D=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/entertainment/xxlPlat.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/entertainment/xxlPlat.go b/modules/entertainment/xxlPlat.go index 6f9f02ed1..35f711217 100644 --- a/modules/entertainment/xxlPlat.go +++ b/modules/entertainment/xxlPlat.go @@ -117,7 +117,7 @@ func (this *MapData) InitMap(module *Entertainment, iType int32) { this.SetIndelibilityPlat() this.Plat = this.GetPalatData() - //this.SetMap() // 方便测试固定地图 + // this.SetMap() // 方便测试固定地图 } // 交换之前先判断是不是特殊元素的交换 @@ -741,12 +741,12 @@ func (this *MapData) SkillUp(pos int32, color int32, skillid int32, value int32, func (this *MapData) SetMap() { sz2 := []int32{ 3, 3, 2, 2, 1, 3, 1, - 5, 1, 2, 3, 1, 2, 2, - 3, 4, 3, 5, 6, 1, 6, - 1, 4, 1, 4, 2, 3, 6, + 5, 1, 3, 3, 1, 2, 2, + 3, 2, 1, 4, 3, 1, 6, + 1, 4, 3, 4, 2, 3, 6, 1, 5, 6, 5, 6, 1, 4, - 6, 6, 3, 6, 4, 3, 3, - 3, 3, 1, 3, 1, 2, 5, + 6, 6, 3, 6, 3, 1, 3, + 3, 3, 1, 3, 3, 2, 5, // 1, 4, 2, 5, 4, 5, 2, // 3, 2, 3, 5, 2, 1, 4, // 2, 5, 5, 4, 5, 4, 1, @@ -1179,8 +1179,8 @@ func (this *MapData) SpecialElem(id int, s int32) (x map[int]struct{}) { // 获取配置 if c, _ := this.module.configure.GetGameBlock(this.Plat[id].Color, FiveType); c != nil { ids := utils.RandomNumbers(0, Total-1, int(c.Value)) - for key := range ids { - x[key] = struct{}{} + for _, v := range ids { + x[v] = struct{}{} } } } else if s == BoomType { // 炸弹类型 带走周围一圈+ 上下左右