go_dreamfactory/modules/enchant/api_challengeover.go
2023-06-06 10:11:23 +08:00

99 lines
3.0 KiB
Go

package enchant
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
)
//参数校验
func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.EnchantChallengeOverReq) (errdata *pb.ErrorData) {
if req.BossType <= 0 {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
}
return
}
return
}
///挑战主线关卡
func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.EnchantChallengeOverReq) (errdata *pb.ErrorData) {
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 errdata != nil {
return // 参数校验失败直接返回
}
enchant, err := this.module.modelEnchant.getEnchantList(session.GetUserId())
if err != nil {
code = pb.ErrorCode_PagodaNotFound
return
}
cfgEnchant, err := this.module.configure.GetEnchantBossConfigData(req.BossType)
if err != nil {
code = pb.ErrorCode_ConfigNoFound
data = &pb.ErrorData{
Title: pb.GetErrorCodeMsg(code),
Message: err.Error(),
}
return
}
// check
code, bWin = this.module.battle.CheckBattleReport(session, req.Report)
if errdata != nil {
return
}
if !bWin { // 战斗失败了 直接返回
if code = this.module.ConsumeRes(session, cfgEnchant[0].PsMg, true); errdata != nil {
return
}
session.SendMsg(string(this.module.GetType()), EnchantChallengeOverResp, &pb.EnchantChallengeOverResp{Data: enchant})
return
}
if code = this.module.ConsumeRes(session, cfgEnchant[0].PsConsume, true); errdata != nil {
return
}
key := req.BossType
if enchant.BossTime[key] > req.Report.Costtime || enchant.BossTime[key] == 0 {
enchant.BossTime[key] = req.Report.Costtime
mapData["bossTime"] = enchant.BossTime // 更新时间
userinfo := this.module.ModuleUser.GetUser(session.GetUserId())
this.module.CheckRank(session.GetUserId(), req.BossType, req.Report, userinfo, req.Score)
}
//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); errdata != nil {
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
}