82 lines
2.2 KiB
Go
82 lines
2.2 KiB
Go
package smithy
|
|
|
|
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 modelAtlas struct {
|
|
modules.MCompModel
|
|
module *Smithy
|
|
}
|
|
|
|
func (this *modelAtlas) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = string(comm.TableAtlas)
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.module = module.(*Smithy)
|
|
// uid 创建索引
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
func (this *modelAtlas) getSmithyAtlasList(uid string) (result *pb.DBAtlas, err error) {
|
|
result = &pb.DBAtlas{}
|
|
if err = this.Get(uid, result); err != nil {
|
|
if mongo.ErrNoDocuments == err {
|
|
result.Id = primitive.NewObjectID().Hex()
|
|
result.Uid = uid
|
|
result.Atlas = make(map[string]*pb.ForgeData, 0)
|
|
result.Award = 1 // 初始1级
|
|
this.Add(uid, result)
|
|
err = nil
|
|
}
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *modelAtlas) modifySmithyAtlasList(uid string, data map[string]interface{}) error {
|
|
return this.Change(uid, data)
|
|
}
|
|
|
|
// 检查是否激活图鉴
|
|
|
|
func (this *modelAtlas) CheckActivateAtlas(uid string, id string, lv int32, quality int32, forgeCount int32) bool {
|
|
conf := this.module.configure.GetSmithyAtlasConf(id)
|
|
if conf != nil {
|
|
return false
|
|
}
|
|
list, err := this.module.modelAtlas.getSmithyAtlasList(uid)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
for k, v := range list.Atlas {
|
|
if k == id { // 找到相同的 校验 对应的分数
|
|
// 获取分数
|
|
scoreConf := this.module.configure.GetSmithyAtlasScoreConf(quality, lv)
|
|
if scoreConf != nil {
|
|
if v.Score <= scoreConf.Score {
|
|
v.Lv = lv
|
|
v.Quality = quality
|
|
v.Score = scoreConf.Score
|
|
v.ForgeCount = forgeCount // 更新锻造次数
|
|
update := make(map[string]interface{}, 0)
|
|
update["tujian"] = list.Atlas
|
|
this.module.modelAtlas.modifySmithyAtlasList(uid, update) // 更新分数信息
|
|
}
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|