230 lines
6.2 KiB
Go
230 lines
6.2 KiB
Go
package worldtask
|
|
|
|
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 *Worldtask
|
|
lock sync.RWMutex
|
|
worldtaskConf 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.(*Worldtask)
|
|
err = this.LoadMultiConfigure(map[string]interface{}{
|
|
gameWorldTask: cfg.NewGameWorldTask,
|
|
gameWorldtaskBattle: cfg.NewGameWorldBattle,
|
|
gameWorldAll: cfg.NewGameWorldAll,
|
|
gameburiedCond: cfg.NewGameBuriedCondi,
|
|
gamerdtasknpc: cfg.NewGameRdtaskNpc,
|
|
})
|
|
this.worldtaskConf = make(map[int32]*cfg.GameWorldTaskData)
|
|
configure.RegisterConfigure(gameWorldTask, cfg.NewGameBuriedCondi, this.updateconfigure)
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) Start() (err error) {
|
|
err = this.MCompConfigure.Start()
|
|
this.checkWorldtaskConf()
|
|
conf, err := this.getWorldtaskCfg()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
this.worldtaskConf = conf.GetDataMap()
|
|
return
|
|
}
|
|
|
|
// 配置文件校验
|
|
func (this *configureComp) checkWorldtaskConf() (err error) {
|
|
worldtaskConf, err := this.getWorldtaskCfg()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
buriedCondConf, err := this.getBuriedCondCfg()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, data := range worldtaskConf.GetDataList() {
|
|
// 检查 lock
|
|
if data.Lock < 1 {
|
|
this.module.Errorf("taskId:%v lock:%v可能存在问题", data.Key, data.Lock)
|
|
}
|
|
//检查group
|
|
if data.Group <= 0 {
|
|
this.module.Errorf("taskId:%v group:%v可能存在问题", data.Key, data.Group)
|
|
}
|
|
//检查des
|
|
if data.Des < 1 || data.Des > 5 {
|
|
// errs = append(errs, fmt.Sprintf("taskId:%v des:%v可能存在问题", data.Key, data.Des))
|
|
this.module.Errorf("taskId:%v des:%v可能存在问题", data.Key, data.Des)
|
|
}
|
|
// 检查completetask 是否有效
|
|
for _, condId := range data.Completetask {
|
|
if condId > 0 {
|
|
if _, ok := buriedCondConf.GetDataMap()[condId]; !ok {
|
|
this.module.Errorf("taskId:%v completetask:%v可能是无效的ID", data.Key, condId)
|
|
// errs = append(errs, fmt.Sprintf("taskId:%v completetask:%v可能是无效的ID", data.Key, condId))
|
|
}
|
|
}
|
|
}
|
|
//检查NPC
|
|
if data.Npc > 0 {
|
|
if _, err := this.getNPCById(data.Npc); err != nil {
|
|
this.module.Errorf("npcId:%v 可能无效,检查world_task表字段Npc值是否存在于buried/rdtasknpc", data.Npc)
|
|
// errs = append(errs, fmt.Sprintf("npcId:%v 可能无效,检查world_task表字段Npc值是否存在于buried/rdtasknpc", data.Npc))
|
|
}
|
|
}
|
|
if data.DeliverNpc > 0 {
|
|
if _, err := this.getNPCById(data.Npc); err != nil {
|
|
this.module.Errorf("npcId:%v 可能无效,检查world_task表字段deliver_npc值是否存在于buried/rdtasknpc", data.Npc)
|
|
// errs = append(errs, fmt.Sprintf("npcId:%v 可能无效,检查world_task表字段deliver_npc值是否存在于buried/rdtasknpc", data.Npc))
|
|
}
|
|
}
|
|
}
|
|
|
|
for _, data := range buriedCondConf.GetDataList() {
|
|
if data.NPC > 0 {
|
|
if _, err := this.getNPCById(data.NPC); err != nil {
|
|
this.module.Errorf("npcId:%v 可能无效,检查buried_condi表字段NPC值是否存在于buried/rdtasknpc", data.NPC)
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
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 {
|
|
return
|
|
}
|
|
|
|
this.lock.Lock()
|
|
this.worldtaskConf = gwt.GetDataMap()
|
|
this.lock.Unlock()
|
|
}
|
|
|
|
func (this *configureComp) getWorldAllCfg() (data *cfg.GameWorldAll, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(gameWorldAll); err != nil {
|
|
return
|
|
} else {
|
|
if data, ok = v.(*cfg.GameWorldAll); !ok {
|
|
err = fmt.Errorf("%T is *cfg.GameWorldAll", v)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) getWorldtaskById(taskId int32) (*cfg.GameWorldTaskData, error) {
|
|
gwt, err := this.getWorldtaskCfg()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if data, ok := gwt.GetDataMap()[taskId]; ok {
|
|
return data, nil
|
|
}
|
|
return nil, comm.NewNotFoundConfErr(moduleName_cn, gameWorldTask, taskId)
|
|
}
|
|
|
|
func (this *configureComp) getNPCById(npcId int32) (npc *cfg.GameRdtaskNpcData, err error) {
|
|
var (
|
|
v interface{}
|
|
)
|
|
if v, err = this.GetConfigure(gamerdtasknpc); err != nil {
|
|
return
|
|
} else {
|
|
data, ok := v.(*cfg.GameRdtaskNpc)
|
|
if !ok {
|
|
err = fmt.Errorf("%T is *cfg.GameRdtaskNpc", v)
|
|
return
|
|
}
|
|
if npc, ok = data.GetDataMap()[npcId]; ok {
|
|
return
|
|
}
|
|
err = comm.NewNotFoundConfErr(moduleName_cn, gamerdtasknpc, npc)
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) getWorldtaskBattleCfg() (data *cfg.GameWorldBattle, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(gameWorldtaskBattle); err != nil {
|
|
return
|
|
} else {
|
|
if data, ok = v.(*cfg.GameWorldBattle); !ok {
|
|
err = fmt.Errorf("%T is *cfg.GameWorldBattle", v)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) getWorldtaskBattleById(confId int32) (*cfg.GameWorldBattleData, error) {
|
|
gwt, err := this.getWorldtaskBattleCfg()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if data, ok := gwt.GetDataMap()[confId]; ok {
|
|
return data, nil
|
|
}
|
|
return nil, fmt.Errorf("GameWorldBattleData config id:%v not found", confId)
|
|
}
|
|
|
|
func (this *configureComp) getBuriedCondCfg() (data *cfg.GameBuriedCondi, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(gameburiedCond); err != nil {
|
|
return
|
|
} else {
|
|
if data, ok = v.(*cfg.GameBuriedCondi); !ok {
|
|
err = fmt.Errorf("%T is *cfg.GameWorldAll", v)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|