146 lines
5.3 KiB
Go
146 lines
5.3 KiB
Go
package hunting
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"strconv"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.HuntingChallengeOverReq) (code pb.ErrorCode) {
|
|
if req.BossType <= 0 && req.Difficulty > 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
///挑战主线关卡
|
|
func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.HuntingChallengeOverReq) (code pb.ErrorCode, data *pb.ErrorData) {
|
|
var (
|
|
mapData map[string]interface{}
|
|
newChallenge bool // 新的关卡
|
|
reward []*cfg.Gameatn
|
|
bWin bool // 战斗是否胜利
|
|
tasks []*comm.TaskParam = make([]*comm.TaskParam, 0)
|
|
)
|
|
mapData = make(map[string]interface{}, 0)
|
|
reward = make([]*cfg.Gameatn, 0)
|
|
code = this.ChallengeOverCheck(session, req)
|
|
if code != pb.ErrorCode_Success {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
|
|
hunting, err := this.module.modelHunting.getHuntingList(session.GetUserId())
|
|
if err != nil {
|
|
code = pb.ErrorCode_PagodaNotFound
|
|
return
|
|
}
|
|
cfgHunting := this.module.configure.GetHuntingBossConfigData(req.BossType, req.Difficulty)
|
|
if cfgHunting == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
|
|
if req.Difficulty == 1 && hunting.Boss[req.BossType] == 0 {
|
|
hunting.Boss[req.BossType] = 1
|
|
}
|
|
|
|
if value, ok := hunting.Boss[req.BossType]; ok { // 类型校验
|
|
if value < req.Difficulty-1 {
|
|
code = pb.ErrorCode_HuntingLvErr
|
|
return
|
|
}
|
|
} else {
|
|
code = pb.ErrorCode_HuntingLvErr
|
|
return
|
|
}
|
|
if hunting.Boss[req.BossType] < req.Difficulty {
|
|
hunting.Boss[req.BossType] = req.Difficulty
|
|
}
|
|
// 校验是不是达到最大难度
|
|
maxDifficulity := this.module.configure.GetMaxDifficultyByBossID(req.BossType)
|
|
if hunting.Boss[req.BossType] > maxDifficulity {
|
|
hunting.Boss[req.BossType] = maxDifficulity
|
|
}
|
|
mapData["boss"] = hunting.Boss
|
|
code, bWin = this.module.battle.CheckBattleReport(session, req.Report)
|
|
if code = this.module.ModuleItems.RecoverTicket(session); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
if !bWin { // 战斗失败了 直接返回
|
|
if code = this.module.ConsumeRes(session, cfgHunting.PsMg, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), HuntingChallengeOverResp, &pb.HuntingChallengeOverResp{Data: hunting})
|
|
return
|
|
}
|
|
if code = this.module.ConsumeRes(session, cfgHunting.PsConsume, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
key := strconv.Itoa(int(req.BossType)) + "_" + strconv.Itoa(int(req.Difficulty))
|
|
if hunting.BossTime[key] == 0 { // 新关卡挑战通过 发放首通奖励
|
|
mapData["boss"] = hunting.Boss
|
|
if code = this.module.DispenseRes(session, cfgHunting.Firstprize, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
}
|
|
hunting.BossTime[key] = req.Report.Costtime
|
|
// 耗时校验 当前战斗胜利时间消耗小于之前刷新数据
|
|
if (hunting.BossTime[key] > req.Report.Costtime || hunting.BossTime[key] == 0) && req.Difficulty >= hunting.Boss[req.BossType] {
|
|
|
|
mapData["bossTime"] = hunting.BossTime // 更新时间
|
|
userinfo := this.module.ModuleUser.GetUser(session.GetUserId())
|
|
this.module.CheckRank(session.GetUserId(), req.BossType, req.Difficulty, req.Report, userinfo)
|
|
}
|
|
// 发放通关随机奖励
|
|
reward = this.module.configure.GetDropReward(cfgHunting.Drop) // 获取掉落奖励
|
|
if code = this.module.DispenseRes(session, reward, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
if newChallenge && bWin { // 新关卡挑战通过 发放首通奖励
|
|
if code = this.module.DispenseRes(session, cfgHunting.Firstprize, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
hunting.Boss[req.BossType] += 1
|
|
mapData["boss"] = hunting.Boss
|
|
}
|
|
|
|
mapData["bossTime"] = hunting.BossTime
|
|
code = this.module.ModifyHuntingData(session.GetUserId(), mapData)
|
|
if session.GetUserId() != "" { // 恢复时间
|
|
if userexpand, err := this.module.ModuleUser.GetUserExpand(session.GetUserId()); err == nil {
|
|
hunting.RecoveryTime = userexpand.Recovertimeunifiedticket
|
|
}
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), HuntingChallengeOverResp, &pb.HuntingChallengeOverResp{Data: hunting})
|
|
tasks = append(tasks, comm.GettaskParam(comm.Rtype80, 1, req.Difficulty, req.BossType))
|
|
// 随机任务统计
|
|
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype81, req.Difficulty, req.BossType)
|
|
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype82, req.BossType)
|
|
tasks = append(tasks, comm.GettaskParam(comm.Rtype81, req.Difficulty, req.BossType))
|
|
tasks = append(tasks, comm.GettaskParam(comm.Rtype82, 1, req.BossType))
|
|
// 狩猎副本掉落觉醒材料
|
|
for _, v := range reward {
|
|
if _conf, err := this.module.configure.GetItemConfigureData(v.T); err == nil {
|
|
if _conf.Usetype == comm.UseType8 {
|
|
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype154, v.N)
|
|
tasks = append(tasks, comm.GettaskParam(comm.Rtype154, v.N))
|
|
}
|
|
}
|
|
}
|
|
if newChallenge && bWin {
|
|
for _, v := range cfgHunting.Firstprize {
|
|
if _conf, err := this.module.configure.GetItemConfigureData(v.T); err == nil {
|
|
if _conf.Usetype == comm.UseType8 {
|
|
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype154, v.N)
|
|
tasks = append(tasks, comm.GettaskParam(comm.Rtype154, v.N))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
go this.module.ModuleRtask.TriggerTask(session.GetUserId(), tasks...)
|
|
return
|
|
}
|