source = $stream->readByte(); $this->namespace = $stream->readUInt32(); $count = $stream->readUInt32(); for($i = 0; $i<$count; $i++) { $namespace = $stream->readUInt32(); $attrid = $stream->readUInt32(); $scope = $stream->readByte(); $value = trim(strrev($stream->readBytes(4))); if(!isset($this->attributes[$scope])) { $this->attributes[$scope] = array(); } $this->attributes[$scope][$attrid] = new Attribute( $attrid, $namespace, $scope, $value ); } } // ----------------------------------------------------------------------------------------------------------------- /** * Get the player attribute for the given player ID * * @param $playerID integer the player ID * @param $attributeID integer the attribute ID * * @return Attribute|null */ public function getPlayerAttribute($playerID, $attributeID) { if(!isset($this->attributes[$playerID])) { return NULL; } $playerScope = $this->attributes[$playerID]; if(!isset($playerScope[$attributeID])) { return NULL; } return $playerScope[$attributeID]; } /** * Get a list of all player attributes for the given player ID * * @param $playerID integer the player ID * * @return Attribute[] */ public function getPlayerAttributes($playerID) { if(!isset($this->attributes[$playerID])) { return array(); } return $this->attributes[$playerID]; } /** * Get the game attribute given by the attribute ID * * @param $attributeID integer the attribute ID * * @return null|Attribute */ public function getGameAttribute($attributeID) { return $this->getPlayerAttribute(self::GAME_ATTRIBUTES_PLAYER_ID, $attributeID); } /** * Get a list of all game attributes * * @return Attribute[] */ public function getGameAttributes() { return $this->getPlayerAttributes(self::GAME_ATTRIBUTES_PLAYER_ID); } // ----------------------------------------------------------------------------------------------------------------- /** * @return int */ public function getSource() { return $this->source; } /** * @return int */ public function getNamespace() { return $this->namespace; } /** * @return Attribute[] */ public function getAttributes() { return $this->attributes; } }