/**
  * Loads the global unlock percentages of all achievements for the given
  * game
  *
  * @param int $appId The unique Steam Application ID of the game (e.g.
  *        <var>440</var> for Team Fortress 2). See
  *        http://developer.valvesoftware.com/wiki/Steam_Application_IDs for
  *        all application IDs
  * @return array The symbolic achievement names with the corresponding
  *         global unlock percentages
  * @throws \SteamCondenser\Exceptions\WebApiException if a request to
  *         Steam's Web API fails
  */
 public static function getGlobalPercentages($appId)
 {
     $params = ['gameid' => $appId];
     $data = WebApi::getJSONObject('ISteamUserStats', 'GetGlobalAchievementPercentagesForApp', 2, $params);
     $percentages = [];
     foreach ($data->achievementpercentages->achievements as $achievementData) {
         $percentages[$achievementData->name] = (double) $achievementData->percent;
     }
     return $percentages;
 }
 /**
  * Returns all Golden Wrenches
  *
  * @return array All Golden Wrenches
  * @throws \SteamCondenser\Exceptions\SteamCondenserException If an error
  *         occurs querying the Web API or the Steam Community
  */
 public static function getGoldenWrenches()
 {
     if (self::$goldenWrenches == null) {
         self::$goldenWrenches = [];
         $data = WebApi::getJSONObject('ITFItems_440', 'GetGoldenWrenches', 2);
         foreach ($data->results->wrenches as $wrenchData) {
             self::$goldenWrenches[] = new TF2GoldenWrench($wrenchData);
         }
     }
     return self::$goldenWrenches;
 }
 /**
  * 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);
     }
 }
 /**
  * Returns the overall number of players currently playing this game
  *
  * @return int The number of players playing this game
  */
 public function getPlayerCount()
 {
     $params = ['appid' => $this->appId];
     $result = WebApi::getJSONObject('ISteamUserStats', 'GetNumberOfCurrentPlayers', 1, $params);
     return $result->response->player_count;
 }
 /**
  * Fetches the groups this user is member of
  *
  * Uses the ISteamUser/GetUserGroupList interface.
  *
  * @return SteamGroup[] The groups of this user
  * @see getGroups()
  */
 public function fetchGroups()
 {
     $params = ['steamid' => $this->getSteamId64()];
     $result = WebApi::getJSONObject('ISteamUser', 'GetUserGroupList', 1, $params);
     $this->groups = [];
     foreach ($result->response->groups as $groupData) {
         $this->groups[] = SteamGroup::create($groupData->gid, false);
     }
     return $this->groups;
 }