198 lines
5.2 KiB
Go
198 lines
5.2 KiB
Go
package pagoda
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.PagodaChallengeOverReq) (errdata *pb.ErrorData) {
|
|
if req.Cid <= 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// /挑战主线关卡
|
|
func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.PagodaChallengeOverReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
mapData map[string]interface{}
|
|
pagoda *pb.DBPagoda
|
|
user *pb.DBUser
|
|
isWin bool
|
|
err error
|
|
atno []*pb.UserAtno // 通关奖励
|
|
award []*cfg.Gameatn
|
|
changExp map[string]int32
|
|
costTime int32 // 耗时
|
|
)
|
|
changExp = make(map[string]int32, 0)
|
|
mapData = make(map[string]interface{}, 0)
|
|
if errdata = this.ChallengeOverCheck(session, req); errdata != nil {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
|
|
conf, err := this.module.configure.GetPagodaConfigData(req.Cid)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_PagodaNotFound,
|
|
Title: pb.ErrorCode_PagodaNotFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
pagoda, err = this.module.modelPagoda.getPagodaList(session.GetUserId())
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_PagodaNotFound,
|
|
Title: pb.ErrorCode_PagodaNotFound.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if v, ok := pagoda.Data[conf.Tab]; !ok {
|
|
if conf.LayerNum == 1 {
|
|
pagoda.Data[conf.Tab] = 0
|
|
} else {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_PagodaLevlErr, // 挑战关卡数据不匹配
|
|
Title: pb.ErrorCode_PagodaLevlErr.ToString(),
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
if conf.LayerNum-1 != v {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_PagodaLevlErr, // 挑战关卡数据不匹配
|
|
Title: pb.ErrorCode_PagodaLevlErr.ToString(),
|
|
}
|
|
return
|
|
}
|
|
}
|
|
// 校验条件
|
|
if conf.Unlock != 0 {
|
|
level := this.mline.InquireMainLinePassLevel(session.GetUserId())
|
|
if _, ok := level[conf.Unlock]; !ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_PagodaUnlock, // 挑战关卡未解锁
|
|
Title: pb.ErrorCode_PagodaUnlock.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
|
|
var score int32
|
|
score = 10000*conf.Key + (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,
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
// 校验是否刷新记录
|
|
record := this.module.modulerank.getcrossPagodaRankList(session.GetUserId())
|
|
this.module.modulerank.SetPagodaRankList(conf.Key, score, session.GetUserId())
|
|
if _, ok := record.Data[conf.Key]; !ok {
|
|
record.Data[conf.Key] = &pb.PagodaRecordData{
|
|
Consttime: costTime,
|
|
Line: &pb.LineData{},
|
|
}
|
|
}
|
|
record.Data[conf.Key].Line = &pb.LineData{
|
|
Leadpos: Leadpos,
|
|
Line: szLine,
|
|
}
|
|
mapData["data"] = record.Data
|
|
if user, err := this.module.ModuleUser.GetUser(session.GetUserId()); err == nil {
|
|
mapData["uinfo"] = comm.GetUserBaseInfo(user)
|
|
}
|
|
|
|
this.module.modulerank.ModifyCrossPagodaCycleData(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
|
|
}
|
|
}
|
|
costTime = req.Report.Costtime
|
|
pagoda.Data[conf.Tab] += 1
|
|
pagoda.PagodaId = conf.Key
|
|
mapData["pagodaId"] = pagoda.PagodaId
|
|
mapData["type"] = pagoda.Type
|
|
mapData["data"] = pagoda.Data
|
|
// 校验所有塔是否通关
|
|
if !pagoda.Complete {
|
|
pagoda.Complete = true
|
|
for k, v := range this.module.configure.GetMapFloorData() {
|
|
if pagoda.Data[k] != v {
|
|
pagoda.Complete = false
|
|
break
|
|
}
|
|
}
|
|
if pagoda.Complete {
|
|
mapData["complete"] = pagoda.Complete
|
|
}
|
|
}
|
|
// 数据直接插入跨服数据库中
|
|
if user, err = this.module.GetUserForSession(session); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
session.SetMate(comm.Session_User, user)
|
|
award = append(award, conf.Reward...)
|
|
// 通关奖励
|
|
if errdata, atno = this.module.DispenseAtno(session, award, true); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if errdata = this.module.ModifyPagodaData(session.GetUserId(), mapData); errdata != nil {
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), PagodaChallengeOverResp, &pb.PagodaChallengeOverResp{
|
|
Data: pagoda,
|
|
Reward: atno,
|
|
Heroexp: changExp,
|
|
})
|
|
|
|
return
|
|
}
|