英雄技能

This commit is contained in:
meixiongfeng 2023-11-01 21:08:55 +08:00
parent 03b8514aee
commit cbf5cd8f3f
3 changed files with 75 additions and 44 deletions

View File

@ -241,7 +241,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
} }
if this.player1.Energy >= conf.Skillload { if this.player1.Energy >= conf.Skillload {
this.player1.Energy = 0 // 清零 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...) szMap = append(szMap, m...)
} else { } else {
szMap = append(szMap, &pb.MapData{ 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 { if this.player2.Energy >= conf.Skillload {
this.player2.Energy = 0 // 清零 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...) szMap = append(szMap, m...)
} else { } else {
szMap = append(szMap, &pb.MapData{ szMap = append(szMap, &pb.MapData{

View File

@ -89,11 +89,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 ", this.Plat[index+j*Height].Oid, this.Plat[index+j*Height].Cid) fmt.Printf("%d:%d ", v, this.Plat[index+j*Height].Cid)
} }
fmt.Printf("\n") fmt.Printf("\n")
@ -372,7 +372,7 @@ func (this *MapData) CheckMap(color int32, bSkill bool) (szMap []*pb.MapData, xc
} else if s == FiveType { // 随机消除 } else if s == FiveType { // 随机消除
// 获取配置 // 获取配置
if c, _ := this.module.configure.GetGameBlock(this.Plat[id].Color, FiveType); c != nil { 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...) //szMap = append(szMap, sz...)
for key := range xc { for key := range xc {
x[key] = struct{}{} x[key] = struct{}{}
@ -499,56 +499,85 @@ func (this *MapData) AiSwapGirde() (szMap []*pb.MapData, oid1 int32, oid2 int32,
} }
// 释放技能 技能id 和参数 // 释放技能 技能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 ( var (
skillScore int32 // 技能获得的分数 skillScore int32 // 技能获得的分数
skillEnergy int32 // 技能获得的能量 skillEnergy int32 // 技能获得的能量
ids []int
) )
if skillid == 1 { // 随机消除盘面上X个方块 if skillid == 1 { // 随机消除盘面上X个方块
x = make(map[int]struct{}) x = make(map[int]struct{})
ids := utils.RandomNumbers(0, Total-1, int(value)) ids = utils.RandomNumbers(0, Total-1, int(value))
for _, id := range ids {
s := this.Plat[id].Special } else if skillid == 2 { // 找到pos 位置的所有方块
if s != 0 { x := int(pos / Width)
if s == FourUType { // 4消上下类型 y := int(pos % Height)
for i := 0; i < Height; i++ { // id 的一条线位置 for i := 1; i < 7; i++ {
x[(id/Width)*Height+i] = struct{}{}
} if x-i >= 0 && y+i < Height { // 左上
} else if s == FourLType { // 左右类型 ids = append(ids, (x-i)*Width+(y+i))
for i := 0; i < Width; i++ { // id 的一条线位置 }
x[id%Height+i*Width] = struct{}{} if x-i >= 0 && y-i >= 0 { // 左下
} ids = append(ids, (x-i)*Width+(y-i))
} else if s == FiveType { // 随机消除 }
// 获取配置
if c, _ := this.module.configure.GetGameBlock(this.Plat[id].Color, FiveType); c != nil { if x+i < Width && y+i < Height { // 右上
if xc, _ := this.SkillUp(color, 1, c.Value, false); len(xc) > 0 { // 递归调用 ids = append(ids, (x+i)*Width+(y+i))
for key := range xc { }
x[key] = struct{}{} 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 { x[id] = struct{}{}
for key := range x { }
if this.Plat[key].Color == color { if bDrop {
skillEnergy += 1 for key := range x {
} if this.Plat[key].Color == color {
skillScore += this.Plat[key].Score skillEnergy += 1
this.Plat[key] = &pb.GirdeData{}
} }
if this.DropGirde() { skillScore += this.Plat[key].Score
szMap = append(szMap, &pb.MapData{ this.Plat[key] = &pb.GirdeData{}
Data: this.GetPalatData(), }
CurSocre: skillScore, if this.DropGirde() {
CurEnergy: skillEnergy, szMap = append(szMap, &pb.MapData{
}) Data: this.GetPalatData(),
if list, _ := this.CheckMap(color, false); len(list) > 0 { CurSocre: skillScore,
szMap = append(szMap, list...) CurEnergy: skillEnergy,
} })
if list, _ := this.CheckMap(color, false); len(list) > 0 {
szMap = append(szMap, list...)
} }
} }
} }

View File

@ -84,6 +84,8 @@ func Test_Main(t *testing.T) {
}() }()
m := new(entertainment.MapData) m := new(entertainment.MapData)
m.InitMap(nil) m.InitMap(nil)
m.Debugf()
m.SkillUp(24, 1, 2, 7, true)
// m.SetMap() // m.SetMap()
b := m.CheckAndRefreshPlat() b := m.CheckAndRefreshPlat()
fmt.Printf("xxxx%v", b) fmt.Printf("xxxx%v", b)
@ -112,7 +114,7 @@ func Test_Main(t *testing.T) {
// if bSwap, m := m.AiSwapGirde(); bSwap { // if bSwap, m := m.AiSwapGirde(); bSwap {
// szMap = append(szMap, m...) // szMap = append(szMap, m...)
// } // }
m.SkillUp(1, 1, 7, true) m.SkillUp(0, 1, 2, 7, true)
m.SwapGirde(1, 8) m.SwapGirde(1, 8)
//m.CheckMap(1) //m.CheckMap(1)