ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/follow.ext
(Generate patch)

Comparing deliantra/server/ext/follow.ext (file contents):
Revision 1.18 by root, Sun May 2 19:04:01 2010 UTC vs.
Revision 1.21 by root, Tue May 18 21:30:16 2010 UTC

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 8
9our $MAX_QUEUE = 5; # the # of positions somebody else can lead 9our $MAX_QUEUE = 5; # the # of positions somebody else can lead
10our %follow; # $followername => [$follower, $target, [$queue]] 10our %follow; # $followername => [$follower, $target, [$queue]]
11
12sub unfollow($) {
13 my $name = shift;
14
15 if (my $f = delete $follow{$name}) {
16 my ($who, $target, undef) = @$f;
17 $who->contr->detach ("follow_aborter");
18 $target->message ("$name no longer follows you.");
19 $who->message ("You no longer follow " . $target->name . ".");
20 }
21}
22
23cf::player::attachment follow_aborter =>
24 on_move => sub {
25 my ($pl, $dir) = @_;
26 unfollow $pl->ob->name;
27 },
28 on_login => sub {
29 my ($pl, $dir) = @_;
30 $pl->detach ("follow_aborter");
31 },
32;
11 33
12our $CORO = cf::async { 34our $CORO = cf::async {
13 $Coro::current->{desc} = "follow handler"; 35 $Coro::current->{desc} = "follow handler";
14 36
15 while () { 37 while () {
26 || $x != $queue->[-1][1] 48 || $x != $queue->[-1][1]
27 || $y != $queue->[-1][2]; 49 || $y != $queue->[-1][2];
28 50
29 # try to move to oldest position 51 # try to move to oldest position
30 if (@$queue > $MAX_QUEUE) { 52 if (@$queue > $MAX_QUEUE) {
31 delete $follow{$who->name};
32 $who->message ($target->name . " is too far away - you can't follow anymore!"); 53 $who->message ($target->name . " is too far away - you can't follow anymore!");
54 unfollow $target->name;
33 } else { 55 } else {
34 my ($map, $x, $y) = @{ $queue->[0] }; 56 my ($map, $x, $y) = @{ $queue->[0] };
35 57
36 $map->load; 58 $map->load;
37 59
38 if ( 60 if (
61 !$map->valid
39 $map->path !~ /^(\{link\}|\/)/ 62 or $map->path !~ /^(\{link\}|\/)/
40 or grep $_->flag (cf::FLAG_IS_FLOOR) && ($_->flag (cf::FLAG_UNIQUE) || $_->type == cf::SHOP_FLOOR), 63 or grep $_->flag (cf::FLAG_IS_FLOOR) && ($_->flag (cf::FLAG_UNIQUE) || $_->type == cf::SHOP_FLOOR),
41 $map->at ($x, $y) 64 $map->at ($x, $y))
42 ) { 65 ) {
43 delete $follow{$who->name};
44 $who->ob->message ("You can't follow " . $target->name . " anymore!"); 66 $who->message ("You can't follow " . $target->name . " anymore!");
67 unfollow $who->name;
45 } elsif (!$who->blocked ($map, $x, $y)) { 68 } elsif (!$who->blocked ($map, $x, $y)) {
46 shift @$queue; 69 shift @$queue;
47 $who->goto ($map, $x, $y); 70 $who->goto ($map, $x, $y);
48 } 71 }
49 } 72 }
71 $follow{$name} = [ 94 $follow{$name} = [
72 $who, 95 $who,
73 $other, 96 $other,
74 [[$other->map, $other->x, $other->y]], 97 [[$other->map, $other->x, $other->y]],
75 ]; 98 ];
99 $who->contr->attach ("follow_aborter");
76 $CORO->ready; 100 $CORO->ready;
77 } else { 101 } else {
78 $who->message ("You must stand directly beside '$args' to follow her/him"); 102 $who->message ("You must stand directly beside '$args' to follow her/him");
79 delete $follow{$name}; 103 delete $follow{$name};
80 } 104 }
88 } 112 }
89}; 113};
90 114
91sub unregister { 115sub unregister {
92 my ($pl) = @_; 116 my ($pl) = @_;
117
93 my $name = $pl->ob->name; 118 my $name = $pl->ob->name;
94 delete $follow{$name};
95 119
96warn "unfollow $name\n";#d# 120 unfollow $name;
97 121
98 while (my ($k, $v) = each %follow) { 122 while (my ($k, $v) = each %follow) {
123 unfollow $k
99 if ($v->[1]->name eq $name) { 124 if $v->[1]->name eq $name;
100warn "unfollow $k\n";#d#
101 delete $follow{$k};
102 }
103 } 125 }
104} 126}
105 127
106cf::player->attach ( 128cf::player->attach (
107 on_death => \&unregister, 129 on_death => \&unregister,
108 on_logout => \&unregister, 130 on_logout => \&unregister,
109); 131);
110 132
111
112
113

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines