| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package data
- import (
- "f1-game/internal/extend/math"
- "f1-game/internal/types"
- )
- var (
- facilityMaxLevelMap map[int32]int32
- )
- func (p *facilityLevelConfig) OnAfterLoad(_ bool) {
- loadMap := map[int32]int32{}
- for _, row := range p.list {
- maxLevel, found := loadMap[row.FacilityID]
- if !found {
- loadMap[row.FacilityID] = row.Level
- continue
- }
- if row.Level > maxLevel {
- loadMap[row.FacilityID] = row.Level
- }
- }
- facilityMaxLevelMap = loadMap
- }
- // 获取最大等级
- func (p *facilityLevelConfig) GetMaxLevel(facilityID int32) int32 {
- maxLevel, found := facilityMaxLevelMap[facilityID]
- if !found {
- return 0
- }
- return maxLevel
- }
- // 获取返还的消耗
- func (p *facilityLevelConfig) GetRefundAssets(facilityID int32, level int32) (types.Assets, bool) {
- row, ok := p.GetByFacilityIDLevel(facilityID, level)
- if !ok {
- return nil, false
- }
- assets := types.Assets{}
- for _, asset := range row.UpgradeCost {
- // 向下取整
- assets.Add(asset.ID, math.Floor[float32, int64](float32(asset.Num)*Const.BuildUpRefundRatio))
- }
- return assets, true
- }
|