ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/follow.ext
Revision: 1.15
Committed: Thu Apr 29 07:52:01 2010 UTC (14 years, 1 month ago) by root
Branch: MAIN
Changes since 1.14: +0 -3 lines
Log Message:
logging

File Contents

# Content
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 our %follow;
10
11 our $CORO = cf::async {
12 $Coro::current->{desc} = "follow handler";
13
14 while () {
15 cf::wait_for_tick;
16
17 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 } else {
44 delete $follow{$name};
45 $who->ob->message ("$target is gone...");
46 }
47 }
48
49 Coro::schedule unless keys %follow;
50 }
51 };
52
53 cf::register_command follow => sub {
54 my ($who, $args) = @_;
55
56 my $name = $who->name;
57
58 if ($args ne "" && $name ne $args) {
59 if (my $other = cf::player::find_active $args) {
60 if ($other->ob->map == $who->map
61 && abs ($other->ob->x - $who->x) <= 1
62 && abs ($other->ob->y - $who->y) <= 1) {
63 $who->message ("Following player '$args', to stop, type: 'follow");
64 $other->ob->message ("$name is now following your every step...");
65 $follow{$name} = [
66 $args,
67 [$other->ob->map->path, $other->ob->x, $other->ob->y],
68 [$who->map->path, $who->x, $who->y],
69 ];
70 $CORO->ready;
71 } else {
72 $who->message ("You must stand directly beside '$args' to follow her/him");
73 delete $follow{$name};
74 }
75 } else {
76 $who->message ("Cannot follow '$args': no such player");
77 delete $follow{$name};
78 }
79 } else {
80 $who->message ("follow mode off");
81 delete $follow{$name};
82 }
83 };
84
85 cf::player->attach (
86 on_death => sub {
87 my ($pl) = @_;
88
89 my $name = $pl->ob->name;
90
91 delete $follow{$name};
92
93 while (my ($k, $v) = each %follow) {
94 if ($v->[0] eq $name) {
95 delete $follow{$k};
96 }
97 }
98 },
99 );
100
101
102
103