From a4046331659add8f9f7c7c18bd762f7bdbdcd9c1 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 25 Oct 2023 13:41:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/entertainment/api_match.go | 2 +- modules/entertainment/configure.go | 14 +++ modules/entertainment/match.go | 125 ++++++++++++++++++++++++ modules/entertainment/module.go | 7 +- modules/entertainment/xxlPlat.go | 3 +- pb/entertain_db.pb.go | 148 ++++++++++++++++++++++------- 6 files changed, 260 insertions(+), 39 deletions(-) create mode 100644 modules/entertainment/match.go diff --git a/modules/entertainment/api_match.go b/modules/entertainment/api_match.go index e5227ef3f..98edbdd9c 100644 --- a/modules/entertainment/api_match.go +++ b/modules/entertainment/api_match.go @@ -18,7 +18,7 @@ func (this *apiComp) MatchCheck(session comm.IUserSession, req *pb.EntertainMatc } func (this *apiComp) Match(session comm.IUserSession, req *pb.EntertainMatchReq) (errdata *pb.ErrorData) { - // 随便找个在线的人 + var ( //bMatch bool s2 comm.IUserSession diff --git a/modules/entertainment/configure.go b/modules/entertainment/configure.go index 2a3dcdaf9..52cdec2ae 100644 --- a/modules/entertainment/configure.go +++ b/modules/entertainment/configure.go @@ -107,3 +107,17 @@ func (this *configureComp) GetGameConsumeintegral(key int32) (conf *cfg.GameInte err = comm.NewNotFoundConfErr(moduleName, game_consumehero, key) return } + +func (this *configureComp) GetRobotGameConsumeHero() (cardid string) { + + if v, err := this.GetConfigure(game_consumehero); err == nil { + if configure, ok := v.(*cfg.GameConsumeHero); ok { + for _, v := range configure.GetDataList() { + cardid = v.Key + break + } + } + } + + return +} diff --git a/modules/entertainment/match.go b/modules/entertainment/match.go new file mode 100644 index 000000000..3ab124114 --- /dev/null +++ b/modules/entertainment/match.go @@ -0,0 +1,125 @@ +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(session, s2, p1, p2) + + // 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(red, bule); err != nil { + // this.module.Error("createbattle err!", log.Field{Key: "key", Value: err.Error()}) + // } + return +} diff --git a/modules/entertainment/module.go b/modules/entertainment/module.go index c0cf03f95..104519d67 100644 --- a/modules/entertainment/module.go +++ b/modules/entertainment/module.go @@ -2,6 +2,7 @@ package entertainment import ( "go_dreamfactory/comm" + "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/pb" @@ -14,12 +15,13 @@ func NewModule() core.IModule { type Entertainment struct { modules.ModuleBase - service core.IService + service base.IRPCXService api *apiComp configure *configureComp model *modelComp gameMgr *gameMgrComp //room *Room + match *matchComp } // 模块名 @@ -32,7 +34,7 @@ func (this *Entertainment) Init(service core.IService, module core.IModule, opti if err = this.ModuleBase.Init(service, module, options); err != nil { return } - this.service = service + this.service = service.(base.IRPCXService) return } @@ -44,6 +46,7 @@ func (this *Entertainment) OnInstallComp() { this.configure = this.RegisterComp(new(configureComp)).(*configureComp) this.gameMgr = this.RegisterComp(new(gameMgrComp)).(*gameMgrComp) //this.room = this.RegisterComp(new(Room)).(*Room) + this.match = this.RegisterComp(new(matchComp)).(*matchComp) } func (this *Entertainment) Start() (err error) { diff --git a/modules/entertainment/xxlPlat.go b/modules/entertainment/xxlPlat.go index d0c2b64cc..3cd065f93 100644 --- a/modules/entertainment/xxlPlat.go +++ b/modules/entertainment/xxlPlat.go @@ -442,9 +442,10 @@ func (this *MapData) Check3X(color int32) (bEliminate bool, score int32, count i // xc 判断用来是否加体力 func (this *MapData) CheckMap(color int32) (score int32, szMap []*pb.MapData, xc bool) { var curScore int32 + var energy int32 for { curScore = 0 - var energy int32 + energy = 0 if bRet, s, c := this.Check5X(color); bRet { fmt.Printf("=====检测消除5x===========\n") curScore += s diff --git a/pb/entertain_db.pb.go b/pb/entertain_db.pb.go index d36278282..25f3a3011 100644 --- a/pb/entertain_db.pb.go +++ b/pb/entertain_db.pb.go @@ -251,35 +251,97 @@ func (x *PlayerData) GetEnergy() int32 { return 0 } +// 消消乐匹配数据 +type DBXXLMatch struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Userinfo *BaseUserInfo `protobuf:"bytes,1,opt,name=userinfo,proto3" json:"userinfo"` + Cardid string `protobuf:"bytes,2,opt,name=cardid,proto3" json:"cardid"` // 选择的卡片ID +} + +func (x *DBXXLMatch) Reset() { + *x = DBXXLMatch{} + if protoimpl.UnsafeEnabled { + mi := &file_entertain_entertain_db_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DBXXLMatch) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DBXXLMatch) ProtoMessage() {} + +func (x *DBXXLMatch) ProtoReflect() protoreflect.Message { + mi := &file_entertain_entertain_db_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DBXXLMatch.ProtoReflect.Descriptor instead. +func (*DBXXLMatch) Descriptor() ([]byte, []int) { + return file_entertain_entertain_db_proto_rawDescGZIP(), []int{3} +} + +func (x *DBXXLMatch) GetUserinfo() *BaseUserInfo { + if x != nil { + return x.Userinfo + } + return nil +} + +func (x *DBXXLMatch) GetCardid() string { + if x != nil { + return x.Cardid + } + return "" +} + var File_entertain_entertain_db_proto protoreflect.FileDescriptor var file_entertain_entertain_db_proto_rawDesc = []byte{ 0x0a, 0x1c, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x74, 0x61, 0x69, 0x6e, 0x2f, 0x65, 0x6e, 0x74, 0x65, - 0x72, 0x74, 0x61, 0x69, 0x6e, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x63, - 0x0a, 0x07, 0x4d, 0x61, 0x70, 0x44, 0x61, 0x74, 0x61, 0x12, 0x1e, 0x0a, 0x04, 0x64, 0x61, 0x74, - 0x61, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x47, 0x69, 0x72, 0x64, 0x65, 0x44, - 0x61, 0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x75, 0x72, - 0x53, 0x6f, 0x63, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x63, 0x75, 0x72, - 0x53, 0x6f, 0x63, 0x72, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x75, 0x72, 0x45, 0x6e, 0x65, 0x72, - 0x67, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x63, 0x75, 0x72, 0x45, 0x6e, 0x65, - 0x72, 0x67, 0x79, 0x22, 0x75, 0x0a, 0x09, 0x47, 0x69, 0x72, 0x64, 0x65, 0x44, 0x61, 0x74, 0x61, - 0x12, 0x10, 0x0a, 0x03, 0x6f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6f, - 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x05, 0x52, 0x05, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x63, 0x69, 0x64, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x63, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x63, - 0x6f, 0x72, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, - 0x12, 0x18, 0x0a, 0x07, 0x73, 0x70, 0x65, 0x63, 0x69, 0x61, 0x6c, 0x18, 0x05, 0x20, 0x01, 0x28, - 0x05, 0x52, 0x07, 0x73, 0x70, 0x65, 0x63, 0x69, 0x61, 0x6c, 0x22, 0x88, 0x01, 0x0a, 0x0a, 0x50, - 0x6c, 0x61, 0x79, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, - 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, - 0x14, 0x0a, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, - 0x73, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x70, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, - 0x05, 0x52, 0x02, 0x70, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x63, 0x61, 0x72, 0x64, 0x69, 0x64, 0x18, - 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x63, 0x61, 0x72, 0x64, 0x69, 0x64, 0x12, 0x16, 0x0a, - 0x06, 0x65, 0x6e, 0x65, 0x72, 0x67, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x65, - 0x6e, 0x65, 0x72, 0x67, 0x79, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x72, 0x74, 0x61, 0x69, 0x6e, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0a, + 0x63, 0x6f, 0x6d, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x63, 0x0a, 0x07, 0x4d, 0x61, + 0x70, 0x44, 0x61, 0x74, 0x61, 0x12, 0x1e, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x47, 0x69, 0x72, 0x64, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, + 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x75, 0x72, 0x53, 0x6f, 0x63, 0x72, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x63, 0x75, 0x72, 0x53, 0x6f, 0x63, 0x72, + 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x75, 0x72, 0x45, 0x6e, 0x65, 0x72, 0x67, 0x79, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x63, 0x75, 0x72, 0x45, 0x6e, 0x65, 0x72, 0x67, 0x79, 0x22, + 0x75, 0x0a, 0x09, 0x47, 0x69, 0x72, 0x64, 0x65, 0x44, 0x61, 0x74, 0x61, 0x12, 0x10, 0x0a, 0x03, + 0x6f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6f, 0x69, 0x64, 0x12, 0x14, + 0x0a, 0x05, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, + 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x63, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x03, 0x63, 0x69, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x18, 0x0a, 0x07, + 0x73, 0x70, 0x65, 0x63, 0x69, 0x61, 0x6c, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x73, + 0x70, 0x65, 0x63, 0x69, 0x61, 0x6c, 0x22, 0x88, 0x01, 0x0a, 0x0a, 0x50, 0x6c, 0x61, 0x79, 0x65, + 0x72, 0x44, 0x61, 0x74, 0x61, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x73, + 0x63, 0x6f, 0x72, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x63, 0x6f, 0x72, + 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x70, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x70, + 0x73, 0x12, 0x16, 0x0a, 0x06, 0x63, 0x61, 0x72, 0x64, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x06, 0x63, 0x61, 0x72, 0x64, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x65, 0x6e, 0x65, + 0x72, 0x67, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x65, 0x6e, 0x65, 0x72, 0x67, + 0x79, 0x22, 0x4f, 0x0a, 0x0a, 0x44, 0x42, 0x58, 0x58, 0x4c, 0x4d, 0x61, 0x74, 0x63, 0x68, 0x12, + 0x29, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x0d, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, + 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x69, 0x6e, 0x66, 0x6f, 0x12, 0x16, 0x0a, 0x06, 0x63, 0x61, + 0x72, 0x64, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x63, 0x61, 0x72, 0x64, + 0x69, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( @@ -294,19 +356,22 @@ func file_entertain_entertain_db_proto_rawDescGZIP() []byte { return file_entertain_entertain_db_proto_rawDescData } -var file_entertain_entertain_db_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_entertain_entertain_db_proto_msgTypes = make([]protoimpl.MessageInfo, 4) var file_entertain_entertain_db_proto_goTypes = []interface{}{ - (*MapData)(nil), // 0: MapData - (*GirdeData)(nil), // 1: GirdeData - (*PlayerData)(nil), // 2: PlayerData + (*MapData)(nil), // 0: MapData + (*GirdeData)(nil), // 1: GirdeData + (*PlayerData)(nil), // 2: PlayerData + (*DBXXLMatch)(nil), // 3: DBXXLMatch + (*BaseUserInfo)(nil), // 4: BaseUserInfo } var file_entertain_entertain_db_proto_depIdxs = []int32{ 1, // 0: MapData.data:type_name -> GirdeData - 1, // [1:1] is the sub-list for method output_type - 1, // [1:1] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name + 4, // 1: DBXXLMatch.userinfo:type_name -> BaseUserInfo + 2, // [2:2] is the sub-list for method output_type + 2, // [2:2] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name } func init() { file_entertain_entertain_db_proto_init() } @@ -314,6 +379,7 @@ func file_entertain_entertain_db_proto_init() { if File_entertain_entertain_db_proto != nil { return } + file_comm_proto_init() if !protoimpl.UnsafeEnabled { file_entertain_entertain_db_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*MapData); i { @@ -351,6 +417,18 @@ func file_entertain_entertain_db_proto_init() { return nil } } + file_entertain_entertain_db_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DBXXLMatch); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -358,7 +436,7 @@ func file_entertain_entertain_db_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_entertain_entertain_db_proto_rawDesc, NumEnums: 0, - NumMessages: 3, + NumMessages: 4, NumExtensions: 0, NumServices: 0, },