Exemplo n.º 1
0
 /**
  * Creates a <var>GameStats</var> object and fetches data from the Steam
  * Community for the given user and game
  *
  * @param string $userId The custom URL or the 64bit Steam ID of the user
  * @param string $appId The app ID or friendly name of the game
  * @throws SteamCondenserException if the stats cannot be fetched
  */
 protected function __construct($userId, $appId)
 {
     $this->schema = GameStatsSchema::create($appId);
     $this->user = SteamId::create($userId, false);
     $this->appId = $appId;
     $this->steamId64 = $this->user->getSteamId64();
     $params = ['appid' => $this->schema->getAppId(), 'steamid' => $this->steamId64];
     $data = WebApi::getJSONObject('ISteamUserStats', 'GetUserStatsForGame', 2, $params);
     $this->achievements = [];
     foreach ($data->playerstats->achievements as $achievement) {
         $apiName = $achievement->name;
         $unlocked = $achievement->achieved == 1;
         $this->achievements[] = $this->schema->getAchievement($apiName)->getInstance($this->user, $unlocked);
     }
     $this->values = [];
     foreach ($data->playerstats->stats as $datum) {
         $this->values[] = $this->schema->getDatum($datum->name)->getInstance($this->user, $datum->value);
     }
 }