186 lines
4.8 KiB
Go
186 lines
4.8 KiB
Go
package caravan
|
|
|
|
import (
|
|
"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_caravan = "game_itinerant_city.json"
|
|
game_caravan_lv = "game_itinerant_lv.json"
|
|
game_caravan_reward = "game_itinerant_reward.json"
|
|
game_caravan_thing = "game_itinerant_thing.json"
|
|
|
|
game_trollgoods = "game_trollgoods.json"
|
|
game_trollcoefficient = "game_trollcoefficient.json"
|
|
game_trolltrain = "game_trolltrain.json"
|
|
game_trollrule = "game_trollrule.json"
|
|
game_trolllv = "game_trolllv.json"
|
|
)
|
|
|
|
///配置管理基础组件
|
|
type configureComp struct {
|
|
hlock sync.RWMutex
|
|
modules.MCompConfigure
|
|
}
|
|
|
|
//组件初始化接口
|
|
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)
|
|
|
|
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) GetTrollGoods(itemId int32) (data *cfg.GameTrollGoodsData) {
|
|
if v, err := this.GetConfigure(game_trollgoods); err == nil {
|
|
if configure, ok := v.(*cfg.GameTrollGoods); ok {
|
|
data = configure.Get(itemId)
|
|
return
|
|
}
|
|
} else {
|
|
log.Errorf("get GameTrollGoodsData conf err:%v", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取商人位置信息
|
|
func (this *configureComp) GetTrollTrain(id int32) (data *cfg.GameTrollTrainData) {
|
|
if v, err := this.GetConfigure(game_trolltrain); err == nil {
|
|
if configure, ok := v.(*cfg.GameTrollTrain); ok {
|
|
data = configure.Get(id)
|
|
return
|
|
}
|
|
} else {
|
|
log.Errorf("get GameTrollTrainData conf err:%v", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取基本规则
|
|
func (this *configureComp) GetTrollRule(id int32) int32 {
|
|
if v, err := this.GetConfigure(game_trollrule); err == nil {
|
|
if configure, ok := v.(*cfg.GameTrollRule); ok {
|
|
return configure.Get(id).Quantity
|
|
}
|
|
}
|
|
log.Errorf("get GetTrollRule conf err:%d", id)
|
|
|
|
return 1
|
|
}
|
|
|
|
func (this *configureComp) GetTrollCoefficient(id int32) (data *cfg.GameTrollCoefficientData) {
|
|
if v, err := this.GetConfigure(game_trollcoefficient); err == nil {
|
|
if configure, ok := v.(*cfg.GameTrollCoefficient); ok {
|
|
data = configure.Get(id)
|
|
return
|
|
}
|
|
} else {
|
|
log.Errorf("get GameTrollCoefficientData conf err:%v", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetTrollLv(id int32) (data *cfg.GameTrollLvData) {
|
|
if v, err := this.GetConfigure(game_trolllv); err == nil {
|
|
if configure, ok := v.(*cfg.GameTrollLv); ok {
|
|
data = configure.Get(id)
|
|
return
|
|
}
|
|
} else {
|
|
log.Errorf("get GameTrollCoefficientData conf err:%v", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetTrollAllTrain() (data []int32) {
|
|
data = make([]int32, 0)
|
|
if v, err := this.GetConfigure(game_trolltrain); err == nil {
|
|
if configure, ok := v.(*cfg.GameTrollTrain); ok {
|
|
for _, v := range configure.GetDataList() {
|
|
time := v.Time
|
|
data = append(data, time)
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
log.Errorf("get GameTrollTrainData conf err:%v", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetTrollMaxCoefficientNux() int32 {
|
|
if v, err := this.GetConfigure(game_trollcoefficient); err == nil {
|
|
if configure, ok := v.(*cfg.GameTrollCoefficient); ok {
|
|
|
|
return int32(len(configure.GetDataList()))
|
|
}
|
|
} else {
|
|
log.Errorf("get GameTrollTrainData conf err:%v", err)
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// 获取车站的数量
|
|
func (this *configureComp) GetTrollMaxTraintNum() int32 {
|
|
if v, err := this.GetConfigure(game_trolltrain); err == nil {
|
|
if configure, ok := v.(*cfg.GameTrollTrain); ok {
|
|
|
|
return int32(len(configure.GetDataList()))
|
|
}
|
|
} else {
|
|
log.Errorf("get GameTrollTrainData conf err:%v", err)
|
|
}
|
|
return 1 // 至少有1个车站
|
|
}
|
|
|
|
func (this *configureComp) GetTrollAllGoods() (data []*cfg.GameTrollGoodsData) {
|
|
if v, err := this.GetConfigure(game_trollgoods); err == nil {
|
|
if configure, ok := v.(*cfg.GameTrollGoods); ok {
|
|
data = configure.GetDataList()
|
|
return
|
|
}
|
|
} else {
|
|
log.Errorf("get GameTrollGoodsData conf err:%v", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
// 返回商人货物信息
|
|
func (this *configureComp) GetTrollGoodsFor(trainID int32) (data []int32) {
|
|
if v, err := this.GetConfigure(game_trollgoods); err == nil {
|
|
if configure, ok := v.(*cfg.GameTrollGoods); ok {
|
|
for _, v := range configure.GetDataList() {
|
|
if v.Goodsfor == trainID {
|
|
data = append(data, v.Id)
|
|
}
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
log.Errorf("get GameTrollGoodsData conf err:%v", err)
|
|
}
|
|
return
|
|
}
|