go_dreamfactory/modules/integral/api_challenge.go
2024-01-02 17:13:14 +08:00

87 lines
2.3 KiB
Go

package integral
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
)
// 参数校验
func (this *apiComp) ChallengeCheck(session comm.IUserSession, req *pb.IntegralChallengeReq) (errdata *pb.ErrorData) {
if req.Nandu <= 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.IntegralChallengeReq) (errdata *pb.ErrorData) {
var (
dibuff []int32
)
errdata = this.ChallengeCheck(session, req)
if errdata != nil {
return // 参数校验失败直接返回
}
list, err := this.module.modelIntegral.getIntegralList(session)
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_PagodaNotFound, // 道具数量不足
Title: pb.ErrorCode_PagodaNotFound.ToString(),
}
return
}
cfgData, err := this.module.configure.GetStageBoss(list.Hid, req.Nandu)
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound, // 道具数量不足
Title: pb.ErrorCode_ConfigNoFound.ToString(),
Message: err.Error(),
}
return
}
// 校验门票 最大值等配置
if list.Count >= this.module.ModuleTools.GetGlobalConf().IntegralBossChallengeNum {
errdata = &pb.ErrorData{ // 不能挑战了
Code: pb.ErrorCode_TntegralDayMaxChallenge,
Title: pb.ErrorCode_TntegralDayMaxChallenge.ToString(),
}
return
}
for k := range list.Buff {
dibuff = append(dibuff, k)
}
errdata, record := this.module.battle.CreateDebuffBattle(session, &pb.BattlePVEReq{
Rulesid: cfgData.BattleReadyID,
Ptype: pb.PlayType_integral,
Title: "",
Format: req.Battle,
Mformat: cfgData.Boss,
}, dibuff)
if errdata != nil {
return
}
session.SendMsg(string(this.module.GetType()), "challenge", &pb.IntegralChallengeResp{
Info: &pb.BattleInfo{Id: record.Id,
Title: record.Title,
Rulesid: cfgData.BattleReadyID,
Btype: record.Btype,
Ptype: record.Ptype,
RedCompId: record.RedCompId,
Redflist: record.Redflist,
BlueCompId: record.BlueCompId,
Buleflist: record.Buleflist,
Tasks: record.Tasks,
Params: []float32{cfgData.Coefficient}, // 伤害系数
},
Nandu: req.Nandu,
})
return
}