go_dreamfactory/modules/exclusive/module.go
2024-02-26 18:41:09 +08:00

112 lines
2.8 KiB
Go

package exclusive
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/event"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
)
const moduleName = "专武"
func NewModule() core.IModule {
m := new(Exclusive)
return m
}
type Exclusive struct {
modules.ModuleBase
service core.IService
chat comm.IChat
api *apiComp
configure *configureComp
model *modelComp
}
// 模块名
func (this *Exclusive) GetType() core.M_Modules {
return comm.ModuleExclusive
}
// 模块初始化接口 注册用户创建角色事件
func (this *Exclusive) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
if err = this.ModuleBase.Init(service, module, options); err != nil {
return
}
this.service = service
return
}
// 模块启动接口
// 模块启动
func (this *Exclusive) Start() (err error) {
if err = this.ModuleBase.Start(); err != nil {
return
}
var module core.IModule
if module, err = this.service.GetModule(comm.ModuleChat); err != nil {
return
}
this.chat = module.(comm.IChat)
event.RegisterGO(comm.EventUserOffline, this.EventUserOffline)
return
}
// 装备组件
func (this *Exclusive) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.model = this.RegisterComp(new(modelComp)).(*modelComp)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
}
// 添加武器
func (this *Exclusive) AddNewExclusive(session comm.IUserSession, cIds map[string]int32, bPush bool) (change []*pb.DB_Exclusive, errdata *pb.ErrorData) {
var (
err error
)
if change, err = this.model.addExclusives(session.GetUserId(), cIds); err != nil {
this.Errorf("err%v", err)
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Message: err.Error(),
}
return
}
if len(change) > 0 && bPush {
this.equipmentsChangePush(session, change)
}
return
}
// 添加武器
func (this *Exclusive) DelNewExclusive(session comm.IUserSession, cIds []string, bPush bool) (change []*pb.DB_Exclusive, errdata *pb.ErrorData) {
var (
err error
)
if change, err = this.model.delExclusives(session.GetUserId(), cIds); err != nil {
this.Errorf("err%v", err)
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Message: err.Error(),
}
return
}
if len(change) > 0 && bPush {
this.equipmentsChangePush(session, change)
}
return
}
// Event------------------------------------------------------------------------------------------------------------
func (this *Exclusive) EventUserOffline(uid, sessionid string) {
this.model.BatchDelLists(uid)
}
// 推送道具变化消息
func (this *Exclusive) equipmentsChangePush(session comm.IUserSession, items []*pb.DB_Exclusive) (err error) {
session.SendMsg(string(this.GetType()), "change", &pb.ExclusiveChangePush{Exclusives: items})
return
}