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.5 by root, Tue Jan 2 08:26:41 2007 UTC vs.
Revision 1.14 by root, Fri Jul 11 21:41:38 2008 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 () { eval {#d#
15
16 while () {
17 cf::wait_for_tick;
18
13 while (my ($name, $v) = each %follow) { 19 while (my ($name, $v) = each %follow) {
14 my ($target, $his, $mine) = @$v; 20 my ($target, $his, $mine) = @$v;
15 my ($who, $other) = (cf::player::find $name, cf::player::find $target); 21 my ($who, $other) = (cf::player::find_active $name, cf::player::find_active $target);
16 22
17 if ($who && $other && $other->ob->map) { 23 if ($who && $other && $other->ob->map) {
18 my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y); 24 my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y);
19 25
26 if (
20 if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) { 27 ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2])
28 && $map !~ /^\{/
29 ) {
21 @$mine = @$his; 30 @$mine = @$his;
22 @$his = ($map, $x, $y); 31 @$his = ($map, $x, $y);
23 } 32 }
24 33
25 my $map; 34 my $map;
26 35
27 if ($map = cf::map::find_map $mine->[0] 36 if ($map = cf::map::find $mine->[0]
37 and $map =~ /^\// # short-gap fix
28 and !grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR), 38 and !grep +($_->flag (cf::FLAG_UNIQUE) || $_->type == cf::SHOP_FLOOR) && $_->flag (cf::FLAG_IS_FLOOR),
29 $map->at ($mine->[1], $mine->[2])) { 39 $map->at ($mine->[1], $mine->[2])) {
30 $who->ob->goto_map (@$mine); 40 $who->ob->goto (@$mine);
31 } else { 41 } else {
32 delete $follow{$name}; 42 delete $follow{$name};
33 $who->ob->message ("You can't follow $target anymore!"); 43 $who->ob->message ("You can't follow $target anymore!");
34 } 44 }
35 } else { 45 } else {
36 delete $follow{$name}; 46 delete $follow{$name};
37 $who->ob->message ("$target is gone..."); 47 $who->ob->message ("$target is gone...");
38 } 48 }
39 } 49 }
40 };
41 50
42 $_[0]->w->stop unless keys %follow; 51 Coro::schedule unless keys %follow;
52 }
53 }; warn "follow handler died <$@>\n"; }#d#
43}); 54};
44 55
45cf::register_command follow => sub { 56cf::register_command follow => sub {
46 my ($who, $args) = @_; 57 my ($who, $args) = @_;
47 58
48 my $name = $who->name; 59 my $name = $who->name;
49 60
50 if ($args ne "" && $name ne $args) { 61 if ($args ne "" && $name ne $args) {
51 if (my $other = cf::player::find $args) { 62 if (my $other = cf::player::find_active $args) {
52 if ($other->ob->map eq $who->map 63 if ($other->ob->map == $who->map
53 && abs ($other->ob->x - $who->x) <= 1 64 && abs ($other->ob->x - $who->x) <= 1
54 && abs ($other->ob->y - $who->y) <= 1) { 65 && abs ($other->ob->y - $who->y) <= 1) {
55 $who->message ("Following player '$args', to stop, type: 'follow"); 66 $who->message ("Following player '$args', to stop, type: 'follow");
56 $other->ob->message ("$name is now following your every step..."); 67 $other->ob->message ("$name is now following your every step...");
57 $follow{$name} = [ 68 $follow{$name} = [
58 $args, 69 $args,
59 [$other->ob->map->path, $other->ob->x, $other->ob->y], 70 [$other->ob->map->path, $other->ob->x, $other->ob->y],
60 [$who->map->path, $who->x, $who->y], 71 [$who->map->path, $who->x, $who->y],
61 ]; 72 ];
62 $timer->start; 73 $CORO->ready;
63 } else { 74 } else {
64 $who->message ("You must stand directly beside '$args' to follow her/him"); 75 $who->message ("You must stand directly beside '$args' to follow her/him");
65 delete $follow{$name}; 76 delete $follow{$name};
66 } 77 }
67 } else { 78 } else {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines