extend_facility_level.go 1.3 KB

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