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