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