This commit is contained in:
liwei1dao 2022-10-21 15:00:16 +08:00
commit 04b0c315ab
3 changed files with 56 additions and 46 deletions

View File

@ -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
}

View File

@ -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,
}
}

View File

@ -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
}
// 赛季塔开始