go_dreamfactory/modules/enchant/model_enchant.go
2022-12-20 20:01:47 +08:00

67 lines
1.6 KiB
Go

package enchant
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
type modelEnchant struct {
modules.MCompModel
module *Enchant
}
func (this *modelEnchant) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.TableName = string(comm.TableEnchant)
err = this.MCompModel.Init(service, module, comp, options)
this.module = module.(*Enchant)
// uid 创建索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
func (this *modelEnchant) modifyEnchantDataByObjId(uid string, data map[string]interface{}) error {
return this.Change(uid, data)
}
// 获取列表信息
func (this *modelEnchant) getEnchantList(uid string) (result *pb.DBEnchant, err error) {
result = &pb.DBEnchant{
Id: primitive.NewObjectID().Hex(),
Uid: uid,
Boss: make(map[int32]int64),
BossTime: make(map[int32]int32),
}
if err = this.Get(uid, result); err != nil {
return
}
err = nil
return result, err
}
// 红点检测
func (this *modelEnchant) checkReddot32(uid string) bool {
conf := this.module.configure.GetGlobalConf()
if conf == nil {
return false
}
costRes := conf.EnchantbossCos
if costRes == nil {
return false
}
amount := int32(this.module.ModuleItems.QueryItemAmount(uid, costRes.T)) // 获取当前数量
if amount > 0 {
return true
}
return false
}