146 lines
3.9 KiB
Go
146 lines
3.9 KiB
Go
package mline
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) ChallengeCheck(session comm.IUserSession, req *pb.MlineChallengeReq) (errdata *pb.ErrorData) {
|
|
if req.StageId == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// /挑战主线关卡
|
|
func (this *apiComp) Challenge(session comm.IUserSession, req *pb.MlineChallengeReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
curChapter *pb.DBMline // 当前章节信息
|
|
ps int32 // 消耗的体力
|
|
psAnt *cfg.Gameatn
|
|
stageConf *cfg.GameMainStageData // 当前章节数据
|
|
preStageConf *cfg.GameMainStageData // 上一章节数据
|
|
err error
|
|
bNew bool // 是否是新章节
|
|
)
|
|
|
|
if errdata = this.ChallengeCheck(session, req); errdata != nil {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
if stageConf, err = this.module.configure.GetMainStageConf(req.StageId); err != nil { // 配置文件校验
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_MainlineNotFindChapter,
|
|
Title: pb.ErrorCode_MainlineNotFindChapter.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
list, _ := this.module.modelMline.getMainlineList(session.GetUserId())
|
|
for _, v := range list {
|
|
if stageConf.Chapterid == v.ChapterId {
|
|
curChapter = v
|
|
break
|
|
}
|
|
}
|
|
|
|
if stageConf.Previoustage != 0 { // 前置关卡是0 不需要做校验 直接通过
|
|
preStageConf, err = this.module.configure.GetMainStageConf(stageConf.Previoustage)
|
|
if err != nil { // 配置文件校验
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_MainlineNotFindChapter,
|
|
Title: pb.ErrorCode_MainlineNotFindChapter.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
for _, v := range list {
|
|
if preStageConf.Chapterid == v.ChapterId { // 有上一章节数据
|
|
if _, ok := v.Star[preStageConf.Id]; !ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_MainlinePreNotFound,
|
|
Title: pb.ErrorCode_MainlinePreNotFound.ToString(),
|
|
}
|
|
return
|
|
}
|
|
break
|
|
}
|
|
}
|
|
|
|
}
|
|
if curChapter == nil {
|
|
curChapter = &pb.DBMline{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: session.GetUserId(),
|
|
CType: stageConf.Episodetype,
|
|
ChapterId: stageConf.Chapterid,
|
|
StageId: stageConf.Id,
|
|
Star: map[int32]int32{},
|
|
Award: map[int32]bool{},
|
|
Ps: map[int32]int32{},
|
|
}
|
|
bNew = true
|
|
}
|
|
if v1, ok := curChapter.Ps[req.StageId]; !ok || v1 == 0 {
|
|
|
|
for _, v := range stageConf.PsConsume {
|
|
if v.A == "attr" && v.T == "ps" {
|
|
ps += v.N
|
|
}
|
|
}
|
|
for _, v := range stageConf.PsMg {
|
|
if v.A == "attr" && v.T == "ps" {
|
|
ps += v.N
|
|
}
|
|
}
|
|
psAnt = &cfg.Gameatn{ // 构建一个atn 对象
|
|
A: "attr",
|
|
T: "ps",
|
|
N: ps,
|
|
}
|
|
if errdata = this.module.ConsumeRes(session, []*cfg.Gameatn{psAnt}, true); errdata != nil {
|
|
return
|
|
}
|
|
|
|
curChapter.Ps[req.StageId] = ps
|
|
if bNew {
|
|
this.module.modelMline.addNewChapter(session.GetUserId(), curChapter) // 首次打新的章节
|
|
} else {
|
|
this.module.modelMline.modifyMlineData(session.GetUserId(), curChapter.Id, map[string]interface{}{"ps": curChapter.Ps})
|
|
}
|
|
}
|
|
errdata, record := this.module.battle.CreatePveBattle(session, &pb.BattlePVEReq{
|
|
Rulesid: stageConf.BattleReadyID,
|
|
Ptype: pb.PlayType_mainline,
|
|
Title: "",
|
|
Format: req.Battle,
|
|
Mformat: stageConf.FormatList,
|
|
})
|
|
if errdata != nil {
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), MlineChallengeResp, &pb.MlineChallengeResp{
|
|
Info: &pb.BattleInfo{
|
|
Id: record.Id,
|
|
Title: record.Title,
|
|
Rulesid: stageConf.BattleReadyID,
|
|
Btype: record.Btype,
|
|
Ptype: record.Ptype,
|
|
RedCompId: record.RedCompId,
|
|
Redflist: record.Redflist,
|
|
BlueCompId: record.BlueCompId,
|
|
Buleflist: record.Buleflist,
|
|
},
|
|
StageId: req.StageId,
|
|
})
|
|
return
|
|
}
|