Commit 2c35f0c9436d0e6c5e64e639e4aa08552e45d5da
1 parent
efb4f5c8
Exists in
master
and in
1 other branch
feat✨:排行榜结算方式改为每天结算
Showing
2 changed files
with
50 additions
and
24 deletions
Show diff stats
service/roomrank/logic.go
| ... | ... | @@ -60,22 +60,34 @@ func TrySettle(gameId string, topType int, player *Player, config *confroomrank. |
| 60 | 60 | return |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | + // 已经结算过的不结算 | |
| 63 | 64 | if room.HasSettle { |
| 64 | 65 | return |
| 65 | 66 | } |
| 66 | - // 未到结算时间不结算 | |
| 67 | - dtYear, dtMonth, dtDay := ActivityTimeToDate(room.ActivityTime) | |
| 68 | - hour, min, sec := ztime.TimeClock(config.ReleaseTime) | |
| 69 | - dt := time.Date(dtYear, dtMonth, dtDay, hour, min, sec, 0, time.Local) | |
| 70 | - dtNow := lxtime.NowUninx() | |
| 71 | - if dtNow < dt.Unix() { | |
| 72 | - return | |
| 73 | - } | |
| 74 | 67 | |
| 75 | 68 | confActivity, hasConfActivity := confroomrank.GetConfig(gameId, room.ActivityId) |
| 76 | 69 | if !hasConfActivity { |
| 77 | 70 | return |
| 78 | 71 | } |
| 72 | + | |
| 73 | + // 活动切换或者时间到 触发结算 | |
| 74 | + needSettle := false | |
| 75 | + if player.ActivityId != config.Id { | |
| 76 | + needSettle = true | |
| 77 | + } else { | |
| 78 | + dtYear, dtMonth, dtDay := ActivityTimeToDate(room.ActivityTime) | |
| 79 | + hour, min, sec := ztime.TimeClock(confActivity.ReleaseTime) | |
| 80 | + dt := time.Date(dtYear, dtMonth, dtDay, hour, min, sec, 0, time.Local) | |
| 81 | + dtNow := lxtime.NowUninx() | |
| 82 | + if dtNow >= dt.Unix() { | |
| 83 | + needSettle = true | |
| 84 | + } | |
| 85 | + } | |
| 86 | + | |
| 87 | + if !needSettle { | |
| 88 | + return | |
| 89 | + } | |
| 90 | + | |
| 79 | 91 | TrySettleRoom(gameId, room, confActivity) |
| 80 | 92 | |
| 81 | 93 | // 找到玩家在房间里的名次 | ... | ... |
service/roomrank/room.go
| ... | ... | @@ -6,9 +6,12 @@ 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 | + "fmt" | |
| 9 | 11 | "math" |
| 10 | 12 | "math/rand" |
| 11 | 13 | "sort" |
| 14 | + "time" | |
| 12 | 15 | ) |
| 13 | 16 | |
| 14 | 17 | func tryInitRoom(gameId string, room *Room) { |
| ... | ... | @@ -214,9 +217,6 @@ func JoinInitRobot(gameId string, room *Room, roomConfig confroomrank.RoomConfig |
| 214 | 217 | |
| 215 | 218 | // TrySettleRoom 尝试结算房间 |
| 216 | 219 | func TrySettleRoom(gameId string, room *Room, confActivity *confroomrank.ActivityConfig) { |
| 217 | - if room.HasSettle { | |
| 218 | - return | |
| 219 | - } | |
| 220 | 220 | // 机器人最终算分 |
| 221 | 221 | for i := 0; i < len(room.Details.Players); i++ { |
| 222 | 222 | roomPlayer := room.Details.Players[i] |
| ... | ... | @@ -241,6 +241,31 @@ func TryResetRobot(room *Room, config *confroomrank.ActivityConfig) { |
| 241 | 241 | return |
| 242 | 242 | } |
| 243 | 243 | room.ResetRobotTime = secNow |
| 244 | + | |
| 245 | + percent := float64(0) | |
| 246 | + dtYear, dtMonth, dtDay := ActivityTimeToDate(room.ActivityTime) | |
| 247 | + hour, min, sec := ztime.TimeClock(config.ReleaseTime) | |
| 248 | + dateEnd := time.Date(dtYear, dtMonth, dtDay, hour, min, sec, 0, time.Local) | |
| 249 | + dateStart := dateEnd.AddDate(0, 0, -1) | |
| 250 | + dtStart := dateStart.Unix() | |
| 251 | + dtEnd := dateEnd.Unix() | |
| 252 | + if dtStart < config.StartTime { | |
| 253 | + dtStart = config.StartTime | |
| 254 | + } | |
| 255 | + if dtEnd > config.EndTime { | |
| 256 | + dtEnd = config.EndTime | |
| 257 | + } | |
| 258 | + if dtEnd <= dtStart { | |
| 259 | + percent = 0 | |
| 260 | + } else if secNow <= dtStart { | |
| 261 | + percent = 0 | |
| 262 | + } else if secNow >= dtEnd { | |
| 263 | + percent = 100 | |
| 264 | + } else { | |
| 265 | + percent = float64(secNow-dtStart) * 100 / float64(dtEnd-dtStart) | |
| 266 | + } | |
| 267 | + fmt.Println("dwjw🐸 percent", percent) | |
| 268 | + | |
| 244 | 269 | // 机器人即时算分 |
| 245 | 270 | for i := 0; i < len(room.Details.Players); i++ { |
| 246 | 271 | roomPlayer := room.Details.Players[i] |
| ... | ... | @@ -249,7 +274,7 @@ func TryResetRobot(room *Room, config *confroomrank.ActivityConfig) { |
| 249 | 274 | } |
| 250 | 275 | confRobot, hasConfRobot := config.Robot[roomPlayer.RobotConfigId] |
| 251 | 276 | if hasConfRobot { |
| 252 | - roomPlayer.Score = GetRobotScoreCurrent(config, &confRobot, secNow) | |
| 277 | + roomPlayer.Score = GetRobotScoreCurrent(&confRobot, percent) | |
| 253 | 278 | } |
| 254 | 279 | } |
| 255 | 280 | } |
| ... | ... | @@ -261,18 +286,7 @@ func TryReSort(room *Room, config *confroomrank.ActivityConfig) { |
| 261 | 286 | } |
| 262 | 287 | |
| 263 | 288 | // GetRobotScoreCurrent 从机器人配置里得到实时得分 |
| 264 | -func GetRobotScoreCurrent(config *confroomrank.ActivityConfig, confRobot *confroomrank.RobotConfig, secNow int64) int64 { | |
| 265 | - percent := float64(0) | |
| 266 | - if config.EndTime <= config.StartTime { | |
| 267 | - percent = 0 | |
| 268 | - } else if secNow <= config.StartTime { | |
| 269 | - percent = 0 | |
| 270 | - } else if secNow >= config.EndTime { | |
| 271 | - percent = 100 | |
| 272 | - } else { | |
| 273 | - percent = float64(secNow-config.StartTime) * 100 / float64(config.EndTime-config.StartTime) | |
| 274 | - } | |
| 275 | - | |
| 289 | +func GetRobotScoreCurrent(confRobot *confroomrank.RobotConfig, percent float64) int64 { | |
| 276 | 290 | score := (float64(confRobot.TotalScore-confRobot.MinScore) * |
| 277 | 291 | float64(100-confRobot.Range+rand.Intn(confRobot.Range*2)) / 100) * percent / 100 |
| 278 | 292 | result := int64(confRobot.MinScore) + int64(math.Ceil(score)) | ... | ... |