95 lines
2.7 KiB
Go
95 lines
2.7 KiB
Go
package mainline
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) BoosChallengeOverCheck(session comm.IUserSession, req *pb.MainlineBoosChallengeOverReq) (errdata *pb.ErrorData) {
|
|
if req.Boosid == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// /挑战主线关卡
|
|
func (this *apiComp) BoosChallengeOver(session comm.IUserSession, req *pb.MainlineBoosChallengeOverReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
conf *cfg.GameMainBossData
|
|
info *pb.DBMainline
|
|
aeward []*pb.UserAtno = make([]*pb.UserAtno, 0)
|
|
isWin bool
|
|
err error
|
|
)
|
|
if errdata = this.BoosChallengeOverCheck(session, req); errdata != nil {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
if conf, err = this.module.configure.getGameMainBossData(req.Boosid); err != nil { // 配置文件校验
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_MainlineNotFindChapter,
|
|
Title: pb.ErrorCode_MainlineNotFindChapter.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if info, err = this.module.modelMline.getMainlineData(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
// 校验通过
|
|
errdata, isWin = this.module.battle.CheckBattleReport(session, req.Report)
|
|
if errdata != nil {
|
|
return
|
|
}
|
|
if !isWin { // 战斗失败返还扣除的体力
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_BattleValidationFailed,
|
|
Title: pb.ErrorCode_BattleValidationFailed.ToString(),
|
|
Message: "battle is defeated",
|
|
}
|
|
return
|
|
}
|
|
|
|
if errdata, aeward = this.module.DispenseAtno(session, conf.Reward, true); errdata != nil {
|
|
this.module.Debugf("Mline Boos DispenseRes err:+%v", conf.Reward)
|
|
return
|
|
}
|
|
if info.Chapterboos[conf.MonsterChapter] < conf.MonsterStrength {
|
|
info.Chapterboos[conf.MonsterChapter] = conf.MonsterStrength
|
|
}
|
|
info.Currbooschallengenum++
|
|
|
|
if err = this.module.modelMline.Change(session.GetUserId(), map[string]interface{}{
|
|
"chapterboos": info.Chapterboos,
|
|
"currbooschallengenum": info.Currbooschallengenum,
|
|
}); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "booschallengeover", &pb.MainlineBoosChallengeOverResp{
|
|
Boosid: req.Boosid,
|
|
Reward: aeward,
|
|
})
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), req, comm.GMResAddType, "MainlineBoosChallengeOverReq", aeward)
|
|
})
|
|
return
|
|
}
|