124 lines
3.2 KiB
Go
124 lines
3.2 KiB
Go
package wtask
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"sync"
|
|
)
|
|
|
|
const (
|
|
gameWorldTask = "game_worldtask.json"
|
|
gameWorldtaskBattle = "game_worldbattle.json"
|
|
gameWorldAll = "game_worldall.json"
|
|
gameburiedCond = "game_buriedcondi.json"
|
|
gamerdtasknpc = "game_rdtasknpc.json"
|
|
)
|
|
|
|
type configureComp struct {
|
|
modules.MCompConfigure
|
|
module *WTask
|
|
lock sync.RWMutex
|
|
condlTask map[int32][]*cfg.GameWorldTaskData //key 条件ID
|
|
}
|
|
|
|
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.(*WTask)
|
|
err = this.LoadMultiConfigure(map[string]interface{}{
|
|
gameWorldTask: cfg.NewGameWorldTask,
|
|
gameWorldtaskBattle: cfg.NewGameWorldBattle,
|
|
gameWorldAll: cfg.NewGameWorldAll,
|
|
gameburiedCond: cfg.NewGameBuriedCondi,
|
|
gamerdtasknpc: cfg.NewGameRdtaskNpc,
|
|
})
|
|
this.condlTask = make(map[int32][]*cfg.GameWorldTaskData)
|
|
configure.RegisterConfigure(gameWorldTask, cfg.NewGameBuriedCondi, this.updateconfigure)
|
|
return
|
|
}
|
|
|
|
// 读取任务配置表
|
|
func (this *configureComp) getWorldtaskCfg() (data *cfg.GameWorldTask, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(gameWorldTask); err != nil {
|
|
return
|
|
} else {
|
|
if data, ok = v.(*cfg.GameWorldTask); !ok {
|
|
err = fmt.Errorf("%T is *cfg.GameWorldTask", v)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 更新任务配置表
|
|
func (this *configureComp) updateconfigure() {
|
|
gwt, err := this.getWorldtaskCfg()
|
|
if err != nil {
|
|
this.module.Error("世界任务配置表异常!")
|
|
return
|
|
}
|
|
worldtaskConf := make(map[int32][]*cfg.GameWorldTaskData)
|
|
for _, v := range gwt.GetDataList() {
|
|
for _, condl := range v.Completetask {
|
|
if _, ok := worldtaskConf[condl]; !ok {
|
|
worldtaskConf[condl] = make([]*cfg.GameWorldTaskData, 0)
|
|
}
|
|
worldtaskConf[condl] = append(worldtaskConf[condl], v)
|
|
}
|
|
}
|
|
|
|
this.lock.Lock()
|
|
this.condlTask = worldtaskConf
|
|
this.lock.Unlock()
|
|
}
|
|
|
|
func (this *configureComp) getcondlTask() map[int32][]*cfg.GameWorldTaskData {
|
|
this.lock.RLock()
|
|
defer this.lock.RUnlock()
|
|
return this.condlTask
|
|
}
|
|
|
|
func (this *configureComp) gettaskconfconfigure(tid int32) (conf *cfg.GameWorldTaskData, err error) {
|
|
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(gameWorldTask); err != nil {
|
|
return
|
|
} else {
|
|
if conf, ok = v.(*cfg.GameWorldTask).GetDataMap()[tid]; !ok {
|
|
err = comm.NewNotFoundConfErr(modulename, gameWorldTask, tid)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取战斗配置
|
|
func (this *configureComp) getWorldtaskBattleById(confId int32) (conf *cfg.GameWorldBattleData, err error) {
|
|
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(gameWorldtaskBattle); err != nil {
|
|
return
|
|
} else {
|
|
if conf, ok = v.(*cfg.GameWorldBattle).GetDataMap()[confId]; !ok {
|
|
err = comm.NewNotFoundConfErr(modulename, gameWorldTask, confId)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|