📜 ⬆️ ⬇️

Simple trading bot for The Settlers Online

Long ago, back in the days when MsDOS lived on personal computers, it was possible to play Settlers II. The game touched me, and I gladly spent a few days alone with her. Much later he passed it again, and then again, and each time despite the antiquity of this game, he spent time playing it with pleasure. Not so long ago I saw an advertisement for the online game The Settlers Online and succumbed to the nostalgia registered in it. The first impression was a delight, so everything was like my favorite Settlers II. But the rainbow euphoria quickly passed. I will not talk about all the pros and cons in this article, I’ll tell you only about one minus - trade. You can read more about the game in the article The Settlers: Now Online .

Cause


Trading in the game is implemented in such a way that it requires constant presence. Any trading lot is set for only 10 minutes, and then becomes unavailable to other players. As a result, in order for the trade to bring any tangible profit at all it is necessary to spend more than one hour in the trade interface.

The investigation


So the idea was born to write a bot that will exhibit the lot automatically.

We write bot


Since Linux is installed on my desktop, the Perl programming language and the xdotool mouse cursor control utility were selected as development tools.
')
And so begin.
The bot will consist of 2 files:


Let's start with the trade.guns.pl file. This file contains a list of HASH (named) arrays containing the coordinates of the buttons that need to be pressed to set a lot, and other additional information.
( { x=>'288', y=>'852'}, #  [].      { x=>'790', y=>'667'}, #  [].    . { x=>'1126', y=>'658'}, #  [].    . { x=>'871', y=>'594'}, #  [].    . { #       . #     100  . #    400 . x=>'983', y=>'742', #   . dx=>'874', dy=>'750', #   . #  99 . inc=>{ #   : x=>'1010', y=>'745', #       1. inc=>'1', #     . rnd=>'0', #   0     0  rnd   inc. timer => [ #        . { sh=>0, eh=>24, inc=>0 } #      0   . ] } }, { x=>'1064', y=>'733', rx=>'20', ry=>'10'}, #  [].     . { x=>'1131', y=>'668', rx=>'10', ry=>'2'}, #  [].    . #          #   . { x=>'1016', y=>'548', rx=>'20', ry=>'10'}, #  [].    . { #       . #     20   + 0, 2, 4  8   #    +   0  15 . #    400 . x=>'988', y=>'743', #   . dx=>'804', dy=>'746', #   . #  1 . inc=>{ #   : x=>'1010', y=>'745', #       1. inc=>'19', #     . rnd=>'15', #   0     0  rnd   inc. timer => [ #        . #    -       . { sh=>0, eh=>24, inc=>0 },# 0   . { sh=>0, eh=>8, inc=>8 },# +8 c 00.00  08.00. { sh=>8, eh=>9, inc=>4 },# +4 c 08.00  09.00. { sh=>9, eh=>10, inc=>2 } # +2 c 09.00  10.00. ] } }, { x=>'1083', y=>'736', rx=>'20', ry=>'10' }, #  [].     . { x=>'961', y=>'596', rx=>'14', ry=>'12' } #  [].    . ); 


In a more detailed description in addition to what is given in the comments, this file does not need. Therefore, let's proceed to the consideration of simple.trade.bot.pl . This is the bot itself.

 #!/usr/bin/perl #      20               sleep 20; #         my @g_trade = do "trade.guns.pl"; #    .  . #          [Ctrl]+c. while(){ #         . print "NEXT TRADE\n"; #          . for my $l_cur ( @g_trade ){ sleep(1); if( defined $l_cur->{dx} ){ #       dx    -   #   . #     ($l_count). #      . my $l_count=$l_cur->{inc}{inc}; #   .   №2 - . my @l_curtime=localtime(time); #     x, y  . move($l_cur); #        . my $l_inc=0; #       . for my $l_timer ( @{$l_cur->{inc}{timer}} ){ #       ,  . $l_inc=$l_timer->{inc} if $l_curtime[2] >= $l_timer->{sh} && $l_curtime[2] <= $l_timer->{eh}; } #      . my $l_rnd=int(rand($l_cur->{inc}{rnd})); #       . $l_count+=$l_inc; $l_count+=$l_rnd; #              . print "\tSET: [$l_count] [$l_cur->{inc}{inc} + $l_up + $l_rnd\($l_cur->{inc}{rnd})]\n"; #      . while ($l_count){ $l_count--; clicktoxy($l_cur->{inc}); usleep(80); } }else{ #   dx   -           . clicktoxy($l_cur); } } #  .  11  +   0  4  (        ). my $l_time=11+int(rand(4)); my $count=0; #           . for($count=0;$count<$l_time;$count++){ sleep 60; mousemove(400,500); sleep 1; mousemove(1400,500); sleep 1; } #       0  60 sleep(int(rand(60))); #         } sub usleep{ #      (   Ms Windows). my $l_ptr=shift; $l_ptr*=1000; `usleep $l_ptr`; } sub move{ #             . my $l_coord=shift; mousemove($l_coord->{x},$l_coord->{y}); mousedown(1); usleep(600); mousemove($l_coord->{dx},$l_coord->{dy}); mouseup(1); } sub click{ #        . mousedown(1); mouseup(1); } sub clicktoxy{ #    ,         #    . my $l_coord=shift; mousemove($l_coord->{x},$l_coord->{y}); mousedown(1); mouseup(1); usleep(300); } sub mousedown{ #     xdotool    . #  : # 1 -    () # 2 -    () my $l_key = shift; if( $l_key ){ `xdotool mousedown $l_key`; } } sub mouseup{ #     xdotool    . #  : # 1 -    () # 2 -    () my $l_key = shift; if( $l_key ){ `xdotool mouseup $l_key`; } } sub mousemove{ #     xdotool      x, y. my $l_x = shift; my $l_y = shift; my $l_com='xdotool mousemove'; $l_com.=" $l_x $l_y"; `$l_com`; } 


The bot is ready.

In conclusion


This bot is very simple. He still does not have many of the necessary features. Here is a short list of ideas how to make the bot more perfect:


Should be considered


Source: https://habr.com/ru/post/145842/


All Articles