131 lines
3.3 KiB
Go
131 lines
3.3 KiB
Go
package exclusive
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"sync"
|
|
|
|
"go_dreamfactory/lego/core"
|
|
)
|
|
|
|
const (
|
|
game_equip = "game_equip.json" //装备信息表
|
|
)
|
|
|
|
// /背包配置管理组件
|
|
type configureComp struct {
|
|
modules.MCompConfigure
|
|
module *Exclusive
|
|
equiplock sync.RWMutex
|
|
suit map[int32][]*cfg.GameEquipData
|
|
}
|
|
|
|
// 组件初始化接口
|
|
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.(*Exclusive)
|
|
this.LoadConfigure(game_equip, cfg.NewGameEquip)
|
|
configure.RegisterConfigure(game_equip, cfg.NewGameEquip, func() {
|
|
this.equiplock.Lock()
|
|
if v, err := this.GetConfigure(game_equip); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
this.suit = make(map[int32][]*cfg.GameEquipData)
|
|
for _, v := range v.(*cfg.GameEquip).GetDataList() {
|
|
if this.suit[v.Suittype] == nil {
|
|
this.suit[v.Suittype] = make([]*cfg.GameEquipData, 0)
|
|
}
|
|
this.suit[v.Suittype] = append(this.suit[v.Suittype], v)
|
|
}
|
|
}
|
|
this.equiplock.Unlock()
|
|
})
|
|
return
|
|
}
|
|
|
|
// 获取全部资源
|
|
func (this *configureComp) GetAllEquipmentConfigure() (configure []*cfg.GameEquipData) {
|
|
if v, err := this.GetConfigure(game_equip); err == nil {
|
|
configure = v.(*cfg.GameEquip).GetDataList()
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取装备配置数据
|
|
func (this *configureComp) GetEquipmentConfigure() (configure *cfg.GameEquip, 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); !ok {
|
|
err = fmt.Errorf("%T no is *cfg.Game_equipment", v)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取装备配置数据
|
|
func (this *configureComp) GetSuitEquipmentConfigure(suitid int32) (configures []*cfg.GameEquipData, err error) {
|
|
var ok bool
|
|
this.equiplock.RLock()
|
|
configures, ok = this.suit[suitid]
|
|
this.equiplock.RUnlock()
|
|
if !ok {
|
|
err = fmt.Errorf("no found suitid:%d", suitid)
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取装备配置数据
|
|
func (this *configureComp) GetEquipmentConfigureById(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 = fmt.Errorf("EquipmentConfigure not found:%s ", equipmentId)
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_equip, equipmentId)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取装备配置数据
|
|
func (this *configureComp) GetEquipmentConfigureByIds(equipmentId []string) (configure []*cfg.GameEquipData, err error) {
|
|
var (
|
|
t interface{}
|
|
c *cfg.GameEquipData
|
|
ok bool
|
|
)
|
|
if t, err = this.GetConfigure(game_equip); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
configure = make([]*cfg.GameEquipData, len(equipmentId))
|
|
for i, v := range equipmentId {
|
|
if c, ok = t.(*cfg.GameEquip).GetDataMap()[v]; ok {
|
|
configure[i] = c
|
|
return
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|