go_dreamfactory/modules/parkour/match_train.go
2023-11-04 15:00:45 +08:00

122 lines
2.9 KiB
Go

package parkour
import (
"context"
"go_dreamfactory/comm"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"google.golang.org/protobuf/types/known/anypb"
)
/*
匹配组件
*/
type matchTrainComp struct {
modules.MCompMatch
service core.IService
module *Parkour
}
//组件初始化接口
func (this *matchTrainComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MCompMatch.Init(service, module, comp, options)
this.module = module.(*Parkour)
this.service = service
this.PoolName = "parkourTrain"
return
}
func (this *matchTrainComp) Start() (err error) {
err = this.MCompMatch.Start()
return
}
func (this *matchTrainComp) MatchReq(v *pb.DBMatchPlayer) (err error) {
data, _ := anypb.New(v)
err = this.module.service.RpcCall(
context.Background(),
comm.Service_Mainte,
string(comm.RPC_JoinMatchPools),
&pb.JoinMatchPoolReq{
Poolname: this.PoolName,
Uid: v.Suser.Uid,
Dan: v.Dan,
Data: data,
Matchnum: 6,
Timeout: 10,
},
&pb.JoinMatchPoolResp{})
if err != nil {
this.module.Errorln(err)
return
}
return
}
func (this *matchTrainComp) MatchNotic(players map[string]interface{}) (err error) {
var (
playerSlice []*pb.DBMatchPlayer
red []*pb.DBRaceMember = make([]*pb.DBRaceMember, 0, 3)
bule []*pb.DBRaceMember = make([]*pb.DBRaceMember, 0, 3)
ais []*pb.DBRaceMember = make([]*pb.DBRaceMember, 0, 6)
n int32
dan int32
leftnum int32
)
playerSlice = make([]*pb.DBMatchPlayer, 0, len(players))
for _, v := range players {
playerSlice = append(playerSlice, v.(*pb.DBMatchPlayer))
}
for i, v := range playerSlice {
if i%2 == 0 {
red = append(red, &pb.DBRaceMember{
User: v.Suser,
Dan: v.Dan,
Integral: v.Integral,
Mlv: v.Mlv,
Mount: v.Mount,
Property: v.Property,
Currhp: v.Property[comm.Dhp],
})
dan = v.Dan
} else {
bule = append(bule, &pb.DBRaceMember{
User: v.Suser,
Dan: v.Dan,
Integral: v.Integral,
Weekintegral: v.Weekintegral,
Mlv: v.Mlv,
Mount: v.Mount,
Property: v.Property,
Currhp: v.Property[comm.Dhp],
})
dan = v.Dan
}
}
leftnum = 6 - int32(len(players))
if leftnum > 0 {
if ais, err = this.module.parkourComp.matcheAI(dan, leftnum); err != nil {
this.module.Error("matcheAI err!", log.Field{Key: "key", Value: err.Error()})
return
}
if len(red) < 3 {
n = 3 - int32(len(red))
red = append(red, ais[0:n]...)
ais = ais[n:]
}
if len(bule) < 3 {
bule = append(bule, ais[0:3-len(bule)]...)
}
}
if err = this.module.createbattle(pb.RaceType_prop, red, bule); err != nil {
this.module.Error("createbattle err!", log.Field{Key: "key", Value: err.Error()})
}
return
}