go_dreamfactory/modules/equipment/configure.go
2022-11-15 09:54:40 +08:00

258 lines
6.8 KiB
Go

package equipment
import (
"fmt"
"go_dreamfactory/modules"
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/lego/core"
)
const (
game_equip = "game_equip.json" //装备信息表
equip_attrlibrary = "game_equipattrlibrary.json" //装备属性配置表
equip_intensify = "game_equipintensify.json" //装备等级消耗表
equip_suit = "game_equipsuit.json" //装备套装表
game_equipcompose = "game_equipcompose.json" //装备锻造
game_equipattribute = "game_equipattribute.json" //装备技能列表
game_equipenchanting = "game_equipenchanting.json" //装备附魔
)
///背包配置管理组件
type configureComp struct {
modules.MCompConfigure
module *Equipment
}
//组件初始化接口
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.NewGameEquipAttrlibrary)
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)
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) 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.GameEquipAttrlibrary, 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.GameEquipAttrlibrary); !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.GameEquipAttrlibraryData, 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.GameEquipAttrlibrary).GetDataMap()[key]; !ok {
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.GameEquipAttrlibraryData, 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.GameEquipAttrlibraryData, 0)
for _, v1 := range v.(*cfg.GameEquipAttrlibrary).GetDataList() {
if v1.Libraryid == Id {
configure = append(configure, v1)
}
}
}
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)
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 = fmt.Errorf("on found getEquipenchanting id:%s", id)
this.module.Errorf("err:%v", err)
return
}
}
return
}