go_dreamfactory/modules/pagoda/api_challenge.go
2022-08-26 15:46:18 +08:00

125 lines
3.7 KiB
Go

package pagoda
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"go.mongodb.org/mongo-driver/bson/primitive"
"google.golang.org/protobuf/proto"
)
//参数校验
func (this *apiComp) ChallengeCheck(session comm.IUserSession, req *pb.PagodaChallengeReq) (code pb.ErrorCode) {
if req.LevelID <= 0 && req.PagodaType != 0 {
code = pb.ErrorCode_ReqParameterError
return
}
return
}
///挑战主线关卡
func (this *apiComp) Challenge(session comm.IUserSession, req *pb.PagodaChallengeReq) (code pb.ErrorCode, data proto.Message) {
var (
mapData map[string]interface{}
)
mapData = make(map[string]interface{}, 0)
code = this.ChallengeCheck(session, req)
if code != pb.ErrorCode_Success {
return // 参数校验失败直接返回
}
pagoda, err := this.module.modelPagoda.getPagodaList(session.GetUserId())
if err != nil {
code = pb.ErrorCode_PagodaNotFound
return
}
cfg := this.module.configure.GetPagodaConfigData(req.PagodaType, req.LevelID)
if cfg == nil {
code = pb.ErrorCode_PagodaNotFound
return
}
if req.PagodaType == comm.PagodaType { // 普通塔
if pagoda.Type != cfg.PagodaType || cfg.PreLevel != pagoda.PagodaId {
code = pb.ErrorCode_PagodaLevlErr // 挑战关卡数据不匹配
return
}
//// todo 战斗相关
pagoda.Type = req.PagodaType
mapData["pagodaId"] = cfg.LayerNum
mapData["type"] = pagoda.Type
this.module.modulerank.ChangeUserRank(session.GetUserId(), mapData)
// 通关奖励
code = this.module.DispenseRes(session, cfg.Reward, true)
if code != pb.ErrorCode_Success {
return
}
pagoda.PagodaId = cfg.LayerNum // 更新层数
mapData["pagodaId"] = cfg.LayerNum
code = this.module.ModifyPagodaData(session.GetUserId(), mapData)
session.SendMsg(string(this.module.GetType()), PagodaChallengeResp, &pb.PagodaChallengeResp{Data: pagoda})
return
} else {
// 普通塔通关了
Nomalcfg := this.module.configure.GetPagodaConfigData(comm.PagodaType, pagoda.PagodaId+1)
if Nomalcfg != nil {
code = pb.ErrorCode_PagodaNotFound
return
}
// 塔数据校验
seasonPagoda, _ := this.module.modelSeasonPagoda.getSeasonPagodaList(session.GetUserId())
if seasonPagoda == nil {
if req.LevelID != 1 {
code = pb.ErrorCode_PagodaLevlErr // 挑战关卡数据不匹配
return
}
} else {
if seasonPagoda.Type != req.PagodaType || cfg.PreLevel != seasonPagoda.PagodaId {
code = pb.ErrorCode_PagodaLevlErr // 挑战关卡数据不匹配
return
}
}
// 挑战处理
if seasonPagoda == nil {
seasonPagoda = &pb.DBSeasonPagoda{}
seasonPagoda.Id = primitive.NewObjectID().Hex()
seasonPagoda.Uid = session.GetUserId()
seasonPagoda.PagodaId = 1 // 初始数据1层
seasonPagoda.Type = req.PagodaType
this.module.modelSeasonPagoda.addNewSeasonPagoda(session.GetUserId(), seasonPagoda)
} else {
seasonPagoda.PagodaId = cfg.LayerNum
mapData["pagodaId"] = cfg.LayerNum
code = this.module.ModifySeasonPagodaData(session.GetUserId(), mapData)
}
rst, _ := this.module.modulerank.GetUserRandData(session.GetUserId())
if rst.Uid == "" {
rst.Uid = session.GetUserId()
rst.Id = primitive.NewObjectID().Hex()
rst.Type = req.PagodaType
rst.Nickname = this.module.ModuleUser.GetUser(session.GetUserId()).Name
rst.Lv = this.module.ModuleUser.GetUser(session.GetUserId()).Lv
rst.PagodaId = pagoda.PagodaId
this.module.modulerank.AddRank(session.GetUserId(), rst)
} else {
mapData["pagodaId"] = cfg.LayerNum
this.module.modulerank.ChangeUserRank(session.GetUserId(), mapData)
}
pagoda.PagodaId = seasonPagoda.PagodaId
pagoda.Type = seasonPagoda.Type
pagoda.Reward = seasonPagoda.Reward
session.SendMsg(string(this.module.GetType()), PagodaChallengeResp, &pb.PagodaChallengeResp{Data: pagoda})
}
return
}