package worldtask import ( "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "sync" ) const ( gameWorldTask = "game_worldtask.json" gameWorldtaskBattle = "game_worldbattle.json" gameWorldAll = "game_worldall.json" gameburiedCond = "game_buriedcondi.json" gamerdtasknpc = "game_rdtasknpc.json" ) type configureComp struct { modules.MCompConfigure lock sync.RWMutex worldtaskConf map[int32]*cfg.GameWorldTaskData //key 条件ID } 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) err = this.LoadMultiConfigure(map[string]interface{}{ gameWorldTask: cfg.NewGameWorldTask, gameWorldtaskBattle: cfg.NewGameWorldBattle, gameWorldAll: cfg.NewGameWorldAll, gameburiedCond: cfg.NewGameBuriedCondi, gamerdtasknpc: cfg.NewGameRdtaskNpc, }) this.worldtaskConf = make(map[int32]*cfg.GameWorldTaskData) configure.RegisterConfigure(gameWorldTask, cfg.NewGameBuriedCondi, this.updateconfigure) return } func (this *configureComp) getWorldtaskCfg() (data *cfg.GameWorldTask, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(gameWorldTask); err != nil { return } else { if data, ok = v.(*cfg.GameWorldTask); !ok { err = fmt.Errorf("%T is *cfg.GameWorldTask", v) return } } return } func (this *configureComp) updateconfigure() { gwt, err := this.getWorldtaskCfg() if err != nil { return } this.lock.Lock() this.worldtaskConf = gwt.GetDataMap() this.lock.Unlock() } func (this *configureComp) getWorldAllCfg() (data *cfg.GameWorldAll, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(gameWorldAll); err != nil { return } else { if data, ok = v.(*cfg.GameWorldAll); !ok { err = fmt.Errorf("%T is *cfg.GameWorldAll", v) return } } return } func (this *configureComp) getWorldtaskById(taskId int32) (*cfg.GameWorldTaskData, error) { gwt, err := this.getWorldtaskCfg() if err != nil { return nil, err } if data, ok := gwt.GetDataMap()[taskId]; ok { return data, nil } return nil, comm.NewNotFoundConfErr(moduleName_cn, gameWorldTask, taskId) } func (this *configureComp) getNPCById(npcId int32) (npc *cfg.GameRdtaskNpcData, err error) { var ( v interface{} ) if v, err = this.GetConfigure(gamerdtasknpc); err != nil { return } else { data, ok := v.(*cfg.GameRdtaskNpc) if !ok { err = fmt.Errorf("%T is *cfg.GameRdtaskNpc", v) return } if npc, ok = data.GetDataMap()[npcId]; ok { return } err = comm.NewNotFoundConfErr(moduleName_cn, gamerdtasknpc, npc) } return } func (this *configureComp) getWorldtaskBattleCfg() (data *cfg.GameWorldBattle, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(gameWorldtaskBattle); err != nil { return } else { if data, ok = v.(*cfg.GameWorldBattle); !ok { err = fmt.Errorf("%T is *cfg.GameWorldBattle", v) return } } return } func (this *configureComp) getWorldtaskBattleById(confId int32) (*cfg.GameWorldBattleData, error) { gwt, err := this.getWorldtaskBattleCfg() if err != nil { return nil, err } if data, ok := gwt.GetDataMap()[confId]; ok { return data, nil } return nil, fmt.Errorf("GameWorldBattleData config id:%v not found", confId) } func (this *configureComp) getBuriedCondCfg() (data *cfg.GameBuriedCondi, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(gameburiedCond); err != nil { return } else { if data, ok = v.(*cfg.GameBuriedCondi); !ok { err = fmt.Errorf("%T is *cfg.GameWorldAll", v) return } } return }