启动校验配置文件

This commit is contained in:
wh_zcy 2023-06-07 11:24:59 +08:00
parent 1b2e96a0c1
commit a60b77f2a9
4 changed files with 106 additions and 20 deletions

View File

@ -29,6 +29,15 @@ func (this *apiComp) Battlefinish(session comm.IUserSession, req *pb.WorldtaskBa
return return
} }
battleConf, err := this.module.configure.getWorldtaskBattleCfg()
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Title: pb.ErrorCode_ConfigNoFound.ToString(),
}
return
}
uid := session.GetUserId() uid := session.GetUserId()
taskConf, err := this.module.configure.getWorldtaskById(req.TaskId) taskConf, err := this.module.configure.getWorldtaskById(req.TaskId)
if err != nil || taskConf == nil { if err != nil || taskConf == nil {
@ -81,7 +90,7 @@ func (this *apiComp) Battlefinish(session comm.IUserSession, req *pb.WorldtaskBa
var isWin bool var isWin bool
if errdata, isWin = ibattle.CheckBattleReport(session, req.Report); errdata == nil { if errdata, isWin = ibattle.CheckBattleReport(session, req.Report); errdata == nil {
if isWin { if isWin {
if battleConf, ok := this.module.worldBattleConf.GetDataMap()[req.BattleConfId]; ok { if battleConf, ok := battleConf.GetDataMap()[req.BattleConfId]; ok {
if errdata = this.module.DispenseRes(session, []*cfg.Gameatn{battleConf.Playexp}, true); errdata != nil { if errdata = this.module.DispenseRes(session, []*cfg.Gameatn{battleConf.Playexp}, true); errdata != nil {
this.module.Error("世界任务战斗玩家经验结算", this.module.Error("世界任务战斗玩家经验结算",
log.Field{Key: "uid", Value: uid}, log.Field{Key: "uid", Value: uid},

View File

@ -12,6 +12,7 @@ const (
gameWorldTask = "game_worldtask.json" gameWorldTask = "game_worldtask.json"
gameWorldtaskBattle = "game_worldbattle.json" gameWorldtaskBattle = "game_worldbattle.json"
gameWorldAll = "game_worldall.json" gameWorldAll = "game_worldall.json"
gameburiedCond = "game_buriedcondi.json"
) )
type configureComp struct { type configureComp struct {
@ -24,6 +25,7 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp
gameWorldTask: cfg.NewGameWorldTask, gameWorldTask: cfg.NewGameWorldTask,
gameWorldtaskBattle: cfg.NewGameWorldBattle, gameWorldtaskBattle: cfg.NewGameWorldBattle,
gameWorldAll: cfg.NewGameWorldAll, gameWorldAll: cfg.NewGameWorldAll,
gameburiedCond: cfg.NewGameBuriedCondi,
}) })
return return
} }
@ -97,3 +99,19 @@ func (this *configureComp) getWorldtaskBattleById(confId int32) (*cfg.GameWorldB
} }
return nil, fmt.Errorf("GameWorldBattleData config id:%v not found", confId) 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
}

View File

@ -77,9 +77,16 @@ func (this *ModelWorldtask) finishTask(groupId, taskId int32, task *pb.DBWorldta
if task == nil { if task == nil {
return errors.New("worldtask is nil") return errors.New("worldtask is nil")
} }
worldtaskConf, err := this.moduleWorldtask.configure.getWorldtaskCfg()
if err != nil {
this.moduleWorldtask.Errorln(err.Error())
return comm.NewCustomError(pb.ErrorCode_ConfigNoFound)
}
update := map[string]interface{}{} update := map[string]interface{}{}
taskConf := this.moduleWorldtask.worldtaskConf.GetDataMap()[taskId] taskConf := worldtaskConf.GetDataMap()[taskId]
if taskConf == nil { if taskConf == nil {
return comm.NewCustomError(pb.ErrorCode_ConfigNoFound) return comm.NewCustomError(pb.ErrorCode_ConfigNoFound)
} }

View File

@ -1,6 +1,7 @@
package worldtask package worldtask
import ( import (
"fmt"
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/base" "go_dreamfactory/lego/base"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
@ -18,12 +19,10 @@ var moduleName_cn = "世界任务"
type Worldtask struct { type Worldtask struct {
modules.ModuleBase modules.ModuleBase
api *apiComp api *apiComp
service base.IRPCXService service base.IRPCXService
configure *configureComp configure *configureComp
modelWorldtask *ModelWorldtask modelWorldtask *ModelWorldtask
worldtaskConf *cfg.GameWorldTask
worldBattleConf *cfg.GameWorldBattle
} }
func NewModule() core.IModule { func NewModule() core.IModule {
@ -49,15 +48,50 @@ func (this *Worldtask) GetType() core.M_Modules {
func (this *Worldtask) Start() (err error) { func (this *Worldtask) Start() (err error) {
err = this.ModuleBase.Start() err = this.ModuleBase.Start()
if this.worldtaskConf, err = this.configure.getWorldtaskCfg(); err != nil { if err = this.checkWorldtaskConf(); err != nil {
return err
}
if this.worldBattleConf, err = this.configure.getWorldtaskBattleCfg(); err != nil {
return err return err
} }
return return
} }
// 配置文件校验
func (this *Worldtask) checkWorldtaskConf() (err error) {
worldtaskConf, err := this.configure.getWorldtaskCfg()
if err != nil {
return err
}
buriedCondConf, err := this.configure.getBuriedCondCfg()
if err != nil {
return err
}
for _, data := range worldtaskConf.GetDataList() {
// 检查 lock
if data.Lock < 1 {
return fmt.Errorf("taskId:%v lock:%v可能存在问题", data.Key, data.Lock)
}
//检查group
if data.Group <= 0 {
return fmt.Errorf("taskId:%v group:%v可能存在问题", data.Key, data.Group)
}
//检查des
if data.Des < 1 || data.Des > 5 {
return fmt.Errorf("taskId:%v des:%v可能存在问题", data.Key, data.Des)
}
// 检查completetask 是否有效
for _, condId := range data.Completetask {
if condId == 0 {
continue
}
if _, ok := buriedCondConf.GetDataMap()[condId]; !ok {
return fmt.Errorf("taskId:%v completetask:%v可能是无效的ID", data.Key, condId)
}
}
}
this.Debug("check worldtask conf completed")
return
}
// 完成条件通知
func (this *Worldtask) TCondFinishNotify(uid string, conds []*pb.ConIProgress) { func (this *Worldtask) TCondFinishNotify(uid string, conds []*pb.ConIProgress) {
this.Debug("世界任务完成条件通知", log.Field{Key: "uid", Value: uid}, log.Field{Key: "condIds", Value: conds}) this.Debug("世界任务完成条件通知", log.Field{Key: "uid", Value: uid}, log.Field{Key: "condIds", Value: conds})
@ -79,11 +113,17 @@ func (this *Worldtask) TCondFinishNotify(uid string, conds []*pb.ConIProgress) {
return return
} }
worldtaskConf, err := this.configure.getWorldtaskCfg()
if err != nil {
this.Errorln(err.Error())
return
}
var groupId, taskId int32 var groupId, taskId int32
// 检索condId是否是世界任务的完成条件 // 检索condId是否是世界任务的完成条件
finishedCondIds := []int32{} finishedCondIds := []int32{}
for _, c := range this.worldtaskConf.GetDataList() { for _, c := range worldtaskConf.GetDataList() {
for _, v := range c.Completetask { for _, v := range c.Completetask {
for _, cond := range conds { for _, cond := range conds {
if v == cond.Conid { if v == cond.Conid {
@ -196,7 +236,13 @@ func (this *Worldtask) BingoJumpTask(session comm.IUserSession, groupId, taskId
return comm.NewCustomError(pb.ErrorCode_WorldtaskFinihed) return comm.NewCustomError(pb.ErrorCode_WorldtaskFinihed)
} }
taskConf := this.worldtaskConf.GetDataMap()[taskId] worldtaskConf, err := this.configure.getWorldtaskCfg()
if err != nil {
this.Errorln(err.Error())
return comm.NewCustomError(pb.ErrorCode_ConfigNoFound)
}
taskConf := worldtaskConf.GetDataMap()[taskId]
if taskConf == nil { if taskConf == nil {
return comm.NewCustomError(pb.ErrorCode_ConfigNoFound) return comm.NewCustomError(pb.ErrorCode_ConfigNoFound)
} }
@ -206,7 +252,7 @@ func (this *Worldtask) BingoJumpTask(session comm.IUserSession, groupId, taskId
//遍历 //遍历
if taskConf.Ontxe != 0 && taskConf.IdAfter != 0 { if taskConf.Ontxe != 0 && taskConf.IdAfter != 0 {
for _, v := range this.worldtaskConf.GetDataList() { for _, v := range worldtaskConf.GetDataList() {
if v.Group == groupId && v.Key <= taskId && v.Des == 2 { if v.Group == groupId && v.Key <= taskId && v.Des == 2 {
mytask.TaskList = append(mytask.TaskList, v.Key) mytask.TaskList = append(mytask.TaskList, v.Key)
} }
@ -278,14 +324,20 @@ func (this *Worldtask) JumpTaskByTaskId(session comm.IUserSession, taskId int32)
// return comm.NewCustomError(pb.ErrorCode_WorldtaskFinihed) // return comm.NewCustomError(pb.ErrorCode_WorldtaskFinihed)
// } // }
worldtaskConf, err := this.configure.getWorldtaskCfg()
if err != nil {
this.Errorln(err.Error())
return comm.NewCustomError(pb.ErrorCode_ConfigNoFound)
}
// 获取当前bingo的任务配置 // 获取当前bingo的任务配置
taskConf := this.worldtaskConf.GetDataMap()[taskId] taskConf := worldtaskConf.GetDataMap()[taskId]
if taskConf == nil { if taskConf == nil {
return comm.NewCustomError(pb.ErrorCode_ConfigNoFound) return comm.NewCustomError(pb.ErrorCode_ConfigNoFound)
} }
// 返回所有前置任务 // 返回所有前置任务
mytask.TaskList = this.recursionTasks(taskId) mytask.TaskList = this.recursionTasks(worldtaskConf, taskId)
update := map[string]interface{}{ update := map[string]interface{}{
"taskList": mytask.TaskList, "taskList": mytask.TaskList,
@ -416,11 +468,11 @@ func (this *Worldtask) UpdateTaskStatus(uid string, taskId int32) {
} }
} }
func (this *Worldtask) recursionTasks(taskId int32) (taskIds []int32) { func (this *Worldtask) recursionTasks(worldtaskConf *cfg.GameWorldTask, taskId int32) (taskIds []int32) {
if taskConf, ok := this.worldtaskConf.GetDataMap()[taskId]; ok { if taskConf, ok := worldtaskConf.GetDataMap()[taskId]; ok {
preId := taskConf.Ontxe preId := taskConf.Ontxe
for preId > 0 { for preId > 0 {
if tc, ok := this.worldtaskConf.GetDataMap()[preId]; ok { if tc, ok := worldtaskConf.GetDataMap()[preId]; ok {
taskIds = append(taskIds, preId) taskIds = append(taskIds, preId)
preId = tc.Ontxe preId = tc.Ontxe
} }