go_dreamfactory/modules/mline/api_challengeover.go
2023-01-06 16:51:12 +08:00

152 lines
4.5 KiB
Go

package mline
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"google.golang.org/protobuf/proto"
)
//参数校验
func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.MlineChallengeOverReq) (code pb.ErrorCode) {
if req.StageId == 0 {
code = pb.ErrorCode_ReqParameterError
return
}
return
}
///挑战主线关卡
func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.MlineChallengeOverReq) (code pb.ErrorCode, data proto.Message) {
var (
curChapter *pb.DBMline // 当前章节信息
stageConf *cfg.GameMainStageData
res []*cfg.Gameatn // 小章节奖励
isWin bool
first bool // 判断是否是首通
update map[string]interface{}
rsp *pb.MlineChallengeOverResp
star int32 // 评星
)
rsp = &pb.MlineChallengeOverResp{}
update = make(map[string]interface{})
res = make([]*cfg.Gameatn, 0)
code = this.ChallengeOverCheck(session, req)
if code != pb.ErrorCode_Success {
return // 参数校验失败直接返回
}
if stageConf = this.module.configure.GetMainStageConf(req.StageId); stageConf == nil { // 配置文件校验
code = pb.ErrorCode_MainlineNotFindChapter
return
}
list, _ := this.module.modelMline.getMainlineList(session.GetUserId())
for _, v := range list {
if stageConf.Chapterid == v.ChapterId {
curChapter = v
break
}
}
if curChapter == nil {
code = pb.ErrorCode_MainlineNotFindChapter
return
}
// 校验通过
code, isWin = this.module.battle.CheckBattleReport(session, req.Report)
if code != pb.ErrorCode_Success {
return
}
if !isWin { // 战斗失败返还扣除的体力
if v, ok := curChapter.Ps[req.StageId]; ok && v > 0 {
if code = this.module.DispenseRes(session, stageConf.PsConsume, true); code != pb.ErrorCode_Success { // 返还预扣体力
return
}
}
curChapter.Ps[req.StageId] = 0 // 清空预扣体力值
update["ps"] = curChapter.Ps
this.module.modelMline.modifyMlineData(session.GetUserId(), curChapter.Id, update)
code = pb.ErrorCode_BattleNoWin
return
}
// 评星规则
if len(stageConf.Star) != len(stageConf.StarType) || len(stageConf.Star) != len(stageConf.StarValue) || len(stageConf.StarValue) != len(stageConf.StarType) {
this.module.Errorf("配置错误, 参数数量不一致,StageId: %d", req.StageId)
code = pb.ErrorCode_ConfigNoFound
return
}
for i, v := range stageConf.StarType {
if v == comm.MainStarType1 {
star += stageConf.Star[i]
} else if v == comm.MainStarType2 {
if req.Report.Death <= stageConf.StarValue[i] {
star += stageConf.Star[i]
}
} else if v == comm.MainStarType3 {
if req.Report.Round <= stageConf.StarValue[i] {
star += stageConf.Star[i]
}
}
}
// 判断是不是首通
if _, ok := curChapter.Star[req.StageId]; !ok {
first = true
curChapter.Star[req.StageId] = star // 星级赋值
update["star"] = curChapter.Star
}
if curChapter.Star[req.StageId] > star { // 给最高星
curChapter.Star[req.StageId] = star
update["star"] = curChapter.Star
}
curChapter.Ps[req.StageId] = 0 // 清空预扣体力值
update["ps"] = curChapter.Ps
curChapter.StageId = req.StageId
update["stageId"] = curChapter.StageId
if first { // 发奖
if code = this.module.DispenseRes(session, stageConf.Firstaward, true); code != pb.ErrorCode_Success {
this.module.Debugf("DispenseRes err:+%v", res)
}
for _, v := range stageConf.Firstaward {
rsp.Reward = append(rsp.Reward, &pb.UserAssets{
A: v.A,
T: v.T,
N: v.N,
})
}
} else {
if code = this.module.DispenseRes(session, stageConf.Commonaward, true); code != pb.ErrorCode_Success {
this.module.Debugf("DispenseRes err:+%v", res)
}
for _, v := range stageConf.Commonaward {
rsp.Reward = append(rsp.Reward, &pb.UserAssets{
A: v.A,
T: v.T,
N: v.N,
})
}
}
// 加英雄经验
if stageConf.HeroExp > 0 {
if req.Report != nil && req.Report.Info != nil && len(req.Report.Info.Redflist) > 0 {
for _, v := range req.Report.Info.Redflist[0].Team {
if !v.Ishelp { // 助战英雄不加经验
this.module.ModuleHero.AddHeroExp(session, v.Oid, stageConf.HeroExp)
}
}
}
}
this.module.modelMline.modifyMlineData(session.GetUserId(), curChapter.Id, update)
rsp.Data = curChapter
session.SendMsg(string(this.module.GetType()), MlineChallengeOverResp, rsp) // 数据推送
// 主线任务统计 Rtype60
this.module.ModuleRtask.SendToRtask(session, comm.Rtype60, 1)
this.module.ModuleRtask.SendToRtask(session, comm.Rtype61, int32(req.StageId))
return
}