Flaming Idiots
Active Member
Recently, Jagex released a new hiscores page made for parsing. This is a code I made to parse it, but make it easily re-usable for hiscores, skill calculators and other things.
Usage:
Example with a Console application:
Code:
Usage:
Code:
'' Lookup a player
Dim Player As New PlayerStats("Player Name")
'' Get a specific skill information
Dim Attack As Skill = Player(Skills.Attack)
'' Get experience to Lvl 99 attack.
Dim Exp As Integer = Attack.ExperienceToLevel(99)
Code:
Module Module1
Sub Main()
Console.Write("Player Name: ")
Dim Player As New PlayerStats(Console.ReadLine)
Console.WriteLine(Player.PlayerName & "'s Combat : ~" & Player.CombatLevel)
If Player(Skills.Attack).OnHiscores Then
Console.WriteLine("Attack Level :{0}", Player(Skills.Attack).Level)
Console.WriteLine("Experience :{0:0,0}", Player(Skills.Attack).Experience)
Console.WriteLine("Rank :{0:0,0}", Player(Skills.Attack).Rank)
Console.WriteLine("Exp To Next Lvl :{0:0,0}", Player(Skills.Attack).ExperienceToNextLevel)
Else
Console.WriteLine("Attack is not listed.")
End If
Console.ReadKey()
End Sub
End Module
Code:
''' <summary>
''' A class which contains RuneScape account information.
''' </summary>
Public NotInheritable Class PlayerStats
Inherits MarshalByRefObject
Private Shared WebClient As New Net.WebClient
Private Shared Function DownloadString(ByVal Url As String) As String
Try
Return WebClient.DownloadString(Url)
Catch ex As Exception
Return ex.Message
End Try
End Function
''' <summary>
''' Looks up the player and lists all skills.
''' </summary>
Public Sub New(ByVal PlayerName As String)
Me._Playername = PlayerName
Dim Html As String = DownloadString("[URL]http://hiscore.runescape.com/index_lite.ws?player=[/URL]" & PlayerName)
_Stats = New List(Of Skill)
If Html.Contains("(404)") Then Return
Dim CurrentStat As Skills = 0
For Each Line As String In Html.Split(vbNewLine.ToCharArray, StringSplitOptions.RemoveEmptyEntries)
If CurrentStat > Skills.Summoning Then Continue For
Dim Skill As New Skill(CurrentStat, Line)
If Skill.Rank <> -1 Then _Stats.Add(Skill)
CurrentStat += 1
Next
End Sub
Private _Playername As String
''' <summary>
''' The name of the player.
''' </summary>
Public ReadOnly Property PlayerName() As String
Get
Return _Playername
End Get
End Property
Private _Stats As List(Of Skill)
''' <summary>
''' A readonly collection of all the players stats.
''' </summary>
Public ReadOnly Property Stats() As Collections.ObjectModel.ReadOnlyCollection(Of Skill)
Get
Return New Collections.ObjectModel.ReadOnlyCollection(Of Skill)(_Stats)
End Get
End Property
''' <summary>
''' Whether the player is listed on the hiscores or not.
''' </summary>
Public ReadOnly Property IsOnHiscores() As Boolean
Get
Return _Stats.Count > 0
End Get
End Property
''' <summary>
''' Returns the skill information of the selected skill.
''' </summary>
Default Public ReadOnly Property Stat(ByVal Skill As Skills) As Skill
Get
For Each I As Skill In _Stats
If I.Skill = Skill Then Return I
Next
Return New Skill(Skill, -1, 1, 0)
End Get
End Property
''' <summary>
''' Returns the level of the selected skill.
''' </summary>
Public ReadOnly Property Level(ByVal Skill As Skills) As Integer
Get
For Each I As Skill In _Stats
If I.Skill = Skill Then Return I.Level
Next
If Skill = Skills.Hitpoints Then Return 10 Else Return 1
End Get
End Property
''' <summary>
''' Returns the rank of the selected skill.
''' </summary>
Public ReadOnly Property Rank(ByVal Skill As Skills) As Integer
Get
For Each I As Skill In _Stats
If I.Skill = Skill Then Return I.Level
Next
Return -1
End Get
End Property
''' <summary>
''' Returns the experience of the selected skill.
''' </summary>
Public ReadOnly Property Experience(ByVal Skill As Skills) As Integer
Get
For Each I As Skill In _Stats
If I.Skill = Skill Then Return I.Level
Next
Return 0
End Get
End Property
''' <summary>
''' Returns the players approximate combat level from supplied information.
''' </summary>
Public ReadOnly Property CombatLevel() As Integer
Get
Try
If Not IsOnHiscores Then Return 3
Dim Base As Double = 0
Base += (Level(Skills.Defence) + Level(Skills.Hitpoints)) * 100
Base += (Level(Skills.Prayer) - (Level(Skills.Prayer) Mod 2)) * 50
Base += (Level(Skills.Summoning) - (Level(Skills.Summoning) Mod 2)) * 50
Base /= 400
Dim MeleeClass As Double = 0
MeleeClass += (Level(Skills.Attack) + Level(Skills.Strength)) * 130
MeleeClass /= 400
Dim RangeClass As Double = 0
RangeClass += (Level(Skills.Ranged) * 195) - (Level(Skills.Ranged) Mod 2) * 65
RangeClass /= 400
Dim MagicClass As Double = 0
MagicClass += (Level(Skills.Magic) * 195) - (Level(Skills.Magic) Mod 2) * 65
MagicClass /= 400
Dim Sort As Double() = {MeleeClass, RangeClass, MagicClass}
Array.Sort(Sort)
Select Case Sort(2)
Case MeleeClass : Return (Sort(2) + Base)
Case RangeClass : Return (Sort(2) + Base)
Case MagicClass : Return (Sort(2) + Base)
Case Else : Return 3
End Select
Catch ex As Exception
Return 3
End Try
End Get
End Property
Public Overrides Function ToString() As String
Dim Builder As New System.Text.StringBuilder
Builder.AppendLine("Name = " & Me.PlayerName)
For Each I As Skill In _Stats
Builder.AppendLine(String.Format("{0} = Lvl: {1} Exp: {2} Rank: {3}", I.Skill.ToString, I.Level, I.Experience, I.Rank))
Next
Return Builder.ToString.Trim(vbNewLine.ToCharArray)
End Function
End Class
Public Class Skill
Friend Sub New(ByVal Skill As Skills, ByVal Rank As Integer, ByVal Level As Integer, ByVal Experience As Integer)
_Skill = Skill : _Rank = Rank : _Level = Level : _Experience = Experience
End Sub
Friend Sub New(ByVal Skill As Skills, ByVal Data As String)
Dim Sl As String() = Data.Split(",")
_Skill = Skill : _Rank = Val(Sl(0)) : _Level = Val(Sl(1)) : _Experience = Val(Sl(2))
End Sub
Private _Experience As Integer
Public ReadOnly Property Experience() As Integer
Get
Return _Experience
End Get
End Property
Private _Level As Integer
Public ReadOnly Property Level() As Integer
Get
Return _Level
End Get
End Property
Private _Rank As Integer
Public ReadOnly Property Rank() As Integer
Get
Return _Rank
End Get
End Property
Private _Skill As Skills
Public ReadOnly Property Skill() As Skills
Get
Return _Skill
End Get
End Property
Public ReadOnly Property ExperienceToLevel(ByVal level As SByte) As Integer
Get
If level <= Me.Level Then Return 0
If level > 99 Then Return 0
Return GetLevelExperience(level) - Experience
End Get
End Property
Public ReadOnly Property ExperienceToNextLevel() As Integer
Get
If Level >= 99 Then Return 0
Return GetLevelExperience(Level + 1) - Experience
End Get
End Property
Public ReadOnly Property OnHiscores() As Boolean
Get
Return Rank <> -1
End Get
End Property
Public Shared Function GetLevelExperience(ByVal Level As Integer) As Long
Dim Output As Double = 0
For L As Double = 1 To Level - 1
Output += Int(L + 300 * (2 ^ (L / 7)))
Next
Return Math.Floor(Output / 4)
End Function
Public Shared Operator =(ByVal Left As Skill, ByVal Right As Skill) As Boolean
Return (Left.Skill = Right.Skill) AndAlso (Left.Rank = Right.Experience)
End Operator
Public Shared Operator <>(ByVal Left As Skill, ByVal Right As Skill) As Boolean
Return Not Left = Right
End Operator
End Class
Public Enum Skills
Overall
Attack
Defence
Strength
Hitpoints
Ranged
Prayer
Magic
Cooking
Woodcutting
Fletching
Fishing
Firemaking
Crafting
Smithing
Mining
Herblore
Agility
Thieving
Slayer
Farming
Runecraft
Construction
Hunter
Summoning
End Enum

