package items import ( "fmt" "go_dreamfactory/modules" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" ) const ( game_item = "game_item.json" ) ///背包配置管理组件 type ConfigureComp struct { modules.MCompConfigure } //组件初始化接口 func (this *ConfigureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { this.ModuleCompBase.Init(service, module, comp, options) this.LoadConfigure(game_item, cfg.NewGame_item) return } //读取物品配置 func (this *ConfigureComp) GetItemConfigure(id int32) (item *cfg.Game_itemData, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(game_item); err != nil { return } else { if item, ok = v.(*cfg.Game_item).GetDataMap()[id]; !ok { err = fmt.Errorf("no found item:%d configure", id) return } } return } //获取指定类型的物品列表 func (this *ConfigureComp) GetPackItemByType(itmes []*pb.DB_UserItemData, usetype int32) (result []*pb.DB_UserItemData) { result = make([]*pb.DB_UserItemData, 0, len(itmes)) var ( v interface{} table *cfg.Game_item item *cfg.Game_itemData id int32 ok bool err error ) if v, err = this.GetConfigure(game_item); err != nil { return } else { table = v.(*cfg.Game_item) for _, v := range itmes { if !v.IsEmpty { if item, ok = table.GetDataMap()[id]; ok { if item.Usetype == usetype { result = append(result, v) } } else { log.Errorf("no found itemConfigure:%d", id) } } } } return }