111 lines
2.3 KiB
Go
111 lines
2.3 KiB
Go
package entertainment
|
|
|
|
import (
|
|
"context"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
|
|
"go_dreamfactory/lego/core"
|
|
|
|
"google.golang.org/protobuf/types/known/anypb"
|
|
)
|
|
|
|
/*
|
|
匹配组件
|
|
*/
|
|
type matchComp struct {
|
|
modules.MCompMatch
|
|
service core.IService
|
|
module *Entertainment
|
|
}
|
|
|
|
//组件初始化接口
|
|
func (this *matchComp) 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.(*Entertainment)
|
|
this.service = service
|
|
this.PoolName = "entertain"
|
|
return
|
|
}
|
|
|
|
func (this *matchComp) Start() (err error) {
|
|
err = this.MCompMatch.Start()
|
|
return
|
|
}
|
|
|
|
func (this *matchComp) MatchReq(v *pb.DBXXLMatch) (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.Userinfo.Uid,
|
|
Data: data,
|
|
Matchnum: 2, // 匹配数量2
|
|
Timeout: 5,
|
|
},
|
|
&pb.JoinMatchPoolResp{})
|
|
if err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *matchComp) MatchNotic(players map[string]interface{}) (err error) {
|
|
var (
|
|
playerSlice []*pb.DBXXLMatch
|
|
p1 *pb.PlayerData
|
|
p2 *pb.PlayerData
|
|
)
|
|
playerSlice = make([]*pb.DBXXLMatch, 0, len(players))
|
|
for _, v := range players {
|
|
playerSlice = append(playerSlice, v.(*pb.DBXXLMatch))
|
|
}
|
|
for pos, v := range playerSlice {
|
|
if pos == 0 {
|
|
p1 = &pb.PlayerData{
|
|
Userinfo: v.Userinfo,
|
|
Cardid: v.Cardid,
|
|
}
|
|
} else if pos == 1 {
|
|
p2 = &pb.PlayerData{
|
|
Userinfo: v.Userinfo,
|
|
Cardid: v.Cardid,
|
|
}
|
|
} else {
|
|
break
|
|
}
|
|
}
|
|
if p1 == nil {
|
|
return
|
|
}
|
|
if p2 == nil { // 玩家2 是空 那么构建一个AI 对象
|
|
if robots, err := this.module.ModuleTools.RandRobotConfig(1); err == nil {
|
|
if len(robots) > 0 {
|
|
p2 = &pb.PlayerData{
|
|
Userinfo: &pb.BaseUserInfo{
|
|
Uid: "999",
|
|
Sid: "",
|
|
Name: robots[0].Name,
|
|
Gender: robots[0].Sex,
|
|
Skin: robots[0].Showid,
|
|
Aframe: "",
|
|
Title: "",
|
|
Lv: robots[0].Lvshow,
|
|
},
|
|
Cardid: this.module.configure.GetRobotGameConsumeHero(),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
go func() {
|
|
this.module.gameMgr.CreateRoom(p1, p2)
|
|
}()
|
|
|
|
return
|
|
}
|