go_dreamfactory/modules/viking/api_challengeover.go
2023-01-09 19:59:03 +08:00

163 lines
5.4 KiB
Go

package viking
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"strconv"
"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{}
reward []*cfg.Gameatn
bWin bool // 战斗是否胜利
atno []*pb.UserAtno // atno 类型
del []string // 自动出售的装备
changExp map[string]int32
)
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
}
// costRes := this.module.configure.GetGlobalConf().VikingExpeditionCos
// if costRes == nil {
// code = pb.ErrorCode_ConfigNoFound
// return
// }
// if code = this.module.CheckRes(session, []*cfg.Gameatn{costRes}); code != pb.ErrorCode_Success {
// return
// }
value, ok := viking.Boss[req.BossId]
if !ok { // 类型校验
viking.Boss[req.BossId] = 1
}
if value < req.Difficulty {
code = pb.ErrorCode_HuntingLvErr
return
}
// 校验是不是达到最大难度
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 { // 新关卡挑战通过 发放首通奖励
viking.Boss[req.BossId]++
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
mapData["bossTime"] = viking.BossTime // 更新时间
userinfo := this.module.ModuleUser.GetUser(session.GetUserId())
this.module.CheckRank(session.GetUserId(), req.BossId, req.Difficulty, req.Report, userinfo)
}
reward = this.module.configure.GetDropReward(vikingCfg.Drop) // 获取掉落奖励
if code, atno = this.module.DispenseAtno(session, reward, true); code != pb.ErrorCode_Success {
return
}
for _, v := range req.Star {
for _, v1 := range atno {
if v1.A == "equp" {
cfg := this.configure.GetEquipmentConfigureById(v1.T)
if cfg != nil && cfg.Star == v {
del = append(del, v1.O)
}
}
}
}
if len(del) > 0 { // 自动出售
this.equip.SellEquipments(session, del)
}
// 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 { // 助战英雄不加经验
// addExp, _ := this.module.ModuleHero.AddHeroExp(session, v.Oid, 500) //临时加500 后面等配置
// changExp[v.Oid] = addExp
// }
// }
// }
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
}
}
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())
}
// 随机任务统计
this.module.ModuleRtask.SendToRtask(session, comm.Rtype73, req.Difficulty, req.BossId, 1)
this.module.ModuleRtask.SendToRtask(session, comm.Rtype74, req.Difficulty, req.BossId)
this.module.ModuleRtask.SendToRtask(session, comm.Rtype78, req.Difficulty, req.BossId, 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 { // 判断是否有助战
this.module.ModuleRtask.SendToRtask(session, comm.Rtype79, req.Difficulty, req.BossId)
break
}
}
}
return
}