118 lines
3.0 KiB
Go
118 lines
3.0 KiB
Go
/*
|
|
模块名:atlas
|
|
描述:武馆图鉴模块
|
|
开发:梅雄风
|
|
*/
|
|
package atlas
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"go_dreamfactory/sys/db"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
)
|
|
|
|
type PandaAtlas struct {
|
|
modules.ModuleBase
|
|
api *apiComp
|
|
configure *configureComp
|
|
modelPandaAtlas *modelPandaAtlas
|
|
service core.IService
|
|
}
|
|
|
|
func NewModule() core.IModule {
|
|
return &PandaAtlas{}
|
|
}
|
|
|
|
func (this *PandaAtlas) GetType() core.M_Modules {
|
|
return comm.ModulePandaAtlas
|
|
}
|
|
|
|
func (this *PandaAtlas) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
|
err = this.ModuleBase.Init(service, module, options)
|
|
this.service = service
|
|
return
|
|
}
|
|
|
|
func (this *PandaAtlas) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
|
this.modelPandaAtlas = this.RegisterComp(new(modelPandaAtlas)).(*modelPandaAtlas)
|
|
}
|
|
|
|
func (this *PandaAtlas) CheckActivatePandaAtlasCollect(uid string, id string) (err error) {
|
|
var (
|
|
conf *cfg.GamePandamasTjData
|
|
model *db.DBModel
|
|
)
|
|
conf, err = this.configure.GetPandoAtlasConf(id)
|
|
if err != nil {
|
|
this.Errorf("GetPandoAtlasConf err:%d", id)
|
|
return
|
|
}
|
|
if this.IsCross() {
|
|
atlas := &pb.DBPandaAtlas{}
|
|
if model, err = this.GetDBModelByUid(uid, this.modelPandaAtlas.TableName); err == nil {
|
|
|
|
if err = model.Get(uid, atlas); err != nil { // 防止数据没有初始化情况
|
|
if mongo.ErrNoDocuments == err {
|
|
atlas.Id = primitive.NewObjectID().Hex()
|
|
atlas.Uid = uid
|
|
atlas.Collect = make(map[string]*pb.CollectInfo, 0)
|
|
atlas.Award = 1 // 初始1级
|
|
|
|
atlas.Collect[id] = &pb.CollectInfo{
|
|
Score: conf.AtlasScore,
|
|
Time: configure.Now().Unix(),
|
|
Activate: false,
|
|
}
|
|
update := make(map[string]interface{}, 0)
|
|
update["collect"] = atlas.Collect
|
|
if err := model.Add(uid, update); err != nil {
|
|
this.Errorf("err:%v", err)
|
|
}
|
|
return
|
|
} else {
|
|
this.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
if _, ok := atlas.Collect[id]; !ok {
|
|
atlas.Collect[id] = &pb.CollectInfo{
|
|
Score: conf.AtlasScore,
|
|
Time: configure.Now().Unix(),
|
|
Activate: false,
|
|
}
|
|
update := make(map[string]interface{}, 0)
|
|
update["collect"] = atlas.Collect
|
|
if err = model.Change(uid, update); err != nil {
|
|
this.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
}
|
|
} else { // 本服
|
|
list, _ := this.modelPandaAtlas.getPandaAtlasList(uid)
|
|
if _, ok := list.Collect[id]; !ok {
|
|
list.Collect[id] = &pb.CollectInfo{
|
|
Score: conf.AtlasScore,
|
|
Time: configure.Now().Unix(),
|
|
Activate: false,
|
|
}
|
|
update := make(map[string]interface{}, 0)
|
|
update["collect"] = list.Collect
|
|
this.modelPandaAtlas.modifyPandaAtlasList(uid, update)
|
|
return
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|