go_dreamfactory/modules/shop/configure.go
2022-07-13 15:06:48 +08:00

117 lines
2.8 KiB
Go

package shop
import (
"fmt"
"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.ModuleCompBase.Init(service, module, comp, options)
this.module = module.(*Shop)
this.LoadConfigure(game_shop, cfg.NewGame_shop)
this.LoadConfigure(game_shopitem, cfg.NewGame_shopitem)
return
}
//获取装备配置数据
func (this *configureComp) GetShopConfigure(id int32) (configure *cfg.Game_shopData, 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.Game_shop).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.Game_shopitemData, 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.Game_shopitem).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.Game_shopitemData, err error) {
result = make([]*cfg.Game_shopitemData, 0, 10)
var (
v interface{}
table *cfg.Game_shopitem
)
if v, err = this.GetConfigure(game_shopitem); err != nil {
this.module.Errorf("err:%v", err)
return
} else {
table = v.(*cfg.Game_shopitem)
for _, v := range table.GetDataMap() {
if v.Id == groupid &&
user.Lv >= v.Lvmin &&
user.Lv <= v.Lvmax &&
v.Vip >= v.Vip {
result = append(result, v)
}
}
}
return
}
//读取商品
func (this *configureComp) GetShopItemsConfigureByIds(keys ...int32) (result []*cfg.Game_shopitemData, err error) {
result = make([]*cfg.Game_shopitemData, 0, len(keys))
var (
v interface{}
table *cfg.Game_shopitem
item *cfg.Game_shopitemData
ok bool
)
if v, err = this.GetConfigure(game_shopitem); err != nil {
this.module.Errorf("err:%v", err)
return
} else {
table = v.(*cfg.Game_shopitem)
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
}