ecs/servers/game/data_old/skill_ext.go

43 lines
914 B
Go
Raw Normal View History

2025-06-04 18:17:39 +08:00
package data
import (
"github.com/oylshe1314/framework/util"
"sort"
)
type SkillTableExtend struct {
*SkillTable
extMap1 map[int][]*Skill
extMap2 map[uint64]*Skill
}
func (this *SkillTableExtend) init() error {
if this.SkillTable == nil {
return nil
}
this.extMap1 = map[int][]*Skill{}
this.extMap2 = map[uint64]*Skill{}
for _, d := range this.l {
this.extMap1[d.SkillId] = append(this.extMap1[d.SkillId], d)
this.extMap2[util.Compose2uint32(uint32(d.SkillId), uint32(d.SkillLevel))] = d
}
for _, levels := range this.extMap1 {
sort.Slice(levels, func(i, j int) bool {
return levels[i].SkillLevel < levels[j].SkillLevel
})
}
return nil
}
func (this *SkillTableExtend) List(skillId int) []*Skill {
return this.extMap1[skillId]
}
func (this *SkillTableExtend) Get(skillId, skillLevel int) *Skill {
return this.extMap2[util.Compose2uint32(uint32(skillId), uint32(skillLevel))]
}