--- deliantra/server/ext/follow.ext 2010/05/02 19:04:01 1.18 +++ deliantra/server/ext/follow.ext 2010/05/02 19:42:15 1.19 @@ -9,6 +9,28 @@ our $MAX_QUEUE = 5; # the # of positions somebody else can lead our %follow; # $followername => [$follower, $target, [$queue]] +sub unfollow($) { + my $name = shift; + + if (my $f = delete $follow{$name}) { + my ($who, $target, undef) = @$f; + $who->contr->detach ("follow_aborter"); + $target->message ("$name no longer follows you."); + $who->message ("You no longer follow " . $target->name . "."); + } +} + +cf::player::attachment follow_aborter => + on_move => sub { + my ($pl, $dir) = @_; + unfollow $pl->ob->name; + }, + on_login => sub { + my ($pl, $dir) = @_; + $pl->detach ("follow_aborter"); + }, +; + our $CORO = cf::async { $Coro::current->{desc} = "follow handler"; @@ -28,8 +50,8 @@ # try to move to oldest position if (@$queue > $MAX_QUEUE) { - delete $follow{$who->name}; $who->message ($target->name . " is too far away - you can't follow anymore!"); + unfollow $target->name; } else { my ($map, $x, $y) = @{ $queue->[0] }; @@ -40,8 +62,8 @@ or grep $_->flag (cf::FLAG_IS_FLOOR) && ($_->flag (cf::FLAG_UNIQUE) || $_->type == cf::SHOP_FLOOR), $map->at ($x, $y) ) { - delete $follow{$who->name}; - $who->ob->message ("You can't follow " . $target->name . " anymore!"); + $who->message ("You can't follow " . $target->name . " anymore!"); + unfollow $who->name; } elsif (!$who->blocked ($map, $x, $y)) { shift @$queue; $who->goto ($map, $x, $y); @@ -73,6 +95,7 @@ $other, [[$other->map, $other->x, $other->y]], ]; + $who->contr->attach ("follow_aborter"); $CORO->ready; } else { $who->message ("You must stand directly beside '$args' to follow her/him"); @@ -90,16 +113,14 @@ sub unregister { my ($pl) = @_; + my $name = $pl->ob->name; - delete $follow{$name}; -warn "unfollow $name\n";#d# + unfollow $name; while (my ($k, $v) = each %follow) { - if ($v->[1]->name eq $name) { -warn "unfollow $k\n";#d# - delete $follow{$k}; - } + unfollow $k + if $v->[1]->name eq $name; } }