章节数据校验
This commit is contained in:
parent
e4575d22c5
commit
6089131bf0
@ -5,11 +5,12 @@ import (
|
||||
"go_dreamfactory/pb"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
//参数校验
|
||||
func (this *apiComp) CleanStageCheck(session comm.IUserSession, req *pb.MlineCleanStageReq) (code pb.ErrorCode) {
|
||||
func (this *apiComp) ChallengeCheck(session comm.IUserSession, req *pb.MlineChallengeReq) (code pb.ErrorCode) {
|
||||
if req.StageId == 0 {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
}
|
||||
@ -17,14 +18,15 @@ func (this *apiComp) CleanStageCheck(session comm.IUserSession, req *pb.MlineCle
|
||||
}
|
||||
|
||||
///挑战主线关卡
|
||||
func (this *apiComp) CleanStage(session comm.IUserSession, req *pb.MlineCleanStageReq) (code pb.ErrorCode, data proto.Message) {
|
||||
func (this *apiComp) Challenge(session comm.IUserSession, req *pb.MlineChallengeReq) (code pb.ErrorCode, data proto.Message) {
|
||||
var (
|
||||
curChapter *pb.DBMline // 当前章节信息
|
||||
ps int32 // 消耗的体力
|
||||
psAnt *cfg.Gameatn
|
||||
stageConf *cfg.GameMainStageData
|
||||
rsp *pb.MlineCleanStageResp
|
||||
)
|
||||
rsp = &pb.MlineCleanStageResp{}
|
||||
if code = this.CleanStageCheck(session, req); code != pb.ErrorCode_Success {
|
||||
|
||||
if code = this.ChallengeCheck(session, req); code != pb.ErrorCode_Success {
|
||||
return // 参数校验失败直接返回
|
||||
}
|
||||
if stageConf = this.module.configure.GetMainStageConf(req.StageId); stageConf == nil { // 配置文件校验
|
||||
@ -40,26 +42,91 @@ func (this *apiComp) CleanStage(session comm.IUserSession, req *pb.MlineCleanSta
|
||||
}
|
||||
}
|
||||
if curChapter == nil { // 校验是不是新的数据
|
||||
code = pb.ErrorCode_MainlineNotFindChapter
|
||||
return
|
||||
}
|
||||
if v, ok := curChapter.Star[req.StageId]; !ok || v < 3 {
|
||||
code = pb.ErrorCode_MainlineNoEnoughStar
|
||||
return
|
||||
}
|
||||
if code = this.module.DispenseRes(session, stageConf.Commonaward, true); code != pb.ErrorCode_Success {
|
||||
this.module.Debugf("Mline Clean DispenseRes err:+%v", stageConf.Commonaward)
|
||||
return
|
||||
}
|
||||
rsp.StageId = req.StageId
|
||||
for _, v := range stageConf.Commonaward {
|
||||
rsp.Reward = append(rsp.Reward, &pb.UserAssets{
|
||||
A: v.A,
|
||||
T: v.T,
|
||||
N: v.N,
|
||||
})
|
||||
if stageConf.Previoustage == 0 { // 创建一条新的章节数据
|
||||
// 新章节数据校验
|
||||
chapter := this.module.configure.GetPreMainChapter(req.StageId)
|
||||
bCheck := false
|
||||
if chapter == 0 {
|
||||
bCheck = true
|
||||
} else {
|
||||
for _, v := range list {
|
||||
if chapter == v.ChapterId { // 有上一章节数据
|
||||
// 获取该章节最后一关卡ID
|
||||
stage := this.module.configure.GetLastStageIDByChapter(chapter)
|
||||
if _, ok := v.Star[stage]; ok {
|
||||
bCheck = true
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if bCheck {
|
||||
newData := &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{},
|
||||
}
|
||||
this.module.modelMline.addNewChapter(session.GetUserId(), newData)
|
||||
} else {
|
||||
code = pb.ErrorCode_MainlineNotFindChapter
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
session.SendMsg(string(this.module.GetType()), MlineChallengeResp, rsp)
|
||||
if v, ok := curChapter.Ps[req.StageId]; ok && v > 0 {
|
||||
if v != 0 { // 扣1点
|
||||
if code = this.module.ConsumeRes(session, stageConf.PsMg, true); code != pb.ErrorCode_Success { // 扣1点
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
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 code = this.module.ConsumeRes(session, []*cfg.Gameatn{psAnt}, true); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
|
||||
curChapter.Ps[req.StageId] = ps
|
||||
|
||||
this.module.modelMline.modifyMlineData(session.GetUserId(), curChapter.Id, map[string]interface{}{
|
||||
"ps": curChapter.Ps,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
code, record := this.module.battle.CreatePveBattle(session, &pb.BattlePVEReq{
|
||||
Ptype: pb.PlayType_mainline,
|
||||
Title: "",
|
||||
Format: req.Battle,
|
||||
Mformat: stageConf.FormatList,
|
||||
})
|
||||
if code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
session.SendMsg(string(this.module.GetType()), MlineChallengeResp, &pb.MlineChallengeResp{
|
||||
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},
|
||||
StageId: req.StageId,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
@ -5,12 +5,11 @@ import (
|
||||
"go_dreamfactory/pb"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
//参数校验
|
||||
func (this *apiComp) ChallengeCheck(session comm.IUserSession, req *pb.MlineChallengeReq) (code pb.ErrorCode) {
|
||||
func (this *apiComp) CleanStageCheck(session comm.IUserSession, req *pb.MlineCleanStageReq) (code pb.ErrorCode) {
|
||||
if req.StageId == 0 {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
}
|
||||
@ -18,15 +17,14 @@ func (this *apiComp) ChallengeCheck(session comm.IUserSession, req *pb.MlineChal
|
||||
}
|
||||
|
||||
///挑战主线关卡
|
||||
func (this *apiComp) Challenge(session comm.IUserSession, req *pb.MlineChallengeReq) (code pb.ErrorCode, data proto.Message) {
|
||||
func (this *apiComp) CleanStage(session comm.IUserSession, req *pb.MlineCleanStageReq) (code pb.ErrorCode, data proto.Message) {
|
||||
var (
|
||||
curChapter *pb.DBMline // 当前章节信息
|
||||
ps int32 // 消耗的体力
|
||||
psAnt *cfg.Gameatn
|
||||
stageConf *cfg.GameMainStageData
|
||||
rsp *pb.MlineCleanStageResp
|
||||
)
|
||||
|
||||
if code = this.ChallengeCheck(session, req); code != pb.ErrorCode_Success {
|
||||
rsp = &pb.MlineCleanStageResp{}
|
||||
if code = this.CleanStageCheck(session, req); code != pb.ErrorCode_Success {
|
||||
return // 参数校验失败直接返回
|
||||
}
|
||||
if stageConf = this.module.configure.GetMainStageConf(req.StageId); stageConf == nil { // 配置文件校验
|
||||
@ -42,71 +40,26 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.MlineChallenge
|
||||
}
|
||||
}
|
||||
if curChapter == nil { // 校验是不是新的数据
|
||||
if stageConf.Previoustage == 0 { // 创建一条新的章节数据
|
||||
newData := &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{},
|
||||
}
|
||||
this.module.modelMline.addNewChapter(session.GetUserId(), newData)
|
||||
}
|
||||
}
|
||||
|
||||
if v, ok := curChapter.Ps[req.StageId]; ok {
|
||||
if v != 0 { // 扣1点
|
||||
if code = this.module.ConsumeRes(session, stageConf.PsMg, true); code != pb.ErrorCode_Success { // 扣1点
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
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 code = this.module.ConsumeRes(session, []*cfg.Gameatn{psAnt}, true); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
|
||||
curChapter.Ps[req.StageId] = ps
|
||||
|
||||
err := this.module.modelMline.modifyMlineData(session.GetUserId(), curChapter.Id, map[string]interface{}{
|
||||
"ps": curChapter.Ps,
|
||||
})
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
code, record := this.module.battle.CreatePveBattle(session, &pb.BattlePVEReq{
|
||||
Ptype: pb.PlayType_mainline,
|
||||
Title: "",
|
||||
Format: req.Battle,
|
||||
Mformat: stageConf.FormatList,
|
||||
})
|
||||
if code != pb.ErrorCode_Success {
|
||||
code = pb.ErrorCode_MainlineNotFindChapter
|
||||
return
|
||||
}
|
||||
session.SendMsg(string(this.module.GetType()), MlineChallengeResp, &pb.MlineChallengeResp{
|
||||
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},
|
||||
StageId: req.StageId,
|
||||
})
|
||||
if v, ok := curChapter.Star[req.StageId]; !ok || v < 3 {
|
||||
code = pb.ErrorCode_MainlineNoEnoughStar
|
||||
return
|
||||
}
|
||||
if code = this.module.DispenseRes(session, stageConf.Commonaward, true); code != pb.ErrorCode_Success {
|
||||
this.module.Debugf("Mline Clean DispenseRes err:+%v", stageConf.Commonaward)
|
||||
return
|
||||
}
|
||||
rsp.StageId = req.StageId
|
||||
for _, v := range stageConf.Commonaward {
|
||||
rsp.Reward = append(rsp.Reward, &pb.UserAssets{
|
||||
A: v.A,
|
||||
T: v.T,
|
||||
N: v.N,
|
||||
})
|
||||
}
|
||||
|
||||
session.SendMsg(string(this.module.GetType()), MlineChallengeResp, rsp)
|
||||
return
|
||||
}
|
||||
|
@ -4,12 +4,15 @@ import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
//参数校验
|
||||
func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.MlineGetListReq) (code pb.ErrorCode) {
|
||||
|
||||
if req.CType == 0 {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@ -32,6 +35,26 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.MlineGetListReq)
|
||||
rsp.Data = append(rsp.Data, v)
|
||||
}
|
||||
}
|
||||
if len(rsp.Data) == 0 { // 什么数据都没有 创建一条
|
||||
stageConf := this.module.configure.GetFirstStageIDByChapter(req.CType)
|
||||
if stageConf != nil { // 配置文件校验
|
||||
newData := &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{},
|
||||
}
|
||||
rsp.Data = append(rsp.Data, newData)
|
||||
this.module.modelMline.addNewChapter(session.GetUserId(), newData)
|
||||
} else {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
session.SendMsg(string(this.module.GetType()), MlineGetListResp, rsp)
|
||||
return
|
||||
|
@ -72,3 +72,59 @@ func (this *configureComp) GetMainStageConf(id int32) (data *cfg.GameMainStageDa
|
||||
this.module.Errorf("GameMainStageData conf not found key :%d", id)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取上一章节信息
|
||||
func (this *configureComp) GetPreMainChapter(id int32) (stageID int32) {
|
||||
|
||||
if v, err := this.GetConfigure(game_mainchapter); err == nil {
|
||||
if configure, ok := v.(*cfg.GameMainChapter); ok {
|
||||
for index, v1 := range configure.GetDataList() {
|
||||
if v1.Id == id {
|
||||
if index > 0 {
|
||||
data := configure.GetDataList()[index-1]
|
||||
if v1.ChapterType != data.ChapterType { // 章节类型必须一致
|
||||
stageID = data.Id
|
||||
}
|
||||
} else { // 第一章节
|
||||
stageID = 0
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 获取该章节最后一关ID
|
||||
func (this *configureComp) GetLastStageIDByChapter(id int32) (stageID int32) {
|
||||
var (
|
||||
sz []int32
|
||||
)
|
||||
if v, err := this.GetConfigure(game_mainstage); err == nil {
|
||||
if configure, ok := v.(*cfg.GameMainStage); ok {
|
||||
for _, v := range configure.GetDataList() {
|
||||
if v.Chapterid == id {
|
||||
sz = append(sz, v.Id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(sz) > 0 {
|
||||
stageID = sz[len(sz)-1]
|
||||
}
|
||||
|
||||
return stageID
|
||||
}
|
||||
func (this *configureComp) GetFirstStageIDByChapter(iType int32) *cfg.GameMainStageData {
|
||||
if v, err := this.GetConfigure(game_mainstage); err == nil {
|
||||
if configure, ok := v.(*cfg.GameMainStage); ok {
|
||||
for _, v := range configure.GetDataList() {
|
||||
if v.Episodetype == iType {
|
||||
return v
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user