go_dreamfactory/modules/oldtimes/api_getall.go
2023-05-24 14:57:29 +08:00

91 lines
2.4 KiB
Go

package oldtimes
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
)
func (this *apiComp) GetallCheck(session comm.IUserSession, req *pb.OldtimesGetallReq) (code pb.ErrorCode) {
return
}
func (this *apiComp) Getall(session comm.IUserSession, req *pb.OldtimesGetallReq) (code pb.ErrorCode, data *pb.ErrorData) {
uid := session.GetUserId()
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) {
level.Status = int32(finish)
if err := this.module.modelOldtimes.updateOldtimes(uid, d); err != nil {
this.module.Error("oldtime更新失败",
log.Field{Key: "uid", Value: uid})
continue
}
unlockLevelIds = append(unlockLevelIds, level.Lid)
}
}
}
}
}
}
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
}