ecs/servers/game/data/upgrade_master.go
2025-06-14 18:49:31 +08:00

76 lines
1.8 KiB
Go

package data
import (
json "github.com/json-iterator/go"
"github.com/oylshe1314/framework/util"
)
type UpgradeMaster struct {
Id int `json:"id"`
Type int `json:"type"`
Level int `json:"level"`
NeedLevel int `json:"need_level"`
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"`
AttrType4 int `json:"attr_type4"`
AttrValue4 int `json:"attr_value4"`
AttrType5 int `json:"attr_type5"`
AttrValue5 int `json:"attr_value5"`
AttrType6 int `json:"attr_type6"`
AttrValue6 int `json:"attr_value6"`
}
type UpgradeMasterTable struct {
l []*UpgradeMaster
m1 map[int][]*UpgradeMaster
m2 map[uint64]*UpgradeMaster
}
func (this *UpgradeMasterTable) load(buf []byte) error {
var err = json.Unmarshal(buf, &this.l)
if err != nil {
return err
}
this.m1 = make(map[int][]*UpgradeMaster)
this.m2 = make(map[uint64]*UpgradeMaster)
for i := range this.l {
this.m1[this.l[i].Type] = append(this.m1[this.l[i].Type], this.l[i])
this.m2[util.Compose2uint32(uint32(this.l[i].Type), uint32(this.l[i].Level))] = this.l[i]
}
return nil
}
func (this *UpgradeMasterTable) List() []*UpgradeMaster {
return this.l
}
func (this *UpgradeMasterTable) Get(i int) *UpgradeMaster {
return this.l[i]
}
func (this *UpgradeMasterTable) Find1(tipe int) []*UpgradeMaster {
return this.m1[tipe]
}
func (this *UpgradeMasterTable) Find2(tipe, level int) *UpgradeMaster {
return this.m2[util.Compose2uint32(uint32(tipe), uint32(level))]
}
func (this *UpgradeMasterTable) FindMax(tipe, minLevel int) *UpgradeMaster {
var l = this.Find1(tipe)
var t *UpgradeMaster
for i := range l {
if l[i].NeedLevel >= minLevel {
break
}
t = l[i]
}
return t
}