package data import ( json "github.com/json-iterator/go" "github.com/oylshe1314/framework/util" ) type HeroLevel struct { Id int `json:"id"` HeroId int `json:"hero_id"` Level int `json:"level"` NeedExp int `json:"need_exp"` AttrType1 int `json:"attr_type1"` AttrValue1 int `json:"attr_value1"` AttrType2 int `json:"attr_type2"` AttrValue2 int `json:"attr_value2"` AttrType3 int `json:"attr_type3"` AttrValue3 int `json:"attr_value3"` AttrType4 int `json:"attr_type4"` AttrValue4 int `json:"attr_value4"` AttrType5 int `json:"attr_type5"` AttrValue5 int `json:"attr_value5"` AttrType6 int `json:"attr_type6"` AttrValue6 int `json:"attr_value6"` AttrType7 int `json:"attr_type7"` AttrValue7 int `json:"attr_value7"` AttrType8 int `json:"attr_type8"` AttrValue8 int `json:"attr_value8"` AttrType9 int `json:"attr_type9"` AttrValue9 int `json:"attr_value9"` AttrType10 int `json:"attr_type10"` AttrValue10 int `json:"attr_value10"` } type HeroLevelTable struct { l []*HeroLevel m1 map[int]*HeroLevel m2 map[int][]*HeroLevel m3 map[uint64]*HeroLevel } func (this *HeroLevelTable) load(buf []byte) error { var err = json.Unmarshal(buf, &this.l) if err != nil { return err } this.m1 = make(map[int]*HeroLevel) this.m2 = make(map[int][]*HeroLevel) this.m3 = make(map[uint64]*HeroLevel) 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 *HeroLevelTable) List() []*HeroLevel { return this.l } func (this *HeroLevelTable) Get(i int) *HeroLevel { return this.l[i] } func (this *HeroLevelTable) Find1(id int) *HeroLevel { return this.m1[id] } func (this *HeroLevelTable) Find2(heroId int) []*HeroLevel { return this.m2[heroId] } func (this *HeroLevelTable) Find3(heroId, level int) *HeroLevel { return this.m3[util.Compose2uint32(uint32(heroId), uint32(level))] }