53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
![]() |
package data
|
||
|
|
||
|
import (
|
||
|
"github.com/oylshe1314/framework/errors"
|
||
|
"github.com/oylshe1314/framework/util"
|
||
|
"sort"
|
||
|
)
|
||
|
|
||
|
func (this *WarshipLevelTable) check() error {
|
||
|
for _, d := range this.l {
|
||
|
if len(d.ConsumeItemNum) != len(d.ConsumeItemId) {
|
||
|
return errors.Error("incorrect 'WarshipLevel' table, error: len(d.ConsumeItemNum) != len(d.ConsumeItemId), id: ", d.id())
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
type WarshipLevelTableExtend struct {
|
||
|
*WarshipLevelTable
|
||
|
|
||
|
extMap1 map[int][]*WarshipLevel
|
||
|
extMap2 map[uint64]*WarshipLevel
|
||
|
}
|
||
|
|
||
|
func (this *WarshipLevelTableExtend) init() error {
|
||
|
if this.WarshipLevelTable == nil {
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
this.extMap1 = map[int][]*WarshipLevel{}
|
||
|
this.extMap2 = map[uint64]*WarshipLevel{}
|
||
|
for _, d := range this.l {
|
||
|
this.extMap1[d.Type] = append(this.extMap1[d.Type], d)
|
||
|
this.extMap2[util.Compose2uint32(uint32(d.Type), uint32(d.Level))] = d
|
||
|
}
|
||
|
|
||
|
for _, levels := range this.extMap1 {
|
||
|
sort.Slice(levels, func(i, j int) bool {
|
||
|
return levels[i].Level < levels[j].Level
|
||
|
})
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (this *WarshipLevelTableExtend) List(tipe int) []*WarshipLevel {
|
||
|
return this.extMap1[tipe]
|
||
|
}
|
||
|
|
||
|
func (this *WarshipLevelTableExtend) Get(tipe, level int) *WarshipLevel {
|
||
|
return this.extMap2[util.Compose2uint32(uint32(tipe), uint32(level))]
|
||
|
}
|