diff --git a/modules/entertainment/room.go b/modules/entertainment/room.go index 14ec67ee3..24f7a57ad 100644 --- a/modules/entertainment/room.go +++ b/modules/entertainment/room.go @@ -1,7 +1,6 @@ package entertainment import ( - "crypto/rand" "errors" "fmt" "go_dreamfactory/comm" @@ -10,7 +9,6 @@ import ( "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" - "math/big" "time" "go.mongodb.org/mongo-driver/bson/primitive" @@ -105,11 +103,6 @@ func (this *Room) RandomPlayType() (itype int32) { } itype = list[comm.GetRandW(weight)].Key - // 临时修改 50% 概率1类型 - n, _ := rand.Int(rand.Reader, big.NewInt(2)) - if n.Int64() == 0 { - itype = 1 - } return } diff --git a/modules/entertainment/xxlPlat.go b/modules/entertainment/xxlPlat.go index 95f8454c0..0359d353c 100644 --- a/modules/entertainment/xxlPlat.go +++ b/modules/entertainment/xxlPlat.go @@ -53,11 +53,9 @@ func (this *MapData) GetRandType() int32 { // 玩法带入 func (this *MapData) CreateGride(index int32, bDrop bool) (girde *pb.GirdeData) { var ( - szWeight []int32 - szId []int32 - id int32 - conf *cfg.GameBlockData - err error + id int32 + conf *cfg.GameBlockData + err error ) // 权重带入 this.oid++ girde = &pb.GirdeData{ // 默认值 @@ -67,25 +65,29 @@ func (this *MapData) CreateGride(index int32, bDrop bool) (girde *pb.GirdeData) Score: 1, Special: 0, } - if this.iType == 4 { - for i := 1; i <= 6; i++ { // 6种颜色 - //for j := 1; j <= 4; j++ { - n1, _ := rand.Int(rand.Reader, big.NewInt(4)) - if conf, err := this.module.configure.GetGameBlock(int32(i), int32(n1.Int64()+5)); err == nil { - szWeight = append(szWeight, conf.Weight) - szId = append(szId, conf.Key) - } - //} - - if conf, err := this.module.configure.GetGameBlock(int32(i), 0); err == nil { - szWeight = append(szWeight, conf.Weight) - szId = append(szId, conf.Key) + 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 + } } } - id = szId[comm.GetRandW(szWeight)] + 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() + } + } else if this.iType == 3 && bDrop { // 创建棋盘的时候此玩法类型执行效率低下 稍后采用同颜色替换模式处理 // 最多2个 - var count int32 for _, v := range this.Plat { if v.Special == 4 { @@ -128,20 +130,32 @@ func (this *MapData) InitMap(module *Entertainment, iType int32) { for i := 0; i < Width*Height; i++ { this.Plat[i] = this.CreateGride(int32(i), false) } - if iType == 3 { - var pos int64 - for i := 0; i < 2; i++ { + if iType > 1 { + var sp int32 + var mp map[int32]struct{} + mp = make(map[int32]struct{}, 0) + for { n1, _ := rand.Int(rand.Reader, big.NewInt(Total-1)) - if pos != n1.Int64() { - pos = n1.Int64() + mp[int32(n1.Int64())] = struct{}{} + if len(mp) >= 2 { + break } - if conf, err := this.module.configure.GetGameBlock(this.Plat[n1.Int64()].Color, 4); err == nil { - this.Plat[n1.Int64()].Cid = conf.Key - this.Plat[n1.Int64()].Special = conf.Type - this.Plat[n1.Int64()].Score = conf.Score + } + if iType == 3 { + sp = 4 + } else if 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 } } } + this.SetIndelibilityPlat() this.Plat = this.GetPalatData() //this.SetMap() // 方便测试固定地图 diff --git a/modules/entertainment/xxl_test.go b/modules/entertainment/xxl_test.go index 766dd00ed..2b32ad14a 100644 --- a/modules/entertainment/xxl_test.go +++ b/modules/entertainment/xxl_test.go @@ -12,6 +12,7 @@ import ( "go_dreamfactory/services" "go_dreamfactory/sys/configure" "go_dreamfactory/sys/db" + "math" "reflect" "strings" "testing" @@ -83,6 +84,7 @@ func Test_Main(t *testing.T) { ) }() + print(math.Pow(2, 238)) // sz := utils.RandomNumbers(0, 2, 2) // fmt.Printf("xxxx%v", sz) m := new(entertainment.MapData)