126 lines
3.0 KiB
Go
126 lines
3.0 KiB
Go
package library
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
)
|
|
|
|
type modelLibrary struct {
|
|
modules.MCompModel
|
|
module *Library
|
|
}
|
|
|
|
func (this *modelLibrary) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = string(comm.TableLibrary)
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.module = module.(*Library)
|
|
// uid 创建索引
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
func (this *modelLibrary) modifyLibraryDataByObjId(uid string, obj string, data map[string]interface{}) error {
|
|
return this.ChangeList(uid, obj, data)
|
|
}
|
|
|
|
// 获取列表信息
|
|
func (this *modelLibrary) getLibraryList(uid string) []*pb.DBLibrary {
|
|
libs := make([]*pb.DBLibrary, 0)
|
|
err := this.GetList(uid, &libs)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return libs
|
|
}
|
|
|
|
//创建一条信息
|
|
func (this *modelLibrary) createLibrary(uid string, fetter *pb.DBLibrary) (err error) {
|
|
|
|
if err = this.AddList(uid, fetter.Id, fetter); err != nil {
|
|
this.module.Errorf("%v", err)
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// 通过objid 找对应的数据
|
|
func (this *modelLibrary) getOneLibrary(uid, oid string) *pb.DBLibrary {
|
|
fetter := &pb.DBLibrary{}
|
|
err := this.GetListObj(uid, oid, fetter)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return fetter
|
|
}
|
|
|
|
func (this *modelLibrary) checkReddot19105(uid string) bool {
|
|
listLabriary := this.getLibraryList(uid)
|
|
for _, v := range listLabriary {
|
|
var (
|
|
minlv int32 // 获取最小等级
|
|
)
|
|
for _, v1 := range v.Herofetter {
|
|
if fet := this.module.modelFetter.getOneHeroFetter(uid, v1); fet != nil {
|
|
if minlv == 0 || minlv > fet.Favorlv {
|
|
minlv = fet.Favorlv
|
|
}
|
|
}
|
|
}
|
|
for i := 1; i <= int(minlv); i++ {
|
|
if _, ok := v.Prize[int32(i)]; !ok { // 找到了没有领奖的数据
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// 有可激活
|
|
func (this *modelLibrary) checkReddot19109(uid string) bool {
|
|
list := this.getLibraryList(uid)
|
|
for _, v := range list {
|
|
if v.Fidlv == 0 {
|
|
c, _ := this.module.configure.GetFriendData(v.Fid, 1)
|
|
if len(v.Herofetter) == len(c) {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// 有升级的情况 非常耗性能o(╯□╰)o不建议使用
|
|
func (this *modelLibrary) checkReddot19110(uid string) bool {
|
|
list := this.getLibraryList(uid)
|
|
for _, v := range list {
|
|
if v.Fidlv > 0 {
|
|
var totalFetterLv int32 // 羁绊累计等级
|
|
for _, oid := range v.Herofetter {
|
|
if _d := this.module.modelFetter.getOneHeroFetter(uid, oid); _d != nil {
|
|
totalFetterLv += _d.Favorlv
|
|
}
|
|
}
|
|
for i := 1; ; i++ {
|
|
c, _err := this.module.configure.GetFriendData(v.Fid, int32(i))
|
|
if _err != nil || len(c) == 0 {
|
|
break
|
|
}
|
|
if c[0].FavorabilityLv > totalFetterLv {
|
|
break
|
|
}
|
|
if _, ok := v.Prize[c[0].FriendId]; !ok {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return false
|
|
}
|