package shop import ( "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" ) const ( game_shop = "game_shop.json" game_shopitem = "game_shopitem.json" ) ///背包配置管理组件 type configureComp struct { modules.MCompConfigure module *Shop } //组件初始化接口 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.(*Shop) this.LoadConfigure(game_shop, cfg.NewGameShop) this.LoadConfigure(game_shopitem, cfg.NewGameShopitem) return } //获取装备配置数据 func (this *configureComp) GetShopConfigure(id int32) (configure *cfg.GameShopData, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(game_shop); err != nil { this.module.Errorf("err:%v", err) return } else { if configure, ok = v.(*cfg.GameShop).GetDataMap()[id]; !ok { err = fmt.Errorf("ShopConfigure not found:%d ", id) this.module.Errorf("err:%v", err) return } } return } //读取商品 func (this *configureComp) GetShopItemsConfigure(key int32) (result *cfg.GameShopitemData, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(game_shopitem); err != nil { this.module.Errorf("err:%v", err) return } else { if result, ok = v.(*cfg.GameShopitem).GetDataMap()[key]; !ok { err = fmt.Errorf("ShopConfigure not found:%d ", key) this.module.Errorf("err:%v", err) return } } return } //读取商品组 func (this *configureComp) GetShopItemsConfigureByGroups(groupid int32, user *pb.DBUser) (result []*cfg.GameShopitemData, err error) { result = make([]*cfg.GameShopitemData, 0, 10) var ( v interface{} table *cfg.GameShopitem ) if v, err = this.GetConfigure(game_shopitem); err != nil { this.module.Errorf("err:%v", err) err = comm.NewNotFoundConfErr("hero", game_shopitem, groupid) return } else { table = v.(*cfg.GameShopitem) for _, v := range table.GetDataMap() { if v.Id == groupid && user.Lv >= v.Lvmin && user.Lv <= v.Lvmax && user.Vip >= v.Vip { result = append(result, v) } } } return } //读取商品 func (this *configureComp) GetShopItemsConfigureByIds(keys ...int32) (result []*cfg.GameShopitemData, err error) { result = make([]*cfg.GameShopitemData, 0, len(keys)) var ( v interface{} table *cfg.GameShopitem item *cfg.GameShopitemData ok bool ) if v, err = this.GetConfigure(game_shopitem); err != nil { this.module.Errorf("err:%v", err) return } else { table = v.(*cfg.GameShopitem) for _, v := range keys { if item, ok = table.GetDataMap()[v]; ok { result = append(result, item) } else { this.module.Errorf("no found GetShopItemsConfigureByIds:%d", v) } } } return }