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 | 15 | Id int64 // ID |
| 16 | 16 | Typ int // 排行榜类型 |
| 17 | 17 | OpenLevel int // 开启等级 |
| 18 | + OpenScore int64 // 开启积分 | |
| 18 | 19 | PreviewTime int64 // 预告时间 |
| 19 | 20 | StartTime int64 // 开始时间 |
| 20 | 21 | EndTime int64 // 结束时间 |
| ... | ... | @@ -56,6 +57,7 @@ type ActivityConfigRaw struct { |
| 56 | 57 | Id int64 `gorm:"column:id;primaryKey"` // ID |
| 57 | 58 | Typ int // 排行榜类型 |
| 58 | 59 | OpenLevel int // 开启等级 |
| 60 | + OpenScore int64 // 开启积分 | |
| 59 | 61 | PreviewTime int64 // 预告时间 |
| 60 | 62 | StartTime int64 // 开始时间 |
| 61 | 63 | EndTime int64 // 结束时间 |
| ... | ... | @@ -75,6 +77,7 @@ func (c *ActivityConfigRaw) GenerateConfigClient() *ActivityConfigClient { |
| 75 | 77 | Id: c.Id, |
| 76 | 78 | Typ: c.Typ, |
| 77 | 79 | OpenLevel: c.OpenLevel, |
| 80 | + OpenScore: c.OpenScore, | |
| 78 | 81 | PreviewTime: c.PreviewTime, |
| 79 | 82 | StartTime: c.StartTime, |
| 80 | 83 | EndTime: c.EndTime, |
| ... | ... | @@ -90,6 +93,7 @@ type ActivityConfigClient struct { |
| 90 | 93 | Id int64 `form:"id" json:"id"` // ID |
| 91 | 94 | Typ int `form:"typ" json:"typ"` // 排行榜类型 |
| 92 | 95 | OpenLevel int `form:"open_level" json:"open_level"` // 开启等级 |
| 96 | + OpenScore int64 `form:"open_score" json:"open_score"` // 开启积分 | |
| 93 | 97 | PreviewTime int64 `form:"preview_time" json:"preview_time"` // 预告时间 |
| 94 | 98 | StartTime int64 `form:"start_time" json:"start_time"` // 开始时间 |
| 95 | 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 | 14 | c.Id = raw.Id |
| 15 | 15 | c.Typ = raw.Typ |
| 16 | 16 | c.OpenLevel = raw.OpenLevel |
| 17 | + c.OpenScore = raw.OpenScore | |
| 17 | 18 | c.PreviewTime = raw.PreviewTime |
| 18 | 19 | c.StartTime = raw.StartTime |
| 19 | 20 | c.EndTime = raw.EndTime | ... | ... |
service/roomrank/dto-player.go
service/roomrank/handle.go
| ... | ... | @@ -69,6 +69,20 @@ func HandleInfo(req *models.ReqRoomRankInfo) (code string, rsp models.RspRoomRan |
| 69 | 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 | 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 | 145 | player.SettleAward = "" |
| 132 | 146 | player.ActivityId = config.Id |
| 133 | 147 | player.RoomUid = 0 |
| 148 | + player.Score = 0 | |
| 134 | 149 | SavePlayer(gameId, player) |
| 135 | 150 | |
| 136 | 151 | // 记录日志 |
| ... | ... | @@ -189,11 +204,32 @@ func HandleAddScore(req *models.ReqRoomRankAddScore) (code string, rsp models.Rs |
| 189 | 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 | 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 | 234 | if !hasRoom { |
| 199 | 235 | code = code_msg.RECODE_MERGE_CONFIG_ERROR |
| ... | ... | @@ -206,9 +242,5 @@ func HandleAddScore(req *models.ReqRoomRankAddScore) (code string, rsp models.Rs |
| 206 | 242 | rsp.RoomRankInfo = GetInfoFromRoom(gameId, player, room, config) |
| 207 | 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 | 245 | return |
| 214 | 246 | } | ... | ... |
service/roomrank/logic.go
| ... | ... | @@ -64,16 +64,15 @@ func TrySettle(gameId string, topType int, player *Player, config *confroomrank. |
| 64 | 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 | 69 | for i := 0; i < len(room.Details.Players); i++ { |
| 70 | 70 | p := room.Details.Players[i] |
| 71 | 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 | 75 | return |
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | - return | |
| 79 | 78 | } | ... | ... |
service/roomrank/player.go
| ... | ... | @@ -72,7 +72,7 @@ func NewRoomPlayer(player *Player) *RoomPlayer { |
| 72 | 72 | Uid: player.Uid, |
| 73 | 73 | Name: player.Name, |
| 74 | 74 | Icon: player.Icon, |
| 75 | - Score: 0, | |
| 75 | + Score: player.Score, | |
| 76 | 76 | JoinTime: lxtime.NowUninx(), |
| 77 | 77 | UserType: player.UserType, |
| 78 | 78 | RobotConfigId: 0, |
| ... | ... | @@ -93,6 +93,15 @@ func GetInfoFromSettle(player *Player, config *confroomrank.ActivityConfig) mode |
| 93 | 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 | 105 | // GetInfoFromRoom 活动信息 从房间 |
| 97 | 106 | func GetInfoFromRoom(gameId string, player *Player, room *Room, config *confroomrank.ActivityConfig) models.RoomRankInfo { |
| 98 | 107 | info := models.RoomRankInfo{} |
| ... | ... | @@ -115,10 +124,10 @@ func GetInfoFromRoom(gameId string, player *Player, room *Room, config *confroom |
| 115 | 124 | } |
| 116 | 125 | if player.Uid == p.Uid { |
| 117 | 126 | info.SelfRank = rank |
| 118 | - info.SelfScore = p.Score | |
| 119 | 127 | } |
| 120 | 128 | info.Tops = append(info.Tops, node) |
| 121 | 129 | } |
| 130 | + info.SelfScore = player.Score | |
| 122 | 131 | info.RobotAvatarPath = svcommon.GetAvatarPath(gameId) |
| 123 | 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 | 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 | 109 | // TryGetRoom 尝试获取房间 |
| 90 | 110 | func TryGetRoom(gameId string, topType int, player *Player, config *confroomrank.ActivityConfig, playerLevel int) (room *Room, hasRoom bool, firstJoin bool) { |
| 91 | 111 | hasRoom = false | ... | ... |