171 lines
4.6 KiB
Go
171 lines
4.6 KiB
Go
package pagoda
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) ChallengeRaceOverCheck(session comm.IUserSession, req *pb.PagodaChallengeRaceOverReq) (errdata *pb.ErrorData) {
|
|
if req.Floor <= 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{}
|
|
list *pb.DBPagodaRace
|
|
isWin bool
|
|
err error
|
|
atno []*pb.UserAtno // 通关奖励
|
|
award []*cfg.Gameatn
|
|
res []*cfg.Gameatn
|
|
changExp map[string]int32
|
|
costTime int32 // 耗时
|
|
new bool // 是否首次挑战
|
|
fresh bool // 刷新记录
|
|
)
|
|
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.GetSixPagodaConf(req.Floor)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_PagodaNotFound,
|
|
Title: pb.ErrorCode_PagodaNotFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
list, 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 _, ok := list.Data[conf.Floors]; !ok {
|
|
if list.Maxfloor+1 == conf.Floors {
|
|
list.Data[conf.Floors] = &pb.RaceData{
|
|
Consttime: costTime,
|
|
Star: req.Star,
|
|
}
|
|
if req.Star > 0 {
|
|
list.Maxfloor = conf.Floors
|
|
mapData["maxfloor"] = list.Maxfloor
|
|
}
|
|
new = true
|
|
}
|
|
}
|
|
|
|
list.Data[conf.Floors].Star |= req.Star
|
|
list.Battlecount += 1
|
|
mapData["data"] = list.Data
|
|
mapData["battlecount"] = list.Battlecount
|
|
if err = this.module.modelRacePagoda.ModifyPagodaRaceData(session.GetUserId(), mapData); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
}
|
|
if list.Data[conf.Floors].Consttime > costTime {
|
|
list.Data[conf.Floors].Consttime = costTime
|
|
fresh = true
|
|
}
|
|
var score int32
|
|
score = 10000*list.Maxfloor + (10000 - costTime)
|
|
szLine := make([]*pb.LineUp, 0)
|
|
var Leadpos int32
|
|
if req.Report != nil && req.Report.Info != nil && len(req.Report.Info.Redflist) > 0 {
|
|
Leadpos = req.Report.Info.Redflist[0].Leadpos
|
|
for _, v := range req.Report.Info.Redflist[0].Team {
|
|
if v != nil {
|
|
szLine = append(szLine, &pb.LineUp{
|
|
Cid: v.HeroID,
|
|
Star: v.Star,
|
|
Lv: v.Lv,
|
|
})
|
|
}
|
|
}
|
|
}
|
|
list.Data[conf.Floors].Line = &pb.LineData{
|
|
Leadpos: Leadpos,
|
|
Line: szLine,
|
|
}
|
|
if new {
|
|
if conf.Floors == 1 { // 写数据
|
|
this.module.modelRacePagoda.addCrossPagodaRace(session.GetUserId(), list)
|
|
}
|
|
res = append(res, conf.KeyReward...) // 首通奖励
|
|
}
|
|
// 校验是否刷新记录
|
|
if fresh || new {
|
|
this.module.modelRacePagoda.SetRacePagodaRankList(score, session.GetUserId())
|
|
mapData["data"] = list.Data
|
|
user, err := this.module.ModuleUser.GetUser(session.GetUserId())
|
|
if err == nil {
|
|
list.Uinfo = comm.GetUserBaseInfo(user)
|
|
}
|
|
list.Uinfo = comm.GetUserBaseInfo(user)
|
|
mapData["uinfo"] = list.Uinfo
|
|
|
|
this.module.modelRacePagoda.ModifyCrossPagodaRaceData(session.GetUserId(), mapData)
|
|
}
|
|
|
|
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, award, errdata = this.module.ModuleHero.AddHerosExp(session, heroObjs, conf.Exp); errdata != nil {
|
|
return
|
|
}
|
|
res = append(res, award...)
|
|
}
|
|
res = append(res, conf.Reward...)
|
|
// 通关奖励
|
|
if errdata, atno = this.module.DispenseAtno(session, res, true); errdata != nil {
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), PagodaChallengeRaceOverResp, &pb.PagodaChallengeRaceOverResp{
|
|
Data: list,
|
|
Reward: atno,
|
|
Heroexp: changExp,
|
|
})
|
|
|
|
return
|
|
}
|