1 |
#! perl |
2 |
|
3 |
# implement a 'follow' command |
4 |
|
5 |
my %follow; |
6 |
|
7 |
cf::register_command follow => 0, sub { |
8 |
my ($who, $args) = @_; |
9 |
|
10 |
my $name = $who->name; |
11 |
|
12 |
if ($args ne "" && $name ne $args) { |
13 |
if (cf::player::find $args) { |
14 |
$who->message ("following player '$args', to stop, type: 'follow"); |
15 |
$follow{$name} = $args; |
16 |
} else { |
17 |
$who->message ("cannot follow '$args': no such player"); |
18 |
} |
19 |
} else { |
20 |
$who->message ("follow mode off"); |
21 |
delete $follow{$name}; |
22 |
} |
23 |
}; |
24 |
|
25 |
sub teleport { |
26 |
my ($pl, $map, $x, $y) = @_; |
27 |
|
28 |
my $portal = cf::object::new ("exit"); |
29 |
|
30 |
$portal->set_slaying ($map->path); |
31 |
$portal->set_hp ($x); |
32 |
$portal->set_sp ($y); |
33 |
|
34 |
$portal->apply ($pl->ob, 0); |
35 |
|
36 |
$portal->free; |
37 |
} |
38 |
|
39 |
sub on_clock { |
40 |
my ($event) = @_; |
41 |
|
42 |
return unless %follow; |
43 |
|
44 |
while (my ($name, $target) = each %follow) { |
45 |
my ($who, $other) = (cf::player::find $name, cf::player::find $target); |
46 |
if ($who && $other) { |
47 |
teleport $who, $other->ob->map, $other->ob->x, $other->ob->y |
48 |
if $who->ob->map->path ne $other->ob->map->path; |
49 |
} else { |
50 |
warn "follow: $name or $target is gone, removing from follow list\n"; |
51 |
delete $follow{$name}; |
52 |
} |
53 |
} |
54 |
} |
55 |
|
56 |
|
57 |
|
58 |
|