package data import ( "f1-game/internal/code" "f1-game/internal/extend/rand" ) var ( dropPoolWeightMap map[int32]*rand.Weight[*DropPoolRow] ) func (p *dropPoolConfig) OnAfterLoad(_ bool) { loadMap := map[int32]*rand.Weight[*DropPoolRow]{} for poolID, rows := range p.idListMaps { weight := rand.NewSliceWeight(rows, func(v *DropPoolRow) int32 { return v.Weight }) loadMap[poolID] = weight } dropPoolWeightMap = loadMap } func (p *dropPoolConfig) RandomOne(dropPoolID int32) (*DropPoolRow, int32) { weighter, found := p.GetWeighter(dropPoolID) if !found { //道具池找不到 return nil, code.ConfigNotFound_DropPool } // 随机取一个奖励 row := weighter.SelectOne() if row == nil { return nil, code.HeroCannotRecruit } return row, code.OK } func (p *dropPoolConfig) Random(dropPoolID int32, num int32) ([]*DropPoolRow, int32) { weighter, found := p.GetWeighter(dropPoolID) if !found { //道具池找不到 return nil, code.ConfigNotFound_DropPool } // 随机num个奖励 rows := weighter.Select(int(num)) if rows == nil { return nil, code.HeroCannotRecruit } return rows, code.OK } func (p *dropPoolConfig) GetWeighter(itemPoolID int32) (*rand.Weight[*DropPoolRow], bool) { value, found := dropPoolWeightMap[itemPoolID] return value, found } func (p *dropPoolConfig) GetDropPoolRow(poolID, itemID int32) (*DropPoolRow, bool) { rows, found := p.ListByID(poolID) if !found { return nil, false } for _, row := range rows { if row.ItemID == itemID { return row, true } } return nil, false }