From 46ec0b910fbd454d936318266f0fbb645022553c Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Fri, 21 Oct 2022 12:02:54 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=88=AC=E5=A1=94=E8=B5=9B=E5=AD=A3?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/pagoda/api_getlist.go | 32 +++++++++++------- modules/timer/season.go | 64 +++++++++++++++++++---------------- 2 files changed, 54 insertions(+), 42 deletions(-) diff --git a/modules/pagoda/api_getlist.go b/modules/pagoda/api_getlist.go index 671123148..6cb4cde4b 100644 --- a/modules/pagoda/api_getlist.go +++ b/modules/pagoda/api_getlist.go @@ -3,7 +3,9 @@ package pagoda import ( "go_dreamfactory/comm" "go_dreamfactory/pb" + "go_dreamfactory/sys/db" + "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" "google.golang.org/protobuf/proto" ) @@ -37,18 +39,24 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.PagodaGetListReq } } else { season, _ := this.module.modelSeasonPagoda.getSeasonPagodaList(session.GetUserId()) - if season == nil { // 创建一条新的数据 - seasonPagoda := &pb.DBSeasonPagoda{} - seasonPagoda.Id = primitive.NewObjectID().Hex() - - seasonPagoda.Uid = session.GetUserId() - seasonPagoda.PagodaId = 0 // 初始数据0层 - seasonPagoda.Type = 201 // TODO 新的塔数据根据配置文件获取 - this.module.modelSeasonPagoda.addNewSeasonPagoda(session.GetUserId(), seasonPagoda) - } else { - list.PagodaId = season.PagodaId - list.Type = season.Type - list.Reward = season.Reward + if season.PagodaId == 0 { // 创建一条新的数据 + season.Id = primitive.NewObjectID().Hex() + season.Uid = session.GetUserId() + season.PagodaId = 0 // 初始数据0层 + if conn, err := db.Cross(); err == nil { + rst := conn.Mgo.FindOne(comm.TableServerData, bson.M{}) + server := &pb.DBServerData{} + rst.Decode(server) + season.Type = server.SeasonType + } + this.module.modelSeasonPagoda.addNewSeasonPagoda(session.GetUserId(), season) + } + list = &pb.DBPagoda{ + Id: season.Id, + Uid: season.Uid, + PagodaId: season.PagodaId, + Reward: season.Reward, + Type: season.Type, } } diff --git a/modules/timer/season.go b/modules/timer/season.go index 71e685ab8..c9c44e585 100644 --- a/modules/timer/season.go +++ b/modules/timer/season.go @@ -1,13 +1,13 @@ package timer import ( - "context" "fmt" "go_dreamfactory/comm" "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" + "go_dreamfactory/sys/db" "time" "go_dreamfactory/lego/core" @@ -54,6 +54,14 @@ func (this *SeasonPagoda) Start() (err error) { // for i := 0; i < 10000; i++ { // this.CreatTestData(i) // } + + // if conn, err := db.Cross(); err == nil { + // rst := conn.Mgo.FindOne(comm.TableServerData, bson.M{}) + // server := &pb.DBServerData{} + // rst.Decode(server) + // fmt.Printf("%v", server) + // } + this.TimerSeasonOver() return } @@ -87,44 +95,40 @@ func (this *SeasonPagoda) GetSeasonLoop(id int32) *cfg.GameSeasonLoopData { // // 赛季塔结束 func (this *SeasonPagoda) TimerSeasonOver() { this.module.Debugf("TimerSeasonOver:%d", time.Now().Unix()) - conf := this.GetSeasonLoop(comm.SeasonType) // 获取赛季塔重置配置 - rest, err := this.DB.Find(comm.TableServerData, bson.M{}) // 查询服务器记录的赛季塔信息 - if err != nil { - serverData := &pb.DBServerData{} - for rest.Next(context.TODO()) { - rest.Decode(serverData) - if serverData.FixedLoop == 0 { - if len(conf.DisposableLoop) >= int(serverData.DisposableLoop) && len(conf.FixedLoop) > 0 { // 开始执行循环逻辑 - serverData.FixedLoop = 1 - serverData.DisposableLoop = 0 + + if db.IsCross() { + if conn, err := db.Cross(); err == nil { + if rst := conn.Mgo.FindOne(comm.TableServerData, bson.M{}); rst != nil { + serverData := &pb.DBServerData{} + rst.Decode(serverData) + conf := this.GetSeasonLoop(comm.SeasonType) // 获取赛季塔重置配置 + if serverData.FixedLoop == 0 { + if len(conf.DisposableLoop) >= int(serverData.DisposableLoop) && len(conf.FixedLoop) > 0 { // 开始执行循环逻辑 + serverData.FixedLoop = 1 + serverData.DisposableLoop = 0 + serverData.SeasonType = conf.FixedLoop[int(serverData.FixedLoop)-1] + } else { + serverData.DisposableLoop++ + serverData.SeasonType = conf.DisposableLoop[int(serverData.DisposableLoop)-1] + } + + } else { // 循环 + if len(conf.FixedLoop) >= int(serverData.FixedLoop) { + serverData.FixedLoop = 1 + } else { + serverData.FixedLoop++ + } serverData.SeasonType = conf.FixedLoop[int(serverData.FixedLoop)-1] - } else { - serverData.DisposableLoop++ - serverData.SeasonType = conf.DisposableLoop[int(serverData.DisposableLoop)-1] } - - } else { // 循环 - if len(conf.FixedLoop) >= int(serverData.FixedLoop) { - serverData.FixedLoop = 1 - } else { - serverData.FixedLoop++ - } - serverData.SeasonType = conf.FixedLoop[int(serverData.FixedLoop)-1] + this.DB.UpdateOne(comm.TableServerData, bson.M{}, serverData) + fmt.Printf("%v", serverData) } - - fmt.Printf("%v", serverData) - break } - - this.DB.UpdateOne(comm.TableServerData, bson.M{}, serverData) } //star := time.Now() this.DB.DeleteMany(comm.TableSeasonPagoda, bson.M{}, options.Delete()) //this.module.Debugf("=====%d,", time.Since(star).Milliseconds()) - - //清除redis - } // 赛季塔开始 From 30a1b1c409c29c1f0ad6f9a170ec8de1166eb418 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Fri, 21 Oct 2022 14:56:56 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=88=98=E6=96=97?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=88=A4=E6=96=AD=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/battle/module.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/battle/module.go b/modules/battle/module.go index 3e4cf169a..1ae466621 100644 --- a/modules/battle/module.go +++ b/modules/battle/module.go @@ -88,8 +88,7 @@ func (this *Battle) CreatePveBattle(session comm.IUserSession, req *pb.BattlePVE this.Errorf("session:%v err:", session, err) return } - if req.Ptype < 0 || req.Ptype > 4 || - req.Format == nil || req.Format.Format == nil || len(req.Format.Format) != 5 { + if req.Format == nil || req.Format.Format == nil || len(req.Format.Format) != 5 { code = pb.ErrorCode_ReqParameterError return } @@ -119,8 +118,7 @@ func (this *Battle) CreatePvbBattle(session comm.IUserSession, req *pb.BattlePVE this.Errorf("session:%v err:", session, err) return } - if req.Ptype < 0 || req.Ptype > 4 || - req.Format == nil || req.Format.Format == nil || len(req.Format.Format) != 5 { + if req.Format == nil || req.Format.Format == nil || len(req.Format.Format) != 5 { code = pb.ErrorCode_ReqParameterError return }