From 53af65a711c0bcdce890e6e1eef2284d20f34cdf Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Sat, 31 Dec 2022 14:08:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=98=E6=96=97=E5=BC=80=E5=A7=8B=E4=BD=93?= =?UTF-8?q?=E5=8A=9B=E9=A2=84=E6=89=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/mainline/api_challenge.go | 32 +++++++++++++++++++-- modules/mainline/api_challengeover.go | 41 +++++++++++---------------- 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/modules/mainline/api_challenge.go b/modules/mainline/api_challenge.go index 64bd1ccdb..ec05a5064 100644 --- a/modules/mainline/api_challenge.go +++ b/modules/mainline/api_challenge.go @@ -3,6 +3,7 @@ package mainline import ( "go_dreamfactory/comm" "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" "google.golang.org/protobuf/proto" ) @@ -20,6 +21,8 @@ func (this *apiComp) ChallengeCheck(session comm.IUserSession, req *pb.MainlineC func (this *apiComp) Challenge(session comm.IUserSession, req *pb.MainlineChallengeReq) (code pb.ErrorCode, data proto.Message) { var ( curChapter *pb.DBMainline // 当前章节信息 + ps int32 + psAnt *cfg.Gameatn ) code = this.ChallengeCheck(session, req) @@ -50,14 +53,37 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.MainlineChalle } if curChapter.Ps != 0 { - if code = this.module.CheckRes(session, node.PsMg); code != pb.ErrorCode_Success { // 扣1点 + if code = this.module.ConsumeRes(session, node.PsMg, true); code != pb.ErrorCode_Success { // 扣1点 return } } else { - if code = this.module.CheckRes(session, node.PsConsume); code != pb.ErrorCode_Success { + for _, v := range node.PsConsume { + if v.A == "attr" && v.T == "ps" { + ps += v.N + } + } + for _, v := range node.PsMg { + if v.A == "attr" && v.T == "ps" { + ps += v.N + } + } + psAnt = &cfg.Gameatn{ + A: "attr", + T: "ps", + N: ps, + } + if code = this.module.ConsumeRes(session, []*cfg.Gameatn{psAnt}, true); code != pb.ErrorCode_Success { return } - if code = this.module.CheckRes(session, node.PsMg); code != pb.ErrorCode_Success { + + curChapter.Ps = ps + update := map[string]interface{}{ + "ps": ps, + } + + err := this.module.modelMainline.modifyMainlineData(session.GetUserId(), curChapter.Id, update) + if err != nil { + code = pb.ErrorCode_DBError return } } diff --git a/modules/mainline/api_challengeover.go b/modules/mainline/api_challengeover.go index ff58e55c0..0e88e6fee 100644 --- a/modules/mainline/api_challengeover.go +++ b/modules/mainline/api_challengeover.go @@ -48,35 +48,33 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.MainlineCh code = pb.ErrorCode_MainlineNotFindChapter return } - // 消耗 - // if code = this.module.ConsumeRes(session, node.PsConsume, true); code != pb.ErrorCode_Success { - // return - // } + for _, v := range mainline.BranchID { + if v == int32(req.MainlineId) { // 重复挑战 + code = pb.ErrorCode_MainlineNotFindChapter + return + } + } // 校验通过 code, isWin = this.module.battle.CheckBattleReport(session, req.Report) if code != pb.ErrorCode_Success { return } if !isWin { // 战斗失败直接返回 + // 返还 + mainline.Ps = 0 + this.module.modelMainline.modifyMainlineData(session.GetUserId(), mainline.Id, map[string]interface{}{ + "ps": 0, + }) + + if code = this.module.DispenseRes(session, node.PsConsume, true); code != pb.ErrorCode_Success { // 扣1点 + return + } code = pb.ErrorCode_BattleNoWin return } - // 胜利返回 - if code = this.module.DispenseRes(session, node.PsConsume, true); code != pb.ErrorCode_Success { // 扣1点 - return - } - for _, v := range mainline.BranchID { - if v == int32(req.MainlineId) { // 重复挑战 - code = pb.ErrorCode_MainlineNotFindChapter - return - } - if v == int32(req.MainlineId) { - break - } - } res = append(res, node.Award...) - for _, v := range res { + for _, v := range node.Award { if v.A == comm.HeroType { hero = append(hero, v.T) } @@ -119,12 +117,6 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.MainlineCh if mainline.Intensity < comm.MaxMainlineIntensity { _data.Intensity = mainline.Intensity + 1 // 难度+1 _data.ChapterId = 1 // 默认第一章节 - } else { // 全部通关 领奖拜拜 - if code = this.module.DispenseRes(session, res, true); code != pb.ErrorCode_Success { - this.module.Debugf("DispenseRes err:+%v", res) - } - session.SendMsg(string(this.module.GetType()), MainlineChallengeOverResp, &pb.MainlineChallengeOverResp{Data: mainline, Newheros: newhero, Olv: user.Lv}) - return } } @@ -134,6 +126,7 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.MainlineCh this.module.modelMainline.addNewChapter(session.GetUserId(), _mData) session.SendMsg(string(this.module.GetType()), MainlineNewChapterPush, &pb.MainlineNewChapterPush{Data: _data}) // 推送新的章节 + } // 发奖 if code = this.module.DispenseRes(session, res, true); code != pb.ErrorCode_Success {