extend_facility_level.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package data
  2. import (
  3. "f1-game/internal/extend/math"
  4. "f1-game/internal/types"
  5. )
  6. var (
  7. facilityMaxLevelMap map[int32]int32
  8. )
  9. func (p *facilityLevelConfig) OnAfterLoad(_ bool) {
  10. loadMap := map[int32]int32{}
  11. for _, row := range p.list {
  12. maxLevel, found := loadMap[row.FacilityID]
  13. if !found {
  14. loadMap[row.FacilityID] = row.Level
  15. continue
  16. }
  17. if row.Level > maxLevel {
  18. loadMap[row.FacilityID] = row.Level
  19. }
  20. }
  21. facilityMaxLevelMap = loadMap
  22. }
  23. // 获取最大等级
  24. func (p *facilityLevelConfig) GetMaxLevel(facilityID int32) int32 {
  25. maxLevel, found := facilityMaxLevelMap[facilityID]
  26. if !found {
  27. return 0
  28. }
  29. return maxLevel
  30. }
  31. // 获取返还的消耗
  32. func (p *facilityLevelConfig) GetRefundAssets(facilityID int32, level int32) (types.Assets, bool) {
  33. row, ok := p.GetByFacilityIDLevel(facilityID, level)
  34. if !ok {
  35. return nil, false
  36. }
  37. assets := types.Assets{}
  38. for _, asset := range row.UpgradeCost {
  39. // 向下取整
  40. assets.Add(asset.ID, math.Floor[float32, int64](float32(asset.Num)*Const.BuildUpRefundRatio))
  41. }
  42. return assets, true
  43. }