From cbf5cd8f3fd85007858b818ed8b25673100bae87 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 1 Nov 2023 21:08:55 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8B=B1=E9=9B=84=E6=8A=80=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/entertainment/room.go | 4 +- modules/entertainment/xxlPlat.go | 111 +++++++++++++++++++----------- modules/entertainment/xxl_test.go | 4 +- 3 files changed, 75 insertions(+), 44 deletions(-) diff --git a/modules/entertainment/room.go b/modules/entertainment/room.go index 7d13dd662..a3ff2adfd 100644 --- a/modules/entertainment/room.go +++ b/modules/entertainment/room.go @@ -241,7 +241,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr } if this.player1.Energy >= conf.Skillload { this.player1.Energy = 0 // 清零 - if _, m := this.chessboard.SkillUp(color, conf.Skilleffect, conf.Skillvalue, true); len(m) > 0 { + if _, m := this.chessboard.SkillUp(0, color, conf.Skilleffect, conf.Skillvalue, true); len(m) > 0 { szMap = append(szMap, m...) } else { szMap = append(szMap, &pb.MapData{ @@ -273,7 +273,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr } if this.player2.Energy >= conf.Skillload { this.player2.Energy = 0 // 清零 - if _, m := this.chessboard.SkillUp(color, conf.Skilleffect, conf.Skillvalue, true); len(m) > 0 { + if _, m := this.chessboard.SkillUp(0, color, conf.Skilleffect, conf.Skillvalue, true); len(m) > 0 { szMap = append(szMap, m...) } else { szMap = append(szMap, &pb.MapData{ diff --git a/modules/entertainment/xxlPlat.go b/modules/entertainment/xxlPlat.go index bd4cb8c28..e55c2ac1d 100644 --- a/modules/entertainment/xxlPlat.go +++ b/modules/entertainment/xxlPlat.go @@ -89,11 +89,11 @@ func (this *MapData) SwapGirde(oldId, newId int32) (bSwap bool) { func (this *MapData) Debugf() { fmt.Printf("================\n") - //var v int + var v int for index := Width - 1; index >= 0; index-- { for j := 0; j < Height; j++ { - // v = index + j*7 - fmt.Printf("%d:%d ", this.Plat[index+j*Height].Oid, this.Plat[index+j*Height].Cid) + v = index + j*7 + fmt.Printf("%d:%d ", v, this.Plat[index+j*Height].Cid) } fmt.Printf("\n") @@ -372,7 +372,7 @@ func (this *MapData) CheckMap(color int32, bSkill bool) (szMap []*pb.MapData, xc } else if s == FiveType { // 随机消除 // 获取配置 if c, _ := this.module.configure.GetGameBlock(this.Plat[id].Color, FiveType); c != nil { - if xc, _ := this.SkillUp(color, 1, c.Value, false); len(xc) > 0 { + if xc, _ := this.SkillUp(0, color, 1, c.Value, false); len(xc) > 0 { //szMap = append(szMap, sz...) for key := range xc { x[key] = struct{}{} @@ -499,56 +499,85 @@ func (this *MapData) AiSwapGirde() (szMap []*pb.MapData, oid1 int32, oid2 int32, } // 释放技能 技能id 和参数 -func (this *MapData) SkillUp(color int32, skillid int32, value int32, bDrop bool) (x map[int]struct{}, szMap []*pb.MapData) { +func (this *MapData) SkillUp(pos int32, color int32, skillid int32, value int32, bDrop bool) (x map[int]struct{}, szMap []*pb.MapData) { var ( skillScore int32 // 技能获得的分数 skillEnergy int32 // 技能获得的能量 + ids []int ) if skillid == 1 { // 随机消除盘面上X个方块 x = make(map[int]struct{}) - ids := utils.RandomNumbers(0, Total-1, int(value)) - for _, id := range ids { - s := this.Plat[id].Special - if s != 0 { - if s == FourUType { // 4消上下类型 - for i := 0; i < Height; i++ { // id 的一条线位置 - x[(id/Width)*Height+i] = struct{}{} - } - } else if s == FourLType { // 左右类型 - for i := 0; i < Width; i++ { // id 的一条线位置 - x[id%Height+i*Width] = struct{}{} - } - } else if s == FiveType { // 随机消除 - // 获取配置 - if c, _ := this.module.configure.GetGameBlock(this.Plat[id].Color, FiveType); c != nil { - if xc, _ := this.SkillUp(color, 1, c.Value, false); len(xc) > 0 { // 递归调用 - for key := range xc { - x[key] = struct{}{} - } + ids = utils.RandomNumbers(0, Total-1, int(value)) + + } else if skillid == 2 { // 找到pos 位置的所有方块 + x := int(pos / Width) + y := int(pos % Height) + for i := 1; i < 7; i++ { + + if x-i >= 0 && y+i < Height { // 左上 + ids = append(ids, (x-i)*Width+(y+i)) + } + if x-i >= 0 && y-i >= 0 { // 左下 + ids = append(ids, (x-i)*Width+(y-i)) + } + + if x+i < Width && y+i < Height { // 右上 + ids = append(ids, (x+i)*Width+(y+i)) + } + if x+i < Width && y-i >= 0 { // 右下 + ids = append(ids, (x+i)*Width+(y-i)) + } + } + + } else if skillid == 3 { //选中一个方块,然后消除盘面上所有相同颜色的方块。 + c := this.Plat[pos].Color + for index, v1 := range this.Plat { + if v1.Color == c { + ids = append(ids, index) + } + } + } + for _, id := range ids { + s := this.Plat[id].Special + if s != 0 { + if s == FourUType { // 4消上下类型 + for i := 0; i < Height; i++ { // id 的一条线位置 + x[(id/Width)*Height+i] = struct{}{} + } + } else if s == FourLType { // 左右类型 + for i := 0; i < Width; i++ { // id 的一条线位置 + x[id%Height+i*Width] = struct{}{} + } + } else if s == FiveType { // 随机消除 + // 获取配置 + if c, _ := this.module.configure.GetGameBlock(this.Plat[id].Color, FiveType); c != nil { + if xc, _ := this.SkillUp(pos, color, 1, c.Value, false); len(xc) > 0 { // 递归调用 + for key := range xc { + x[key] = struct{}{} } } } } - x[id] = struct{}{} } - if bDrop { - for key := range x { - if this.Plat[key].Color == color { - skillEnergy += 1 - } - skillScore += this.Plat[key].Score - this.Plat[key] = &pb.GirdeData{} + x[id] = struct{}{} + } + if bDrop { + for key := range x { + if this.Plat[key].Color == color { + skillEnergy += 1 } - if this.DropGirde() { - szMap = append(szMap, &pb.MapData{ - Data: this.GetPalatData(), - CurSocre: skillScore, - CurEnergy: skillEnergy, - }) - if list, _ := this.CheckMap(color, false); len(list) > 0 { - szMap = append(szMap, list...) - } + skillScore += this.Plat[key].Score + this.Plat[key] = &pb.GirdeData{} + } + if this.DropGirde() { + szMap = append(szMap, &pb.MapData{ + Data: this.GetPalatData(), + CurSocre: skillScore, + CurEnergy: skillEnergy, + }) + if list, _ := this.CheckMap(color, false); len(list) > 0 { + szMap = append(szMap, list...) } } } diff --git a/modules/entertainment/xxl_test.go b/modules/entertainment/xxl_test.go index 2de7003ee..79e456390 100644 --- a/modules/entertainment/xxl_test.go +++ b/modules/entertainment/xxl_test.go @@ -84,6 +84,8 @@ func Test_Main(t *testing.T) { }() m := new(entertainment.MapData) m.InitMap(nil) + m.Debugf() + m.SkillUp(24, 1, 2, 7, true) // m.SetMap() b := m.CheckAndRefreshPlat() fmt.Printf("xxxx%v", b) @@ -112,7 +114,7 @@ func Test_Main(t *testing.T) { // if bSwap, m := m.AiSwapGirde(); bSwap { // szMap = append(szMap, m...) // } - m.SkillUp(1, 1, 7, true) + m.SkillUp(0, 1, 2, 7, true) m.SwapGirde(1, 8) //m.CheckMap(1)