PDA

View Full Version : [VB .net] Mystery Island Training School Functions



Carnage
05-25-2014, 07:00 PM
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 [Only registered and activated users can see links] and Getbetween, and Joe for advice on variable conversion.

---------------------------------------------------------------------

You will need the following couple functions for any of these to work:

GetBetween:

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

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:

action = checkStatus([Only registered and activated users can see links] strhtml, cmbPets)


Public Function checkStatus(ByVal [Only registered and activated users can see links] As [Only registered and activated users can see links] ByVal strhtml As String, ByVal cmbpets As ComboBox) As Integer
strhtml = [Only registered and activated users can see links]("GET", "[Only registered and activated users can see links]")
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:

retrieveStats([Only registered and activated users can see links] strhtml, cmbPets, petlvl, petstr, pethp, petagil, petdef)
lbllvl.Text = petlvl
lblstr.Text = petstr
lblhp.Text = pethp
lblagil.Text = petagil
lbldef.Text = petdef





Public Function retrieveStats(ByVal [Only registered and activated users can see links] As [Only registered and activated users can see links] 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 = [Only registered and activated users can see links]("GET", "[Only registered and activated users can see links]")
strstattemp = GetBetween(strhtml, "[Only registered and activated users can see links]" & cmbpets.SelectedItem & "/1/2.png", "<br><br></td><td width=250 align=center>")
If strstattemp = "" Then strstattemp = GetBetween(strhtml, "[Only registered and activated users can see links]" & 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:

finish = finishTraining([Only registered and activated users can see links] strhtml, cmbPets)


Public Function finishTraining(ByVal [Only registered and activated users can see links] As [Only registered and activated users can see links] ByVal strhtml As String, ByVal cmbpets As ComboBox ByRef superbonus as Integer) As Integer
strhtml = [Only registered and activated users can see links]("POST", "[Only registered and activated users can see links]" & "type=complete&pet_name=" & cmbpets.SelectedItem, "[Only registered and activated users can see links]")
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:

done = checkIfDone([Only registered and activated users can see links] strhtml, cmbPets)



Public Function checkIfDone(ByVal [Only registered and activated users can see links] As [Only registered and activated users can see links] ByVal strhtml As String, ByVal cmbpets As ComboBox) As Boolean
strhtml = [Only registered and activated users can see links]("GET", "[Only registered and activated users can see links]")
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:

strtime = checkTimeString([Only registered and activated users can see links] strhtml, cmbpets)


Public Function checkTimeString(ByVal [Only registered and activated users can see links] As [Only registered and activated users can see links] ByVal strhtml As String, ByVal cmbpets As ComboBox) As String
Dim strtemp As String
Dim stringtime As String
strhtml = [Only registered and activated users can see links]("GET", "[Only registered and activated users can see links]")
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:

strtimeCookie = checkTimeString([Only registered and activated users can see links] strhtml)


Public Function checkTimeStringFortune(ByVal [Only registered and activated users can see links] As [Only registered and activated users can see links] ByVal strhtml As String) As String
Dim stringtime As String
strhtml = [Only registered and activated users can see links]("GET", "[Only registered and activated users can see links]")
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:

timeinsecs = checkTimeSeconds([Only registered and activated users can see links] 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:

timeinmillisecs = checkTimeSeconds([Only registered and activated users can see links] strhtml, cmbpets) * 1000


Public Function checkTimeSeconds(ByVal [Only registered and activated users can see links] As [Only registered and activated users can see links] 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 = [Only registered and activated users can see links]("GET", "[Only registered and activated users can see links]")
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:

timeinsecsFortune = checkTimeSecondsFortune([Only registered and activated users can see links] 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:

timeinmillisecsFortune = checkTimeSeconds([Only registered and activated users can see links] strhtml, cmbpets) * 1000


Public Function checkTimeSecondsFortune(ByVal [Only registered and activated users can see links] As [Only registered and activated users can see links] 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 = [Only registered and activated users can see links]("GET", "[Only registered and activated users can see links]")
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:

pay = payCourse([Only registered and activated users can see links] strTemp, strhtml, cmbPets, codestones, maxprice, CheckBox3, txtMax)


Public Function payCourse(ByVal [Only registered and activated users can see links] As [Only registered and activated users can see links] 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 = [Only registered and activated users can see links]("GET", "[Only registered and activated users can see links]")
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 = [Only registered and activated users can see links]("GET", "[Only registered and activated users can see links]")
If checkbox3.Checked = True Then
maxprice = txtMax.Text
Else
maxprice = "99999"
End If
strhtml = [Only registered and activated users can see links]("POST", "[Only registered and activated users can see links]" & codestones.Items(m).replace(" ", "+") & "&table=shop&criteria=exact&min_price=0&max_price=" & maxprice, "[Only registered and activated users can see links]")

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 = [Only registered and activated users can see links]("GET", "[Only registered and activated users can see links]" & strshop)
stritem = GetBetween(strhtml, "valign=" & strquote & "top" & strquote & "><A href=" & strquote, strquote)
strhtml = [Only registered and activated users can see links]("GET", "[Only registered and activated users can see links]" & 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:

begin = startCourse([Only registered and activated users can see links] strhtml, cmbstats, cmbpets

Public Function startCourse(ByVal [Only registered and activated users can see links] As [Only registered and activated users can see links] ByVal strhtml As String, ByVal cmbStats As ComboBox, ByVal cmbpets As ComboBox) As Integer
strhtml = [Only registered and activated users can see links]("POST", "[Only registered and activated users can see links]" & "type=start" & "&course_type=" & cmbStats.SelectedItem & "&pet_name=" & cmbpets.SelectedItem, "[Only registered and activated users can see links]")
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!

j03
05-26-2014, 10:19 AM
For the super bonus detection, does it output how many extra points you got?

Carnage
05-26-2014, 10:29 AM
For the super bonus detection, does it output how many extra points you got?

To my knowledge, super bonuses are always 2 points. That is recognized by that particular function. If you've found otherwise, please let me know.

EDIT:
"Occasionally, however, you might get a 2 point boost and, rarely, a mega 3 point boost"
I didn't really look into that prior to this. I've never received a 3 point bonus, so I didn't even know it existed o_o. I'll modify the function to return the size of the bonus.

EDIT x2:

Added 2 and 3 point bonus return.

Ban
05-29-2014, 07:45 AM
To my knowledge, super bonuses are always 2 points. That is recognized by that particular function. If you've found otherwise, please let me know.

EDIT:
"Occasionally, however, you might get a 2 point boost and, rarely, a mega 3 point boost"
I didn't really look into that prior to this. I've never received a 3 point bonus, so I didn't even know it existed o_o. I'll modify the function to return the size of the bonus.

EDIT x2:

Added 2 and 3 point bonus return.

Just adding, there's also a chance you will get 4 or even 5 (highest I've ever seen) bonus :3

Carnage
05-29-2014, 11:12 AM
Just adding, there's also a chance you will get 4 or even 5 (highest I've ever seen) bonus :3

Thanks for the info. Do you know what the HTML for those bonuses are? I think 2 is super, 3 is mega. Didn't even know 4 or 5 existed so I'm stumped as to what they could be.

Ban
05-29-2014, 11:44 AM
Thanks for the info. Do you know what the HTML for those bonuses are? I think 2 is super, 3 is mega. Didn't even know 4 or 5 existed so I'm stumped as to what they could be.

Unfortunately I don't D:
But I'll do some research and try to find out :3

Carnage
05-29-2014, 11:46 AM
Unfortunately I don't D:
But I'll do some research and try to find out :3

Thanks, much appreciated. I'll credit you if you can find them.

Zachafer
05-29-2014, 06:21 PM
finishTraining will return 3 for an error and also a superbonus of 3 o.o

Carnage
05-29-2014, 08:35 PM
finishTraining will return 3 for an error and also a superbonus of 3 o.o

No o.o Superbonus will be returned as a separate integer containing the value of the Super bonus. It's initiated as a reference.