146 lines
4.0 KiB
Go
146 lines
4.0 KiB
Go
package arena
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) ChallengeCheck(session comm.IUserSession, req *pb.ArenaChallengeReq) (errdata *pb.ErrorData) {
|
|
if (!req.Isai && req.Playerid == "") || (req.Isai && req.MformatId == 0) || req.Battle.Format == nil || len(req.Battle.Format) != 5 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
///挑战
|
|
func (this *apiComp) Challenge(session comm.IUserSession, req *pb.ArenaChallengeReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
red *pb.DBArenaUser
|
|
bule *pb.ArenaPlayer
|
|
heros []*pb.DBHero
|
|
record *pb.DBBattleRecord
|
|
cd pb.ErrorCode
|
|
change bool
|
|
err error
|
|
)
|
|
defer func() {
|
|
if cd == pb.ErrorCode_Success {
|
|
session.SendMsg(string(this.module.GetType()), "challenge", &pb.ArenaChallengeResp{Code: cd, Info: &pb.BattleInfo{
|
|
Id: record.Id,
|
|
Title: record.Title,
|
|
Rulesid: 105,
|
|
Btype: record.Btype,
|
|
Ptype: record.Ptype,
|
|
RedCompId: record.RedCompId,
|
|
Redflist: record.Redflist,
|
|
BlueCompId: record.BlueCompId,
|
|
Buleflist: record.Buleflist,
|
|
Tasks: record.Tasks,
|
|
}})
|
|
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype130, 1)
|
|
go this.module.ModuleBuried.TriggerBuried(session.GetUserId(), comm.GetBuriedParam(comm.Rtype130, 1))
|
|
} else {
|
|
session.SendMsg(string(this.module.GetType()), "challenge", &pb.ArenaChallengeResp{Code: cd, Info: nil})
|
|
}
|
|
}()
|
|
if cd = this.ChallengeCheck(session, req); cd != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
if red, err = this.module.modelArena.queryPlayerInfo(session.GetUserId()); err != nil {
|
|
cd = pb.ErrorCode_DBError
|
|
data = &pb.ErrorData{
|
|
Title: pb.GetErrorCodeMsg(code),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
this.module.modelArena.recoverTicket(session, red)
|
|
if cd = this.module.ConsumeRes(session, []*cfg.Gameatn{this.module.ModuleTools.GetGlobalConf().ArenaTicketCos}, true); cd != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
if red.Attack != nil {
|
|
for i, v := range req.Battle.Format {
|
|
if red.Attack.Formt[i].Id != v {
|
|
change = true
|
|
}
|
|
}
|
|
} else {
|
|
change = true
|
|
}
|
|
|
|
if red.Defend == nil || change {
|
|
if heros, err = this.module.modelArena.queryUserHeros(session.GetUserId(), req.Battle.Format); err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
data = &pb.ErrorData{
|
|
Title: pb.GetErrorCodeMsg(code),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if red.Defend == nil {
|
|
red.Defend = &pb.DBPlayerBattleFormt{
|
|
Leadpos: req.Battle.Leadpos,
|
|
Formt: heros,
|
|
}
|
|
red.Isdef = true
|
|
}
|
|
if change {
|
|
red.Attack = &pb.DBPlayerBattleFormt{
|
|
Leadpos: req.Battle.Leadpos,
|
|
Formt: heros,
|
|
}
|
|
}
|
|
}
|
|
|
|
if !req.Isai {
|
|
if bule, err = this.module.modelArena.queryArenaPlayer(req.Playerid); err != nil {
|
|
cd = pb.ErrorCode_DBError
|
|
data = &pb.ErrorData{
|
|
Title: pb.GetErrorCodeMsg(code),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
if bule, err = this.module.modelArena.getAI(req.MformatId); err != nil {
|
|
cd = pb.ErrorCode_DBError
|
|
data = &pb.ErrorData{
|
|
Title: pb.GetErrorCodeMsg(code),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
}
|
|
redplay := &pb.ArenaPlayer{
|
|
Uid: red.Uid,
|
|
Integral: red.Integral,
|
|
Dan: red.Dan,
|
|
}
|
|
this.module.modelArena.integralCompute(redplay, &pb.ArenaPlayer{
|
|
Uid: bule.Uid,
|
|
Integral: bule.Integral,
|
|
Dan: bule.Dan,
|
|
}, false)
|
|
red.Integral = redplay.Integral
|
|
red.Prededuction = -1 * redplay.Changeintegral
|
|
if err = this.module.modelArena.updateArenaUserInfo(red); err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
data = &pb.ErrorData{
|
|
Title: pb.GetErrorCodeMsg(code),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
cd, record = this.module.battle.CreatePvpBattle(session, &pb.BattlePVPReq{
|
|
Ptype: pb.PlayType_arena,
|
|
Redformat: &pb.PVPFormation{Uid: red.Uid, Leadpos: red.Attack.Leadpos, Format: red.Attack.Formt},
|
|
Buleformat: &pb.PVPFormation{Uid: bule.Uid, Leadpos: bule.Defend.Leadpos, Format: bule.Defend.Formt},
|
|
})
|
|
return
|
|
}
|