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

168 lines
4.4 KiB
Go

package integral
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
)
//参数校验
func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.IntegralChallengeOverReq) (errdata *pb.ErrorData) {
if req.Nandu <= 0 {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
}
return
}
return
}
///挑战主线关卡
func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.IntegralChallengeOverReq) (errdata *pb.ErrorData) {
var (
update map[string]interface{}
res []*cfg.Gameatn
award []*cfg.Gameatn
first bool // 是否是首通
line []*pb.LineUp // 阵容数据
harm int32
changExp map[string]int32
atno []*pb.UserAtno // atno 类型
)
changExp = make(map[string]int32)
harm = req.Report.Harm
update = make(map[string]interface{}, 0)
if errdata = this.ChallengeOverCheck(session, req); errdata != nil {
return // 参数校验失败直接返回
}
list, err := this.module.modelIntegral.getIntegralList(session)
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_PagodaNotFound,
Title: pb.ErrorCode_PagodaNotFound.ToString(),
}
return
}
if _, ok := list.Score[req.Nandu]; !ok {
list.Score[req.Nandu] = harm
update["score"] = list.Score
first = true
}
cfgData, err := this.module.configure.GetStageBoss(list.Hid, req.Nandu)
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound, // 道具数量不足
Title: pb.ErrorCode_ConfigNoFound.ToString(),
Message: err.Error(),
}
return
}
// check
errdata, _ = this.module.battle.CheckBattleReport(session, req.Report)
if errdata != nil {
return
}
userinfo, err := this.module.GetUserForSession(session)
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
return
}
list.Count++
update["count"] = list.Count
// 更新积分数据
if list.Score[req.Nandu] < harm {
list.Score[req.Nandu] = harm
update["score"] = list.Score
}
if list.Maxscore < harm { // 更新最大积分数据
list.Maxscore = harm
update["maxscore"] = list.Maxscore
}
list.Totalscore += harm
update["totalscore"] = list.Totalscore
if first {
for _, v := range cfgData.Firstprize { // 发放通关随机奖励
res = append(res, v)
}
}
for _, v := range req.Report.Info.Redflist[0].Team {
line = append(line, &pb.LineUp{
Cid: v.HeroID,
Star: v.Star,
Lv: v.Lv,
})
}
list.Line[req.Nandu] = &pb.LineData{
Leadpos: req.Report.Info.Redflist[0].Leadpos,
Line: line,
}
update["line"] = list.Line
reward := this.module.ModuleTools.GetGroupDataByLottery(cfgData.Drop, userinfo.Vip, userinfo.Lv)
res = append(res, reward...)
if len(res) > 0 {
if errdata = this.module.DispenseRes(session, res, true); errdata != nil {
return
}
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
this.module.WriteUserLog(session.GetUserId(), req, comm.GMResAddType, "IntegralChallengeOverReq", res)
})
}
if first {
res = append(res, cfgData.Firstprize...)
}
if user, err := this.module.GetUserForSession(session); err == nil {
reward = this.module.ModuleTools.GetGroupDataByLottery(cfgData.Drop, user.Vip, user.Lv)
res = append(res, reward...)
}
// 加经验
if cfgData.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.HeroID != "" {
if !v.Ishelp { // 助战英雄不加经验
heroObjs = append(heroObjs, v.Oid)
}
}
}
}
if changExp, award, errdata = this.module.ModuleHero.AddHerosExp(session, heroObjs, cfgData.Heroexp); errdata != nil {
return
}
res = append(res, award...)
}
if errdata, atno = this.module.DispenseAtno(session, res, true); errdata != nil {
return
}
if err = this.module.modelIntegral.modifyIntegralData(session.GetUserId(), update); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Message: err.Error(),
}
return
}
this.module.modelRank.updateRank(harm, session.GetUserId(), int(req.Nandu))
session.SendMsg(string(this.module.GetType()), "challengeover", &pb.IntegralChallengeOverResp{
Data: list,
Atno: atno,
Heroexp: changExp,
})
return
}