package pack import ( "context" "go_dreamfactory/comm" "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/sys/cache" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" ) const ( QueryUserPackReq = "pack.queryuserpackreq" QueryUserPackResp = "pack.queryuserpackresp" UseItemReq = "pack.useitemreq" UseItemResp = "pack.useitemresp" SellItemReq = "pack.sellitemreq" SellItemResp = "pack.sellitemresp" ) type Api_Comp struct { modules.MComp_GateComp service core.IService module *Pack mail comm.Imail } func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { this.MComp_GateComp.Init(service, module, comp, options) this.service = service this.module = module.(*Pack) return } func (this *Api_Comp) Start() (err error) { err = this.MComp_GateComp.Start() var module core.IModule if module, err = this.service.GetModule(comm.SM_MailModule); err != nil { return } this.mail = module.(comm.Imail) return } ///查询用户背包数据 func (this *Api_Comp) QueryUserPackReq(ctx context.Context, session comm.IUserSession, req *pb.QueryUserPackReq) (err error) { var ( code pb.ErrorCode pack *pb.DB_UserPackData grids []*pb.DB_GridData ) defer func() { session.SendMsg(string(this.module.GetType()), "queryuserpackresp", code, &pb.QueryUserPackResp{Grids: grids}) }() if !session.IsLogin() { code = pb.ErrorCode_NoLogin return } if pack, err = cache.Defsys.Pack_QueryUserPack(session.GetUserId()); err != nil { log.Errorf("QueryUserPackReq err:%v", err) code = pb.ErrorCode_CacheReadError return } else { grids = this.module.configure_comp.GetPackItemByType(pack, req.IType) } return } //使用道具 func (this *Api_Comp) UseItemReq(ctx context.Context, session comm.IUserSession, req *pb.UseItemReq) (err error) { var ( code pb.ErrorCode ) defer func() { session.SendMsg(string(this.module.GetType()), UseItemResp, code, &pb.UseItemResp{}) }() if !session.IsLogin() { code = pb.ErrorCode_NoLogin return } return } //出售道具 func (this *Api_Comp) SellItemReq(ctx context.Context, session comm.IUserSession, req *pb.QueryUserPackReq) (err error) { var ( code pb.ErrorCode ) defer func() { session.SendMsg(string(this.module.GetType()), SellItemResp, code, &pb.SellItemResp{}) }() if !session.IsLogin() { code = pb.ErrorCode_NoLogin return } return }