118 lines
2.8 KiB
Go
118 lines
2.8 KiB
Go
package pagoda
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) ChallengeRaceCheck(session comm.IUserSession, req *pb.PagodaChallengeRaceReq) (errdata *pb.ErrorData) {
|
|
if req.Floor <= 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// /六合塔开始挑战
|
|
func (this *apiComp) ChallengeRace(session comm.IUserSession, req *pb.PagodaChallengeRaceReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
pagoda *pb.DBPagodaRace
|
|
err error
|
|
timeCheckOk bool
|
|
pType pb.PlayType
|
|
)
|
|
if errdata = this.ChallengeRaceCheck(session, req); errdata != nil {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
|
|
conf, err := this.module.configure.GetSixPagodaConf(req.Floor)
|
|
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
|
|
}
|
|
|
|
if len(conf.Openingtime) == 0 {
|
|
timeCheckOk = true
|
|
} else {
|
|
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
|
|
}
|
|
pagoda, err = this.module.modelRacePagoda.getPagodaRaceList(session.GetUserId())
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_PagodaNotFound,
|
|
Title: pb.ErrorCode_PagodaNotFound.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if _, ok := pagoda.Data[conf.Floors]; !ok {
|
|
if pagoda.Maxfloor+1 != conf.Floors {
|
|
errdata = &pb.ErrorData{ // 挑战关卡数据不匹配
|
|
Code: pb.ErrorCode_PagodaLevlErr,
|
|
Title: pb.ErrorCode_PagodaLevlErr.ToString(),
|
|
}
|
|
return
|
|
}
|
|
}
|
|
if pagoda.Battlecount > 9999 { // 暂时不做限制
|
|
errdata = &pb.ErrorData{ // 今日挑战达到上限
|
|
Code: pb.ErrorCode_PagodaMaxCount,
|
|
Title: pb.ErrorCode_PagodaMaxCount.ToString(),
|
|
}
|
|
return
|
|
}
|
|
errdata, record := this.module.battle.CreatePveBattle(session, &pb.BattlePVEReq{
|
|
Rulesid: conf.BattlereadyID,
|
|
Ptype: pType,
|
|
Title: "",
|
|
Format: req.Battle,
|
|
Mformat: conf.Monsterlineup,
|
|
})
|
|
if errdata != nil {
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), PagodaChallengeRaceResp, &pb.PagodaChallengeRaceResp{
|
|
Info: &pb.BattleInfo{
|
|
Id: record.Id,
|
|
Title: record.Title,
|
|
Rulesid: conf.BattlereadyID,
|
|
Btype: record.Btype,
|
|
Ptype: record.Ptype,
|
|
RedCompId: record.RedCompId,
|
|
Redflist: record.Redflist,
|
|
BlueCompId: record.BlueCompId,
|
|
Buleflist: record.Buleflist,
|
|
Tasks: record.Tasks,
|
|
},
|
|
Floor: req.Floor,
|
|
})
|
|
return
|
|
}
|