ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/follow.ext
(Generate patch)

Comparing deliantra/server/ext/follow.ext (file contents):
Revision 1.12 by root, Mon Oct 8 14:32:44 2007 UTC vs.
Revision 1.13 by root, Thu Oct 11 00:34:31 2007 UTC

4# TODO: check for player leaving 4# TODO: check for player leaving
5 5
6# implement a 'follow' command 6# implement a 'follow' command
7# don't follow on damned ground 7# don't follow on damned ground
8 8
9my %follow; 9our %follow;
10 10
11my $timer = Event->timer (interval => 0.2, parked => 1, data => cf::WF_AUTOCANCEL, cb => sub { 11our $CORO = cf::async {
12 while (my ($name, $v) = each %follow) { 12 $Coro::current->{desc} = "follow handler";
13 my ($target, $his, $mine) = @$v;
14 my ($who, $other) = (cf::player::find_active $name, cf::player::find_active $target);
15 13
16 if ($who && $other && $other->ob->map) { 14 while () {
17 my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y); 15 cf::wait_for_tick;
18 16
19 if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) { 17 while (my ($name, $v) = each %follow) {
20 @$mine = @$his; 18 my ($target, $his, $mine) = @$v;
21 @$his = ($map, $x, $y); 19 my ($who, $other) = (cf::player::find_active $name, cf::player::find_active $target);
22 }
23 20
24 my $map; 21 if ($who && $other && $other->ob->map) {
22 my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y);
25 23
24 if (
25 ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2])
26 && $map !~ /^\{/
27 ) {
28 @$mine = @$his;
29 @$his = ($map, $x, $y);
30 }
31
32 my $map;
33
26 if ($map = cf::map::find $mine->[0] 34 if ($map = cf::map::find $mine->[0]
27 and $map =~ /^\// # short-gap fix 35 and $map =~ /^\// # short-gap fix
28 and !grep +($_->flag (cf::FLAG_UNIQUE) || $_->type == cf::SHOP_FLOOR) && $_->flag (cf::FLAG_IS_FLOOR), 36 and !grep +($_->flag (cf::FLAG_UNIQUE) || $_->type == cf::SHOP_FLOOR) && $_->flag (cf::FLAG_IS_FLOOR),
29 $map->at ($mine->[1], $mine->[2])) { 37 $map->at ($mine->[1], $mine->[2])) {
30 $who->ob->goto (@$mine); 38 $who->ob->goto (@$mine);
39 } else {
40 delete $follow{$name};
41 $who->ob->message ("You can't follow $target anymore!");
42 }
31 } else { 43 } else {
32 delete $follow{$name}; 44 delete $follow{$name};
33 $who->ob->message ("You can't follow $target anymore!"); 45 $who->ob->message ("$target is gone...");
34 } 46 }
35 } else {
36 delete $follow{$name};
37 $who->ob->message ("$target is gone...");
38 } 47 }
48
49 Coro::schedule unless keys %follow;
39 } 50 }
40
41 $_[0]->w->stop unless keys %follow;
42}); 51};
43 52
44cf::register_command follow => sub { 53cf::register_command follow => sub {
45 my ($who, $args) = @_; 54 my ($who, $args) = @_;
46 55
47 my $name = $who->name; 56 my $name = $who->name;
56 $follow{$name} = [ 65 $follow{$name} = [
57 $args, 66 $args,
58 [$other->ob->map->path, $other->ob->x, $other->ob->y], 67 [$other->ob->map->path, $other->ob->x, $other->ob->y],
59 [$who->map->path, $who->x, $who->y], 68 [$who->map->path, $who->x, $who->y],
60 ]; 69 ];
61 $timer->start; 70 $CORO->ready;
62 } else { 71 } else {
63 $who->message ("You must stand directly beside '$args' to follow her/him"); 72 $who->message ("You must stand directly beside '$args' to follow her/him");
64 delete $follow{$name}; 73 delete $follow{$name};
65 } 74 }
66 } else { 75 } else {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines