Commit 7194495268a93d03ad9449818a65fde18b569bc4

Authored by 王家文
1 parent 34aa5a19
Exists in master

feat✨:排行榜功能 发送已结算的排行榜信息

models/roomrank.go
@@ -64,10 +64,11 @@ type ReqRoomRankGetSettleAward struct { @@ -64,10 +64,11 @@ type ReqRoomRankGetSettleAward struct {
64 64
65 // RspRoomRankGetSettleAward 返回 领取上期结算奖励 65 // RspRoomRankGetSettleAward 返回 领取上期结算奖励
66 type RspRoomRankGetSettleAward struct { 66 type RspRoomRankGetSettleAward struct {
67 - SettleRank int `form:"settle_rank" json:"settle_rank"` // 结算名次  
68 - SettleScore int64 `form:"settle_score" json:"settle_score"` // 结算分数  
69 - UserClass int `form:"user_class" json:"user_class"` // 用户评级  
70 - AwardText string `form:"award_text" json:"award_text"` // 上期结算奖励内容 67 + SettleRank int `form:"settle_rank" json:"settle_rank"` // 结算名次
  68 + SettleScore int64 `form:"settle_score" json:"settle_score"` // 结算分数
  69 + UserClass int `form:"user_class" json:"user_class"` // 用户评级
  70 + AwardText string `form:"award_text" json:"award_text"` // 上期结算奖励内容
  71 + Tops []RoomRankTopNode `form:"tops" json:"tops"` // 排行榜数据列表
71 } 72 }
72 73
73 // ReqRoomRankAddScore 请求 房间排行增加积分 74 // ReqRoomRankAddScore 请求 房间排行增加积分
service/roomrank/handle.go
@@ -161,6 +161,18 @@ func HandleGetSettleAward(req *models.ReqRoomRankGetSettleAward) (code string, r @@ -161,6 +161,18 @@ func HandleGetSettleAward(req *models.ReqRoomRankGetSettleAward) (code string, r
161 } 161 }
162 /* ----- 结算 End -----*/ 162 /* ----- 结算 End -----*/
163 163
  164 + // 尝试发送已结算的排行榜信息
  165 + {
  166 + confActivity, hasConfActivity := confroomrank.GetConfig(gameId, player.ActivityId)
  167 + if hasConfActivity {
  168 + // 查找玩家所在的房间
  169 + room, hasRoom := TryGetRoom(gameId, req.TopType, player, confActivity)
  170 + if hasRoom {
  171 + rsp.Tops = GetTopsInfoFromRoom(room, confActivity)
  172 + }
  173 + }
  174 + }
  175 +
164 oldActivityId := player.ActivityId 176 oldActivityId := player.ActivityId
165 177
166 // 领取奖励 178 // 领取奖励
service/roomrank/player.go
@@ -131,3 +131,26 @@ func GetInfoFromRoom(gameId string, player *Player, room *Room, config *confroom @@ -131,3 +131,26 @@ func GetInfoFromRoom(gameId string, player *Player, room *Room, config *confroom
131 info.RobotAvatarPath = svcommon.GetAvatarPath(gameId) 131 info.RobotAvatarPath = svcommon.GetAvatarPath(gameId)
132 return info 132 return info
133 } 133 }
  134 +
  135 +func GetTopsInfoFromRoom(room *Room, config *confroomrank.ActivityConfig) []models.RoomRankTopNode {
  136 + info := make([]models.RoomRankTopNode, 0)
  137 + for i := 0; i < len(room.Details.Players); i++ {
  138 + p := room.Details.Players[i]
  139 + rank := i + 1
  140 + node := models.RoomRankTopNode{
  141 + Rank: rank,
  142 + Uid: p.Uid,
  143 + Score: p.Score,
  144 + Name: p.Name,
  145 + Icon: p.Icon,
  146 + IsRobot: p.IsRobot(),
  147 + }
  148 + if confRoom, hasConfRoom := config.Room[room.ConfigId]; hasConfRoom {
  149 + if confAward, hasConfAward := confRoom.Awards[zconvert.IntToStr(rank)]; hasConfAward {
  150 + node.Award = confAward
  151 + }
  152 + }
  153 + info = append(info, node)
  154 + }
  155 + return info
  156 +}