go_dreamfactory/modules/viking/api_challengeover.go

203 lines
6.7 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
oldDifficulty int32 // 记录通关之前的难度
consumPs int32
userExp int32
)
changExp = make(map[string]int32, 0)
mapData = make(map[string]interface{}, 0)
reward = make([]*cfg.Gameatn, 0)
if errdata = this.ChallengeOverCheck(session, req); errdata != nil {
return // 参数校验失败直接返回
}
viking, err := this.module.modelViking.getVikingList(session.GetUserId())
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_VikingBoosType,
Title: pb.ErrorCode_VikingBoosType.ToString(),
}
return
}
vikingCfg, err := this.module.configure.GetVikingBossConfigData(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 == 1 && viking.Boss[req.BossId] == 0 {
viking.Boss[req.BossId] = 1
mapData["boss"] = viking.Boss
}
if viking.Boss[req.BossId] < req.Difficulty-1 {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_VikingLvErr,
Title: pb.ErrorCode_VikingLvErr.ToString(),
}
return
}
oldDifficulty = viking.Boss[req.BossId]
if viking.Boss[req.BossId] < req.Difficulty {
viking.Boss[req.BossId] = req.Difficulty
mapData["boss"] = viking.Boss
}
errdata, bWin = this.module.battle.CheckBattleReport(session, req.Report)
consumPs = viking.Ps[req.BossId]
viking.Ps[req.BossId] = 0 // 清空预扣体力值
mapData["ps"] = viking.Ps
if !bWin { // 战斗失败了 直接返回
if errdata = this.module.DispenseRes(session, vikingCfg.PsConsume, true); errdata != nil { // 返还预扣体力
return
}
viking.Boss[req.BossId] = oldDifficulty
mapData["boss"] = viking.Boss
errdata = this.module.ModifyVikingData(session.GetUserId(), mapData)
session.SendMsg(string(this.module.GetType()), VikingChallengeOverResp, &pb.VikingChallengeOverResp{
Data: viking,
})
return
}
key := strconv.Itoa(int(req.BossId)) + "_" + strconv.Itoa(int(req.Difficulty))
if viking.BossTime[key] == 0 { // 新关卡挑战通过 发放首通奖励
//viking.BossTime[key] = req.Report.Costtime
//mapData["bossTime"] = viking.BossTime // 更新时间
if errdata = this.module.DispenseRes(session, vikingCfg.Firstprize, true); errdata != nil {
return
}
}
if viking.BossTime[key] == 0 || viking.BossTime[key] > req.Report.Costtime {
viking.BossTime[key] = req.Report.Costtime
mapData["bossTime"] = viking.BossTime // 更新时间
this.module.CheckRank(session.GetUserId(), req.BossId, req.Difficulty, req.Report)
}
user := this.module.ModuleUser.GetUser(session.GetUserId())
reward = this.module.ModuleTools.GetGroupDataByLottery(vikingCfg.Drop, user.Vip, user.Lv)
//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.Color { // 自动出售 转换成其他道具
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)
}
}
if errdata, atno = this.module.DispenseAtno(session, res, true); errdata != nil {
return
}
errdata = 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)
changExp[v.Oid] = vikingCfg.Heroexp
}
if v.Ishelp {
bHelp = true
}
}
}
userExp, _ = this.module.ModuleUser.ConsumePsAddExp(session, consumPs)
session.SendMsg(string(this.module.GetType()), VikingChallengeOverResp, &pb.VikingChallengeOverResp{
Data: viking,
Asset: atno,
Sell: del,
Heroexp: changExp,
UserExp: userExp,
})
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.Rtype201, consumPs))
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
}