162 lines
4.9 KiB
Go
162 lines
4.9 KiB
Go
package pagoda
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/db"
|
|
"math"
|
|
"strconv"
|
|
"time"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.PagodaChallengeOverReq) (code pb.ErrorCode) {
|
|
if req.Cid <= 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
///挑战主线关卡
|
|
func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.PagodaChallengeOverReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
mapData map[string]interface{}
|
|
pagoda *pb.DBPagoda
|
|
costTime int32 // 本次战斗消耗的时间
|
|
isWin bool
|
|
err error
|
|
)
|
|
mapData = make(map[string]interface{}, 0)
|
|
code = this.ChallengeOverCheck(session, req)
|
|
if code != pb.ErrorCode_Success {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
|
|
conf := this.module.configure.GetPagodaConfigData(req.Cid)
|
|
if conf == nil {
|
|
code = pb.ErrorCode_PagodaNotFound
|
|
return
|
|
}
|
|
pagoda, err = this.module.modelPagoda.getPagodaList(session.GetUserId())
|
|
if err != nil {
|
|
code = pb.ErrorCode_PagodaNotFound
|
|
return
|
|
}
|
|
|
|
if v, ok := pagoda.Data[conf.Tab]; !ok {
|
|
if conf.LayerNum == 1 {
|
|
pagoda.Data[conf.Tab] = 0
|
|
} else {
|
|
code = pb.ErrorCode_PagodaLevlErr // 挑战关卡数据不匹配
|
|
return
|
|
}
|
|
} else {
|
|
if conf.LayerNum-1 != v {
|
|
code = pb.ErrorCode_PagodaLevlErr // 挑战关卡数据不匹配
|
|
return
|
|
}
|
|
}
|
|
// 校验条件
|
|
if conf.Unlock != 0 {
|
|
if !this.mline.CheckCommpleteStage(session.GetUserId(), conf.Unlock) {
|
|
code = pb.ErrorCode_PagodaUnlock
|
|
return
|
|
}
|
|
}
|
|
// 校验通过
|
|
code, isWin = this.module.battle.CheckBattleReport(session, req.Report)
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
if !isWin { // 战斗失败直接返回
|
|
code = pb.ErrorCode_BattleNoWin
|
|
return
|
|
}
|
|
costTime = req.Report.Costtime
|
|
// 加经验
|
|
if req.Report != nil && req.Report.Info != nil && len(req.Report.Info.Redflist) > 0 {
|
|
for _, v := range req.Report.Info.Redflist[0].Team {
|
|
if conf.Exp > 0 && !v.Ishelp { // 助战英雄不加经验
|
|
this.module.ModuleHero.AddHeroExp(session, v.Oid, conf.Exp)
|
|
}
|
|
}
|
|
}
|
|
|
|
pagoda.Data[conf.Tab] += 1
|
|
|
|
mapData["pagodaId"] = pagoda.PagodaId
|
|
mapData["type"] = pagoda.Type
|
|
mapData["data"] = pagoda.Data
|
|
|
|
this.module.modulerank.AddPagodaRecord(session.GetUserId(), costTime, pagoda.PagodaId, conf.PagodaType)
|
|
if conf.LayerNum > pagoda.PagodaId {
|
|
pagoda.PagodaId = conf.LayerNum // 更新层数
|
|
}
|
|
|
|
code = this.module.ModifyPagodaData(session.GetUserId(), mapData)
|
|
session.SendMsg(string(this.module.GetType()), PagodaChallengeOverResp, &pb.PagodaChallengeOverResp{Data: pagoda})
|
|
if user := this.module.ModuleUser.GetUser(session.GetUserId()); user != 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 != nil {
|
|
szLine = append(szLine, &pb.LineUp{
|
|
Cid: v.HeroID,
|
|
Star: v.Star,
|
|
Lv: v.Lv,
|
|
})
|
|
}
|
|
}
|
|
// 数据直接插入跨服数据库中
|
|
uid := session.GetUserId()
|
|
userinfo := this.module.ModuleUser.GetUser(session.GetUserId())
|
|
newData := &pb.DBPagodaRecord{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: session.GetUserId(),
|
|
PagodaId: pagoda.PagodaId,
|
|
Type: pagoda.Type,
|
|
Nickname: userinfo.Name,
|
|
Icon: "",
|
|
Lv: userinfo.Lv,
|
|
Leadpos: leadpos,
|
|
Line: szLine,
|
|
CostTime: req.Report.Costtime,
|
|
}
|
|
costTime = newData.CostTime
|
|
// 数据写到跨服中
|
|
conn_, err := db.Cross()
|
|
dbModel := db.NewDBModel(comm.TableSeasonRecord, time.Hour, conn_)
|
|
dbModel.AddList(uid, newData.Id, newData)
|
|
this.module.SetPagodaRankList("pagodaList"+strconv.Itoa(int(newData.PagodaId)), int64(math.MaxInt32-newData.CostTime), newData.Id)
|
|
dbModelTable := db.NewDBModel(comm.TableSeasonPagoda, time.Hour, conn_)
|
|
if err = dbModelTable.Get(session.GetUserId(), pagoda); err == nil {
|
|
dbModelTable.Change(session.GetUserId(), mapData) // 修改跨服数据
|
|
score := int64(pagoda.PagodaId)<<31 + int64(math.MaxInt32-costTime)
|
|
this.module.SetPagodaRankList("pagodaSeasonRank", score, session.GetUserId())
|
|
}
|
|
}
|
|
|
|
// 通关奖励
|
|
code = this.module.DispenseRes(session, conf.Reward, true)
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
// 任务相关
|
|
|
|
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype58, 1)
|
|
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype59, pagoda.PagodaId)
|
|
go this.module.ModuleRtask.TriggerTask(session.GetUserId(), comm.GettaskParam(comm.Rtype58, 1), comm.GettaskParam(comm.Rtype59, pagoda.PagodaId))
|
|
return
|
|
}
|