95 lines
2.4 KiB
Go
95 lines
2.4 KiB
Go
package arena
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"time"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) PlotCheck(session comm.IUserSession, req *pb.ArenaPlotReq) (errdata *pb.ErrorData) {
|
|
|
|
return
|
|
}
|
|
|
|
// /获取自己的排行榜信息
|
|
func (this *apiComp) Plot(session comm.IUserSession, req *pb.ArenaPlotReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
npc *cfg.GameArenaChallengeNpcData
|
|
info *pb.DBArenaUser
|
|
record *pb.DBBattleRecord
|
|
index int32
|
|
err error
|
|
)
|
|
if errdata = this.PlotCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if npc, err = this.module.configure.getChallengenpc(req.Pid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if info, err = this.module.modelArena.queryPlayerInfo(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
this.module.modelArena.recoverTicket(session, info)
|
|
if errdata = this.module.ConsumeRes(session, []*cfg.Gameatn{this.module.ModuleTools.GetGlobalConf().ArenaTicketCos}, true); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if info.Npc[req.Pid] != nil {
|
|
ndata := info.Npc[req.Pid]
|
|
if !configure.Now().After(time.Unix(ndata.Cd, 0)) { //已经过了cd时间
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ArenaTicketNpcInCd,
|
|
Title: pb.ErrorCode_ArenaTicketNpcInCd.ToString(),
|
|
}
|
|
return
|
|
}
|
|
index = ndata.Index
|
|
}
|
|
if errdata, record = this.module.battle.CreatePveBattle(session, &pb.BattlePVEReq{
|
|
Rulesid: npc.BattleReadyID,
|
|
Ptype: pb.PlayType_arena,
|
|
Format: req.Battle,
|
|
Mformat: []int32{npc.MonsterformatId[index]},
|
|
}); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if err = this.module.modelArena.updateArenaUserInfo(info); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "plot", &pb.ArenaPlotResp{
|
|
Pid: req.Pid,
|
|
Info: &pb.BattleInfo{
|
|
Id: record.Id,
|
|
Title: record.Title,
|
|
Rulesid: npc.BattleReadyID,
|
|
Btype: record.Btype,
|
|
Ptype: record.Ptype,
|
|
RedCompId: record.RedCompId,
|
|
Redflist: record.Redflist,
|
|
BlueCompId: record.BlueCompId,
|
|
Buleflist: record.Buleflist,
|
|
},
|
|
})
|
|
|
|
return
|
|
}
|