go_dreamfactory/modules/equipment/module.go
2022-07-26 15:14:37 +08:00

116 lines
3.4 KiB
Go

package equipment
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/event"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"github.com/go-redis/redis/v8"
"github.com/smallnest/rpcx/log"
)
/*
模块名:装备
描述:用户装备管理以及装备升级强化相关
开发:李伟
*/
func NewModule() core.IModule {
m := new(Equipment)
return m
}
type Equipment struct {
modules.ModuleBase
service core.IService
api *apiComp
configure *configureComp
modelEquipment *modelEquipmentComp
}
//模块名
func (this *Equipment) GetType() core.M_Modules {
return comm.ModuleEquipment
}
//模块初始化接口 注册用户创建角色事件
func (this *Equipment) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
err = this.ModuleBase.Init(service, module, options)
this.service = service
return
}
//模块启动接口
//模块启动
func (this *Equipment) Start() (err error) {
err = this.ModuleBase.Start()
event.RegisterGO(comm.EventUserOffline, this.EventUserOffline)
return
}
//装备组件
func (this *Equipment) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.modelEquipment = this.RegisterComp(new(modelEquipmentComp)).(*modelEquipmentComp)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
}
//Event------------------------------------------------------------------------------------------------------------
func (this *Equipment) EventUserOffline(session comm.IUserSession) {
err := this.modelEquipment.BatchDelLists(session.GetUserId())
this.Debugf("EventUserOffline:%s err:%v", session, err)
}
//IEquipment-------------------------------------------------------------------------------------------------------------------------------
//查询武器信息
func (this *Equipment) QueryEquipment(source *comm.ModuleCallSource, uid string, id string) (equipment *pb.DB_Equipment, code pb.ErrorCode) {
var err error
if uid == "" || id == "" {
log.Errorf("请求参数错误 uid:%s Id:%s", uid, id)
code = pb.ErrorCode_ReqParameterError
return
}
if equipment, err = this.modelEquipment.QueryUserEquipmentsById(uid, id); err != nil {
if err == redis.Nil {
code = pb.ErrorCode_EquipmentOnFoundEquipment
} else {
code = pb.ErrorCode_SystemError
}
}
return
}
//查询卡片数量
func (this *Equipment) QueryEquipmentAmount(source *comm.ModuleCallSource, uid string, equipmentId string) (amount uint32) {
amount = this.modelEquipment.QueryEquipmentAmount(uid, equipmentId)
return
}
//添加武器
func (this *Equipment) AddNewEquipments(source *comm.ModuleCallSource, session comm.IUserSession, cIds map[string]uint32, bPush bool) (code pb.ErrorCode) {
var (
err error
change []*pb.DB_Equipment
)
if change, err = this.modelEquipment.AddEquipments(session.GetUserId(), cIds); err != nil {
log.Errorf("err%v", err)
code = pb.ErrorCode_SystemError
return
}
if len(change) > 0 && bPush {
this.equipmentsChangePush(session, change)
}
return
}
//Evens--------------------------------------------------------------------------------------------------------------------------------
//推送道具变化消息
func (this *Equipment) equipmentsChangePush(session comm.IUserSession, items []*pb.DB_Equipment) (err error) {
session.SendMsg(string(this.GetType()), "change", &pb.EquipmentChangePush{Equipments: items})
return
}