… | |
… | |
11 | my ($who, $args) = @_; |
11 | my ($who, $args) = @_; |
12 | |
12 | |
13 | my $name = $who->name; |
13 | my $name = $who->name; |
14 | |
14 | |
15 | if ($args ne "" && $name ne $args) { |
15 | if ($args ne "" && $name ne $args) { |
16 | if (cf::player::find $args) { |
16 | if (my $other = cf::player::find $args) { |
|
|
17 | if ($other->ob->map->path eq $who->map->path |
|
|
18 | && abs ($other->ob->x - $who->x) <= 1 |
|
|
19 | && abs ($other->ob->y - $who->y) <= 1) { |
17 | $who->message ("following player '$args', to stop, type: 'follow"); |
20 | $who->message ("Following player '$args', to stop, type: 'follow"); |
18 | $follow{$name} = $args; |
21 | $follow{$name} = [ |
|
|
22 | $args, |
|
|
23 | [$other->ob->map->path, $other->ob->x, $other->ob->y], |
|
|
24 | [$who->map->path, $who->x, $who->y], |
|
|
25 | ]; |
|
|
26 | } else { |
|
|
27 | $who->message ("You must stand directly beside '$args' to follow her/him"); |
|
|
28 | delete $follow{$name}; |
|
|
29 | } |
19 | } else { |
30 | } else { |
20 | $who->message ("cannot follow '$args': no such player"); |
31 | $who->message ("Cannot follow '$args': no such player"); |
|
|
32 | delete $follow{$name}; |
21 | } |
33 | } |
22 | } else { |
34 | } else { |
23 | $who->message ("follow mode off"); |
35 | $who->message ("follow mode off"); |
24 | delete $follow{$name}; |
36 | delete $follow{$name}; |
25 | } |
37 | } |
26 | }; |
38 | }; |
27 | |
39 | |
28 | sub teleport { |
40 | sub teleport { |
29 | my ($pl, $map, $x, $y) = @_; |
41 | my ($pl, $map, $x, $y) = @_; |
30 | |
42 | |
|
|
43 | return if $pl->ob->map->path eq $map |
|
|
44 | && abs ($pl->ob->x - $x) <= 1 |
|
|
45 | && abs ($pl->ob->y - $y) <= 1; |
|
|
46 | |
31 | my $portal = cf::object::new ("exit"); |
47 | my $portal = cf::object::new ("exit"); |
32 | |
48 | |
33 | $portal->set_slaying ($map->path); |
49 | $portal->set_slaying ($map); |
34 | $portal->set_hp ($x); |
50 | $portal->set_hp ($x); |
35 | $portal->set_sp ($y); |
51 | $portal->set_sp ($y); |
36 | |
52 | |
37 | $portal->apply ($pl->ob, 0); |
53 | $portal->apply ($pl->ob, 0); |
38 | |
54 | |
… | |
… | |
42 | sub on_clock { |
58 | sub on_clock { |
43 | my ($event) = @_; |
59 | my ($event) = @_; |
44 | |
60 | |
45 | return unless %follow; |
61 | return unless %follow; |
46 | |
62 | |
47 | while (my ($name, $target) = each %follow) { |
63 | while (my ($name, $v) = each %follow) { |
|
|
64 | my ($target, $his, $mine) = @$v; |
48 | my ($who, $other) = (cf::player::find $name, cf::player::find $target); |
65 | my ($who, $other) = (cf::player::find $name, cf::player::find $target); |
|
|
66 | |
49 | if ($who && $other) { |
67 | if ($who && $other) { |
50 | teleport $who, $other->ob->map, $other->ob->x, $other->ob->y |
68 | my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y); |
51 | if $who->ob->map->path ne $other->ob->map->path; |
69 | |
|
|
70 | if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) { |
|
|
71 | @$mine = @$his; |
|
|
72 | @$his = ($map, $x, $y); |
|
|
73 | } |
|
|
74 | |
|
|
75 | my $map; |
|
|
76 | |
|
|
77 | if ($map = cf::map::map $mine->[0] |
|
|
78 | and !grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR), |
|
|
79 | $map->at ($mine->[1], $mine->[2])) { |
|
|
80 | teleport $who, @$mine; |
|
|
81 | } else { |
|
|
82 | delete $follow{$name}; |
|
|
83 | $who->ob->message ("$target is gone where you can't follow..."); |
|
|
84 | } |
52 | } else { |
85 | } else { |
53 | warn "follow: $name or $target is gone, removing from follow list\n"; |
|
|
54 | delete $follow{$name}; |
86 | delete $follow{$name}; |
|
|
87 | $who->ob->message ("$name or $target is gone..."); |
55 | } |
88 | } |
56 | } |
89 | } |
57 | } |
90 | } |
58 | |
91 | |
59 | |
92 | |