package entertainment import ( "fmt" "go_dreamfactory/comm" "go_dreamfactory/modules" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "sync" "go_dreamfactory/lego/core" ) const ( game_block = "game_block.json" game_consumehero = "game_consumehero.json" game_integral = "game_integral.json" ) // /配置管理组件 type configureComp struct { modules.MCompConfigure module *Entertainment lock sync.RWMutex block map[int32]*cfg.GameBlockData } const moduleName = "entertainment" 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.(*Entertainment) err = this.LoadMultiConfigure(map[string]interface{}{ game_consumehero: cfg.NewGameConsumeHero, game_integral: cfg.NewGameIntegral, }) configure.RegisterConfigure(game_block, cfg.NewGameBlock, this.LoadGameBlock) return } func (this *configureComp) LoadGameBlock() { var ( v interface{} configure *cfg.GameBlock err error ok bool ) if v, err = this.GetConfigure(game_block); err != nil { this.module.Errorln(err) return } block := make(map[int32]*cfg.GameBlockData) if configure, ok = v.(*cfg.GameBlock); ok { for _, v := range configure.GetDataList() { key := v.Color<<8 + v.Type block[key] = v } } this.lock.Lock() this.block = block this.lock.Unlock() return } func (this *configureComp) GetGameBlock(color int32, iType int32) (conf *cfg.GameBlockData, err error) { var ( ok bool key int32 ) key = color<<8 + iType this.lock.RLock() defer this.lock.RUnlock() if conf, ok = this.block[key]; !ok { err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_block, fmt.Sprintf("color:%d,itype:%d", color, key)) } return } func (this *configureComp) GetGameConsumeHero(heroid string) (conf *cfg.GameConsumeHeroData, err error) { var ( v interface{} ) if v, err = this.GetConfigure(game_consumehero); err == nil { if configure, ok := v.(*cfg.GameConsumeHero); ok { if conf = configure.Get(heroid); conf != nil { return } } } err = comm.NewNotFoundConfErr(moduleName, game_consumehero, heroid) return } func (this *configureComp) GetGameConsumeintegral(key int32) (conf *cfg.GameIntegralData, err error) { var ( v interface{} configure *cfg.GameIntegral ok bool ) if v, err = this.GetConfigure(game_integral); err == nil { if configure, ok = v.(*cfg.GameIntegral); ok { for pos, v := range configure.GetDataList() { if v.Key >= key { if pos == 0 { conf = configure.GetDataList()[1] return } conf = v return } } } } if configure.GetDataList()[len(configure.GetDataList())-1].Key < key { // 设置最大值 conf = configure.GetDataList()[len(configure.GetDataList())-1] return } err = comm.NewNotFoundConfErr(moduleName, game_integral, key) return } func (this *configureComp) GetRobotGameConsumeHero() (cardid string) { if v, err := this.GetConfigure(game_consumehero); err == nil { if configure, ok := v.(*cfg.GameConsumeHero); ok { for _, v := range configure.GetDataList() { cardid = v.Key break } } } return } func (this *configureComp) GetGameConsumeintegralReward(key int32) (conf *cfg.GameIntegralData, err error) { var ( v interface{} ) if v, err = this.GetConfigure(game_integral); err == nil { if configure, ok := v.(*cfg.GameIntegral); ok { if conf = configure.Get(key); conf != nil { return } } } err = comm.NewNotFoundConfErr(moduleName, game_integral, key) return } func (this *configureComp) GetInitGameConsumeHero() (cardid []string) { if v, err := this.GetConfigure(game_consumehero); err == nil { if configure, ok := v.(*cfg.GameConsumeHero); ok { for _, v := range configure.GetDataList() { if v.Type == 1 { cardid = append(cardid, v.Key) } } } } return }