71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
package enchant
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) ChallengeCheck(session comm.IUserSession, req *pb.EnchantChallengeReq) (errdata *pb.ErrorData) {
|
|
if req.BossType <= 0 || req.Battle == nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// /挑战主线关卡
|
|
func (this *apiComp) Challenge(session comm.IUserSession, req *pb.EnchantChallengeReq) (errdata *pb.ErrorData) {
|
|
|
|
errdata = this.ChallengeCheck(session, req)
|
|
if errdata != nil {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
|
|
cfgData, err := this.module.configure.GetEnchantBossConfigData(req.BossType)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound, // 道具数量不足
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if errdata = this.module.CheckRes(session, cfgData.PsConsume); errdata != nil {
|
|
return
|
|
}
|
|
|
|
errdata, record := this.module.battle.CreatePveBattle(session, &pb.BattlePVEReq{
|
|
Rulesid: cfgData.BattleReadyID,
|
|
Ptype: pb.PlayType_enchant,
|
|
Title: "",
|
|
Format: req.Battle,
|
|
Mformat: cfgData.Boss,
|
|
})
|
|
|
|
if errdata != nil {
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), EnchantChallengeResp, &pb.EnchantChallengeResp{
|
|
Info: &pb.BattleInfo{
|
|
Id: record.Id,
|
|
Title: record.Title,
|
|
Rulesid: record.Battlereadyid,
|
|
Scoregroup: record.Scoregroup,
|
|
Btype: record.Btype,
|
|
Ptype: record.Ptype,
|
|
RedCompId: record.RedCompId,
|
|
Redflist: record.Redflist,
|
|
BlueCompId: record.BlueCompId,
|
|
Buleflist: record.Buleflist,
|
|
Tasks: record.Tasks,
|
|
},
|
|
BossType: req.BossType,
|
|
})
|
|
|
|
return
|
|
}
|