144 lines
4.4 KiB
Go
144 lines
4.4 KiB
Go
package mainline
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) LevelPassCheck(session comm.IUserSession, req *pb.MainlineLevelPassReq) (errdata *pb.ErrorData) {
|
|
if req.Level == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// /挑战主线关卡
|
|
func (this *apiComp) LevelPass(session comm.IUserSession, req *pb.MainlineLevelPassReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
conf *cfg.GameMainStageData
|
|
info *pb.DBMainline
|
|
atno []*pb.UserAtno
|
|
aeward []*pb.UserAtno = make([]*pb.UserAtno, 0)
|
|
first bool // 判断是否是首通
|
|
star int32 // 评星
|
|
tasks []*pb.BuriedParam = make([]*pb.BuriedParam, 0)
|
|
err error
|
|
// consumPs int32
|
|
)
|
|
if errdata = this.LevelPassCheck(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(),
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
// 评星规则
|
|
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
|
|
}
|
|
star = 1
|
|
// 判断是不是首通
|
|
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)
|
|
}
|
|
aeward = append(aeward, atno...)
|
|
|
|
} 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...)
|
|
}
|
|
// consumPs = info.Ps[req.Level]
|
|
// if atno, errdata = this.module.ModuleUser.ConsumePsAddExp(session, consumPs); errdata != nil {
|
|
// return
|
|
// }
|
|
// aeward = append(aeward, 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)
|
|
}
|
|
aeward = append(aeward, atno...)
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "levelpass", &pb.MainlineLevelPassResp{
|
|
Level: req.Level,
|
|
Star: star,
|
|
HeroExp: conf.HeroExp,
|
|
Reward: aeward,
|
|
}) // 数据推送
|
|
|
|
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
|
|
}
|
|
|
|
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.WriteUserLog(session.GetUserId(), comm.GMResAddType, "MainlineLevelPassReq", aeward)
|
|
})
|
|
return
|
|
}
|