package sys import ( "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "sync" ) const ( gameOpencond = "game_opencond.json" ) type configureComp struct { modules.MCompConfigure module *ModuleSys lock sync.RWMutex condlTask map[int32][]*cfg.GameOpencondData cmds map[string]*cfg.GameOpencondData } 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.LoadConfigure(gameOpencond, cfg.NewGameOpencond) configure.RegisterConfigure(gameOpencond, cfg.NewGameOpencond, this.updateconfigure) this.module = module.(*ModuleSys) return } // 更新任务配置表 func (this *configureComp) updateconfigure() { gwt, err := this.getOpencondCfg() if err != nil { this.module.Error("世界任务配置表异常!") return } condlTask := make(map[int32][]*cfg.GameOpencondData) cmds := make(map[string]*cfg.GameOpencondData) for _, v := range gwt.GetDataList() { cmds[v.Id] = v for _, condi := range v.Opencondi { if _, ok := condlTask[condi]; !ok { condlTask[condi] = make([]*cfg.GameOpencondData, 0) } condlTask[condi] = append(condlTask[condi], v) } } this.lock.Lock() this.condlTask = condlTask this.cmds = cmds this.lock.Unlock() } func (this *configureComp) getOpencondCfg() (data *cfg.GameOpencond, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(gameOpencond); err == nil { if data, ok = v.(*cfg.GameOpencond); !ok { err = fmt.Errorf("%T no is *cfg.GameOpencond", v) return } } return } func (this *configureComp) GetOpenCondCfgById(id string) (data *cfg.GameOpencondData, err error) { var ( v interface{} ) if v, err = this.GetConfigure(gameOpencond); err == nil { if c, ok := v.(*cfg.GameOpencond); ok { if data = c.Get(id); data != nil { return } } } err = comm.NewNotFoundConfErr("opencond", gameOpencond, id) return } func (this *configureComp) getOpencondConf() (list []*cfg.GameOpencondData) { if cfg, err := this.getOpencondCfg(); err == nil { list = cfg.GetDataList() } return }