三消优化

This commit is contained in:
meixiongfeng 2023-11-17 18:27:46 +08:00
parent e2f4c3cc04
commit 853742995d
2 changed files with 133 additions and 106 deletions

View File

@ -175,7 +175,8 @@ func (this *Room) AiOperator() {
} }
this.curPower = this.NexPower this.curPower = this.NexPower
if this.RoomType == 2 && this.curPower == this.player2.Userinfo.Uid { if this.RoomType == 2 && this.curPower == this.player2.Userinfo.Uid {
this.AiOperator() //this.AiOperator()
this.AutoOperator(this.player2)
} }
} }
@ -204,86 +205,9 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
color = 2 color = 2
} }
if req.Itype == 1 { //释放技能 if req.Itype == 1 { //释放技能
// 能量校验 if errdata = this.UserSkillUp(color, req.Curid); errdata != nil {
if color == 1 { // 玩家1 放技能
conf, err := this.module.configure.GetGameConsumeHero(this.player1.Cardid)
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_EntertainNoHeroSkill,
Title: pb.ErrorCode_EntertainNoHeroSkill.ToString(),
}
return return
} }
if this.player1.Energy >= conf.Skillload {
this.player1.Energy = 0 // 清零
if _, m := this.chessboard.SkillUp(req.Curid, color, conf.Skilleffect, conf.Skillvalue, true); len(m) > 0 {
szMap = append(szMap, m...)
} else {
szMap = append(szMap, &pb.MapData{
Data: this.chessboard.GetPalatData(),
})
}
for _, v := range szMap {
curScore += v.CurSocre
this.player1.Score += v.CurSocre
v.CurSocre = this.player1.Score
}
} else {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_EntertainNoEnergy,
Title: pb.ErrorCode_EntertainNoEnergy.ToString(),
}
return
}
this.NexPower = this.curPower
} else {
conf, err := this.module.configure.GetGameConsumeHero(this.player2.Cardid)
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_EntertainNoHeroSkill,
Title: pb.ErrorCode_EntertainNoHeroSkill.ToString(),
}
return
}
if this.player2.Energy >= conf.Skillload {
this.player2.Energy = 0 // 清零
if _, m := this.chessboard.SkillUp(0, color, conf.Skilleffect, conf.Skillvalue, true); len(m) > 0 {
szMap = append(szMap, m...)
} else {
szMap = append(szMap, &pb.MapData{
Data: this.chessboard.GetPalatData(),
})
}
for _, v := range szMap {
curScore += v.CurSocre
this.player2.Score += v.CurSocre
v.CurSocre = this.player2.Score
}
} else {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_EntertainNoEnergy,
Title: pb.ErrorCode_EntertainNoEnergy.ToString(),
}
return
}
this.NexPower = this.curPower
}
if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
Mpadata: szMap,
Power: this.NexPower,
Curpower: this.curPower,
Score: curScore,
Round: this.round,
User1: this.player1,
User2: this.player2,
Itype: req.Itype,
Curid: oid1,
Targetid: oid2,
}, this.szSession...); err != nil {
this.module.Errorln(err)
}
return return
} }
if req.Itype == 0 && req.Curid == 0 && req.Targetid == 0 { if req.Itype == 0 && req.Curid == 0 && req.Targetid == 0 {
@ -519,7 +443,8 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr
this.module.Errorln(err) this.module.Errorln(err)
} }
if this.curPower == this.player2.Userinfo.Uid { if this.curPower == this.player2.Userinfo.Uid {
this.AiOperator() //this.AiOperator()
this.AutoOperator(this.player2)
} }
} else { } else {
@ -743,14 +668,7 @@ func (this *Room) AutoOperator(p *pb.PlayerData) {
szMap, oid1, oid2, bAddPs = this.chessboard.AiSwapGirde() szMap, oid1, oid2, bAddPs = this.chessboard.AiSwapGirde()
p.Ps-- p.Ps--
if p.Ps <= 0 { // 权限给下一个人 if p.Ps <= 0 { // 权限给下一个人
if p == this.player2 { this.ChangePower()
this.NexPower = this.player1.Userinfo.Uid
this.player1.Ps = MaxPs
} else {
this.NexPower = this.player2.Userinfo.Uid
this.player2.Ps = MaxPs
}
this.round++ this.round++
} }
if bAddPs { if bAddPs {
@ -800,7 +718,112 @@ func (this *Room) AutoOperator(p *pb.PlayerData) {
return return
} }
this.curPower = this.NexPower this.curPower = this.NexPower
if this.RoomType == 2 && this.curPower == this.player2.Userinfo.Uid { if this.RoomType == 2 && this.curPower == p.Userinfo.Uid {
this.AutoOperator(this.player2) this.AutoOperator(p)
}
}
// 玩家释放技能
func (this *Room) UserSkillUp(color int32, curid int32) (errdata *pb.ErrorData) {
var (
curScore int32 // 该次操作的得分
oid1 int32 // 唯一id
oid2 int32
)
var szMap []*pb.MapData
// 能量校验
if color == 1 { // 玩家1 放技能
conf, err := this.module.configure.GetGameConsumeHero(this.player1.Cardid)
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_EntertainNoHeroSkill,
Title: pb.ErrorCode_EntertainNoHeroSkill.ToString(),
}
return
}
if this.player1.Energy >= conf.Skillload {
this.player1.Energy = 0 // 清零
if _, m := this.chessboard.SkillUp(curid, color, conf.Skilleffect, conf.Skillvalue, true); len(m) > 0 {
szMap = append(szMap, m...)
} else {
szMap = append(szMap, &pb.MapData{
Data: this.chessboard.GetPalatData(),
})
}
for _, v := range szMap {
curScore += v.CurSocre
this.player1.Score += v.CurSocre
v.CurSocre = this.player1.Score
}
} else {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_EntertainNoEnergy,
Title: pb.ErrorCode_EntertainNoEnergy.ToString(),
}
return
}
this.NexPower = this.curPower
} else {
conf, err := this.module.configure.GetGameConsumeHero(this.player2.Cardid)
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_EntertainNoHeroSkill,
Title: pb.ErrorCode_EntertainNoHeroSkill.ToString(),
}
return
}
if this.player2.Energy >= conf.Skillload {
this.player2.Energy = 0 // 清零
if _, m := this.chessboard.SkillUp(curid, color, conf.Skilleffect, conf.Skillvalue, true); len(m) > 0 {
szMap = append(szMap, m...)
} else {
szMap = append(szMap, &pb.MapData{
Data: this.chessboard.GetPalatData(),
})
}
for _, v := range szMap {
curScore += v.CurSocre
this.player2.Score += v.CurSocre
v.CurSocre = this.player2.Score
}
} else {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_EntertainNoEnergy,
Title: pb.ErrorCode_EntertainNoEnergy.ToString(),
}
return
}
this.NexPower = this.curPower
}
if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
Mpadata: szMap,
Power: this.NexPower,
Curpower: this.curPower,
Score: curScore,
Round: this.round,
User1: this.player1,
User2: this.player2,
Itype: 1,
Curid: oid1,
Targetid: oid2,
}, this.szSession...); err != nil {
this.module.Errorln(err)
}
return
}
// 交换玩家权限
func (this *Room) ChangePower() {
if this.curPower == this.player1.Userinfo.Uid {
this.NexPower = this.player2.Userinfo.Uid
this.player2.Ps = MaxPs
this.player1.Ps = 0
}
if this.curPower == this.player2.Userinfo.Uid {
this.NexPower = this.player1.Userinfo.Uid
this.player1.Ps = MaxPs
this.player2.Ps = 0
} }
} }

View File

@ -65,8 +65,7 @@ func (this *MapData) CreateGride(count int) (girdes []*pb.GirdeData) {
Special: 0, Special: 0,
} }
id = this.GetRandType() id = this.GetRandType()
conf, err = this.module.configure.GetGameBlockByKey(id) if conf, err = this.module.configure.GetGameBlockByKey(id); err == nil {
if err == nil {
girde.Color = conf.Color girde.Color = conf.Color
girde.Cid = conf.Key girde.Cid = conf.Key
girde.Special = conf.Type girde.Special = conf.Type
@ -124,19 +123,20 @@ func (this *MapData) InitMap(module *Entertainment, iType int32) {
var mp map[int32]struct{} var mp map[int32]struct{}
mp = make(map[int32]struct{}, 0) mp = make(map[int32]struct{}, 0)
for { for {
n1, _ := rand.Int(rand.Reader, big.NewInt(Total-1)) n1, _ := rand.Int(rand.Reader, big.NewInt(Total))
mp[int32(n1.Int64())] = struct{}{} mp[int32(n1.Int64())] = struct{}{}
if len(mp) >= 2 { if len(mp) >= 2 {
break break
} }
} }
for key := range mp {
if iType == 3 { if iType == 3 {
sp = 4 sp = 4
} else if iType == 4 { } else if iType == 4 {
n1, _ := rand.Int(rand.Reader, big.NewInt(4)) // 随机一个消除类型 n1, _ := rand.Int(rand.Reader, big.NewInt(4)) // 随机一个消除类型
sp = int32(n1.Int64()) + 5 sp = int32(n1.Int64()) + 5
} }
for key := range mp {
if conf, err := this.module.configure.GetGameBlock(this.Plat[key].Color, sp); err == nil { if conf, err := this.module.configure.GetGameBlock(this.Plat[key].Color, sp); err == nil {
this.Plat[key].Cid = conf.Key this.Plat[key].Cid = conf.Key
this.Plat[key].Special = conf.Type this.Plat[key].Special = conf.Type
@ -548,6 +548,9 @@ func (this *MapData) DropGirde() bool {
} }
} }
} }
if len(fill) == 0 {
return bDrop
}
sz := this.CreateGride(len(fill)) sz := this.CreateGride(len(fill))
for pos, id := range fill { for pos, id := range fill {
this.Plat[id] = sz[pos] this.Plat[id] = sz[pos]
@ -586,13 +589,14 @@ func (this *MapData) DropGirde() bool {
mp[fill[n1.Int64()]] = struct{}{} mp[fill[n1.Int64()]] = struct{}{}
} }
for key := range mp {
if this.iType == 3 { if this.iType == 3 {
sp = 4 sp = 4
} else if this.iType == 4 { } else if this.iType == 4 {
n1, _ := rand.Int(rand.Reader, big.NewInt(4)) // 随机一个消除类型 n1, _ := rand.Int(rand.Reader, big.NewInt(4)) // 随机一个消除类型
sp = int32(n1.Int64()) + 5 sp = int32(n1.Int64()) + 5
} }
for key := range mp {
if conf, err := this.module.configure.GetGameBlock(this.Plat[key].Color, sp); err == nil { if conf, err := this.module.configure.GetGameBlock(this.Plat[key].Color, sp); err == nil {
this.Plat[key].Cid = conf.Key this.Plat[key].Cid = conf.Key
this.Plat[key].Special = conf.Type this.Plat[key].Special = conf.Type