ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/follow.ext
Revision: 1.12
Committed: Mon Oct 8 14:32:44 2007 UTC (16 years, 7 months ago) by root
Branch: MAIN
Changes since 1.11: +24 -26 lines
Log Message:
no sync job in follow please :)

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