63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package data
|
|
|
|
import (
|
|
"github.com/oylshe1314/framework/errors"
|
|
"github.com/oylshe1314/framework/util"
|
|
"sort"
|
|
)
|
|
|
|
func (this *BattlePassRewardTable) check() error {
|
|
for _, d := range this.l {
|
|
if len(d.OrdinaryNumList) != len(d.OrdinaryItemList) {
|
|
return errors.Error("incorrect 'BattlePassReward' table, error: len(d.OrdinaryNumList) != len(d.OrdinaryItemList), id: ", d.id())
|
|
}
|
|
if len(d.PrivilegeNumList) != len(d.PrivilegeItemList) {
|
|
return errors.Error("incorrect 'BattlePassReward' table, error: len(d.PrivilegeNumList) != len(d.PrivilegeItemList), id: ", d.id())
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type BattlePassRewardTableExtend struct {
|
|
*BattlePassRewardTable
|
|
|
|
extList map[int][]*BattlePassReward
|
|
extMap map[uint64]*BattlePassReward
|
|
}
|
|
|
|
func (this *BattlePassRewardTableExtend) init() error {
|
|
if this.BattlePassRewardTable == nil {
|
|
return nil
|
|
}
|
|
|
|
this.extList = map[int][]*BattlePassReward{}
|
|
this.extMap = map[uint64]*BattlePassReward{}
|
|
for _, d := range this.l {
|
|
this.extList[d.SeasonId] = append(this.extList[d.SeasonId], d)
|
|
this.extMap[util.Compose2uint32(uint32(d.SeasonId), uint32(d.Level))] = d
|
|
}
|
|
|
|
for _, rewards := range this.extList {
|
|
var lastLevel = 0
|
|
sort.Slice(rewards, func(i, j int) bool {
|
|
return rewards[i].Level < rewards[j].Level
|
|
})
|
|
for _, reward := range rewards {
|
|
if reward.Level != lastLevel+1 {
|
|
return errors.Error("the levels of battle pass are not continuous, id: ", reward.Id)
|
|
}
|
|
lastLevel = reward.Level
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (this *BattlePassRewardTableExtend) List(seasonId int) []*BattlePassReward {
|
|
return this.extList[seasonId]
|
|
}
|
|
|
|
func (this *BattlePassRewardTableExtend) Get(seasonId int, level int) *BattlePassReward {
|
|
return this.extMap[util.Compose2uint32(uint32(seasonId), uint32(level))]
|
|
}
|