… | |
… | |
2 | |
2 | |
3 | # TODO: skip arena |
3 | # TODO: skip arena |
4 | # TODO: check for player leaving |
4 | # TODO: check for player leaving |
5 | |
5 | |
6 | # implement a 'follow' command |
6 | # implement a 'follow' command |
|
|
7 | # don't follow on damned ground |
7 | |
8 | |
8 | my %follow; |
9 | my %follow; |
9 | |
10 | |
10 | cf::register_command follow => 0, sub { |
11 | cf::register_command follow => 0, sub { |
11 | my ($who, $args) = @_; |
12 | my ($who, $args) = @_; |
… | |
… | |
43 | |
44 | |
44 | return if $pl->ob->map->path eq $map |
45 | return if $pl->ob->map->path eq $map |
45 | && abs ($pl->ob->x - $x) <= 1 |
46 | && abs ($pl->ob->x - $x) <= 1 |
46 | && abs ($pl->ob->y - $y) <= 1; |
47 | && abs ($pl->ob->y - $y) <= 1; |
47 | |
48 | |
48 | my $portal = cf::object::new ("exit"); |
49 | my $portal = cf::object::new "exit"; |
49 | |
50 | |
50 | $portal->set_slaying ($map); |
51 | $portal->set_slaying ($map); |
51 | $portal->set_hp ($x); |
52 | $portal->set_hp ($x); |
52 | $portal->set_sp ($y); |
53 | $portal->set_sp ($y); |
53 | |
54 | |
54 | $portal->apply ($pl->ob, 0); |
55 | $portal->apply ($pl->ob); |
55 | |
56 | |
56 | $portal->free; |
57 | $portal->free; |
57 | } |
58 | } |
58 | |
59 | |
|
|
60 | sub on_player_death { |
|
|
61 | my ($ob) = @_; |
|
|
62 | |
|
|
63 | my $name = $ob->name; |
|
|
64 | |
|
|
65 | delete $follow{$name}; |
|
|
66 | |
|
|
67 | while (my ($k, $v) = each %follow) { |
|
|
68 | if ($v->[0] eq $name) { |
|
|
69 | delete $follow{$k}; |
|
|
70 | } |
|
|
71 | } |
|
|
72 | |
|
|
73 | 0 |
|
|
74 | } |
|
|
75 | |
59 | sub on_clock { |
76 | sub on_clock { |
60 | my ($event) = @_; |
|
|
61 | |
|
|
62 | return unless %follow; |
77 | return 0 unless %follow; |
63 | |
78 | |
64 | while (my ($name, $v) = each %follow) { |
79 | while (my ($name, $v) = each %follow) { |
65 | my ($target, $his, $mine) = @$v; |
80 | my ($target, $his, $mine) = @$v; |
66 | my ($who, $other) = (cf::player::find $name, cf::player::find $target); |
81 | my ($who, $other) = (cf::player::find $name, cf::player::find $target); |
67 | |
82 | |