示例#1
0
 public static function buildCombinedStats($games)
 {
     // combined numbers (move out of controller in future)
     $combined = [];
     $gameCount = 0;
     $timeCount = 0;
     $revives = false;
     foreach ($games as $game) {
         // Check for Trials game, and check if any non Panda are playing
         $pandaId = 0;
         if ($game->isToO()) {
             $pandaId = $game->pvp->pandaId;
         }
         foreach ($game->players as $player) {
             if (!$player->completed) {
                 continue;
             }
             if (isset($combined[$player->membershipId])) {
                 $combined[$player->membershipId]['kills'] += $player->kills;
                 $combined[$player->membershipId]['deaths'] += $player->deaths;
                 $combined[$player->membershipId]['assists'] += $player->assists;
                 $combined[$player->membershipId]['level'] += $player->level;
                 $combined[$player->membershipId]['count'] += 1;
                 $combined[$player->membershipId]['revives_given'] += $player->revives_given;
                 $combined[$player->membershipId]['revives_taken'] += $player->revives_taken;
                 if ($player->revives_given != 0) {
                     $revives = true;
                 }
                 // find players max level
                 $combined[$player->membershipId]['maxLevel'] = max($combined[$player->membershipId]['maxLevel'], $player->level);
             } else {
                 $combined[$player->membershipId] = ['kills' => $player->kills, 'deaths' => $player->deaths, 'assists' => $player->assists, 'level' => $player->level, 'count' => 1, 'maxLevel' => 0, 'class' => $player->class, 'charId' => $player->characterId, 'revives_given' => $player->revives_given, 'revives_taken' => $player->revives_taken];
                 if (isset($player->account->gamertag)) {
                     $extra = ['gamertag' => $player->account->gamertag, 'seo' => $player->account->seo, 'isPandaLove' => $player->account->isPandaLove(), 'isPandaGuest' => false];
                     // Check if this player is on PandaTeam, if so mark them as Panda
                     if ($game->isToO()) {
                         if (!$extra['isPandaLove'] && $player->team == $pandaId) {
                             $extra['isPandaLove'] = true;
                             $extra['isPandaGuest'] = true;
                         }
                     }
                     $combined[$player->membershipId] = array_merge($combined[$player->membershipId], ['player' => $extra]);
                 }
             }
         }
         $game->players = $game->players->each(function ($player) {
             $player->kd = $player->kdr();
         })->sortByDesc('kd');
         $gameCount++;
         $timeCount += $game->getRawSeconds();
     }
     foreach ($combined as $key => $user) {
         $combined[$key]['avgLevel'] = round($user['level'] / $user['count'], 1);
         $combined[$key]['kdr'] = Game::kd($user['kills'], $user['deaths']);
         $combined[$key]['kadr'] = Game::kadr($user['kills'], $user['assists'], $user['deaths']);
     }
     $combined = new Collection($combined);
     $combined = $combined->sortByDesc('kdr');
     return ['players' => $combined, 'stats' => ['games' => $gameCount, 'combinedGameTime' => Text::timeDuration($timeCount), 'revives' => $revives]];
 }
示例#2
0
 public function kadr()
 {
     return GameHelper::kadr($this->kills, $this->assists, $this->deaths);
 }
示例#3
0
 public function getPassage($passageId, $gameId = null)
 {
     $games = Game::with('players.gameChar', 'players.account.destiny', 'pvp')->ofPassage($passageId)->get();
     if ($games->isEmpty()) {
         \App::abort(404);
     }
     Hashes::cacheTuesdayHashes($games);
     $combined = GameHelper::buildCombinedStats($games);
     $passageCombined = GameHelper::buildQuickPassageStats($games);
     return view('destiny.games.passage')->with('passageId', intval($passageId))->with('revives', $combined['stats']['revives'])->with('games', $games)->with('combined', $combined)->with('passage', $passageCombined)->with('title', 'PandaLove: Trials Of Osiris #' . $passageId)->with('description', 'PandaLove: Trials Of Osiris #' . $passageId)->with('showAll', true)->with('gameId', GameHelper::gameIdExists($games, $gameId));
 }