195 lines
5.6 KiB
Go
195 lines
5.6 KiB
Go
package pagoda
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
"go_dreamfactory/sys/db"
|
|
"strconv"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
// 参数校验
|
|
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 // 通关奖励
|
|
//timeCheckOk bool // 开启条件校验
|
|
)
|
|
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
|
|
}
|
|
if v, ok := race.Race[conf.Restriction]; !ok {
|
|
if conf.Floors == 1 {
|
|
race.Race[conf.Restriction] = &pb.RaceData{
|
|
Race: conf.Restriction,
|
|
Rtime: configure.Now().Unix(),
|
|
Defeat: 0,
|
|
Endtime: 0,
|
|
Curfloor: 0,
|
|
}
|
|
} else {
|
|
errdata = &pb.ErrorData{ // 挑战关卡数据不匹配
|
|
Code: pb.ErrorCode_PagodaLevlErr,
|
|
Title: pb.ErrorCode_PagodaLevlErr.ToString(),
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
if v.Curfloor+1 != conf.Floors {
|
|
errdata = &pb.ErrorData{ // 挑战关卡数据不匹配
|
|
Code: pb.ErrorCode_PagodaLevlErr,
|
|
Title: pb.ErrorCode_PagodaLevlErr.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)
|
|
}
|
|
|
|
race.Race[conf.Restriction].Curfloor += 1
|
|
race.Race[conf.Restriction].Defeat += 1
|
|
race.Race[conf.Restriction].Task = conf.Fightevents
|
|
mapData["race"] = race.Race
|
|
|
|
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{
|
|
Race: race.Race[conf.Restriction],
|
|
Reward: atno,
|
|
})
|
|
|
|
// 记录爬塔明细数据
|
|
if req.Report != nil && req.Report.Info != nil && len(req.Report.Info.Redflist) > 0 {
|
|
|
|
// 数据直接插入跨服数据库中
|
|
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.DBRacePagodaRecord{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: session.GetUserId(),
|
|
Floor: race.Race[conf.Restriction].Curfloor,
|
|
Type: conf.Restriction,
|
|
Nickname: userinfo.Name,
|
|
Skin: userinfo.CurSkin, // 皮肤
|
|
Sex: userinfo.Gender,
|
|
Lv: userinfo.Lv,
|
|
Overtime: configure.Now().Unix(),
|
|
Title: userinfo.Curtitle,
|
|
}
|
|
|
|
// 数据写到跨服中
|
|
if conn_, err := db.Cross(); err == nil {
|
|
dbModel := db.NewDBModel(comm.TableRaceRecord, conn_)
|
|
result := make([]*pb.DBRacePagodaRecord, 0)
|
|
bRet := false
|
|
dbModel.GetList(uid, &result)
|
|
for _, v := range result {
|
|
if v.Type == conf.Restriction {
|
|
newData.Id = v.Id
|
|
mapRankData := make(map[string]interface{}, 0)
|
|
mapRankData["floor"] = race.Race[conf.Restriction].Curfloor
|
|
mapRankData["overtime"] = configure.Now().Unix()
|
|
dbModel.ChangeList(uid, newData.Id, mapRankData)
|
|
bRet = true
|
|
break
|
|
}
|
|
}
|
|
if !bRet {
|
|
dbModel.AddList(uid, newData.Id, newData)
|
|
}
|
|
|
|
} else {
|
|
this.module.Errorf("db crosserr :%v", err)
|
|
}
|
|
this.module.SetRacePagodaRankList("race"+strconv.Itoa(int(conf.Restriction)), race.Race[conf.Restriction].Curfloor, session.GetUserId(), newData.Id)
|
|
}
|
|
// 任务相关
|
|
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(), comm.GMResAddType, "PagodaChallengeRaceOverReq", atno)
|
|
})
|
|
return
|
|
}
|