148 lines
4.7 KiB
Go
148 lines
4.7 KiB
Go
package mainline
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.MainlineChallengeOverReq) (code pb.ErrorCode) {
|
|
if req.MainlineId == 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
///挑战主线关卡
|
|
func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.MainlineChallengeOverReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
mainline *pb.DBMainline // 当前章节信息
|
|
res []*cfg.Gameatn // 小章节奖励
|
|
isWin bool
|
|
user *pb.DBUser
|
|
hero []string //新的英雄
|
|
newhero []string //新的英雄
|
|
)
|
|
res = make([]*cfg.Gameatn, 0)
|
|
hero = make([]string, 0)
|
|
newhero = make([]string, 0)
|
|
code = this.ChallengeOverCheck(session, req)
|
|
if code != pb.ErrorCode_Success {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
// 校验关卡存不存在
|
|
mainline = this.module.modelMainline.getOneChapterInfo(session.GetUserId(), req.ChapterObj)
|
|
if mainline == nil {
|
|
code = pb.ErrorCode_MainlineNotFound
|
|
return
|
|
}
|
|
|
|
node := this.module.configure.GetMainlineConfigData(int32(req.MainlineId), mainline.Intensity)
|
|
if node == nil { // 配置文件校验
|
|
code = pb.ErrorCode_MainlineNotFindChapter
|
|
return
|
|
}
|
|
// 校验通过
|
|
code, isWin = this.module.battle.CheckBattleReport(session, req.Report)
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
if !isWin { // 战斗失败直接返回
|
|
code = pb.ErrorCode_BattleNoWin
|
|
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 {
|
|
if v.A == comm.HeroType {
|
|
hero = append(hero, v.T)
|
|
}
|
|
}
|
|
if len(hero) > 0 {
|
|
ishave := this.module.ModuleUser.CheckTujianHero(session, hero)
|
|
for i, v := range ishave {
|
|
if !v {
|
|
newhero = append(newhero, hero[i])
|
|
}
|
|
}
|
|
}
|
|
user = this.module.ModuleUser.GetUser(session.GetUserId())
|
|
mainline.MainlineId = int32(req.MainlineId)
|
|
mainline.BranchID = append(mainline.BranchID, int32(req.MainlineId))
|
|
update := map[string]interface{}{
|
|
"mainlineId": req.MainlineId,
|
|
"chapterId": mainline.ChapterId,
|
|
"branchID": mainline.BranchID,
|
|
}
|
|
if node.Episodetype == comm.MainLineBoss { // 打完boss 设置领奖状态
|
|
update["awaredID"] = pb.AwaredType_TypeAvailable
|
|
mainline.AwaredID = pb.AwaredType_TypeAvailable
|
|
}
|
|
err := this.module.modelMainline.modifyMainlineData(session.GetUserId(), mainline.Id, update)
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
|
|
if node.Episodetype == comm.MainLineBoss { // 挑战完成 boss关
|
|
_data := &pb.DBMainline{}
|
|
conf := this.module.configure.GetMainlineChapter(mainline.ChapterId + 1)
|
|
_data.Id = primitive.NewObjectID().Hex()
|
|
_data.ChapterId = mainline.ChapterId + 1
|
|
_data.Intensity = mainline.Intensity
|
|
if conf == nil { // 这里就是切换下一个难度了
|
|
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
|
|
}
|
|
}
|
|
|
|
_mData := make(map[string]interface{}, 0)
|
|
_data.Uid = session.GetUserId()
|
|
_mData[_data.Id] = _data
|
|
|
|
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 {
|
|
this.module.Debugf("DispenseRes err:+%v", res)
|
|
}
|
|
// 加经验
|
|
if node.Episodetype != 5 && node.Episodetype != 7 {
|
|
if req.Report != nil && req.Report.Info != nil && len(req.Report.Info.Redflist) > 0 {
|
|
for _, v := range req.Report.Info.Redflist[0].Team {
|
|
if node.Exp > 0 && !v.Ishelp { // 助战英雄不加经验
|
|
this.module.ModuleHero.AddHeroExp(session, v.Oid, node.Exp)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), MainlineChallengeOverResp, &pb.MainlineChallengeOverResp{Data: mainline, Newheros: newhero, Olv: user.Lv})
|
|
// 主线任务统计 Rtype60
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype60, 1)
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype61, int32(req.MainlineId))
|
|
return
|
|
}
|