52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
![]() |
package data
|
||
|
|
||
|
import (
|
||
|
"github.com/oylshe1314/framework/errors"
|
||
|
"github.com/oylshe1314/framework/util"
|
||
|
"sort"
|
||
|
)
|
||
|
|
||
|
func (this *PlanetCivilizationTable) check() error {
|
||
|
for _, d := range this.l {
|
||
|
if len(d.CostItemNum) != len(d.CostItemId) {
|
||
|
return errors.Error("incorrect 'PlanetCivilization' table, error: len(d.CostItemNum) != len(d.CostItemId), id: ", d.id())
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
type PlanetCivilizationTableExtend struct {
|
||
|
*PlanetCivilizationTable
|
||
|
|
||
|
extMap1 map[int][]*PlanetCivilization
|
||
|
extMap2 map[uint64]*PlanetCivilization
|
||
|
}
|
||
|
|
||
|
func (this *PlanetCivilizationTableExtend) init() error {
|
||
|
if this.PlanetCivilizationTable == nil {
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
this.extMap1 = map[int][]*PlanetCivilization{}
|
||
|
this.extMap2 = map[uint64]*PlanetCivilization{}
|
||
|
for _, d := range this.l {
|
||
|
this.extMap1[d.CivilizationId] = append(this.extMap1[d.CivilizationId], d)
|
||
|
this.extMap2[util.Compose2uint32(uint32(d.CivilizationId), uint32(d.Level))] = d
|
||
|
}
|
||
|
|
||
|
for _, civilizations := range this.extMap1 {
|
||
|
sort.Slice(civilizations, func(i, j int) bool {
|
||
|
return civilizations[i].Level < civilizations[j].Level
|
||
|
})
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (this *PlanetCivilizationTableExtend) List(civilizationId int) []*PlanetCivilization {
|
||
|
return this.extMap1[civilizationId]
|
||
|
}
|
||
|
|
||
|
func (this *PlanetCivilizationTableExtend) Get(civilizationId, level int) *PlanetCivilization {
|
||
|
return this.extMap2[util.Compose2uint32(uint32(civilizationId), uint32(level))]
|
||
|
}
|