185 lines
4.6 KiB
Go
185 lines
4.6 KiB
Go
package items
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"sync"
|
|
|
|
"go_dreamfactory/lego/core"
|
|
)
|
|
|
|
const (
|
|
game_item = "game_item.json"
|
|
game_potions = "game_potions.json"
|
|
|
|
// game_propsgroup = "game_propsgroup.json"
|
|
// game_propsgrouplist = "game_propsgrouplist.json"
|
|
)
|
|
|
|
///背包配置管理组件
|
|
type ConfigureComp struct {
|
|
modules.MCompConfigure
|
|
module *Items
|
|
lock sync.RWMutex
|
|
// propsgroup map[int32][]*cfg.GamePropsgroupData
|
|
}
|
|
|
|
//组件初始化接口
|
|
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)
|
|
// this.propsgroup = make(map[int32][]*cfg.GamePropsgroupData)
|
|
err = this.LoadConfigure(game_item, cfg.NewGameItem)
|
|
err = this.LoadConfigure(game_potions, cfg.NewGamePotions)
|
|
// err = configure.RegisterConfigure(game_propsgroup, cfg.NewGamePropsgroup, func() {
|
|
// if v, err := this.GetConfigure(game_propsgroup); err == nil {
|
|
// if configure, ok := v.(*cfg.GamePropsgroup); ok {
|
|
// this.lock.Lock()
|
|
// defer this.lock.Unlock()
|
|
// for _, value := range configure.GetDataList() {
|
|
// if _, ok = this.propsgroup[value.Group]; !ok {
|
|
// this.propsgroup[value.Group] = make([]*cfg.GamePropsgroupData, 0)
|
|
// }
|
|
// this.propsgroup[value.Group] = append(this.propsgroup[value.Group], value)
|
|
// }
|
|
// return
|
|
// }
|
|
// } else {
|
|
// this.module.Errorln(err)
|
|
// }
|
|
// })
|
|
return
|
|
}
|
|
|
|
//读取物品配置
|
|
func (this *ConfigureComp) GetItemsConfigure() (items map[string]*cfg.GameItemData, 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.GameItem).GetDataMap()
|
|
}
|
|
return
|
|
}
|
|
|
|
//读取物品配置
|
|
func (this *ConfigureComp) GetItemConfigure(id string) (item *cfg.GameItemData, 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.GameItem).GetDataMap()[id]; !ok {
|
|
err = fmt.Errorf("no found item:%s configure", id)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//读取物品配置
|
|
func (this *ConfigureComp) GetItemConfigures(ids []string) (item []*cfg.GameItemData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_item); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
item = make([]*cfg.GameItemData, len(ids))
|
|
for i, v1 := range ids {
|
|
if item[i], ok = v.(*cfg.GameItem).GetDataMap()[v1]; !ok {
|
|
err = fmt.Errorf("no found item:%s configure", v1)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取指定类型的物品列表
|
|
func (this *ConfigureComp) GetPackItemByType(itmes []*pb.DB_UserItemData, bagtype int32) (result []*pb.DB_UserItemData) {
|
|
result = make([]*pb.DB_UserItemData, 0, len(itmes))
|
|
var (
|
|
v interface{}
|
|
table *cfg.GameItem
|
|
item *cfg.GameItemData
|
|
ok bool
|
|
err error
|
|
)
|
|
if v, err = this.GetConfigure(game_item); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
table = v.(*cfg.GameItem)
|
|
for _, v := range itmes {
|
|
if item, ok = table.GetDataMap()[v.ItemId]; ok {
|
|
if item.Bagtype == bagtype {
|
|
result = append(result, v)
|
|
}
|
|
} else {
|
|
this.module.Errorf("no found itemConfigure:%d", v.ItemId)
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *ConfigureComp) GetchallengeDataCount() (count int, err error) {
|
|
count = len(this.module.ModuleTools.GetGlobalConf().CopsBuy)
|
|
return
|
|
}
|
|
|
|
func (this *ConfigureComp) GetchallengeData(buy int) (result *cfg.Gameatn) {
|
|
for i, v := range this.module.ModuleTools.GetGlobalConf().CopsBuy {
|
|
if i == buy-1 {
|
|
result = v
|
|
return
|
|
}
|
|
result = v
|
|
}
|
|
return
|
|
}
|
|
|
|
// //获取道具礼包组
|
|
// func (this *ConfigureComp) GetPropsgroupConfigure(gid int32) (result []*cfg.GamePropsgroupData, err error) {
|
|
// var ok bool
|
|
// this.lock.RLock()
|
|
// result, ok = this.getd[gid]
|
|
// this.lock.RUnlock()
|
|
// if !ok {
|
|
// err = fmt.Errorf("no found gid:%d", gid)
|
|
// }
|
|
// return
|
|
// }
|
|
|
|
//读取物品配置
|
|
func (this *ConfigureComp) GetMaterialConfigure(id int32) (configure *cfg.GamePotionsData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_potions); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
if configure, ok = v.(*cfg.GamePotions).GetDataMap()[id]; !ok {
|
|
err = fmt.Errorf("no found Material:%d configure", id)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|