Commit e9b50cae8d355b9c911d1b0331e5e0750809c56d

Authored by 王家文
1 parent 84499c60
Exists in master and in 1 other branch dev-wjw

feat✨:房间排行活动:排行榜数据细化

models/roomrank.go
... ... @@ -29,12 +29,15 @@ type RoomRankTopNode struct {
29 29  
30 30 // RoomRankInfo 房间排行信息
31 31 type RoomRankInfo struct {
32   - SettleHas bool `form:"settle_has" json:"settle_has"` // 有结算内容未领取
33   - SettleAward string `form:"settle_award" json:"settle_award"` // 结算奖励内容
34   - UserClass int `form:"user_class" json:"user_class"` // 用户评级
35   - SelfRank int `form:"self_rank" json:"self_rank"` // 自己排名
36   - SelfScore int64 `form:"self_score" json:"self_score"` // 自己积分
37   - Tops []RoomRankTopNode `form:"tops" json:"tops"` // 排行榜数据列表
  32 + SettleHas bool `form:"settle_has" json:"settle_has"` // 有结算内容未领取
  33 + SettleRank int `form:"settle_rank" json:"settle_rank"` // 结算名次
  34 + SettleScore int64 `form:"settle_score" json:"settle_score"` // 结算分数
  35 + SettleUserClass int `form:"settle_user_class" json:"settle_user_class"` // 结算用户评级
  36 + SettleAward string `form:"settle_award" json:"settle_award"` // 结算奖励内容
  37 + UserClass int `form:"user_class" json:"user_class"` // 用户评级
  38 + SelfRank int `form:"self_rank" json:"self_rank"` // 自己排名
  39 + SelfScore int64 `form:"self_score" json:"self_score"` // 自己积分
  40 + Tops []RoomRankTopNode `form:"tops" json:"tops"` // 排行榜数据列表
38 41 }
39 42  
40 43 // ReqRoomRankInfo 请求 房间排行信息
... ... @@ -62,8 +65,10 @@ type ReqRoomRankGetSettleAward struct {
62 65  
63 66 // RspRoomRankGetSettleAward 返回 领取上期结算奖励
64 67 type RspRoomRankGetSettleAward struct {
65   - AwardText string `form:"award_text" json:"award_text"` // 上期结算奖励内容
66   - UserClass int `form:"user_class" json:"user_class"` // 用户评级
  68 + SettleRank int `form:"settle_rank" json:"settle_rank"` // 结算名次
  69 + SettleScore int64 `form:"settle_score" json:"settle_score"` // 结算分数
  70 + UserClass int `form:"user_class" json:"user_class"` // 用户评级
  71 + AwardText string `form:"award_text" json:"award_text"` // 上期结算奖励内容
67 72 }
68 73  
69 74 // ReqRoomRankAddScore 请求 房间排行增加积分
... ...
service/roomrank/dto-player.go
... ... @@ -21,6 +21,9 @@ type Player struct {
21 21 RoomUid int64 `gorm:"comment:所在房间唯一ID"`
22 22  
23 23 SettleActivityId int64 `gorm:"comment:上次结算的活动ID"`
  24 + SettleRank int `gorm:"comment:结算名次"`
  25 + SettleScore int64 `gorm:"comment:结算分数"`
  26 + SettleUserClass int `gorm:"comment:结算用户评级"`
24 27 SettleAward string `gorm:"comment:结算奖励内容"`
25 28  
26 29 CreateTime int64 `gorm:"comment:创建时间戳"`
... ...
service/roomrank/dto-room.go
... ... @@ -72,19 +72,19 @@ func (d *Room) Decode() {
72 72 }
73 73 }
74 74  
75   -// FindPlayer 找到玩家排名 -1=没找到
76   -func (d *Room) FindPlayer(playerUid int64) int {
  75 +// FindPlayer 找到玩家排名和积分 -1=没找到
  76 +func (d *Room) FindPlayer(playerUid int64) (int, int64) {
77 77 count := len(d.Details.Players)
78 78 if count > 0 {
79 79 for i := 0; i < count; i++ {
80 80 p := d.Details.Players[i]
81 81 if p.Uid == playerUid {
82   - return i
  82 + return i, p.Score
83 83 }
84 84 }
85 85 }
86 86  
87   - return -1
  87 + return -1, 0
88 88 }
89 89  
90 90 func (d *Room) GetPlayerTypeCount(userType int) int {
... ...
service/roomrank/handle.go
... ... @@ -132,8 +132,10 @@ func HandleGetSettleAward(req *models.ReqRoomRankGetSettleAward) (code string, r
132 132 oldActivityId := player.ActivityId
133 133  
134 134 // 领取奖励
  135 + rsp.SettleRank = player.SettleRank
  136 + rsp.SettleScore = player.SettleScore
  137 + rsp.UserClass = player.SettleUserClass
135 138 rsp.AwardText = player.SettleAward
136   - rsp.UserClass = player.UserClass
137 139 player.SettleAward = ""
138 140 player.ActivityId = config.Id
139 141 player.RoomUid = 0
... ...
service/roomrank/logic.go
... ... @@ -30,16 +30,20 @@ func TrySettle(gameId string, player *Player, config *confroomrank.ActivityConfi
30 30 if !hasRoom {
31 31 return
32 32 }
33   - // 找到玩家在房间里的名次
34   - rankIndex := room.FindPlayer(player.Uid)
35   - if rankIndex < 0 {
36   - return
37   - }
38 33 confActivity, hasConfActivity := confroomrank.GetConfig(gameId, room.ActivityId)
39 34 if !hasConfActivity {
40 35 return
41 36 }
42 37 TrySettleRoom(gameId, room, confActivity)
  38 +
  39 + // 找到玩家在房间里的名次
  40 + // rankIndex = 0-49 rank = 1-50
  41 + rankIndex, rankScore := room.FindPlayer(player.Uid)
  42 + if rankIndex < 0 {
  43 + return
  44 + }
  45 + player.SettleRank = rankIndex + 1
  46 + player.SettleScore = rankScore
43 47 // 设置玩家奖励等数据
44 48 hasChange = true
45 49 player.SettleActivityId = config.Id
... ... @@ -47,11 +51,12 @@ func TrySettle(gameId string, player *Player, config *confroomrank.ActivityConfi
47 51 if !hasConfRoom {
48 52 return
49 53 }
50   - if confAward, hasConfAward := confRoom.Awards[utstring.IntToString(rankIndex+1)]; hasConfAward {
  54 + if confAward, hasConfAward := confRoom.Awards[utstring.IntToString(player.SettleRank)]; hasConfAward {
51 55 player.SettleAward = confAward
52 56 }
53 57 if len(confRoom.SettleScores) > rankIndex {
54 58 player.AddUserScore(confRoom.SettleScores[rankIndex])
  59 + player.SettleUserClass = player.UserClass
55 60 }
56 61 if len(confRoom.SettleUserType) > rankIndex {
57 62 player.UserType = confRoom.SettleUserType[rankIndex]
... ...
service/roomrank/player.go
... ... @@ -71,6 +71,9 @@ func GetInfoFromSettle(player *Player, config *confroomrank.ActivityConfig) mode
71 71 info := models.RoomRankInfo{}
72 72 if player.SettleHas() {
73 73 info.SettleHas = true
  74 + info.SettleRank = player.SettleRank
  75 + info.SettleScore = player.SettleScore
  76 + info.SettleUserClass = player.SettleUserClass
74 77 info.SettleAward = player.SettleAward
75 78 }
76 79 return info
... ...