90 lines
2.2 KiB
Go
90 lines
2.2 KiB
Go
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 ( //消息回复的头名称
|
|
QueryUserPackResp = "queryuserpackresp"
|
|
UseItemResp = "useitemresp"
|
|
SellItemResp = "sellitemresp"
|
|
)
|
|
|
|
/*
|
|
背包 处理用户的请求组件 必须继承 modules.MComp_GateComp
|
|
*/
|
|
type Api_Comp struct {
|
|
modules.MComp_GateComp
|
|
service core.IService
|
|
module *Pack
|
|
}
|
|
|
|
//组件初始化接口
|
|
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) 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
|
|
}
|