154 lines
4.1 KiB
Go
154 lines
4.1 KiB
Go
package pagoda
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) ChallengeRaceOverCheck(session comm.IUserSession, req *pb.PagodaChallengeRaceOverReq) (errdata *pb.ErrorData) {
|
|
if req.Cid <= 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// /挑战主线关卡
|
|
func (this *apiComp) ChallengeRaceOver(session comm.IUserSession, req *pb.PagodaChallengeRaceOverReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
mapData map[string]interface{}
|
|
race *pb.DBPagodaRace
|
|
isWin bool
|
|
err error
|
|
atno []*pb.UserAtno // 通关奖励
|
|
//timeCheckOk bool // 开启条件校验
|
|
)
|
|
mapData = make(map[string]interface{}, 0)
|
|
if errdata = this.ChallengeRaceOverCheck(session, req); errdata != nil {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
|
|
conf, err := this.module.configure.GetPagodaRaceConfById(req.Cid)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_PagodaNotFound,
|
|
Title: pb.ErrorCode_PagodaNotFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
// 判断开启时间
|
|
// curWeekDay := int32(configure.Now().Weekday())
|
|
// if curWeekDay == 0 {
|
|
// curWeekDay = 7
|
|
// }
|
|
// for _, v := range conf.Openingtime {
|
|
// if v == curWeekDay {
|
|
// timeCheckOk = true
|
|
// break
|
|
// }
|
|
// }
|
|
// if !timeCheckOk {
|
|
// errdata = &pb.ErrorData{
|
|
// Code: pb.ErrorCode_PagodaTimeError,
|
|
// Title: pb.ErrorCode_PagodaTimeError.ToString(),
|
|
// }
|
|
// return
|
|
// }
|
|
|
|
race, err = this.module.modelRacePagoda.getPagodaRaceList(session.GetUserId())
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_PagodaNotFound,
|
|
Title: pb.ErrorCode_PagodaNotFound.ToString(),
|
|
}
|
|
return
|
|
}
|
|
if v, ok := race.Race[conf.Restriction]; !ok {
|
|
if conf.Floors == 1 {
|
|
race.Race[conf.Restriction] = &pb.RaceData{
|
|
Race: conf.Restriction,
|
|
Rtime: configure.Now().Unix(),
|
|
Defeat: 0,
|
|
Endtime: 0,
|
|
Curfloor: 1,
|
|
}
|
|
} else {
|
|
errdata = &pb.ErrorData{ // 挑战关卡数据不匹配
|
|
Code: pb.ErrorCode_PagodaLevlErr,
|
|
Title: pb.ErrorCode_PagodaLevlErr.ToString(),
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
if v.Curfloor+1 != conf.Floors {
|
|
errdata = &pb.ErrorData{ // 挑战关卡数据不匹配
|
|
Code: pb.ErrorCode_PagodaLevlErr,
|
|
Title: pb.ErrorCode_PagodaLevlErr.ToString(),
|
|
}
|
|
return
|
|
}
|
|
}
|
|
// 校验条件
|
|
if conf.Unlock != 1 {
|
|
if !this.mline.CheckCommpleteStage(session.GetUserId(), conf.Unlock) {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_PagodaUnlock,
|
|
Title: pb.ErrorCode_PagodaUnlock.ToString(),
|
|
}
|
|
return
|
|
}
|
|
}
|
|
// 校验通过
|
|
errdata, isWin = this.module.battle.CheckBattleReport(session, req.Report)
|
|
if errdata != nil {
|
|
return
|
|
}
|
|
if !isWin { // 战斗失败直接返回
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_BattleNoWin,
|
|
Title: pb.ErrorCode_BattleNoWin.ToString(),
|
|
}
|
|
return
|
|
}
|
|
// 加经验
|
|
if req.Report != nil && req.Report.Info != nil && len(req.Report.Info.Redflist) > 0 {
|
|
for _, v := range req.Report.Info.Redflist[0].Team {
|
|
if conf.Exp > 0 && !v.Ishelp { // 助战英雄不加经验
|
|
this.module.ModuleHero.AddHeroExp(session, v.Oid, conf.Exp)
|
|
}
|
|
}
|
|
}
|
|
|
|
race.Race[conf.Restriction].Curfloor += 1
|
|
race.Race[conf.Restriction].Defeat += 1
|
|
race.Race[conf.Restriction].Task = conf.Fightevents
|
|
mapData["race"] = race.Race
|
|
|
|
if err = this.module.modelRacePagoda.ModifyPagodaRaceDataByObjId(session.GetUserId(), mapData); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
}
|
|
// 通关奖励
|
|
if errdata, atno = this.module.DispenseAtno(session, conf.Reward, true); errdata != nil {
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), PagodaChallengeRaceOverResp, &pb.PagodaChallengeRaceOverResp{
|
|
Race: race.Race[conf.Restriction],
|
|
Reward: atno,
|
|
})
|
|
|
|
// 任务相关
|
|
//go this.module.ModuleBuried.TriggerBuried(session.Clone(), comm.GetBuriedParam(comm.Rtype168, pagoda.Data[conf.Tab], conf.Tab))
|
|
return
|
|
}
|