--- deliantra/server/ext/follow.ext 2007/01/04 18:48:15 1.6 +++ deliantra/server/ext/follow.ext 2008/07/11 21:41:38 1.14 @@ -6,18 +6,27 @@ # implement a 'follow' command # don't follow on damned ground -my %follow; +our %follow; + +our $CORO = cf::async { + $Coro::current->{desc} = "follow handler"; + + while () { eval {#d# + + while () { + cf::wait_for_tick; -my $timer = Event->timer (interval => 0.2, parked => 1, data => cf::WF_AUTOCANCEL, cb => sub { - cf::sync_job { while (my ($name, $v) = each %follow) { my ($target, $his, $mine) = @$v; - my ($who, $other) = (cf::player::find $name, cf::player::find $target); + my ($who, $other) = (cf::player::find_active $name, cf::player::find_active $target); if ($who && $other && $other->ob->map) { my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y); - if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) { + if ( + ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) + && $map !~ /^\{/ + ) { @$mine = @$his; @$his = ($map, $x, $y); } @@ -25,9 +34,10 @@ my $map; if ($map = cf::map::find $mine->[0] - and !grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR), + and $map =~ /^\// # short-gap fix + and !grep +($_->flag (cf::FLAG_UNIQUE) || $_->type == cf::SHOP_FLOOR) && $_->flag (cf::FLAG_IS_FLOOR), $map->at ($mine->[1], $mine->[2])) { - $who->ob->goto_map (@$mine); + $who->ob->goto (@$mine); } else { delete $follow{$name}; $who->ob->message ("You can't follow $target anymore!"); @@ -37,10 +47,11 @@ $who->ob->message ("$target is gone..."); } } - }; - $_[0]->w->stop unless keys %follow; -}); + Coro::schedule unless keys %follow; + } + }; warn "follow handler died <$@>\n"; }#d# +}; cf::register_command follow => sub { my ($who, $args) = @_; @@ -48,8 +59,8 @@ my $name = $who->name; if ($args ne "" && $name ne $args) { - if (my $other = cf::player::find $args) { - if ($other->ob->map eq $who->map + if (my $other = cf::player::find_active $args) { + if ($other->ob->map == $who->map && abs ($other->ob->x - $who->x) <= 1 && abs ($other->ob->y - $who->y) <= 1) { $who->message ("Following player '$args', to stop, type: 'follow"); @@ -59,7 +70,7 @@ [$other->ob->map->path, $other->ob->x, $other->ob->y], [$who->map->path, $who->x, $who->y], ]; - $timer->start; + $CORO->ready; } else { $who->message ("You must stand directly beside '$args' to follow her/him"); delete $follow{$name};