Example #1
0
 public static function buildQuickPassageStats($games)
 {
     $combined = [];
     $combined['stats'] = ['pandaPts' => 0, 'opponentPts' => 0, 'pandaWins' => 0, 'opponentWins' => 0, 'totalGames' => 0, 'blowoutGames' => 0, 'differentMaps' => false];
     $combined['buffs'] = ['favor' => false, 'mercy' => false, 'boon' => false, 'boon-or-favor' => false, 'quitout' => 0];
     $previous = null;
     $maps = new Collection();
     foreach ($games as $game) {
         $pandaId = $game->pvp->pandaId;
         $opponentId = $game->pvp->opposite($pandaId);
         if ($maps->has($game->referenceId)) {
             $count = $maps->get($game->referenceId);
             $maps->forget($game->referenceId);
             $maps->put($game->referenceId, ++$count);
         } else {
             $maps->put($game->referenceId, 1);
         }
         $combined['stats']['pandaPts'] += $game->pvp->pts($pandaId);
         $combined['stats']['opponentPts'] += $game->pvp->pts($opponentId);
         $combined['stats']['pandaWins'] += $pandaId == $game->pvp->winnerId ? 1 : 0;
         $combined['stats']['opponentWins'] += $opponentId == $game->pvp->winnerId ? 1 : 0;
         $combined['stats']['totalGames'] += 1;
         // Check if PandaLove blew them out (15 - 0)
         // Update: Trials #2 maxes at 5-0
         // Update: Forget max, just check if enemy got 0pts
         if ($pandaId == $game->pvp->winnerId) {
             if ($game->pvp->pts($opponentId) == 0) {
                 $combined['stats']['blowoutGames'] += 1;
             }
         }
         if ($previous == null) {
             $previous = $game->referenceId;
         } else {
             if ($previous != $game->referenceId) {
                 $combined['stats']['differentMaps'] = true;
             }
         }
         foreach ($game->players as $player) {
             $id = $player->account->membershipId;
             if ($player->account->isPandaLove() || $player->team == $pandaId) {
                 // check for unbroken
                 if ($player->deaths == 0) {
                     if (isset($combined['stats']['unbroken'][$id])) {
                         $combined['stats']['unbroken'][$id]['count'] += 1;
                     } else {
                         $combined['stats']['unbroken'][$id] = ['gamertag' => $player->account->gamertag, 'seo' => $player->account->seo, 'count' => 1];
                     }
                 }
             }
         }
     }
     // are we on different maps? If so lets get the names of them
     if ($combined['stats']['differentMaps']) {
         $map_list = '';
         $new_maps = null;
         $maps->each(function ($count, $map) use(&$map_list, &$new_maps) {
             $map_list .= Hashes::quick($map)['title'] . ", ";
         });
         $combined['stats']['maps'] = rtrim($map_list, ", ");
         $new_maps = $maps->toArray();
         arsort($new_maps);
         $combined['stats']['rMaps'] = $new_maps;
     }
     $bonus = 0;
     if ($combined['stats']['pandaWins'] < 7) {
         $combined['buffs']['quitout'] = 7 - $combined['stats']['pandaWins'];
         $bonus += $combined['buffs']['quitout'];
     }
     // Lets check for Boon/Mercy/Favor of Osiris
     if ($combined['stats']['pandaWins'] != $combined['stats']['totalGames']) {
         // Our Panda # of wins does not equal total games, therefore a loss was encountered
         $combined['buffs']['mercy'] = true;
     }
     if ($combined['stats']['pandaWins'] == 8 - $bonus) {
         // We have 8 wins. This means the group could of either used a Boon (First win = two wins)
         // or a Favor (start with 1 win).
         $combined['buffs']['boon-or-favor'] = true;
     }
     if ($combined['stats']['pandaWins'] == 7 - $bonus) {
         // We have 7 wins. That means both the Boon and Favor was used.
         $combined['buffs']['favor'] = true;
         $combined['buffs']['boon'] = true;
     }
     return $combined;
 }