199 lines
6.4 KiB
Go
199 lines
6.4 KiB
Go
package viking
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"strconv"
|
|
)
|
|
|
|
// 参数校验
|
|
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 *pb.ErrorData) {
|
|
var (
|
|
mapData map[string]interface{}
|
|
reward []*cfg.Gameatn
|
|
bWin bool // 战斗是否胜利
|
|
atno []*pb.UserAtno // atno 类型
|
|
del []string // 自动出售的装备
|
|
changExp map[string]int32
|
|
res []*cfg.Gameatn // 最后获得的资源
|
|
bHelp bool
|
|
)
|
|
changExp = make(map[string]int32, 0)
|
|
mapData = make(map[string]interface{}, 0)
|
|
reward = make([]*cfg.Gameatn, 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
|
|
}
|
|
|
|
vikingCfg := this.module.configure.GetVikingBossConfigData(req.BossId, req.Difficulty)
|
|
if vikingCfg == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
|
|
if req.Difficulty == 1 && viking.Boss[req.BossId] == 0 {
|
|
viking.Boss[req.BossId] = 1
|
|
}
|
|
|
|
if value, ok := viking.Boss[req.BossId]; ok { // 类型校验
|
|
if value < req.Difficulty-1 {
|
|
code = pb.ErrorCode_HuntingLvErr
|
|
return
|
|
}
|
|
} else {
|
|
code = pb.ErrorCode_HuntingLvErr
|
|
return
|
|
}
|
|
if viking.Boss[req.BossId] < req.Difficulty {
|
|
viking.Boss[req.BossId] = req.Difficulty
|
|
}
|
|
// 校验是不是达到最大难度
|
|
maxDifficulity := this.module.configure.GetMaxDifficultyByBossID(req.BossId)
|
|
if viking.Boss[req.BossId] > maxDifficulity {
|
|
viking.Boss[req.BossId] = maxDifficulity
|
|
}
|
|
mapData["boss"] = viking.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, vikingCfg.PsMg, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), VikingChallengeOverResp, &pb.VikingChallengeOverResp{
|
|
Data: viking,
|
|
})
|
|
return
|
|
}
|
|
if code = this.module.ConsumeRes(session, vikingCfg.PsConsume, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
key := strconv.Itoa(int(req.BossId)) + "_" + strconv.Itoa(int(req.Difficulty))
|
|
if viking.BossTime[key] == 0 { // 新关卡挑战通过 发放首通奖励
|
|
|
|
mapData["boss"] = viking.Boss
|
|
if code = this.module.DispenseRes(session, vikingCfg.Firstprize, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
}
|
|
|
|
if (viking.BossTime[key] > req.Report.Costtime || viking.BossTime[key] == 0) && req.Difficulty >= viking.Boss[req.BossId] {
|
|
viking.BossTime[key] = req.Report.Costtime
|
|
userinfo := this.module.ModuleUser.GetUser(session.GetUserId())
|
|
this.module.CheckRank(session.GetUserId(), req.BossId, req.Difficulty, req.Report, userinfo)
|
|
}
|
|
mapData["bossTime"] = viking.BossTime // 更新时间
|
|
|
|
reward = this.module.configure.GetDropReward(vikingCfg.Drop) // 获取掉落奖励
|
|
// 星级校验
|
|
for _, v := range reward {
|
|
bFound := false
|
|
if v.A == "equp" {
|
|
for _, star := range req.Star {
|
|
cfg := this.configure.GetEquipmentConfigureById(v.T)
|
|
if cfg != nil && star == cfg.Star { // 自动出售 转换成其他道具
|
|
if len(cfg.Sale) != 0 {
|
|
bFound = true
|
|
del = append(del, cfg.Id)
|
|
res = append(res, cfg.Sale...)
|
|
}
|
|
break
|
|
}
|
|
}
|
|
}
|
|
// else if v.A == "item" { //道具出售 以后补充
|
|
// if cfg, err := this.configure.GetItemConfigureData(v.T); err != nil { // 自动出售 转换成其他道具
|
|
// if len(cfg.Sale) != 0 {
|
|
// bFound = true
|
|
// res = append(res, cfg.Sale...)
|
|
// }
|
|
// }
|
|
// }
|
|
if !bFound {
|
|
res = append(res, v)
|
|
}
|
|
}
|
|
res = append(res, vikingCfg.Manexp) //给玩家加经验
|
|
if code, atno = this.module.DispenseAtno(session, res, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
code = this.module.ModifyVikingData(session.GetUserId(), mapData)
|
|
|
|
if session.GetUserId() != "" { // 恢复时间
|
|
if userexpand, err := this.module.ModuleUser.GetUserExpand(session.GetUserId()); err == nil {
|
|
viking.RecoveryTime = userexpand.Recovertimeunifiedticket
|
|
}
|
|
}
|
|
|
|
// 加经验
|
|
if req.Report != nil && req.Report.Info != nil && len(req.Report.Info.Redflist) > 0 {
|
|
for _, v := range req.Report.Info.Redflist[0].Team {
|
|
if vikingCfg.Heroexp > 0 && !v.Ishelp { // 助战英雄不加经验
|
|
this.module.ModuleHero.AddHeroExp(session, v.Oid, vikingCfg.Heroexp)
|
|
}
|
|
if v.Ishelp {
|
|
bHelp = true
|
|
}
|
|
}
|
|
}
|
|
//给玩家加经验
|
|
|
|
session.SendMsg(string(this.module.GetType()), VikingChallengeOverResp, &pb.VikingChallengeOverResp{
|
|
Data: viking,
|
|
Asset: atno,
|
|
Sell: del,
|
|
Heroexp: changExp,
|
|
})
|
|
if user := this.module.ModuleUser.GetUser(session.GetUserId()); user != nil {
|
|
this.chat.SendSysChatToWorld(comm.ChatSystem14, nil, req.BossId, req.Difficulty, user.Name)
|
|
} else {
|
|
this.module.Errorf("no found userdata uid:%s", session.GetUserId())
|
|
}
|
|
// 随机任务统计
|
|
var szTask []*comm.TaskParam
|
|
szTask = append(szTask, comm.GettaskParam(comm.Rtype73, 1, req.BossId, req.Difficulty))
|
|
//szTask = append(szTask, comm.GettaskParam(comm.Rtype74, req.BossId, req.Difficulty))
|
|
szTask = append(szTask, comm.GettaskParam(comm.Rtype78, req.BossId, req.Difficulty, req.Report.Costtime))
|
|
|
|
if req.Report != nil && req.Report.Info != nil && len(req.Report.Info.Redflist) > 0 {
|
|
for _, v := range req.Report.Info.Redflist[0].Team {
|
|
if v.Ishelp { // 判断是否有助战
|
|
szTask = append(szTask, comm.GettaskParam(comm.Rtype79, req.Difficulty, req.BossId))
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
if req.Auto {
|
|
szTask = append(szTask, comm.GettaskParam(comm.Rtype75, req.BossId, req.Difficulty))
|
|
szTask = append(szTask, comm.GettaskParam(comm.Rtype172, 1))
|
|
szTask = append(szTask, comm.GettaskParam(comm.Rtype181, req.BossId, req.Difficulty, 1))
|
|
}
|
|
szTask = append(szTask, comm.GettaskParam(comm.Rtype76, 1, req.BossId))
|
|
if bHelp {
|
|
szTask = append(szTask, comm.GettaskParam(comm.Rtype180, req.BossId, 1))
|
|
}
|
|
go this.module.ModuleRtask.TriggerTask(session.GetUserId(), szTask...)
|
|
return
|
|
}
|