68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
package data
|
|
|
|
import (
|
|
json "github.com/json-iterator/go"
|
|
"github.com/oylshe1314/framework/util"
|
|
)
|
|
|
|
type HeroSoul struct {
|
|
Id int `json:"id"`
|
|
HeroId int `json:"hero_id"`
|
|
Level int `json:"level"`
|
|
ConsumeLeft int `json:"consume_left"`
|
|
ConsumeLeftFirst int `json:"consume_left_first"`
|
|
ConsumeLeftNum int `json:"consume_left_num"`
|
|
ConsumeMiddle int `json:"consume_middle"`
|
|
ConsumeMiddleNum int `json:"consume_middle_num"`
|
|
ConsumeRight int `json:"consume_right"`
|
|
ConsumeRightFirst int `json:"consume_right_first"`
|
|
ConsumeRightNum int `json:"consume_right_num"`
|
|
SoulSkillLeft int `json:"soul_skill_left"`
|
|
SoulSkillRight int `json:"soul_skill_right"`
|
|
}
|
|
|
|
type HeroSoulTable struct {
|
|
l []*HeroSoul
|
|
m1 map[int]*HeroSoul
|
|
m2 map[int][]*HeroSoul
|
|
m3 map[uint64]*HeroSoul
|
|
}
|
|
|
|
func (this *HeroSoulTable) load(buf []byte) error {
|
|
var err = json.Unmarshal(buf, &this.l)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
this.m1 = make(map[int]*HeroSoul)
|
|
this.m2 = make(map[int][]*HeroSoul)
|
|
this.m3 = make(map[uint64]*HeroSoul)
|
|
for i := range this.l {
|
|
this.m1[this.l[i].Id] = this.l[i]
|
|
this.m2[this.l[i].HeroId] = append(this.m2[this.l[i].HeroId], this.l[i])
|
|
this.m3[util.Compose2uint32(uint32(this.l[i].HeroId), uint32(this.l[i].Level))] = this.l[i]
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (this *HeroSoulTable) List() []*HeroSoul {
|
|
return this.l
|
|
}
|
|
|
|
//func (this *HeroSoulTable) Get(i int) *HeroSoul {
|
|
// return this.l[i]
|
|
//}
|
|
|
|
func (this *HeroSoulTable) Find1(id int) *HeroSoul {
|
|
return this.m1[id]
|
|
}
|
|
|
|
func (this *HeroSoulTable) Find2(heroId int) []*HeroSoul {
|
|
return this.m2[heroId]
|
|
}
|
|
|
|
func (this *HeroSoulTable) Find3(heroId, level int) *HeroSoul {
|
|
return this.m3[util.Compose2uint32(uint32(heroId), uint32(level))]
|
|
}
|