ecs/servers/game/data/reward_login.go

70 lines
1.6 KiB
Go
Raw Normal View History

2025-06-21 16:17:24 +08:00
package data
import (
json "github.com/json-iterator/go"
"github.com/oylshe1314/framework/util"
)
type RewardLogin struct {
Id int `json:"id"`
SeriesId int `json:"series_id"`
Days int `json:"days"`
DaysModule int `json:"days_module"`
ItemIds []interface{} `json:"item_ids"`
ItemNums []interface{} `json:"item_nums"`
VipLevel int `json:"vip_level"`
VipMultiple int `json:"vip_multiple"`
}
type RewardLoginTable struct {
l []*RewardLogin
m1 map[int]*RewardLogin
m2 map[int][]*RewardLogin
m3 map[int]int
}
func (this *RewardLoginTable) load(buf []byte) error {
var err = json.Unmarshal(buf, &this.l)
if err != nil {
return err
}
this.m1 = make(map[int]*RewardLogin)
this.m2 = make(map[int][]*RewardLogin)
this.m3 = make(map[int]int)
for i := range this.l {
this.m1[this.l[i].Id] = this.l[i]
this.m2[this.l[i].SeriesId] = append(this.m2[this.l[i].Id], this.l[i])
if this.l[i].Days > this.m3[this.l[i].SeriesId] {
this.m3[this.l[i].SeriesId] = this.l[i].Days
}
}
return nil
}
func (this *RewardLoginTable) List() []*RewardLogin {
return this.l
}
//func (this *RewardLoginTable) Get(i int) *RewardLogin {
// return this.l[i]
//}
func (this *RewardLoginTable) Find1(id int) *RewardLogin {
return this.m1[id]
}
func (this *RewardLoginTable) Find2(seriesId int) []*RewardLogin {
return this.m2[seriesId]
}
func (this *RewardLoginTable) SeriesIds() []int {
return util.MapKeys(this.m3)
}
func (this *RewardLoginTable) MaxDays(seriesId int) (days int, ok bool) {
days, ok = this.m3[seriesId]
return
}