ecs/servers/game/data_old/copy_speed_reward_ext.go
2025-06-04 18:17:39 +08:00

59 lines
1.3 KiB
Go

package data
import (
"github.com/oylshe1314/framework/errors"
"github.com/oylshe1314/framework/util"
"sort"
)
func (this *CopySpeedRewardTable) 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 CopySpeedRewardTableExtend struct {
*CopySpeedRewardTable
extMap map[uint64][]*CopySpeedReward
}
func (this *CopySpeedRewardTableExtend) init() error {
if this.CopySpeedRewardTable == nil {
return nil
}
this.extMap = map[uint64][]*CopySpeedReward{}
for _, d := range this.CopySpeedRewardTable.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 *CopySpeedRewardTableExtend) Get(copyId, tipe int) []*CopySpeedReward {
return this.extMap[util.Compose2uint32(uint32(copyId), uint32(tipe))]
}
func (this *CopySpeedRewardTableExtend) CalcReward(copyId, tipe int, arg int) *CopySpeedReward {
var rewards = this.Get(copyId, tipe)
for _, reward := range rewards {
if reward.TypeArg < arg {
continue
}
return reward
}
return nil
}