go_dreamfactory/modules/enchant/api_challengeover.go

102 lines
2.9 KiB
Go

package enchant
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"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
}
conf := this.module.configure.GetGlobalConf()
if conf == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
costRes := conf.EnchantbossCos
if costRes == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
if code = this.module.CheckRes(session, []*cfg.Gameatn{costRes}); code != pb.ErrorCode_Success {
code = pb.ErrorCode_EnchantNoChallengeCount
return
}
cfgEnchant := this.module.configure.GetEnchantBossConfigData(req.BossType)
if cfgEnchant == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
// 校验门票数量够不够
if code = this.module.ConsumeRes(session, []*cfg.Gameatn{costRes}, true); code != pb.ErrorCode_Success {
return
}
// check
code, bWin = this.module.battle.CheckBattleReport(session, req.Report)
if code != pb.ErrorCode_Success {
return
}
amount := int32(this.module.ModuleItems.QueryItemAmount(session.GetUserId(), costRes.T)) // 获取当前数量
if amount < conf.EnchantbossMax { // 挑战卷 小于副本最大存储数的时候开始恢复
enchant.RecoveryTime = configure.Now().Unix()
mapData["recoveryTime"] = enchant.RecoveryTime
}
if bWin {
this.module.CheckRank(session.GetUserId(), req.BossType, enchant, req.Report, 0)
}
enchant.Boss[req.BossType] = 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["challengeTime"] = enchant.BossTime
mapData["boss"] = enchant.Boss
code = this.module.ModifyEnchantData(session.GetUserId(), mapData)
session.SendMsg(string(this.module.GetType()), EnchantChallengeOverResp, &pb.EnchantChallengeOverResp{Data: enchant})
return
}