package mline import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "sync" ) const moduleName = "mline" const ( game_mainchapter = "game_mainchapter.json" game_mainstage = "game_mainstage.json" game_mainstarreward = "game_mainstarreward.json" ) ///配置管理基础组件 type configureComp struct { modules.MCompConfigure module *Mline hlock sync.RWMutex _mapMilne map[int32][]int32 // key 章节id value cid } //组件初始化接口 func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { err = this.MCompConfigure.Init(service, module, comp, options) this.module = module.(*Mline) err = this.LoadMultiConfigure(map[string]interface{}{ game_mainchapter: cfg.NewGameMainChapter, game_mainstage: cfg.NewGameMainStage, game_mainstarreward: cfg.NewGameMainStarreward, }) configure.RegisterConfigure(game_mainstage, cfg.NewGameMainStage, this.LoadMlineStage) return } //读取配置数据 func (this *configureComp) GetConfigure(name string) (v interface{}, err error) { return configure.GetConfigure(name) } func (this *configureComp) GetMainChapterConf(id int32) (data *cfg.GameMainChapterData) { if v, err := this.GetConfigure(game_mainchapter); err == nil { if configure, ok := v.(*cfg.GameMainChapter); ok { return configure.Get(id) } } this.module.Errorf("GameMainChapterData conf not found key :%d", id) return } func (this *configureComp) GetMainStarRewardConf(boxId int32) (data []*cfg.GameMainStarrewardData) { if v, err := this.GetConfigure(game_mainstarreward); err == nil { if configure, ok := v.(*cfg.GameMainStarreward); ok { for _, v1 := range configure.GetDataList() { if v1.Boxid == boxId { data = append(data, v1) } } } } return } func (this *configureComp) GetMainStageConf(id int32) (data *cfg.GameMainStageData, err error) { var ( v interface{} ) if v, err = this.GetConfigure(game_mainstage); err == nil { if configure, ok := v.(*cfg.GameMainStage); ok { data = configure.Get(id) if data != nil { return } } } err = comm.NewNotFoundConfErr(moduleName, game_mainstage, id) return } // 获取上一关卡信息 func (this *configureComp) GetPreMainChapter(stageId int32) (preStageID int32) { if v, err := this.GetConfigure(game_mainstage); err == nil { if configure, ok := v.(*cfg.GameMainStage); ok { for _, v1 := range configure.GetDataList() { if v1.Previoustage == stageId { preStageID = v1.Id break } } } } return } func (this *configureComp) GetFirstChapterIDByType(iType int32) (conf *cfg.GameMainChapterData, err error) { var ( v interface{} ) if v, err = this.GetConfigure(game_mainchapter); err == nil { if configure, ok := v.(*cfg.GameMainChapter); ok { for _, conf = range configure.GetDataList() { if conf.ChapterType == iType { return } } } } err = comm.NewNotFoundConfErr(moduleName, game_mainchapter, iType) return } func (this *configureComp) GetFirstStageIDByChapter(chapterID int32) *cfg.GameMainStageData { if v, err := this.GetConfigure(game_mainstage); err == nil { if configure, ok := v.(*cfg.GameMainStage); ok { for _, v := range configure.GetDataList() { if v.Chapterid == chapterID { return v } } } } return nil } // 红点用 获取所有章节数据 func (this *configureComp) GetAllChapterID() (chapter []int32) { if v, err := this.GetConfigure(game_mainchapter); err == nil { if configure, ok := v.(*cfg.GameMainChapter); ok { for _, v1 := range configure.GetDataList() { chapter = append(chapter, v1.Id) } } } return } func (this *configureComp) GetAllStageByChapterID(chapterID int32) (stage []int32) { return this._mapMilne[chapterID] } func (this *configureComp) LoadMlineStage() { if v, err := this.GetConfigure(game_mainstage); err == nil { if configure, ok := v.(*cfg.GameMainStage); ok { this.hlock.Lock() defer this.hlock.Unlock() this._mapMilne = make(map[int32][]int32) for _, v1 := range configure.GetDataList() { this._mapMilne[v1.Chapterid] = append(this._mapMilne[v1.Chapterid], v1.Id) } } } return } // GM 专用 获取这个章节之前的所有章节信息 func (this *configureComp) GMGetPreStage(chapterID int32) (chapter []int32) { curChapter := this.GetMainChapterConf(chapterID) if curChapter == nil { return } if v, err := this.GetConfigure(game_mainchapter); err == nil { if configure, ok := v.(*cfg.GameMainChapter); ok { for _, conf := range configure.GetDataList() { //if conf.ChapterType == curChapter.ChapterType { if chapterID == conf.Id { break } chapter = append(chapter, conf.Id) //} } } } return }