143 lines
4.3 KiB
Go
143 lines
4.3 KiB
Go
package pagoda
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.PagodaChallengeOverReq) (code pb.ErrorCode) {
|
|
if req.LevelID <= 0 && req.PagodaType != 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
///挑战主线关卡
|
|
func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.PagodaChallengeOverReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
mapData map[string]interface{}
|
|
)
|
|
mapData = make(map[string]interface{}, 0)
|
|
code = this.ChallengeOverCheck(session, req)
|
|
if code != pb.ErrorCode_Success {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
|
|
pagoda, err := this.module.modelPagoda.getPagodaList(session.GetUserId())
|
|
if err != nil {
|
|
code = pb.ErrorCode_PagodaNotFound
|
|
return
|
|
}
|
|
cfg := this.module.configure.GetPagodaConfigData(req.PagodaType, req.LevelID)
|
|
if cfg == nil {
|
|
code = pb.ErrorCode_PagodaNotFound
|
|
return
|
|
}
|
|
if req.PagodaType == comm.PagodaType { // 普通塔
|
|
|
|
if pagoda.Type != cfg.PagodaType || cfg.PreLevel != pagoda.PagodaId {
|
|
code = pb.ErrorCode_PagodaLevlErr // 挑战关卡数据不匹配
|
|
return
|
|
}
|
|
|
|
//// todo 战斗相关
|
|
|
|
pagoda.Type = req.PagodaType
|
|
mapData["pagodaId"] = cfg.LayerNum
|
|
mapData["type"] = pagoda.Type
|
|
|
|
this.module.modulerank.ChangeUserRank(session.GetUserId(), mapData)
|
|
|
|
// 通关奖励
|
|
code = this.module.DispenseRes(session, cfg.Reward, true)
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
pagoda.PagodaId = cfg.LayerNum // 更新层数
|
|
mapData["pagodaId"] = cfg.LayerNum
|
|
code = this.module.ModifyPagodaData(session.GetUserId(), mapData)
|
|
session.SendMsg(string(this.module.GetType()), PagodaChallengeOverResp, &pb.PagodaChallengeOverResp{Data: pagoda})
|
|
return
|
|
} else {
|
|
// 普通塔通关了
|
|
Nomalcfg := this.module.configure.GetPagodaConfigData(comm.PagodaType, pagoda.PagodaId+1)
|
|
if Nomalcfg != nil {
|
|
code = pb.ErrorCode_PagodaNotFound
|
|
return
|
|
}
|
|
|
|
// 塔数据校验
|
|
seasonPagoda, _ := this.module.modelSeasonPagoda.getSeasonPagodaList(session.GetUserId())
|
|
|
|
if seasonPagoda == nil {
|
|
if req.LevelID != 1 {
|
|
code = pb.ErrorCode_PagodaLevlErr // 挑战关卡数据不匹配
|
|
return
|
|
}
|
|
} else {
|
|
if seasonPagoda.Type != req.PagodaType || cfg.PreLevel != seasonPagoda.PagodaId {
|
|
code = pb.ErrorCode_PagodaLevlErr // 挑战关卡数据不匹配
|
|
return
|
|
}
|
|
}
|
|
// 挑战处理
|
|
if seasonPagoda == nil {
|
|
seasonPagoda = &pb.DBSeasonPagoda{}
|
|
seasonPagoda.Id = primitive.NewObjectID().Hex()
|
|
|
|
seasonPagoda.Uid = session.GetUserId()
|
|
seasonPagoda.PagodaId = 1 // 初始数据1层
|
|
seasonPagoda.Type = req.PagodaType
|
|
this.module.modelSeasonPagoda.addNewSeasonPagoda(session.GetUserId(), seasonPagoda)
|
|
|
|
} else {
|
|
seasonPagoda.PagodaId = cfg.LayerNum
|
|
mapData["pagodaId"] = cfg.LayerNum
|
|
code = this.module.ModifySeasonPagodaData(session.GetUserId(), mapData)
|
|
}
|
|
|
|
rst, _ := this.module.modulerank.GetUserRandData(session.GetUserId())
|
|
if rst.Uid == "" {
|
|
rst.Uid = session.GetUserId()
|
|
rst.Id = primitive.NewObjectID().Hex()
|
|
rst.Type = req.PagodaType
|
|
rst.Nickname = this.module.ModuleUser.GetUser(session.GetUserId()).Name
|
|
rst.Lv = this.module.ModuleUser.GetUser(session.GetUserId()).Lv
|
|
rst.PagodaId = pagoda.PagodaId
|
|
this.module.modulerank.AddRank(session.GetUserId(), rst)
|
|
} else {
|
|
if req.Report != nil && len(req.Report.Info.Redflist) > 0 {
|
|
sz := make([]*pb.LineUp, 5)
|
|
for i, v := range req.Report.Info.Redflist[0].Team {
|
|
if v != nil {
|
|
sz[i] = &pb.LineUp{
|
|
Cid: v.HeroID,
|
|
Star: v.Star,
|
|
Lv: v.Lv,
|
|
}
|
|
}
|
|
}
|
|
|
|
this.module.modulerank.updatePagodaRankList(session, seasonPagoda, req.Report.Info.Redflist[0].Leadpos, sz)
|
|
}
|
|
mapData["pagodaId"] = cfg.LayerNum
|
|
this.module.modulerank.ChangeUserRank(session.GetUserId(), mapData)
|
|
}
|
|
pagoda.PagodaId = seasonPagoda.PagodaId
|
|
pagoda.Type = seasonPagoda.Type
|
|
pagoda.Reward = seasonPagoda.Reward
|
|
session.SendMsg(string(this.module.GetType()), PagodaChallengeOverResp, &pb.PagodaChallengeOverResp{Data: pagoda})
|
|
}
|
|
|
|
if req.PagodaType == comm.PagodaType {
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype58, 1)
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype59, pagoda.PagodaId)
|
|
}
|
|
return
|
|
}
|