package equipment import ( "fmt" "go_dreamfactory/modules" cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/lego/core" ) const ( game_equip = "game_equip.json" //装备信息表 equip_attrlibrary = "game_equipattrlibrary.json" //装备属性配置表 equip_intensify = "game_equipintensify.json" //装备等级消耗表 equip_suit = "game_equipsuit.json" //装备套装表 ) ///背包配置管理组件 type configureComp struct { modules.MCompConfigure module *Equipment } //组件初始化接口 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.(*Equipment) this.LoadConfigure(game_equip, cfg.NewGameEquip) this.LoadConfigure(equip_attrlibrary, cfg.NewGameEquipAttrlibrary) this.LoadConfigure(equip_intensify, cfg.NewGameEquipIntensify) this.LoadConfigure(equip_suit, cfg.NewGameEquipSuit) return } //获取装备配置数据 func (this *configureComp) GetEquipmentConfigure() (configure *cfg.GameEquip, 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); !ok { err = fmt.Errorf("%T no is *cfg.Game_equipment", v) this.module.Errorf("err:%v", err) return } } return } //获取装备配置数据 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 } //获取装备配置数据 func (this *configureComp) GetEquipmentConfigureByIds(equipmentId []string) (configure []*cfg.GameEquipData, err error) { var ( t interface{} c *cfg.GameEquipData ok bool ) if t, err = this.GetConfigure(game_equip); err != nil { this.module.Errorf("err:%v", err) return } else { configure = make([]*cfg.GameEquipData, len(equipmentId)) for i, v := range equipmentId { if c, ok = t.(*cfg.GameEquip).GetDataMap()[v]; ok { configure[i] = c return } } } return } //获取装备属性表 func (this *configureComp) GetEquipmentAttrlibraryConfigure() (configure *cfg.GameEquipAttrlibrary, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(equip_attrlibrary); err != nil { this.module.Errorf("err:%v", err) return } else { if configure, ok = v.(*cfg.GameEquipAttrlibrary); !ok { err = fmt.Errorf("%T no is *cfg.Game_equipment", v) this.module.Errorf("err:%v", err) return } } return } //获取属性词列表 func (this *configureComp) GetEquipmentAttrlibraryConfigureByKey(key int32) (configure *cfg.GameEquipAttrlibraryData, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(equip_attrlibrary); err != nil { this.module.Errorf("err:%v", err) return } else { if configure, ok = v.(*cfg.GameEquipAttrlibrary).GetDataMap()[key]; !ok { err = fmt.Errorf("EquipmentConfigure GetEquipmentAttrlibraryConfigureByKey not found:%d ", key) this.module.Errorf("err:%v", err) return } } return } //获取属性词列表 func (this *configureComp) GetEquipmentAttrlibraryConfigureById(Id int32) (configure []*cfg.GameEquipAttrlibraryData, err error) { var ( v interface{} ) if v, err = this.GetConfigure(equip_attrlibrary); err != nil { this.module.Errorf("err:%v", err) return } else { configure = make([]*cfg.GameEquipAttrlibraryData, 0) for _, v1 := range v.(*cfg.GameEquipAttrlibrary).GetDataList() { if v1.Libraryid == Id { configure = append(configure, v1) } } } return } //获取武器等级消耗表 func (this *configureComp) GetEquipmentIntensifyConfigure() (configure *cfg.GameEquipIntensify, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(equip_intensify); err != nil { this.module.Errorf("err:%v", err) return } else { if configure, ok = v.(*cfg.GameEquipIntensify); !ok { err = fmt.Errorf("%T no is *cfg.Game_equipment", v) this.module.Errorf("err:%v", err) return } } return } //获取武器等级消耗表 func (this *configureComp) GetEquipmentIntensifyConfigureById(star, lv int32) (configure *cfg.GameEquipIntensifyData, err error) { var ( v interface{} ) if v, err = this.GetConfigure(equip_intensify); err != nil { this.module.Errorf("err:%v", err) return } else { for _, v1 := range v.(*cfg.GameEquipIntensify).GetDataList() { if v1.Star == star && v1.Level == lv { configure = v1 } } if configure == nil { err = fmt.Errorf("EquipmentConfigure not found star :%d lv:%d", star, lv) this.module.Errorf("err:%v", err) return } } return }