180 lines
3.7 KiB
Go
180 lines
3.7 KiB
Go
package rtask
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
const (
|
|
gameRtask = "game_rdtask.json"
|
|
gameRtaskChoose = "game_rdtaskchoose.json"
|
|
gameRtaskCondi = "game_rdtaskcondi.json"
|
|
gameRtaskSide = "game_rdtaskside.json"
|
|
gameRtaskBattle = "game_rdtaskbattle.json"
|
|
)
|
|
|
|
type configureComp struct {
|
|
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)
|
|
err = this.LoadMultiConfigure(map[string]interface{}{
|
|
gameRtask: cfg.NewGameRdtask,
|
|
gameRtaskChoose: cfg.NewGameRdtaskChoose,
|
|
gameRtaskCondi: cfg.NewGameRdtaskCondi,
|
|
gameRtaskSide: cfg.NewGameRdtaskSide,
|
|
gameRtaskBattle: cfg.NewGameRdtaskBattle,
|
|
})
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) getRtaskCfg() (data *cfg.GameRdtask, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(gameRtask); err != nil {
|
|
return
|
|
} else {
|
|
if data, ok = v.(*cfg.GameRdtask); !ok {
|
|
err = fmt.Errorf("%T no is *cfg.GameRdtaskAll", v)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) getRtaskCondiCfg() (data *cfg.GameRdtaskCondi, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(gameRtaskCondi); err != nil {
|
|
return
|
|
} else {
|
|
if data, ok = v.(*cfg.GameRdtaskCondi); !ok {
|
|
err = fmt.Errorf("%T is *cfg.GameRdtaskCondi", v)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) getRtaskChoose() (data *cfg.GameRdtaskChoose, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(gameRtaskChoose); err != nil {
|
|
return
|
|
} else {
|
|
if data, ok = v.(*cfg.GameRdtaskChoose); !ok {
|
|
err = fmt.Errorf("%T is *cfg.getRtaskChoose", v)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) getRtaskSide() (data *cfg.GameRdtaskSide, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(gameRtaskSide); err != nil {
|
|
return
|
|
} else {
|
|
if data, ok = v.(*cfg.GameRdtaskSide); !ok {
|
|
err = fmt.Errorf("%T is *cfg.GameRdtaskSide", v)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) getRtaskBattle() (data *cfg.GameRdtaskBattle, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(gameRtaskBattle); err != nil {
|
|
return
|
|
} else {
|
|
if data, ok = v.(*cfg.GameRdtaskBattle); !ok {
|
|
err = fmt.Errorf("%T is *cfg.GameRdtaskBattle", v)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取选项配置
|
|
func (this *configureComp) getRtaskChooseCfg(id int32) *cfg.GameRdtaskChooseData {
|
|
cfg, err := this.getRtaskChoose()
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
|
|
if data, ok := cfg.GetDataMap()[id]; ok {
|
|
return data
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (this *configureComp) getRtaskSidById(id int32) *cfg.GameRdtaskSideData {
|
|
cfg, err := this.getRtaskSide()
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
|
|
if data, ok := cfg.GetDataMap()[id]; ok {
|
|
return data
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// 查询任务类型
|
|
func (this *configureComp) getRtaskTypeById(typeId int32) (data *cfg.GameRdtaskCondiData, err error) {
|
|
cfg, err := this.getRtaskCondiCfg()
|
|
if err != nil {
|
|
return
|
|
}
|
|
if cfg != nil {
|
|
if data, ok := cfg.GetDataMap()[typeId]; ok {
|
|
return data, nil
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 任务
|
|
func (this *configureComp) getRtaskById(taskId int32) (data *cfg.GameRdtaskData) {
|
|
cfg, err := this.getRtaskCfg()
|
|
if err != nil {
|
|
return
|
|
}
|
|
if cfg != nil {
|
|
if data, ok := cfg.GetDataMap()[taskId]; ok {
|
|
return data
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// 战斗配置
|
|
func (this *configureComp) getRtaskBattleById(id int32) (data *cfg.GameRdtaskBattleData) {
|
|
cfg, err := this.getRtaskBattle()
|
|
if err != nil {
|
|
return
|
|
}
|
|
if cfg != nil {
|
|
if data, ok := cfg.GetDataMap()[id]; ok {
|
|
return data
|
|
}
|
|
}
|
|
return nil
|
|
}
|