go_dreamfactory/modules/atlas/module.go
2024-02-27 14:17:15 +08:00

174 lines
4.2 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) {
if err = this.ModuleBase.Init(service, module, options); err != nil {
return
}
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,
}
if err = model.Add(uid, atlas); 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
}
//红点查询
func (this *PandaAtlas) Reddot(session comm.IUserSession, rid map[comm.ReddotType]struct{}) (items map[comm.ReddotType]*pb.ReddotItem) {
var (
selfrid []comm.ReddotType = []comm.ReddotType{comm.Reddot18108, comm.Reddot18111}
info *pb.DBPandaAtlas
err error
ok bool
)
items = make(map[comm.ReddotType]*pb.ReddotItem)
for _, v := range selfrid {
if _, ok = rid[v]; ok {
break
}
}
if !ok {
return
}
if info, err = this.modelPandaAtlas.getPandaAtlasList(session.GetUserId()); err != nil {
return
}
for _, v := range selfrid {
if _, ok = rid[v]; ok {
switch v {
case comm.Reddot18108: // 铁匠铺手册台
for _, v := range info.Collect {
if !v.Activate {
items[comm.Reddot18108] = &pb.ReddotItem{
Rid: int32(comm.Reddot18108),
Activated: true,
}
break
}
}
break
case comm.Reddot18111: // 铁匠铺手册台
conf, err := this.configure.GetPandoAtlasAwardConf(info.Award + 1)
if err != nil {
break
}
if info.Score < conf.AtlasScore { // 校验积分够不够
break
}
items[comm.Reddot18111] = &pb.ReddotItem{
Rid: int32(comm.Reddot18111),
Activated: true,
}
break
}
}
}
return
}