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.10 by root, Mon Oct 8 13:58:07 2007 UTC vs.
Revision 1.15 by root, Thu Apr 29 07:52:01 2010 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 cf::sync_job { 12 $Coro::current->{desc} = "follow handler";
13
14 while () {
15 cf::wait_for_tick;
16
13 while (my ($name, $v) = each %follow) { 17 while (my ($name, $v) = each %follow) {
14 my ($target, $his, $mine) = @$v; 18 my ($target, $his, $mine) = @$v;
15 my ($who, $other) = (cf::player::find_active $name, cf::player::find_active $target); 19 my ($who, $other) = (cf::player::find_active $name, cf::player::find_active $target);
16 20
17 if ($who && $other && $other->ob->map) { 21 if ($who && $other && $other->ob->map) {
18 my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y); 22 my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y);
19 23
24 if (
20 if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) { 25 ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2])
26 && $map !~ /^\{/
27 ) {
21 @$mine = @$his; 28 @$mine = @$his;
22 @$his = ($map, $x, $y); 29 @$his = ($map, $x, $y);
23 } 30 }
24 31
25 my $map; 32 my $map;
26 33
27 if ($map = cf::map::find $mine->[0] 34 if ($map = cf::map::find $mine->[0]
28 and $map =~ /^\// # short-gap fix 35 and $map =~ /^\// # short-gap fix
29 and !grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR), 36 and !grep +($_->flag (cf::FLAG_UNIQUE) || $_->type == cf::SHOP_FLOOR) && $_->flag (cf::FLAG_IS_FLOOR),
30 $map->at ($mine->[1], $mine->[2])) { 37 $map->at ($mine->[1], $mine->[2])) {
31 $who->ob->goto (@$mine); 38 $who->ob->goto (@$mine);
32 } else { 39 } else {
33 delete $follow{$name}; 40 delete $follow{$name};
34 $who->ob->message ("You can't follow $target anymore!"); 41 $who->ob->message ("You can't follow $target anymore!");
36 } else { 43 } else {
37 delete $follow{$name}; 44 delete $follow{$name};
38 $who->ob->message ("$target is gone..."); 45 $who->ob->message ("$target is gone...");
39 } 46 }
40 } 47 }
41 };
42 48
43 $_[0]->w->stop unless keys %follow; 49 Coro::schedule unless keys %follow;
50 }
44}); 51};
45 52
46cf::register_command follow => sub { 53cf::register_command follow => sub {
47 my ($who, $args) = @_; 54 my ($who, $args) = @_;
48 55
49 my $name = $who->name; 56 my $name = $who->name;
58 $follow{$name} = [ 65 $follow{$name} = [
59 $args, 66 $args,
60 [$other->ob->map->path, $other->ob->x, $other->ob->y], 67 [$other->ob->map->path, $other->ob->x, $other->ob->y],
61 [$who->map->path, $who->x, $who->y], 68 [$who->map->path, $who->x, $who->y],
62 ]; 69 ];
63 $timer->start; 70 $CORO->ready;
64 } else { 71 } else {
65 $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");
66 delete $follow{$name}; 73 delete $follow{$name};
67 } 74 }
68 } else { 75 } else {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines