261 lines
7.2 KiB
Go
261 lines
7.2 KiB
Go
package hunting
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) SweepCheck(session comm.IUserSession, req *pb.HuntingSweepReq) (errdata *pb.ErrorData) {
|
|
if req.BossId <= 0 && req.Difficulty > 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// /挑战完成
|
|
func (this *apiComp) Sweep(session comm.IUserSession, req *pb.HuntingSweepReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
viking *pb.DBHunting
|
|
record *pb.DBBattleRecord
|
|
infos []*pb.BattleInfo
|
|
runresp *pb.BattleRunResp
|
|
conf *cfg.GameSweepData
|
|
boosCfg *cfg.GameHuntingBossData
|
|
user *pb.DBUser
|
|
bWin bool // 战斗是否胜利
|
|
rewardatno []*pb.UserAtno // atno 类型
|
|
consumeatns []*pb.UserAssets // 消耗
|
|
changExp map[string]int32
|
|
heroupaward []*cfg.Gameatn
|
|
reward []*cfg.Gameatn
|
|
consume []*cfg.Gameatn
|
|
allconsume []*cfg.Gameatn
|
|
|
|
err error
|
|
result []*pb.HuntingSweepResult
|
|
ps int32
|
|
totalps int32
|
|
// 随机任务统计
|
|
tasks []*pb.BuriedParam
|
|
)
|
|
changExp = make(map[string]int32, 0)
|
|
|
|
if errdata = this.SweepCheck(session, req); errdata != nil {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
|
|
if viking, err = this.module.modelHunting.getHuntingList(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_VikingBoosType,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
boosCfg, err = this.module.configure.GetHuntingBossConfigData(req.BossId, req.Difficulty)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if req.Difficulty > viking.Boss[req.BossId] {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_VikingLvErr,
|
|
Title: pb.ErrorCode_VikingLvErr.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if user, err = this.module.GetUserForSession(session); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if errdata, record = this.module.battle.CreatePveBattle(session, &pb.BattlePVEReq{
|
|
Rulesid: boosCfg.BattleReadyID,
|
|
Ptype: pb.PlayType_viking,
|
|
Title: "",
|
|
Format: req.Battle,
|
|
Mformat: boosCfg.Boss,
|
|
}); errdata != nil {
|
|
return
|
|
}
|
|
for i := 0; i < int(req.Sweepnum); i++ {
|
|
infos = append(infos, &pb.BattleInfo{
|
|
Id: primitive.NewObjectID().Hex(),
|
|
Title: record.Title,
|
|
Rulesid: boosCfg.BattleReadyID,
|
|
Btype: record.Btype,
|
|
Ptype: record.Ptype,
|
|
RedCompId: record.RedCompId,
|
|
Redflist: record.Redflist,
|
|
BlueCompId: record.BlueCompId,
|
|
Buleflist: record.Buleflist,
|
|
Tasks: record.Tasks,
|
|
})
|
|
}
|
|
if errdata, runresp = this.module.battle.RunServerBattle(session, &pb.BattleRunReq{Info: infos}); errdata != nil {
|
|
return
|
|
}
|
|
|
|
for _, v := range runresp.Reports {
|
|
bWin = false
|
|
ps = 0
|
|
reward = make([]*cfg.Gameatn, 0)
|
|
consume = make([]*cfg.Gameatn, 0)
|
|
consumeatns = make([]*pb.UserAssets, 0)
|
|
if v.WinSide == 1 {
|
|
bWin = true
|
|
}
|
|
|
|
for _, v := range boosCfg.PsMg {
|
|
if v.A == "attr" && v.T == "ps" {
|
|
ps += v.N
|
|
}
|
|
}
|
|
consume = append(consume, boosCfg.PsMg...)
|
|
if conf, err = this.module.configure.GetGameSweepData(req.Sweepgroup, v.Round); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if !bWin { // 战斗失败了 直接返回
|
|
consume = append(consume, conf.LoseCost...)
|
|
reward = append(reward, this.module.ModuleUser.PsConvertExp(ps))
|
|
for _, v := range consume {
|
|
consumeatns = append(consumeatns, &pb.UserAssets{
|
|
A: v.A,
|
|
T: v.T,
|
|
N: v.N,
|
|
})
|
|
}
|
|
//发放资源
|
|
if errdata, rewardatno = this.module.DispenseAtno(session, reward, true); errdata != nil {
|
|
return
|
|
}
|
|
result = append(result, &pb.HuntingSweepResult{
|
|
Battleid: v.Info.Id,
|
|
Iswin: false,
|
|
Consume: consumeatns,
|
|
Rounds: v.Round,
|
|
Award: rewardatno,
|
|
})
|
|
totalps += ps
|
|
allconsume = append(allconsume, consume...)
|
|
|
|
break
|
|
}
|
|
for _, v := range boosCfg.PsConsume {
|
|
if v.A == "attr" && v.T == "ps" {
|
|
ps += v.N
|
|
}
|
|
}
|
|
totalps += ps
|
|
consume = append(consume, conf.WinCost...)
|
|
consume = append(consume, boosCfg.PsConsume...)
|
|
reward = append(reward, this.module.ModuleUser.PsConvertExp(ps))
|
|
reward = this.module.ModuleTools.GetGroupDataByLottery(boosCfg.Drop, user.Vip, user.Lv)
|
|
b := this.module.ModuleActivity.HDCelebration(session, 2, req.BossId)
|
|
for _, v := range reward {
|
|
reward = append(reward, v)
|
|
if b { // 活动双倍
|
|
reward = append(reward, v)
|
|
}
|
|
}
|
|
|
|
// 加经验
|
|
if boosCfg.Heroexp > 0 {
|
|
var heroObjs []string
|
|
if v != nil && v.Info != nil && len(v.Info.Redflist) > 0 {
|
|
for _, v1 := range v.Info.Redflist[0].Team {
|
|
if v1 != nil && v1.HeroID != "" {
|
|
if !v1.Ishelp { // 助战英雄不加经验
|
|
heroObjs = append(heroObjs, v1.Oid)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if changExp, heroupaward, errdata = this.module.ModuleHero.AddHerosExp(session, heroObjs, boosCfg.Heroexp); errdata != nil {
|
|
return
|
|
}
|
|
reward = append(reward, heroupaward...)
|
|
}
|
|
//发放资源
|
|
if errdata, rewardatno = this.module.DispenseAtno(session, reward, true); errdata != nil {
|
|
return
|
|
}
|
|
|
|
// 狩猎副本掉落觉醒材料
|
|
for _, v := range reward {
|
|
if v.A == "item" {
|
|
if _conf, err := this.module.configure.GetItemConfigureData(v.T); err == nil {
|
|
if _conf.Usetype == comm.UseType8 {
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype154, v.N))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
for _, v := range consume {
|
|
consumeatns = append(consumeatns, &pb.UserAssets{
|
|
A: v.A,
|
|
T: v.T,
|
|
N: v.N,
|
|
})
|
|
}
|
|
result = append(result, &pb.HuntingSweepResult{
|
|
Battleid: v.Info.Id,
|
|
Iswin: true,
|
|
Rounds: v.Round,
|
|
Consume: consumeatns,
|
|
Award: rewardatno,
|
|
Heroexp: changExp,
|
|
})
|
|
allconsume = append(allconsume, consume...)
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype80, 1, req.BossId, req.Difficulty))
|
|
// 随机任务统计
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype81, req.Difficulty, req.BossId))
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype82, 1, req.BossId))
|
|
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype83, 1, req.BossId, req.Difficulty))
|
|
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype200, 1))
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype251, 1, boosCfg.Id, v.Round))
|
|
}
|
|
|
|
//消耗资源
|
|
if errdata = this.module.ConsumeRes(session, allconsume, true); errdata != nil {
|
|
return
|
|
}
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype202, totalps))
|
|
session.SendMsg(string(this.module.GetType()), "sweep", &pb.HuntingSweepResp{
|
|
Result: result,
|
|
})
|
|
if len(tasks) > 0 {
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.chat.SendSysChatToWorld(session, comm.ChatSystem14, nil, req.BossId, req.Difficulty, user.Name)
|
|
this.module.ModuleBuried.TriggerBuried(session, tasks...)
|
|
this.module.WriteUserLog(session.GetUserId(), req, comm.GMResAddType, "HuntingSweepReq", rewardatno)
|
|
})
|
|
}
|
|
return
|
|
}
|