62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
package data
|
|
|
|
import (
|
|
json "github.com/json-iterator/go"
|
|
"github.com/oylshe1314/framework/util"
|
|
)
|
|
|
|
type Item struct {
|
|
Id int `json:"id"`
|
|
Name string `json:"name"`
|
|
Type int `json:"type"`
|
|
SubType int `json:"subType"`
|
|
Value int `json:"value"`
|
|
Quality int `json:"quality"`
|
|
StackLimit int `json:"stack_limit"`
|
|
SortBy int `json:"sort_by"`
|
|
UseMulti bool `json:"use_multi"`
|
|
SaleAllow bool `json:"sale_allow"`
|
|
UseAllow bool `json:"use_allow"`
|
|
UseDirect bool `json:"use_direct"`
|
|
UseConsume int `json:"use_consume"`
|
|
ConsumeNums int `json:"consume_nums"`
|
|
}
|
|
|
|
type ItemTable struct {
|
|
l []*Item
|
|
m1 map[int]*Item
|
|
m2 map[uint64][]*Item
|
|
}
|
|
|
|
func (this *ItemTable) load(buf []byte) error {
|
|
var err = json.Unmarshal(buf, &this.l)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
this.m1 = make(map[int]*Item)
|
|
this.m2 = make(map[uint64][]*Item)
|
|
for i := range this.l {
|
|
this.m1[this.l[i].Id] = this.l[i]
|
|
this.m2[util.Compose2uint32(uint32(this.l[i].Type), uint32(this.l[i].SubType))] = append(this.m2[util.Compose2uint32(uint32(this.l[i].Type), uint32(this.l[i].SubType))], this.l[i])
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (this *ItemTable) List() []*Item {
|
|
return this.l
|
|
}
|
|
|
|
func (this *ItemTable) Get(i int) *Item {
|
|
return this.l[i]
|
|
}
|
|
|
|
func (this *ItemTable) Find1(id int) *Item {
|
|
return this.m1[id]
|
|
}
|
|
|
|
func (this *ItemTable) Find2(tipe, subType int) []*Item {
|
|
return this.m2[util.Compose2uint32(uint32(tipe), uint32(subType))]
|
|
}
|