94 lines
2.8 KiB
Go
94 lines
2.8 KiB
Go
package viking
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) ChallengeCheck(session comm.IUserSession, req *pb.VikingChallengeReq) (code pb.ErrorCode) {
|
|
if req.BossType <= 0 && req.Difficulty > 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
///挑战主线关卡
|
|
func (this *apiComp) Challenge(session comm.IUserSession, req *pb.VikingChallengeReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
mapData map[string]interface{}
|
|
newChallenge bool // 新的关卡
|
|
reward []*cfg.Gameatn
|
|
)
|
|
mapData = make(map[string]interface{}, 0)
|
|
reward = make([]*cfg.Gameatn, 0)
|
|
code = this.ChallengeCheck(session, req)
|
|
if code != pb.ErrorCode_Success {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
|
|
viking, err := this.module.modelViking.getVikingList(session.GetUserId())
|
|
if err != nil {
|
|
code = pb.ErrorCode_VikingBoosType
|
|
return
|
|
}
|
|
|
|
if viking.ChallengeCount > this.module.configure.GetGlobalConf().VikingNum+viking.BuyCount {
|
|
code = pb.ErrorCode_VikingMaxChallengeCount
|
|
return
|
|
}
|
|
cfg := this.module.configure.GetVikingBossConfigData(req.BossType, req.Difficulty)
|
|
if cfg == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
|
|
value, ok := viking.Boss[req.BossType]
|
|
if !ok { // 类型校验
|
|
viking.Boss[req.BossType] = 0
|
|
}
|
|
if value < req.Difficulty {
|
|
if value+1 != req.Difficulty {
|
|
code = pb.ErrorCode_VikingLvErr
|
|
return
|
|
}
|
|
newChallenge = true
|
|
}
|
|
if newChallenge { // 新关卡挑战通过 发放首通奖励
|
|
if code = this.module.DispenseRes(session, cfg.Firstprize, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
viking.Boss[req.BossType] += 1
|
|
mapData["Boss"] = viking.Boss
|
|
// viking.ChallengeTime[req.BossType<<16+req.Difficulty] = 0 // todo 耗时
|
|
// mapData["challengeTime"] = viking.ChallengeTime
|
|
|
|
}
|
|
// 耗时校验 当前战斗胜利时间消耗小于之前刷新数据
|
|
|
|
viking.ChallengeCount++
|
|
mapData["challengeCount"] = viking.ChallengeCount
|
|
code = this.module.ModifyVikingData(session.GetUserId(), mapData)
|
|
// 发放通关随机奖励
|
|
this.module.configure.GetDropReward(cfg.Drop, reward) // 获取掉落奖励
|
|
if code = this.module.DispenseRes(session, reward, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
mapRankData := make(map[string]interface{}, 0)
|
|
mapRankData["difficulty"] = req.Difficulty
|
|
mapRankData["bosstype"] = req.BossType
|
|
mapRankData["uid"] = session.GetUserId()
|
|
userinfo := this.module.ModuleUser.GetUser(session.GetUserId())
|
|
mapRankData["nickname"] = userinfo.Name
|
|
mapRankData["lv"] = userinfo.Lv
|
|
mapRankData["costTime"] = 120
|
|
this.module.modulerank.ChangeUserRank(session.GetUserId(), mapRankData)
|
|
session.SendMsg(string(this.module.GetType()), VikingChallengeResp, &pb.VikingChallengeResp{Data: viking})
|
|
return
|
|
}
|