#! perl use List::Util; sub on_move { my ($event, $who) = @_; my ($x1, $y1) = ($who->x, $who->y); # on first call (there is no initialiser callback), initialise my $self = $who->{map_grid_move} ||= do { my %opt = split /(?:\s+|=)/, $event->options; for my $ob ($who->inv) { my $num = $opt{"num_" . $ob->name} || 1; for (1 .. $num) { my $ob = $ob->clone (0); $who->map->insert_object ($ob, $x1 + rand $opt{width}, $y1 + rand $opt{height}); push @{ $opt{ob} }, $ob; } } \%opt }; my ($x2, $y2) = ($x1 + $self->{width} - 1, $y1 + $self->{height} - 1); for my $ob (@{$self->{ob}}) { my ($x, $y) = ($ob->x, $ob->y); if (0.5 <= rand) { $x += 1 - int rand 3; } else { $y += 1 - int rand 3; } $x = List::Util::max $x1, List::Util::min $x2, $x; $y = List::Util::max $y1, List::Util::min $y2, $y; $ob->remove; $ob->insert_ob_in_map_at ($ob->map, undef, cf::INS_ABOVE_FLOOR_ONLY, $x, $y); } 1 }