159 lines
4.8 KiB
Go
159 lines
4.8 KiB
Go
package hunting
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"go_dreamfactory/sys/db"
|
|
"strconv"
|
|
"time"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
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 proto.Message) {
|
|
var (
|
|
mapData map[string]interface{}
|
|
newChallenge bool // 新的关卡
|
|
reward []*cfg.Gameatn
|
|
costTime int32
|
|
)
|
|
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
|
|
}
|
|
if hunting.ChallengeCount > this.module.configure.GetGlobalConf().HuntingNum+hunting.BuyCount {
|
|
code = pb.ErrorCode_HuntingMaxChallengeCount
|
|
return
|
|
}
|
|
cfg := this.module.configure.GetHuntingBossConfigData(req.BossType, req.Difficulty)
|
|
if cfg == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
value, ok := hunting.Boss[req.BossType]
|
|
if !ok { // 类型校验
|
|
hunting.Boss[req.BossType] = 0
|
|
}
|
|
if value < req.Difficulty {
|
|
if value+1 != req.Difficulty {
|
|
code = pb.ErrorCode_HuntingLvErr
|
|
return
|
|
}
|
|
newChallenge = true
|
|
}
|
|
// check
|
|
code, _ = this.module.battle.CheckBattleReport(session, req.Report)
|
|
if code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
if req.Report != nil {
|
|
costTime = req.Report.Costtime
|
|
}
|
|
key := strconv.Itoa(int(req.BossType)) + "_" + strconv.Itoa(int(req.Difficulty))
|
|
|
|
if hunting.BossTime[key] > costTime || hunting.BossTime[key] == 0 && req.Difficulty >= hunting.Boss[req.BossType] { // 刷新记录
|
|
hunting.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 := ""
|
|
bFind := false
|
|
ranks := this.module.modulerank.getHuntingRankList(session.GetUserId())
|
|
for _, v := range ranks {
|
|
if v.Bosstype == req.BossType {
|
|
mapRankData := make(map[string]interface{}, 0)
|
|
mapRankData["difficulty"] = req.Difficulty
|
|
mapRankData["bosstype"] = req.BossType
|
|
mapRankData["Leadpos"] = Leadpos
|
|
mapRankData["line"] = szLine
|
|
mapRankData["costTime"] = costTime
|
|
conn_, _ := db.Cross()
|
|
dbModel := db.NewDBModel(comm.TableHuntingRank, time.Hour, conn_)
|
|
dbModel.ChangeList(session.GetUserId(), v.Id, mapRankData)
|
|
objID = v.Id
|
|
bFind = true
|
|
break
|
|
}
|
|
}
|
|
if !bFind {
|
|
userinfo := this.module.ModuleUser.GetUser(session.GetUserId())
|
|
new := &pb.DBHuntingRank{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Uid: session.GetUserId(),
|
|
Difficulty: req.Difficulty,
|
|
Bosstype: req.BossType,
|
|
Nickname: userinfo.Name,
|
|
Icon: "",
|
|
Lv: userinfo.Lv,
|
|
Leadpos: int32(Leadpos),
|
|
Line: szLine,
|
|
CostTime: costTime,
|
|
}
|
|
objID = new.Id
|
|
conn_, _ := db.Cross()
|
|
dbModel := db.NewDBModel(comm.TableHuntingRank, time.Hour, conn_)
|
|
dbModel.AddList(session.GetUserId(), new.Id, new)
|
|
}
|
|
this.module.modulerank.SetRankListData("huntingRank"+strconv.Itoa(int(req.BossType)), req.Difficulty<<16+costTime, objID)
|
|
}
|
|
|
|
// 耗时校验 当前战斗胜利时间消耗小于之前刷新数据
|
|
hunting.LeftCount--
|
|
mapData["leftCount"] = hunting.LeftCount
|
|
hunting.ChallengeCount++
|
|
mapData["challengeCount"] = hunting.ChallengeCount
|
|
|
|
code = this.module.ModifyHuntingData(session.GetUserId(), mapData)
|
|
// 发放通关随机奖励
|
|
reward = this.module.configure.GetDropReward(cfg.Drop) // 获取掉落奖励
|
|
if code = this.module.DispenseRes(session, reward, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
if newChallenge { // 新关卡挑战通过 发放首通奖励
|
|
if code = this.module.DispenseRes(session, cfg.Firstprize, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
hunting.Boss[req.BossType] += 1
|
|
mapData["boss"] = hunting.Boss
|
|
mapData["challengeTime"] = hunting.BossTime
|
|
}
|
|
for k := range hunting.Boss {
|
|
hunting.Boss[k] += 1
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), HuntingChallengeOverResp, &pb.HuntingChallengeOverResp{Data: hunting})
|
|
return
|
|
}
|