--- deliantra/server/ext/follow.ext 2006/12/17 00:44:59 1.2 +++ deliantra/server/ext/follow.ext 2007/01/14 18:00:34 1.9 @@ -6,54 +6,38 @@ # implement a 'follow' command # don't follow on damned ground -sub teleport { - my ($pl, $map, $x, $y) = @_; - - return if $pl->ob->map->path eq $map - && abs ($pl->ob->x - $x) <= 1 - && abs ($pl->ob->y - $y) <= 1; - - my $portal = cf::object::new "exit"; - - $portal->slaying ($map); - $portal->stats->hp ($x); - $portal->stats->sp ($y); - - $portal->apply ($pl->ob); - - $portal->destroy; -} - my %follow; my $timer = Event->timer (interval => 0.2, parked => 1, data => cf::WF_AUTOCANCEL, cb => sub { - while (my ($name, $v) = each %follow) { - my ($target, $his, $mine) = @$v; - my ($who, $other) = (cf::player::find $name, cf::player::find $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]) { - @$mine = @$his; - @$his = ($map, $x, $y); - } - - my $map; - - if ($map = cf::map::find $mine->[0] - and !grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR), - $map->at ($mine->[1], $mine->[2])) { - teleport $who, @$mine; + cf::sync_job { + while (my ($name, $v) = each %follow) { + my ($target, $his, $mine) = @$v; + 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]) { + @$mine = @$his; + @$his = ($map, $x, $y); + } + + my $map; + + if ($map = cf::map::find $mine->[0] + and !grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR), + $map->at ($mine->[1], $mine->[2])) { + $who->ob->goto (@$mine); + } else { + delete $follow{$name}; + $who->ob->message ("You can't follow $target anymore!"); + } } else { delete $follow{$name}; - $who->ob->message ("You can't follow $target anymore!"); + $who->ob->message ("$target is gone..."); } - } else { - delete $follow{$name}; - $who->ob->message ("$target is gone..."); } - } + }; $_[0]->w->stop unless keys %follow; }); @@ -64,8 +48,8 @@ my $name = $who->name; if ($args ne "" && $name ne $args) { - if (my $other = cf::player::find $args) { - if ($other->ob->map->path eq $who->map->path + 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"); @@ -90,7 +74,7 @@ } }; -cf::attach_to_players +cf::player->attach ( on_death => sub { my ($pl) = @_; @@ -104,7 +88,7 @@ } } }, -; +);