Results 1 to 9 of 9

Thread: [VB .net] Mystery Island Training School Functions

  1. #1

    Joined
    Apr 2014
    Posts
    363
    Thanks
    77
    Thanked
    346/143
    DL/UL
    51/7
    Mentioned
    105 times
    Time Online
    21d 20h 18m
    Avg. Time Online
    8m

    [VB .net] Mystery Island Training School Functions

    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!
    Last edited by Carnage; 05-26-2014 at 10:48 AM.

  2. The Following User Says Thank You to Carnage For This Useful Post:

    j03 (05-26-2014)

  3. #2
    Saiyan Race
    j03's Avatar
    Joined
    Dec 2011
    Posts
    13,722
    Userbars
    166
    Thanks
    5,906
    Thanked
    33,078/6,609
    DL/UL
    23/36
    Mentioned
    3,867 times
    Time Online
    563d 5h 25m
    Avg. Time Online
    3h 13m
    For the super bonus detection, does it output how many extra points you got?
    (you need an account to see links)
    (you need an account to see links)(you need an account to see links)

    ------------------------
    [02/24/2013] Stealth CORE is made into the first standalone Neopets auto-player.
    ------------------------


  4. #3

    Joined
    Apr 2014
    Posts
    363
    Thanks
    77
    Thanked
    346/143
    DL/UL
    51/7
    Mentioned
    105 times
    Time Online
    21d 20h 18m
    Avg. Time Online
    8m
    Quote Originally Posted by Infamous Joe View Post
    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.
    Last edited by Carnage; 05-26-2014 at 10:48 AM.

  5. #4

    Joined
    Jan 2013
    Posts
    2,113
    Thanks
    1,851
    Thanked
    2,614/827
    DL/UL
    403/1
    Mentioned
    734 times
    Time Online
    120d 8h 12m
    Avg. Time Online
    42m
    Quote Originally Posted by Carnage View Post
    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

  6. #5

    Joined
    Apr 2014
    Posts
    363
    Thanks
    77
    Thanked
    346/143
    DL/UL
    51/7
    Mentioned
    105 times
    Time Online
    21d 20h 18m
    Avg. Time Online
    8m
    Quote Originally Posted by Discord View Post
    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.

  7. #6

    Joined
    Jan 2013
    Posts
    2,113
    Thanks
    1,851
    Thanked
    2,614/827
    DL/UL
    403/1
    Mentioned
    734 times
    Time Online
    120d 8h 12m
    Avg. Time Online
    42m
    Quote Originally Posted by Carnage View Post
    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

  8. #7

    Joined
    Apr 2014
    Posts
    363
    Thanks
    77
    Thanked
    346/143
    DL/UL
    51/7
    Mentioned
    105 times
    Time Online
    21d 20h 18m
    Avg. Time Online
    8m
    Quote Originally Posted by Discord View Post
    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.

  9. #8
    Zachafer's Avatar
    Joined
    Dec 2011
    Posts
    1,235
    Userbars
    11
    Thanks
    769
    Thanked
    1,466/678
    DL/UL
    98/0
    Mentioned
    512 times
    Time Online
    24d 13h 9m
    Avg. Time Online
    8m
    finishTraining will return 3 for an error and also a superbonus of 3 o.o

  10. #9

    Joined
    Apr 2014
    Posts
    363
    Thanks
    77
    Thanked
    346/143
    DL/UL
    51/7
    Mentioned
    105 times
    Time Online
    21d 20h 18m
    Avg. Time Online
    8m
    Quote Originally Posted by Zachafer View Post
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •