180 lines
5.1 KiB
Go
180 lines
5.1 KiB
Go
package enchant
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"time"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.EnchantChallengeOverReq) (errdata *pb.ErrorData) {
|
|
if req.BossType <= 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
///挑战主线关卡
|
|
func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.EnchantChallengeOverReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
conf *cfg.GameEnchantBossData
|
|
info *pb.DBEnchant
|
|
user *pb.DBUser
|
|
rconf *cfg.GameEnchantbossRewardData
|
|
res []*cfg.Gameatn
|
|
atno []*pb.UserAtno
|
|
award []*cfg.Gameatn
|
|
line []*pb.LineUp // 阵容数据
|
|
changExp map[string]int32
|
|
boos *pb.DBEnchantBoos
|
|
ok bool
|
|
err error
|
|
//bNewRecord bool
|
|
)
|
|
if errdata = this.ChallengeOverCheck(session, req); errdata != nil {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
|
|
info, err = this.module.modelEnchant.getEnchantList(session.GetUserId())
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_PagodaNotFound,
|
|
Title: pb.ErrorCode_PagodaNotFound.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
conf, err = this.module.configure.GetEnchantBossConfigData(req.BossType)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound, // 道具数量不足
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if rconf, err = this.module.configure.getGameRepeatAllData(req.Report.Grade); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound, // 道具数量不足
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if errdata, _ = this.module.battle.CheckBattleReport(session, req.Report); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if errdata = this.module.ConsumeRes(session, conf.PsConsume, true); errdata != nil {
|
|
return
|
|
}
|
|
|
|
user, err = this.module.GetUserForSession(session)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
for _, v := range req.Report.Info.Redflist[0].Team {
|
|
line = append(line, &pb.LineUp{
|
|
Cid: v.HeroID,
|
|
Star: v.Star,
|
|
Lv: v.Lv,
|
|
})
|
|
}
|
|
if boos, ok = info.Boss[req.BossType]; !ok {
|
|
boos = &pb.DBEnchantBoos{
|
|
Score: req.Report.Score,
|
|
Grade: req.Report.Grade,
|
|
Gradegroup: req.Report.Info.Scoregroup,
|
|
Battletime: req.Report.Costtime,
|
|
Line: &pb.LineData{
|
|
Leadpos: req.Report.Info.Redflist[0].Leadpos,
|
|
Line: line,
|
|
},
|
|
}
|
|
info.Boss[req.BossType] = boos
|
|
//bNewRecord = true
|
|
} else {
|
|
if boos.Score < req.Report.Score {
|
|
boos = &pb.DBEnchantBoos{
|
|
Score: req.Report.Score,
|
|
Grade: req.Report.Grade,
|
|
Gradegroup: req.Report.Info.Scoregroup,
|
|
Battletime: req.Report.Costtime,
|
|
Line: &pb.LineData{
|
|
Leadpos: req.Report.Info.Redflist[0].Leadpos,
|
|
Line: line,
|
|
},
|
|
}
|
|
info.Boss[req.BossType] = boos
|
|
//bNewRecord = true
|
|
}
|
|
}
|
|
|
|
for _, v1 := range rconf.Reward1Drop {
|
|
reward := this.module.ModuleTools.GetGroupDataByLottery(v1, user.Vip, user.Lv)
|
|
res = append(res, reward...)
|
|
}
|
|
for _, v1 := range rconf.Reward2Drop {
|
|
reward := this.module.ModuleTools.GetGroupDataByLottery(v1, user.Vip, user.Lv)
|
|
res = append(res, reward...)
|
|
}
|
|
if conf.Heroexp > 0 {
|
|
var heroObjs []string
|
|
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.HeroID != "" {
|
|
if !v.Ishelp { // 助战英雄不加经验
|
|
heroObjs = append(heroObjs, v.Oid)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if changExp, award, errdata = this.module.ModuleHero.AddHerosExp(session, heroObjs, conf.Heroexp); errdata != nil {
|
|
return
|
|
}
|
|
res = append(res, award...)
|
|
}
|
|
|
|
if errdata, atno = this.module.DispenseAtno(session, res, true); errdata != nil {
|
|
return
|
|
}
|
|
if err = this.module.modelEnchant.Change(session.GetUserId(), map[string]interface{}{
|
|
"boss": info.Boss,
|
|
}); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
//if bNewRecord { // 只有新记录才记录战报数据
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
|
|
this.module.battlerecord.WrietBattleRecord(session.GetUserId(), req.Report, time.Now().Add(time.Hour*24*8))
|
|
this.module.modelRank.CheckRank(session.GetUserId(), req.BossType, req.Report)
|
|
})
|
|
//}
|
|
//this.module.modelRank.updateRank(req.Report.Score, session.GetUserId(), req.BossType)
|
|
session.SendMsg(string(this.module.GetType()), EnchantChallengeOverResp, &pb.EnchantChallengeOverResp{Data: info, Heroexp: changExp, Atno: atno})
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), req, comm.GMResDelType, "EnchantChallengeOverReq", conf.PsConsume)
|
|
if len(atno) > 0 {
|
|
this.module.WriteUserLog(session.GetUserId(), req, comm.GMResAddType, "EnchantChallengeOverReq", atno)
|
|
}
|
|
})
|
|
return
|
|
}
|