go_dreamfactory/modules/mainline/api_challengeover.go
2023-10-11 17:12:26 +08:00

199 lines
5.8 KiB
Go

package mainline
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
)
// 参数校验
func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.MainlineChallengeOverReq) (errdata *pb.ErrorData) {
if req.Level == 0 {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
}
return
}
return
}
// /挑战主线关卡
func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.MainlineChallengeOverReq) (errdata *pb.ErrorData) {
var (
conf *cfg.GameMainStageData
info *pb.DBMainline
atno []*pb.UserAtno
reward []*pb.UserAtno = make([]*pb.UserAtno, 0)
isWin bool
first bool // 判断是否是首通
star int32 // 评星
tasks []*pb.BuriedParam = make([]*pb.BuriedParam, 0)
err error
consumPs int32
)
if errdata = this.ChallengeOverCheck(session, req); errdata != nil {
return // 参数校验失败直接返回
}
if conf, err = this.module.configure.GetMainStageConf(req.Level); err != nil { // 配置文件校验
errdata = &pb.ErrorData{
Code: pb.ErrorCode_MainlineNotFindChapter,
Title: pb.ErrorCode_MainlineNotFindChapter.ToString(),
Message: err.Error(),
}
return
}
if info, err = this.module.modelMline.getMainlineData(session.GetUserId()); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
return
}
if err = this.module.modelMline.checklevel(req.Level, info); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
Message: err.Error(),
}
return
}
// 校验通过
errdata, isWin = this.module.battle.CheckBattleReport(session, req.Report)
if errdata != nil {
return
}
if req.Report != nil && !isWin && conf.BattleFail == 1 { //战斗失败特殊处理
isWin = true
}
if !isWin { // 战斗失败返还扣除的体力
if errdata = this.module.DispenseRes(session, conf.PsConsume, true); errdata != nil { // 返还预扣体力
return
}
session.SendMsg(string(this.module.GetType()), "challengeover", &pb.MainlineChallengeOverResp{
Level: req.Level,
}) // 数据推送
return
}
// 评星规则
if len(conf.Star) != len(conf.StarType) || len(conf.Star) != len(conf.StarValue) || len(conf.StarValue) != len(conf.StarType) {
this.module.Errorf("配置错误, 参数数量不一致,StageId: %d", req.Level)
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Title: pb.ErrorCode_ConfigNoFound.ToString(),
}
return
}
var szStar []int32
szStar = append(szStar, 1<<0)
szStar = append(szStar, 1<<1)
szStar = append(szStar, 1<<2)
for i, v := range conf.StarType {
if v == comm.MainStarType1 {
star ^= szStar[i]
} else if v == comm.MainStarType2 {
if req.Report.Death <= conf.StarValue[i] {
star ^= szStar[i]
}
} else if v == comm.MainStarType3 {
if req.Report.Round <= conf.StarValue[i] {
star ^= szStar[i]
}
}
}
// 判断是不是首通
if _, ok := info.Level[req.Level]; !ok {
first = true
info.Level[req.Level] = star
}
if len(conf.Grouptype) == 2 {
info.Stategroup[conf.Grouptype[0]] = conf.Grouptype[1]
}
if conf.Inherit == 0 {
info.Lastlevel[conf.Chapterid] = req.Level
}
this.module.modelMline.updateprogress(info)
if first { // 发奖
if errdata, atno = this.module.DispenseAtno(session, conf.Firstaward, true); errdata != nil {
this.module.Debugf("Mline first DispenseRes err:+%v", conf.Firstaward)
return
}
reward = append(reward, atno...)
} else {
if errdata, atno = this.module.DispenseAtno(session, conf.Commonaward, true); errdata != nil {
this.module.Debugf("Mline Commonaward DispenseRes err:+%v", conf.Commonaward)
return
}
reward = append(reward, atno...)
}
user, err := this.module.ModuleUser.GetUser(session.GetUserId())
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
return
}
if lotteryward := this.module.ModuleTools.GetGroupDataByLottery(conf.Lotteryward, user.Vip, user.Lv); len(lotteryward) > 0 {
if errdata, atno = this.module.DispenseAtno(session, lotteryward, true); errdata != nil {
this.module.Debugf("Mline lotteryward DispenseRes err:+%v", lotteryward)
return
}
reward = append(reward, atno...)
}
// 加英雄经验
if conf.HeroExp > 0 {
var heroObjs []string
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.Oid != "" && !v.Ishelp { // 助战英雄不加经验
heroObjs = append(heroObjs, v.Oid)
}
}
}
this.module.ModuleHero.AddHerosExp(session, heroObjs, conf.HeroExp)
}
consumPs = info.Ps[req.Level]
if atno, errdata = this.module.ModuleUser.ConsumePsAddExp(session, consumPs); errdata != nil {
return
}
reward = append(reward, atno...)
if err = this.module.modelMline.updateMainlineData(session.GetUserId(), info); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
return
}
session.SendMsg(string(this.module.GetType()), "challengeover", &pb.MainlineChallengeOverResp{
Level: req.Level,
Star: star,
HeroExp: conf.HeroExp,
Reward: reward,
})
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype60, 1))
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype61, 1, int32(req.Level)))
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
this.module.ModuleBuried.TriggerBuried(session, tasks...)
this.module.ModuleSys.CheckOpenCond(session, comm.OpencondTypeMaxmapid, req.Level)
})
return
}