public function index($gamertag = '', $characterId = '') { try { $account = Account::with('destiny.characters')->where('seo', Text::seoGamertag($gamertag))->firstOrFail(); $games = GamePlayer::with('game')->select('game_players.*', 'games.occurredAt')->leftJoin('games', 'game_players.game_id', '=', 'games.instanceId')->where('membershipId', $account->destiny->membershipId)->where('deaths', 0)->where('games.instanceId', '!=', 0)->orderBy('games.occurredAt', 'DESC')->get(); $games->each(function ($game_player) { $game_player->url = $game_player->game->buildUrl(); }); // setup hash cache Hashes::cacheAccountHashes($account, $games); return view('destiny.profile', ['account' => $account, 'games' => $games, 'characterId' => $account->destiny->characterExists($characterId) ? $characterId : false, 'description' => ($account->isPandaLove() ? "PandaLove: " : null) . $account->gamertag . " Destiny Profile", 'title' => $account->gamertag . ($account->isPandaLove() ? " (Panda Love Member)" : null)]); } catch (ModelNotFoundException $e) { \App::abort(404, 'Da Gone!!! We have no idea what you are looking for.'); } }
/** * Run the migrations. * * @return void */ public function up() { Schema::table('game_players', function (Blueprint $table) { $table->integer('account_id', false, true); }); // Loop all game_players, find the account_id via membershipId on DestinyData \Onyx\Destiny\Objects\GamePlayer::chunk(100, function ($players) { foreach ($players as $player) { $data = \Onyx\Destiny\Objects\Data::where('membershipId', $player->membershipId)->first(); if ($data instanceof \Onyx\Destiny\Objects\Data) { $player->account_id = $data->account_id; $player->save(); } } }); }
/** * @param $entry * @param $game * @param $pvp * @param $regular */ private function gamePlayerSetup($data, $entry, &$game, $pvp, $regular = true) { $player = new GamePlayer(); $player->game_id = $game->instanceId; $player->membershipId = $entry['player']['destinyUserInfo']['membershipId']; $player->account_id = Account::getAccountIdViaDestiny($player->membershipId); // check if we have player if ($this->checkCacheForGamertag($entry['player']['destinyUserInfo']['displayName']) == false && $regular) { Bus::dispatch(new UpdateGamertag($entry['player']['destinyUserInfo']['displayName'], $entry['player']['destinyUserInfo']['membershipType'])); if ($player->account_id == null) { // we are re-running this, because an Account doesnt exist yet so the previous check is NULL // this is technically a bug-fix for a RACE condition, where we cant create a Player // without an AccountId which doesn't exist till after the Event is dispatched. $player->account_id = Account::getAccountIdViaDestiny($player->membershipId); } } $player->characterId = $entry['characterId']; $player->level = $entry['player']['characterLevel']; $player->class = $entry['player']['characterClass']; $player->emblem = $entry['player']['destinyUserInfo']['iconPath']; $player->assists = $entry['values']['assists']['basic']['value']; $player->deaths = $entry['values']['deaths']['basic']['value']; $player->kills = $entry['values']['kills']['basic']['value']; $player->completed = boolval($entry['values']['completed']['basic']['value']); // PVP games don't seem to have secondsPlayed or averageLifespan if (isset($entry['values']['secondsPlayed']['basic']['value'])) { $player->secondsPlayed = $entry['values']['secondsPlayed']['basic']['value']; } if (isset($entry['extended']['values']['averageLifespan']['basic']['value'])) { $player->averageLifespan = $entry['extended']['values']['averageLifespan']['basic']['value']; } if (isset($entry['values']['score']['basic']['value'])) { $player->score = $entry['values']['score']['basic']['value']; } if (isset($entry['values']['standing']['basic']['values'])) { $player->standing = $entry['values']['standing']['basic']['value']; } // Check for team or rumble if (isset($entry['values']['team']['basic']['value'])) { $player->team = $entry['values']['team']['basic']['value']; } // Check for revives given/received if (isset($entry['extended']['values']['resurrectionsPerformed']['basic']['value'])) { $player->revives_given = $entry['extended']['values']['resurrectionsPerformed']['basic']['value']; } if (isset($entry['extended']['values']['resurrectionsReceived']['basic']['value'])) { $player->revives_taken = $entry['extended']['values']['resurrectionsReceived']['basic']['value']; } if (isset($entry['extended']['values']['medalsActivityCompleteVictoryMercy']['basic']['value'])) { $game->mercy = true; $game->save(); } // Don't save if 0/0 if ($player->score == 0 && $player->deaths == 0 && $player->kills == 0) { return; } else { $player->save(); $duration = $entry['values']['activityDurationSeconds']['basic']['value']; if (isset($data['Response']['data']['activityDetails']['mode']) && Gametype::isPVP($data['Response']['data']['activityDetails']['mode'])) { // We need to figure out which "team" is PandaLove via checking the players if ($player->account->isPandaLove()) { if ($entry['standing'] == 0) { $pvp->pandaId = $pvp->winnerId; } else { $pvp->pandaId = $pvp->loserId; } $pvp->save(); } } } return isset($duration) ? $duration : null; }