From 440f4fe1f9056d32e725b00aaa2a753d3765ced2 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Thu, 30 Mar 2023 11:47:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/imodule.go | 2 +- modules/atlas/module.go | 67 +++++++++++++++++------------------ modules/modulebase.go | 2 +- modules/smithy/model_atlas.go | 22 ------------ modules/smithy/module.go | 59 +++++++++++++++++++++++++++--- pb/errorcode.pb.go | 43 ++++++++++++---------- 6 files changed, 113 insertions(+), 82 deletions(-) diff --git a/comm/imodule.go b/comm/imodule.go index d1d3a7c9c..7aa497aaa 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -431,7 +431,7 @@ type ( } ISmithy interface { - CheckActivateAtlasCollect(uid string, id string) (code pb.ErrorCode) + CheckActivateAtlasCollect(uid string, id string) } IPandaAtlas interface { diff --git a/modules/atlas/module.go b/modules/atlas/module.go index 2ba5a1106..f36b87f06 100644 --- a/modules/atlas/module.go +++ b/modules/atlas/module.go @@ -46,6 +46,10 @@ func (this *PandaAtlas) OnInstallComp() { } func (this *PandaAtlas) CheckActivatePandaAtlasCollect(uid string, id string) { + conf := this.configure.GetPandoAtlasConf(id) + if conf != nil { + return + } if this.IsCross() { atlas := &pb.DBPandaAtlas{} if model, err := this.GetDBModelByUid(uid, this.modelPandaAtlas.TableName, this.modelPandaAtlas.Expired); err == nil { @@ -56,17 +60,16 @@ func (this *PandaAtlas) CheckActivatePandaAtlasCollect(uid string, id string) { atlas.Uid = uid atlas.Collect = make(map[string]*pb.CollectInfo, 0) atlas.Award = 1 // 初始1级 - if conf := this.configure.GetPandoAtlasConf(id); conf != nil { - 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) - } + + 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 { @@ -75,36 +78,32 @@ func (this *PandaAtlas) CheckActivatePandaAtlasCollect(uid string, id string) { } } if _, ok := atlas.Collect[id]; !ok { - if conf := this.configure.GetPandoAtlasConf(id); conf != nil { - 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 { - if conf := this.configure.GetPandoAtlasConf(id); conf != nil { - list.Collect[id] = &pb.CollectInfo{ + atlas.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 + 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 diff --git a/modules/modulebase.go b/modules/modulebase.go index 0d6d36f00..45f1e3441 100644 --- a/modules/modulebase.go +++ b/modules/modulebase.go @@ -450,7 +450,7 @@ func (this *ModuleBase) DispenseRes(session comm.IUserSession, res []*cfg.Gameat } if len(atlas) > 0 { for k := range atlas { - code = this.ModuleSmithy.CheckActivateAtlasCollect(session.GetUserId(), k) + this.ModuleSmithy.CheckActivateAtlasCollect(session.GetUserId(), k) this.Debugf("发放图鉴资源: %v [%v]", k, code) } } diff --git a/modules/smithy/model_atlas.go b/modules/smithy/model_atlas.go index 02977d7d8..c53aab760 100644 --- a/modules/smithy/model_atlas.go +++ b/modules/smithy/model_atlas.go @@ -121,25 +121,3 @@ func (this *modelAtlas) CheckActivateAtlas(uid string, id string, lv int32, qual } 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) // 更新分数信息 - } - } - } -} diff --git a/modules/smithy/module.go b/modules/smithy/module.go index 51d1fc290..e556e1fc1 100644 --- a/modules/smithy/module.go +++ b/modules/smithy/module.go @@ -11,6 +11,9 @@ import ( "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" + + "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/mongo" ) type Smithy struct { @@ -47,9 +50,58 @@ func (this *Smithy) OnInstallComp() { this.modelTask = this.RegisterComp(new(modelTask)).(*modelTask) } -func (this *Smithy) CheckActivateAtlasCollect(uid string, id string) (code pb.ErrorCode) { +func (this *Smithy) CheckActivateAtlasCollect(uid string, id string) { atlasConf := this.configure.GetSmithyAtlasConf(id) - if atlasConf != nil && atlasConf.TypeId == 2 { //类型为2表示特殊类型图鉴 + if atlasConf == nil || atlasConf.TypeId != 2 { + return + } + + if this.IsCross() { + atlas := &pb.DBAtlas{} + if model, err := this.GetDBModelByUid(uid, this.modelAtlas.TableName, this.modelAtlas.Expired); err == nil { + + if err := model.Get(uid, atlas); err != nil { // 防止数据没有初始化情况 + if mongo.ErrNoDocuments == err { + atlas.Id = primitive.NewObjectID().Hex() + atlas.Uid = uid + atlas.Atlas = make(map[string]*pb.ForgeList, 0) + atlas.Collect = make(map[string]*pb.CollectData, 0) + atlas.Award = 1 // 初始1级 + + atlas.Collect[id] = &pb.CollectData{ + Id: id, + Score: atlasConf.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.CollectData{ + Id: id, + Score: atlasConf.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 { + if list, err := this.modelAtlas.getSmithyAtlasList(uid); err == nil { if _, ok := list.Collect[id]; !ok { list.Collect[id] = &pb.CollectData{ @@ -58,16 +110,13 @@ func (this *Smithy) CheckActivateAtlasCollect(uid string, id string) (code pb.Er Time: configure.Now().Unix(), Activate: false, } - //list.Score += atlasConf.AtlasScore update := make(map[string]interface{}, 0) update["collect"] = list.Collect - //update["score"] = list.Score this.modelAtlas.modifySmithyAtlasList(uid, update) // 更新信息 return } } } - code = pb.ErrorCode_SmithyNoFoundAtlas return } diff --git a/pb/errorcode.pb.go b/pb/errorcode.pb.go index 510d016d8..4a54a1ffe 100644 --- a/pb/errorcode.pb.go +++ b/pb/errorcode.pb.go @@ -340,6 +340,7 @@ const ( ErrorCode_SmithyNoActivateAtlas ErrorCode = 4113 // 没有图鉴更新数据 ErrorCode_SmithyLvToolsFailed ErrorCode = 4114 // ErrorCode_SmithyLvToolsPre ErrorCode = 4115 // 前置条件不足 + ErrorCode_SmithyAtlasTypeErr ErrorCode = 4116 //图鉴类型错误 // dispatch ErrorCode_DispatchHeroNoReached ErrorCode = 4201 //英雄条件未达标 ErrorCode_DispatchNoFree ErrorCode = 4202 //免费次数用尽 @@ -643,6 +644,7 @@ var ( 4113: "SmithyNoActivateAtlas", 4114: "SmithyLvToolsFailed", 4115: "SmithyLvToolsPre", + 4116: "SmithyAtlasTypeErr", 4201: "DispatchHeroNoReached", 4202: "DispatchNoFree", 4203: "DispatchTicketNoEnough", @@ -941,6 +943,7 @@ var ( "SmithyNoActivateAtlas": 4113, "SmithyLvToolsFailed": 4114, "SmithyLvToolsPre": 4115, + "SmithyAtlasTypeErr": 4116, "DispatchHeroNoReached": 4201, "DispatchNoFree": 4202, "DispatchTicketNoEnough": 4203, @@ -986,7 +989,7 @@ var File_errorcode_proto protoreflect.FileDescriptor var file_errorcode_proto_rawDesc = []byte{ 0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2a, 0xe5, 0x35, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, + 0x6f, 0x2a, 0xfe, 0x35, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x45, 0x78, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x10, 0x01, 0x12, 0x11, 0x0a, 0x0d, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, @@ -1399,25 +1402,27 @@ var file_errorcode_proto_rawDesc = []byte{ 0x20, 0x12, 0x18, 0x0a, 0x13, 0x53, 0x6d, 0x69, 0x74, 0x68, 0x79, 0x4c, 0x76, 0x54, 0x6f, 0x6f, 0x6c, 0x73, 0x46, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x10, 0x92, 0x20, 0x12, 0x15, 0x0a, 0x10, 0x53, 0x6d, 0x69, 0x74, 0x68, 0x79, 0x4c, 0x76, 0x54, 0x6f, 0x6f, 0x6c, 0x73, 0x50, 0x72, 0x65, 0x10, - 0x93, 0x20, 0x12, 0x1a, 0x0a, 0x15, 0x44, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x48, 0x65, - 0x72, 0x6f, 0x4e, 0x6f, 0x52, 0x65, 0x61, 0x63, 0x68, 0x65, 0x64, 0x10, 0xe9, 0x20, 0x12, 0x13, - 0x0a, 0x0e, 0x44, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x4e, 0x6f, 0x46, 0x72, 0x65, 0x65, - 0x10, 0xea, 0x20, 0x12, 0x1b, 0x0a, 0x16, 0x44, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x54, - 0x69, 0x63, 0x6b, 0x65, 0x74, 0x4e, 0x6f, 0x45, 0x6e, 0x6f, 0x75, 0x67, 0x68, 0x10, 0xeb, 0x20, + 0x93, 0x20, 0x12, 0x17, 0x0a, 0x12, 0x53, 0x6d, 0x69, 0x74, 0x68, 0x79, 0x41, 0x74, 0x6c, 0x61, + 0x73, 0x54, 0x79, 0x70, 0x65, 0x45, 0x72, 0x72, 0x10, 0x94, 0x20, 0x12, 0x1a, 0x0a, 0x15, 0x44, + 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x48, 0x65, 0x72, 0x6f, 0x4e, 0x6f, 0x52, 0x65, 0x61, + 0x63, 0x68, 0x65, 0x64, 0x10, 0xe9, 0x20, 0x12, 0x13, 0x0a, 0x0e, 0x44, 0x69, 0x73, 0x70, 0x61, + 0x74, 0x63, 0x68, 0x4e, 0x6f, 0x46, 0x72, 0x65, 0x65, 0x10, 0xea, 0x20, 0x12, 0x1b, 0x0a, 0x16, + 0x44, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x54, 0x69, 0x63, 0x6b, 0x65, 0x74, 0x4e, 0x6f, + 0x45, 0x6e, 0x6f, 0x75, 0x67, 0x68, 0x10, 0xeb, 0x20, 0x12, 0x19, 0x0a, 0x14, 0x44, 0x69, 0x73, + 0x70, 0x61, 0x74, 0x63, 0x68, 0x48, 0x65, 0x72, 0x6f, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x65, + 0x64, 0x10, 0xec, 0x20, 0x12, 0x18, 0x0a, 0x13, 0x44, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, + 0x54, 0x61, 0x73, 0x6b, 0x45, 0x78, 0x70, 0x69, 0x72, 0x65, 0x64, 0x10, 0xed, 0x20, 0x12, 0x17, + 0x0a, 0x12, 0x44, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, + 0x68, 0x4d, 0x61, 0x78, 0x10, 0xee, 0x20, 0x12, 0x17, 0x0a, 0x12, 0x44, 0x69, 0x73, 0x70, 0x61, + 0x74, 0x63, 0x68, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64, 0x10, 0xef, 0x20, 0x12, 0x19, 0x0a, 0x14, 0x44, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x48, 0x65, 0x72, 0x6f, - 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x10, 0xec, 0x20, 0x12, 0x18, 0x0a, 0x13, 0x44, - 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x54, 0x61, 0x73, 0x6b, 0x45, 0x78, 0x70, 0x69, 0x72, - 0x65, 0x64, 0x10, 0xed, 0x20, 0x12, 0x17, 0x0a, 0x12, 0x44, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, - 0x68, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x4d, 0x61, 0x78, 0x10, 0xee, 0x20, 0x12, 0x17, - 0x0a, 0x12, 0x44, 0x69, 0x73, 0x70, 0x61, 0x74, 0x63, 0x68, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x69, - 0x73, 0x68, 0x65, 0x64, 0x10, 0xef, 0x20, 0x12, 0x19, 0x0a, 0x14, 0x44, 0x69, 0x73, 0x70, 0x61, - 0x74, 0x63, 0x68, 0x48, 0x65, 0x72, 0x6f, 0x4e, 0x6f, 0x45, 0x6e, 0x6f, 0x75, 0x67, 0x68, 0x10, - 0xf0, 0x20, 0x12, 0x16, 0x0a, 0x11, 0x50, 0x72, 0x61, 0x63, 0x74, 0x69, 0x63, 0x65, 0x51, 0x69, - 0x65, 0x63, 0x75, 0x6f, 0x69, 0x6e, 0x67, 0x10, 0xcd, 0x21, 0x12, 0x11, 0x0a, 0x0c, 0x50, 0x72, - 0x61, 0x63, 0x74, 0x69, 0x63, 0x65, 0x53, 0x65, 0x6e, 0x74, 0x10, 0xce, 0x21, 0x12, 0x1a, 0x0a, - 0x15, 0x50, 0x72, 0x61, 0x63, 0x74, 0x69, 0x63, 0x65, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x54, - 0x69, 0x6d, 0x65, 0x4f, 0x75, 0x74, 0x10, 0xcf, 0x21, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, - 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x4e, 0x6f, 0x45, 0x6e, 0x6f, 0x75, 0x67, 0x68, 0x10, 0xf0, 0x20, 0x12, 0x16, 0x0a, 0x11, 0x50, + 0x72, 0x61, 0x63, 0x74, 0x69, 0x63, 0x65, 0x51, 0x69, 0x65, 0x63, 0x75, 0x6f, 0x69, 0x6e, 0x67, + 0x10, 0xcd, 0x21, 0x12, 0x11, 0x0a, 0x0c, 0x50, 0x72, 0x61, 0x63, 0x74, 0x69, 0x63, 0x65, 0x53, + 0x65, 0x6e, 0x74, 0x10, 0xce, 0x21, 0x12, 0x1a, 0x0a, 0x15, 0x50, 0x72, 0x61, 0x63, 0x74, 0x69, + 0x63, 0x65, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x4f, 0x75, 0x74, 0x10, + 0xcf, 0x21, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var (