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 change bool err error ) if errdata = this.ChallengeCheck(session, req); errdata != nil { return } if red, 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, red) if errdata = this.module.ConsumeRes(session, []*cfg.Gameatn{this.module.ModuleTools.GetGlobalConf().ArenaTicketCos}, true); errdata != nil { 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 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), 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 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } } else { if bule, err = this.module.modelArena.getAI(req.MformatId); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), 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 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } if errdata, 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}, }); errdata != nil { return } session.SendMsg(string(this.module.GetType()), "challenge", &pb.ArenaChallengeResp{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, }}) return }