184 lines
5.3 KiB
Go
184 lines
5.3 KiB
Go
package viking
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"strconv"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.VikingChallengeOverReq) (code pb.ErrorCode) {
|
|
if req.BossId <= 0 && req.Difficulty > 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
///挑战完成
|
|
func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.VikingChallengeOverReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
mapData map[string]interface{}
|
|
newChallenge bool // 新的关卡
|
|
reward []*cfg.Gameatn
|
|
asset []*pb.UserAssets
|
|
costTime int32 // 战斗花费的时间
|
|
)
|
|
mapData = make(map[string]interface{}, 0)
|
|
reward = make([]*cfg.Gameatn, 0)
|
|
asset = make([]*pb.UserAssets, 0)
|
|
code = this.ChallengeOverCheck(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.BossId, req.Difficulty)
|
|
if cfg == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
|
|
value, ok := viking.Boss[req.BossId]
|
|
if !ok { // 类型校验
|
|
viking.Boss[req.BossId] = 0
|
|
}
|
|
if value < req.Difficulty {
|
|
if value+1 != req.Difficulty {
|
|
code = pb.ErrorCode_VikingLvErr
|
|
return
|
|
}
|
|
newChallenge = true
|
|
viking.Boss[req.BossId]++
|
|
// 校验是不是达到最大难度
|
|
maxDifficulity := this.module.configure.GetMaxDifficultyByBossID(req.BossId)
|
|
if viking.Boss[req.BossId] > maxDifficulity {
|
|
viking.Boss[req.BossId] = maxDifficulity
|
|
}
|
|
mapData["boss"] = viking.Boss
|
|
}
|
|
|
|
// 耗时校验 当前战斗胜利时间消耗小于之前刷新数据
|
|
code, _ = this.module.battle.CheckBattleReport(session, req.Report)
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
conf := this.module.configure.GetGlobalConf()
|
|
if conf != nil {
|
|
if viking.LeftCount >= conf.VikingNum {
|
|
viking.RecoveryTime = configure.Now().Unix()
|
|
}
|
|
}
|
|
viking.LeftCount--
|
|
mapData["leftCount"] = viking.LeftCount
|
|
viking.ChallengeCount++
|
|
mapData["challengeCount"] = viking.ChallengeCount
|
|
|
|
// 时间写入
|
|
key := strconv.Itoa(int(req.BossId)) + "_" + strconv.Itoa(int(req.Difficulty))
|
|
//if t, ok := viking.BossTime[key]; ok {
|
|
if viking.BossTime[key] > costTime || viking.BossTime[key] == 0 { // 刷新记录
|
|
viking.BossTime[key] = costTime
|
|
szLine := make([]*pb.LineUp, 5)
|
|
Leadpos := 0
|
|
if req.Report != nil && req.Report.Info != nil && len(req.Report.Info.Redflist) > 0 {
|
|
costTime = req.Report.Costtime
|
|
Leadpos = int(req.Report.Info.Redflist[0].Leadpos)
|
|
for i, v := range req.Report.Info.Redflist[0].Team {
|
|
if v != nil {
|
|
szLine[i] = &pb.LineUp{
|
|
Cid: v.HeroID,
|
|
Star: v.Star,
|
|
Lv: v.Lv,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 写入排行榜
|
|
objID := ""
|
|
if newChallenge { // 插入
|
|
userinfo := this.module.ModuleUser.GetUser(session.GetUserId())
|
|
new := &pb.DBVikingRank{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: session.GetUserId(),
|
|
Difficulty: req.Difficulty,
|
|
Bosstype: req.BossId,
|
|
Nickname: userinfo.Name,
|
|
Icon: "",
|
|
Lv: userinfo.Lv,
|
|
Leadpos: int32(Leadpos),
|
|
Line: szLine,
|
|
CostTime: costTime,
|
|
}
|
|
objID = new.Id
|
|
this.module.modulerank.AddList(session.GetUserId(), new.Id, new)
|
|
} else { // 更新数据
|
|
ranks := this.module.modulerank.getVikingRankList(session.GetUserId())
|
|
for _, v := range ranks {
|
|
if v.Bosstype == req.BossId && v.Difficulty == req.Difficulty {
|
|
mapRankData := make(map[string]interface{}, 0)
|
|
mapRankData["difficulty"] = req.Difficulty
|
|
mapRankData["bosstype"] = req.BossId
|
|
mapRankData["Leadpos"] = Leadpos
|
|
mapRankData["line"] = szLine
|
|
mapRankData["costTime"] = costTime
|
|
this.module.modulerank.ChangeUserRank(session.GetUserId(), v.Id, mapRankData)
|
|
objID = v.Id
|
|
break
|
|
}
|
|
}
|
|
}
|
|
this.module.modulerank.SetRankListData("vikingRank"+strconv.Itoa(int(req.BossId)), req.Difficulty<<16+costTime, objID)
|
|
}
|
|
//}
|
|
mapData["bossTime"] = viking.BossTime // 更新时间
|
|
if newChallenge { // 新关卡挑战通过 发放首通奖励
|
|
if code = this.module.DispenseRes(session, cfg.Firstprize, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
viking.Boss[req.BossId] += 1
|
|
mapData["boss"] = viking.Boss
|
|
for _, v := range cfg.Firstprize {
|
|
asset = append(asset, &pb.UserAssets{
|
|
A: v.A,
|
|
T: v.T,
|
|
N: v.N,
|
|
})
|
|
}
|
|
} else {
|
|
reward = this.module.configure.GetDropReward(cfg.Drop) // 获取掉落奖励
|
|
if code = this.module.DispenseRes(session, reward, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
for _, v := range reward {
|
|
asset = append(asset, &pb.UserAssets{
|
|
A: v.A,
|
|
T: v.T,
|
|
N: v.N,
|
|
})
|
|
}
|
|
}
|
|
code = this.module.ModifyVikingData(session.GetUserId(), mapData)
|
|
// 发放通关随机奖励
|
|
session.SendMsg(string(this.module.GetType()), VikingChallengeOverResp, &pb.VikingChallengeOverResp{
|
|
Data: viking,
|
|
Asset: asset,
|
|
})
|
|
return
|
|
}
|