package genPool import ( "f1-game/internal/data" "f1-game/internal/enum" ctime "github.com/cherry-game/cherry/extend/time" ) const ( CountKey = "count" PeriodEndTimeKey = "periodEndTime" ) type GenPoolItem struct { GenPoolID int32 // 产出池ID ItemID int32 // 道具ID Count int64 // 已产出数量 PeriodEndTime int64 // 周期结束时间 } func NewGenPoolItem(GenPoolID, itemID int32) *GenPoolItem { return &GenPoolItem{ GenPoolID: GenPoolID, ItemID: itemID, Count: 0, } } // 检查是否可以重置 func (p *GenPoolItem) CheckReset(nowTime ctime.CherryTime) bool { // 未到到重置时间 if nowTime.ToMillisecond() > p.PeriodEndTime { return true } return false } // 根据时间类型,计算周期结束时间 func (p *GenPoolItem) CalcPeriodEndTime(nowTime ctime.CherryTime) int64 { genPoolRow, _ := data.GenPool.GetByIDItemID(p.GenPoolID, p.ItemID) switch genPoolRow.TimeType { case enum.GenPoolTimeType_Hour: // 每小时 return nowTime.EndOfHour().ToMillisecond() case enum.GenPoolTimeType_Day: // 每天 return nowTime.EndOfDay().ToMillisecond() case enum.GenPoolTimeType_Week: // 每周 return nowTime.EndOfWeek().ToMillisecond() case enum.GenPoolTimeType_Month: // 每月 return nowTime.EndOfMonth().ToMillisecond() default: return 0 } } // 重置产出数量并刷新周期结束时间 func (p *GenPoolItem) ResetCount(nowTime ctime.CherryTime) { p.Count = 0 p.PeriodEndTime = p.CalcPeriodEndTime(nowTime) } // 增加产出数量 func (p *GenPoolItem) AddCount(count int64) { p.Count += count } // 获取可产出数量 func (p *GenPoolItem) GetCanCount(add int64) int64 { genPoolRow, _ := data.GenPool.GetByIDItemID(p.GenPoolID, p.ItemID) // 剩余可产出数量 remaining := genPoolRow.Num - p.Count return min(remaining, add) }