ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/map-grid-move-random.ext
Revision: 1.5
Committed: Tue May 4 21:45:42 2010 UTC (14 years ago) by root
Branch: MAIN
CVS Tags: rel-3_1, rel-3_0, HEAD
Changes since 1.4: +0 -2 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
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 root 1.4 $who->map->insert ($ob, ($x1 + cf::rndm $opt{width}), ($y1 + cf::rndm $opt{height}));
22 root 1.1
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 root 1.3 if (0.5 <= cf::rndm) {
36     $x += 1 - cf::rndm 3;
37 root 1.1 } else {
38 root 1.3 $y += 1 - cf::rndm 3;
39 root 1.1 }
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