| 1 |
root |
1.1 |
#! perl |
| 2 |
|
|
#CONVERSION: NONE |
| 3 |
|
|
|
| 4 |
|
|
use List::Util; |
| 5 |
|
|
|
| 6 |
|
|
sub on_move { |
| 7 |
|
|
my ($event, $who) = @_; |
| 8 |
|
|
|
| 9 |
|
|
my ($x1, $y1) = ($who->x, $who->y); |
| 10 |
|
|
|
| 11 |
|
|
# on first call (there is no initialiser callback), initialise |
| 12 |
|
|
my $self = $who->{map_grid_move} ||= do { |
| 13 |
|
|
my %opt = split /(?:\s+|=)/, $event->options; |
| 14 |
|
|
|
| 15 |
|
|
for my $ob ($who->inv) { |
| 16 |
|
|
my $num = $opt{"num_" . $ob->name} || 1; |
| 17 |
|
|
|
| 18 |
|
|
for (1 .. $num) { |
| 19 |
|
|
my $ob = $ob->clone (0); |
| 20 |
|
|
|
| 21 |
|
|
$who->map->insert_object ($ob, $x1 + rand $opt{width}, $y1 + rand $opt{height}); |
| 22 |
|
|
|
| 23 |
|
|
push @{ $opt{ob} }, $ob; |
| 24 |
|
|
} |
| 25 |
|
|
} |
| 26 |
|
|
|
| 27 |
|
|
\%opt |
| 28 |
|
|
}; |
| 29 |
|
|
|
| 30 |
|
|
my ($x2, $y2) = ($x1 + $self->{width} - 1, $y1 + $self->{height} - 1); |
| 31 |
|
|
|
| 32 |
|
|
for my $ob (@{$self->{ob}}) { |
| 33 |
|
|
my ($x, $y) = ($ob->x, $ob->y); |
| 34 |
|
|
|
| 35 |
|
|
if (0.5 <= rand) { |
| 36 |
|
|
$x += 1 - int rand 3; |
| 37 |
|
|
} else { |
| 38 |
|
|
$y += 1 - int rand 3; |
| 39 |
|
|
} |
| 40 |
|
|
|
| 41 |
|
|
$x = List::Util::max $x1, List::Util::min $x2, $x; |
| 42 |
|
|
$y = List::Util::max $y1, List::Util::min $y2, $y; |
| 43 |
|
|
|
| 44 |
|
|
$ob->remove; |
| 45 |
|
|
$ob->insert_ob_in_map_at ($ob->map, undef, cf::INS_ABOVE_FLOOR_ONLY, $x, $y); |
| 46 |
|
|
} |
| 47 |
|
|
|
| 48 |
|
|
1 |
| 49 |
|
|
} |
| 50 |
|
|
|
| 51 |
|
|
|
| 52 |
|
|
|