| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package data
- import (
- "f1-game/internal/extend/math"
- "slices"
- )
- // 获取当前使用的签到库ID
- // round 如果只有两个库,每个库签到上限是30天,当前开服95天 那么round为4 第二个库签到第5天(如果签到库用完还没结束,继续循环用最后一个库)
- func (p *signInConfig) GetCurrentPoolID(openDays int32) (int32, int32) {
- var (
- curPoolID = int32(1)
- round = int32(0)
- cumDays = int32(0)
- )
- // 获取所有 PoolID 并排序
- poolIDs := make([]int32, 0, len(p.poolIDListMaps))
- for poolID := range p.poolIDListMaps {
- poolIDs = append(poolIDs, poolID)
- }
- slices.Sort(poolIDs)
- // 按顺序遍历
- for _, poolID := range poolIDs {
- rows := p.poolIDListMaps[poolID]
- cumDays += int32(len(rows))
- round++
- if openDays <= cumDays {
- return round, poolID
- }
- curPoolID = math.Max(curPoolID, poolID)
- }
- if openDays > cumDays {
- row := p.poolIDListMaps[curPoolID]
- round += (openDays - cumDays) / int32(len(row))
- }
- // 如果是最后一个则返回最大的库ID
- return round, curPoolID
- }
- // 获取当前签到天数
- func (p *signInConfig) GetCurrenSignInDays(openDays int32) int32 {
- maxPoolID := int32(0)
- for poolID, rows := range p.poolIDListMaps {
- maxPoolID = math.Max(maxPoolID, poolID)
- totalDays := int32(len(rows))
- if openDays <= totalDays {
- return openDays
- }
- if openDays <= 0 {
- return 0
- }
- openDays -= totalDays
- }
- // 可能是最后一期循环
- maxPoolRow, found := p.poolIDListMaps[maxPoolID]
- if !found {
- return 0
- }
- return openDays % int32(len(maxPoolRow))
- }
|