go_dreamfactory/modules/practice/module.go
2023-02-28 17:17:36 +08:00

86 lines
2.2 KiB
Go

package practice
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/base"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
)
/*
模块名:熊猫武馆 练功子系统
描述:熊猫武馆 主系统 打桩 以及武馆相关数据管理
开发:李伟
*/
func NewModule() core.IModule {
m := new(Practice)
return m
}
type Practice struct {
modules.ModuleBase
service base.IRPCXService
mail comm.Imail
atlas comm.IPandaAtlas
api *apiComp
configure *configureComp
modelPandata *modelPandata
}
//模块名
func (this *Practice) GetType() core.M_Modules {
return comm.ModulePractice
}
//模块初始化接口 注册用户创建角色事件
func (this *Practice) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
err = this.ModuleBase.Init(service, module, options)
this.service = service.(base.IRPCXService)
return
}
func (this *Practice) Start() (err error) {
err = this.ModuleBase.Start()
var module core.IModule
if module, err = this.service.GetModule(comm.ModuleMail); err != nil {
return
}
this.mail = module.(comm.Imail)
if module, err = this.service.GetModule(comm.ModulePandaAtlas); err != nil {
return
}
this.atlas = module.(comm.IPandaAtlas)
return
}
//装备组件
func (this *Practice) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
this.modelPandata = this.RegisterComp(new(modelPandata)).(*modelPandata)
}
func (this *Practice) AddItems(session comm.IUserSession, items map[string]int32, bPush bool) (code pb.ErrorCode) {
var (
err error
room *pb.DBPracticeRoom
id []string
)
if room, err = this.modelPandata.queryUserMartialhall(session.GetUserId()); err != nil {
code = pb.ErrorCode_DBError
return
}
id = make([]string, 0)
for k, _ := range items {
room.Knapsack[k] = 0
id = append(id, k)
this.atlas.CheckActivatePandaAtlasCollect(session.GetUserId(), k)
}
this.modelPandata.Change(session.GetUserId(), map[string]interface{}{
"knapsack": room.Knapsack,
})
session.SendMsg(string(this.GetType()), "jxitem", &pb.PracticeJXItemPush{Id: id})
return
}