2024-12-10 11:20:04 +08:00

72 lines
1.3 KiB
Go

package mt
import (
"f5"
"main/mtb"
"q5"
"strings"
)
type MapGridRewardItem struct {
ItemId int32
ItemNum int32
}
type MapGrid struct {
mtb.MapGrid
rewardItems []*MapGridRewardItem
}
type MapGridTable struct {
f5.IdMetaTable[MapGrid]
awardGrids []*MapGrid
maxGridId int32
}
func (this *MapGrid) Init1() {
if this.MapGrid.GetReward() == "" {
return
}
tmpStrs := strings.Split(this.MapGrid.GetReward(), "|")
for _, tmpStr := range tmpStrs {
tmpStrs2 := strings.Split(tmpStr, ":")
if len(tmpStrs2) > 1 {
p := new(MapGridRewardItem)
p.ItemId = q5.ToInt32(tmpStrs2[0])
p.ItemNum = q5.ToInt32(tmpStrs2[1])
q5.AppendSlice(&this.rewardItems, p)
}
}
}
func (this *MapGrid) GetRewardItems() *[]*MapGridRewardItem {
return &this.rewardItems
}
func (this *MapGridTable) PostInit1() {
this.Traverse(func(gridMeta *MapGrid) bool {
if gridMeta.GetId() > this.maxGridId {
this.maxGridId = gridMeta.GetId()
}
if len(gridMeta.rewardItems) > 0 {
this.awardGrids = append(this.awardGrids, gridMeta)
}
return true
})
}
func (this *MapGridTable) GetMaxGridId() int32 {
return this.maxGridId
}
func (this *MapGridTable) GetAwardGridIdList() []int32 {
idlist := []int32{}
for _, item := range this.awardGrids {
if item.GetId() > 0 {
idlist = append(idlist, item.GetId())
}
}
return idlist
}