| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- 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) Random(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) 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
- }
|