Quantcast

Jump to content


Photo

Inkheart's Autotrainer


  • Please log in to reply
57 replies to this topic

#1 Inkheart

Inkheart
  • 268 posts

Posted 17 March 2012 - 12:28 AM

*
POPULAR POST!

So I decided to bother with the nastiness of GUI programming for my fellow Codexians and figured I'd tackle the project of highest demand, an Autotrainer. Behold!

It's simplistic, I guess, but that almost comes with the territory. You pretty much only need a way to start and stop training, and of course the ability to tell it how to train, and these are the things on offer. When you start the program, you're greeted with a simple login prompt. Fill it out, and you'll then be taken to a screen similar to the image above, except it will of course display your pets. It's built using Ruby and the GTK+ toolkit, so it should look pretty much the same on all operating systems.

Clicking a pet's "Start Training" button will bring up a prompt for choosing the training strategy. "Balanced" keeps a 2/1 ratio between Level and the other stats, which can be filtered with the checkboxes if, for instance, you only want to train Level and HP. "Random" will just pick a random stat out of the ones you've checked, and "Set Order" allows you to fill in a string like "LDSLLSD" if you wanted to train Level, then Defense, then Strength, and so on. Of course, it will always train Level if required by some other stat being more than twice the current.

I've tried to make it as foolproof as possible, but there are no absolutes in that particular domain. It makes sure you're logged in before making any requests to Neopets, will pick up right in the middle if the pet is training, waiting for its course to be paid for, or has already finished. Pets can't be trained at the Island if they're in the Academy; right now, the program just informs you of such and stops processing that pet.

When gathering Codestones, it checks inventory first, then SDB, and finally buys them from the Shop Wizard if necessary. This process takes a couple seconds because it has to hit Neopets quite a few times, and currently the program's interface hangs when making HTTP requests. Don't freak out and click like crazy, you will only do harm. When buying codestones, it chooses the first shop that has as many of the Codestone in stock as you need + 1, just to ensure you can buy the requisite amount in the event that somebody picks one up in the interim. I have all labbed pets with low levels, so wasn't able to test multiple Codestones, but I think the implementation is sound. We'll see. : )

Hm... well, that's about it for usage, I suppose. Now for the technical side. The program is Ruby, but I didn't want to make everybody have to go through the process of installing it and properly setting up; in fact, I wanted it to be as simple as possible to just download it and get it running. To that end, I used Ocra (One-Click Ruby Application) to package everything up into a single .exe. Here is the code that gets compiled:

require 'gtk2'
require 'net/http'
require 'oily_png'
include Gtk, Gdk

code = Net::HTTP.start('inkheart.googlecode.com').get( "/svn/trunk/autotrainer.rb?#{rand}" ).body
eval code

This grabs all of the actual code from a remote file hosted on Google Projects. I set it up this way to allow for seamless bug fixes and updates. This is usually a very shifty way of doing things, but I solemnly swear that I am up to no evil. Because the program has to dynamically load all of the Ruby interpreter before starting, IT WILL TAKE A WHILE FOR THE PROGRAM TO START. Don't keep clicking it, as this will benefit nothing. Shouldn't take more than 15 or 20 seconds for your computer to figure out where everything is and should go.

Non-Windows users (please reproduce, you beautiful people) or those who despise the slow startup time should be able to simply save the above code as a .rb file and pass it to Ruby, but will of course have to download Ruby before doing so. People who don't use Windows tend to be a brighter bunch, though, so that shouldn't be much trouble.

Roadmap

Use Typhoeus to do non-blocking HTTP calls, which prevents the GUI from hanging. Requires Windows users to download and set up libcurl, though, which is why I avoided it for the initial release.

Clean up the incredibly shitty code, if only for the sake of pride. I wanted to see what building an interface from scratch was like, as opposed to using Glade to design it, and it was not a pleasant experience.

Allow for training at the Academy, maybe.

Download

Unfortunately, the .exe has to package the entire Ruby language to run, so it's ~20MB, meaning I can't host it here. MediaFire is entirely reputable, and they scan for viruses during upload, so you're in no danger there. As for stealing your passwords, well, that's the risk you take just wait for somebody who can detect those things to come along and say it's safe if you have reservations. Otherwise, enjoy! Please feel free to post any bugs or feature requests. I'd be happy to squash/implement them.

#2 AngryArtist

AngryArtist
  • 13 posts

Posted 17 March 2012 - 12:57 AM

Well done! :) I personally don't need training atm, but I'm sure the community will be happy. Thanks for your hard work!

#3 Melchoire

Melchoire
  • 5284 posts


Users Awards

Posted 17 March 2012 - 01:17 AM

Grab the code from your own repo and execute it....that's brilliant!

#4 iomega

iomega
  • 1070 posts


Users Awards

Posted 17 March 2012 - 01:17 AM

It seems to stop responding and closes itself a moment or two after I press "Go!"
Everything else before that worked fine. It showed all my pets and their correct stats as well as saying that one of them was awaiting payment.

(I'm running Windows 7)

#5 Inkheart

Inkheart
  • 268 posts

Posted 17 March 2012 - 01:23 AM

Grab the code from your own repo and execute it....that's brilliant!


Not sure what to take from this. Do you mean it's a good idea for streamlining updates, or bad in the sense that it can be changed to something nefarious at any time? I imagine you mean the latter, and I do recognize this as an issue. I'd be happy to try to work something out with the admins. I was thinking the code could just be stored in a locked post somewhere here on the boards, and then they'd unlock it for me if I needed to make changes, but that seems bothersome.

It seems to stop responding and closes itself a moment or two after I press "Go!"
Everything else before that worked fine. It showed all my pets and their correct stats as well as saying that one of them was awaiting payment.

(I'm running Windows 7)


Hm... I tested on Windows 7. Will look into. : /

#6 Melchoire

Melchoire
  • 5284 posts


Users Awards

Posted 17 March 2012 - 01:29 AM

Not sure what to take from this. Do you mean it's a good idea for streamlining updates, or bad in the sense that it can be changed to something nefarious at any time? I imagine you mean the latter, and I do recognize this as an issue. I'd be happy to try to work something out with the admins. I was thinking the code could just be stored in a locked post somewhere here on the boards, and then they'd unlock it for me if I needed to make changes, but that seems bothersome.


Not at all, I don't do anything with neopets so "nefarious" in that sense doesn't matter to me =P I meant it's a very cool way to do your updates, and since it's an internet app you need an internet connection to use it anyway. Plus it's a publicly viewable repository isn't it?

Anyway, if it wanted to do any real damage on a linux machine it would need to be run as root, which most level-headed users would avoid.

E: yep your code can be viewed anyway...but what's with that "#{rand}" in the url?

#7 Inkheart

Inkheart
  • 268 posts

Posted 17 March 2012 - 01:33 AM

Not at all, I don't do anything with neopets so "nefarious" in that sense doesn't matter to me =P I meant it's a very cool way to do your updates, and since it's an internet app you need an internet connection to use it anyway. Plus it's a publicly viewable repository isn't it?

Anyway, if it wanted to do any real damage on a linux machine it would need to be run as root, which most level-headed users would avoid.

E: yep your code can be viewed anyway...but what's with that "#{rand}" in the url?


Ah, right on. I mean, I like it. So long as there's a level of trust between parties, it's a very effective and convenient way to make a piece of code dynamic. It is of course public, or else I would have taken a different approach. Transparency is a virtue. No, I didn't mean damage in terms of the user's machine, but rather stealing login credentials, which for most users here is just as serious. The "#{rand}" bit just appends a random float to the URL to bust the cache, ensuring the user always executes the most updated version of the code.

#8 Melchoire

Melchoire
  • 5284 posts


Users Awards

Posted 17 March 2012 - 01:53 AM

The "#{rand}" bit just appends a random float to the URL to bust the cache, ensuring the user always executes the most updated version of the code.


That explains it. That one had me wondering.

E: what cache?

#9 Inkheart

Inkheart
  • 268 posts

Posted 17 March 2012 - 01:59 AM

That explains it. That one had me wondering.

E: what cache?


Well, it's probably not necessary but, in my browser at least, committing to the Subversion repository and then refreshing the page doesn't immediately show the changes. If, however, I add on a random query string, the updates are shown. I don't think Ruby's Net::HTTP library does any internal caching, but I tack on a random number just to be certain.

iomega: I can't reproduce your bug on my Windows 7 machine. If the interface loads and you see your pets' stats, that means that all of the necessarily libraries are in place. If I open the program fresh with a pet's status as "Awaiting Payment", I can click "Start Training" and, after a bit of time for Codestone gathering, the timer properly starts. Did you do anything weird with the strategy dialog?

Edited by Inkheart, 17 March 2012 - 02:30 AM.


#10 Neoquest

Neoquest
  • 1760 posts


Users Awards

Posted 17 March 2012 - 09:06 AM

I get the same results as iomega. I'm running on Windows 7.

#11 Inkheart

Inkheart
  • 268 posts

Posted 17 March 2012 - 09:27 AM

I get the same results as iomega. I'm running on Windows 7.


Well, shit. It seems Ocra doesn't quite live up to its name. Doing a clean install of Windows isn't in this cards for this little project, but I'll update once I've tested on a friend's machine with none of the dependencies installed. Sorry, guys. : / I would love to help make programs for the Codex, but it seems you guys're gonna have to install Ruby for that to go forward. : (

Edited by Inkheart, 17 March 2012 - 11:31 AM.


#12 Neoquest

Neoquest
  • 1760 posts


Users Awards

Posted 17 March 2012 - 10:23 AM

Well, shit. It seems Ocra doesn't quit live up to its name. Doing a clean install of Windows isn't in this cards for this little project, but I'll update once I've tested on a friend's machine with none of the dependencies installed. Sorry, guys. : / I would love to help make programs for the Codex, but it seems you guys're gonna have to install Ruby for that to go forward. : (


I installed the latest version of Ruby and now it works just fine, thanks for the great program Inkheart. I actually like the UI a bit more than the old Codex one!

Edited by Neoquest, 17 March 2012 - 10:27 AM.


#13 Nymh

Nymh
  • Keeper of Secrets

  • 4626 posts


Users Awards

Posted 17 March 2012 - 10:48 AM

OMGGGGGG

Posted Image

Edited by nymh, 17 March 2012 - 10:48 AM.


#14 Inkheart

Inkheart
  • 268 posts

Posted 17 March 2012 - 11:30 AM

I installed the latest version of Ruby and now it works just fine, thanks for the great program Inkheart. I actually like the UI a bit more than the old Codex one!


Huzzah! It's not a difficult procedure, of course, I just want the barrier to entry to be as low as possible. Should have access to a clean system later this evening, will hopefully test and fix.

OMGGGGGG

Posted Image


Ah, the summit. Gorgeous scenery, but where does one go from here...

#15 Nymh

Nymh
  • Keeper of Secrets

  • 4626 posts


Users Awards

Posted 17 March 2012 - 11:48 AM

Ah, the summit. Gorgeous scenery, but where does one go from here...


I don't believe you have yet reached the summit. There is plenty left to do.

#16 Inkheart

Inkheart
  • 268 posts

Posted 17 March 2012 - 11:52 AM

I don't believe you have yet reached the summit. There is plenty left to do.


I meant that I joined Neocodex solely for your love and admiration, quantities arbitrary.

#17 blue

blue
  • doge

  • 2048 posts


Users Awards

Posted 17 March 2012 - 03:23 PM

Friggin awesome!

Thank you for this!

#18 Icey Defeat

Icey Defeat
  • 8298 posts


Users Awards

Posted 17 March 2012 - 05:26 PM

I meant that I joined Neocodex solely for your love and admiration, quantities arbitrary.


Don't let her fool you, she's really a dude. ;)

#19 Nymh

Nymh
  • Keeper of Secrets

  • 4626 posts


Users Awards

Posted 17 March 2012 - 07:12 PM

It has crashed on me a couple of times, once was right after I opened it and started training the first time, and once was after running for several hours. I wasn't keeping an eye on it at the time but from going to the training school it looks like it crashed after finishing the course because the pet is not currently training and it had not initiated the next one yet. Going to run it all night long tonight and see how it performs.

#20 Bone

Bone
  • no

  • 3638 posts


Users Awards

Posted 17 March 2012 - 07:17 PM

It has crashed on me a couple of times, once was right after I opened it and started training the first time, and once was after running for several hours. I wasn't keeping an eye on it at the time but from going to the training school it looks like it crashed after finishing the course because the pet is not currently training and it had not initiated the next one yet. Going to run it all night long tonight and see how it performs.


This happened to me too, I left for a few hours and when I returned it had (presumably) crashed. The pet hadn't started another course.

#21 Nymh

Nymh
  • Keeper of Secrets

  • 4626 posts


Users Awards

Posted 17 March 2012 - 07:40 PM

Yeah, when I say "crashed" it's more like it just closed itself, it's not locked up or anything it's just no longer open at all.

Another bit of feedback:

I wanted to train Strength and Defense tonight, so I picked Random: Strength + Defense

This is my dialogue:

Logged in as xxxxxxx.
Set strategy for Xxxxxx: ["random", ["Strength", "Defence"]]
Xxxxxx is on standby, should be training.
Xxxxxx is restricted to training Level.
Starting Level course for Xxxxxx...
Hang on, grabbing Codestones might take a bit.
Xxxxxx is now training Level.


The stats were under 2x the level so the pet was not restricted to training level

Edited by nymh, 17 March 2012 - 07:41 PM.


#22 Dangocat

Dangocat
  • 119 posts

Posted 18 March 2012 - 12:38 AM

It's crashing for me too (windows 7) :(. But this is awesome~ hope I will be able to use it in the future

#23 Nymh

Nymh
  • Keeper of Secrets

  • 4626 posts


Users Awards

Posted 18 March 2012 - 05:05 AM

I am also Windows 7. It closed again last night, this time it seems to have happened before course completion because I have the "Complete Course" button still to click at the training school. It looks like it happened on the first attempted course.

Edited by nymh, 18 March 2012 - 05:05 AM.


#24 Neoquest

Neoquest
  • 1760 posts


Users Awards

Posted 18 March 2012 - 08:18 AM

It's crashing for me too (windows 7) :(. But this is awesome~ hope I will be able to use it in the future


Currently you need to install Ruby to get it to work.

#25 Noitidart

Noitidart
  • Neocodex Co-Founder

  • 23214 posts


Users Awards

Posted 18 March 2012 - 09:48 AM

Wow inkheart nice open source job there


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users