ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/follow.ext
Revision: 1.16
Committed: Sun May 2 14:31:49 2010 UTC (14 years ago) by root
Branch: MAIN
Changes since 1.15: +2 -1 lines
Log Message:
fix follow

File Contents

# User Rev Content
1 root 1.1 #! perl
2    
3     # TODO: skip arena
4     # TODO: check for player leaving
5    
6     # implement a 'follow' command
7     # don't follow on damned ground
8    
9 root 1.13 our %follow;
10 root 1.1
11 root 1.13 our $CORO = cf::async {
12     $Coro::current->{desc} = "follow handler";
13 root 1.12
14 root 1.13 while () {
15     cf::wait_for_tick;
16 root 1.12
17 root 1.13 while (my ($name, $v) = each %follow) {
18     my ($target, $his, $mine) = @$v;
19     my ($who, $other) = (cf::player::find_active $name, cf::player::find_active $target);
20    
21     if ($who && $other && $other->ob->map) {
22     my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y);
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    
34     if ($map = cf::map::find $mine->[0]
35     and $map =~ /^\// # short-gap fix
36     and !grep +($_->flag (cf::FLAG_UNIQUE) || $_->type == cf::SHOP_FLOOR) && $_->flag (cf::FLAG_IS_FLOOR),
37     $map->at ($mine->[1], $mine->[2])) {
38     $who->ob->goto (@$mine);
39     } else {
40     delete $follow{$name};
41     $who->ob->message ("You can't follow $target anymore!");
42     }
43 root 1.1 } else {
44     delete $follow{$name};
45 root 1.16 $who->ob->message ("$target is gone...")
46     if $who;
47 root 1.1 }
48     }
49 root 1.13
50     Coro::schedule unless keys %follow;
51 root 1.12 }
52 root 1.13 };
53 root 1.1
54     cf::register_command follow => sub {
55     my ($who, $args) = @_;
56    
57     my $name = $who->name;
58    
59     if ($args ne "" && $name ne $args) {
60 root 1.8 if (my $other = cf::player::find_active $args) {
61 root 1.9 if ($other->ob->map == $who->map
62 root 1.1 && abs ($other->ob->x - $who->x) <= 1
63     && abs ($other->ob->y - $who->y) <= 1) {
64     $who->message ("Following player '$args', to stop, type: 'follow");
65     $other->ob->message ("$name is now following your every step...");
66     $follow{$name} = [
67     $args,
68     [$other->ob->map->path, $other->ob->x, $other->ob->y],
69     [$who->map->path, $who->x, $who->y],
70     ];
71 root 1.13 $CORO->ready;
72 root 1.1 } else {
73     $who->message ("You must stand directly beside '$args' to follow her/him");
74     delete $follow{$name};
75     }
76     } else {
77     $who->message ("Cannot follow '$args': no such player");
78     delete $follow{$name};
79     }
80     } else {
81     $who->message ("follow mode off");
82     delete $follow{$name};
83     }
84     };
85    
86 root 1.3 cf::player->attach (
87 root 1.1 on_death => sub {
88     my ($pl) = @_;
89    
90     my $name = $pl->ob->name;
91    
92     delete $follow{$name};
93    
94     while (my ($k, $v) = each %follow) {
95     if ($v->[0] eq $name) {
96     delete $follow{$k};
97     }
98     }
99     },
100 root 1.3 );
101 root 1.1
102    
103    
104