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) this.module.service.Destroy() 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: 10, }, &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{ Uid: v.Userinfo.Uid, Name: v.Userinfo.Name, Score: 0, Cardid: v.Cardid, } } else if pos == 1 { p2 = &pb.PlayerData{ Uid: v.Userinfo.Uid, Name: v.Userinfo.Name, Score: 0, 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{ Uid: "999", // AI uid 暂定 Name: robots[0].Name, Score: 0, Ps: 0, Cardid: this.module.configure.GetRobotGameConsumeHero(), // 机器人临时数据 } } } } //roomid := this.module.gameMgr.CreateRoom(p1, p2) return }