refactor: 重构 PVP 匹配逻辑使用模型结构体
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"blazing/common/data"
|
||||
"blazing/cool"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/tnnmigga/enum"
|
||||
)
|
||||
|
||||
@@ -20,6 +21,17 @@ type PVP struct {
|
||||
RankInfo PVPRankInfo `gorm:"type:jsonb;not null;comment:'本赛季排名信息'" json:"rank_info"`
|
||||
}
|
||||
|
||||
func (u *PVP) Key() uint32 {
|
||||
return uint32(u.ID)
|
||||
}
|
||||
|
||||
// 如果分数不对的话,就按时间排序
|
||||
func (u *PVP) Less(than *PVP) bool {
|
||||
if u.RankInfo.Score == than.RankInfo.Score {
|
||||
return u.RankInfo.LastMatchTime.Unix() < than.RankInfo.LastMatchTime.Unix()
|
||||
}
|
||||
return u.RankInfo.Score < than.RankInfo.Score
|
||||
}
|
||||
func NewPVP() *PVP {
|
||||
return &PVP{
|
||||
Model: cool.NewModel(),
|
||||
@@ -29,16 +41,16 @@ func NewPVP() *PVP {
|
||||
// PVPSeasonData PVP赛季核心统计数据
|
||||
// 聚合维度:总场次、胜负、积分、胜率等
|
||||
type PVPRankInfo struct {
|
||||
Rank uint32 `json:"rank"` // 本赛季全服排名(0=未上榜)
|
||||
Score int32 `json:"score"` // 当前积分
|
||||
TotalMatch uint32 `json:"total_match"` // 本赛季总场次
|
||||
WinMatch uint32 `json:"win_match"` // 本赛季胜利场次
|
||||
LoseMatch uint32 `json:"lose_match"` // 本赛季失败场次
|
||||
DrawMatch uint32 `json:"draw_match"` // 本赛季平局场次
|
||||
TotalScore int32 `json:"total_score"` // 本赛季总积分(胜加负减)
|
||||
HighestScore int32 `json:"highest_score"` // 本赛季最高积分
|
||||
ContinuousWin uint32 `json:"continuous_win"` // 本赛季最高连胜次数
|
||||
LastMatchTime uint64 `json:"last_match_time"` // 最后一场PVP时间(时间戳)
|
||||
Rank uint32 `json:"rank"` // 本赛季全服排名(0=未上榜)
|
||||
Score int `json:"score"` // 当前积分
|
||||
TotalMatch uint32 `json:"total_match"` // 本赛季总场次
|
||||
WinMatch uint32 `json:"win_match"` // 本赛季胜利场次
|
||||
LoseMatch uint32 `json:"lose_match"` // 本赛季失败场次
|
||||
DrawMatch uint32 `json:"draw_match"` // 本赛季平局场次
|
||||
TotalScore int32 `json:"total_score"` // 本赛季总积分(胜加负减)
|
||||
HighestScore int32 `json:"highest_score"` // 本赛季最高积分
|
||||
ContinuousWin uint32 `json:"continuous_win"` // 本赛季最高连胜次数
|
||||
LastMatchTime *gtime.Time `json:"last_match_time"` // 最后一场PVP时间(时间戳)
|
||||
}
|
||||
|
||||
// NoteReadyToFightInfo 战斗准备就绪消息结构体,NoteReadyToFightInfo
|
||||
|
||||
Reference in New Issue
Block a user