旧时光自动解锁

This commit is contained in:
wh_zcy 2023-04-28 16:51:45 +08:00
parent 5ad4705391
commit 94cca4d515
6 changed files with 69 additions and 199 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -16,10 +16,19 @@ func (this *apiComp) Getall(session comm.IUserSession, req *pb.OldtimesGetallReq
rsp := &pb.OldtimesGetallResp{} rsp := &pb.OldtimesGetallResp{}
d := this.module.modelOldtimes.getDBOldtimes(uid) d := this.module.modelOldtimes.getDBOldtimes(uid)
var unlockLevelIds []int32
// 更新关卡状态
if imodule, err := this.service.GetModule(comm.ModuleCombat); err == nil { if imodule, err := this.service.GetModule(comm.ModuleCombat); err == nil {
if combat, ok := imodule.(comm.ICombat); ok { if combat, ok := imodule.(comm.ICombat); ok {
for _, chapter := range d.Chapters { for _, chapter := range d.Chapters {
if chapter.Status == int32(finish) {
continue
}
for _, level := range chapter.Levels { for _, level := range chapter.Levels {
if level.Status == int32(finish) {
unlockLevelIds = append(unlockLevelIds, level.Lid)
continue
}
conf := this.module.configure.getMaintaskCfgBy(level.Lid) conf := this.module.configure.getMaintaskCfgBy(level.Lid)
if conf != nil { if conf != nil {
if combat.GetLevelStatus(uid, conf.Stageid) { if combat.GetLevelStatus(uid, conf.Stageid) {
@ -28,6 +37,7 @@ func (this *apiComp) Getall(session comm.IUserSession, req *pb.OldtimesGetallReq
this.module.Error("oldtime更新失败", this.module.Error("oldtime更新失败",
log.Field{Key: "uid", Value: uid}) 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 rsp.Data = d
session.SendMsg(string(this.module.GetType()), "getall", rsp) session.SendMsg(string(this.module.GetType()), "getall", rsp)
return return

View File

@ -121,103 +121,14 @@ func (this *ModelOldtimes) getLevel(levelId int32, chapter *pb.Chapter) *pb.Leve
return nil return nil
} }
func (this *ModelOldtimes) levelFinish(uid string, chapterId, levelId int32, data *pb.DBOldtimes) error { func (this *ModelOldtimes) isExist(levelId int32, ot *pb.DBOldtimes) bool {
glmt, err := this.moduleOldtimes.configure.getMaintaskCfg() for _, chapter := range ot.Chapters {
if err != nil { for _, level := range chapter.Levels {
return nil if level.Lid == levelId {
} return true
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
}
} }
} }
} }
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 return false
} }

View File

@ -31,6 +31,7 @@ func (this *apiComp) TaskList(session comm.IUserSession, req *pb.SociatyTaskList
if _, ok := this.module.modelSociaty.validTask(uid, v.TaskId); ok { if _, ok := this.module.modelSociaty.validTask(uid, v.TaskId); ok {
status = 1 //完成 status = 1 //完成
} }
taskList = append(taskList, &pb.SociatyTask{ taskList = append(taskList, &pb.SociatyTask{
TaskId: v.TaskId, TaskId: v.TaskId,
Status: status, Status: status,
@ -38,6 +39,13 @@ func (this *apiComp) TaskList(session comm.IUserSession, req *pb.SociatyTaskList
}) })
} }
rsp.List = taskList 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 { if err := session.SendMsg(string(this.module.GetType()), SociatySubTypeTasklist, rsp); err != nil {

View File

@ -59,7 +59,7 @@ func (this *ModelSociatyTask) initSociatyTask(uid, sociatyId string) error {
return this.moduleSociaty.modelSociatyTask.AddList(sociatyId, uid, sociatyTask) return this.moduleSociaty.modelSociatyTask.AddList(sociatyId, uid, sociatyTask)
} }
//公会任务列表 // 公会任务列表
func (this *ModelSociatyTask) getUserTask(uid, sociatyId string) (task *pb.DBSociatyTask) { func (this *ModelSociatyTask) getUserTask(uid, sociatyId string) (task *pb.DBSociatyTask) {
task = &pb.DBSociatyTask{} task = &pb.DBSociatyTask{}
this.GetListObj(sociatyId, uid, task) this.GetListObj(sociatyId, uid, task)
@ -118,3 +118,11 @@ func (this *ModelSociatyTask) activityReceive(id int32, sociatyId, uid string) e
} }
return nil 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)
}