ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/follow.ext
Revision: 1.14
Committed: Fri Jul 11 21:41:38 2008 UTC (15 years, 10 months ago) by root
Branch: MAIN
CVS Tags: rel-2_82, rel-2_81, rel-2_80, rel-2_6, rel-2_7, rel-2_72, rel-2_73, rel-2_71, rel-2_76, rel-2_77, rel-2_74, rel-2_75, rel-2_79, rel-2_90, rel-2_92, rel-2_93, rel-2_78, rel-2_61
Changes since 1.13: +3 -0 lines
Log Message:
*** empty log message ***

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.14 while () { eval {#d#
15    
16 root 1.13 while () {
17     cf::wait_for_tick;
18 root 1.12
19 root 1.13 while (my ($name, $v) = each %follow) {
20     my ($target, $his, $mine) = @$v;
21     my ($who, $other) = (cf::player::find_active $name, cf::player::find_active $target);
22    
23     if ($who && $other && $other->ob->map) {
24     my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y);
25    
26     if (
27     ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2])
28     && $map !~ /^\{/
29     ) {
30     @$mine = @$his;
31     @$his = ($map, $x, $y);
32     }
33    
34     my $map;
35    
36     if ($map = cf::map::find $mine->[0]
37     and $map =~ /^\// # short-gap fix
38     and !grep +($_->flag (cf::FLAG_UNIQUE) || $_->type == cf::SHOP_FLOOR) && $_->flag (cf::FLAG_IS_FLOOR),
39     $map->at ($mine->[1], $mine->[2])) {
40     $who->ob->goto (@$mine);
41     } else {
42     delete $follow{$name};
43     $who->ob->message ("You can't follow $target anymore!");
44     }
45 root 1.1 } else {
46     delete $follow{$name};
47 root 1.13 $who->ob->message ("$target is gone...");
48 root 1.1 }
49     }
50 root 1.13
51     Coro::schedule unless keys %follow;
52 root 1.12 }
53 root 1.14 }; warn "follow handler died <$@>\n"; }#d#
54 root 1.13 };
55 root 1.1
56     cf::register_command follow => sub {
57     my ($who, $args) = @_;
58    
59     my $name = $who->name;
60    
61     if ($args ne "" && $name ne $args) {
62 root 1.8 if (my $other = cf::player::find_active $args) {
63 root 1.9 if ($other->ob->map == $who->map
64 root 1.1 && abs ($other->ob->x - $who->x) <= 1
65     && abs ($other->ob->y - $who->y) <= 1) {
66     $who->message ("Following player '$args', to stop, type: 'follow");
67     $other->ob->message ("$name is now following your every step...");
68     $follow{$name} = [
69     $args,
70     [$other->ob->map->path, $other->ob->x, $other->ob->y],
71     [$who->map->path, $who->x, $who->y],
72     ];
73 root 1.13 $CORO->ready;
74 root 1.1 } else {
75     $who->message ("You must stand directly beside '$args' to follow her/him");
76     delete $follow{$name};
77     }
78     } else {
79     $who->message ("Cannot follow '$args': no such player");
80     delete $follow{$name};
81     }
82     } else {
83     $who->message ("follow mode off");
84     delete $follow{$name};
85     }
86     };
87    
88 root 1.3 cf::player->attach (
89 root 1.1 on_death => sub {
90     my ($pl) = @_;
91    
92     my $name = $pl->ob->name;
93    
94     delete $follow{$name};
95    
96     while (my ($k, $v) = each %follow) {
97     if ($v->[0] eq $name) {
98     delete $follow{$k};
99     }
100     }
101     },
102 root 1.3 );
103 root 1.1
104    
105    
106