package mainline import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "sync" ) const ( game_mainchapter = "game_mainchapter.json" game_mainstage = "game_mainstage.json" game_mainstarreward = "game_mainstarreward.json" game_mainshopitem = "game_mainshopitem.json" game_mainachievement = "game_mainachievement.json" game_mainboos = "game_mainboss.json" ) // /配置管理基础组件 type configureComp struct { modules.MCompConfigure module *Mainline lock sync.RWMutex chapterMap map[int32][]*cfg.GameMainStageData rewardMap map[int32][]*cfg.GameMainStarrewardData tasks map[int32]struct{} groupTasks map[int32][]*cfg.GameMainAchievementData //key 条件ID // 章节解锁 ctasks map[int32]struct{} } // 组件初始化接口 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.(*Mainline) err = this.LoadMultiConfigure(map[string]interface{}{ game_mainchapter: cfg.NewGameMainChapter, game_mainshopitem: cfg.NewGameMainShopItem, game_mainboos: cfg.NewGameMainBoss, }) this.chapterMap = make(map[int32][]*cfg.GameMainStageData) configure.RegisterConfigure(game_mainstage, cfg.NewGameMainStage, this.updateMlineStage) configure.RegisterConfigure(game_mainstarreward, cfg.NewGameMainStarreward, this.updateMlineReward) configure.RegisterConfigure(game_mainachievement, cfg.NewGameMainAchievement, this.GameMainAchievement) configure.RegisterConfigure(game_mainchapter, cfg.NewGameMainChapter, this.updateGameMainChapter) return } func (this *configureComp) getchapterMap() map[int32][]*cfg.GameMainStageData { this.lock.Lock() chapterMap := this.chapterMap this.lock.Unlock() return chapterMap } func (this *configureComp) getrewardMap() map[int32][]*cfg.GameMainStarrewardData { this.lock.Lock() rewardMap := this.rewardMap this.lock.Unlock() return rewardMap } func (this *configureComp) updateMlineStage() { var ( v interface{} configure *cfg.GameMainStage chapterMap map[int32][]*cfg.GameMainStageData err error ok bool ) if v, err = this.GetConfigure(game_mainstage); err != nil { this.module.Errorln(err) return } if configure, ok = v.(*cfg.GameMainStage); ok { chapterMap = make(map[int32][]*cfg.GameMainStageData) for _, v := range configure.GetDataList() { if _, ok = chapterMap[v.Chapterid]; !ok { chapterMap[v.Chapterid] = make([]*cfg.GameMainStageData, 0) } chapterMap[v.Chapterid] = append(chapterMap[v.Chapterid], v) } } this.lock.Lock() this.chapterMap = chapterMap this.lock.Unlock() return } func (this *configureComp) updateMlineReward() { var ( v interface{} configure *cfg.GameMainStarreward rewardMap map[int32][]*cfg.GameMainStarrewardData err error ok bool ) if v, err = this.GetConfigure(game_mainstarreward); err != nil { this.module.Errorln(err) return } if configure, ok = v.(*cfg.GameMainStarreward); ok { rewardMap = make(map[int32][]*cfg.GameMainStarrewardData) for _, v := range configure.GetDataList() { if _, ok = rewardMap[v.Boxid]; !ok { rewardMap[v.Boxid] = make([]*cfg.GameMainStarrewardData, 0) } rewardMap[v.Boxid] = append(rewardMap[v.Boxid], v) } } this.lock.Lock() this.rewardMap = rewardMap this.lock.Unlock() return } func (this *configureComp) GetMainChapterConf(id int32) (conf *cfg.GameMainChapterData, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(game_mainchapter); err != nil { this.module.Errorln(err) return } if conf, ok = v.(*cfg.GameMainChapter).GetDataMap()[id]; !ok { err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_mainchapter, id) } return } func (this *configureComp) GetMainStageConfs() (data []*cfg.GameMainStageData, err error) { var ( v interface{} ) if v, err = this.GetConfigure(game_mainstage); err != nil { this.module.Errorln(err) return } data = v.(*cfg.GameMainStage).GetDataList() 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(string(this.module.GetType()), game_mainstage, id) return } func (this *configureComp) GetAllShopConf() (sz []*cfg.GameMainShopItemData) { if v, err := this.GetConfigure(game_mainshopitem); err == nil { if configure, ok := v.(*cfg.GameMainShopItem); ok { for _, v := range configure.GetDataList() { if v.Unlock != 0 { sz = append(sz, v) } } } } return } func (this *configureComp) GetMlineShopConfById(cid int32) (conf *cfg.GameMainShopItemData, err error) { var ( v interface{} ) if v, err = this.GetConfigure(game_mainshopitem); err == nil { if configure, ok := v.(*cfg.GameMainShopItem); ok { if conf = configure.Get(cid); conf != nil { return } } } err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_mainstage, cid) return } // 更新任务配置表 func (this *configureComp) GameMainAchievement() { var ( v interface{} conf *cfg.GameMainAchievement ok bool err error ) if v, err = this.GetConfigure(game_mainachievement); err != nil { return } if conf, ok = v.(*cfg.GameMainAchievement); !ok { this.module.Error("日常任务配置异常!") return } tasks := make(map[int32]struct{}) groupTasksConf := make(map[int32][]*cfg.GameMainAchievementData) for _, v := range conf.GetDataList() { if _, ok := groupTasksConf[v.Id]; !ok { groupTasksConf[v.Id] = make([]*cfg.GameMainAchievementData, 0) } groupTasksConf[v.Id] = append(groupTasksConf[v.Id], v) tasks[v.Taskid] = struct{}{} } this.lock.Lock() this.groupTasks = groupTasksConf this.tasks = tasks this.lock.Unlock() } func (this *configureComp) gettasks() map[int32]struct{} { this.lock.RLock() defer this.lock.RUnlock() return this.tasks } func (this *configureComp) getgroupTasks(gropp int32) []*cfg.GameMainAchievementData { this.lock.RLock() defer this.lock.RUnlock() return this.groupTasks[gropp] } // 获取主线章节任务 func (this *configureComp) getMainAchievementTask(id int32) (conf *cfg.GameMainAchievementData, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(game_mainachievement); err != nil { return } if conf, ok = v.(*cfg.GameMainAchievement).GetDataMap()[id]; !ok { err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_mainachievement, id) this.module.Errorln(err) return } return } func (this *configureComp) getChapteTasks() map[int32]struct{} { this.lock.RLock() defer this.lock.RUnlock() return this.ctasks } func (this *configureComp) updateGameMainChapter() { var ( v interface{} err error ) if v, err = this.GetConfigure(game_mainchapter); err != nil { this.module.Errorln(err) return } rewardMap := make(map[int32]struct{}) if configure, ok := v.(*cfg.GameMainChapter); ok { for _, v := range configure.GetDataList() { if v.Achunlock != 0 { if _, ok = rewardMap[v.Achunlock]; !ok { rewardMap[v.Achunlock] = struct{}{} } } // if v.Shopunlock != 0 { // if _, ok = rewardMap[v.Shopunlock]; !ok { // rewardMap[v.Achunlock] = struct{}{} // } // } } } this.lock.Lock() this.ctasks = rewardMap this.lock.Unlock() return } // 获取主线boos func (this *configureComp) getGameMainBossData(id int32) (conf *cfg.GameMainBossData, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(game_mainboos); err != nil { return } if conf, ok = v.(*cfg.GameMainBoss).GetDataMap()[id]; !ok { err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_mainboos, id) this.module.Errorln(err) return } return } func (this *configureComp) getGroupGameMainStageData(chapter, groupid int32) (confs []*cfg.GameMainStageData, err error) { this.lock.Lock() chapterMap := this.chapterMap this.lock.Unlock() if chapter, ok := chapterMap[chapter]; ok { for _, v := range chapter { if v.GroupId == groupid { confs = append(confs, v) } } } if confs == nil { err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_mainstage, groupid) this.module.Errorln(err) return } return }