# World Fetcher Fetches and filters OSRS world information for world selection. Credits: Developed by TazE Acknowledgements: Thanks to BigAussie for initial world scraper prototype ## Getting Started Basic example for finding a suitable world: ```pascal var BestWorld: TWorldInfo; begin // Setup WorldFetcher with default settings WorldFetcher.Setup(); // Fetch all available worlds if WorldFetcher.FetchAll() then begin // Find the best world (excludes dangerous/restricted by default) BestWorld := WorldFetcher.FindBestWorld(); WriteLn('Best world: ', BestWorld.WorldNumber, ' with ', BestWorld.PlayerCount, ' players'); end; end; ``` Example for checking skill requirements: ```pascal var WorldInfo: TWorldInfo; begin // Check a specific world WorldInfo := WorldFetcher.GetWorldInfo(420, False); if WorldInfo.MinSkillTotal > 0 then WriteLn('World ', WorldInfo.WorldNumber, ' requires ', WorldInfo.MinSkillTotal, ' total level') else if WorldInfo.Activity = WA_DANGEROUS then WriteLn('World ', WorldInfo.WorldNumber, ' is a PvP world - avoid!') else WriteLn('World ', WorldInfo.WorldNumber, ' is suitable'); end; ``` - - - ## type EWorldType ```pascal EWorldType = enum(FREE_TO_PLAY, MEMBERS); ``` An enumeration representing the membership type of a world. - - - ## type EWorldActivity ```pascal EWorldActivity = enum(NORMAL, DANGEROUS, RESTRICTED, SKILL_TOTAL); ``` An enumeration representing world activity categories. - - - ## type EWorldLocation ```pascal EWorldLocation = enum(GERMANY, UNITED_KINGDOM, UNITED_STATES, AUSTRALIA); ``` An enumeration representing the geographical location of world servers. - - - ## type EWorldSort ```pascal EWorldSort = enum(WORLD_NUMBER, PLAYER_COUNT_ASC, PLAYER_COUNT_DESC, PING_ASC, PING_DESC); ``` An enumeration for sorting world lists. - - - ## type TWorldInfo Contains comprehensive information about a single game world. - `WorldNumber`: The unique world number (e.g., 301, 302). - `Location`: The geographical location of the world server. - `PlayerCount`: Current number of players online (-1 if unavailable). - `WorldType`: Whether the world is free-to-play or members-only. - `Activity`: Activity category (Normal, Dangerous, Restricted, Skill Total). - `ActivityString`: Original activity description from the world list. - `MinSkillTotal`: Minimum skill total required (0, 500, 750, 1250, 1500, 1750, 2000, 2200). - `Ping`: Round-trip time in milliseconds (-1 if not measured). - `LastCheck`: Timestamp when this information was last updated. - - - ## type TSettings Configurable settings for filtering and scoring worlds in FindBestWorld. - `MaxPing`: Maximum acceptable ping in milliseconds. - `MaxPlayers`: Maximum acceptable player count. - `MinPlayers`: Minimum acceptable player count. - `ExcludeActivities`: Array of activities to exclude from results. - `ExcludeWorlds`: Array of specific world numbers to exclude. - `ExcludeLocations`: Array of locations to exclude. - `ExcludeTypes`: Array of world types to exclude. - `IncludeActivities`: If set, ONLY worlds with these activities are considered. - `IncludeLocations`: If set, ONLY worlds in these locations are considered. - `PingWeight`: Weight factor for ping in scoring (0.0-1.0). - `PlayerWeight`: Weight factor for player count in scoring (0.0-1.0). - `PingNormalize`: Normalization factor for ping values. - `PlayerNormalize`: Normalization factor for player count values. - - - ## type TWorldFetcher The main record for fetching and managing world information. - `Worlds`: Cached array of world information. - `LastFetched`: Timestamp of the last successful fetch operation. - `Settings`: Default search settings for this instance. - - - ## TWorldFetcher.Setup ```pascal procedure TWorldFetcher.Setup(); ``` Setup WorldFetcher with default search settings. Override this method to customize settings. - - - ## TWorldFetcher.PingWorld ```pascal function TWorldFetcher.PingWorld(WorldNum: Int32): Int32; ``` Measures the round-trip time (ping) to a specific world server. Example: ```pascal Ping := WorldFetcher.PingWorld(301); WriteLn('World 301 ping: ', Ping, 'ms'); ``` - - - ## TWorldFetcher.GetWorldInfo ```pascal function TWorldFetcher.GetWorldInfo(WorldNum: Int32; IncludePing: Boolean = False): TWorldInfo; ``` Fetches information for a specific world from the official server list. ### Parameters - `WorldNum`: The world number to fetch. - `IncludePing`: Whether to measure ping (default: False). ### Returns - TWorldInfo record with the world's data. Example: ```pascal WorldInfo := WorldFetcher.GetWorldInfo(301, True); WriteLn('World 301: ', WorldInfo.PlayerCount, ' players, ', WorldInfo.Ping, 'ms ping'); ``` - - - ## TWorldFetcher.Fetch ```pascal function TWorldFetcher.Fetch(WorldNumbers: TIntegerArray): Boolean; ``` Fetches information for multiple specific worlds in a single HTTP request. Results are stored in the Worlds array. Example: ```pascal if WorldFetcher.Fetch([301, 302, 303]) then WriteLn('Fetched ', Length(WorldFetcher.Worlds), ' specific worlds'); ``` - - - ## TWorldFetcher.FetchAll ```pascal function TWorldFetcher.FetchAll(): Boolean; ``` Fetches information for all available worlds from the official server list. Results are stored in the Worlds array. ### Returns - True if the fetch was successful, False otherwise. Example: ```pascal if WorldFetcher.FetchAll() then WriteLn('Fetched ', Length(WorldFetcher.Worlds), ' worlds'); ``` - - - ## TWorldFetcher.GetAvailableWorlds ```pascal function TWorldFetcher.GetAvailableWorlds(): TIntegerArray; ``` Fetches and returns all currently available world numbers from the official server list. This method performs a fresh HTTP request each time it's called. Example: ```pascal WorldNumbers := WorldFetcher.GetAvailableWorlds(); WriteLn('Found ', Length(WorldNumbers), ' available worlds'); ``` - - - ## TWorldFetcher.GetWorld ```pascal function TWorldFetcher.GetWorld(WorldNum: Int32): TWorldInfo; ``` Retrieves cached information for a specific world. Example: ```pascal CachedWorld := WorldFetcher.GetWorld(301); if CachedWorld.WorldNumber > 0 then WriteLn('World 301 has ', CachedWorld.PlayerCount, ' players'); ``` - - - ## TWorldFetcher.FilterByType ```pascal function TWorldFetcher.FilterByType(WorldType: EWorldType): array of TWorldInfo; ``` Filters the cached worlds by membership type. Example: ```pascal F2PWorlds := WorldFetcher.FilterByType(EWorldType.FREE_TO_PLAY); ``` - - - ## TWorldFetcher.FilterByLocation ```pascal function TWorldFetcher.FilterByLocation(Location: EWorldLocation): array of TWorldInfo; ``` Filters the cached worlds by server location. Example: ```pascal GermanWorlds := WorldFetcher.FilterByLocation(EWorldLocation.WL_GERMANY); ``` - - - ## TWorldFetcher.FilterWorldsByPing ```pascal function TWorldFetcher.FilterWorldsByPing(MinPing, MaxPing: Int32): array of TWorldInfo; ``` Filters the cached worlds by ping range. Only includes worlds with valid ping measurements. Example: ```pascal LowPingWorlds := WorldFetcher.FilterWorldsByPing(0, 50); WriteLn('Found ', Length(LowPingWorlds), ' worlds with ping < 50ms'); ``` - - - ## TWorldFetcher.FilterByPlayerCount ```pascal function TWorldFetcher.FilterByPlayerCount(MinPlayers, MaxPlayers: Int32): array of TWorldInfo; ``` Filters the cached worlds by player count range. Example: ```pascal MediumWorlds := WorldFetcher.FilterByPlayerCount(200, 800); ``` - - - ## TWorldFetcher.FilterByActivity ```pascal function TWorldFetcher.FilterByActivity(Activity: EWorldActivity): array of TWorldInfo; ``` Filters the cached worlds by activity type. Example: ```pascal SkillWorlds := WorldFetcher.FilterByActivity(EWorldActivity.SKILL_TOTAL); ``` - - - ## TWorldFetcher.FilterBySettings ```pascal function TWorldFetcher.FilterBySettings(Settings: TSettings): array of TWorldInfo; ``` Applies all filter criteria from the provided settings to return matching worlds. Example: ```pascal Settings.IncludeLocations := [WL_GERMANY, WL_UNITED_KINGDOM]; Settings.ExcludeActivities := [WA_DANGEROUS, WA_RESTRICTED]; Worlds := WorldFetcher.FilterBySettings(Settings); ``` - - - ## TWorldFetcher.GetFilteredWorlds ```pascal function TWorldFetcher.GetFilteredWorlds(): array of TWorldInfo; ``` Helper method that applies the instance's Settings to filter cached worlds. Example: ```pascal WorldFetcher.Settings.IncludeLocations := [WL_UNITED_STATES]; Worlds := WorldFetcher.GetFilteredWorlds(); ``` - - - ## TWorldFetcher.FindBestWorld ```pascal function TWorldFetcher.FindBestWorld(): TWorldInfo; ``` Finds the best world based on the search settings configured in Setup. Example: ```pascal BestWorld := WorldFetcher.FindBestWorld(); if BestWorld.WorldNumber > 0 then WriteLn('Best world: ', BestWorld.WorldNumber); ``` - - - ## TWorldFetcher.FindLowestPingWorld ```pascal function TWorldFetcher.FindLowestPingWorld(): TWorldInfo; ``` Finds the world with the lowest ping from the cached data. Note: Only considers worlds with valid ping measurements (> 0). Example: ```pascal LowestPing := WorldFetcher.FindLowestPingWorld(); if LowestPing.WorldNumber > 0 then WriteLn('Best ping: World ', LowestPing.WorldNumber, ' (', LowestPing.Ping, 'ms)'); ``` - - - ## TWorldFetcher.FindLowestPlayerWorld ```pascal function TWorldFetcher.FindLowestPlayerWorld(): TWorldInfo; ``` Finds the world with the lowest player count from the cached data. Example: ```pascal EmptyWorld := WorldFetcher.FindLowestPlayerWorld(); WriteLn('Least crowded: World ', EmptyWorld.WorldNumber, ' (', EmptyWorld.PlayerCount, ' players)'); ``` - - - ## TWorldFetcher.SortWorlds ```pascal function TWorldFetcher.SortWorlds(Worlds: array of TWorldInfo; worldSort: EWordSort): array of TWorldInfo; ``` Sorts an array of worlds according to the specified criteria. Example: ```pascal SortedWorlds := WorldFetcher.SortWorlds(FilteredWorlds, SORT_PLAYER_COUNT_ASC); ``` - - - ## var WorldFetcher ```pascal var WorldFetcher: TWorldFetcher; ``` Global instance of TWorldFetcher for convenient access to world fetching functionality.