go_dreamfactory/modules/pack/api_comp.go
2022-06-07 19:50:08 +08:00

89 lines
2.1 KiB
Go

package pack
import (
"context"
"go_dreamfactory/comm"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go_dreamfactory/sys/cache"
"github.com/liwei1dao/lego/core"
"github.com/liwei1dao/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
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.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
}