Commit 2ed2e73dc2d448db2e99ead186d0de54bc89bd9e
1 parent
9bceeb16
Exists in
master
and in
1 other branch
feat✨:排行活动增加了积分限制
Showing
2 changed files
with
24 additions
and
38 deletions
Show diff stats
service/roomrank/handle.go
| @@ -69,12 +69,16 @@ func HandleInfo(req *models.ReqRoomRankInfo) (code string, rsp models.RspRoomRan | @@ -69,12 +69,16 @@ 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 | 72 | + needSavePlayer := false |
| 73 | + defer func() { | ||
| 74 | + if needSavePlayer { | ||
| 75 | + SavePlayer(gameId, player) | ||
| 77 | } | 76 | } |
| 77 | + }() | ||
| 78 | + if player.ActivityId != config.Id { | ||
| 79 | + player.ActivityId = config.Id | ||
| 80 | + player.RoomUid = 0 | ||
| 81 | + needSavePlayer = true | ||
| 78 | } | 82 | } |
| 79 | 83 | ||
| 80 | // 判断玩家积分 | 84 | // 判断玩家积分 |
| @@ -90,6 +94,8 @@ func HandleInfo(req *models.ReqRoomRankInfo) (code string, rsp models.RspRoomRan | @@ -90,6 +94,8 @@ func HandleInfo(req *models.ReqRoomRankInfo) (code string, rsp models.RspRoomRan | ||
| 90 | code = code_msg.RECODE_MERGE_CONFIG_ERROR | 94 | code = code_msg.RECODE_MERGE_CONFIG_ERROR |
| 91 | return | 95 | return |
| 92 | } | 96 | } |
| 97 | + | ||
| 98 | + needSavePlayer = true | ||
| 93 | TryReSort(room, config) | 99 | TryReSort(room, config) |
| 94 | SavePlayer(gameId, player) | 100 | SavePlayer(gameId, player) |
| 95 | SaveRoom(gameId, room) | 101 | SaveRoom(gameId, room) |
| @@ -204,17 +210,22 @@ func HandleAddScore(req *models.ReqRoomRankAddScore) (code string, rsp models.Rs | @@ -204,17 +210,22 @@ func HandleAddScore(req *models.ReqRoomRankAddScore) (code string, rsp models.Rs | ||
| 204 | return | 210 | return |
| 205 | } | 211 | } |
| 206 | 212 | ||
| 207 | - // 尝试找到旧房间 并获取原来的积分 这里主要是为了兼容之前版本没有积分要求的设置 | ||
| 208 | - { | ||
| 209 | - _, hasOldRoom, scoreOld := TryGetOldRoomScore(gameId, req.TopType, player, config) | ||
| 210 | - if hasOldRoom { | ||
| 211 | - player.Score = scoreOld | 213 | + needSavePlayer := false |
| 214 | + defer func() { | ||
| 215 | + if needSavePlayer { | ||
| 216 | + SavePlayer(gameId, player) | ||
| 212 | } | 217 | } |
| 218 | + }() | ||
| 219 | + if player.ActivityId != config.Id { | ||
| 220 | + player.ActivityId = config.Id | ||
| 221 | + player.RoomUid = 0 | ||
| 222 | + needSavePlayer = true | ||
| 213 | } | 223 | } |
| 214 | 224 | ||
| 215 | oldScore := player.Score | 225 | oldScore := player.Score |
| 216 | player.Score += req.AddScore | 226 | player.Score += req.AddScore |
| 217 | newScore := player.Score | 227 | newScore := player.Score |
| 228 | + needSavePlayer = true | ||
| 218 | // 记录日志 | 229 | // 记录日志 |
| 219 | recordBase := NewRecordBase(player.Uid, req.TopType, config.Id) | 230 | recordBase := NewRecordBase(player.Uid, req.TopType, config.Id) |
| 220 | SaveRecordAddScore(gameId, NewRecordAddScore(recordBase, req.AddScore, oldScore, newScore)) | 231 | SaveRecordAddScore(gameId, NewRecordAddScore(recordBase, req.AddScore, oldScore, newScore)) |
| @@ -228,15 +239,14 @@ func HandleAddScore(req *models.ReqRoomRankAddScore) (code string, rsp models.Rs | @@ -228,15 +239,14 @@ func HandleAddScore(req *models.ReqRoomRankAddScore) (code string, rsp models.Rs | ||
| 228 | // 尝试加入房间 | 239 | // 尝试加入房间 |
| 229 | room, hasRoom, firstJoin := TryGetRoom(gameId, req.TopType, player, config, playerLevel) | 240 | room, hasRoom, firstJoin := TryGetRoom(gameId, req.TopType, player, config, playerLevel) |
| 230 | 241 | ||
| 231 | - // 房间排行增加积分 | ||
| 232 | - UpdatePlayerScore(room, player) | ||
| 233 | - | ||
| 234 | if !hasRoom { | 242 | if !hasRoom { |
| 235 | code = code_msg.RECODE_MERGE_CONFIG_ERROR | 243 | code = code_msg.RECODE_MERGE_CONFIG_ERROR |
| 236 | return | 244 | return |
| 237 | } | 245 | } |
| 246 | + | ||
| 247 | + // 房间排行增加积分 | ||
| 248 | + UpdatePlayerScore(room, player) | ||
| 238 | TryReSort(room, config) | 249 | TryReSort(room, config) |
| 239 | - SavePlayer(gameId, player) | ||
| 240 | SaveRoom(gameId, room) | 250 | SaveRoom(gameId, room) |
| 241 | 251 | ||
| 242 | rsp.RoomRankInfo = GetInfoFromRoom(gameId, player, room, config) | 252 | rsp.RoomRankInfo = GetInfoFromRoom(gameId, player, room, config) |
service/roomrank/room.go
| @@ -86,34 +86,10 @@ func FindRoom(gameId string, topType int, activityId int64, roomConfigId int) (r | @@ -86,34 +86,10 @@ 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 | - | ||
| 109 | // TryGetRoom 尝试获取房间 | 89 | // TryGetRoom 尝试获取房间 |
| 110 | func TryGetRoom(gameId string, topType int, player *Player, config *confroomrank.ActivityConfig, playerLevel int) (room *Room, hasRoom bool, firstJoin bool) { | 90 | func TryGetRoom(gameId string, topType int, player *Player, config *confroomrank.ActivityConfig, playerLevel int) (room *Room, hasRoom bool, firstJoin bool) { |
| 111 | hasRoom = false | 91 | hasRoom = false |
| 112 | firstJoin = false | 92 | firstJoin = false |
| 113 | - if player.ActivityId != config.Id { | ||
| 114 | - player.ActivityId = config.Id | ||
| 115 | - player.RoomUid = 0 | ||
| 116 | - } | ||
| 117 | // 查找玩家所在的房间 | 93 | // 查找玩家所在的房间 |
| 118 | room, hasRoom = LoadRoom(gameId, topType, config.Id, player.RoomUid) | 94 | room, hasRoom = LoadRoom(gameId, topType, config.Id, player.RoomUid) |
| 119 | if hasRoom { | 95 | if hasRoom { |