Commit 2a6cfa386c60380d5e3d2a6ac450f1fd21c0eede
1 parent
c49a96c6
Exists in
master
and in
1 other branch
feat✨:排行榜功能
Showing
2 changed files
with
15 additions
and
13 deletions
Show diff stats
service/roomrank/logic.go
| ... | ... | @@ -34,6 +34,13 @@ func ActivityTimeToDate(activityTime int64) (year int, month time.Month, day int |
| 34 | 34 | return |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | +func GetTimeEnd(activityTime int64, releaseTime string) time.Time { | |
| 38 | + dtYear, dtMonth, dtDay := ActivityTimeToDate(activityTime) | |
| 39 | + hour, min, sec := ztime.TimeClock(releaseTime) | |
| 40 | + dt := time.Date(dtYear, dtMonth, dtDay, hour, min, sec, 0, time.Local) | |
| 41 | + return dt | |
| 42 | +} | |
| 43 | + | |
| 37 | 44 | // TrySettle 尝试判断结算 |
| 38 | 45 | func TrySettle(gameId string, topType int, player *Player, config *confroomrank.ActivityConfig, activityTime int64) (hasChange bool) { |
| 39 | 46 | hasChange = false | ... | ... |
service/roomrank/room.go
| ... | ... | @@ -6,11 +6,9 @@ import ( |
| 6 | 6 | "apigame/service-common/svmysql" |
| 7 | 7 | "apigame/util/util-lx/lxalilog" |
| 8 | 8 | "apigame/util/util-lx/lxtime" |
| 9 | - "apigame/util/ztime" | |
| 10 | 9 | "math" |
| 11 | 10 | "math/rand" |
| 12 | 11 | "sort" |
| 13 | - "time" | |
| 14 | 12 | ) |
| 15 | 13 | |
| 16 | 14 | func tryInitRoom(gameId string, room *Room) { |
| ... | ... | @@ -97,7 +95,7 @@ func TryGetRoom(gameId string, topType int, player *Player, config *confroomrank |
| 97 | 95 | room, hasRoom = LoadRoom(gameId, topType, config.Id, player.RoomUid) |
| 98 | 96 | if hasRoom { |
| 99 | 97 | if confRoom, hasConfRoom := config.Room[room.ConfigId]; hasConfRoom { |
| 100 | - TryCloseRoom(gameId, room, confRoom) | |
| 98 | + TryCloseRoom(gameId, room, config, confRoom) | |
| 101 | 99 | } |
| 102 | 100 | return |
| 103 | 101 | } |
| ... | ... | @@ -122,7 +120,7 @@ func TryGetRoom(gameId string, topType int, player *Player, config *confroomrank |
| 122 | 120 | if has { |
| 123 | 121 | for i := 0; i < len(rooms); i++ { |
| 124 | 122 | roomTemp := rooms[i] |
| 125 | - TryCloseRoom(gameId, roomTemp, roomConfig) | |
| 123 | + TryCloseRoom(gameId, roomTemp, config, roomConfig) | |
| 126 | 124 | if roomTemp.Closed { |
| 127 | 125 | continue |
| 128 | 126 | } |
| ... | ... | @@ -166,12 +164,13 @@ func PlayerJoinRoom(room *Room, player *Player) { |
| 166 | 164 | } |
| 167 | 165 | |
| 168 | 166 | // TryCloseRoom 尝试关闭房间 |
| 169 | -func TryCloseRoom(gameId string, room *Room, roomConfig confroomrank.RoomConfig) { | |
| 167 | +func TryCloseRoom(gameId string, room *Room, config *confroomrank.ActivityConfig, roomConfig confroomrank.RoomConfig) { | |
| 170 | 168 | if room.Closed { |
| 171 | 169 | return |
| 172 | 170 | } |
| 173 | 171 | secNow := lxtime.NowUninx() |
| 174 | - if secNow > room.ActivityTime-RoomCloseSecond { | |
| 172 | + dateEnd := GetTimeEnd(room.ActivityTime, config.ReleaseTime) | |
| 173 | + if secNow > dateEnd.Unix()-RoomCloseSecond { | |
| 175 | 174 | room.Closed = true |
| 176 | 175 | // 根据缺口自动填充机器人 |
| 177 | 176 | for i := 0; i < len(roomConfig.PlayerTypeCount); i++ { |
| ... | ... | @@ -225,11 +224,9 @@ func TrySettleRoom(gameId string, room *Room, confActivity *confroomrank.Activit |
| 225 | 224 | if room.ActivityId != confActivity.Id { |
| 226 | 225 | needSettle = true |
| 227 | 226 | } else { |
| 228 | - dtYear, dtMonth, dtDay := ActivityTimeToDate(room.ActivityTime) | |
| 229 | - hour, min, sec := ztime.TimeClock(confActivity.ReleaseTime) | |
| 230 | - dt := time.Date(dtYear, dtMonth, dtDay, hour, min, sec, 0, time.Local) | |
| 227 | + dateEnd := GetTimeEnd(room.ActivityTime, confActivity.ReleaseTime) | |
| 231 | 228 | dtNow := lxtime.NowUninx() |
| 232 | - if dtNow >= dt.Unix() { | |
| 229 | + if dtNow >= dateEnd.Unix() { | |
| 233 | 230 | needSettle = true |
| 234 | 231 | } |
| 235 | 232 | } |
| ... | ... | @@ -264,9 +261,7 @@ func TryResetRobot(room *Room, config *confroomrank.ActivityConfig) { |
| 264 | 261 | room.ResetRobotTime = secNow |
| 265 | 262 | |
| 266 | 263 | percent := float64(0) |
| 267 | - dtYear, dtMonth, dtDay := ActivityTimeToDate(room.ActivityTime) | |
| 268 | - hour, min, sec := ztime.TimeClock(config.ReleaseTime) | |
| 269 | - dateEnd := time.Date(dtYear, dtMonth, dtDay, hour, min, sec, 0, time.Local) | |
| 264 | + dateEnd := GetTimeEnd(room.ActivityTime, config.ReleaseTime) | |
| 270 | 265 | dateStart := dateEnd.AddDate(0, 0, -1) |
| 271 | 266 | dtStart := dateStart.Unix() |
| 272 | 267 | dtEnd := dateEnd.Unix() | ... | ... |