package smithy import ( "fmt" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "sync" ) const ( game_smithy = "game_smithy.json" game_smithystove = "game_smithystove.json" game_equip = "game_equip.json" //装备信息表 ) ///配置管理基础组件 type configureComp struct { modules.MCompConfigure module *Smithy hlock sync.RWMutex _smithyMap map[int64]*cfg.GameSmithyData } //组件初始化接口 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._smithyMap = make(map[int64]*cfg.GameSmithyData, 0) this.module = module.(*Smithy) configure.RegisterConfigure(game_smithy, cfg.NewGameSmithy, func() { if v, err := this.GetConfigure(game_smithy); err == nil { if configure, ok := v.(*cfg.GameSmithy); ok { this.hlock.Lock() defer this.hlock.Unlock() for _, value := range configure.GetDataList() { this._smithyMap[int64(value.Type<<16)+int64(value.Star)] = value } return } } log.Errorf("get game_pagoda conf err:%v", err) return }) err = this.LoadConfigure(game_smithystove, cfg.NewGameSmithyStove) err = this.LoadConfigure(game_equip, cfg.NewGameEquip) return } // 获取美食馆配置数据 func (this *configureComp) GetSmithyConfigData(smithyType int32, level int32) (data *cfg.GameSmithyData) { return this._smithyMap[int64(smithyType<<16)+int64(level)] } func (this *configureComp) GetSmithyTypeConfigData() (mapType map[int32]struct{}) { mapType = make(map[int32]struct{}, 0) if v, err := this.GetConfigure(game_smithy); err == nil { if configure, ok := v.(*cfg.GameSmithy); ok { for _, v1 := range configure.GetDataList() { if _, ok := mapType[v1.Type]; !ok { mapType[v1.Type] = struct{}{} } } return } } return } // 获取炉子配置数据 func (this *configureComp) GetSmithyStoveConfigData(level int32) (data *cfg.GameSmithyStoveData) { if v, err := this.GetConfigure(game_smithystove); err == nil { if configure, ok := v.(*cfg.GameSmithyStove); ok { data = configure.Get(int32(level)) return } } return } //加载多个配置文件 func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err error) { for k, v := range confs { err = configure.RegisterConfigure(k, v, nil) if err != nil { log.Errorf("配置文件:%s解析失败!", k) break } } return } //读取配置数据 func (this *configureComp) GetConfigure(name string) (v interface{}, err error) { return configure.GetConfigure(name) } func (this *configureComp) GetEquipmentConfigureById(equipmentId string) (configure *cfg.GameEquipData, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(game_equip); err != nil { this.module.Errorf("err:%v", err) return } else { if configure, ok = v.(*cfg.GameEquip).GetDataMap()[equipmentId]; !ok { err = fmt.Errorf("EquipmentConfigure not found:%s ", equipmentId) this.module.Errorf("err:%v", err) return } } return }