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 modelFetter *modelFetter 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.modelFetter = this.RegisterComp(new(modelFetter)).(*modelFetter) this.configure = this.RegisterComp(new(configureComp)).(*configureComp) } // 接口信息 更新藏书馆数据 func (this *Library) ModifyLibraryData(uid string, obj string, data map[string]interface{}) (code pb.ErrorCode) { err := this.modelLibrary.modifyLibraryDataByObjId(uid, obj, 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: map[int32]int32{}, Fetterlv: 0, } conf := this.configure.GetLibraryFetter(fid, 1) 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 } func (this *Library) ModifyHeroFetterData(uid string, obj string, data map[string]interface{}) (code pb.ErrorCode) { err := this.modelFetter.modifyHeroFetterDataByObjId(uid, obj, data) if err != nil { code = pb.ErrorCode_DBError } return } func (this *Library) GetHeroFetterList(uid string) []*pb.DBHeroFetter { return this.modelFetter.getHeroFetterList(uid) } // 创建一条英雄羁绊信息 func (this *Library) createHeroFetter(uid string, heroConfId string) (code pb.ErrorCode) { obj := &pb.DBHeroFetter{ Id: primitive.NewObjectID().Hex(), Uid: uid, Heroid: heroConfId, History: 0, Favorlv: 1, // 所有好感度默认1级 Stroyprize: 0, } if err := this.modelFetter.createHeroFetter(uid, obj); err != nil { code = pb.ErrorCode_DBError } return } func (this *Library) QueryHeroFetter(session comm.IUserSession) (data []*pb.DBHeroFetter) { data = this.GetHeroFetterList(session.GetUserId()) return } func (this *Library) QueryOneHeroFetter(session comm.IUserSession, cid string) *pb.DBHeroFetter { _data := this.GetHeroFetterList(session.GetUserId()) for _, v := range _data { if v.Heroid == cid { return v } } return nil } // 创建一条羁绊信息 func (this *Library) AddHeroFetterData(session comm.IUserSession, heroConfId string) { this.createHeroFetter(session.GetUserId(), heroConfId) return }