go_dreamfactory/modules/mainline/api_challengeover.go
2024-01-12 11:09:15 +08:00

204 lines
5.9 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
isWin bool
first bool // 判断是否是首通
star int32 // 评星
tasks []*pb.BuriedParam = make([]*pb.BuriedParam, 0)
err error
changExp map[string]int32
res []*cfg.Gameatn
award []*cfg.Gameatn
)
changExp = make(map[string]int32, 0)
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 { //战斗失败特殊处理
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,
}) // 数据推送
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
this.module.WriteUserLog(session.GetUserId(), req, comm.GMResAddType, "MainlineChallengeOverReq false", conf.PsConsume)
})
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 {
info.Lastlevel[conf.Chapterid] = &pb.DBMainlineLastLevel{
Level: req.Level,
Pos: req.Pos,
}
} else {
info.Lastlevel[conf.Chapterid] = &pb.DBMainlineLastLevel{
Pos: req.Pos,
}
}
this.module.modelMline.updateprogress(info)
if first { // 发奖
res = append(res, conf.Firstaward...)
} else {
res = append(res, conf.Commonaward...)
}
user, err := this.module.GetUserForSession(session)
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
return
}
session.SetMate(comm.Session_User, user)
if lotteryward := this.module.ModuleTools.GetGroupDataByLottery(conf.Lotteryward, user.Vip, user.Lv); len(lotteryward) > 0 {
res = append(res, lotteryward...)
}
res = append(res, this.module.ModuleUser.PsConvertExp(info.Ps[req.Level]))
// 加英雄经验
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)
}
}
}
if changExp, award, errdata = this.module.ModuleHero.AddHerosExp(session, heroObjs, conf.HeroExp); errdata != nil {
return
}
res = append(res, award...)
}
if errdata, atno = this.module.DispenseAtno(session, res, true); errdata != nil {
this.module.Debugf("Mline DispenseRes err:+%v", res)
return
}
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: changExp,
Reward: atno,
})
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)
this.module.WriteUserLog(session.GetUserId(), req, comm.GMResAddType, "MainlineChallengeOverReq", atno)
})
return
}