上传代码
This commit is contained in:
parent
9609b8e72a
commit
d8fa73a48b
@ -94,10 +94,12 @@ func (this *configureComp) GetGameConsumeHero(heroid string) (conf *cfg.GameCons
|
||||
|
||||
func (this *configureComp) GetGameConsumeintegral(key int32) (conf *cfg.GameIntegralData, err error) {
|
||||
var (
|
||||
v interface{}
|
||||
v interface{}
|
||||
configure *cfg.GameIntegral
|
||||
ok bool
|
||||
)
|
||||
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() {
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
@ -34,7 +34,11 @@ func (this *modelComp) getEntertainmList(uid string) (result *pb.DBXXLData, err
|
||||
var (
|
||||
dbModel *db.DBModel
|
||||
)
|
||||
result = &pb.DBXXLData{}
|
||||
result = &pb.DBXXLData{
|
||||
|
||||
Reward: map[int32]int32{},
|
||||
Card: map[string]int32{},
|
||||
}
|
||||
if db.IsCross() {
|
||||
if tag, _, b := utils.UIdSplit(uid); b {
|
||||
if conn, err := db.ServerDBConn(tag); err == nil {
|
||||
|
@ -90,3 +90,30 @@ func (this *Entertainment) AddXxlCard(session comm.IUserSession, cards map[strin
|
||||
}
|
||||
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
|
||||
}
|
||||
|
@ -86,11 +86,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 ", v, this.Plat[index+j*Height].Color)
|
||||
//v = index + j*7
|
||||
fmt.Printf("%d:%d ", this.Plat[index+j*Height].Cid, this.Plat[index+j*Height].Color)
|
||||
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
@ -98,10 +98,11 @@ func (this *MapData) Debugf() {
|
||||
}
|
||||
|
||||
// 检查5消
|
||||
func (this *MapData) Check5X(color int32) (bEliminate bool, score int32, count int32) {
|
||||
var xiaochu []int // 即将消除的key
|
||||
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 {
|
||||
if v.Color == 0 {
|
||||
if v.Cid == 0 {
|
||||
continue
|
||||
}
|
||||
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
|
||||
|
||||
if k1 == k2 && k3 == k4 && k5 == k1 && k2 == k3 {
|
||||
if k1 == color {
|
||||
count++
|
||||
}
|
||||
this.oid++
|
||||
// 生成一个新的类型元素
|
||||
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)
|
||||
}
|
||||
|
||||
s[k+2] = FiveType
|
||||
|
||||
xiaochu = append(xiaochu, k+2)
|
||||
xiaochu = append(xiaochu, []int{k, k + 1, k + 3, k + 4}...)
|
||||
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
|
||||
|
||||
if k1 == k2 && k3 == k4 && k5 == k1 && k2 == k3 {
|
||||
if k1 == color {
|
||||
count++
|
||||
}
|
||||
|
||||
this.oid++
|
||||
// 生成一个新的类型元素
|
||||
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)
|
||||
this.Plat[k+2*Width] = &pb.GirdeData{
|
||||
Oid: this.oid,
|
||||
Color: k1,
|
||||
Cid: 1,
|
||||
Score: 1,
|
||||
Special: 1,
|
||||
}
|
||||
// 生成一个新的类型元素
|
||||
// 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}...)
|
||||
|
||||
@ -164,56 +158,21 @@ func (this *MapData) Check5X(color int32) (bEliminate bool, score int32, count i
|
||||
}
|
||||
}
|
||||
}
|
||||
var next []int
|
||||
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))
|
||||
for _, v := range xiaochu {
|
||||
this.Plat[v].Cid = 0
|
||||
}
|
||||
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 (
|
||||
newElem int // 生成的一个新的元素CID
|
||||
)
|
||||
|
||||
s = make(map[int]int)
|
||||
fmt.Printf("=====开始检测消除4x===========\n")
|
||||
|
||||
var xiaochu []int // 即将消除的key
|
||||
//var xiaochu []int // 即将消除的key
|
||||
for k, v := range this.Plat {
|
||||
if v.Color == 0 {
|
||||
if v.Cid == 0 {
|
||||
continue
|
||||
}
|
||||
x := int32(k % Height) // x
|
||||
@ -239,28 +198,9 @@ func (this *MapData) Check4X(color int32) (bEliminate bool, score int32, count i
|
||||
if newElem == 0 {
|
||||
newElem = k + 2 // 给个默认值
|
||||
}
|
||||
this.oid++
|
||||
// 生成一个新的类型元素
|
||||
|
||||
if conf, err := this.module.configure.GetGameBlock(k1, FourUType); 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, newElem)
|
||||
}
|
||||
if newElem == k+1 {
|
||||
xiaochu = append(xiaochu, []int{k, k + 2, k + 3}...)
|
||||
} else {
|
||||
xiaochu = append(xiaochu, []int{k, k + 1, k + 3}...)
|
||||
}
|
||||
s[newElem] = FourUType
|
||||
xiaochu = append(xiaochu, []int{k, k + 1, k + 2, k + 3}...)
|
||||
bEliminate = true
|
||||
}
|
||||
}
|
||||
@ -286,77 +226,25 @@ func (this *MapData) Check4X(color int32) (bEliminate bool, score int32, count i
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var next []int
|
||||
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))
|
||||
for _, v := range xiaochu {
|
||||
this.Plat[v].Cid = 0
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *MapData) Check3X(color int32) (bEliminate bool, score int32, count int32) {
|
||||
var xiaochu []int // 即将消除的key
|
||||
func (this *MapData) Check3X() (bEliminate bool, xiaochu []int) {
|
||||
//var xiaochu []int // 即将消除的key
|
||||
for k, v := range this.Plat {
|
||||
if v.Color == 0 {
|
||||
if v.Cid == 0 {
|
||||
continue
|
||||
}
|
||||
x := int32(k % Height) // x
|
||||
@ -382,43 +270,8 @@ func (this *MapData) Check3X(color int32) (bEliminate bool, score int32, count i
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var next []int
|
||||
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))
|
||||
for _, v := range xiaochu {
|
||||
this.Plat[v].Cid = 0
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -426,26 +279,87 @@ func (this *MapData) Check3X(color int32) (bEliminate bool, score int32, count i
|
||||
// 校验地图可消除的 判断各组上面2个和右边两个是否三个相等
|
||||
// xc 判断用来是否加体力
|
||||
func (this *MapData) CheckMap(color int32, bSkill bool) (szMap []*pb.MapData, xc bool) {
|
||||
var curScore int32
|
||||
var energy int32
|
||||
var (
|
||||
//tXiaochu []int
|
||||
tXiaochu map[int]struct{}
|
||||
curScore int32
|
||||
energy int32
|
||||
new map[int]int
|
||||
x map[int]struct{}
|
||||
)
|
||||
|
||||
for {
|
||||
new = make(map[int]int)
|
||||
x = make(map[int]struct{})
|
||||
tXiaochu = make(map[int]struct{})
|
||||
curScore = 0
|
||||
energy = 0
|
||||
if bRet, s, c := this.Check5X(color); bRet {
|
||||
curScore += s
|
||||
energy += c
|
||||
if bEliminate, xiaochu, s := this.Check5X(); bEliminate {
|
||||
for _, v := range xiaochu {
|
||||
tXiaochu[v] = struct{}{}
|
||||
}
|
||||
for k, v := range s {
|
||||
new[k] = v
|
||||
}
|
||||
xc = true // 只要有 4x 5x 就标记ture
|
||||
}
|
||||
if bRet, s, c := this.Check4X(color); bRet {
|
||||
curScore += s
|
||||
energy += c
|
||||
xc = true
|
||||
if bEliminate, xiaochu, s := this.Check4X(); bEliminate {
|
||||
for _, v := range xiaochu {
|
||||
tXiaochu[v] = struct{}{}
|
||||
}
|
||||
for k, v := range s {
|
||||
new[k] = v
|
||||
}
|
||||
xc = true // 只要有 4x 5x 就标记ture
|
||||
}
|
||||
if bRet, s, c := this.Check3X(color); bRet {
|
||||
curScore += s
|
||||
energy += c
|
||||
if bEliminate, xiaochu := this.Check3X(); bEliminate {
|
||||
for _, v := range xiaochu {
|
||||
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 !bSkill {
|
||||
energy = 0
|
||||
@ -455,6 +369,7 @@ func (this *MapData) CheckMap(color int32, bSkill bool) (szMap []*pb.MapData, xc
|
||||
CurSocre: curScore,
|
||||
CurEnergy: energy,
|
||||
})
|
||||
this.Debugf()
|
||||
}
|
||||
|
||||
// 检查掉落
|
||||
@ -472,12 +387,12 @@ func (this *MapData) DropGirde() bool {
|
||||
for i := 0; i < Width; i++ {
|
||||
for j := 0; j < Height; j++ {
|
||||
index := i*Width + j
|
||||
if this.Plat[index].Color == 0 { // 说明这列有空
|
||||
if this.Plat[index].Cid == 0 { // 说明这列有空
|
||||
bDrop = true
|
||||
var add int
|
||||
for m := j + 1; m < Height; m++ {
|
||||
k1 := i*Width + m
|
||||
if this.Plat[k1].Color != 0 {
|
||||
if this.Plat[k1].Cid != 0 {
|
||||
this.Plat[index] = this.Plat[k1]
|
||||
index++
|
||||
add++
|
||||
@ -491,7 +406,7 @@ func (this *MapData) DropGirde() bool {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//this.Debugf()
|
||||
return bDrop
|
||||
}
|
||||
func (this *MapData) GetPalatData() (data []*pb.GirdeData) {
|
||||
|
@ -84,22 +84,26 @@ func Test_Main(t *testing.T) {
|
||||
}()
|
||||
m := new(entertainment.MapData)
|
||||
m.InitMap(nil)
|
||||
for i := 0; i < 100; i++ {
|
||||
m := new(entertainment.MapData)
|
||||
m.InitMap(nil)
|
||||
//m.SetMap()
|
||||
m.SetIndelibilityPlat()
|
||||
d, _ := m.CheckMap(0, true)
|
||||
if len(d) > 0 {
|
||||
fmt.Println("===========有消除")
|
||||
m.Debugf()
|
||||
}
|
||||
m.SetMap()
|
||||
m.SwapGirde(1, 8)
|
||||
m.CheckMap(1, false)
|
||||
m.Debugf()
|
||||
// for i := 0; i < 100; i++ {
|
||||
// m := new(entertainment.MapData)
|
||||
// m.InitMap(nil)
|
||||
// //m.SetMap()
|
||||
// m.SetIndelibilityPlat()
|
||||
// d, _ := m.CheckMap(0, true)
|
||||
// if len(d) > 0 {
|
||||
// fmt.Println("===========有消除")
|
||||
// m.Debugf()
|
||||
// }
|
||||
|
||||
if m.CheckAndRefreshPlat() {
|
||||
m.Debugf()
|
||||
fmt.Println("xxxx")
|
||||
}
|
||||
}
|
||||
// if m.CheckAndRefreshPlat() {
|
||||
// m.Debugf()
|
||||
// fmt.Println("xxxx")
|
||||
// }
|
||||
// }
|
||||
|
||||
//var szMap []*pb.MapData
|
||||
// if bSwap, m := m.AiSwapGirde(); bSwap {
|
||||
|
Loading…
Reference in New Issue
Block a user