167 lines
4.4 KiB
Go
167 lines
4.4 KiB
Go
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"
|
|
game_shopbuyequicos = "game_shopbuyequicos.json"
|
|
game_equip = "game_equip.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)
|
|
this.LoadConfigure(game_shopbuyequicos, cfg.NewGameShopBuyequiCos)
|
|
this.LoadConfigure(game_equip, cfg.NewGameEquip)
|
|
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)
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_shop, 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)
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_shopitem, 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)
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_shopitem, v)
|
|
return
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取装备套装配置
|
|
func (this *configureComp) getShopBuyequiCosData(intlv, lv int32) (conf *cfg.GameShopBuyequiCosData, err error) {
|
|
var (
|
|
v interface{}
|
|
)
|
|
if v, err = this.GetConfigure(game_shopbuyequicos); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
for _, v := range v.(*cfg.GameShopBuyequiCos).GetDataList() {
|
|
if v.InitLv == intlv && v.UpLv == lv {
|
|
conf = v
|
|
return
|
|
}
|
|
}
|
|
}
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_shopbuyequicos, fmt.Sprintf("intlv:%d lv:%d", intlv, lv))
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
|
|
// 获取装备配置数据
|
|
func (this *configureComp) getGameEquipData(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 = comm.NewNotFoundConfErr(string(this.module.GetType()), game_equip, equipmentId)
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|