go_dreamfactory/modules/viking/api_challengeover.go
2023-06-06 10:11:23 +08:00

206 lines
6.5 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) (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) ChallengeOver(session comm.IUserSession, req *pb.VikingChallengeOverReq) (errdata *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 errdata != nil {
return // 参数校验失败直接返回
}
viking, err := this.module.modelViking.getVikingList(session.GetUserId())
if err != nil {
code = pb.ErrorCode_VikingBoosType
return
}
vikingCfg, err := this.module.configure.GetVikingBossConfigData(req.BossId, req.Difficulty)
if err != nil {
code = pb.ErrorCode_ConfigNoFound
data = &pb.ErrorData{
Title: pb.GetErrorCodeMsg(code),
Message: err.Error(),
}
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); errdata != nil {
// return
// }
if !bWin { // 战斗失败了 直接返回
if v, ok := viking.Ps[req.BossId]; ok && v > 0 {
if code = this.module.DispenseRes(session, vikingCfg.PsConsume, true); errdata != nil { // 返还预扣体力
return
}
}
viking.Ps[req.BossId] = 0 // 清空预扣体力值
mapData["ps"] = viking.Ps
code = this.module.ModifyVikingData(session.GetUserId(), mapData)
session.SendMsg(string(this.module.GetType()), VikingChallengeOverResp, &pb.VikingChallengeOverResp{
Data: viking,
})
return
}
// if code = this.module.ConsumeRes(session, vikingCfg.PsConsume, true); errdata != nil {
// 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); errdata != nil {
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); errdata != nil {
return
}
code = this.module.ModifyVikingData(session.GetUserId(), mapData)
// 加经验
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 []*pb.BuriedParam
szTask = append(szTask, comm.GetBuriedParam(comm.Rtype73, 1, req.BossId, req.Difficulty))
//szTask = append(szTask, comm.GetBuriedParam(comm.Rtype74, req.BossId, req.Difficulty))
szTask = append(szTask, comm.GetBuriedParam(comm.Rtype78, req.BossId, req.Report.Costtime/1000, req.Difficulty))
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.GetBuriedParam(comm.Rtype79, req.Difficulty, req.BossId))
break
}
}
}
if req.Auto {
szTask = append(szTask, comm.GetBuriedParam(comm.Rtype75, req.BossId, req.Difficulty))
szTask = append(szTask, comm.GetBuriedParam(comm.Rtype172, 1))
szTask = append(szTask, comm.GetBuriedParam(comm.Rtype181, 1, req.BossId, req.Difficulty))
}
szTask = append(szTask, comm.GetBuriedParam(comm.Rtype76, 1, req.BossId))
if bHelp {
szTask = append(szTask, comm.GetBuriedParam(comm.Rtype180, req.BossId, 1))
}
go this.module.ModuleBuried.TriggerBuried(session.GetUserId(), szTask...)
return
}