ecs/servers/game/data_old/shop_ext.go
2025-06-04 18:17:39 +08:00

46 lines
978 B
Go

package data
import "github.com/oylshe1314/framework/util"
type ShopTableExtend struct {
*ShopTable
extMap map[uint64][]*Shop
}
func (this *ShopTableExtend) init() error {
if this.ShopTable == nil {
return nil
}
this.extMap = map[uint64][]*Shop{}
for _, d := range this.l {
var key = util.Compose2uint32(uint32(d.ShopType), uint32(d.PoolId))
this.extMap[key] = append(this.extMap[key], d)
}
return nil
}
func (this *ShopTableExtend) List(shopType, poolId int) []*Shop {
return this.extMap[util.Compose2uint32(uint32(shopType), uint32(poolId))]
}
func (this *ShopTableExtend) Random(shopType, poolId int, exclude map[int]struct{}) *Shop {
var shopTables []*Shop
for _, shop := range this.List(shopType, poolId) {
if shop.PoolWeight <= 0 {
continue
}
if _, ok := exclude[shop.id()]; ok {
continue
}
shopTables = append(shopTables, shop)
}
return util.RandomWeights(shopTables, func(i int) int {
return shopTables[i].PoolWeight
})
}