147 lines
4.1 KiB
Go
147 lines
4.1 KiB
Go
package smithy
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
|
|
"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{
|
|
Id: "",
|
|
Uid: uid,
|
|
Atlas: map[string]*pb.ForgeList{},
|
|
Collect: map[string]*pb.CollectData{},
|
|
Score: 0,
|
|
Award: 0,
|
|
}
|
|
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.ForgeList, 0)
|
|
result.Collect = make(map[string]*pb.CollectData, 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 {
|
|
atlasConf := this.module.configure.GetSmithyAtlasConf(id)
|
|
if atlasConf == nil {
|
|
return false
|
|
}
|
|
list, err := this.module.modelAtlas.getSmithyAtlasList(uid)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
if atlasConf.TypeId == 1 { // 装备收藏图鉴信息
|
|
scoreConf := this.module.configure.GetSmithyAtlasScoreConf(quality, lv)
|
|
if scoreConf == nil {
|
|
return false
|
|
}
|
|
update := make(map[string]interface{}, 0)
|
|
if v, ok := list.Atlas[id]; ok { // 找到相同的
|
|
if v.Activate { // 已经激活的
|
|
if len(v.Data) > 1 {
|
|
if v.Data[1].Score <= scoreConf.Score {
|
|
v.Data[1].ForgeCount = forgeCount
|
|
v.Data[1].Lv = lv
|
|
v.Data[1].Quality = quality
|
|
v.Data[1].Score = scoreConf.Score
|
|
v.Data[1].Time = configure.Now().Unix()
|
|
}
|
|
}
|
|
} else { // 没有激活的
|
|
if len(v.Data) == 1 {
|
|
if v.Data[0].Score <= scoreConf.Score {
|
|
v.Data[0].ForgeCount = forgeCount
|
|
v.Data[0].Lv = lv
|
|
v.Data[0].Quality = quality
|
|
v.Data[0].Score = scoreConf.Score
|
|
v.Data[0].Time = configure.Now().Unix()
|
|
}
|
|
} else {
|
|
v.Data = make([]*pb.ForgeData, 0)
|
|
newData := &pb.ForgeData{
|
|
ForgeCount: forgeCount,
|
|
Lv: lv,
|
|
Quality: quality,
|
|
Score: scoreConf.Score,
|
|
Time: configure.Now().Unix(),
|
|
}
|
|
v.Data = append(v.Data, newData)
|
|
}
|
|
}
|
|
} else {
|
|
sz := &pb.ForgeList{}
|
|
newData := &pb.ForgeData{
|
|
ForgeCount: forgeCount,
|
|
Lv: lv,
|
|
Quality: quality,
|
|
Score: scoreConf.Score,
|
|
Time: configure.Now().Unix(),
|
|
}
|
|
sz.Data = append(sz.Data, newData)
|
|
sz.Activate = false // 第一次获得 默认是非激活状态
|
|
list.Atlas[id] = sz
|
|
}
|
|
update["atlas"] = list.Atlas
|
|
this.module.modelAtlas.modifySmithyAtlasList(uid, update) // 更新分数信息
|
|
}
|
|
return true
|
|
}
|
|
|
|
// 检查是否激活收藏品
|
|
func (this *modelAtlas) CheckActivateAtlasCollect(uid string, id string) {
|
|
atlasConf := this.module.configure.GetSmithyAtlasConf(id)
|
|
if atlasConf != nil && atlasConf.TypeId == 2 {
|
|
if list, err := this.module.modelAtlas.getSmithyAtlasList(uid); err == nil {
|
|
|
|
if _, ok := list.Collect[id]; !ok {
|
|
list.Collect[id] = &pb.CollectData{
|
|
Id: id,
|
|
Score: atlasConf.AtlasScore,
|
|
Time: configure.Now().Unix(),
|
|
}
|
|
list.Score += atlasConf.AtlasScore
|
|
update := make(map[string]interface{}, 0)
|
|
update["collect"] = list.Collect
|
|
update["score"] = list.Score
|
|
this.module.modelAtlas.modifySmithyAtlasList(uid, update) // 更新分数信息
|
|
}
|
|
}
|
|
}
|
|
}
|