go_dreamfactory/modules/library/module.go

85 lines
2.0 KiB
Go

package library
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type Library struct {
modules.ModuleBase
modelLibrary *modelLibrary
api *apiComp
configure *configureComp
}
func NewModule() core.IModule {
return &Library{}
}
func (this *Library) GetType() core.M_Modules {
return comm.ModuleLibrary
}
func (this *Library) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
err = this.ModuleBase.Init(service, module, options)
return
}
func (this *Library) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.modelLibrary = this.RegisterComp(new(modelLibrary)).(*modelLibrary)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
}
// 接口信息
func (this *Library) ModifyLibraryData(uid string, data map[string]interface{}) (code pb.ErrorCode) {
err := this.modelLibrary.modifyLibraryDataByObjId(uid, data)
if err != nil {
code = pb.ErrorCode_DBError
}
return
}
//英雄列表
func (this *Library) GetLibraryList(uid string) []*pb.DBLibrary {
return this.modelLibrary.getLibraryList(uid)
}
//通过羁绊id 创建多个羁绊信息
func (this *Library) CreateLibrary(uid string, fids []int32, heroConfId string) (code pb.ErrorCode, objLibrary []*pb.DBLibrary) {
for _, fid := range fids {
obj := &pb.DBLibrary{
Id: primitive.NewObjectID().Hex(),
Uid: uid,
Fid: fid,
Hero: map[string]int32{},
Prize: false,
Fetterlv: 0,
}
conf := this.configure.GetLibraryFetter(fid)
if conf == nil {
for _, v := range conf.Hid {
obj.Hero[v] = 0
if v == heroConfId {
obj.Hero[heroConfId] = 1
}
}
if err := this.modelLibrary.createLibrary(uid, obj); err != nil {
code = pb.ErrorCode_DBError
break
}
objLibrary = append(objLibrary, obj)
}
}
return
}