Commit 9bceeb169dd60c110eb4b827ed3ac769d6ec3329
1 parent
efaa7bf7
Exists in
master
and in
1 other branch
feat✨:排行活动增加了积分限制
Showing
7 changed files
with
80 additions
and
13 deletions
Show diff stats
configs/confroomrank/config.go
| @@ -15,6 +15,7 @@ type ActivityConfig struct { | @@ -15,6 +15,7 @@ type ActivityConfig struct { | ||
| 15 | Id int64 // ID | 15 | Id int64 // ID |
| 16 | Typ int // 排行榜类型 | 16 | Typ int // 排行榜类型 |
| 17 | OpenLevel int // 开启等级 | 17 | OpenLevel int // 开启等级 |
| 18 | + OpenScore int64 // 开启积分 | ||
| 18 | PreviewTime int64 // 预告时间 | 19 | PreviewTime int64 // 预告时间 |
| 19 | StartTime int64 // 开始时间 | 20 | StartTime int64 // 开始时间 |
| 20 | EndTime int64 // 结束时间 | 21 | EndTime int64 // 结束时间 |
| @@ -56,6 +57,7 @@ type ActivityConfigRaw struct { | @@ -56,6 +57,7 @@ type ActivityConfigRaw struct { | ||
| 56 | Id int64 `gorm:"column:id;primaryKey"` // ID | 57 | Id int64 `gorm:"column:id;primaryKey"` // ID |
| 57 | Typ int // 排行榜类型 | 58 | Typ int // 排行榜类型 |
| 58 | OpenLevel int // 开启等级 | 59 | OpenLevel int // 开启等级 |
| 60 | + OpenScore int64 // 开启积分 | ||
| 59 | PreviewTime int64 // 预告时间 | 61 | PreviewTime int64 // 预告时间 |
| 60 | StartTime int64 // 开始时间 | 62 | StartTime int64 // 开始时间 |
| 61 | EndTime int64 // 结束时间 | 63 | EndTime int64 // 结束时间 |
| @@ -75,6 +77,7 @@ func (c *ActivityConfigRaw) GenerateConfigClient() *ActivityConfigClient { | @@ -75,6 +77,7 @@ func (c *ActivityConfigRaw) GenerateConfigClient() *ActivityConfigClient { | ||
| 75 | Id: c.Id, | 77 | Id: c.Id, |
| 76 | Typ: c.Typ, | 78 | Typ: c.Typ, |
| 77 | OpenLevel: c.OpenLevel, | 79 | OpenLevel: c.OpenLevel, |
| 80 | + OpenScore: c.OpenScore, | ||
| 78 | PreviewTime: c.PreviewTime, | 81 | PreviewTime: c.PreviewTime, |
| 79 | StartTime: c.StartTime, | 82 | StartTime: c.StartTime, |
| 80 | EndTime: c.EndTime, | 83 | EndTime: c.EndTime, |
| @@ -90,6 +93,7 @@ type ActivityConfigClient struct { | @@ -90,6 +93,7 @@ type ActivityConfigClient struct { | ||
| 90 | Id int64 `form:"id" json:"id"` // ID | 93 | Id int64 `form:"id" json:"id"` // ID |
| 91 | Typ int `form:"typ" json:"typ"` // 排行榜类型 | 94 | Typ int `form:"typ" json:"typ"` // 排行榜类型 |
| 92 | OpenLevel int `form:"open_level" json:"open_level"` // 开启等级 | 95 | OpenLevel int `form:"open_level" json:"open_level"` // 开启等级 |
| 96 | + OpenScore int64 `form:"open_score" json:"open_score"` // 开启积分 | ||
| 93 | PreviewTime int64 `form:"preview_time" json:"preview_time"` // 预告时间 | 97 | PreviewTime int64 `form:"preview_time" json:"preview_time"` // 预告时间 |
| 94 | StartTime int64 `form:"start_time" json:"start_time"` // 开始时间 | 98 | StartTime int64 `form:"start_time" json:"start_time"` // 开始时间 |
| 95 | EndTime int64 `form:"end_time" json:"end_time"` // 结束时间 | 99 | EndTime int64 `form:"end_time" json:"end_time"` // 结束时间 |
configs/confroomrank/decode.go
| @@ -14,6 +14,7 @@ func (c *ActivityConfig) Decode(gameId string, rawData any) { | @@ -14,6 +14,7 @@ func (c *ActivityConfig) Decode(gameId string, rawData any) { | ||
| 14 | c.Id = raw.Id | 14 | c.Id = raw.Id |
| 15 | c.Typ = raw.Typ | 15 | c.Typ = raw.Typ |
| 16 | c.OpenLevel = raw.OpenLevel | 16 | c.OpenLevel = raw.OpenLevel |
| 17 | + c.OpenScore = raw.OpenScore | ||
| 17 | c.PreviewTime = raw.PreviewTime | 18 | c.PreviewTime = raw.PreviewTime |
| 18 | c.StartTime = raw.StartTime | 19 | c.StartTime = raw.StartTime |
| 19 | c.EndTime = raw.EndTime | 20 | c.EndTime = raw.EndTime |
service/roomrank/dto-player.go
| @@ -19,6 +19,8 @@ type Player struct { | @@ -19,6 +19,8 @@ type Player struct { | ||
| 19 | UserScore int `gorm:"comment:用户评级分"` | 19 | UserScore int `gorm:"comment:用户评级分"` |
| 20 | UserClass int `gorm:"comment:用户评级"` | 20 | UserClass int `gorm:"comment:用户评级"` |
| 21 | 21 | ||
| 22 | + Score int64 `gorm:"comment:本轮分数"` | ||
| 23 | + | ||
| 22 | RoomUid int64 `gorm:"comment:所在房间唯一ID"` | 24 | RoomUid int64 `gorm:"comment:所在房间唯一ID"` |
| 23 | 25 | ||
| 24 | SettleActivityId int64 `gorm:"comment:上次结算的活动ID"` | 26 | SettleActivityId int64 `gorm:"comment:上次结算的活动ID"` |
service/roomrank/handle.go
| @@ -69,6 +69,20 @@ func HandleInfo(req *models.ReqRoomRankInfo) (code string, rsp models.RspRoomRan | @@ -69,6 +69,20 @@ func HandleInfo(req *models.ReqRoomRankInfo) (code string, rsp models.RspRoomRan | ||
| 69 | return | 69 | return |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | + // 尝试找到旧房间 并获取原来的积分 这里主要是为了兼容之前版本没有积分要求的设置 | ||
| 73 | + { | ||
| 74 | + _, hasOldRoom, scoreOld := TryGetOldRoomScore(gameId, req.TopType, player, config) | ||
| 75 | + if hasOldRoom { | ||
| 76 | + player.Score = scoreOld | ||
| 77 | + } | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + // 判断玩家积分 | ||
| 81 | + if player.Score < config.OpenScore { | ||
| 82 | + rsp.RoomRankInfo = GetInfoFromPlayer(gameId, player, config) | ||
| 83 | + return | ||
| 84 | + } | ||
| 85 | + | ||
| 72 | // 尝试加入房间 | 86 | // 尝试加入房间 |
| 73 | room, hasRoom, firstJoin := TryGetRoom(gameId, req.TopType, player, config, playerLevel) | 87 | room, hasRoom, firstJoin := TryGetRoom(gameId, req.TopType, player, config, playerLevel) |
| 74 | 88 | ||
| @@ -131,6 +145,7 @@ func HandleGetSettleAward(req *models.ReqRoomRankGetSettleAward) (code string, r | @@ -131,6 +145,7 @@ func HandleGetSettleAward(req *models.ReqRoomRankGetSettleAward) (code string, r | ||
| 131 | player.SettleAward = "" | 145 | player.SettleAward = "" |
| 132 | player.ActivityId = config.Id | 146 | player.ActivityId = config.Id |
| 133 | player.RoomUid = 0 | 147 | player.RoomUid = 0 |
| 148 | + player.Score = 0 | ||
| 134 | SavePlayer(gameId, player) | 149 | SavePlayer(gameId, player) |
| 135 | 150 | ||
| 136 | // 记录日志 | 151 | // 记录日志 |
| @@ -189,11 +204,32 @@ func HandleAddScore(req *models.ReqRoomRankAddScore) (code string, rsp models.Rs | @@ -189,11 +204,32 @@ func HandleAddScore(req *models.ReqRoomRankAddScore) (code string, rsp models.Rs | ||
| 189 | return | 204 | return |
| 190 | } | 205 | } |
| 191 | 206 | ||
| 207 | + // 尝试找到旧房间 并获取原来的积分 这里主要是为了兼容之前版本没有积分要求的设置 | ||
| 208 | + { | ||
| 209 | + _, hasOldRoom, scoreOld := TryGetOldRoomScore(gameId, req.TopType, player, config) | ||
| 210 | + if hasOldRoom { | ||
| 211 | + player.Score = scoreOld | ||
| 212 | + } | ||
| 213 | + } | ||
| 214 | + | ||
| 215 | + oldScore := player.Score | ||
| 216 | + player.Score += req.AddScore | ||
| 217 | + newScore := player.Score | ||
| 218 | + // 记录日志 | ||
| 219 | + recordBase := NewRecordBase(player.Uid, req.TopType, config.Id) | ||
| 220 | + SaveRecordAddScore(gameId, NewRecordAddScore(recordBase, req.AddScore, oldScore, newScore)) | ||
| 221 | + | ||
| 222 | + // 判断玩家积分 | ||
| 223 | + if player.Score < config.OpenScore { | ||
| 224 | + rsp.RoomRankInfo = GetInfoFromPlayer(gameId, player, config) | ||
| 225 | + return | ||
| 226 | + } | ||
| 227 | + | ||
| 192 | // 尝试加入房间 | 228 | // 尝试加入房间 |
| 193 | room, hasRoom, firstJoin := TryGetRoom(gameId, req.TopType, player, config, playerLevel) | 229 | room, hasRoom, firstJoin := TryGetRoom(gameId, req.TopType, player, config, playerLevel) |
| 194 | 230 | ||
| 195 | // 房间排行增加积分 | 231 | // 房间排行增加积分 |
| 196 | - oldScore, newScore := ChangePlayerScore(room, player, req.AddScore) | 232 | + UpdatePlayerScore(room, player) |
| 197 | 233 | ||
| 198 | if !hasRoom { | 234 | if !hasRoom { |
| 199 | code = code_msg.RECODE_MERGE_CONFIG_ERROR | 235 | code = code_msg.RECODE_MERGE_CONFIG_ERROR |
| @@ -206,9 +242,5 @@ func HandleAddScore(req *models.ReqRoomRankAddScore) (code string, rsp models.Rs | @@ -206,9 +242,5 @@ func HandleAddScore(req *models.ReqRoomRankAddScore) (code string, rsp models.Rs | ||
| 206 | rsp.RoomRankInfo = GetInfoFromRoom(gameId, player, room, config) | 242 | rsp.RoomRankInfo = GetInfoFromRoom(gameId, player, room, config) |
| 207 | rsp.RoomRankInfo.FirstJoin = firstJoin | 243 | rsp.RoomRankInfo.FirstJoin = firstJoin |
| 208 | 244 | ||
| 209 | - // 记录日志 | ||
| 210 | - recordBase := NewRecordBase(player.Uid, req.TopType, config.Id) | ||
| 211 | - SaveRecordAddScore(gameId, NewRecordAddScore(recordBase, req.AddScore, oldScore, newScore)) | ||
| 212 | - | ||
| 213 | return | 245 | return |
| 214 | } | 246 | } |
service/roomrank/logic.go
| @@ -64,16 +64,15 @@ func TrySettle(gameId string, topType int, player *Player, config *confroomrank. | @@ -64,16 +64,15 @@ func TrySettle(gameId string, topType int, player *Player, config *confroomrank. | ||
| 64 | return | 64 | return |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | -// ChangePlayerScore 房间排行增加积分 | ||
| 68 | -func ChangePlayerScore(room *Room, player *Player, addScore int64) (oldScore, newScore int64) { | 67 | +// UpdatePlayerScore 房间排行更新积分 |
| 68 | +func UpdatePlayerScore(room *Room, player *Player) { | ||
| 69 | for i := 0; i < len(room.Details.Players); i++ { | 69 | for i := 0; i < len(room.Details.Players); i++ { |
| 70 | p := room.Details.Players[i] | 70 | p := room.Details.Players[i] |
| 71 | if player.Uid == p.Uid { | 71 | if player.Uid == p.Uid { |
| 72 | - oldScore = p.Score | ||
| 73 | - p.Score += addScore | ||
| 74 | - newScore = p.Score | 72 | + p.Name = player.Name |
| 73 | + p.Icon = player.Icon | ||
| 74 | + p.Score = player.Score | ||
| 75 | return | 75 | return |
| 76 | } | 76 | } |
| 77 | } | 77 | } |
| 78 | - return | ||
| 79 | } | 78 | } |
service/roomrank/player.go
| @@ -72,7 +72,7 @@ func NewRoomPlayer(player *Player) *RoomPlayer { | @@ -72,7 +72,7 @@ func NewRoomPlayer(player *Player) *RoomPlayer { | ||
| 72 | Uid: player.Uid, | 72 | Uid: player.Uid, |
| 73 | Name: player.Name, | 73 | Name: player.Name, |
| 74 | Icon: player.Icon, | 74 | Icon: player.Icon, |
| 75 | - Score: 0, | 75 | + Score: player.Score, |
| 76 | JoinTime: lxtime.NowUninx(), | 76 | JoinTime: lxtime.NowUninx(), |
| 77 | UserType: player.UserType, | 77 | UserType: player.UserType, |
| 78 | RobotConfigId: 0, | 78 | RobotConfigId: 0, |
| @@ -93,6 +93,15 @@ func GetInfoFromSettle(player *Player, config *confroomrank.ActivityConfig) mode | @@ -93,6 +93,15 @@ func GetInfoFromSettle(player *Player, config *confroomrank.ActivityConfig) mode | ||
| 93 | return info | 93 | return info |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | +// GetInfoFromPlayer 活动信息 从玩家 未报名时 | ||
| 97 | +func GetInfoFromPlayer(gameId string, player *Player, config *confroomrank.ActivityConfig) models.RoomRankInfo { | ||
| 98 | + info := models.RoomRankInfo{} | ||
| 99 | + info.UserClass = player.UserClass | ||
| 100 | + info.SelfScore = player.Score | ||
| 101 | + info.RobotAvatarPath = svcommon.GetAvatarPath(gameId) | ||
| 102 | + return info | ||
| 103 | +} | ||
| 104 | + | ||
| 96 | // GetInfoFromRoom 活动信息 从房间 | 105 | // GetInfoFromRoom 活动信息 从房间 |
| 97 | func GetInfoFromRoom(gameId string, player *Player, room *Room, config *confroomrank.ActivityConfig) models.RoomRankInfo { | 106 | func GetInfoFromRoom(gameId string, player *Player, room *Room, config *confroomrank.ActivityConfig) models.RoomRankInfo { |
| 98 | info := models.RoomRankInfo{} | 107 | info := models.RoomRankInfo{} |
| @@ -115,10 +124,10 @@ func GetInfoFromRoom(gameId string, player *Player, room *Room, config *confroom | @@ -115,10 +124,10 @@ func GetInfoFromRoom(gameId string, player *Player, room *Room, config *confroom | ||
| 115 | } | 124 | } |
| 116 | if player.Uid == p.Uid { | 125 | if player.Uid == p.Uid { |
| 117 | info.SelfRank = rank | 126 | info.SelfRank = rank |
| 118 | - info.SelfScore = p.Score | ||
| 119 | } | 127 | } |
| 120 | info.Tops = append(info.Tops, node) | 128 | info.Tops = append(info.Tops, node) |
| 121 | } | 129 | } |
| 130 | + info.SelfScore = player.Score | ||
| 122 | info.RobotAvatarPath = svcommon.GetAvatarPath(gameId) | 131 | info.RobotAvatarPath = svcommon.GetAvatarPath(gameId) |
| 123 | return info | 132 | return info |
| 124 | } | 133 | } |
service/roomrank/room.go
| @@ -86,6 +86,26 @@ func FindRoom(gameId string, topType int, activityId int64, roomConfigId int) (r | @@ -86,6 +86,26 @@ func FindRoom(gameId string, topType int, activityId int64, roomConfigId int) (r | ||
| 86 | return | 86 | return |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | +// TryGetOldRoomScore 尝试获取旧房间里的积分 | ||
| 90 | +func TryGetOldRoomScore(gameId string, topType int, player *Player, config *confroomrank.ActivityConfig) (room *Room, hasOldRoom bool, scoreOld int64) { | ||
| 91 | + hasOldRoom = false | ||
| 92 | + if player.ActivityId != config.Id { | ||
| 93 | + player.ActivityId = config.Id | ||
| 94 | + player.RoomUid = 0 | ||
| 95 | + return | ||
| 96 | + } | ||
| 97 | + // 查找玩家所在的房间 | ||
| 98 | + room, hasOldRoom = LoadRoom(gameId, topType, config.Id, player.RoomUid) | ||
| 99 | + for i := 0; i < len(room.Details.Players); i++ { | ||
| 100 | + p := room.Details.Players[i] | ||
| 101 | + if player.Uid == p.Uid { | ||
| 102 | + scoreOld = p.Score | ||
| 103 | + break | ||
| 104 | + } | ||
| 105 | + } | ||
| 106 | + return | ||
| 107 | +} | ||
| 108 | + | ||
| 89 | // TryGetRoom 尝试获取房间 | 109 | // TryGetRoom 尝试获取房间 |
| 90 | func TryGetRoom(gameId string, topType int, player *Player, config *confroomrank.ActivityConfig, playerLevel int) (room *Room, hasRoom bool, firstJoin bool) { | 110 | func TryGetRoom(gameId string, topType int, player *Player, config *confroomrank.ActivityConfig, playerLevel int) (room *Room, hasRoom bool, firstJoin bool) { |
| 91 | hasRoom = false | 111 | hasRoom = false |