338 lines
9.3 KiB
Go
338 lines
9.3 KiB
Go
package equipment
|
|
|
|
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" //装备信息表
|
|
equip_attrlibrary = "game_equipattrlibrarys.json" //装备属性配置表
|
|
equip_intensify = "game_equipintensify.json" //装备等级消耗表
|
|
equip_suit = "game_equipsuit.json" //装备套装表
|
|
game_equipcompose = "game_equipscompose.json" //装备锻造
|
|
game_equipattribute = "game_equipattribute.json" //装备技能列表
|
|
game_equipenchanting = "game_equipenchanting.json" //装备附魔
|
|
game_sellcoefficient = "game_sellcoefficient.json" //装备出售品质系数
|
|
|
|
)
|
|
|
|
///背包配置管理组件
|
|
type configureComp struct {
|
|
modules.MCompConfigure
|
|
module *Equipment
|
|
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.(*Equipment)
|
|
this.LoadConfigure(game_equip, cfg.NewGameEquip)
|
|
this.LoadConfigure(equip_attrlibrary, cfg.NewGameEquipAttrlibraryS)
|
|
this.LoadConfigure(equip_intensify, cfg.NewGameEquipIntensify)
|
|
this.LoadConfigure(equip_suit, cfg.NewGameEquipSuit)
|
|
this.LoadConfigure(game_equipcompose, cfg.NewGameEquipSCompose)
|
|
this.LoadConfigure(game_equipattribute, cfg.NewGameEquipAttribute)
|
|
this.LoadConfigure(game_equipenchanting, cfg.NewGameEquipEnchanting)
|
|
this.LoadConfigure(game_sellcoefficient, cfg.NewGameSellCoefficient)
|
|
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) 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)
|
|
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
|
|
}
|
|
|
|
//获取装备属性表
|
|
func (this *configureComp) GetEquipmentAttrlibraryConfigure() (configure *cfg.GameEquipAttrlibraryS, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(equip_attrlibrary); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
if configure, ok = v.(*cfg.GameEquipAttrlibraryS); !ok {
|
|
err = fmt.Errorf("%T no is *cfg.Game_equipment", v)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取属性词列表
|
|
func (this *configureComp) GetEquipmentAttrlibraryConfigureByKey(key int32) (configure *cfg.GameEquipAttrlibrarySData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(equip_attrlibrary); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
if configure, ok = v.(*cfg.GameEquipAttrlibraryS).GetDataMap()[key]; !ok {
|
|
err = comm.NewNotFoundConfErr(moduleName, equip_attrlibrary, key)
|
|
// err = fmt.Errorf("EquipmentConfigure GetEquipmentAttrlibraryConfigureByKey not found:%d ", key)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取属性词列表
|
|
func (this *configureComp) GetEquipmentAttrlibraryConfigureById(Id int32) (configure []*cfg.GameEquipAttrlibrarySData, err error) {
|
|
var (
|
|
v interface{}
|
|
)
|
|
if v, err = this.GetConfigure(equip_attrlibrary); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
configure = make([]*cfg.GameEquipAttrlibrarySData, 0)
|
|
for _, v1 := range v.(*cfg.GameEquipAttrlibraryS).GetDataList() {
|
|
if v1.Libraryid == Id {
|
|
configure = append(configure, v1)
|
|
}
|
|
}
|
|
}
|
|
if len(configure) == 0 {
|
|
err = fmt.Errorf("game_equipattrlibrary.json on found %d", Id)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取武器等级消耗表
|
|
func (this *configureComp) GetEquipmentIntensifyConfigure() (configure *cfg.GameEquipIntensify, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(equip_intensify); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
if configure, ok = v.(*cfg.GameEquipIntensify); !ok {
|
|
err = fmt.Errorf("%T no is *cfg.Game_equipment", v)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取武器等级消耗表
|
|
func (this *configureComp) GetEquipmentIntensifyConfigureById(etype, star, lv int32) (configure *cfg.GameEquipIntensifyData, err error) {
|
|
var (
|
|
v interface{}
|
|
)
|
|
if v, err = this.GetConfigure(equip_intensify); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
for _, v1 := range v.(*cfg.GameEquipIntensify).GetDataList() {
|
|
if v1.TypeId == etype && v1.Star == star && v1.Level == lv {
|
|
configure = v1
|
|
}
|
|
}
|
|
if configure == nil {
|
|
err = fmt.Errorf("EquipmentConfigure not found star :%d lv:%d", star, lv)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取装备锻造数据
|
|
func (this *configureComp) GetEquipCompose(id int32) (result *cfg.GameEquipSComposeData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_equipcompose); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
if result, ok = v.(*cfg.GameEquipSCompose).GetDataMap()[id]; !ok {
|
|
err = fmt.Errorf("on found GetEquipCompose id:%d", id)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取装备锻造数据
|
|
func (this *configureComp) getEquipAttribute(sid string) (result *cfg.GameEquipAttributeData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_equipattribute); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
if result, ok = v.(*cfg.GameEquipAttribute).GetDataMap()[sid]; !ok {
|
|
// err = fmt.Errorf("on found getEquipAttribute id:%s", sid)
|
|
err = comm.NewNotFoundConfErr(moduleName, equip_attrlibrary, sid)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取附魔数据
|
|
func (this *configureComp) getEquipenchanting(id string) (result *cfg.GameEquipEnchantingData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_equipenchanting); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
if result, ok = v.(*cfg.GameEquipEnchanting).GetDataMap()[id]; !ok {
|
|
err = comm.NewNotFoundConfErr(moduleName, equip_attrlibrary, id)
|
|
// err = fmt.Errorf("on found getEquipenchanting id:%s", id)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//读取装备出售系数配置
|
|
func (this *configureComp) getSellcoefficient(id int32) (result *cfg.GameSellCoefficientData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_sellcoefficient); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
if result, ok = v.(*cfg.GameSellCoefficient).GetDataMap()[id]; !ok {
|
|
err = comm.NewNotFoundConfErr(moduleName, equip_attrlibrary, id)
|
|
// err = fmt.Errorf("on found getSellcoefficient id:%d", id)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//获取装备套装配置
|
|
func (this *configureComp) getEquipSuit(sid int32) (result *cfg.GameEquipSuitData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(equip_suit); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
if result, ok = v.(*cfg.GameEquipSuit).GetDataMap()[sid]; !ok {
|
|
// err = fmt.Errorf("on found getEquipAttribute id:%s", sid)
|
|
err = comm.NewNotFoundConfErr(moduleName, equip_suit, sid)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|