46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
package data
|
|
|
|
import (
|
|
"github.com/oylshe1314/framework/errors"
|
|
"github.com/oylshe1314/framework/util"
|
|
"sort"
|
|
)
|
|
|
|
func (this *AchievementTable) check() error {
|
|
for _, d := range this.l {
|
|
if len(d.NumList) != len(d.ItemList) {
|
|
return errors.Error("incorrect 'Achievement' table, error: len(d.NumList) != len(d.ItemList), id: ", d.id())
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type AchievementTableExtend struct {
|
|
*AchievementTable
|
|
|
|
extMap map[uint64][]*Achievement
|
|
}
|
|
|
|
func (this *AchievementTableExtend) init() error {
|
|
if this.AchievementTable == nil {
|
|
return nil
|
|
}
|
|
|
|
this.extMap = map[uint64][]*Achievement{}
|
|
for _, d := range this.l {
|
|
var key = util.Compose2uint32(uint32(d.AchievementType), uint32(d.ExtraNum))
|
|
this.extMap[key] = append(this.extMap[key], d)
|
|
}
|
|
|
|
for _, ds := range this.extMap {
|
|
sort.Slice(ds, func(i, j int) bool {
|
|
return ds[i].id() < ds[j].id()
|
|
})
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (this *AchievementTableExtend) Get(achievementType, extraNum int) []*Achievement {
|
|
return this.extMap[util.Compose2uint32(uint32(achievementType), uint32(extraNum))]
|
|
}
|