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.3 by root, Thu Dec 21 22:41:34 2006 UTC vs.
Revision 1.4 by root, Mon Jan 1 21:19:52 2007 UTC

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 8
9sub teleport {
10 my ($pl, $map, $x, $y) = @_;
11
12 return if $pl->ob->map->path eq $map
13 && abs ($pl->ob->x - $x) <= 1
14 && abs ($pl->ob->y - $y) <= 1;
15
16 my $portal = cf::object::new "exit";
17
18 $portal->slaying ($map);
19 $portal->stats->hp ($x);
20 $portal->stats->sp ($y);
21
22 $portal->apply ($pl->ob);
23
24 $portal->destroy;
25}
26
27my %follow; 9my %follow;
28 10
29my $timer = Event->timer (interval => 0.2, parked => 1, data => cf::WF_AUTOCANCEL, cb => sub { 11my $timer = Event->timer (interval => 0.2, parked => 1, data => cf::WF_AUTOCANCEL, cb => sub {
12 cf::sync_job {
30 while (my ($name, $v) = each %follow) { 13 while (my ($name, $v) = each %follow) {
31 my ($target, $his, $mine) = @$v; 14 my ($target, $his, $mine) = @$v;
32 my ($who, $other) = (cf::player::find $name, cf::player::find $target); 15 my ($who, $other) = (cf::player::find $name, cf::player::find $target);
33 16
34 if ($who && $other && $other->ob->map) { 17 if ($who && $other && $other->ob->map) {
35 my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y); 18 my ($map, $x, $y) = ($other->ob->map, $other->ob->x, $other->ob->y);
36 19
37 if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) { 20 if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) {
38 @$mine = @$his; 21 @$mine = @$his;
39 @$his = ($map, $x, $y); 22 @$his = ($map, $x, $y);
40 } 23 }
41 24
42 my $map; 25 my $map;
43 26
44 if ($map = cf::map::find $mine->[0] 27 if ($map = cf::map::find_map $mine->[0]
45 and !grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR), 28 and !grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR),
46 $map->at ($mine->[1], $mine->[2])) { 29 $map->at ($mine->[1], $mine->[2])) {
47 teleport $who, @$mine; 30 $who->ob->goto_map (@$mine);
31 } else {
32 delete $follow{$name};
33 $who->ob->message ("You can't follow $target anymore!");
34 }
48 } else { 35 } else {
49 delete $follow{$name}; 36 delete $follow{$name};
50 $who->ob->message ("You can't follow $target anymore!"); 37 $who->ob->message ("$target is gone...");
51 } 38 }
52 } else {
53 delete $follow{$name};
54 $who->ob->message ("$target is gone...");
55 } 39 }
56 } 40 };
57 41
58 $_[0]->w->stop unless keys %follow; 42 $_[0]->w->stop unless keys %follow;
59}); 43});
60 44
61cf::register_command follow => sub { 45cf::register_command follow => sub {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines