Displaying a Player’s Latest World of Warcraft Achievements in VB.Net and C#

Setup

To fetch the achievement data of the World of Warcraft character we are going to make use of armoryapi, the armoryapi library currently requires that the project’s target framework be 3.5 or higher so set your project up to use 3.5 or higher in the project properties.

After creating your project and setting up the target framework the next step is to add the reference to the armoryapi library. Download and extract the latest armoryapi package and you will find a DLL and an XML file inside, make note of where you have extracted these files and head back to Visual Studio. Open the “Add Reference” dialog (see http://msdn.microsoft.com/en-us/library/wkze6zky(v=vs.80).aspx) and click the tab labelled “Browse” and navigate to the armoryapi DLL that you extracted.

Note: in order for the intellisense documentation to work you must also extract the XML file to the same directory as the DLL

Code

Now that your project is setup let’s get started with some code, first thing’s first let’s create a very simple form that we can use to fetch and display the data. Create a form and add the following controls:

characterNameTextBox – TextBox
realmTextBox – TextBox
achievementList – ListBox
fetchButton – Button

You should now have something similar to this (I have added a few labels and a groupbox, but you obviously don’t have to do this to get started):

The main form

Now that we have our GUI sorted double click on fetchButton to create the click event handler for the button. Once you are in the code view we need to add an import to the ArmoryAPI namespace, to do this add the following line at the top of the file:

VB.Net

Imports ArmoryAPI

C#

using ArmoryAPI;

Once you’ve added the namespace import go back to the event handler for the button click and add the following code:

VB.Net

Dim armory As Armory = New Armory(BattleNetRegion.Europe, BattleNetLocale.en_GB)
Dim character As Character = armory.GetCharacter(characterNameTextBox.Text, realmTextBox.Text)

For Each a As UnlockedAchievement In character.Achievements
    If (DateTime.Now.AddDays(-14) < a.Unlocked) Then
        achievementList.Items.Add(String.Format("{0} ({1} points)", a.Title, a.Points))
    End If
Next

C#

Armory armory = new Armory(BattleNetRegion.Europe, BattleNetLocale.en_GB);
Character character = armory.GetCharacter(characterNameTextBox.Text, realmTextBox.Text);

foreach (UnlockedAchievement a in character.Achievements)
{
    if (DateTime.Now.AddDays(-14) < a.Unlocked)
    {
        achievementList.Items.Add(String.Format("{0} ({1} points)", a.Title, a.Points));
    }
}

If you debug the project now you will be able to fetch the achievements the character entered has unlocked within the last two weeks as can be seen below.

Main screen with achievement data

This code queries the European servers and returns the data in English, if you need a different configuration simply change the line that creates the Armory object, the following regions and locales are supported:

Regions

  • America
  • China
  • Europe
  • Korea
  • Taiwan

Locales

  • de_DE
  • en_GB
  • en_US
  • es_ES
  • es_MX
  • fr_FR
  • ko_KR
  • ru_RU
  • zh_CN
  • zh_TW

Extra Steps

In order to improve upon this project, you can utiilise the caching functionality of armoryapi, to do this you’ll have to setup a database (see http://code.google.com/p/armoryapi/wiki/GettingStarted#Setting_up_a_Database) and simply pass the connection string to the Armory object and the time in minutes that the data should be cached for as shown in the example below.

armory.ConnectionString = "Data Source=(local)\SQLEXPRESS;Initial Catalog=armoryapi;User ID=username;Password=password"
armory.RefreshInterval = 120
Posted in Gaming, Programming, Technology, Tutorials at October 8th, 2011. 2 Comments.

Winner of the O’Reilly Academic Prize Scheme 2010

This year my university decided to enter all the third year BSc computing students into a competition held by O’Reilly for the best and most original dissertation; my entry was of course phpAnalyzer. A couple of days ago along side the results of my degree, I got my prize in the mail as well as a little certificate – definitely a good way to end three years of higher education!

In addition to getting good results and winning the contest held by O’Reilly I also got a new job as a software developer, so now when I’m not at home programming, I’m at work programming! It’s been a bit tough making the transition from the life of a student to doing five full days of work every week but I can’t complain as I am doing something I love and I am working with nice people who are helping me get to grips with their way of doing things. As a result of starting my new job one of my new projects has been slowed down a bit, as well as the development of EDK (which is now nearly finished) but I’m slowly picking the pace back up as I get adjusted to working life. My new project is another Xbox LIVE game which I will also make available on the PC, I have managed to get quite a lot of people on board so far; at the moment the team consists of:

  • One developer (myself as you can imagine)
  • One artist
  • Two graphics designers
  • Five level designers
  • Two audio engineers

The only thing really missing at the moment is someone to come up with a storyline, but if I fail to find anyone to come up with a plot I’ll just throw in more blood and violence – that is a suitable replacement for a good story isn’t it?