Commit c49a96c6de49d2eda13ebb9ad0bca1720a1ee005

Authored by 王家文
1 parent c72be610
Exists in master and in 1 other branch dev-wjw

feat✨:排行榜功能

service/roomrank/logic.go
... ... @@ -3,7 +3,6 @@ package roomrank
3 3 import (
4 4 "apigame/configs/confroomrank"
5 5 "apigame/service-common/svconst"
6   - "apigame/util/util-lx/lxtime"
7 6 "apigame/util/utstring"
8 7 "apigame/util/ztime"
9 8 "fmt"
... ... @@ -60,36 +59,17 @@ func TrySettle(gameId string, topType int, player *Player, config *confroomrank.
60 59 return
61 60 }
62 61  
63   - // 已经结算过的不结算
64   - if room.HasSettle {
65   - return
66   - }
67   -
68 62 confActivity, hasConfActivity := confroomrank.GetConfig(gameId, room.ActivityId)
69 63 if !hasConfActivity {
70 64 return
71 65 }
72 66  
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   - }
  67 + TrySettleRoom(gameId, room, confActivity)
86 68  
87   - if !needSettle {
  69 + if !room.HasSettle {
88 70 return
89 71 }
90 72  
91   - TrySettleRoom(gameId, room, confActivity)
92   -
93 73 // 找到玩家在房间里的名次
94 74 // rankIndex = 0-49 rank = 1-50
95 75 rankIndex, rankScore := room.FindPlayer(player.Uid)
... ...
service/roomrank/room.go
... ... @@ -216,6 +216,28 @@ func JoinInitRobot(gameId string, room *Room, roomConfig confroomrank.RoomConfig
216 216  
217 217 // TrySettleRoom 尝试结算房间
218 218 func TrySettleRoom(gameId string, room *Room, confActivity *confroomrank.ActivityConfig) {
  219 + // 已经结算过的不结算
  220 + if room.HasSettle {
  221 + return
  222 + }
  223 + // 活动切换或者时间到 触发结算
  224 + needSettle := false
  225 + if room.ActivityId != confActivity.Id {
  226 + needSettle = true
  227 + } 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)
  231 + dtNow := lxtime.NowUninx()
  232 + if dtNow >= dt.Unix() {
  233 + needSettle = true
  234 + }
  235 + }
  236 +
  237 + if !needSettle {
  238 + return
  239 + }
  240 +
219 241 // 机器人最终算分
220 242 for i := 0; i < len(room.Details.Players); i++ {
221 243 roomPlayer := room.Details.Players[i]
... ...