三消优化

This commit is contained in:
meixiongfeng 2023-11-08 17:26:36 +08:00
parent d88d719560
commit 7e31b04d51
3 changed files with 85 additions and 27 deletions

View File

@ -251,3 +251,24 @@ func (this *configureComp) GetGameBlockByKey(key int32) (conf *cfg.GameBlockData
err = comm.NewNotFoundConfErr(moduleName, game_block, key) err = comm.NewNotFoundConfErr(moduleName, game_block, key)
return return
} }
// 通过权重获取一个普通元素
func (this *configureComp) GetGameNormalElem() (rd int32) {
var (
v interface{}
szWeight []int32
err error
)
if v, err = this.GetConfigure(game_block); err == nil {
if configure, ok := v.(*cfg.GameBlock); ok {
for _, v := range configure.GetDataList() {
if v.Key > 6 {
break
}
szWeight = append(szWeight, v.Weight)
}
}
}
rd = comm.GetRandW(szWeight) + 1
return
}

View File

@ -55,7 +55,7 @@ func (this *Room) RandomPlayType() (itype int32) {
weight = append(weight, v.Weight) weight = append(weight, v.Weight)
} }
itype = list[comm.GetRandW(weight)].Key itype = list[comm.GetRandW(weight)].Key
//itype = 4 itype = 3
return return
} }
@ -146,17 +146,17 @@ func (this *Room) AiOperator() {
this.player2.Energy += v.CurEnergy this.player2.Energy += v.CurEnergy
v.CurEnergy = this.player2.Energy v.CurEnergy = this.player2.Energy
} }
for _, v := range szMap { // // for _, v := range szMap { //
fmt.Printf("================\n") // fmt.Printf("================\n")
var v1 int // var v1 int
for index := Width - 1; index >= 0; index-- { // for index := Width - 1; index >= 0; index-- {
for j := 0; j < Height; j++ { // for j := 0; j < Height; j++ {
v1 = index + j*7 // v1 = index + j*7
fmt.Printf("%d:%d ", v.Data[v1].Oid, v.Data[v1].Cid) // fmt.Printf("%d:%d ", v1, v.Data[v1].Cid)
} // }
fmt.Printf("\n") // fmt.Printf("\n")
} // }
} // }
// 广播消息 // 广播消息
if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{ if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
Mpadata: szMap, Mpadata: szMap,
@ -392,17 +392,17 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
this.round++ this.round++
} }
for _, v := range szMap { // // for _, v := range szMap { //
fmt.Printf("================\n") // fmt.Printf("================\n")
var v1 int // var v1 int
for index := Width - 1; index >= 0; index-- { // for index := Width - 1; index >= 0; index-- {
for j := 0; j < Height; j++ { // for j := 0; j < Height; j++ {
v1 = index + j*7 // v1 = index + j*7
fmt.Printf("%d:%d ", v.Data[v1].Oid, v.Data[v1].Cid) // fmt.Printf("%d:%d ", v1, v.Data[v1].Cid)
} // }
fmt.Printf("\n") // fmt.Printf("\n")
} // }
} // }
// 广播消息 // 广播消息
if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{ if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
Mpadata: szMap, Mpadata: szMap,

View File

@ -45,9 +45,7 @@ type MapData struct {
// 1~6随机一个数 // 1~6随机一个数
func (this *MapData) GetRandType() int32 { func (this *MapData) GetRandType() int32 {
return this.module.configure.GetGameNormalElem() // 权重随机
n, _ := rand.Int(rand.Reader, big.NewInt(6))
return int32(n.Int64() + 1)
} }
// 玩法带入 // 玩法带入
@ -80,6 +78,39 @@ func (this *MapData) CreateGride(count int) (girdes []*pb.GirdeData) {
return return
} }
// 生成自定义地图
func (this *MapData) SetMap() {
sz2 := []int32{
3, 1, 2, 2, 1, 3, 1,
5, 1, 2, 3, 1, 2, 2,
2, 4, 3, 4, 3, 1, 6,
1, 3, 3, 4, 2, 3, 6,
1, 5, 2, 5, 6, 1, 4,
6, 6, 3, 26, 3, 1, 3,
3, 3, 1, 3, 3, 2, 5,
}
var pos int
for index := Width - 1; index >= 0; index-- {
for j := 0; j < Height; j++ {
Color := sz2[pos]
Cid := sz2[pos]
if sz2[pos] > 6 { // 特殊元素
conf, err := this.module.configure.GetGameBlockByKey(sz2[pos])
if err == nil {
Color = conf.Color
Cid = conf.Key
this.Plat[index+j*Height].Special = conf.Type
}
}
this.Plat[index+j*Height].Color = Color
this.Plat[index+j*Height].Cid = Cid
pos++
}
}
this.CheckAndRefreshPlat()
// this.SetIndelibilityPlat()
}
// 初始化地图数据 // 初始化地图数据
func (this *MapData) InitMap(module *Entertainment, iType int32) { func (this *MapData) InitMap(module *Entertainment, iType int32) {
this.module = module this.module = module
@ -136,6 +167,7 @@ func (this *MapData) CheckSpecialElemChange(oldId, newId int32, color int32) (bS
this.Plat[oldId] = tmp this.Plat[oldId] = tmp
this.operElem = append(this.operElem, newId) this.operElem = append(this.operElem, newId)
this.operElem = append(this.operElem, oldId) this.operElem = append(this.operElem, oldId)
x = this.SpecialElem(int(oldId), this.Plat[oldId].Special) x = this.SpecialElem(int(oldId), this.Plat[oldId].Special)
xc := this.SpecialElem(int(newId), this.Plat[newId].Special) xc := this.SpecialElem(int(newId), this.Plat[newId].Special)
for k := range xc { for k := range xc {
@ -1137,6 +1169,9 @@ func (this *MapData) GetFireBoom(pos int, itype int32) (elem []int) {
// 特殊类型元素 统一处理 // 特殊类型元素 统一处理
func (this *MapData) SpecialElem(id int, s int32) (x map[int]struct{}) { func (this *MapData) SpecialElem(id int, s int32) (x map[int]struct{}) {
if s <= 0 {
return
}
x = make(map[int]struct{}) x = make(map[int]struct{})
if s == FourUType { // 4消上下类型 if s == FourUType { // 4消上下类型
@ -1155,6 +1190,7 @@ func (this *MapData) SpecialElem(id int, s int32) (x map[int]struct{}) {
x[v] = struct{}{} x[v] = struct{}{}
} }
} }
} else if s == BoomType { // 炸弹类型 带走周围一圈+ 上下左右 } else if s == BoomType { // 炸弹类型 带走周围一圈+ 上下左右
for _, key := range this.GetBoomElem(id) { for _, key := range this.GetBoomElem(id) {
x[key] = struct{}{} x[key] = struct{}{}
@ -1164,7 +1200,8 @@ func (this *MapData) SpecialElem(id int, s int32) (x map[int]struct{}) {
x[key] = struct{}{} x[key] = struct{}{}
} }
} }
this.Plat[id].Special = 0
x[id] = struct{}{}
for k := range x { for k := range x {
if k == id { if k == id {
continue continue