diff --git a/modules/oldtimes/api_enter.go b/modules/oldtimes/api_enter.go deleted file mode 100644 index e4e8e7163..000000000 --- a/modules/oldtimes/api_enter.go +++ /dev/null @@ -1,60 +0,0 @@ -package oldtimes - -import ( - "go_dreamfactory/comm" - "go_dreamfactory/pb" -) - -func (this *apiComp) EnterCheck(session comm.IUserSession, req *pb.OldtimesEnterReq) (code pb.ErrorCode) { - if req.ChapterId <= 0 || req.LevelId <= 0 { - code = pb.ErrorCode_ReqParameterError - } - return -} - -func (this *apiComp) Enter(session comm.IUserSession, req *pb.OldtimesEnterReq) (code pb.ErrorCode, data *pb.ErrorData) { - if code = this.EnterCheck(session, req); code != pb.ErrorCode_Success { - return - } - rsp := &pb.OldtimesEnterResp{} - uid := session.GetUserId() - ot := this.module.modelOldtimes.getDBOldtimes(uid) - if ot == nil { - code = pb.ErrorCode_DataNotFound - return - } - - chapter := this.module.modelOldtimes.getChatper(req.ChapterId, ot) - if chapter != nil { - if chapter.Status == int32(finish) { - code = pb.ErrorCode_OldtimesFinished - return - } - - var exist bool - for _, l := range chapter.Levels { - if l.Lid == req.LevelId { - if l.Status == int32(finish) { - code = pb.ErrorCode_OldtimesLevelOver - return - } else { - l.Status = int32(ongoing) - } - exist = true - break - } - } - - if !exist { - chapter.Levels = append(chapter.Levels, &pb.Level{ - Lid: req.LevelId, - Status: int32(unlock), - }) - } - } - - this.module.modelOldtimes.updateOldtimes(uid, ot) - - session.SendMsg(string(this.module.GetType()), "enter", rsp) - return -} diff --git a/modules/oldtimes/api_finish.go b/modules/oldtimes/api_finish.go deleted file mode 100644 index eca2d46d8..000000000 --- a/modules/oldtimes/api_finish.go +++ /dev/null @@ -1,44 +0,0 @@ -package oldtimes - -import ( - "go_dreamfactory/comm" - "go_dreamfactory/pb" -) - -func (this *apiComp) FinishCheck(session comm.IUserSession, req *pb.OldtimesFinishReq) (code pb.ErrorCode) { - if req.ChapterId <= 0 || req.LevelId <= 0 { - code = pb.ErrorCode_ReqParameterError - } - return -} - -func (this *apiComp) Finish(session comm.IUserSession, req *pb.OldtimesFinishReq) (code pb.ErrorCode, data *pb.ErrorData) { - if code = this.FinishCheck(session, req); code != pb.ErrorCode_Success { - return - } - uid := session.GetUserId() - rsp := &pb.OldtimesFinishResp{} - - ot := this.module.modelOldtimes.getDBOldtimes(uid) - if ot == nil { - code = pb.ErrorCode_DataNotFound - return - } - - chapter := this.module.modelOldtimes.getChatper(req.ChapterId, ot) - level := this.module.modelOldtimes.getLevel(req.LevelId, chapter) - if level != nil && level.Status == 3 { - code = pb.ErrorCode_OldtimesLevelOver - return - } - - if !this.module.modelOldtimes.isPreFinished(req.ChapterId, req.LevelId, ot) { - code = pb.ErrorCode_OldtimesPreLevelNoFinished - return - } - - this.module.modelOldtimes.levelFinish(uid, req.ChapterId, req.LevelId, ot) - - session.SendMsg(string(this.module.GetType()), "finish", rsp) - return -} diff --git a/modules/oldtimes/api_getall.go b/modules/oldtimes/api_getall.go index b715b815e..db62a64a6 100644 --- a/modules/oldtimes/api_getall.go +++ b/modules/oldtimes/api_getall.go @@ -16,10 +16,19 @@ func (this *apiComp) Getall(session comm.IUserSession, req *pb.OldtimesGetallReq rsp := &pb.OldtimesGetallResp{} d := this.module.modelOldtimes.getDBOldtimes(uid) + var unlockLevelIds []int32 + // 更新关卡状态 if imodule, err := this.service.GetModule(comm.ModuleCombat); err == nil { if combat, ok := imodule.(comm.ICombat); ok { for _, chapter := range d.Chapters { + if chapter.Status == int32(finish) { + continue + } for _, level := range chapter.Levels { + if level.Status == int32(finish) { + unlockLevelIds = append(unlockLevelIds, level.Lid) + continue + } conf := this.module.configure.getMaintaskCfgBy(level.Lid) if conf != nil { if combat.GetLevelStatus(uid, conf.Stageid) { @@ -28,6 +37,7 @@ func (this *apiComp) Getall(session comm.IUserSession, req *pb.OldtimesGetallReq this.module.Error("oldtime更新失败", log.Field{Key: "uid", Value: uid}) } + unlockLevelIds = append(unlockLevelIds, level.Lid) } } } @@ -35,6 +45,43 @@ func (this *apiComp) Getall(session comm.IUserSession, req *pb.OldtimesGetallReq } } + glmt, err := this.module.configure.getMaintaskCfg() + if err != nil || glmt == nil { + return + } + + // 查询出前置是已完成的任务ID + var levelIds []int32 + for _, conf := range glmt.GetDataList() { + for _, id := range unlockLevelIds { + if conf.SubTask == id { + levelIds = append(levelIds, conf.Id) + } + } + } + + //添加解锁关卡 + for _, lid := range levelIds { + // 判断是否已加入 + if !this.module.modelOldtimes.isExist(lid, d) { + levelConf := this.module.configure.getMaintaskCfgBy(lid) + if levelConf != nil { + chapter := this.module.modelOldtimes.getChatper(levelConf.Group, d) + if chapter != nil { + chapter.Levels = append(chapter.Levels, &pb.Level{Lid: lid}) + } else { + chapter := &pb.Chapter{ + Cid: levelConf.Group, + } + chapter.Levels = append(chapter.Levels, &pb.Level{Lid: lid}) + d.Chapters = append(d.Chapters, chapter) + } + } + } + } + + this.module.modelOldtimes.updateOldtimes(uid, d) + rsp.Data = d session.SendMsg(string(this.module.GetType()), "getall", rsp) return diff --git a/modules/oldtimes/model_oldtimes.go b/modules/oldtimes/model_oldtimes.go index 108217efd..76cf2f984 100644 --- a/modules/oldtimes/model_oldtimes.go +++ b/modules/oldtimes/model_oldtimes.go @@ -121,103 +121,14 @@ func (this *ModelOldtimes) getLevel(levelId int32, chapter *pb.Chapter) *pb.Leve return nil } -func (this *ModelOldtimes) levelFinish(uid string, chapterId, levelId int32, data *pb.DBOldtimes) error { - glmt, err := this.moduleOldtimes.configure.getMaintaskCfg() - if err != nil { - return nil - } - - chapter := this.getChatper(chapterId, data) - if chapter == nil { - return nil - } - - var exist bool - for _, l := range chapter.Levels { - if l.Lid == levelId { - l.Status = int32(finish) - exist = true - break - } - } - - if !exist { - chapter.Levels = append(chapter.Levels, &pb.Level{ - Lid: levelId, - Status: int32(finish), - }) - } - - // 检查章节下的关卡状态 - var flag bool - for _, v := range glmt.GetDataList() { - if v.Group == chapterId { - - for _, l := range chapter.Levels { - if l.Status == int32(finish) && l.Lid == v.Id { - flag = true - } else { - flag = false - } +func (this *ModelOldtimes) isExist(levelId int32, ot *pb.DBOldtimes) bool { + for _, chapter := range ot.Chapters { + for _, level := range chapter.Levels { + if level.Lid == levelId { + return true } } } - - if flag { - chapter.Status = int32(finish) //章节完成 - } - - this.unlockTask(levelId, data) - - this.updateOldtimes(uid, data) - return nil -} - -// 解锁任务 -func (this *ModelOldtimes) unlockTask(levelId int32, ot *pb.DBOldtimes) error { - glmt, err := this.moduleOldtimes.configure.getMaintaskCfg() - if err != nil { - return err - } - - for _, v := range glmt.GetDataList() { - if v.SubTask == levelId { - chapter := this.getChatper(v.Group, ot) - level := this.getLevel(v.Id, chapter) - if level != nil { - level.Status = int32(ongoing) - } else { - if chapter != nil { - chapter.Levels = append(chapter.Levels, &pb.Level{ - Lid: v.Id, - Status: int32(unlock), - }) - } - } - } - } - - return nil -} - -// 前置关卡是否完成 -func (this *ModelOldtimes) isPreFinished(chapterId, levelId int32, ot *pb.DBOldtimes) bool { - glmt, err := this.moduleOldtimes.configure.getMaintaskCfg() - if err != nil { - return false - } - - if conf, ok := glmt.GetDataMap()[levelId]; ok { - if conf.SubTask == 0 { - return true - } - //判断前置关卡状态 - preLevel := this.getLevel(conf.SubTask, this.getChatper(chapterId, ot)) - if preLevel != nil && preLevel.Status == int32(finish) { - return true - } - } - return false } diff --git a/modules/sociaty/api_cross_tasklist.go b/modules/sociaty/api_cross_tasklist.go index 7ce804b6c..c3d8d9a1a 100644 --- a/modules/sociaty/api_cross_tasklist.go +++ b/modules/sociaty/api_cross_tasklist.go @@ -31,6 +31,7 @@ func (this *apiComp) TaskList(session comm.IUserSession, req *pb.SociatyTaskList if _, ok := this.module.modelSociaty.validTask(uid, v.TaskId); ok { status = 1 //完成 } + taskList = append(taskList, &pb.SociatyTask{ TaskId: v.TaskId, Status: status, @@ -38,6 +39,13 @@ func (this *apiComp) TaskList(session comm.IUserSession, req *pb.SociatyTaskList }) } rsp.List = taskList + + if err := this.module.modelSociatyTask.updateTaskList(sociaty.Id, uid, taskList); err != nil { + this.module.Error("更新公会任务列表失败", + log.Field{Key: "uid", Value: uid}, + log.Field{Key: "sociatyId", Value: sociaty.Id}, + log.Field{Key: "err", Value: err.Error()}) + } } if err := session.SendMsg(string(this.module.GetType()), SociatySubTypeTasklist, rsp); err != nil { diff --git a/modules/sociaty/model_sociatytask.go b/modules/sociaty/model_sociatytask.go index e292caa66..b1c3a7bb3 100644 --- a/modules/sociaty/model_sociatytask.go +++ b/modules/sociaty/model_sociatytask.go @@ -59,7 +59,7 @@ func (this *ModelSociatyTask) initSociatyTask(uid, sociatyId string) error { return this.moduleSociaty.modelSociatyTask.AddList(sociatyId, uid, sociatyTask) } -//公会任务列表 +// 公会任务列表 func (this *ModelSociatyTask) getUserTask(uid, sociatyId string) (task *pb.DBSociatyTask) { task = &pb.DBSociatyTask{} this.GetListObj(sociatyId, uid, task) @@ -118,3 +118,11 @@ func (this *ModelSociatyTask) activityReceive(id int32, sociatyId, uid string) e } return nil } + +// 更新任务列表 +func (this *ModelSociatyTask) updateTaskList(sociatyId, uid string, taskList []*pb.SociatyTask) error { + update := map[string]interface{}{ + "taskList": taskList, + } + return this.ChangeList(sociatyId, uid, update) +}