extend_monster_pool.go 759 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package data
  2. import (
  3. "f1-game/internal/extend/rand"
  4. )
  5. var (
  6. monsterPoolWeightMap map[int32]*rand.Weight[*MonsterPoolRow]
  7. )
  8. func (p *monsterPoolConfig) OnAfterLoad(_ bool) {
  9. loadMap := map[int32]*rand.Weight[*MonsterPoolRow]{}
  10. for poolID, rows := range p.poolIDGroupIDUniMaps {
  11. weight := rand.NewMapWeight(rows, func(v *MonsterPoolRow) int32 {
  12. return v.Weight
  13. })
  14. loadMap[poolID] = weight
  15. }
  16. monsterPoolWeightMap = loadMap
  17. }
  18. func (p *monsterPoolConfig) RandIDList(poolID int32, num int) []int32 {
  19. weighter, ok := monsterPoolWeightMap[poolID]
  20. if !ok {
  21. return nil
  22. }
  23. rows := weighter.Select(num)
  24. if len(rows) == 0 {
  25. return nil
  26. }
  27. ids := make([]int32, len(rows))
  28. for i, row := range rows {
  29. ids[i] = row.GroupID
  30. }
  31. return ids
  32. }