ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/map-grid-move-random.ext
Revision: 1.4
Committed: Fri Dec 15 19:11:46 2006 UTC (17 years, 4 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +0 -0 lines
State: FILE REMOVED
Log Message:
move .ext to server

File Contents

# Content
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