go_dreamfactory/modules/items/configure.go
2022-07-22 19:34:05 +08:00

110 lines
2.5 KiB
Go

package items
import (
"fmt"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/lego/core"
)
const (
game_item = "game_item.json"
game_propsgroup = "game_propsgroup.json"
)
///背包配置管理组件
type ConfigureComp struct {
modules.MCompConfigure
module *Items
}
//组件初始化接口
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.(*Items)
err = this.LoadConfigure(game_item, cfg.NewGame_item)
return
}
//读取物品配置
func (this *ConfigureComp) GetItemsConfigure() (items map[int32]*cfg.Game_itemData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_item); err != nil {
this.module.Errorf("err:%v", err)
return
} else {
items = v.(*cfg.Game_item).GetDataMap()
}
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 {
this.module.Errorf("err:%v", err)
return
} else {
if item, ok = v.(*cfg.Game_item).GetDataMap()[id]; !ok {
err = fmt.Errorf("no found item:%d configure", id)
this.module.Errorf("err:%v", err)
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
ok bool
err error
)
if v, err = this.GetConfigure(game_item); err != nil {
this.module.Errorf("err:%v", err)
return
} else {
table = v.(*cfg.Game_item)
for _, v := range itmes {
if item, ok = table.GetDataMap()[v.ItemId]; ok {
if item.Usetype == usetype {
result = append(result, v)
}
} else {
this.module.Errorf("no found itemConfigure:%d", v.ItemId)
}
}
}
return
}
//获取道具礼包组
func (this *ConfigureComp) GetPropsgroupConfigure(id int32) (item *cfg.Game_propsgroupData, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(game_propsgroup); err != nil {
this.module.Errorf("err:%v", err)
return
} else {
if item, ok = v.(*cfg.Game_propsgroup).GetDataMap()[id]; !ok {
err = fmt.Errorf("no found item:%d configure", id)
this.module.Errorf("err:%v", err)
return
}
}
return
}