This commit is contained in:
meixiongfeng 2023-10-20 20:57:39 +08:00
parent a6aa603dc3
commit c8cf135258
8 changed files with 170 additions and 119 deletions

View File

@ -917,6 +917,7 @@ const (
Rtype234 TaskType = 234 // 完成多次捕羊大赛
Rtype235 TaskType = 235 // 指定X龙的等级达到Y级
Rtype236 TaskType = 236 // 购买X章的商店物品数量达到Y件
Rtype237 TaskType = 237 // 在梦境回廊内消耗X点体力
)
const (
MailLineEasy int32 = 1 // 简单

View File

@ -18,10 +18,12 @@ func (this *apiComp) OperatorCheck(session comm.IUserSession, req *pb.EntertainO
func (this *apiComp) Operator(session comm.IUserSession, req *pb.EntertainOperatorReq) (errdata *pb.ErrorData) {
this.module.gameMgr.RoomDistribute(req.Roomid, session, "operator", req)
if errdata = this.module.gameMgr.RoomDistribute(req.Roomid, session, "operator", req); errdata == nil {
// 操作消息返回
session.SendMsg(string(this.module.GetType()), "operator", &pb.EntertainOperatorResp{
Success: true,
})
}
return
}

View File

@ -1,10 +0,0 @@
package entertainment
// type Player struct {
// uid string
// operate int32 // 该谁操作
// score int32 // 玩家积分
// step int32 // 操作步骤
// status int32 // 状态
// session comm.IUserSession
// }

View File

@ -48,6 +48,7 @@ func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) {
if this.round > MaxRound*2 { // 游戏结束
this.GameOver()
return
}
this.operatetimer = timewheel.Add(time.Second*MaxTime, this.operateTimeOut) // 开启新的定时器
var szMap []*pb.MapData
@ -95,6 +96,8 @@ func (this *Room) AiTimeOut(task *timewheel.Task, args ...interface{}) {
curScore int32
szMap []*pb.MapData
)
this.module.Debugf("AI 操作\n")
this.player2.Ps--
if this.player2.Ps <= 0 { // 权限给下一个人
this.power = this.player1.Uid
@ -110,15 +113,16 @@ func (this *Room) AiTimeOut(task *timewheel.Task, args ...interface{}) {
if !bSwap {
this.module.Errorf("AiSwapGirde fialed")
}
szMap = append(szMap, &pb.MapData{
Data: this.chessboard.Plat,
})
if score, m := this.chessboard.CheckMap(); score > 0 {
if score, m, _ := this.chessboard.CheckMap(2); score > 0 {
curScore += score
szMap = append(szMap, m...)
}
this.player2.Score += curScore
szMap = append(szMap, &pb.MapData{
Data: this.chessboard.Plat,
CurSocre: 0,
})
// 清理旧的计时器 开启一个新的
if this.operatetimer != nil {
timewheel.Remove(this.operatetimer)
@ -147,20 +151,32 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
req := msg.(*pb.EntertainOperatorReq)
if session.GetUserId() != this.power { // 校验是不是你的权限
errdata = &pb.ErrorData{
Code: pb.ErrorCode_EntertainNoPower,
Title: pb.ErrorCode_EntertainNoPower.ToString(),
}
return
}
if this.operatetimer != nil {
timewheel.Remove(this.operatetimer)
}
// 交换元素
this.chessboard.SwapGirde(req.Curid, req.Targetid) // 交换格子
szMap = append(szMap, &pb.MapData{
Data: this.chessboard.Plat,
})
if score, m := this.chessboard.CheckMap(); score > 0 {
if b, _ := this.chessboard.SwapGirde(req.Curid, req.Targetid, 1); !b { // 交换格子
errdata = &pb.ErrorData{
Code: pb.ErrorCode_EntertainCantSwap, // 不能交换 直接返回
Title: pb.ErrorCode_EntertainCantSwap.ToString(),
}
return
}
if score, m, _ := this.chessboard.CheckMap(1); score > 0 {
curScore += score
szMap = append(szMap, m...)
}
szMap = append(szMap, &pb.MapData{
Data: this.chessboard.Plat,
CurSocre: 0,
})
//this.player2.Score += curScore
// 开启新的定时器
if this.operatetimer != nil {
@ -217,7 +233,7 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
},
Power: this.power,
Round: this.round,
}, session); err != nil {
}, this.szSession...); err != nil {
this.Errorln(err)
}
@ -229,14 +245,6 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
return
}
// 玩家操作
func (this *Room) Opertor(uid string, iType int32, old int32, new int32) (errdata *pb.ErrorData) {
if iType == 1 {
this.chessboard.SwapGirde(old, new) // 交换格子
}
return
}
func (this *Room) StartGame() (errdata *pb.ErrorData) {
if err := this.module.SendMsgToSession(string(this.module.GetType()), "startgame", &pb.EntertainStartGamePush{
@ -267,8 +275,8 @@ func (this *Room) GameOver() (errdata *pb.ErrorData) {
Mpadata: &pb.MapData{
Data: this.chessboard.Plat,
},
Power: "",
Power: "", // 清理权限
Round: this.round,
})
}, this.szSession...)
return
}

View File

@ -17,13 +17,6 @@ const (
FourLType = 2 // 4消左右类型
)
// type Girde struct {
// X int32 // x
// Y int32
// ID int32
// Itype int32
// }
type Girde struct {
oid int32 // 唯一ID
color int32 // 颜色
@ -70,12 +63,9 @@ func (this *MapData) InitMap(module *Entertainment) {
}
// 交换2个元素(参数 oid )
func (this *MapData) SwapGirde(oldId, newId int32) bool {
var (
bSwap bool // 能否交换
)
// x = int32(i/Width), y = int32(i%Height)
if (oldId%Height != Total-1 && oldId+1 == newId) ||
func (this *MapData) SwapGirde(oldId, newId int32, color int32) (bSwap bool, xCount int32) {
if (oldId%Height-1 < Total && oldId+1 == newId) ||
(oldId%Height > 0 && oldId-1 == newId) ||
(oldId+Width < Total && oldId+Width == newId) ||
(oldId-Width > 0 && oldId-Width == newId) {
@ -85,7 +75,8 @@ func (this *MapData) SwapGirde(oldId, newId int32) bool {
this.Plat[newId] = this.Plat[oldId]
this.Plat[oldId] = tmp
}
return bSwap
//this.CheckMap(color)
return
}
func (this *MapData) SetMap() {
@ -117,7 +108,7 @@ func (this *MapData) Debugf() {
}
// 检查5消
func (this *MapData) Check5X() (bEliminate bool, score int32) {
func (this *MapData) Check5X(color int32) (bEliminate bool, score int32, count int32) {
var xiaochu []int // 即将消除的key
for k, v := range this.Plat {
if v.Color == 0 {
@ -135,7 +126,7 @@ func (this *MapData) Check5X() (bEliminate bool, score int32) {
this.oid++
// 生成一个新的类型元素
conf, _ := this.module.configure.GetGameBlock(k1, FiveType)
if conf, err := this.module.configure.GetGameBlock(k1, FiveType); err != nil {
this.Plat[k+2] = &pb.GirdeData{
Oid: this.oid,
Color: k1,
@ -143,6 +134,9 @@ func (this *MapData) Check5X() (bEliminate bool, score int32) {
Score: conf.Score,
Special: conf.Type,
}
} else {
xiaochu = append(xiaochu, k+2)
}
xiaochu = append(xiaochu, []int{k, k + 1, k + 3, k + 4}...)
bEliminate = true
}
@ -158,7 +152,7 @@ func (this *MapData) Check5X() (bEliminate bool, score int32) {
this.oid++
// 生成一个新的类型元素
conf, _ := this.module.configure.GetGameBlock(k1, FiveType)
if conf, err := this.module.configure.GetGameBlock(k1, FiveType); err != nil {
this.Plat[k+2*Width] = &pb.GirdeData{
Oid: this.oid,
Color: k1,
@ -166,6 +160,10 @@ func (this *MapData) Check5X() (bEliminate bool, score int32) {
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}...)
bEliminate = true
@ -190,21 +188,27 @@ func (this *MapData) Check5X() (bEliminate bool, score int32) {
}
} else if s == FiveType { // 随机消除
}
} else { // 普通类型 直接消除
if this.Plat[id].Color == color {
count++
}
score += this.Plat[id].Score
this.Plat[id] = &pb.GirdeData{}
}
}
}
for _, v := range next {
if this.Plat[v].Color == color {
count++
}
score += this.Plat[v].Score
this.Plat[v] = &pb.GirdeData{}
}
return
}
func (this *MapData) Check4X() (bEliminate bool, score int32) {
func (this *MapData) Check4X(color int32) (bEliminate bool, score int32, count int32) {
var xiaochu []int // 即将消除的key
for k, v := range this.Plat {
if v.Color == 0 {
@ -222,7 +226,8 @@ func (this *MapData) Check4X() (bEliminate bool, score int32) {
this.oid++
// 生成一个新的类型元素
conf, _ := this.module.configure.GetGameBlock(k1, FourUType) // 上下类型
if this.module != nil {
if conf, err := this.module.configure.GetGameBlock(k1, FourUType); err != nil { // 上下类型
this.Plat[k+1] = &pb.GirdeData{
Oid: this.oid,
Color: k1,
@ -230,6 +235,11 @@ func (this *MapData) Check4X() (bEliminate bool, score int32) {
Score: conf.Score,
Special: conf.Type,
}
} else {
xiaochu = append(xiaochu, k+1)
}
}
xiaochu = append(xiaochu, k+1)
xiaochu = append(xiaochu, []int{k, k + 2, k + 3}...)
bEliminate = true
@ -243,15 +253,24 @@ func (this *MapData) Check4X() (bEliminate bool, score int32) {
if k1 == k2 && k3 == k4 && k2 == k3 {
this.oid++
if this.module != nil {
// 生成一个新的类型元素
conf, _ := this.module.configure.GetGameBlock(k1, FourLType) // 左右类型
this.Plat[k+1*Width] = &pb.GirdeData{
if conf, err := this.module.configure.GetGameBlock(k1, FourLType); err != nil { // 左右类型
this.Plat[k+Width] = &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)
}
}
xiaochu = append(xiaochu, k+Width)
xiaochu = append(xiaochu, []int{k, k + 2*Width, k + 3*Width}...)
bEliminate = true
@ -277,21 +296,27 @@ func (this *MapData) Check4X() (bEliminate bool, score int32) {
}
} else if s == FiveType { // 随机消除
}
} else { // 普通类型 直接消除
if this.Plat[id].Color == color {
count++
}
score += this.Plat[id].Score
this.Plat[id] = &pb.GirdeData{}
}
}
}
for _, v := range next {
if this.Plat[v].Color == color {
count++
}
score += this.Plat[v].Score
this.Plat[v] = &pb.GirdeData{}
}
return
}
func (this *MapData) Check3X() (bEliminate bool, score int32) {
func (this *MapData) Check3X(color int32) (bEliminate bool, score int32, count int32) {
var xiaochu []int // 即将消除的key
for k, v := range this.Plat {
if v.Color == 0 {
@ -305,7 +330,6 @@ func (this *MapData) Check3X() (bEliminate bool, score int32) {
k3 := this.Plat[k+2].Color
if k1 == k2 && k2 == k3 {
xiaochu = append(xiaochu, []int{k, k + 1, k + 2}...)
bEliminate = true
}
}
@ -316,7 +340,7 @@ func (this *MapData) Check3X() (bEliminate bool, score int32) {
k3 := this.Plat[k+2*Width].Color
if k1 == k2 && k2 == k3 {
xiaochu = append(xiaochu, []int{k, k + 1, k + 2}...)
xiaochu = append(xiaochu, []int{k, k + Width, k + 2*Width}...)
bEliminate = true
}
}
@ -340,14 +364,20 @@ func (this *MapData) Check3X() (bEliminate bool, score int32) {
}
} else if s == FiveType { // 随机消除
}
} else { // 普通类型 直接消除
if this.Plat[id].Color == color {
count++
}
score += this.Plat[id].Score
this.Plat[id] = &pb.GirdeData{}
}
}
}
for _, v := range next {
if this.Plat[v].Color == color {
count++
}
score += this.Plat[v].Score
this.Plat[v] = &pb.GirdeData{}
}
@ -355,32 +385,36 @@ func (this *MapData) Check3X() (bEliminate bool, score int32) {
}
// 校验地图可消除的 判断各组上面2个和右边两个是否三个相等
func (this *MapData) CheckMap() (score int32, szMap []*pb.MapData) {
for {
func (this *MapData) CheckMap(color int32) (score int32, szMap []*pb.MapData, count int32) {
var curScore int32
if bRet, s := this.Check5X(); !bRet {
for {
curScore = 0
this.DropGirde() // 先掉落
if bRet, s, c := this.Check5X(color); bRet {
fmt.Printf("=====检测消除5x===========\n")
curScore += s
count += c
}
if bRet, s := this.Check4X(); !bRet {
if bRet, s, c := this.Check4X(color); bRet {
fmt.Printf("=====检测消除4x===========\n")
curScore += s
count += c
}
if bRet, s := this.Check3X(); !bRet {
if bRet, s, c := this.Check3X(color); bRet {
fmt.Printf("=====检测消除3x===========\n")
curScore += s
count += c
}
score += curScore // 总分
if curScore == 0 {
break
}
this.DropGirde()
szMap = append(szMap, &pb.MapData{
Data: this.Plat,
CurSocre: curScore,
})
if curScore == 0 {
break
}
}
//this.Debugf()
return
}
@ -421,13 +455,13 @@ func (this *MapData) AiSwapGirde() bool {
for pos := 0; pos < Total; pos++ {
y := pos % Height
if y < Height-1 {
if this.SwapGirde(int32(pos), int32(pos+1)) {
if b, _ := this.SwapGirde(int32(pos), int32(pos+1), 2); b {
bSwap = true
break
}
}
if pos/Width+1 < Width {
if this.SwapGirde(int32(pos), int32(pos+Width)) {
if b, _ := this.SwapGirde(int32(pos), int32(pos+Width), 2); b {
bSwap = true
break
}

View File

@ -68,17 +68,6 @@ func NewService(ops ...rpcx.Option) core.IService {
}
func Test_Main(t *testing.T) {
m := new(entertainment.MapData)
m.InitMap(nil)
m.SetMap()
m.SwapGirde(1, 8)
m.DropGirde()
m.CheckMap()
m.SwapGirde(1, 11)
//fmt.Printf("得分:%d\n", m.CheckMap())
m.DropGirde()
flag.Parse()
s := NewService(
@ -93,6 +82,22 @@ func Test_Main(t *testing.T) {
entertainment.NewModule(),
)
}()
m := new(entertainment.MapData)
m.InitMap(nil)
m.SetMap()
m.SwapGirde(1, 8, 1)
m.DropGirde()
var szMap []*pb.MapData
if score, m, _ := m.CheckMap(1); score > 0 {
szMap = append(szMap, m...)
}
m.SwapGirde(1, 11, 1)
m.DropGirde()
m.CheckMap(1)
time.Sleep(time.Second * 2000)
//equipment.CloneEquipment()

View File

@ -241,6 +241,7 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.VikingChal
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype172, 1))
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype181, 1, req.BossId, req.Difficulty))
}
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype237, consumPs))
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype201, consumPs))
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype76, 1, req.BossId))
if bHelp {

View File

@ -450,6 +450,9 @@ const (
ErrorCode_ActivityCantReward ErrorCode = 5006 // 还不能领奖
//捕羊大赛的
ErrorCode_CapturesheepRankCloseed ErrorCode = 5101 //排位比赛不在开启时间内
// xxl
ErrorCode_EntertainCantSwap ErrorCode = 5201 //不能交换
ErrorCode_EntertainNoPower ErrorCode = 5202 //对方操作
)
// Enum value maps for ErrorCode.
@ -838,6 +841,8 @@ var (
5005: "ActivityInvalid",
5006: "ActivityCantReward",
5101: "CapturesheepRankCloseed",
5201: "EntertainCantSwap",
5202: "EntertainNoPower",
}
ErrorCode_value = map[string]int32{
"Success": 0,
@ -1223,6 +1228,8 @@ var (
"ActivityInvalid": 5005,
"ActivityCantReward": 5006,
"CapturesheepRankCloseed": 5101,
"EntertainCantSwap": 5201,
"EntertainNoPower": 5202,
}
)
@ -1257,7 +1264,7 @@ var File_errorcode_proto protoreflect.FileDescriptor
var file_errorcode_proto_rawDesc = []byte{
0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x2a, 0x82, 0x47, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12,
0x6f, 0x2a, 0xb1, 0x47, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12,
0x0b, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10,
0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x45, 0x78, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6f, 0x6e,
0x10, 0x01, 0x12, 0x11, 0x0a, 0x0d, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76,
@ -1825,8 +1832,11 @@ var file_errorcode_proto_rawDesc = []byte{
0x17, 0x0a, 0x12, 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x43, 0x61, 0x6e, 0x74, 0x52,
0x65, 0x77, 0x61, 0x72, 0x64, 0x10, 0x8e, 0x27, 0x12, 0x1c, 0x0a, 0x17, 0x43, 0x61, 0x70, 0x74,
0x75, 0x72, 0x65, 0x73, 0x68, 0x65, 0x65, 0x70, 0x52, 0x61, 0x6e, 0x6b, 0x43, 0x6c, 0x6f, 0x73,
0x65, 0x65, 0x64, 0x10, 0xed, 0x27, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x65, 0x65, 0x64, 0x10, 0xed, 0x27, 0x12, 0x16, 0x0a, 0x11, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x74,
0x61, 0x69, 0x6e, 0x43, 0x61, 0x6e, 0x74, 0x53, 0x77, 0x61, 0x70, 0x10, 0xd1, 0x28, 0x12, 0x15,
0x0a, 0x10, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x74, 0x61, 0x69, 0x6e, 0x4e, 0x6f, 0x50, 0x6f, 0x77,
0x65, 0x72, 0x10, 0xd2, 0x28, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (