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.6 by root, Thu Jan 4 18:48:15 2007 UTC vs.
Revision 1.17 by root, Sun May 2 14:54:06 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 $name, cf::player::find $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
32 if (my $map = cf::map::find $mine->[0]) {
25 my $map; 33 $map->load;
26 34
27 if ($map = cf::map::find $mine->[0] 35 if ($map =~ /^\// # short-gap fix
28 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),
29 $map->at ($mine->[1], $mine->[2])) { 37 $map->at ($mine->[1], $mine->[2])
38 ) {
30 $who->ob->goto_map (@$mine); 39 $who->ob->goto (@$mine)
40 unless $who->ob->blocked ($map, $mine->[1], $mine->[2])
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!");
44 }
34 } 45 }
35 } else { 46 } else {
36 delete $follow{$name}; 47 delete $follow{$name};
37 $who->ob->message ("$target is gone..."); 48 $who->ob->message ("$target is gone...")
49 if $who;
38 } 50 }
39 } 51 }
40 };
41 52
42 $_[0]->w->stop unless keys %follow; 53 Coro::schedule unless keys %follow;
54 }
43}); 55};
44 56
45cf::register_command follow => sub { 57cf::register_command follow => sub {
46 my ($who, $args) = @_; 58 my ($who, $args) = @_;
47 59
48 my $name = $who->name; 60 my $name = $who->name;
49 61
50 if ($args ne "" && $name ne $args) { 62 if ($args ne "" && $name ne $args) {
51 if (my $other = cf::player::find $args) { 63 if (my $other = cf::player::find_active $args) {
52 if ($other->ob->map eq $who->map 64 if ($other->ob->map == $who->map
53 && abs ($other->ob->x - $who->x) <= 1 65 && abs ($other->ob->x - $who->x) <= 1
54 && abs ($other->ob->y - $who->y) <= 1) { 66 && abs ($other->ob->y - $who->y) <= 1) {
55 $who->message ("Following player '$args', to stop, type: 'follow"); 67 $who->message ("Following player '$args', to stop, type: 'follow");
56 $other->ob->message ("$name is now following your every step..."); 68 $other->ob->message ("$name is now following your every step...");
57 $follow{$name} = [ 69 $follow{$name} = [
58 $args, 70 $args,
59 [$other->ob->map->path, $other->ob->x, $other->ob->y], 71 [$other->ob->map->path, $other->ob->x, $other->ob->y],
60 [$who->map->path, $who->x, $who->y], 72 [$who->map->path, $who->x, $who->y],
61 ]; 73 ];
62 $timer->start; 74 $CORO->ready;
63 } else { 75 } else {
64 $who->message ("You must stand directly beside '$args' to follow her/him"); 76 $who->message ("You must stand directly beside '$args' to follow her/him");
65 delete $follow{$name}; 77 delete $follow{$name};
66 } 78 }
67 } else { 79 } else {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines