Commit 84499c6028b57cde0b0601ca7d34e5bcef183246

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

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

models/roomrank.go
... ... @@ -24,6 +24,7 @@ type RoomRankTopNode struct {
24 24 Score int64 `form:"score" json:"score"` // 玩家排行分数
25 25 Name string `form:"name" json:"name"` // 名字
26 26 Icon string `form:"icon" json:"icon"` // 头像
  27 + Award string `form:"award" json:"award"` // 排名奖励内容
27 28 }
28 29  
29 30 // RoomRankInfo 房间排行信息
... ...
service/roomrank/dto-player.go
... ... @@ -20,8 +20,8 @@ type Player struct {
20 20  
21 21 RoomUid int64 `gorm:"comment:所在房间唯一ID"`
22 22  
23   - SettleHas bool `gorm:"comment:有结算内容未领取"`
24   - SettleAward string `gorm:"comment:结算奖励内容"`
  23 + SettleActivityId int64 `gorm:"comment:上次结算的活动ID"`
  24 + SettleAward string `gorm:"comment:结算奖励内容"`
25 25  
26 26 CreateTime int64 `gorm:"comment:创建时间戳"`
27 27 UpdateTime int64 `gorm:"comment:修改时间戳"`
... ... @@ -65,3 +65,7 @@ func (d *Player) AddUserScore(count int) {
65 65 d.UserClass = UserClassMax
66 66 }
67 67 }
  68 +
  69 +func (d *Player) SettleHas() bool {
  70 + return d.SettleAward != ""
  71 +}
... ...
service/roomrank/handle.go
... ... @@ -68,7 +68,7 @@ func HandleInfo(req *models.ReqRoomRankInfo) (code string, rsp models.RspRoomRan
68 68 if hasSettleChange {
69 69 SavePlayer(gameId, player)
70 70 }
71   - if player.SettleHas {
  71 + if player.SettleHas() {
72 72 rsp.RoomRankInfo = GetInfoFromSettle(player, config)
73 73 return
74 74 }
... ... @@ -89,7 +89,7 @@ func HandleInfo(req *models.ReqRoomRankInfo) (code string, rsp models.RspRoomRan
89 89 TryReSort(room, config)
90 90 SavePlayer(gameId, player)
91 91 SaveRoom(gameId, room)
92   - rsp.RoomRankInfo = GetInfoFromRoom(player, room)
  92 + rsp.RoomRankInfo = GetInfoFromRoom(player, room, config)
93 93  
94 94 return
95 95 }
... ... @@ -125,7 +125,7 @@ func HandleGetSettleAward(req *models.ReqRoomRankGetSettleAward) (code string, r
125 125  
126 126 // 尝试判断结算
127 127 _ = TrySettle(gameId, player, config)
128   - if !player.SettleHas {
  128 + if !player.SettleHas() {
129 129 code = code_msg.RECODE_MERGE_ROOMRANK_NOTHASSETTLE_ERROR
130 130 return
131 131 }
... ... @@ -134,7 +134,6 @@ func HandleGetSettleAward(req *models.ReqRoomRankGetSettleAward) (code string, r
134 134 // 领取奖励
135 135 rsp.AwardText = player.SettleAward
136 136 rsp.UserClass = player.UserClass
137   - player.SettleHas = false
138 137 player.SettleAward = ""
139 138 player.ActivityId = config.Id
140 139 player.RoomUid = 0
... ... @@ -184,7 +183,8 @@ func HandleAddScore(req *models.ReqRoomRankAddScore) (code string, rsp models.Rs
184 183 if hasSettleChange {
185 184 SavePlayer(gameId, player)
186 185 }
187   - if player.SettleHas {
  186 +
  187 + if player.SettleHas() {
188 188 rsp.RoomRankInfo = GetInfoFromSettle(player, config)
189 189 code = code_msg.RECODE_MERGE_ROOMRANK_HASSETTLE_ERROR
190 190 return
... ... @@ -210,7 +210,7 @@ func HandleAddScore(req *models.ReqRoomRankAddScore) (code string, rsp models.Rs
210 210 SavePlayer(gameId, player)
211 211 SaveRoom(gameId, room)
212 212  
213   - rsp.RoomRankInfo = GetInfoFromRoom(player, room)
  213 + rsp.RoomRankInfo = GetInfoFromRoom(player, room, config)
214 214  
215 215 // 记录日志
216 216 recordBase := NewRecordBase(player.Uid, config.Id)
... ...
service/roomrank/logic.go
... ... @@ -15,7 +15,7 @@ func getLockKey(gameId string, activityId int64) string {
15 15 // TrySettle 尝试判断结算
16 16 func TrySettle(gameId string, player *Player, config *confroomrank.ActivityConfig) (hasChange bool) {
17 17 hasChange = false
18   - if player.SettleHas {
  18 + if player.SettleActivityId == config.Id {
19 19 return
20 20 }
21 21 if player.ActivityId == 0 {
... ... @@ -42,12 +42,12 @@ func TrySettle(gameId string, player *Player, config *confroomrank.ActivityConfi
42 42 TrySettleRoom(gameId, room, confActivity)
43 43 // 设置玩家奖励等数据
44 44 hasChange = true
45   - player.SettleHas = true
  45 + player.SettleActivityId = config.Id
46 46 confRoom, hasConfRoom := confActivity.Room[room.ConfigId]
47 47 if !hasConfRoom {
48 48 return
49 49 }
50   - if confAward, hasConfAward := confRoom.Awards[utstring.IntToString(rankIndex)]; hasConfAward {
  50 + if confAward, hasConfAward := confRoom.Awards[utstring.IntToString(rankIndex+1)]; hasConfAward {
51 51 player.SettleAward = confAward
52 52 }
53 53 if len(confRoom.SettleScores) > rankIndex {
... ...
service/roomrank/player.go
... ... @@ -7,6 +7,7 @@ import (
7 7 "apigame/service-common/svmysql"
8 8 "apigame/util/util-lx/lxalilog"
9 9 "apigame/util/util-lx/lxtime"
  10 + "apigame/util/utstring"
10 11 "math/rand"
11 12 )
12 13  
... ... @@ -66,17 +67,17 @@ func NewRoomPlayer(player *Player) *RoomPlayer {
66 67 }
67 68  
68 69 // GetInfoFromSettle 活动信息 从结算
69   -func GetInfoFromSettle(player *Player, conf *confroomrank.ActivityConfig) models.RoomRankInfo {
  70 +func GetInfoFromSettle(player *Player, config *confroomrank.ActivityConfig) models.RoomRankInfo {
70 71 info := models.RoomRankInfo{}
71   - if player.SettleHas {
72   - info.SettleHas = player.SettleHas
  72 + if player.SettleHas() {
  73 + info.SettleHas = true
73 74 info.SettleAward = player.SettleAward
74 75 }
75 76 return info
76 77 }
77 78  
78 79 // GetInfoFromRoom 活动信息 从房间
79   -func GetInfoFromRoom(player *Player, room *Room) models.RoomRankInfo {
  80 +func GetInfoFromRoom(player *Player, room *Room, config *confroomrank.ActivityConfig) models.RoomRankInfo {
80 81 info := models.RoomRankInfo{}
81 82 info.UserClass = player.UserClass
82 83 for i := 0; i < len(room.Details.Players); i++ {
... ... @@ -89,6 +90,11 @@ func GetInfoFromRoom(player *Player, room *Room) models.RoomRankInfo {
89 90 Name: p.Name,
90 91 Icon: p.Icon,
91 92 }
  93 + if confRoom, hasConfRoom := config.Room[room.ConfigId]; hasConfRoom {
  94 + if confAward, hasConfAward := confRoom.Awards[utstring.IntToString(rank)]; hasConfAward {
  95 + node.Award = confAward
  96 + }
  97 + }
92 98 if player.Uid == p.Uid {
93 99 info.SelfRank = rank
94 100 info.SelfScore = p.Score
... ...
service/roomrank/room.go
... ... @@ -86,11 +86,9 @@ func FindRoom(gameId string, activityId int64, roomConfigId int) (rooms []*Room,
86 86 // TryGetRoom 尝试获取房间
87 87 func TryGetRoom(gameId string, player *Player, config *confroomrank.ActivityConfig, playerLevel int) (room *Room, hasRoom bool) {
88 88 hasRoom = false
89   - if player.SettleHas {
90   - return
91   - }
92 89 if player.ActivityId != config.Id {
93 90 player.ActivityId = config.Id
  91 + player.RoomUid = 0
94 92 }
95 93 // 查找玩家所在的房间
96 94 room, hasRoom = LoadRoom(gameId, config.Id, player.RoomUid)
... ...