74 lines
2.0 KiB
Go
74 lines
2.0 KiB
Go
package mainline
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) ChallengeCheck(session comm.IUserSession, req *pb.MainlineChallengeReq) (code pb.ErrorCode) {
|
|
if req.MainlineId == 0 || req.ChapterObj == "" || req.Leadpos >= 5 || len(req.Teamids) != 5 || req.Leadpos < 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
///挑战主线关卡
|
|
func (this *apiComp) Challenge(session comm.IUserSession, req *pb.MainlineChallengeReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
curChapter *pb.DBMainline // 当前章节信息
|
|
)
|
|
|
|
code = this.ChallengeCheck(session, req)
|
|
if code != pb.ErrorCode_Success {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
// 校验关卡存不存在
|
|
curChapter = this.module.modelMainline.getOneChapterInfo(session.GetUserId(), req.ChapterObj)
|
|
if curChapter == nil {
|
|
code = pb.ErrorCode_MainlineNotFound
|
|
return
|
|
}
|
|
|
|
node := this.module.configure.GetMainlineConfigData(int32(req.MainlineId), curChapter.Intensity)
|
|
if node == nil { // 配置文件校验
|
|
code = pb.ErrorCode_MainlineNotFindChapter
|
|
return
|
|
}
|
|
|
|
for _, v := range curChapter.BranchID {
|
|
if v == int32(req.MainlineId) { // 重复挑战
|
|
code = pb.ErrorCode_MainlineNotFindChapter
|
|
return
|
|
}
|
|
}
|
|
|
|
if node.Previoustage != curChapter.MainlineId {
|
|
code = pb.ErrorCode_MainlineNotFindChapter
|
|
return
|
|
}
|
|
|
|
code, record := this.module.battle.CreatePveBattle(session, &pb.BattlePVEReq{
|
|
Ptype: pb.PlayType_moonfantasy,
|
|
Leadpos: req.Leadpos,
|
|
Teamids: req.Teamids,
|
|
Mformat: node.FormatList,
|
|
})
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), MainlineChallengeResp, &pb.MainlineChallengeResp{Info: &pb.BattleInfo{
|
|
Id: record.Id,
|
|
Btype: record.Btype,
|
|
Ptype: record.Ptype,
|
|
RedCompId: record.RedCompId,
|
|
Redflist: record.Redflist,
|
|
BlueCompId: record.BlueCompId,
|
|
Buleflist: record.Buleflist,
|
|
}})
|
|
return
|
|
}
|