259 lines
6.9 KiB
Go
259 lines
6.9 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"
|
|
gamesearchitemall = "game_searchitemall.json"
|
|
gamesearchitembox = "game_searchitembox.json"
|
|
game_worlddeal = "game_worlddeal.json"
|
|
)
|
|
|
|
type configureComp struct {
|
|
modules.MCompConfigure
|
|
module *WTask
|
|
lock sync.RWMutex
|
|
condlTask map[int32][]*cfg.GameWorldTaskData //key 条件ID
|
|
desTask map[int32][]*cfg.GameWorldTaskData //key 分类
|
|
groupTask map[int32][]*cfg.GameWorldTaskData //key 任务组
|
|
opencmdTask map[string][]*cfg.GameWorldTaskData //key 功能开启
|
|
daylock sync.RWMutex
|
|
daygroupTasks map[int32][]*cfg.GameAnnulartask_LibraryData //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,
|
|
gamesearchitemall: cfg.NewGameSearchitemAll,
|
|
gamesearchitembox: cfg.NewGameSearchitemBox,
|
|
game_worlddeal: cfg.NewGameWorldDeal,
|
|
})
|
|
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)
|
|
destaskConf := make(map[int32][]*cfg.GameWorldTaskData)
|
|
grouptaskConf := make(map[int32][]*cfg.GameWorldTaskData)
|
|
opencmdConf := make(map[string][]*cfg.GameWorldTaskData)
|
|
for _, v := range gwt.GetDataList() {
|
|
|
|
if _, ok := destaskConf[v.Des]; !ok {
|
|
destaskConf[v.Des] = make([]*cfg.GameWorldTaskData, 0)
|
|
}
|
|
destaskConf[v.Des] = append(destaskConf[v.Des], v)
|
|
|
|
if _, ok := grouptaskConf[v.Group]; !ok {
|
|
grouptaskConf[v.Group] = make([]*cfg.GameWorldTaskData, 0)
|
|
}
|
|
grouptaskConf[v.Group] = append(grouptaskConf[v.Group], v)
|
|
|
|
if v.Opencond != "" {
|
|
if _, ok := opencmdConf[v.Opencond]; !ok {
|
|
opencmdConf[v.Opencond] = make([]*cfg.GameWorldTaskData, 0)
|
|
}
|
|
opencmdConf[v.Opencond] = append(opencmdConf[v.Opencond], v)
|
|
}
|
|
|
|
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.desTask = destaskConf
|
|
this.groupTask = grouptaskConf
|
|
this.opencmdTask = opencmdConf
|
|
this.lock.Unlock()
|
|
}
|
|
|
|
func (this *configureComp) getcondlTask() map[int32][]*cfg.GameWorldTaskData {
|
|
this.lock.RLock()
|
|
defer this.lock.RUnlock()
|
|
return this.condlTask
|
|
}
|
|
|
|
func (this *configureComp) getdesTask(des int32) []*cfg.GameWorldTaskData {
|
|
this.lock.RLock()
|
|
defer this.lock.RUnlock()
|
|
if _, ok := this.desTask[des]; ok {
|
|
return this.desTask[des]
|
|
} else {
|
|
return make([]*cfg.GameWorldTaskData, 0)
|
|
}
|
|
}
|
|
|
|
func (this *configureComp) getgroupTask() map[int32][]*cfg.GameWorldTaskData {
|
|
this.lock.RLock()
|
|
defer this.lock.RUnlock()
|
|
return this.groupTask
|
|
}
|
|
|
|
func (this *configureComp) getopencmdTask() map[string][]*cfg.GameWorldTaskData {
|
|
this.lock.RLock()
|
|
defer this.lock.RUnlock()
|
|
return this.opencmdTask
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
func (this *configureComp) getGameWorldAll(id int32) (conf *cfg.GameWorldAllData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(gameWorldAll); err != nil {
|
|
return
|
|
} else {
|
|
if conf, ok = v.(*cfg.GameWorldAll).GetDataMap()[id]; !ok {
|
|
err = comm.NewNotFoundConfErr(modulename, gameWorldTask, id)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) getGameSearchitemAll(id int32) (results map[int32]int32, err error) {
|
|
var (
|
|
v interface{}
|
|
conf *cfg.GameSearchitemAllData
|
|
|
|
weight []int
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(gamesearchitemall); err != nil {
|
|
return
|
|
} else {
|
|
if conf, ok = v.(*cfg.GameSearchitemAll).GetDataMap()[id]; !ok {
|
|
err = comm.NewNotFoundConfErr(modulename, gameWorldTask, id)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
results = make(map[int32]int32)
|
|
weight = comm.RandShuffle(len(conf.Pointweight))
|
|
for i := 0; i < int(conf.Pointnum); i++ {
|
|
results[conf.Point[weight[i]]] = 0
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) getGameSearchitemBox(id int32) (conf *cfg.GameSearchitemBoxData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(gamesearchitembox); err != nil {
|
|
return
|
|
} else {
|
|
if conf, ok = v.(*cfg.GameSearchitemBox).GetDataMap()[id]; !ok {
|
|
err = comm.NewNotFoundConfErr(modulename, gameWorldTask, id)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) getGameWorldDeal(id int32) (conf *cfg.GameWorldDealData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_worlddeal); err != nil {
|
|
return
|
|
} else {
|
|
if conf, ok = v.(*cfg.GameWorldDeal).GetDataMap()[id]; !ok {
|
|
err = comm.NewNotFoundConfErr(modulename, gameWorldTask, id)
|
|
this.module.Errorf("err:%v", err)
|
|
return
|
|
}
|
|
|
|
}
|
|
return
|
|
}
|