go_dreamfactory/modules/pagoda/api_racechallengeover.go
2024-01-10 17:38:11 +08:00

127 lines
3.5 KiB
Go

package pagoda
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
)
// 参数校验
func (this *apiComp) ChallengeRaceOverCheck(session comm.IUserSession, req *pb.PagodaChallengeRaceOverReq) (errdata *pb.ErrorData) {
if req.Cid <= 0 {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
}
return
}
return
}
// /挑战主线关卡
func (this *apiComp) ChallengeRaceOver(session comm.IUserSession, req *pb.PagodaChallengeRaceOverReq) (errdata *pb.ErrorData) {
var (
mapData map[string]interface{}
race *pb.DBPagodaRace
isWin bool
err error
atno []*pb.UserAtno // 通关奖励
changExp map[string]int32
costTime int32 // 耗时
star int32 // 当前星级
)
changExp = make(map[string]int32, 0)
mapData = make(map[string]interface{}, 0)
if errdata = this.ChallengeRaceOverCheck(session, req); errdata != nil {
return // 参数校验失败直接返回
}
conf, err := this.module.configure.GetPagodaRaceConfById(req.Cid)
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_PagodaNotFound,
Title: pb.ErrorCode_PagodaNotFound.ToString(),
Message: err.Error(),
}
return
}
race, err = this.module.modelRacePagoda.getPagodaRaceList(session.GetUserId())
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_PagodaNotFound,
Title: pb.ErrorCode_PagodaNotFound.ToString(),
}
return
}
// 校验通过
errdata, isWin = this.module.battle.CheckBattleReport(session, req.Report)
if errdata != nil {
return
}
if !isWin { // 战斗失败直接返回
errdata = &pb.ErrorData{
Code: pb.ErrorCode_BattleNoWin,
Title: pb.ErrorCode_BattleNoWin.ToString(),
}
return
}
costTime = req.Report.Costtime
if conf.Exp > 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.Oid != "" && !v.Ishelp { // 助战英雄不加经验
heroObjs = append(heroObjs, v.Oid)
}
}
}
if changExp, errdata = this.module.ModuleHero.AddHerosExp(session, heroObjs, conf.Exp); errdata != nil {
return
}
}
if _, ok := race.Data[conf.Floors]; !ok {
if race.Maxfloor == conf.Floors+1 {
race.Data[conf.Floors] = &pb.RaceData{
Consttime: costTime,
Star: star,
}
race.Maxfloor = conf.Floors + 1
mapData["maxfloor"] = race.Maxfloor
}
}
race.Battlecount += 1
mapData["data"] = race.Data
mapData["battlecount"] = race.Battlecount
if err = this.module.modelRacePagoda.ModifyPagodaRaceDataByObjId(session.GetUserId(), mapData); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
}
// 通关奖励
if errdata, atno = this.module.DispenseAtno(session, conf.Reward, true); errdata != nil {
return
}
session.SendMsg(string(this.module.GetType()), PagodaChallengeRaceOverResp, &pb.PagodaChallengeRaceOverResp{
Data: race,
Reward: atno,
Heroexp: changExp,
})
// 任务相关
var tasks []*pb.BuriedParam
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype232, conf.Restriction, conf.Floors))
if conf.Restriction >= 10 {
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype231, conf.Floors))
}
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
this.module.ModuleBuried.TriggerBuried(session, tasks...)
this.module.WriteUserLog(session.GetUserId(), req, comm.GMResAddType, "PagodaChallengeRaceOverReq", atno)
})
return
}