package monkey import ( "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "sync" ) const ( monkey_main = "game_monkeymain.json" monkey_reward = "game_monkeyreward.json" ) type configureComp struct { modules.MCompConfigure module *Monkey hlock sync.RWMutex reward map[int32][]*cfg.GameMonkeyRewardData } 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.LoadConfigure(monkey_main, cfg.NewGameMonkeyMain) configure.RegisterConfigure(monkey_reward, cfg.NewGameGameFast, func() { if v, err := this.GetConfigure(monkey_reward); err == nil { this.hlock.Lock() defer this.hlock.Unlock() this.reward = make(map[int32][]*cfg.GameMonkeyRewardData) if _configure, ok := v.(*cfg.GameMonkeyReward); ok { for _, v := range _configure.GetDataList() { this.reward[v.Chapter] = append(this.reward[v.Chapter], v) } return } } else { err = fmt.Errorf("%T no is *cfg.GameMonkeyReward", v) } }) return } // 通过章节id 获取信息 func (this *configureComp) getGameMonkeyData(id int32) (result *cfg.GameMonkeyMainData, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(monkey_main); err == nil { if result, ok = v.(*cfg.GameMonkeyMain).GetDataMap()[id]; ok { return } } err = comm.NewNotFoundConfErr(string(this.module.GetType()), monkey_main, id) return } // 获取章节对应的奖励 func (this *configureComp) getGameMonkeyRewardData(chapterid int32) (result []*cfg.GameMonkeyRewardData, err error) { var ( ok bool ) this.hlock.Lock() result, ok = this.reward[chapterid] this.hlock.Unlock() if !ok { err = comm.NewNotFoundConfErr(string(this.module.GetType()), monkey_reward, chapterid) } return }