go_dreamfactory/modules/pagoda/api_racechallenge.go
2023-08-11 17:22:49 +08:00

148 lines
3.6 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.Cid <= 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.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
}
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.Race[conf.Restriction]; !ok {
if conf.Floors == 1 {
pagoda.Race[conf.Restriction] = &pb.RaceData{
Race: conf.Restriction,
Rtime: configure.Now().Unix(),
Defeat: 0,
Endtime: 0,
Curfloor: 0,
}
//mapData := make(map[string]interface{}, 0)
//mapData["Race"] = list.Race
errdata = this.module.ModifyPagodaData(session.GetUserId(), map[string]interface{}{
"Race": pagoda.Race,
})
} else {
errdata = &pb.ErrorData{ // 挑战关卡数据不匹配
Code: pb.ErrorCode_PagodaLevlErr,
Title: pb.ErrorCode_PagodaLevlErr.ToString(),
}
return
}
} else {
if pagoda.Race[conf.Restriction].Curfloor+1 != conf.Floors {
errdata = &pb.ErrorData{ // 挑战关卡数据不匹配
Code: pb.ErrorCode_PagodaLevlErr,
Title: pb.ErrorCode_PagodaLevlErr.ToString(),
}
return
}
// 阵营塔每天最高挑战10层
if conf.Restriction < 10 {
if pagoda.Race[conf.Restriction].Defeat >= 10 {
errdata = &pb.ErrorData{ // 今日挑战达到上限
Code: pb.ErrorCode_PagodaMaxCount,
Title: pb.ErrorCode_PagodaMaxCount.ToString(),
}
}
}
}
if req.Race >= 10 {
pType = pb.PlayType_cycle
} else {
pType = pb.PlayType_race
}
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,
},
Cid: req.Cid,
})
return
}