上传代码

This commit is contained in:
meixiongfeng 2023-10-27 18:25:49 +08:00
parent 9609b8e72a
commit d8fa73a48b
5 changed files with 184 additions and 228 deletions

View File

@ -94,10 +94,12 @@ func (this *configureComp) GetGameConsumeHero(heroid string) (conf *cfg.GameCons
func (this *configureComp) GetGameConsumeintegral(key int32) (conf *cfg.GameIntegralData, err error) { func (this *configureComp) GetGameConsumeintegral(key int32) (conf *cfg.GameIntegralData, err error) {
var ( var (
v interface{} v interface{}
configure *cfg.GameIntegral
ok bool
) )
if v, err = this.GetConfigure(game_integral); err == nil { if v, err = this.GetConfigure(game_integral); err == nil {
if configure, ok := v.(*cfg.GameIntegral); ok { if configure, ok = v.(*cfg.GameIntegral); ok {
for pos, v := range configure.GetDataList() { for pos, v := range configure.GetDataList() {
if v.Key >= key { if v.Key >= key {
@ -111,6 +113,10 @@ func (this *configureComp) GetGameConsumeintegral(key int32) (conf *cfg.GameInte
} }
} }
} }
if configure.GetDataList()[len(configure.GetDataList())-1].Key < key { // 设置最大值
conf = configure.GetDataList()[len(configure.GetDataList())-1]
return
}
err = comm.NewNotFoundConfErr(moduleName, game_integral, key) err = comm.NewNotFoundConfErr(moduleName, game_integral, key)
return return
} }

View File

@ -34,7 +34,11 @@ func (this *modelComp) getEntertainmList(uid string) (result *pb.DBXXLData, err
var ( var (
dbModel *db.DBModel dbModel *db.DBModel
) )
result = &pb.DBXXLData{} result = &pb.DBXXLData{
Reward: map[int32]int32{},
Card: map[string]int32{},
}
if db.IsCross() { if db.IsCross() {
if tag, _, b := utils.UIdSplit(uid); b { if tag, _, b := utils.UIdSplit(uid); b {
if conn, err := db.ServerDBConn(tag); err == nil { if conn, err := db.ServerDBConn(tag); err == nil {

View File

@ -90,3 +90,30 @@ func (this *Entertainment) AddXxlCard(session comm.IUserSession, cards map[strin
} }
return return
} }
// 消耗一张卡
func (this *Entertainment) ConsumXxlCard(session comm.IUserSession, card string) (errdata *pb.ErrorData) {
var (
result *pb.DBXXLData
err error
)
if result, err = this.model.getEntertainmList(session.GetUserId()); err != nil {
return
}
if _, ok := result.Card[card]; ok {
if result.Card[card] <= 0 {
return
}
result.Card[card] -= 1
this.model.modifyEntertainmList(session.GetUserId(), map[string]interface{}{
"card": result.Card,
})
}
session.SendMsg(string(this.GetType()), "titlelist", &pb.EntertainChangePush{
Card: result.Card,
})
return
}

View File

@ -86,11 +86,11 @@ func (this *MapData) SwapGirde(oldId, newId int32) (bSwap bool) {
func (this *MapData) Debugf() { func (this *MapData) Debugf() {
fmt.Printf("================\n") fmt.Printf("================\n")
var v int //var v 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++ {
v = index + j*7 //v = index + j*7
fmt.Printf("%d:%d ", v, this.Plat[index+j*Height].Color) fmt.Printf("%d:%d ", this.Plat[index+j*Height].Cid, this.Plat[index+j*Height].Color)
} }
fmt.Printf("\n") fmt.Printf("\n")
@ -98,10 +98,11 @@ func (this *MapData) Debugf() {
} }
// 检查5消 // 检查5消
func (this *MapData) Check5X(color int32) (bEliminate bool, score int32, count int32) { func (this *MapData) Check5X() (bEliminate bool, xiaochu []int, s map[int]int) {
var xiaochu []int // 即将消除的key //var xiaochu []int // 即将消除的key
s = make(map[int]int)
for k, v := range this.Plat { for k, v := range this.Plat {
if v.Color == 0 { if v.Cid == 0 {
continue continue
} }
x := int32(k % Height) // x x := int32(k % Height) // x
@ -113,22 +114,10 @@ func (this *MapData) Check5X(color int32) (bEliminate bool, score int32, count i
k5 := this.Plat[k+4].Color k5 := this.Plat[k+4].Color
if k1 == k2 && k3 == k4 && k5 == k1 && k2 == k3 { if k1 == k2 && k3 == k4 && k5 == k1 && k2 == k3 {
if k1 == color {
count++ s[k+2] = FiveType
}
this.oid++ xiaochu = append(xiaochu, k+2)
// 生成一个新的类型元素
if conf, err := this.module.configure.GetGameBlock(k1, FiveType); err == nil {
this.Plat[k+2] = &pb.GirdeData{
Oid: this.oid,
Color: k1,
Cid: conf.Key,
Score: conf.Score,
Special: conf.Type,
}
} else {
xiaochu = append(xiaochu, k+2)
}
xiaochu = append(xiaochu, []int{k, k + 1, k + 3, k + 4}...) xiaochu = append(xiaochu, []int{k, k + 1, k + 3, k + 4}...)
bEliminate = true bEliminate = true
} }
@ -141,22 +130,27 @@ func (this *MapData) Check5X(color int32) (bEliminate bool, score int32, count i
k5 := this.Plat[k+4*Width].Color k5 := this.Plat[k+4*Width].Color
if k1 == k2 && k3 == k4 && k5 == k1 && k2 == k3 { if k1 == k2 && k3 == k4 && k5 == k1 && k2 == k3 {
if k1 == color {
count++
}
this.oid++ this.oid++
// 生成一个新的类型元素 this.Plat[k+2*Width] = &pb.GirdeData{
if conf, err := this.module.configure.GetGameBlock(k1, FiveType); err == nil { Oid: this.oid,
this.Plat[k+2*Width] = &pb.GirdeData{ Color: k1,
Oid: this.oid, Cid: 1,
Color: k1, Score: 1,
Cid: conf.Key, Special: 1,
Score: conf.Score,
Special: conf.Type,
}
} else {
xiaochu = append(xiaochu, k+2*Width)
} }
// 生成一个新的类型元素
// if conf, err := this.module.configure.GetGameBlock(k1, FiveType); err == nil {
// this.Plat[k+2*Width] = &pb.GirdeData{
// Oid: this.oid,
// Color: k1,
// Cid: conf.Key,
// Score: conf.Score,
// Special: conf.Type,
// }
// } else {
// xiaochu = append(xiaochu, k+2*Width)
// }
xiaochu = append(xiaochu, []int{k, k + Width, k + 3*Width, k + 4*Width}...) xiaochu = append(xiaochu, []int{k, k + Width, k + 3*Width, k + 4*Width}...)
@ -164,56 +158,21 @@ func (this *MapData) Check5X(color int32) (bEliminate bool, score int32, count i
} }
} }
} }
var next []int for _, v := range xiaochu {
for _, id := range xiaochu { this.Plat[v].Cid = 0
if s := this.Plat[id].Special; s != 0 {
if s == FourUType { // 4消上下类型
for i := 0; i < Total; i++ {
if id/Height == i/Height {
next = append(next, i)
}
}
next = append(next, 1)
} else if s == FourLType { // 左右类型
for i := 0; i < Total; i++ {
if id%Height == i%Height {
next = append(next, i)
}
}
} else if s == FiveType { // 随机消除
}
} else { // 普通类型 直接消除
if this.Plat[id].Color == color {
count++
}
score += this.Plat[id].Score
this.Plat[id] = &pb.GirdeData{}
this.operElem = append(this.operElem, int32(id))
}
}
for _, v := range next {
if this.Plat[v].Color == color {
count++
}
score += this.Plat[v].Score
this.Plat[v] = &pb.GirdeData{}
this.operElem = append(this.operElem, int32(v))
} }
return return
} }
func (this *MapData) Check4X(color int32) (bEliminate bool, score int32, count int32) { func (this *MapData) Check4X() (bEliminate bool, xiaochu []int, s map[int]int) {
var ( var (
newElem int // 生成的一个新的元素CID newElem int // 生成的一个新的元素CID
) )
s = make(map[int]int)
fmt.Printf("=====开始检测消除4x===========\n") fmt.Printf("=====开始检测消除4x===========\n")
//var xiaochu []int // 即将消除的key
var xiaochu []int // 即将消除的key
for k, v := range this.Plat { for k, v := range this.Plat {
if v.Color == 0 { if v.Cid == 0 {
continue continue
} }
x := int32(k % Height) // x x := int32(k % Height) // x
@ -239,28 +198,9 @@ func (this *MapData) Check4X(color int32) (bEliminate bool, score int32, count i
if newElem == 0 { if newElem == 0 {
newElem = k + 2 // 给个默认值 newElem = k + 2 // 给个默认值
} }
this.oid++
// 生成一个新的类型元素
if conf, err := this.module.configure.GetGameBlock(k1, FourUType); err == nil { // 上下类型 s[newElem] = FourUType
this.Plat[newElem] = &pb.GirdeData{ xiaochu = append(xiaochu, []int{k, k + 1, k + 2, k + 3}...)
Oid: this.oid,
Color: k1,
Cid: conf.Key,
Score: conf.Score,
Special: conf.Type,
}
if k1 == color {
count++
}
} else {
xiaochu = append(xiaochu, newElem)
}
if newElem == k+1 {
xiaochu = append(xiaochu, []int{k, k + 2, k + 3}...)
} else {
xiaochu = append(xiaochu, []int{k, k + 1, k + 3}...)
}
bEliminate = true bEliminate = true
} }
} }
@ -286,77 +226,25 @@ func (this *MapData) Check4X(color int32) (bEliminate bool, score int32, count i
newElem = k + 2*Width // 给个默认值 newElem = k + 2*Width // 给个默认值
} }
this.oid++ s[newElem] = FourLType
xiaochu = append(xiaochu, k+Width)
xiaochu = append(xiaochu, []int{k, k + Width, k + 2*Width, k + 3*Width}...)
// 生成一个新的类型元素
if conf, err := this.module.configure.GetGameBlock(k1, FourLType); err == nil { // 左右类型
this.Plat[newElem] = &pb.GirdeData{
Oid: this.oid,
Color: k1,
Cid: conf.Key,
Score: conf.Score,
Special: conf.Type,
}
if k1 == color {
count++
}
} else {
xiaochu = append(xiaochu, k+Width)
}
if newElem == k+Width {
xiaochu = append(xiaochu, []int{k, k + 2*Width, k + 3*Width}...)
} else {
xiaochu = append(xiaochu, []int{k, k + Width, k + 3*Width}...)
}
bEliminate = true bEliminate = true
} }
} }
} }
var next []int for _, v := range xiaochu {
for _, id := range xiaochu { this.Plat[v].Cid = 0
if s := this.Plat[id].Special; s != 0 {
if s == FourUType { // 4消上下类型
for i := 0; i < Total; i++ {
if id/Height == i/Height {
next = append(next, i)
}
}
next = append(next, 1)
} else if s == FourLType { // 左右类型
for i := 0; i < Total; i++ {
if id%Height == i%Height {
next = append(next, i)
}
}
} else if s == FiveType { // 随机消除
}
} else { // 普通类型 直接消除
if this.Plat[id].Color == color {
count++
}
score += this.Plat[id].Score
this.Plat[id] = &pb.GirdeData{}
this.operElem = append(this.operElem, int32(id))
}
}
for _, v := range next {
if this.Plat[v].Color == color {
count++
}
score += this.Plat[v].Score
this.Plat[v] = &pb.GirdeData{}
this.operElem = append(this.operElem, int32(v))
} }
return return
} }
func (this *MapData) Check3X(color int32) (bEliminate bool, score int32, count int32) { func (this *MapData) Check3X() (bEliminate bool, xiaochu []int) {
var xiaochu []int // 即将消除的key //var xiaochu []int // 即将消除的key
for k, v := range this.Plat { for k, v := range this.Plat {
if v.Color == 0 { if v.Cid == 0 {
continue continue
} }
x := int32(k % Height) // x x := int32(k % Height) // x
@ -382,43 +270,8 @@ func (this *MapData) Check3X(color int32) (bEliminate bool, score int32, count i
} }
} }
} }
for _, v := range xiaochu {
var next []int this.Plat[v].Cid = 0
for _, id := range xiaochu {
if s := this.Plat[id].Special; s != 0 {
if s == FourUType { // 4消上下类型
for i := 0; i < Total; i++ {
if id/Height == i/Height {
next = append(next, i)
}
}
next = append(next, 1)
} else if s == FourLType { // 左右类型
for i := 0; i < Total; i++ {
if id%Height == i%Height {
next = append(next, i)
}
}
} else if s == FiveType { // 随机消除
}
} else { // 普通类型 直接消除
if this.Plat[id].Color == color {
count++
}
score += this.Plat[id].Score
this.Plat[id] = &pb.GirdeData{}
this.operElem = append(this.operElem, int32(id))
}
}
for _, v := range next {
if this.Plat[v].Color == color {
count++
}
score += this.Plat[v].Score
this.Plat[v] = &pb.GirdeData{}
this.operElem = append(this.operElem, int32(v))
} }
return return
} }
@ -426,26 +279,87 @@ func (this *MapData) Check3X(color int32) (bEliminate bool, score int32, count i
// 校验地图可消除的 判断各组上面2个和右边两个是否三个相等 // 校验地图可消除的 判断各组上面2个和右边两个是否三个相等
// xc 判断用来是否加体力 // xc 判断用来是否加体力
func (this *MapData) CheckMap(color int32, bSkill bool) (szMap []*pb.MapData, xc bool) { func (this *MapData) CheckMap(color int32, bSkill bool) (szMap []*pb.MapData, xc bool) {
var curScore int32 var (
var energy int32 //tXiaochu []int
tXiaochu map[int]struct{}
curScore int32
energy int32
new map[int]int
x map[int]struct{}
)
for { for {
new = make(map[int]int)
x = make(map[int]struct{})
tXiaochu = make(map[int]struct{})
curScore = 0 curScore = 0
energy = 0 energy = 0
if bRet, s, c := this.Check5X(color); bRet { if bEliminate, xiaochu, s := this.Check5X(); bEliminate {
curScore += s for _, v := range xiaochu {
energy += c tXiaochu[v] = struct{}{}
}
for k, v := range s {
new[k] = v
}
xc = true // 只要有 4x 5x 就标记ture xc = true // 只要有 4x 5x 就标记ture
} }
if bRet, s, c := this.Check4X(color); bRet { if bEliminate, xiaochu, s := this.Check4X(); bEliminate {
curScore += s for _, v := range xiaochu {
energy += c tXiaochu[v] = struct{}{}
xc = true }
for k, v := range s {
new[k] = v
}
xc = true // 只要有 4x 5x 就标记ture
} }
if bRet, s, c := this.Check3X(color); bRet { if bEliminate, xiaochu := this.Check3X(); bEliminate {
curScore += s for _, v := range xiaochu {
energy += c tXiaochu[v] = struct{}{}
}
} }
for id := range tXiaochu {
if _, ok := new[id]; ok {
if this.Plat[id].Color == color {
energy++
}
curScore += this.Plat[id].Score
if conf, err := this.module.configure.GetGameBlock(this.Plat[id].Color, int32(new[id])); err == nil {
this.oid++ // 生成一个新的类型元素
this.Plat[id] = &pb.GirdeData{
Oid: this.oid,
Color: this.Plat[id].Color,
Cid: conf.Key,
Score: conf.Score,
Special: conf.Type,
}
}
continue
}
if s := this.Plat[id].Special; 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 { // 随机消除
}
}
x[id] = struct{}{}
}
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() { if this.DropGirde() {
if !bSkill { if !bSkill {
energy = 0 energy = 0
@ -455,6 +369,7 @@ func (this *MapData) CheckMap(color int32, bSkill bool) (szMap []*pb.MapData, xc
CurSocre: curScore, CurSocre: curScore,
CurEnergy: energy, CurEnergy: energy,
}) })
this.Debugf()
} }
// 检查掉落 // 检查掉落
@ -472,12 +387,12 @@ func (this *MapData) DropGirde() bool {
for i := 0; i < Width; i++ { for i := 0; i < Width; i++ {
for j := 0; j < Height; j++ { for j := 0; j < Height; j++ {
index := i*Width + j index := i*Width + j
if this.Plat[index].Color == 0 { // 说明这列有空 if this.Plat[index].Cid == 0 { // 说明这列有空
bDrop = true bDrop = true
var add int var add int
for m := j + 1; m < Height; m++ { for m := j + 1; m < Height; m++ {
k1 := i*Width + m k1 := i*Width + m
if this.Plat[k1].Color != 0 { if this.Plat[k1].Cid != 0 {
this.Plat[index] = this.Plat[k1] this.Plat[index] = this.Plat[k1]
index++ index++
add++ add++
@ -491,7 +406,7 @@ func (this *MapData) DropGirde() bool {
} }
} }
} }
//this.Debugf()
return bDrop return bDrop
} }
func (this *MapData) GetPalatData() (data []*pb.GirdeData) { func (this *MapData) GetPalatData() (data []*pb.GirdeData) {

View File

@ -84,22 +84,26 @@ func Test_Main(t *testing.T) {
}() }()
m := new(entertainment.MapData) m := new(entertainment.MapData)
m.InitMap(nil) m.InitMap(nil)
for i := 0; i < 100; i++ { m.SetMap()
m := new(entertainment.MapData) m.SwapGirde(1, 8)
m.InitMap(nil) m.CheckMap(1, false)
//m.SetMap() m.Debugf()
m.SetIndelibilityPlat() // for i := 0; i < 100; i++ {
d, _ := m.CheckMap(0, true) // m := new(entertainment.MapData)
if len(d) > 0 { // m.InitMap(nil)
fmt.Println("===========有消除") // //m.SetMap()
m.Debugf() // m.SetIndelibilityPlat()
} // d, _ := m.CheckMap(0, true)
// if len(d) > 0 {
// fmt.Println("===========有消除")
// m.Debugf()
// }
if m.CheckAndRefreshPlat() { // if m.CheckAndRefreshPlat() {
m.Debugf() // m.Debugf()
fmt.Println("xxxx") // fmt.Println("xxxx")
} // }
} // }
//var szMap []*pb.MapData //var szMap []*pb.MapData
// if bSwap, m := m.AiSwapGirde(); bSwap { // if bSwap, m := m.AiSwapGirde(); bSwap {