While working on my Mystery Island Training School program, I've decided to release all of the functions I wrote for it.
I will be adding to this list as I refine and expand the functionality in development of this program.
Credits to the original writer of httpwrapper and Getbetween, and Joe for advice on variable conversion.
---------------------------------------------------------------------
You will need the following couple functions for any of these to work:
GetBetween:
Code:
Public Function GetBetween(ByVal main As String, ByVal start As String, ByVal finish As String, Optional ByVal index As Integer = 0) As String
Dim gbMatch As Match = New Regex(Regex.Escape(start) & "(.+?)" & Regex.Escape(finish)).Match(main, index)
If gbMatch.Success Then
Return gbMatch.Groups(1).Value
Else
Return String.Empty
End If
End Function
GetBetweenAll
Code:
Public Function GetBetweenAll(ByVal main As String, ByVal start As String, ByVal finish As String, Optional ByVal index As Integer = 0) As List(Of String)
Dim matches As List(Of String) = New List(Of String)()
Dim gbMatch As Match = New Regex(Regex.Escape(start) & "(.+?)" & Regex.Escape(finish)).Match(main, index)
While gbMatch.Success
matches.Add(gbMatch.Groups(1).Value)
gbMatch = gbMatch.NextMatch()
End While
Return matches
End Function
---------------------------------
FUNCTIONS:
checkStatus - Will check the current status of your Neopets in the training school.
Returns an integer:
0 = Unknown error
1 = Pet is already on a course and a time is available
2 = Pet is on a course which needs to be completed
3 = Pet is on a course which needs to be payed for
As you can see, this function is set to use a value which is stored in a combobox. You can change that to anything you'd like to store the value of the pets name you're training with.
Example of use:
Code:
action = checkStatus(httpwrapper, strhtml, cmbPets)
Code:
Public Function checkStatus(ByVal httpwrapper As httpwrapper, ByVal strhtml As String, ByVal cmbpets As ComboBox) As Integer
strhtml = httpwrapper.Request("GET", "http://www.neopets.com/island/training.phtml?type=status")
If strhtml.Contains(cmbpets.SelectedItem & "/2/2.png") Then
Return "1" 'Not on course
ElseIf strhtml.Contains("value='" & cmbpets.SelectedItem & "'><input type='submit' value='Complete Course!") Then
Return "2" 'Course needs to be completed
ElseIf strhtml.Contains("type=pay&pet_name=" & cmbpets.SelectedItem & "'><b>here</b></a> to pay)<p>") Then
Return "3" 'Needs to be payed for
Else : Return "0"
End If
End Function
retrieveStats - Will retrieve your pets statistics.
Returns 5 separate values
petlvl - Returns pet level as an integer
petstr - Returns pet strength as an integer
pethp - Returns pet HP as an integer
petagil - Returns pet speed/agility as an integer
petdef - Returns pet defense as an integer
As you can see, this is set to use the value of what's stored in a combo box (cmbPets). You can change this to whatever other value container you wish.
Example of use:
Code:
retrieveStats(httpwrapper, strhtml, cmbPets, petlvl, petstr, pethp, petagil, petdef)
lbllvl.Text = petlvl
lblstr.Text = petstr
lblhp.Text = pethp
lblagil.Text = petagil
lbldef.Text = petdef
Code:
Public Function retrieveStats(ByVal httpwrapper As httpwrapper, ByVal strhtml As String, ByVal cmbpets As ComboBox, ByRef petlvl As Integer, ByRef petstr As Integer, ByRef pethp As Integer, ByRef petagil As Integer, ByRef petdef As Integer) As String
Dim strstattemp As String
strhtml = httpwrapper.Request("GET", "http://www.neopets.com/island/training.phtml?type=status")
strstattemp = GetBetween(strhtml, "http://pets.neopets.com/cpn/" & cmbpets.SelectedItem & "/1/2.png", "<br><br></td><td width=250 align=center>")
If strstattemp = "" Then strstattemp = GetBetween(strhtml, "http://pets.neopets.com/cpn/" & cmbpets.SelectedItem & "/2/2.png", "<br><br></td><td width=250 align=center>")
petlvl = Convert.toInt32(GetBetween(strstattemp, "<br>Lvl : <font color=green><b>", "</b>"))
petstr = Convert.toInt32(GetBetween(strstattemp, "</font><br>Str : <b>", "</b"))
pethp = Convert.toInt32(GetBetween(strstattemp, "/ ", "</b>"))
petagil = Convert.toInt32(GetBetween(strstattemp, "Mov : <b>", "</b>"))
petdef = Convert.toInt32(GetBetween(strstattemp, "Def : <b>", "</b>"))
Return petlvl
Return petstr
Return pethp
Return petagil
Return petdef
End Function
finishTraining - Will complete a course for pet name stored in cmbPets (combobox).
Returns an integer 2 integers; finishTraining() and superbonus. Super bonus contains the bonus (as an integer) if applicable:
1 = Course finished successfully and no bonus was awarded.
2 = Course finished successfully and a bonus was awarded.
3 = An unknown error occurred
As you can see, this is set to use the value of what's stored in a combo box (cmbPets). You can change this to whatever other value container you wish.
Example of use:
Code:
finish = finishTraining(httpwrapper, strhtml, cmbPets)
Code:
Public Function finishTraining(ByVal httpwrapper As httpwrapper, ByVal strhtml As String, ByVal cmbpets As ComboBox ByRef superbonus as Integer) As Integer
strhtml = httpwrapper.Request("POST", "http://www.neopets.com/island/process_training.phtml?" & "type=complete&pet_name=" & cmbpets.SelectedItem, "http://www.neopets.com/island/training.phtml?type=status")
If strhtml.Contains("now has increased") Then
Return 1 'Succesfully trained
ElseIf strhtml.Contains("*** SUPER BONUS") Then
if strhtml.Contains("You went up 3") Then
superbonus = 3
else
superbonus = 2
Return superbonus
End if
Return 2 'Super bonus
Else
Return 3 'An unknown error occured
End If
End Function
checkIfDone - Will check to see if selected pet has completed their course.
Returns a boolean:
True = Course is ready to be completed
False = Course is not done
As you can see, this is set to use the value of what's stored in a combo box (cmbPets). You can change this to whatever other value container you wish.
Example of use:
Code:
done = checkIfDone(httpwrapper, strhtml, cmbPets)
Code:
Public Function checkIfDone(ByVal httpwrapper As httpwrapper, ByVal strhtml As String, ByVal cmbpets As ComboBox) As Boolean
strhtml = httpwrapper.Request("GET", "http://www.neopets.com/island/training.phtml?type=status")
If strhtml.Contains("value='" & cmbpets.SelectedItem & "'><input type='submit' value='Complete Course!") Then
Return True
Else
Return False
End If
End Function
checkTimeString - Will retrieve the amount of time (as a string) left in the pet's training course
Returns:
Value of stringtime as a string
As you can see, this is set to use the value of what's stored in a combo box (cmbPets). You can change this to whatever other value container you wish.
Example:
Code:
strtime = checkTimeString(httpwrapper, strhtml, cmbpets)
Code:
Public Function checkTimeString(ByVal httpwrapper As httpwrapper, ByVal strhtml As String, ByVal cmbpets As ComboBox) As String
Dim strtemp As String
Dim stringtime As String
strhtml = httpwrapper.Request("GET", "http://www.neopets.com/island/training.phtml?type=status")
strtemp = GetBetween(strhtml, "colspan=2><b>" & cmbpets.SelectedItem, "nds</b></td>")
stringtime = GetBetween(strtemp, "align=center>Time till course finishes : <br><b>", " seco")
Return stringtime
End Function
checkTimeStringFortune - Will retrieve the amount of time (as a string) left in the pet's training course while using a Training School Fortune Cookie. Since the html for displaying these times is different than not using a fortune cookie, this separate function is required.
Returns:
Value of stringtime as a string
Example:
Code:
strtimeCookie = checkTimeString(httpwrapper, strhtml)
Code:
Public Function checkTimeStringFortune(ByVal httpwrapper As httpwrapper, ByVal strhtml As String) As String
Dim stringtime As String
strhtml = httpwrapper.Request("GET", "http://www.neopets.com/island/training.phtml?type=status")
stringtime = GetBetween(strhtml, " <b>", "</b>")
Return stringtime
End Function
checkTimeSeconds - Will retrieve the amount of time (in seconds) left in the pet's training course. This function is useful for delaying between training.
Returns:
Value of strtotalsecs as an Integer
As you can see, this is set to use the value of what's stored in a combo box (cmbPets). You can change this to whatever other value container you wish.
Example:
Code:
timeinsecs = checkTimeSeconds(httpwrapper, strhtml, cmbpets)
NOTE: If you would like to convert this to milliseconds (if you're using a wait which requires millisecond input) simply multiply the outcome value by 1000.
Example:
Code:
timeinmillisecs = checkTimeSeconds(httpwrapper, strhtml, cmbpets) * 1000
Code:
Public Function checkTimeSeconds(ByVal httpwrapper As httpwrapper, ByVal strhtml As String, ByVal cmbpets As ComboBox) As Integer
Dim strtemp As String
Dim strhrs As Integer
Dim strmins As Integer
Dim strsecs As Integer
Dim strtotalsecs As Integer
strhtml = httpwrapper.Request("GET", "http://www.neopets.com/island/training.phtml?type=status")
strtemp = GetBetween(strhtml, "colspan=2><b>" & cmbpets.SelectedItem, "nds</b></td>")
strhrs = Convert.ToInt32(GetBetween(strtemp, "Time till course finishes : <br><b>", " hrs"))
strmins = Convert.ToInt32(GetBetween(strtemp, "hrs, ", " minutes"))
strsecs = Convert.ToInt32(GetBetween(strtemp, "minutes, ", " seco"))
strtotalsecs = ((strhrs * 60) * 60 + (strmins * 60) + (strsecs))
Return strtotalsecs
End Function
checkTimeSecondsFortune - Will retrieve the amount of time (in seconds) left in the pet's training course while using a Training School Fortune Cookie. Since the html for displaying these times is different than not using a fortune cookie, this separate function is required. This function is useful for delaying between training.
Returns:
Value of strtotalsecs as an Integer
As you can see, this is set to use the value of what's stored in a combo box (cmbPets). You can change this to whatever other value container you wish.
Example:
Code:
timeinsecsFortune = checkTimeSecondsFortune(httpwrapper, strhtml, cmbpets)
NOTE: If you would like to convert this to milliseconds (if you're using a wait which requires millisecond input) simply multiply the outcome value by 1000.
Example:
Code:
timeinmillisecsFortune = checkTimeSeconds(httpwrapper, strhtml, cmbpets) * 1000
Code:
Public Function checkTimeSecondsFortune(ByVal httpwrapper As httpwrapper, ByVal strhtml As String) As Integer
Dim strtemp As String
Dim strhrs As Integer
Dim strmins As Integer
Dim strsecs As Integer
Dim strtotalsecs As Integer
strhtml = httpwrapper.Request("GET", "http://www.neopets.com/island/training.phtml?type=status")
strtemp = GetBetween(strhtml, " <b", "/b>")
strhrs = Convert.ToInt32(GetBetween(strtemp, ">", " hrs"))
strmins = Convert.ToInt32(GetBetween(strtemp, ", ", " minutes"))
strsecs = Convert.ToInt32(GetBetween(strtemp, "minutes, ", " seconds"))
strtotalsecs = ((strhrs * 60) * 60 + (strmins * 60) + (strsecs))
Return strtotalsecs
End Function
payCourse - This function will retrieve the Codestones required to train your pet, search the shopwiz for a price based on maximum value, and return an integer based on the result of purchasing.
Returns:
1 = Nothing found on wiz
2 = Inventory is full
As you can see, this is set to use the value of what's stored in a combo box (cmbPets), has a checkbox verification, loads list of codestones required to a listbox and a maximum buy value retrieved from a textbox. You can change this to whatever other value container you wish.
Example:
Code:
pay = payCourse(httpwrapper, strTemp, strhtml, cmbPets, codestones, maxprice, CheckBox3, txtMax)
Code:
Public Function payCourse(ByVal httpwrapper As httpwrapper, ByVal strtemp As String, ByVal strhtml As String, ByVal cmbpets As ComboBox, ByVal codestones As ListBox, ByVal maxprice As Integer, ByVal checkbox3 As CheckBox, ByVal txtmax As TextBox) As Integer
Dim i As Integer
Dim m As Integer
Dim strshop As String
Dim strquote As String = """"
Dim stritem As String
Dim strprice As String
strhtml = httpwrapper.Request("GET", "http://www.neopets.com/island/training.phtml?type=status")
strtemp = GetBetween(strhtml, "type=pay&pet_name=" & cmbpets.SelectedItem & "'><b>here</b></a> to pay)<p>", "<br><br><br></td></tr>")
Dim strcodestones As List(Of String) = GetBetweenAll(strtemp, "<b>", "</b>")
''''''''''''''''
For i = 0 To strcodestones.Count - 1
codestones.Items.Add(strcodestones.Item(i))
Next (i)
''''''''''''''''''
For m = 0 To codestones.Items.Count - 1
strhtml = httpwrapper.Request("GET", "http://www.neopets.com/market.phtml?type=wizard")
If checkbox3.Checked = True Then
maxprice = txtMax.Text
Else
maxprice = "99999"
End If
strhtml = httpwrapper.Request("POST", "http://www.neopets.com/market.phtml?type=process_wizard&feedset=0&shopwizard=" & codestones.Items(m).replace(" ", "+") & "&table=shop&criteria=exact&min_price=0&max_price=" & maxprice, "http://www.neopets.com/market.phtml?type=wizard")
If strhtml.Contains("I did not find anything.") Then
Return 1 'Failed to find
End If
strshop = GetBetween(strhtml, "/browseshop.phtml", """")
strprice = GetBetween(strhtml, "<td align=" & strquote & "right" & strquote & " bgcolor=" & strquote & "#F6F6F6" & strquote & "><b>", "</b>")
strprice.Replace(",", "")
strhtml = httpwrapper.Request("GET", "http://www.neopets.com/browseshop.phtml" & strshop)
stritem = GetBetween(strhtml, "valign=" & strquote & "top" & strquote & "><A href=" & strquote, strquote)
strhtml = httpwrapper.Request("GET", "http://www.neopets.com/" & stritem)
If strhtml.Contains("Sorry, you can only carry") Then
Return 2 'Carrying too many items
End If
Next m
codestones.items.clear()
End Function
startCourse - This function will begin a course in the Mystery Island Training School.
Returns:
0 = An unknown error occurred
1 = Your pet is already on a course
2 = Your pet can't do this course (due to stat requirements)
3 = Began course successfully
As you can see, this is set to use the value of what's stored in a combo box's (cmbPets) and (cmmStats). You can change this to whatever other value container you wish.
Example:
Code:
begin = startCourse(httpwrapper, strhtml, cmbstats, cmbpets
Code:
Public Function startCourse(ByVal httpwrapper As httpwrapper, ByVal strhtml As String, ByVal cmbStats As ComboBox, ByVal cmbpets As ComboBox) As Integer
strhtml = httpwrapper.Request("POST", "http://www.neopets.com/island/process_training.phtml?" & "type=start" & "&course_type=" & cmbStats.SelectedItem & "&pet_name=" & cmbpets.SelectedItem, "http://www.neopets.com/island/training.phtml?type=courses")
If strhtml.Contains("That pet is already doing a course") Then
Return 1
ElseIf strhtml.Contains("No statistic can go above twice") Then
Return 2
ElseIf strhtml.Contains("<a href='process_training.phtml?type=pay&pet_name=" & cmbpets.SelectedItem & "'><b>here</b></a> to pay)<p>") Then
Return 3
Else
Return 0
End If
End Function
Welp, that's about it! Hope this helps/motivates some of you to look into .net programming and possibly contribute some programs to the community. All I ask is if you use any of these functions, please give credit where credit is due.
Cheers!