89 lines
2.6 KiB
Go
89 lines
2.6 KiB
Go
package enchant
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.EnchantChallengeOverReq) (code pb.ErrorCode) {
|
|
if req.BossType <= 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
///挑战主线关卡
|
|
func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.EnchantChallengeOverReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
mapData map[string]interface{}
|
|
bWin bool // 战斗是否胜利
|
|
score int32 // 通关获得分数
|
|
)
|
|
mapData = make(map[string]interface{}, 0)
|
|
// reward = make([]*cfg.Gameatn, 0)
|
|
code = this.ChallengeOverCheck(session, req)
|
|
if code != pb.ErrorCode_Success {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
|
|
enchant, err := this.module.modelEnchant.getEnchantList(session.GetUserId())
|
|
if err != nil {
|
|
code = pb.ErrorCode_PagodaNotFound
|
|
return
|
|
}
|
|
|
|
cfgEnchant := this.module.configure.GetEnchantBossConfigData(req.BossType)
|
|
if cfgEnchant == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
|
|
// check
|
|
code, bWin = this.module.battle.CheckBattleReport(session, req.Report)
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
if !bWin { // 战斗失败了 直接返回
|
|
if code = this.module.ConsumeRes(session, cfgEnchant[0].PsMg, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), EnchantChallengeOverResp, &pb.EnchantChallengeOverResp{Data: enchant})
|
|
return
|
|
}
|
|
if code = this.module.ConsumeRes(session, cfgEnchant[0].PsConsume, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
if bWin {
|
|
this.module.CheckRank(session.GetUserId(), req.BossType, enchant, req.Report, req.Score)
|
|
}
|
|
enchant.Boss[req.BossType] = req.Score // 获得的积分
|
|
// 发放通关随机奖励
|
|
for _, v := range cfgEnchant {
|
|
if score >= v.ScoreLow && score <= v.ScoreUp {
|
|
for _, v1 := range v.RewardDrop {
|
|
reward := this.module.configure.GetDropReward(v1) // 获取掉落奖励
|
|
if code = this.module.DispenseRes(session, reward, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
mapData["bossTime"] = enchant.BossTime
|
|
mapData["boss"] = enchant.Boss
|
|
code = this.module.ModifyEnchantData(session.GetUserId(), mapData)
|
|
if session.GetUserId() != "" { // 恢复时间
|
|
if userexpand, err := this.module.ModuleUser.GetUserExpand(session.GetUserId()); err == nil {
|
|
enchant.RecoveryTime = userexpand.Recovertimeunifiedticket
|
|
}
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), EnchantChallengeOverResp, &pb.EnchantChallengeOverResp{Data: enchant})
|
|
|
|
return
|
|
}
|