227 lines
6.5 KiB
Go
227 lines
6.5 KiB
Go
package mline
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.MlineChallengeOverReq) (errdata *pb.ErrorData) {
|
|
if req.StageId == 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
///挑战主线关卡
|
|
func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.MlineChallengeOverReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
curChapter *pb.DBMline // 当前章节信息
|
|
stageConf *cfg.GameMainStageData
|
|
|
|
isWin bool
|
|
first bool // 判断是否是首通
|
|
update map[string]interface{}
|
|
rsp *pb.MlineChallengeOverResp
|
|
star int32 // 评星
|
|
tasks []*pb.BuriedParam = make([]*pb.BuriedParam, 0)
|
|
)
|
|
rsp = &pb.MlineChallengeOverResp{}
|
|
update = make(map[string]interface{})
|
|
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
|
|
rsp.Data = curChapter
|
|
session.SendMsg(string(this.module.GetType()), MlineChallengeOverResp, rsp) // 数据推送
|
|
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
|
|
}
|
|
|
|
var szStar []int32
|
|
szStar = append(szStar, 1<<0)
|
|
szStar = append(szStar, 1<<1)
|
|
szStar = append(szStar, 1<<2)
|
|
for i, v := range stageConf.StarType {
|
|
if v == comm.MainStarType1 {
|
|
star ^= szStar[i]
|
|
} else if v == comm.MainStarType2 {
|
|
if req.Report.Death <= stageConf.StarValue[i] {
|
|
star ^= szStar[i]
|
|
}
|
|
} else if v == comm.MainStarType3 {
|
|
if req.Report.Round <= stageConf.StarValue[i] {
|
|
star ^= szStar[i]
|
|
}
|
|
}
|
|
}
|
|
|
|
// 判断是不是首通
|
|
if _, ok := curChapter.Star[req.StageId]; !ok {
|
|
first = true
|
|
curChapter.Star[req.StageId] = star // 星级赋值
|
|
update["star"] = curChapter.Star
|
|
}
|
|
|
|
// 判断星数
|
|
var (
|
|
totalStar int32
|
|
preStar int32
|
|
)
|
|
if curChapter.Star[req.StageId] != star {
|
|
for _, v := range szStar {
|
|
if star&v == v {
|
|
totalStar++
|
|
}
|
|
|
|
if curChapter.Star[req.StageId]&v == v {
|
|
preStar++
|
|
}
|
|
}
|
|
if totalStar >= preStar { // 给最高星
|
|
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 rst, err := this.module.ModuleUser.GetUserExpand(session.GetUserId()); err == nil { // 统计主线进度
|
|
_mp := rst.Mline
|
|
if v, ok := _mp[curChapter.CType]; ok {
|
|
if v <= req.StageId {
|
|
_mp[curChapter.CType] = req.StageId
|
|
}
|
|
} else {
|
|
_mp[curChapter.CType] = req.StageId
|
|
}
|
|
this.module.ModuleUser.ChangeUserExpand(session.GetUserId(), map[string]interface{}{
|
|
"mline": _mp,
|
|
})
|
|
}
|
|
|
|
if code = this.module.DispenseRes(session, stageConf.Firstaward, true); code != pb.ErrorCode_Success {
|
|
this.module.Debugf("Mline first DispenseRes err:+%v", stageConf.Firstaward)
|
|
}
|
|
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("Mline Commonaward DispenseRes err:+%v", stageConf.Commonaward)
|
|
}
|
|
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))
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype60, 1))
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype61, 1, int32(req.StageId)))
|
|
var (
|
|
ChapterStar int32
|
|
bAll3Star bool
|
|
allStar int32
|
|
)
|
|
bAll3Star = true
|
|
for _, v1 := range curChapter.Star {
|
|
star := 0
|
|
for _, v := range szStar {
|
|
if v1&v == v {
|
|
ChapterStar++
|
|
star++
|
|
}
|
|
}
|
|
if star != 3 && bAll3Star {
|
|
bAll3Star = false
|
|
}
|
|
}
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype158, curChapter.ChapterId, ChapterStar))
|
|
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype158, curChapter.ChapterId, ChapterStar)
|
|
if bAll3Star {
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype159, curChapter.ChapterId))
|
|
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype159, curChapter.ChapterId)
|
|
}
|
|
for _, v2 := range list {
|
|
for _, v1 := range v2.Star {
|
|
for _, v := range szStar {
|
|
if v1&v == v {
|
|
allStar++
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype160, allStar)
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype160, allStar, stageConf.Chapterid))
|
|
go this.module.ModuleBuried.TriggerBuried(session.GetUserId(), tasks...)
|
|
return
|
|
}
|