Wednesday, August 29, 2012

League of Legends Timer

In this post I want to present you a little project of mine, namely a timer for League of Legends.
League of Legends is a computer game, also if the topic is not entirely matching to this blog, players of the game and also others are welcome to continue reading.
First something general about this game, also called LoL: It is inspired by the Warcraft III Mod Defence of the Ancients and is now an autonomous game.
The goal is, to fight one's way with a hero to the base of the opponents. On the map some neutral creeps are placed, which are revived some time after killing. Some players now use for imporant creeps a timer, which tells them, when they revive.

First I want to present you the functions of this in C# written timer: By pressing NumPad0 - 5 the timers of the single monsters are activated, the numbers represent: Baron, Dragon, Blue, Red, enemy Blue, enemy Red. The time till their spawn is then displayed on the form, additionally accoustic alarms sound 30 and 60 seconds before.

A in my opinion pretty cool feature is the possibility of the timer, to synchronize only with others. The idea is the following: All members of the team have a timer running and the one killing the creeps (or someone, who sees it), presses the corresponding key. Then all connected timers of the team members get this information, so that all get the corresponding time and warnings.

With the key NumPad9 the times of all active timers can be read out. With F2 the form is brought to the front. With F9 the "chat mode" can be enabled or disabled. If this is active, when starting a timer, the respawn time of the corresponding creep is written to the chat. For this though F10 has to be pressed when the game starts, so the program can set the null point correctly.

Now to the code: As always I want to hint here, that I made this out of fun and did not program it very neatly,  I was more interes in the idea behind it.

I require the following previous posts, since I used their contents programming the timer:

Bring Application to Front
Create Global Hotkeys
FTP Requests
Serialize Objects
Simulate Key Presses
Speech Output


Important for the synchroniation of the different clients is a global time. Similiar to this post the program therefor reads out the source code of the webpage http://www.uhrzeit.org, to get a standardized time.
On startup the user selects a channel X between 100 and 999. On the server then the files "syncX" and "timesX" are created. In the "sync" file only the global time of the last usage are written, so that they can be deleted and reused 2 hours after the game. More important is the "times" file. In this the serialized times till the respawn of the creeps is written as well as the global time, on which the file was modified.
Every 30 seconds the clients now download this file from the server. They deserialize the times (which are managed in the class LoLTimer) and substract from these times the difference of the current global time and globale time of file modification, so they convert the times till respawn to the clients' current times.
For these times always the highest is consiered, meaning who started the timer last, those time is used.
This rule is now considered when chaning the local instances of LoLTimer, if one of the current times is higher, the instance is serialized and uploaded as a new "times" file to the server.
This is the in my opinion greatest logical difficulty behind the source code, I will leave it with that and simply post the source code in the next post.

I hope you like the program for playing around, as always, I am happy about questions and suggestions. The whole program can be downloaded on this link.

No comments:

Post a Comment