ecs/servers/game/data_old/copy_chapter_ext.go
2025-06-04 18:17:39 +08:00

57 lines
1.3 KiB
Go

package data
import (
"github.com/oylshe1314/framework/errors"
"sort"
)
func (this *CopyChapterTable) check() error {
for _, d := range this.l {
if len(d.UnlockArg) != len(d.UnlockType) {
return errors.Error("incorrect 'CopyChapter' table, error: len(d.UnlockArg) != len(d.UnlockType), id: ", d.id())
}
}
return nil
}
type CopyChapterTableExtend struct {
*CopyChapterTable
extMap1 map[int]*CopyChapter
extMap2 map[int][]*CopyChapter
}
func (this *CopyChapterTableExtend) init() error {
if this.CopyChapterTable == nil {
return nil
}
this.extMap1 = map[int]*CopyChapter{}
this.extMap2 = map[int][]*CopyChapter{}
for _, d := range this.CopyChapterTable.l {
this.extMap1[d.SceneId] = d
this.extMap2[d.ChapterId] = append(this.extMap2[d.ChapterId], d)
}
for _, chapters := range this.extMap2 {
sort.Slice(chapters, func(i, j int) bool {
return chapters[i].SectionId < chapters[j].SectionId
})
}
return nil
}
func (this *CopyChapterTableExtend) Get(sceneId int) *CopyChapter {
return this.extMap1[sceneId]
}
func (this *CopyChapterTableExtend) List(chapterId int) []*CopyChapter {
return this.extMap2[chapterId]
}
func (this *CopyChapterTableExtend) GetFirstBattle() *CopyChapter {
if this.CopyChapterTable == nil || len(this.CopyChapterTable.l) == 0 {
return nil
}
return this.l[0]
}