ecs/servers/game/data/hero_book.go

46 lines
1.0 KiB
Go
Raw Normal View History

2025-06-04 18:17:39 +08:00
package data
import json "github.com/json-iterator/go"
2025-06-05 17:48:23 +08:00
type HeroBook struct {
2025-06-04 18:17:39 +08:00
Id int `json:"id"`
HeroId int `json:"hero_id"`
NeedHeroes []int `json:"need_heroes"`
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"`
}
2025-06-05 17:48:23 +08:00
type HeroBookTable struct {
l []*HeroBook
m1 map[int]*HeroBook
m2 map[int][]*HeroBook
2025-06-04 18:17:39 +08:00
}
2025-06-05 17:48:23 +08:00
func (this *HeroBookTable) load(buf []byte) error {
2025-06-04 18:17:39 +08:00
var err = json.Unmarshal(buf, &this.l)
if err != nil {
return err
}
2025-06-05 17:48:23 +08:00
this.m1 = make(map[int]*HeroBook)
this.m2 = make(map[int][]*HeroBook)
2025-06-04 18:17:39 +08:00
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])
}
return nil
}
2025-06-05 17:48:23 +08:00
func (this *HeroBookTable) Find1(id int) *HeroBook {
return this.m1[id]
2025-06-04 18:17:39 +08:00
}
2025-06-05 17:48:23 +08:00
func (this *HeroBookTable) Find2(heroId int) []*HeroBook {
2025-06-04 18:17:39 +08:00
return this.m2[heroId]
}