59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
![]() |
package data
|
||
|
|
||
|
import (
|
||
|
"github.com/oylshe1314/framework/errors"
|
||
|
"github.com/oylshe1314/framework/util"
|
||
|
"sort"
|
||
|
)
|
||
|
|
||
|
func (this *CopyArenaRewardTable) check() error {
|
||
|
for _, d := range this.l {
|
||
|
if len(d.NumList) != len(d.ItemList) {
|
||
|
return errors.Error("incorrect 'CopySpeedReward' table, error: len(d.NumList) != len(d.ItemList), id: ", d.id())
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
type CopyArenaRewardTableExtend struct {
|
||
|
*CopyArenaRewardTable
|
||
|
|
||
|
extMap map[uint64][]*CopyArenaReward
|
||
|
}
|
||
|
|
||
|
func (this *CopyArenaRewardTableExtend) init() error {
|
||
|
if this.CopyArenaRewardTable == nil {
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
this.extMap = map[uint64][]*CopyArenaReward{}
|
||
|
for _, d := range this.CopyArenaRewardTable.l {
|
||
|
var key = util.Compose2uint32(uint32(d.CopyId), uint32(d.Type))
|
||
|
this.extMap[key] = append(this.extMap[key], d)
|
||
|
}
|
||
|
|
||
|
for _, rewards := range this.extMap {
|
||
|
sort.Slice(rewards, func(i, j int) bool {
|
||
|
return uint32(rewards[i].TypeArg) < uint32(rewards[j].TypeArg)
|
||
|
})
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (this *CopyArenaRewardTableExtend) Get(copyId, tipe int) []*CopyArenaReward {
|
||
|
return this.extMap[util.Compose2uint32(uint32(copyId), uint32(tipe))]
|
||
|
}
|
||
|
|
||
|
func (this *CopyArenaRewardTableExtend) CalcReward(copyId, tipe int, arg int) *CopyArenaReward {
|
||
|
var rewards = this.Get(copyId, tipe)
|
||
|
for _, reward := range rewards {
|
||
|
if reward.TypeArg < arg {
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
return reward
|
||
|
}
|
||
|
return nil
|
||
|
}
|