优化
This commit is contained in:
parent
380c658687
commit
b0fc8396fb
@ -2,9 +2,9 @@ package pagoda
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/db"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
@ -27,6 +27,7 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.PagodaChal
|
||||
mapData map[string]interface{}
|
||||
pagoda *pb.DBPagoda
|
||||
seasonPagoda *pb.DBSeasonPagoda
|
||||
costTime int32 // 本次战斗消耗的时间
|
||||
)
|
||||
mapData = make(map[string]interface{}, 0)
|
||||
code = this.ChallengeOverCheck(session, req)
|
||||
@ -55,7 +56,6 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.PagodaChal
|
||||
code = pb.ErrorCode_PagodaLevlErr // 挑战关卡数据不匹配
|
||||
return
|
||||
}
|
||||
|
||||
} else {
|
||||
// 塔数据校验
|
||||
seasonPagoda, err = this.module.modelSeasonPagoda.getSeasonPagodaList(session.GetUserId())
|
||||
@ -111,24 +111,11 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.PagodaChal
|
||||
}
|
||||
}
|
||||
}
|
||||
if !this.module.IsCross() {
|
||||
if conn, err := db.Cross(); err == nil {
|
||||
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,
|
||||
}
|
||||
|
||||
conn.Mgo.InsertOne(comm.TablePagodaRecord, newData)
|
||||
}
|
||||
if req.Report != nil {
|
||||
costTime = req.Report.Costtime
|
||||
}
|
||||
//this.module.modulerank.addPagodaList(session, pagoda, req.Report.Info.Redflist[0].Leadpos, sz, req.Report.Costtime)
|
||||
|
||||
this.module.modulerank.SetNormalPagodaRankList("pagodaRank", pagoda.PagodaId<<8+costTime, session.GetUserId())
|
||||
}
|
||||
// 普通塔通关了
|
||||
Nomalcfg := this.module.configure.GetPagodaConfigData(comm.PagodaType, pagoda.PagodaId+1)
|
||||
@ -157,6 +144,8 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.PagodaChal
|
||||
session.SendMsg(string(this.module.GetType()), PagodaGetListResp, &pb.PagodaGetListResp{Data: pagoda})
|
||||
}
|
||||
} else {
|
||||
seasonPagoda.PagodaId = conf.LayerNum
|
||||
mapData["pagodaId"] = conf.LayerNum
|
||||
// 记录爬塔明细数据
|
||||
if req.Report != nil && req.Report.Info != nil && len(req.Report.Info.Redflist) > 0 {
|
||||
sz := make([]*pb.LineUp, 5)
|
||||
@ -170,6 +159,7 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.PagodaChal
|
||||
}
|
||||
}
|
||||
// 数据直接插入跨服数据库中
|
||||
uid := session.GetUserId()
|
||||
userinfo := this.module.ModuleUser.GetUser(session.GetUserId())
|
||||
newData := &pb.DBPagodaRecord{
|
||||
Id: primitive.NewObjectID().Hex(),
|
||||
@ -181,52 +171,20 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.PagodaChal
|
||||
Lv: userinfo.Lv,
|
||||
CostTime: req.Report.Costtime,
|
||||
}
|
||||
costTime = newData.CostTime
|
||||
// 数据写到跨服中
|
||||
if !this.module.IsCross() {
|
||||
if conn, err := db.Cross(); err == nil {
|
||||
conn.Mgo.InsertOne(comm.TableSeasonRecord, newData)
|
||||
}
|
||||
}
|
||||
var dbModel *db.DBModel
|
||||
if !this.module.IsCross() {
|
||||
if dbModel, err = this.module.GetDBNoduleByUid(session.GetUserId(), comm.TableSeasonRecord, time.Hour); err == nil {
|
||||
if err = dbModel.Add(session.GetUserId(), newData); err != nil {
|
||||
this.module.Errorf("err:%v", err)
|
||||
}
|
||||
// 同步zset
|
||||
|
||||
}
|
||||
} else {
|
||||
if err = this.module.modelPagoda.Add(session.GetUserId(), newData); err != nil {
|
||||
this.module.Errorf("err:%v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
//this.module.modulerank.addPagodaRankList(session, seasonPagoda, req.Report.Info.Redflist[0].Leadpos, sz, req.Report.Costtime)
|
||||
}
|
||||
|
||||
// 挑战处理
|
||||
seasonPagoda.PagodaId = conf.LayerNum
|
||||
mapData["pagodaId"] = conf.LayerNum
|
||||
if !this.module.IsCross() {
|
||||
if conn, err := db.Cross(); err == nil {
|
||||
data := &comm.Autogenerated{
|
||||
ID: primitive.NewObjectID().Hex(),
|
||||
UID: seasonPagoda.Uid,
|
||||
Act: string(comm.LogHandleType_Update),
|
||||
}
|
||||
table := comm.TableSeasonRecord //, uid, , data)
|
||||
data.D = append(data.D, table) // D[0]
|
||||
data.D = append(data.D, bson.M{"uid": session.GetUserId()}) // D[1]
|
||||
data.D = append(data.D, seasonPagoda) // D[2]
|
||||
|
||||
_, err = conn.Mgo.InsertOne("model_log", data)
|
||||
if err != nil {
|
||||
log.Errorf("insert model db err %v", err)
|
||||
}
|
||||
conn_, err := db.Cross()
|
||||
dbModel := db.NewDBModel(comm.TableSeasonRecord, time.Hour, conn_)
|
||||
//if err = dbModel.GetList(uid, newData); err == nil {
|
||||
dbModel.AddList(uid, newData.Id, newData)
|
||||
this.module.SetPagodaRankList("pagodaList"+strconv.Itoa(int(newData.PagodaId)), newData.CostTime, newData.Id)
|
||||
//}
|
||||
dbModelTable := db.NewDBModel(comm.TableSeasonPagoda, time.Hour, conn_)
|
||||
if err = dbModelTable.Get(session.GetUserId(), seasonPagoda); err == nil {
|
||||
dbModelTable.Change(session.GetUserId(), mapData) // 修改跨服数据
|
||||
this.module.SetPagodaRankList("pagodaSeasonRank", seasonPagoda.PagodaId<<8+costTime, session.GetUserId())
|
||||
}
|
||||
}
|
||||
|
||||
code = this.module.ModifySeasonPagodaData(session.GetUserId(), mapData)
|
||||
pagoda = &pb.DBPagoda{
|
||||
Id: seasonPagoda.Id,
|
||||
|
@ -61,6 +61,10 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.PagodaGetListReq
|
||||
Type: season.Type,
|
||||
}
|
||||
}
|
||||
this.RankList(session, &pb.PagodaRankListReq{
|
||||
FloorId: 0,
|
||||
Friend: false,
|
||||
})
|
||||
session.SendMsg(string(this.module.GetType()), PagodaGetListResp, &pb.PagodaGetListResp{Data: list})
|
||||
return
|
||||
}
|
||||
|
@ -1,9 +1,15 @@
|
||||
package pagoda
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/sys/redis/pipe"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/db"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
@ -16,22 +22,39 @@ func (this *apiComp) RankListCheck(session comm.IUserSession, req *pb.PagodaRank
|
||||
func (this *apiComp) RankList(session comm.IUserSession, req *pb.PagodaRankListReq) (code pb.ErrorCode, data proto.Message) {
|
||||
var (
|
||||
szRank []*pb.DBPagodaRecord
|
||||
err error
|
||||
rd *redis.StringSliceCmd
|
||||
)
|
||||
code = this.RankListCheck(session, req)
|
||||
if code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
if !req.Friend {
|
||||
if req.FloorId == 0 {
|
||||
szRank, err = this.module.modulerank.GetRankData()
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
}
|
||||
} else {
|
||||
szRank, err = this.module.modulerank.GetFloorRankList(req.FloorId)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
if !this.module.IsCross() {
|
||||
if conn, err := db.Cross(); err == nil {
|
||||
var (
|
||||
pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO())
|
||||
)
|
||||
if req.FloorId == 0 {
|
||||
rd = pipe.ZRange("pagodaSeasonRank"+strconv.Itoa(int(req.FloorId)), 0, 50)
|
||||
} else {
|
||||
rd = pipe.ZRange("pagodaList"+strconv.Itoa(int(req.FloorId)), 0, 50)
|
||||
}
|
||||
|
||||
if _, err = pipe.Exec(); err != nil {
|
||||
this.module.Errorln(err)
|
||||
return
|
||||
}
|
||||
_data3 := rd.Val()
|
||||
_data, err2 := rd.Result()
|
||||
this.module.Errorln(_data, err2, _data3)
|
||||
for _, v := range _data3 {
|
||||
conn_, err := db.Cross()
|
||||
dbModel := db.NewDBModel(comm.TableSeasonRecord, time.Hour, conn_)
|
||||
result := &pb.DBPagodaRecord{}
|
||||
if err = dbModel.GetListObj(session.GetUserId(), v, result); err == nil {
|
||||
szRank = append(szRank, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,17 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/lego/sys/redis"
|
||||
|
||||
//"go_dreamfactory/lego/sys/redis"
|
||||
"go_dreamfactory/lego/sys/redis/pipe"
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/db"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
@ -41,14 +45,14 @@ func (this *ModelRank) AddRank(uId string, data *pb.DBPagodaRecord) (err error)
|
||||
}
|
||||
|
||||
//获取用户通过扩展表
|
||||
func (this *ModelRank) GetUserRandData(uid string) (result *pb.DBPagodaRecord, err error) {
|
||||
result = &pb.DBPagodaRecord{}
|
||||
if err = this.Get(uid, result); err != nil && redis.RedisNil != err {
|
||||
return
|
||||
}
|
||||
err = nil
|
||||
return result, err
|
||||
}
|
||||
// func (this *ModelRank) GetUserRandData(uid string) (result *pb.DBPagodaRecord, err error) {
|
||||
// result = &pb.DBPagodaRecord{}
|
||||
// if err = this.Get(uid, result); err != nil && redis.RedisNil != err {
|
||||
// return
|
||||
// }
|
||||
// err = nil
|
||||
// return result, err
|
||||
// }
|
||||
|
||||
func (this *ModelRank) ChangeUserRank(uid string, value map[string]interface{}) (err error) {
|
||||
if len(value) == 0 {
|
||||
@ -237,3 +241,27 @@ func (this *ModelRank) getPagodaRankListByFloorid(uid string, floorid int32) *pb
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//设置本服
|
||||
func (this *ModelRank) SetNormalPagodaRankList(tableName string, score int32, uid string) {
|
||||
|
||||
var (
|
||||
pipe *pipe.RedisPipe = this.DBModel.Redis.RedisPipe(context.TODO())
|
||||
menbers *redis.Z
|
||||
)
|
||||
|
||||
menbers = &redis.Z{Score: float64(score), Member: uid}
|
||||
|
||||
if cmd := pipe.ZAdd(tableName, menbers); cmd != nil {
|
||||
|
||||
dock, err1 := cmd.Result()
|
||||
if err1 != nil {
|
||||
this.modulePagoda.Errorln(dock, err1)
|
||||
}
|
||||
}
|
||||
if _, err := pipe.Exec(); err != nil {
|
||||
this.modulePagoda.Errorln(err)
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -114,38 +114,28 @@ func (this *Pagoda) CleanSeasonPagodaData() (code pb.ErrorCode) {
|
||||
return
|
||||
}
|
||||
|
||||
func (this *Pagoda) SetPagodaRank(tableName string, time int32, uid string) (err error) {
|
||||
|
||||
// redis 排序 tableName:"pagodaList"
|
||||
func (this *Pagoda) SetPagodaRankList(tableName string, score int32, uid string) {
|
||||
if !this.IsCross() {
|
||||
if conn, err1 := db.Cross(); err1 == nil {
|
||||
if conn, err := db.Cross(); err == nil {
|
||||
var (
|
||||
pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO())
|
||||
menbers *redis.Z
|
||||
)
|
||||
|
||||
menbers = &redis.Z{Score: float64(time), Member: uid}
|
||||
menbers = &redis.Z{Score: float64(score), Member: uid}
|
||||
|
||||
if cmd := pipe.ZAdd(tableName, menbers); cmd != nil {
|
||||
this.Errorln(err)
|
||||
|
||||
dock, err := cmd.Result()
|
||||
this.Errorln(dock, err)
|
||||
dock, err1 := cmd.Result()
|
||||
if err1 != nil {
|
||||
this.Errorln(dock, err1)
|
||||
}
|
||||
}
|
||||
if _, err = pipe.Exec(); err != nil {
|
||||
this.Errorln(err)
|
||||
return
|
||||
}
|
||||
//rd := pipe.ZRevRank("pagodaList", "dfmxf_6358f3f1375f6a340a12e2ab01234567")
|
||||
rd := pipe.ZRange("pagodaList", 1, 5)
|
||||
if _, err = pipe.Exec(); err != nil {
|
||||
this.Errorln(err)
|
||||
return
|
||||
}
|
||||
_data3 := rd.Val()
|
||||
_data, err2 := rd.Result()
|
||||
this.Errorln(_data, err2, _data3)
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.TrollGetListReq)
|
||||
}
|
||||
curTime = (int32(t) % circle)
|
||||
// 循环次数
|
||||
index := int32((int32(t) / circle)) * 3
|
||||
index := int32((int32(t) / circle)) * this.configure.GetTrollMaxTraintNum()
|
||||
trolltrain.TarinPos += index
|
||||
for pos, v := range sz {
|
||||
trolltrain.TarinPos++
|
||||
|
@ -139,3 +139,16 @@ func (this *configureComp) GetTrollMaxCoefficientNux() int32 {
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// 获取车站的数量
|
||||
func (this *configureComp) GetTrollMaxTraintNum() int32 {
|
||||
if v, err := this.GetConfigure(game_trolltrain); err == nil {
|
||||
if configure, ok := v.(*cfg.GameTrollTrain); ok {
|
||||
|
||||
return int32(len(configure.GetDataList()))
|
||||
}
|
||||
} else {
|
||||
log.Errorf("get GameTrollTrainData conf err:%v", err)
|
||||
}
|
||||
return 1 // 至少有1个车站
|
||||
}
|
||||
|
@ -52,24 +52,28 @@ func (this *Troll) ModifyTrollData(uid string, data map[string]interface{}) (cod
|
||||
|
||||
// AI 玩法
|
||||
func (this *Troll) TrollAI(uid string, troll *pb.DBTrollTrain) (code pb.ErrorCode) {
|
||||
var (
|
||||
trainCount int32 // 车站数量
|
||||
fTime []int32 //每个车站货物刷新的时间
|
||||
index int32 // 当前位置索引
|
||||
crossTime int32 // 经过的时间
|
||||
)
|
||||
if troll.Buy != 0 && troll.Sell != 0 {
|
||||
return
|
||||
}
|
||||
var fTime [3]int32
|
||||
for i := 0; i < 3; i++ {
|
||||
trainCount = this.configure.GetTrollMaxTraintNum()
|
||||
fTime = make([]int32, trainCount)
|
||||
for i := 0; i < int(trainCount); i++ {
|
||||
if conf := this.configure.GetTrollTrain(int32(i) + 1); conf != nil {
|
||||
fTime[i] = conf.Time
|
||||
}
|
||||
}
|
||||
var (
|
||||
index int32
|
||||
crossTime int32 // 经过的时间
|
||||
)
|
||||
|
||||
// 计算时间差
|
||||
crossTime = int32(time.Now().Unix() - troll.RefreshTime)
|
||||
for i := 0; ; i++ {
|
||||
|
||||
index = int32(i) % 3
|
||||
index = int32(i) % trainCount
|
||||
if crossTime > fTime[index] { // 获取
|
||||
troll.RangeId += 1
|
||||
if _d := this.configure.GetTrollCoefficient(troll.RangeId); _d != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user