package herotask import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "sync" ) const ( game_fategiftfate = "game_fategiftfate.json" game_fategiftreward = "game_fategiftreward.json" ) type configureComp struct { modules.MCompConfigure module *HeroTask lock sync.RWMutex tasks map[int32]struct{} grouptask map[int32]map[int32][]int32 groupreward map[int32]map[int32]*cfg.GameFategiftrewardData } 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.(*HeroTask) configure.RegisterConfigure(game_fategiftfate, cfg.NewGameFategiftFate, this.updateconfigure) configure.RegisterConfigure(game_fategiftreward, cfg.NewGameFategiftreward, this.updateconfigurereward) return } func (this *configureComp) gettasks() map[int32]struct{} { this.lock.RLock() defer this.lock.RUnlock() return this.tasks } func (this *configureComp) getgrouptask(hero, stage int32) (conf []int32, err error) { this.lock.RLock() heros, ok := this.grouptask[hero] this.lock.RUnlock() if !ok { err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_fategiftfate, hero) return } tasks, ok := heros[stage] if !ok { err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_fategiftfate, hero) return } conf = tasks return } func (this *configureComp) getgroupreward(hero, stage int32) (conf *cfg.GameFategiftrewardData, err error) { this.lock.RLock() heros, ok := this.groupreward[hero] this.lock.RUnlock() if !ok { err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_fategiftfate, hero) return } tasks, ok := heros[stage] if !ok { err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_fategiftfate, hero) return } conf = tasks return } // 更新任务配置表 func (this *configureComp) updateconfigure() { var ( v interface{} conf *cfg.GameFategiftFate ok bool err error ) if v, err = this.GetConfigure(game_fategiftfate); err != nil { return } if conf, ok = v.(*cfg.GameFategiftFate); !ok { this.module.Error("日常任务配置异常!") return } tasks := make(map[int32]struct{}) grouptask := make(map[int32]map[int32][]int32) for _, v := range conf.GetDataList() { if _, ok := grouptask[v.Heroid]; !ok { grouptask[v.Heroid] = make(map[int32][]int32) } if _, ok := grouptask[v.Heroid][v.Herostage]; !ok { grouptask[v.Heroid][v.Herostage] = make([]int32, 0) } grouptask[v.Heroid][v.Herostage] = append(grouptask[v.Heroid][v.Herostage], v.Stagetask) tasks[v.Stagetask] = struct{}{} } this.lock.Lock() this.grouptask = grouptask this.tasks = tasks this.lock.Unlock() } // 更新任务配置表 func (this *configureComp) updateconfigurereward() { var ( v interface{} conf *cfg.GameFategiftreward ok bool err error ) if v, err = this.GetConfigure(game_fategiftreward); err != nil { return } if conf, ok = v.(*cfg.GameFategiftreward); !ok { this.module.Error("日常任务配置异常!") return } groupTasksConf := make(map[int32]map[int32]*cfg.GameFategiftrewardData) for _, v := range conf.GetDataList() { if _, ok := groupTasksConf[v.Heroid]; !ok { groupTasksConf[v.Heroid] = make(map[int32]*cfg.GameFategiftrewardData) } groupTasksConf[v.Heroid][v.Stageid] = v } this.lock.Lock() this.groupreward = groupTasksConf this.lock.Unlock() }