117 lines
2.4 KiB
Go
117 lines
2.4 KiB
Go
package rtask
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
const (
|
|
gameRtask = "game_rdtaskall.json"
|
|
gameRtaskChoose = "game_rdtaskchoose.json"
|
|
gameRtaskType = "game_rdtasktype.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,
|
|
gameRtaskType: cfg.NewGameRdtaskCondi,
|
|
})
|
|
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) getRtaskTypeCfg() (data *cfg.GameRdtaskCondi, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(gameRtask); err != nil {
|
|
return
|
|
} else {
|
|
if data, ok = v.(*cfg.GameRdtaskCondi); !ok {
|
|
err = fmt.Errorf("%T is *cfg.GameRdtaskType", v)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取随机任务配置
|
|
func (this *configureComp) getRtaskList() (data []*cfg.GameRdtaskData, err error) {
|
|
cfg, err := this.getRtaskCfg()
|
|
if err != nil {
|
|
return
|
|
}
|
|
if cfg != nil {
|
|
data = cfg.GetDataList()
|
|
}
|
|
return
|
|
}
|
|
|
|
// 查询任务类型
|
|
func (this *configureComp) getRtaskTypeById(typeId int32) (data *cfg.GameRdtaskCondiData, err error) {
|
|
cfg, err := this.getRtaskTypeCfg()
|
|
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) getFirstTask() *cfg.GameRdtaskData {
|
|
cfg, err := this.getRtaskCfg()
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
if cfg != nil {
|
|
for _, v := range cfg.GetDataList() {
|
|
if v.NextTid == 0 {
|
|
return v
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|