186 lines
5.5 KiB
Go
186 lines
5.5 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
|
|
aeward []*pb.UserAtno = make([]*pb.UserAtno, 0)
|
|
isWin bool
|
|
first bool // 判断是否是首通
|
|
star int32 // 评星
|
|
tasks []*pb.BuriedParam = make([]*pb.BuriedParam, 0)
|
|
err error
|
|
consumPs int32
|
|
userExp 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 !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
|
|
}
|
|
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)
|
|
}
|
|
aeward = append(aeward, atno...)
|
|
// for _, v := range conf.Firstaward {
|
|
// aeward = append(aeward, &pb.UserAssets{
|
|
// A: v.A,
|
|
// T: v.T,
|
|
// N: v.N,
|
|
// })
|
|
// }
|
|
} else {
|
|
if errdata, atno = this.module.DispenseAtno(session, conf.Commonaward, true); errdata != nil {
|
|
this.module.Debugf("Mline Commonaward DispenseRes err:+%v", conf.Commonaward)
|
|
}
|
|
aeward = append(aeward, atno...)
|
|
// for _, v := range conf.Commonaward {
|
|
// aeward = append(aeward, &pb.UserAssets{
|
|
// A: v.A,
|
|
// T: v.T,
|
|
// N: v.N,
|
|
// })
|
|
// }
|
|
}
|
|
user := this.module.ModuleUser.GetUser(session.GetUserId())
|
|
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)
|
|
}
|
|
aeward = append(aeward, atno...)
|
|
}
|
|
|
|
// 加英雄经验
|
|
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 conf.HeroExp > 0 && !v.Ishelp { // 助战英雄不加经验
|
|
heroObjs = append(heroObjs, v.Oid)
|
|
}
|
|
}
|
|
}
|
|
this.module.ModuleHero.AddHerosExp(session, heroObjs, conf.HeroExp)
|
|
|
|
consumPs = info.Ps[req.Level]
|
|
if userExp, errdata = this.module.ModuleUser.ConsumePsAddExp(session, consumPs); errdata != nil {
|
|
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: conf.HeroExp,
|
|
UserExp: userExp,
|
|
Reward: aeward,
|
|
})
|
|
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype60, 1))
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype61, 1, int32(req.Level)))
|
|
go this.module.ModuleBuried.TriggerBuried(session.Clone(), tasks...)
|
|
return
|
|
}
|