extend_sign_in.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package data
  2. import (
  3. "f1-game/internal/extend/math"
  4. "slices"
  5. )
  6. // 获取当前使用的签到库ID
  7. // round 如果只有两个库,每个库签到上限是30天,当前开服95天 那么round为4 第二个库签到第5天(如果签到库用完还没结束,继续循环用最后一个库)
  8. func (p *signInConfig) GetCurrentPoolID(openDays int32) (int32, int32) {
  9. var (
  10. curPoolID = int32(1)
  11. round = int32(0)
  12. cumDays = int32(0)
  13. )
  14. // 获取所有 PoolID 并排序
  15. poolIDs := make([]int32, 0, len(p.poolIDListMaps))
  16. for poolID := range p.poolIDListMaps {
  17. poolIDs = append(poolIDs, poolID)
  18. }
  19. slices.Sort(poolIDs)
  20. // 按顺序遍历
  21. for _, poolID := range poolIDs {
  22. rows := p.poolIDListMaps[poolID]
  23. cumDays += int32(len(rows))
  24. round++
  25. if openDays <= cumDays {
  26. return round, poolID
  27. }
  28. curPoolID = math.Max(curPoolID, poolID)
  29. }
  30. if openDays > cumDays {
  31. row := p.poolIDListMaps[curPoolID]
  32. round += (openDays - cumDays) / int32(len(row))
  33. }
  34. // 如果是最后一个则返回最大的库ID
  35. return round, curPoolID
  36. }
  37. // 获取当前签到天数
  38. func (p *signInConfig) GetCurrenSignInDays(openDays int32) int32 {
  39. maxPoolID := int32(0)
  40. for poolID, rows := range p.poolIDListMaps {
  41. maxPoolID = math.Max(maxPoolID, poolID)
  42. totalDays := int32(len(rows))
  43. if openDays <= totalDays {
  44. return openDays
  45. }
  46. if openDays <= 0 {
  47. return 0
  48. }
  49. openDays -= totalDays
  50. }
  51. // 可能是最后一期循环
  52. maxPoolRow, found := p.poolIDListMaps[maxPoolID]
  53. if !found {
  54. return 0
  55. }
  56. return openDays % int32(len(maxPoolRow))
  57. }