119 lines
3.1 KiB
Go
119 lines
3.1 KiB
Go
package enchant
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"sync"
|
|
)
|
|
|
|
const (
|
|
game_enchantboss = "game_enchantboss.json"
|
|
game_enchantshop = "game_enchantshop.json"
|
|
game_enchantbossreward = "game_enchantbossreward.json"
|
|
)
|
|
|
|
///配置管理基础组件
|
|
type configureComp struct {
|
|
modules.MCompConfigure
|
|
module *Enchant
|
|
hlock sync.RWMutex
|
|
}
|
|
|
|
//组件初始化接口
|
|
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
err = this.MCompConfigure.Init(service, module, comp, options)
|
|
this.module = module.(*Enchant)
|
|
err = this.LoadConfigure(game_enchantboss, cfg.NewGameEnchantBoss)
|
|
err = this.LoadConfigure(game_enchantshop, cfg.NewGameEnchantShop)
|
|
err = this.LoadConfigure(game_enchantbossreward, cfg.NewGameEnchantbossReward)
|
|
return
|
|
}
|
|
|
|
// 参数: boss类型 难度
|
|
func (this *configureComp) GetEnchantBossConfigData(bossId int32) (conf *cfg.GameEnchantBossData, err error) {
|
|
var (
|
|
v interface{}
|
|
)
|
|
if v, err = this.GetConfigure(game_enchantboss); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
for _, v := range v.(*cfg.GameEnchantBoss).GetDataList() {
|
|
if v.Bossid == bossId {
|
|
conf = v
|
|
return
|
|
}
|
|
}
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_enchantboss, bossId)
|
|
}
|
|
return
|
|
}
|
|
|
|
// 读取装备出售系数配置
|
|
func (this *configureComp) getGameRepeatAllData(id int32) (conf *cfg.GameEnchantbossRewardData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_enchantbossreward); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
} else {
|
|
if conf, ok = v.(*cfg.GameEnchantbossReward).GetDataMap()[id]; !ok {
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_enchantbossreward, id)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//加载多个配置文件
|
|
func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err error) {
|
|
for k, v := range confs {
|
|
err = configure.RegisterConfigure(k, v, nil)
|
|
if err != nil {
|
|
log.Errorf("配置文件:%s解析失败!", k)
|
|
break
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//读取配置数据
|
|
func (this *configureComp) GetConfigure(name string) (v interface{}, err error) {
|
|
return configure.GetConfigure(name)
|
|
}
|
|
|
|
func (this *configureComp) GetBuyChallengeCount(index int32) (data *cfg.GameEnchantShopData, err error) {
|
|
var (
|
|
v interface{}
|
|
)
|
|
if v, err = this.GetConfigure(game_enchantshop); err == nil {
|
|
if configure, ok := v.(*cfg.GameEnchantShop); ok {
|
|
data = configure.Get(index)
|
|
if data == nil {
|
|
err = comm.NewNotFoundConfErr("enchant", game_enchantshop, index)
|
|
}
|
|
return
|
|
}
|
|
}
|
|
err = comm.NewNotFoundConfErr("enchant", game_enchantshop, index)
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetMaxBuyChallengeCount() int32 {
|
|
if v, err := this.GetConfigure(game_enchantshop); err == nil {
|
|
if configure, ok := v.(*cfg.GameEnchantShop); ok {
|
|
return int32(len(configure.GetDataList()))
|
|
}
|
|
} else {
|
|
log.Errorf("get game_challenge conf err:%v", err)
|
|
}
|
|
|
|
return 0
|
|
}
|