From e9b50cae8d355b9c911d1b0331e5e0750809c56d Mon Sep 17 00:00:00 2001 From: 王家文 Date: Wed, 24 Apr 2024 15:35:17 +0800 Subject: [PATCH] feat✨:房间排行活动:排行榜数据细化 --- models/roomrank.go | 21 +++++++++++++-------- service/roomrank/dto-player.go | 3 +++ service/roomrank/dto-room.go | 8 ++++---- service/roomrank/handle.go | 4 +++- service/roomrank/logic.go | 17 +++++++++++------ service/roomrank/player.go | 3 +++ 6 files changed, 37 insertions(+), 19 deletions(-) diff --git a/models/roomrank.go b/models/roomrank.go index 87f023f..9f23c52 100644 --- a/models/roomrank.go +++ b/models/roomrank.go @@ -29,12 +29,15 @@ type RoomRankTopNode struct { // RoomRankInfo 房间排行信息 type RoomRankInfo struct { - SettleHas bool `form:"settle_has" json:"settle_has"` // 有结算内容未领取 - SettleAward string `form:"settle_award" json:"settle_award"` // 结算奖励内容 - UserClass int `form:"user_class" json:"user_class"` // 用户评级 - SelfRank int `form:"self_rank" json:"self_rank"` // 自己排名 - SelfScore int64 `form:"self_score" json:"self_score"` // 自己积分 - Tops []RoomRankTopNode `form:"tops" json:"tops"` // 排行榜数据列表 + SettleHas bool `form:"settle_has" json:"settle_has"` // 有结算内容未领取 + SettleRank int `form:"settle_rank" json:"settle_rank"` // 结算名次 + SettleScore int64 `form:"settle_score" json:"settle_score"` // 结算分数 + SettleUserClass int `form:"settle_user_class" json:"settle_user_class"` // 结算用户评级 + SettleAward string `form:"settle_award" json:"settle_award"` // 结算奖励内容 + UserClass int `form:"user_class" json:"user_class"` // 用户评级 + SelfRank int `form:"self_rank" json:"self_rank"` // 自己排名 + SelfScore int64 `form:"self_score" json:"self_score"` // 自己积分 + Tops []RoomRankTopNode `form:"tops" json:"tops"` // 排行榜数据列表 } // ReqRoomRankInfo 请求 房间排行信息 @@ -62,8 +65,10 @@ type ReqRoomRankGetSettleAward struct { // RspRoomRankGetSettleAward 返回 领取上期结算奖励 type RspRoomRankGetSettleAward struct { - AwardText string `form:"award_text" json:"award_text"` // 上期结算奖励内容 - UserClass int `form:"user_class" json:"user_class"` // 用户评级 + SettleRank int `form:"settle_rank" json:"settle_rank"` // 结算名次 + SettleScore int64 `form:"settle_score" json:"settle_score"` // 结算分数 + UserClass int `form:"user_class" json:"user_class"` // 用户评级 + AwardText string `form:"award_text" json:"award_text"` // 上期结算奖励内容 } // ReqRoomRankAddScore 请求 房间排行增加积分 diff --git a/service/roomrank/dto-player.go b/service/roomrank/dto-player.go index 1446eea..0a036d2 100644 --- a/service/roomrank/dto-player.go +++ b/service/roomrank/dto-player.go @@ -21,6 +21,9 @@ type Player struct { RoomUid int64 `gorm:"comment:所在房间唯一ID"` SettleActivityId int64 `gorm:"comment:上次结算的活动ID"` + SettleRank int `gorm:"comment:结算名次"` + SettleScore int64 `gorm:"comment:结算分数"` + SettleUserClass int `gorm:"comment:结算用户评级"` SettleAward string `gorm:"comment:结算奖励内容"` CreateTime int64 `gorm:"comment:创建时间戳"` diff --git a/service/roomrank/dto-room.go b/service/roomrank/dto-room.go index 7db7342..ef9ee6d 100644 --- a/service/roomrank/dto-room.go +++ b/service/roomrank/dto-room.go @@ -72,19 +72,19 @@ func (d *Room) Decode() { } } -// FindPlayer 找到玩家排名 -1=没找到 -func (d *Room) FindPlayer(playerUid int64) int { +// FindPlayer 找到玩家排名和积分 -1=没找到 +func (d *Room) FindPlayer(playerUid int64) (int, int64) { count := len(d.Details.Players) if count > 0 { for i := 0; i < count; i++ { p := d.Details.Players[i] if p.Uid == playerUid { - return i + return i, p.Score } } } - return -1 + return -1, 0 } func (d *Room) GetPlayerTypeCount(userType int) int { diff --git a/service/roomrank/handle.go b/service/roomrank/handle.go index acef2cd..7e8f7bd 100644 --- a/service/roomrank/handle.go +++ b/service/roomrank/handle.go @@ -132,8 +132,10 @@ func HandleGetSettleAward(req *models.ReqRoomRankGetSettleAward) (code string, r oldActivityId := player.ActivityId // 领取奖励 + rsp.SettleRank = player.SettleRank + rsp.SettleScore = player.SettleScore + rsp.UserClass = player.SettleUserClass rsp.AwardText = player.SettleAward - rsp.UserClass = player.UserClass player.SettleAward = "" player.ActivityId = config.Id player.RoomUid = 0 diff --git a/service/roomrank/logic.go b/service/roomrank/logic.go index 8d0c411..664960f 100644 --- a/service/roomrank/logic.go +++ b/service/roomrank/logic.go @@ -30,16 +30,20 @@ func TrySettle(gameId string, player *Player, config *confroomrank.ActivityConfi if !hasRoom { return } - // 找到玩家在房间里的名次 - rankIndex := room.FindPlayer(player.Uid) - if rankIndex < 0 { - return - } confActivity, hasConfActivity := confroomrank.GetConfig(gameId, room.ActivityId) if !hasConfActivity { return } TrySettleRoom(gameId, room, confActivity) + + // 找到玩家在房间里的名次 + // rankIndex = 0-49 rank = 1-50 + rankIndex, rankScore := room.FindPlayer(player.Uid) + if rankIndex < 0 { + return + } + player.SettleRank = rankIndex + 1 + player.SettleScore = rankScore // 设置玩家奖励等数据 hasChange = true player.SettleActivityId = config.Id @@ -47,11 +51,12 @@ func TrySettle(gameId string, player *Player, config *confroomrank.ActivityConfi if !hasConfRoom { return } - if confAward, hasConfAward := confRoom.Awards[utstring.IntToString(rankIndex+1)]; hasConfAward { + if confAward, hasConfAward := confRoom.Awards[utstring.IntToString(player.SettleRank)]; hasConfAward { player.SettleAward = confAward } if len(confRoom.SettleScores) > rankIndex { player.AddUserScore(confRoom.SettleScores[rankIndex]) + player.SettleUserClass = player.UserClass } if len(confRoom.SettleUserType) > rankIndex { player.UserType = confRoom.SettleUserType[rankIndex] diff --git a/service/roomrank/player.go b/service/roomrank/player.go index d7c5bb8..589edbf 100644 --- a/service/roomrank/player.go +++ b/service/roomrank/player.go @@ -71,6 +71,9 @@ func GetInfoFromSettle(player *Player, config *confroomrank.ActivityConfig) mode info := models.RoomRankInfo{} if player.SettleHas() { info.SettleHas = true + info.SettleRank = player.SettleRank + info.SettleScore = player.SettleScore + info.SettleUserClass = player.SettleUserClass info.SettleAward = player.SettleAward } return info -- libgit2 0.21.0