89 lines
2.0 KiB
Go
89 lines
2.0 KiB
Go
package pagoda
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) ChallengeCheck(session comm.IUserSession, req *pb.PagodaChallengeReq) (errdata *pb.ErrorData) {
|
|
if req.Cid <= 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
///挑战主线关卡
|
|
func (this *apiComp) Challenge(session comm.IUserSession, req *pb.PagodaChallengeReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
pagoda *pb.DBPagoda
|
|
err error
|
|
)
|
|
code = this.ChallengeCheck(session, req)
|
|
if errdata != nil {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
|
|
conf := this.module.configure.GetPagodaConfigData(req.Cid)
|
|
if conf == nil {
|
|
code = pb.ErrorCode_PagodaNotFound
|
|
return
|
|
}
|
|
|
|
pagoda, err = this.module.modelPagoda.getPagodaList(session.GetUserId())
|
|
if err != nil {
|
|
code = pb.ErrorCode_PagodaNotFound
|
|
return
|
|
}
|
|
|
|
if v, ok := pagoda.Data[conf.Tab]; !ok {
|
|
if conf.LayerNum == 1 {
|
|
pagoda.Data[conf.Tab] = 0
|
|
} else {
|
|
code = pb.ErrorCode_PagodaLevlErr // 挑战关卡数据不匹配
|
|
return
|
|
}
|
|
} else {
|
|
if conf.LayerNum-1 != v {
|
|
code = pb.ErrorCode_PagodaLevlErr // 挑战关卡数据不匹配
|
|
return
|
|
}
|
|
}
|
|
|
|
// 校验条件
|
|
if conf.Unlock != 0 {
|
|
if !this.mline.CheckCommpleteStage(session.GetUserId(), conf.Unlock) {
|
|
code = pb.ErrorCode_PagodaUnlock
|
|
return
|
|
}
|
|
}
|
|
code, record := this.module.battle.CreatePveBattle(session, &pb.BattlePVEReq{
|
|
Ptype: pb.PlayType_pagoda,
|
|
Title: "",
|
|
Format: req.Battle,
|
|
Mformat: conf.MonsterId,
|
|
})
|
|
if errdata != nil {
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), PagodaChallengeResp, &pb.PagodaChallengeResp{
|
|
Info: &pb.BattleInfo{
|
|
Id: record.Id,
|
|
Title: record.Title,
|
|
Rulesid: conf.BattleReadyID,
|
|
Btype: record.Btype,
|
|
Ptype: record.Ptype,
|
|
RedCompId: record.RedCompId,
|
|
Redflist: record.Redflist,
|
|
BlueCompId: record.BlueCompId,
|
|
Buleflist: record.Buleflist,
|
|
},
|
|
Cid: req.Cid,
|
|
})
|
|
return
|
|
}
|