1 | #! perl |
1 | #! perl |
|
|
2 | |
|
|
3 | # TODO: skip arena |
|
|
4 | # TODO: check for player leaving |
2 | |
5 | |
3 | # implement a 'follow' command |
6 | # implement a 'follow' command |
4 | |
7 | |
5 | my %follow; |
8 | my %follow; |
6 | |
9 | |
… | |
… | |
20 | $who->message ("follow mode off"); |
23 | $who->message ("follow mode off"); |
21 | delete $follow{$name}; |
24 | delete $follow{$name}; |
22 | } |
25 | } |
23 | }; |
26 | }; |
24 | |
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 | |
25 | sub on_clock { |
42 | sub on_clock { |
26 | my ($event) = @_; |
43 | my ($event) = @_; |
27 | |
44 | |
28 | return unless %follow; |
45 | return unless %follow; |
29 | |
46 | |
30 | while (my ($name, $target) = each %follow) { |
47 | while (my ($name, $target) = each %follow) { |
31 | my ($who, $other) = (cf::player::find $name, cf::player::find $target); |
48 | my ($who, $other) = (cf::player::find $name, cf::player::find $target); |
32 | if ($who && $other) { |
49 | if ($who && $other) { |
33 | $who->ob->teleport ($other->ob->map, $other->ob->x, $other->ob->y); |
50 | teleport $who, $other->ob->map, $other->ob->x, $other->ob->y |
|
|
51 | if $who->ob->map->path ne $other->ob->map->path; |
34 | } else { |
52 | } else { |
35 | warn "follow: $name or $target is gone, removing from follow list\n"; |
53 | warn "follow: $name or $target is gone, removing from follow list\n"; |
36 | delete $follow{$name}; |
54 | delete $follow{$name}; |
37 | } |
55 | } |
38 | } |
56 | } |