go_dreamfactory/modules/enchant/api_challenge.go
2022-12-30 10:16:13 +08:00

83 lines
2.2 KiB
Go

package enchant
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"google.golang.org/protobuf/proto"
)
//参数校验
func (this *apiComp) ChallengeCheck(session comm.IUserSession, req *pb.EnchantChallengeReq) (code pb.ErrorCode) {
if req.BossType <= 0 || req.Battle == nil {
code = pb.ErrorCode_ReqParameterError
return
}
return
}
///挑战主线关卡
func (this *apiComp) Challenge(session comm.IUserSession, req *pb.EnchantChallengeReq) (code pb.ErrorCode, data proto.Message) {
code = this.ChallengeCheck(session, req)
if code != pb.ErrorCode_Success {
return // 参数校验失败直接返回
}
enchant, err := this.module.modelEnchant.getEnchantList(session.GetUserId())
if err != nil {
code = pb.ErrorCode_PagodaNotFound
return
}
conf := this.module.configure.GetGlobalConf()
if conf == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
costRes := conf.EnchantbossCos
if costRes == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
if code = this.module.CheckRes(session, []*cfg.Gameatn{costRes}); code != pb.ErrorCode_Success {
code = pb.ErrorCode_EnchantNoChallengeCount
return
}
cfgData := this.module.configure.GetEnchantBossConfigData(req.BossType)
if cfgData == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
_, ok := enchant.Boss[req.BossType]
if !ok { // 类型校验
enchant.Boss[req.BossType] = 0
}
// 获取分数
var score int32
var format []int32
score = int32(enchant.Boss[req.BossType])
for _, v := range cfgData {
if v.ScoreLow <= score && v.ScoreUp >= score {
format = v.Boss
}
}
code, record := this.module.battle.CreatePveBattle(session, &pb.BattlePVEReq{
Ptype: pb.PlayType_enchant,
Title: "",
Format: req.Battle,
Mformat: format,
})
if code != pb.ErrorCode_Success {
return
}
session.SendMsg(string(this.module.GetType()), EnchantChallengeResp, &pb.EnchantChallengeResp{
Info: &pb.BattleInfo{Id: record.Id, Title: record.Title, Btype: record.Btype, Ptype: record.Ptype, RedCompId: record.RedCompId, Redflist: record.Redflist, BlueCompId: record.BlueCompId, Buleflist: record.Buleflist},
BossType: req.BossType,
})
return
}