ecs/servers/game/data/equip_level.go

62 lines
1.5 KiB
Go

package data
import (
json "github.com/json-iterator/go"
"github.com/oylshe1314/framework/util"
)
type EquipLevel struct {
Id int `json:"id"`
EquipId int `json:"Equip_id"`
Level int `json:"level"`
ConsumeItems []int `json:"consume_items"`
ConsumeNums []int `json:"consume_nums"`
AttrType int `json:"attr_type"`
AttrValue int `json:"attr_value"`
}
type EquipLevelTable struct {
l []*EquipLevel
m1 map[int]*EquipLevel
m2 map[int][]*EquipLevel
m3 map[uint64]*EquipLevel
}
func (this *EquipLevelTable) load(buf []byte) error {
var err = json.Unmarshal(buf, &this.l)
if err != nil {
return err
}
this.m1 = make(map[int]*EquipLevel)
this.m2 = make(map[int][]*EquipLevel)
this.m3 = make(map[uint64]*EquipLevel)
for i := range this.l {
this.m1[this.l[i].Id] = this.l[i]
this.m2[this.l[i].EquipId] = append(this.m2[this.l[i].EquipId], this.l[i])
this.m3[util.Compose2uint32(uint32(this.l[i].EquipId), uint32(this.l[i].Level))] = this.l[i]
}
return nil
}
func (this *EquipLevelTable) List() []*EquipLevel {
return this.l
}
//func (this *EquipLevelTable) Get(i int) *EquipLevel {
// return this.l[i]
//}
func (this *EquipLevelTable) Find1(id int) *EquipLevel {
return this.m1[id]
}
func (this *EquipLevelTable) Find2(equipId int) []*EquipLevel {
return this.m2[equipId]
}
func (this *EquipLevelTable) Find3(equipId, level int) *EquipLevel {
return this.m3[util.Compose2uint32(uint32(equipId), uint32(level))]
}