61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package data
|
|
|
|
import (
|
|
json "github.com/json-iterator/go"
|
|
"github.com/oylshe1314/framework/util"
|
|
)
|
|
|
|
type TreasureLevel struct {
|
|
Id int `json:"id"`
|
|
TreasureId int `json:"treasure_id"`
|
|
Level int `json:"level"`
|
|
NeedExp int `json:"need_exp"`
|
|
AttrType int `json:"attr_type"`
|
|
AttrValue int `json:"attr_value"`
|
|
}
|
|
|
|
type TreasureLevelTable struct {
|
|
l []*TreasureLevel
|
|
m1 map[int]*TreasureLevel
|
|
m2 map[int][]*TreasureLevel
|
|
m3 map[uint64]*TreasureLevel
|
|
}
|
|
|
|
func (this *TreasureLevelTable) load(buf []byte) error {
|
|
var err = json.Unmarshal(buf, &this.l)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
this.m1 = make(map[int]*TreasureLevel)
|
|
this.m2 = make(map[int][]*TreasureLevel)
|
|
this.m3 = make(map[uint64]*TreasureLevel)
|
|
for i := range this.l {
|
|
this.m1[this.l[i].Id] = this.l[i]
|
|
this.m2[this.l[i].TreasureId] = append(this.m2[this.l[i].TreasureId], this.l[i])
|
|
this.m3[util.Compose2uint32(uint32(this.l[i].TreasureId), uint32(this.l[i].Level))] = this.l[i]
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (this *TreasureLevelTable) List() []*TreasureLevel {
|
|
return this.l
|
|
}
|
|
|
|
//func (this *TreasureLevelTable) Get(i int) *TreasureLevel {
|
|
// return this.l[i]
|
|
//}
|
|
|
|
func (this *TreasureLevelTable) Find1(id int) *TreasureLevel {
|
|
return this.m1[id]
|
|
}
|
|
|
|
func (this *TreasureLevelTable) Find2(treasureId int) []*TreasureLevel {
|
|
return this.m2[treasureId]
|
|
}
|
|
|
|
func (this *TreasureLevelTable) Find3(treasureId, level int) *TreasureLevel {
|
|
return this.m3[util.Compose2uint32(uint32(treasureId), uint32(level))]
|
|
}
|