… | |
… | |
7 | # don't follow on damned ground |
7 | # don't follow on damned ground |
8 | |
8 | |
9 | my %follow; |
9 | my %follow; |
10 | |
10 | |
11 | my $timer = Event->timer (interval => 0.2, parked => 1, data => cf::WF_AUTOCANCEL, cb => sub { |
11 | my $timer = Event->timer (interval => 0.2, parked => 1, data => cf::WF_AUTOCANCEL, cb => sub { |
12 | cf::sync_job { |
|
|
13 | while (my ($name, $v) = each %follow) { |
12 | while (my ($name, $v) = each %follow) { |
14 | my ($target, $his, $mine) = @$v; |
13 | my ($target, $his, $mine) = @$v; |
15 | my ($who, $other) = (cf::player::find $name, cf::player::find $target); |
14 | my ($who, $other) = (cf::player::find_active $name, cf::player::find_active $target); |
16 | |
15 | |
17 | if ($who && $other && $other->ob->map) { |
16 | if ($who && $other && $other->ob->map) { |
18 | my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y); |
17 | my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y); |
19 | |
18 | |
20 | if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) { |
19 | if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) { |
21 | @$mine = @$his; |
20 | @$mine = @$his; |
22 | @$his = ($map, $x, $y); |
21 | @$his = ($map, $x, $y); |
23 | } |
22 | } |
24 | |
23 | |
25 | my $map; |
24 | my $map; |
26 | |
25 | |
27 | if ($map = cf::map::find $mine->[0] |
26 | if ($map = cf::map::find $mine->[0] |
|
|
27 | and $map =~ /^\// # short-gap fix |
28 | and !grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR), |
28 | and !grep +($_->flag (cf::FLAG_UNIQUE) || $_->type == cf::SHOP_FLOOR) && $_->flag (cf::FLAG_IS_FLOOR), |
29 | $map->at ($mine->[1], $mine->[2])) { |
29 | $map->at ($mine->[1], $mine->[2])) { |
30 | $who->ob->goto (@$mine); |
30 | $who->ob->goto (@$mine); |
31 | } else { |
|
|
32 | delete $follow{$name}; |
|
|
33 | $who->ob->message ("You can't follow $target anymore!"); |
|
|
34 | } |
|
|
35 | } else { |
31 | } else { |
36 | delete $follow{$name}; |
32 | delete $follow{$name}; |
37 | $who->ob->message ("$target is gone..."); |
33 | $who->ob->message ("You can't follow $target anymore!"); |
38 | } |
34 | } |
|
|
35 | } else { |
|
|
36 | delete $follow{$name}; |
|
|
37 | $who->ob->message ("$target is gone..."); |
39 | } |
38 | } |
40 | }; |
39 | } |
41 | |
40 | |
42 | $_[0]->w->stop unless keys %follow; |
41 | $_[0]->w->stop unless keys %follow; |
43 | }); |
42 | }); |
44 | |
43 | |
45 | cf::register_command follow => sub { |
44 | cf::register_command follow => sub { |
46 | my ($who, $args) = @_; |
45 | my ($who, $args) = @_; |
47 | |
46 | |
48 | my $name = $who->name; |
47 | my $name = $who->name; |
49 | |
48 | |
50 | if ($args ne "" && $name ne $args) { |
49 | if ($args ne "" && $name ne $args) { |
51 | if (my $other = cf::player::find $args) { |
50 | if (my $other = cf::player::find_active $args) { |
52 | if ($other->ob->map eq $who->map |
51 | if ($other->ob->map == $who->map |
53 | && abs ($other->ob->x - $who->x) <= 1 |
52 | && abs ($other->ob->x - $who->x) <= 1 |
54 | && abs ($other->ob->y - $who->y) <= 1) { |
53 | && abs ($other->ob->y - $who->y) <= 1) { |
55 | $who->message ("Following player '$args', to stop, type: 'follow"); |
54 | $who->message ("Following player '$args', to stop, type: 'follow"); |
56 | $other->ob->message ("$name is now following your every step..."); |
55 | $other->ob->message ("$name is now following your every step..."); |
57 | $follow{$name} = [ |
56 | $follow{$name} = [ |