go_dreamfactory/modules/mline/api_challengeover.go
2023-06-06 15:48:53 +08:00

244 lines
7.0 KiB
Go

package mline
import (
"fmt"
"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 {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
}
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{})
if errdata = this.ChallengeOverCheck(session, req); errdata != nil {
return // 参数校验失败直接返回
}
if stageConf = this.module.configure.GetMainStageConf(req.StageId); stageConf == nil { // 配置文件校验
errdata = &pb.ErrorData{
Code: pb.ErrorCode_MainlineNotFindChapter,
Title: pb.ErrorCode_MainlineNotFindChapter.ToString(),
}
return
}
list, _ := this.module.modelMline.getMainlineList(session.GetUserId())
for _, v := range list {
if stageConf.Chapterid == v.ChapterId {
curChapter = v
break
}
}
if curChapter == nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_MainlineNotFindChapter,
Title: pb.ErrorCode_MainlineNotFindChapter.ToString(),
}
return
}
// 校验通过
errdata, isWin = this.module.battle.CheckBattleReport(session, req.Report)
if errdata != nil {
return
}
if v, ok := curChapter.Ps[req.StageId]; !ok || v == 0 {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_HuntingLvErr,
Title: pb.ErrorCode_HuntingLvErr.ToString(),
Message: fmt.Sprintf("关卡体力参数异常,uid:%s,预扣体力:%d", session.GetUserId(), v),
}
return
}
curChapter.Ps[req.StageId] = 0 // 清空预扣体力值
update["ps"] = curChapter.Ps
if !isWin { // 战斗失败返还扣除的体力
if errdata = this.module.DispenseRes(session, stageConf.PsConsume, true); errdata != nil { // 返还预扣体力
return
}
this.module.modelMline.modifyMlineData(session.GetUserId(), curChapter.Id, update)
// errdata = &pb.ErrorData{
// Code: pb.ErrorCode_BattleNoWin, // 战斗失败了
// Title: pb.ErrorCode_BattleNoWin.ToString(),
// }
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)
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 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.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 errdata = this.module.DispenseRes(session, stageConf.Firstaward, true); errdata != nil {
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 errdata = this.module.DispenseRes(session, stageConf.Commonaward, true); errdata != nil {
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
}