199 lines
5.5 KiB
Go
199 lines
5.5 KiB
Go
package pagoda
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/db"
|
|
"strconv"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
// 参数校验
|
|
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
|
|
isWin bool
|
|
err error
|
|
)
|
|
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
|
|
}
|
|
// 加经验
|
|
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)
|
|
}
|
|
}
|
|
}
|
|
this.module.ModuleHero.AddHerosExp(session, heroObjs, conf.Exp)
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|
|
|
|
errdata = this.module.ModifyPagodaData(session.GetUserId(), mapData)
|
|
session.SendMsg(string(this.module.GetType()), PagodaChallengeOverResp, &pb.PagodaChallengeOverResp{Data: pagoda})
|
|
if user, err := this.module.ModuleUser.GetUser(session.GetUserId()); err == nil { // 发系统公告
|
|
this.chat.SendSysChatToWorld(comm.ChatSystem4, nil, pagoda.PagodaId, 0, user.Name)
|
|
} else {
|
|
this.module.Errorf("no found userdata uid:%s", session.GetUserId())
|
|
}
|
|
|
|
// 记录爬塔明细数据
|
|
if req.Report != nil && req.Report.Info != nil && len(req.Report.Info.Redflist) > 0 {
|
|
leadpos := req.Report.Info.Redflist[0].Leadpos
|
|
szLine := make([]*pb.LineUp, 0)
|
|
for _, v := range req.Report.Info.Redflist[0].Team {
|
|
if v.Oid != "" {
|
|
szLine = append(szLine, &pb.LineUp{
|
|
Cid: v.HeroID,
|
|
Star: v.Star,
|
|
Lv: v.Lv,
|
|
})
|
|
}
|
|
}
|
|
// 数据直接插入跨服数据库中
|
|
uid := session.GetUserId()
|
|
userinfo, err := this.module.ModuleUser.GetUser(session.GetUserId())
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
newData := &pb.DBPagodaRecord{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: session.GetUserId(),
|
|
PagodaId: pagoda.PagodaId,
|
|
Type: pagoda.Type,
|
|
Nickname: userinfo.Name,
|
|
Icon: userinfo.CurSkin,
|
|
Lv: userinfo.Lv,
|
|
Leadpos: leadpos,
|
|
Line: szLine,
|
|
CostTime: req.Report.Costtime,
|
|
Tab: conf.Tab,
|
|
}
|
|
|
|
// 数据写到跨服中
|
|
if conn_, err := db.Cross(); err == nil {
|
|
dbModel := db.NewDBModel(comm.TablePagodaRecord, conn_)
|
|
dbModel.AddList(uid, newData.Id, newData)
|
|
} else {
|
|
this.module.Errorf("db crosserr :%v", err)
|
|
}
|
|
|
|
this.module.SetPagodaRankList("pagodaList"+strconv.Itoa(int(newData.PagodaId)), pagoda.PagodaId, newData.Id)
|
|
}
|
|
|
|
// 通关奖励
|
|
errdata = this.module.DispenseRes(session, conf.Reward, true)
|
|
if errdata != nil {
|
|
return
|
|
}
|
|
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.ModuleSys.CheckOpenCond(session, comm.OpencondTypePagoda, conf.Key)
|
|
this.module.ModuleBuried.TriggerBuried(session, comm.GetBuriedParam(comm.Rtype168, pagoda.Data[conf.Tab], conf.Tab))
|
|
this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "PagodaChallengeOverReq", conf.Reward)
|
|
})
|
|
return
|
|
}
|