package practice import ( "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "sync" ) const ( game_pandamasmz = "game_pandamasmz.json" pandamas_js = "pandamas_js.json" game_pandamasjs = "game_pandamasjs.json" game_pandamasjx = "game_pandamasjx.json" game_pandamasyxjx = "game_pandamasyxjx.json" game_pandamasmryl = "game_pandamasmryl.json" game_pandamasbuff = "game_pandamasbuff.json" ) ///背包配置管理组件 type configureComp struct { modules.MCompConfigure module *Practice lock sync.RWMutex buffs map[int32][]*cfg.GamePandamasBuffData } //组件初始化接口 func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { this.MCompConfigure.Init(service, module, comp, options) this.module = module.(*Practice) this.LoadConfigure(game_pandamasmz, cfg.NewGamePandamasMz) this.LoadConfigure(pandamas_js, cfg.NewGamePandamasJs) this.LoadConfigure(game_pandamasjs, cfg.NewGamePandamasJs) this.LoadConfigure(game_pandamasjx, cfg.NewGamePandamasJx) this.LoadConfigure(game_pandamasyxjx, cfg.NewGamePandamasYxjx) this.LoadConfigure(game_pandamasmryl, cfg.NewGamePandamasMryl) configure.RegisterConfigure(game_pandamasbuff, cfg.NewGamePandamasBuff, func() { this.lock.Lock() if v, err := this.GetConfigure(game_pandamasbuff); err != nil { this.module.Errorf("err:%v", err) this.lock.Unlock() return } else { this.buffs = make(map[int32][]*cfg.GamePandamasBuffData) for _, v := range v.(*cfg.GamePandamasBuff).GetDataList() { if this.buffs[v.BuffGroup] == nil { this.buffs[v.Id] = make([]*cfg.GamePandamasBuffData, 0) } this.buffs[v.BuffGroup] = append(this.buffs[v.BuffGroup], v) } } this.lock.Unlock() }) return } func (this *configureComp) getGamePandamasMz(lv int32) (configure *cfg.GamePandamasMzData, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(game_pandamasmz); err != nil { this.module.Errorln(err) return } else { if configure, ok = v.(*cfg.GamePandamasMz).GetDataMap()[lv]; !ok { err = fmt.Errorf("not found:%d ", lv) this.module.Errorln(err) return } } return } func (this *configureComp) getGamePandamasJs() (configure []*cfg.GamePandamasJsData, err error) { var ( v interface{} ) if v, err = this.GetConfigure(game_pandamasjx); err != nil { this.module.Errorln(err) return } else { configure = v.(*cfg.GamePandamasJs).GetDataList() } return } func (this *configureComp) getGamePandamasJx(id string) (configure *cfg.GamePandamasJxData, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(game_pandamasjx); err != nil { this.module.Errorln(err) return } else { if configure, ok = v.(*cfg.GamePandamasJx).GetDataMap()[id]; !ok { err = fmt.Errorf("not found:%s ", id) this.module.Errorln(err) return } } return } func (this *configureComp) getGamePandamasYxjx(id int32) (configure *cfg.GamePandamasYxjxData, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(game_pandamasjx); err != nil { this.module.Errorln(err) return } else { if configure, ok = v.(*cfg.GamePandamasYxjx).GetDataMap()[id]; !ok { err = fmt.Errorf("not found:%d", id) this.module.Errorln(err) return } } return } func (this *configureComp) getGamePandamasMryls() (configure []*cfg.GamePandamasMrylData, err error) { var ( v interface{} ) if v, err = this.GetConfigure(game_pandamasmryl); err != nil { this.module.Errorln(err) return } else { configure = v.(*cfg.GamePandamasMryl).GetDataList() } return } func (this *configureComp) getPandamasMryl(id int32) (configure *cfg.GamePandamasMrylData, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(game_pandamasmryl); err != nil { this.module.Errorln(err) return } else { if configure, ok = v.(*cfg.GamePandamasMryl).GetDataMap()[id]; !ok { err = fmt.Errorf("not found:%d ", id) this.module.Errorln(err) return } } return } //随机获取buff权重 func (this *configureComp) getGamePandamasBuff(groupid int32) (configure *cfg.GamePandamasBuffData, err error) { var ( group []*cfg.GamePandamasBuffData weight []int32 index int32 ok bool ) this.lock.RLock() group, ok = this.buffs[groupid] this.lock.RUnlock() if !ok { err = fmt.Errorf("no found groupid:%d", groupid) this.module.Errorln(err) return } weight = make([]int32, len(group)) for i, v := range group { weight[i] = v.P } index = comm.GetRandW(weight) configure = group[index] return }