ecs/servers/game/data/treasure.go

57 lines
1.2 KiB
Go

package data
import json "github.com/json-iterator/go"
type Treasure struct {
Id int `json:"id"`
ItemId int `json:"item_id"`
Quality int `json:"quality"`
Type int `json:"type"`
Levels int `json:"levels"`
RefineLevel int `json:"refine_level"`
Holes1 int `json:"holes1"`
OpenedHoles1 int `json:"opened_holes1"`
Holes2 int `json:"holes2"`
OpenedHoles2 int `json:"opened_holes2"`
UnlockArgs1 []int `json:"unlock_args1"`
UnlockArgs2 []int `json:"unlock_args2"`
}
type TreasureTable struct {
l []*Treasure
m1 map[int]*Treasure
m2 map[int]*Treasure
}
func (this *TreasureTable) load(buf []byte) error {
var err = json.Unmarshal(buf, &this.l)
if err != nil {
return err
}
this.m1 = make(map[int]*Treasure)
this.m2 = make(map[int]*Treasure)
for i := range this.l {
this.m1[this.l[i].Id] = this.l[i]
this.m2[this.l[i].ItemId] = this.l[i]
}
return nil
}
func (this *TreasureTable) List() []*Treasure {
return this.l
}
//func (this *TreasureTable) Get(i int) *Treasure {
// return this.l[i]
//}
func (this *TreasureTable) Find1(id int) *Treasure {
return this.m1[id]
}
func (this *TreasureTable) Find2(itemId int) *Treasure {
return this.m2[itemId]
}