diff --git a/modules/hero/model_hero.go b/modules/hero/model_hero.go index ed103de59..3cdd7ba7c 100644 --- a/modules/hero/model_hero.go +++ b/modules/hero/model_hero.go @@ -547,7 +547,7 @@ func (this *ModelHero) AddCardExp(session comm.IUserSession, hero *pb.DBHero, ex hero.SameCount -= 1 newhero = this.CloneNewHero(hero) // 克隆一个新的 } - + this.moduleHero.Debugf("add hero exp :old lv:%d,old exp:%d,new lv:%d,new exp:%d,addexp:%d", hero.Lv, hero.Exp, curLv, curExp, exp) update["lv"] = curLv update["exp"] = curExp update["isOverlying"] = false @@ -557,7 +557,7 @@ func (this *ModelHero) AddCardExp(session comm.IUserSession, hero *pb.DBHero, ex hero.Exp = curExp hero.IsOverlying = false hero.SameCount = 1 - this.moduleHero.Debugf("add hero exp :%v", hero) + if err := this.ChangeList(session.GetUserId(), hero.Id, update); err != nil { this.moduleHero.Errorf("add hero exp failed ChangeList %v", err) code = pb.ErrorCode_DBError diff --git a/modules/pagoda/api_activate.go b/modules/pagoda/api_activate.go index aada19c85..8ea7d0eb6 100644 --- a/modules/pagoda/api_activate.go +++ b/modules/pagoda/api_activate.go @@ -22,13 +22,19 @@ func (this *apiComp) Activate(session comm.IUserSession, req *pb.PagodaActivateR var ( list *pb.DBPagoda ) - this.ActivateCheck(session, req) - expand, err := this.module.ModuleUser.GetUserExpand(session.GetUserId()) + list, err := this.module.modelPagoda.getPagodaList(session.GetUserId()) if err != nil { code = pb.ErrorCode_DBError return } - if expand.CompletePagoda { // 普通塔 + Nomalcfg := this.module.configure.GetPagodaConfigData(comm.PagodaType, list.PagodaId+1) + if Nomalcfg == nil && !list.Complete { + list.Complete = true + this.module.ModifyPagodaData(session.GetUserId(), map[string]interface{}{ + "complete": true, + }) + } + if list.Complete { season, _ := this.module.modelSeasonPagoda.getSeasonPagodaList(session.GetUserId()) if season.Id == "" { season.Id = primitive.NewObjectID().Hex() diff --git a/modules/pagoda/api_challengeover.go b/modules/pagoda/api_challengeover.go index 8299e3701..aba1e8120 100644 --- a/modules/pagoda/api_challengeover.go +++ b/modules/pagoda/api_challengeover.go @@ -27,6 +27,8 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.PagodaChal pagoda *pb.DBPagoda costTime int32 // 本次战斗消耗的时间 isWin bool + err error + bSeason bool ) mapData = make(map[string]interface{}, 0) code = this.ChallengeOverCheck(session, req) @@ -34,38 +36,29 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.PagodaChal return // 参数校验失败直接返回 } - // 校验是不是通关了普通塔 - expand, err := this.module.ModuleUser.GetUserExpand(session.GetUserId()) - if err != nil { - code = pb.ErrorCode_DBError - return - } conf := this.module.configure.GetPagodaConfigData(req.PagodaType, req.LevelID) if conf == nil { code = pb.ErrorCode_PagodaNotFound return } - if !expand.CompletePagoda { - pagoda, err = this.module.modelPagoda.getPagodaList(session.GetUserId()) - if err != nil { - code = pb.ErrorCode_PagodaNotFound - return - } - if pagoda.Type != conf.PagodaType || conf.LayerNum-1 != pagoda.PagodaId { - code = pb.ErrorCode_PagodaLevlErr // 挑战关卡数据不匹配 - return - } - } else { + pagoda, err = this.module.modelPagoda.getPagodaList(session.GetUserId()) + if err != nil { + code = pb.ErrorCode_PagodaNotFound + return + } + + if pagoda.Complete { // 塔数据校验 pagoda, err = this.module.modelSeasonPagoda.getSeasonPagodaList(session.GetUserId()) if err != nil { code = pb.ErrorCode_PagodaNotFound return } - if pagoda.Type != req.PagodaType || conf.LayerNum-1 != pagoda.PagodaId { - code = pb.ErrorCode_PagodaLevlErr // 挑战关卡数据不匹配 - return - } + bSeason = true + } + if pagoda.Type != conf.PagodaType || conf.LayerNum-1 != pagoda.PagodaId { + code = pb.ErrorCode_PagodaLevlErr // 挑战关卡数据不匹配 + return } // 校验通过 code, isWin = this.module.battle.CheckBattleReport(session, req.Report) @@ -85,43 +78,27 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.PagodaChal } } } - if !expand.CompletePagoda { // 普通塔 + if !bSeason { // 普通塔 pagoda.Type = req.PagodaType mapData["pagodaId"] = conf.LayerNum mapData["type"] = pagoda.Type - pagoda.PagodaId = conf.LayerNum // 更新层数 - code = this.module.ModifyPagodaData(session.GetUserId(), mapData) - session.SendMsg(string(this.module.GetType()), PagodaChallengeOverResp, &pb.PagodaChallengeOverResp{Data: pagoda}) - - if user := this.module.ModuleUser.GetUser(session.GetUserId()); user != nil { - this.chat.SendSysChatToWorld(comm.ChatSystem4, nil, pagoda.PagodaId, 0, user.Name) - } else { - this.module.Errorf("no found userdata uid:%s", session.GetUserId()) - } - userinfo := this.module.ModuleUser.GetUser(session.GetUserId()) - newData := &pb.DBPagodaRecord{ - Id: primitive.NewObjectID().Hex(), - Uid: session.GetUserId(), - PagodaId: pagoda.PagodaId, - Type: pagoda.Type, - Nickname: userinfo.Name, - Icon: "", // icon 暂无 - Lv: userinfo.Lv, - CostTime: req.Report.Costtime, - } - costTime = newData.CostTime - this.module.modulerank.AddPagodaRecord(session.GetUserId(), newData) - //this.module.modulerank.SetNormalPagodaRankList("pagodaRank", pagoda.PagodaId<<16-costTime, session.GetUserId()) + this.module.modulerank.AddPagodaRecord(session.GetUserId(), costTime, pagoda.PagodaId, conf.PagodaType) // 普通塔通关了 Nomalcfg := this.module.configure.GetPagodaConfigData(comm.PagodaType, pagoda.PagodaId+1) if Nomalcfg == nil { - // 修改expand 数据 - update := map[string]interface{}{ - "completePagoda": true, - } - this.module.ModuleUser.ChangeUserExpand(session.GetUserId(), update) + pagoda.Complete = true + mapData["complete"] = pagoda.Complete + } + + pagoda.PagodaId = conf.LayerNum // 更新层数 + code = this.module.ModifyPagodaData(session.GetUserId(), mapData) + session.SendMsg(string(this.module.GetType()), PagodaChallengeOverResp, &pb.PagodaChallengeOverResp{Data: pagoda}) + if user := this.module.ModuleUser.GetUser(session.GetUserId()); user != nil { // 发系统公告 + this.chat.SendSysChatToWorld(comm.ChatSystem4, nil, pagoda.PagodaId, 0, user.Name) + } else { + this.module.Errorf("no found userdata uid:%s", session.GetUserId()) } } else { pagoda.PagodaId = conf.LayerNum diff --git a/modules/pagoda/api_getlist.go b/modules/pagoda/api_getlist.go index 6b7521fb3..4151aee18 100644 --- a/modules/pagoda/api_getlist.go +++ b/modules/pagoda/api_getlist.go @@ -19,14 +19,8 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.PagodaGetListReq var ( list *pb.DBPagoda ) - this.GetListCheck(session, req) - expand, err := this.module.ModuleUser.GetUserExpand(session.GetUserId()) - if err != nil { - code = pb.ErrorCode_DBError - return - } list, _ = this.module.modelPagoda.getPagodaList(session.GetUserId()) - if !expand.CompletePagoda { // 普通塔 + if list.Id == "" { // 普通塔 if list == nil { // redis没有数据 list = &pb.DBPagoda{} list.Id = primitive.NewObjectID().Hex() @@ -36,13 +30,8 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.PagodaGetListReq list.Type = comm.PagodaType this.module.modelPagoda.addNewPagoda(session.GetUserId(), list) } - } else { - season, _ := this.module.modelSeasonPagoda.getSeasonPagodaList(session.GetUserId()) - if season.Id == "" { - list.Complete = true - } else { - list = season - } + } else if list.Complete { + list, _ = this.module.modelSeasonPagoda.getSeasonPagodaList(session.GetUserId()) } session.SendMsg(string(this.module.GetType()), PagodaGetListResp, &pb.PagodaGetListResp{Data: list}) diff --git a/modules/pagoda/model_pagoda.go b/modules/pagoda/model_pagoda.go index 1b3f1591f..0bd90c69d 100644 --- a/modules/pagoda/model_pagoda.go +++ b/modules/pagoda/model_pagoda.go @@ -3,7 +3,7 @@ package pagoda import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" - "go_dreamfactory/lego/sys/redis" + "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/modules" "go_dreamfactory/pb" @@ -30,10 +30,8 @@ func (this *ModelPagoda) Init(service core.IService, module core.IModule, comp c // 获取爬塔信息 func (this *ModelPagoda) getPagodaList(uid string) (result *pb.DBPagoda, err error) { result = &pb.DBPagoda{} - if err = this.Get(uid, result); err != nil { - if redis.RedisNil != err { - result = nil - } + if err = this.Get(uid, result); err != nil && err == mgo.MongodbNil { + err = nil return } err = nil diff --git a/modules/pagoda/model_rank.go b/modules/pagoda/model_rank.go index e4ebb1abb..877a16f6f 100644 --- a/modules/pagoda/model_rank.go +++ b/modules/pagoda/model_rank.go @@ -14,6 +14,7 @@ import ( "go_dreamfactory/sys/db" "github.com/go-redis/redis/v8" + "go.mongodb.org/mongo-driver/bson/primitive" ) var floorRankKey = "pagoda:floor" @@ -40,8 +41,20 @@ func (this *ModelRank) GetRankData() (data []*pb.DBPagodaRecord, err error) { return } -func (this *ModelRank) AddPagodaRecord(uid string, record *pb.DBPagodaRecord) (err error) { - err = this.AddList(uid, record.Id, record) +// 写记录 +func (this *ModelRank) AddPagodaRecord(uid string, costTime, pagodaId, pagodaType int32) (err error) { + userinfo := this.modulePagoda.ModuleUser.GetUser(uid) + newData := &pb.DBPagodaRecord{ + Id: primitive.NewObjectID().Hex(), + Uid: uid, + PagodaId: pagodaId, + Type: pagodaType, + Nickname: userinfo.Name, + Icon: "", // icon 暂无 + Lv: userinfo.Lv, + CostTime: costTime, + } + err = this.AddList(uid, newData.Id, newData) return } diff --git a/modules/pagoda/module.go b/modules/pagoda/module.go index 98b48abef..50e1df804 100644 --- a/modules/pagoda/module.go +++ b/modules/pagoda/module.go @@ -241,43 +241,27 @@ func (this *Pagoda) CheckPagodaMaxFloor(uid string, pagodaType int32) int32 { // 赛季塔跳转 func (this *Pagoda) ModifySeasonPagodaFloor(session comm.IUserSession, level int32) (code pb.ErrorCode) { + list, _ := this.modelSeasonPagoda.getSeasonPagodaList(session.GetUserId()) + if list.Id == "" { + list.Id = primitive.NewObjectID().Hex() + list.Uid = session.GetUserId() + list.PagodaId = level + if conn, err := db.Cross(); err == nil { + rst := conn.Mgo.FindOne(comm.TableServerData, bson.M{}) + server := &pb.DBServerData{} + rst.Decode(server) + list.Type = server.SeasonType - expand, err := this.ModuleUser.GetUserExpand(session.GetUserId()) - if err != nil { - code = pb.ErrorCode_DBError - return - } - if !expand.CompletePagoda { // 普通塔 - expand.CompletePagoda = true - update := map[string]interface{}{ - "completePagoda": true, - } - this.ModuleUser.ChangeUserExpand(session.GetUserId(), update) - list, _ := this.modelSeasonPagoda.getSeasonPagodaList(session.GetUserId()) - if list.Id == "" { - list.Id = primitive.NewObjectID().Hex() - list.Uid = session.GetUserId() - list.PagodaId = level - if conn, err := db.Cross(); err == nil { - rst := conn.Mgo.FindOne(comm.TableServerData, bson.M{}) - server := &pb.DBServerData{} - rst.Decode(server) - list.Type = server.SeasonType - - } - this.modelSeasonPagoda.addNewSeasonPagoda(session.GetUserId(), list) - session.SendMsg(string(this.GetType()), PagodaGetListResp, &pb.PagodaGetListResp{Data: list}) } + this.modelSeasonPagoda.addNewSeasonPagoda(session.GetUserId(), list) + session.SendMsg(string(this.GetType()), PagodaGetListResp, &pb.PagodaGetListResp{Data: list}) } else { - list, _ := this.modelSeasonPagoda.getSeasonPagodaList(session.GetUserId()) - if list.Id != "" { - list.PagodaId = level - mapData := make(map[string]interface{}, 0) - mapData["pagodaId"] = level - code = this.ModifySeasonPagodaData(session.GetUserId(), mapData) - session.SendMsg(string(this.GetType()), PagodaGetListResp, &pb.PagodaGetListResp{Data: list}) - } + list.PagodaId = level + mapData := make(map[string]interface{}, 0) + mapData["pagodaId"] = level + code = this.ModifySeasonPagodaData(session.GetUserId(), mapData) + session.SendMsg(string(this.GetType()), PagodaGetListResp, &pb.PagodaGetListResp{Data: list}) } return