Код: Выделить всё
# free выполняет команду, подставляя вместо ~ случайные координаты свободной клетки вокруг бота
do free sl 27 ~
pause 1
do warp 1
# freer подставляет последние использованные координаты
do freer move ~
- package handsFree;
- use strict;
- #########################################################################
- # handsFree OpenKore plugin v1.0 by EternalHarvest
- #########################################################################
- use Globals;
- use Log qw(message);
- use Commands;
- use constant DEFAULT_SPREAD => 7;
- my $spread = defined $::config{'handsFree_spread'} ? $::config{'handsFree_spread'} : DEFAULT_SPREAD;
- Plugins::register ('handsFree', 'Find free cell', \&unload);
- my $cmds = Commands::register (
- ["free", "Perform command at free cell", \&handsFree],
- ["freer", "Perform command on last free cell", \&handsFreeRepeat]
- );
- sub unload {
- Commands::unregister ($cmds);
- }
- my ($lastX, $lastY);
- sub handsFreeAction {
- my (@reach, @dead, $x, $y, $a, $b, $m, $n);
- my $s;
- my $count = ($spread*2+1) ** 2 - 1;
- for ($x = $char->{pos}{x}-$spread; $x <= $char->{pos}{x}+$spread; $x++) {
- for ($y = $char->{pos}{y}-$spread; $y <= $char->{pos}{y}+$spread; $y++) {
- $count -= !($reach[$x][$y] = $field->isWalkable ($x, $y));
- }
- }
- for ($m = -1; $m < 2; $m += 2) {
- for ($n = -1; $n < 2; $n += 2) {
- for ($x = 0; $x <= $spread; $x++) {
- for ($y = 0; $y <= $spread; $y++) {
- next if $dead[$char->{pos}{x} + $x*$m][$char->{pos}{y} + $y*$n] || $reach[$char->{pos}{x} + $x*$m][$char->{pos}{y} + $y*$n];
- for ($a = $x; $a <= $spread; $a++) {
- for ($b = $y; $b <= $spread; $b++) {
- $count -= $reach[$char->{pos}{x} + $a*$m][$char->{pos}{y} + $b*$n];
- $reach[$char->{pos}{x} + $a*$m][$char->{pos}{y} + $b*$n] = 0;
- $dead[$char->{pos}{x} + $a*$m][$char->{pos}{y} + $b*$n] = 1;
- }
- }
- }
- }
- }
- }
- foreach my $actor (
- @{$monstersList->getItems ()},
- @{$playersList->getItems ()},
- @{$petsList->getItems ()},
- @{$npcsList->getItems ()}
- ) {
- $count -= $reach[$actor->{pos}{x}][$actor->{pos}{y}];
- $reach[$actor->{pos}{x}][$actor->{pos}{y}] = 0;
- }
- $reach[$char->{pos}{x}][$char->{pos}{y}] = 0;
- if ($count > 0) {
- until ($reach[$x][$y]) {
- $x = $char->{pos}{x} + int (rand ($spread*2 + 1)) - $spread;
- $y = $char->{pos}{y} + int (rand ($spread*2 + 1)) - $spread;
- }
- } else {
- $x = 0; $y = 0;
- message "handsFree: no available cells!\n";
- }
- $lastX = $x; $lastY = $y;
- }
- sub handsFree {
- shift;
- my $params = shift;
- handsFreeAction ();
- if ($params && $lastX) {
- $params =~ s/~/$lastX $lastY/;
- Commands::run ($params);
- }
- }
- sub handsFreeRepeat {
- shift;
- my $params = shift;
- if ($params && $lastX) {
- $params =~ s/~/$lastX $lastY/;
- Commands::run ($params);
- }
- }
- 1;