go_dreamfactory/modules/viking/api_challenge.go
2022-11-28 19:56:16 +08:00

82 lines
2.2 KiB
Go

package viking
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.VikingChallengeReq) (code pb.ErrorCode) {
if req.BossId <= 0 && req.Difficulty > 0 || 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.VikingChallengeReq) (code pb.ErrorCode, data proto.Message) {
code = this.ChallengeCheck(session, req)
if code != pb.ErrorCode_Success {
return // 参数校验失败直接返回
}
viking, err := this.module.modelViking.getVikingList(session.GetUserId())
if err != nil {
code = pb.ErrorCode_VikingBoosType
return
}
conf := this.module.configure.GetGlobalConf()
if conf == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
costRes := conf.VikingExpeditionCos
if costRes == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
if code = this.module.CheckRes(session, []*cfg.Gameatn{costRes}); code != pb.ErrorCode_Success {
code = pb.ErrorCode_VikingMaxChallengeCount
return
}
cfgData := this.module.configure.GetVikingBossConfigData(req.BossId, req.Difficulty)
if cfgData == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
value, ok := viking.Boss[req.BossId]
if !ok { // 类型校验
viking.Boss[req.BossId] = 0
}
if value < req.Difficulty {
if value+1 != req.Difficulty {
code = pb.ErrorCode_VikingLvErr
return
}
}
code, record := this.module.battle.CreatePveBattle(session, &pb.BattlePVEReq{
Ptype: pb.PlayType_viking,
Title: "",
Format: &pb.BattleFormation{
Leadpos: req.Leadpos,
Format: req.Teamids,
},
Mformat: cfgData.Boss,
})
if code != pb.ErrorCode_Success {
return
}
session.SendMsg(string(this.module.GetType()), VikingChallengeResp, &pb.VikingChallengeResp{
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},
BossId: req.BossId,
Difficulty: req.Difficulty,
})
return
}