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