From a60b77f2a972090b194d1654838a1d22d2c1d4d3 Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Wed, 7 Jun 2023 11:24:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=A0=A1=E9=AA=8C=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/worldtask/api_battlefinish.go | 11 +++- modules/worldtask/configure.go | 18 ++++++ modules/worldtask/model_worldtask.go | 9 ++- modules/worldtask/module.go | 88 +++++++++++++++++++++------ 4 files changed, 106 insertions(+), 20 deletions(-) diff --git a/modules/worldtask/api_battlefinish.go b/modules/worldtask/api_battlefinish.go index 4338cbba9..49df25c94 100644 --- a/modules/worldtask/api_battlefinish.go +++ b/modules/worldtask/api_battlefinish.go @@ -29,6 +29,15 @@ func (this *apiComp) Battlefinish(session comm.IUserSession, req *pb.WorldtaskBa 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() taskConf, err := this.module.configure.getWorldtaskById(req.TaskId) if err != nil || taskConf == nil { @@ -81,7 +90,7 @@ func (this *apiComp) Battlefinish(session comm.IUserSession, req *pb.WorldtaskBa var isWin bool if errdata, isWin = ibattle.CheckBattleReport(session, req.Report); errdata == nil { 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 { this.module.Error("世界任务战斗玩家经验结算", log.Field{Key: "uid", Value: uid}, diff --git a/modules/worldtask/configure.go b/modules/worldtask/configure.go index 20bbf8135..640f32cd5 100644 --- a/modules/worldtask/configure.go +++ b/modules/worldtask/configure.go @@ -12,6 +12,7 @@ const ( gameWorldTask = "game_worldtask.json" gameWorldtaskBattle = "game_worldbattle.json" gameWorldAll = "game_worldall.json" + gameburiedCond = "game_buriedcondi.json" ) type configureComp struct { @@ -24,6 +25,7 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp gameWorldTask: cfg.NewGameWorldTask, gameWorldtaskBattle: cfg.NewGameWorldBattle, gameWorldAll: cfg.NewGameWorldAll, + gameburiedCond: cfg.NewGameBuriedCondi, }) return } @@ -97,3 +99,19 @@ func (this *configureComp) getWorldtaskBattleById(confId int32) (*cfg.GameWorldB } 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 +} diff --git a/modules/worldtask/model_worldtask.go b/modules/worldtask/model_worldtask.go index b2fecbc72..b20e45ae5 100644 --- a/modules/worldtask/model_worldtask.go +++ b/modules/worldtask/model_worldtask.go @@ -77,9 +77,16 @@ func (this *ModelWorldtask) finishTask(groupId, taskId int32, task *pb.DBWorldta if task == 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{}{} - taskConf := this.moduleWorldtask.worldtaskConf.GetDataMap()[taskId] + taskConf := worldtaskConf.GetDataMap()[taskId] if taskConf == nil { return comm.NewCustomError(pb.ErrorCode_ConfigNoFound) } diff --git a/modules/worldtask/module.go b/modules/worldtask/module.go index 0b3747521..e1899ca01 100644 --- a/modules/worldtask/module.go +++ b/modules/worldtask/module.go @@ -1,6 +1,7 @@ package worldtask import ( + "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" @@ -18,12 +19,10 @@ var moduleName_cn = "世界任务" type Worldtask struct { modules.ModuleBase - api *apiComp - service base.IRPCXService - configure *configureComp - modelWorldtask *ModelWorldtask - worldtaskConf *cfg.GameWorldTask - worldBattleConf *cfg.GameWorldBattle + api *apiComp + service base.IRPCXService + configure *configureComp + modelWorldtask *ModelWorldtask } func NewModule() core.IModule { @@ -49,15 +48,50 @@ func (this *Worldtask) GetType() core.M_Modules { func (this *Worldtask) Start() (err error) { err = this.ModuleBase.Start() - if this.worldtaskConf, err = this.configure.getWorldtaskCfg(); err != nil { - return err - } - if this.worldBattleConf, err = this.configure.getWorldtaskBattleCfg(); err != nil { + if err = this.checkWorldtaskConf(); err != nil { return err } 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) { 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 } + worldtaskConf, err := this.configure.getWorldtaskCfg() + if err != nil { + this.Errorln(err.Error()) + return + } + var groupId, taskId int32 // 检索condId是否是世界任务的完成条件 finishedCondIds := []int32{} - for _, c := range this.worldtaskConf.GetDataList() { + for _, c := range worldtaskConf.GetDataList() { for _, v := range c.Completetask { for _, cond := range conds { if v == cond.Conid { @@ -196,7 +236,13 @@ func (this *Worldtask) BingoJumpTask(session comm.IUserSession, groupId, taskId 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 { 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 { - for _, v := range this.worldtaskConf.GetDataList() { + for _, v := range worldtaskConf.GetDataList() { if v.Group == groupId && v.Key <= taskId && v.Des == 2 { 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) // } + worldtaskConf, err := this.configure.getWorldtaskCfg() + if err != nil { + this.Errorln(err.Error()) + return comm.NewCustomError(pb.ErrorCode_ConfigNoFound) + } + // 获取当前bingo的任务配置 - taskConf := this.worldtaskConf.GetDataMap()[taskId] + taskConf := worldtaskConf.GetDataMap()[taskId] if taskConf == nil { return comm.NewCustomError(pb.ErrorCode_ConfigNoFound) } // 返回所有前置任务 - mytask.TaskList = this.recursionTasks(taskId) + mytask.TaskList = this.recursionTasks(worldtaskConf, taskId) update := map[string]interface{}{ "taskList": mytask.TaskList, @@ -416,11 +468,11 @@ func (this *Worldtask) UpdateTaskStatus(uid string, taskId int32) { } } -func (this *Worldtask) recursionTasks(taskId int32) (taskIds []int32) { - if taskConf, ok := this.worldtaskConf.GetDataMap()[taskId]; ok { +func (this *Worldtask) recursionTasks(worldtaskConf *cfg.GameWorldTask, taskId int32) (taskIds []int32) { + if taskConf, ok := worldtaskConf.GetDataMap()[taskId]; ok { preId := taskConf.Ontxe for preId > 0 { - if tc, ok := this.worldtaskConf.GetDataMap()[preId]; ok { + if tc, ok := worldtaskConf.GetDataMap()[preId]; ok { taskIds = append(taskIds, preId) preId = tc.Ontxe }