From 7400744e09913cf2d522d47ec6a946c4bb6b3987 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Thu, 28 Dec 2023 16:33:30 +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 --- modules/viking/model_rank.go | 36 ++++++++++++++++++----------------- modules/viking/model_srank.go | 31 +++++++++++++++++------------- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/modules/viking/model_rank.go b/modules/viking/model_rank.go index 3b8f482d9..ae3d881ee 100644 --- a/modules/viking/model_rank.go +++ b/modules/viking/model_rank.go @@ -91,7 +91,9 @@ func (this *ModelRank) CheckRank(uid string, boosID int32, difficulty int32, lin model := db.NewDBModelByExpired(comm.TableVikingRank, conn_) // 写入排行榜 - record := &pb.DBVikingRecord{} + record := &pb.DBVikingRecord{ + Data: map[int32]*pb.ScoreData{}, + } if err = model.Get(uid, record); err == mgo.MongodbNil { record.Id = primitive.NewObjectID().Hex() record.Data = make(map[int32]*pb.ScoreData, 0) @@ -111,7 +113,7 @@ func (this *ModelRank) CheckRank(uid string, boosID int32, difficulty int32, lin tmp := make(map[int32]int32, 0) tmp[difficulty] = costTime - if record.Data[boosID] == nil { + if _, ok := record.Data[boosID]; !ok { record.Data[boosID] = &pb.ScoreData{ Costime: tmp, Maxnandu: difficulty, @@ -137,27 +139,27 @@ func (this *ModelRank) CheckRank(uid string, boosID int32, difficulty int32, lin } update := make(map[string]interface{}, 0) update["uinfo"] = record.Uinfo - if record.Data == nil { - record.Data = make(map[int32]*pb.ScoreData) - } + if _, ok := record.Data[boosID]; !ok { + tmp := make(map[int32]int32, 0) + tmp[difficulty] = costTime + mpLine := make(map[int32]*pb.LineData, 0) + mpLine[difficulty] = line record.Data[boosID] = &pb.ScoreData{ - Costime: map[int32]int32{}, - Maxnandu: 0, - Line: map[int32]*pb.LineData{}, + Costime: tmp, + Maxnandu: difficulty, + Line: mpLine, } - } - if record.Data[boosID] == nil { - record.Data[boosID].Costime = make(map[int32]int32, 0) - record.Data[boosID].Line = make(map[int32]*pb.LineData, 0) - } - if record.Data[boosID].Maxnandu < difficulty { - record.Data[boosID].Maxnandu = difficulty } else { - if record.Data[boosID].Costime[difficulty] > costTime { // 不是新记录不写 - return + if record.Data[boosID].Maxnandu < difficulty { + record.Data[boosID].Maxnandu = difficulty + } else { + if record.Data[boosID].Costime[difficulty] > costTime { // 不是新记录不写 + return + } } } + record.Data[boosID].Costime[difficulty] = costTime record.Data[boosID].Line[difficulty] = line update["data"] = record.Data diff --git a/modules/viking/model_srank.go b/modules/viking/model_srank.go index f202378e2..0b123b652 100644 --- a/modules/viking/model_srank.go +++ b/modules/viking/model_srank.go @@ -122,8 +122,7 @@ func (this *ModelSRank) CheckSeasonRank(uid string, boosID int32, difficulty int record = &pb.DBVSeasonRecord{ Id: "", Uinfo: &pb.BaseUserInfo{}, - Data: map[int32]*pb.HuiheData{}, - //Line: &pb.LineData{}, + Data: make(map[int32]*pb.HuiheData, 0), } if err = model.Get(uid, record); err == mgo.MongodbNil { record.Id = primitive.NewObjectID().Hex() @@ -144,7 +143,7 @@ func (this *ModelSRank) CheckSeasonRank(uid string, boosID int32, difficulty int tmp := make(map[int32]int32, 0) tmp[difficulty] = huihe - if record.Data[boosID] == nil { + if _, ok := record.Data[boosID]; !ok { record.Data[boosID] = &pb.HuiheData{ Huihe: tmp, Maxnandu: difficulty, @@ -158,7 +157,6 @@ func (this *ModelSRank) CheckSeasonRank(uid string, boosID int32, difficulty int model.Add(uid, record) } else if err == nil { - record.Uinfo = &pb.BaseUserInfo{ Uid: uid, Sid: user.Sid, @@ -170,16 +168,23 @@ func (this *ModelSRank) CheckSeasonRank(uid string, boosID int32, difficulty int Lv: user.Lv, } update["uinfo"] = record.Uinfo - if record.Data[boosID] == nil { - record.Data[boosID].Huihe = make(map[int32]int32, 0) - record.Data[boosID].Line = make(map[int32]*pb.LineData, 0) - } - - if record.Data[boosID].Maxnandu < difficulty { - record.Data[boosID].Maxnandu = difficulty + if _, ok := record.Data[boosID]; !ok { + mpLine := make(map[int32]*pb.LineData, 0) + mpLine[difficulty] = line + tmp := make(map[int32]int32, 0) + tmp[difficulty] = huihe + record.Data[boosID] = &pb.HuiheData{ + Huihe: tmp, + Maxnandu: difficulty, + Line: mpLine, + } } else { - if record.Data[boosID].Huihe[difficulty] > huihe { // 不是新记录不写 - return + if record.Data[boosID].Maxnandu < difficulty { + record.Data[boosID].Maxnandu = difficulty + } else { + if record.Data[boosID].Huihe[difficulty] > huihe { // 不是新记录不写 + return + } } } record.Data[boosID].Huihe[difficulty] = huihe