… | |
… | |
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 | # don't follow on damned ground |
8 | |
|
|
9 | my %follow; |
|
|
10 | |
|
|
11 | cf::register_command follow => 0, sub { |
|
|
12 | my ($who, $args) = @_; |
|
|
13 | |
|
|
14 | my $name = $who->name; |
|
|
15 | |
|
|
16 | if ($args ne "" && $name ne $args) { |
|
|
17 | if (my $other = cf::player::find $args) { |
|
|
18 | if ($other->ob->map->path eq $who->map->path |
|
|
19 | && abs ($other->ob->x - $who->x) <= 1 |
|
|
20 | && abs ($other->ob->y - $who->y) <= 1) { |
|
|
21 | $who->message ("Following player '$args', to stop, type: 'follow"); |
|
|
22 | $other->ob->message ("$name is now following your every step..."); |
|
|
23 | $follow{$name} = [ |
|
|
24 | $args, |
|
|
25 | [$other->ob->map->path, $other->ob->x, $other->ob->y], |
|
|
26 | [$who->map->path, $who->x, $who->y], |
|
|
27 | ]; |
|
|
28 | } else { |
|
|
29 | $who->message ("You must stand directly beside '$args' to follow her/him"); |
|
|
30 | delete $follow{$name}; |
|
|
31 | } |
|
|
32 | } else { |
|
|
33 | $who->message ("Cannot follow '$args': no such player"); |
|
|
34 | delete $follow{$name}; |
|
|
35 | } |
|
|
36 | } else { |
|
|
37 | $who->message ("follow mode off"); |
|
|
38 | delete $follow{$name}; |
|
|
39 | } |
|
|
40 | }; |
|
|
41 | |
8 | |
42 | sub teleport { |
9 | sub teleport { |
43 | my ($pl, $map, $x, $y) = @_; |
10 | my ($pl, $map, $x, $y) = @_; |
44 | |
11 | |
45 | return if $pl->ob->map->path eq $map |
12 | return if $pl->ob->map->path eq $map |
… | |
… | |
55 | $portal->apply ($pl->ob); |
22 | $portal->apply ($pl->ob); |
56 | |
23 | |
57 | $portal->free; |
24 | $portal->free; |
58 | } |
25 | } |
59 | |
26 | |
60 | sub on_player_death { |
27 | my %follow; |
61 | my ($ob) = @_; |
|
|
62 | |
28 | |
63 | my $name = $ob->name; |
29 | my $timer = Event->timer (interval => 0.2, parked => 1, cb => sub { |
64 | |
30 | warn "follow\n";#d# |
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 | |
|
|
76 | sub on_clock { |
|
|
77 | return 0 unless %follow; |
|
|
78 | |
31 | |
79 | while (my ($name, $v) = each %follow) { |
32 | while (my ($name, $v) = each %follow) { |
80 | my ($target, $his, $mine) = @$v; |
33 | my ($target, $his, $mine) = @$v; |
81 | my ($who, $other) = (cf::player::find $name, cf::player::find $target); |
34 | my ($who, $other) = (cf::player::find $name, cf::player::find $target); |
82 | |
35 | |
… | |
… | |
102 | delete $follow{$name}; |
55 | delete $follow{$name}; |
103 | $who->ob->message ("$target is gone..."); |
56 | $who->ob->message ("$target is gone..."); |
104 | } |
57 | } |
105 | } |
58 | } |
106 | |
59 | |
|
|
60 | $_[0]->w->stop unless keys %follow; |
|
|
61 | }); |
|
|
62 | |
|
|
63 | cf::register_command follow => 0, sub { |
|
|
64 | my ($who, $args) = @_; |
|
|
65 | |
|
|
66 | my $name = $who->name; |
|
|
67 | |
|
|
68 | if ($args ne "" && $name ne $args) { |
|
|
69 | if (my $other = cf::player::find $args) { |
|
|
70 | if ($other->ob->map->path eq $who->map->path |
|
|
71 | && abs ($other->ob->x - $who->x) <= 1 |
|
|
72 | && abs ($other->ob->y - $who->y) <= 1) { |
|
|
73 | $who->message ("Following player '$args', to stop, type: 'follow"); |
|
|
74 | $other->ob->message ("$name is now following your every step..."); |
|
|
75 | $follow{$name} = [ |
|
|
76 | $args, |
|
|
77 | [$other->ob->map->path, $other->ob->x, $other->ob->y], |
|
|
78 | [$who->map->path, $who->x, $who->y], |
|
|
79 | ]; |
|
|
80 | $timer->start; |
|
|
81 | } else { |
|
|
82 | $who->message ("You must stand directly beside '$args' to follow her/him"); |
|
|
83 | delete $follow{$name}; |
|
|
84 | } |
|
|
85 | } else { |
|
|
86 | $who->message ("Cannot follow '$args': no such player"); |
|
|
87 | delete $follow{$name}; |
|
|
88 | } |
|
|
89 | } else { |
|
|
90 | $who->message ("follow mode off"); |
|
|
91 | delete $follow{$name}; |
|
|
92 | } |
|
|
93 | }; |
|
|
94 | |
|
|
95 | sub on_player_death { |
|
|
96 | my ($ob) = @_; |
|
|
97 | |
|
|
98 | my $name = $ob->name; |
|
|
99 | |
|
|
100 | delete $follow{$name}; |
|
|
101 | |
|
|
102 | while (my ($k, $v) = each %follow) { |
|
|
103 | if ($v->[0] eq $name) { |
|
|
104 | delete $follow{$k}; |
|
|
105 | } |
|
|
106 | } |
|
|
107 | |
107 | 0 |
108 | 0 |
108 | } |
109 | } |
109 | |
110 | |
110 | |
111 | |
111 | |
112 | |
112 | |
113 | |
|
|
114 | |