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

Comparing deliantra/maps/perl/follow.ext (file contents):
Revision 1.4 by root, Sat Feb 4 05:28:41 2006 UTC vs.
Revision 1.8 by root, Tue Feb 7 02:08:22 2006 UTC

11 my ($who, $args) = @_; 11 my ($who, $args) = @_;
12 12
13 my $name = $who->name; 13 my $name = $who->name;
14 14
15 if ($args ne "" && $name ne $args) { 15 if ($args ne "" && $name ne $args) {
16 if (cf::player::find $args) { 16 if (my $other = cf::player::find $args) {
17 if ($other->ob->map->path eq $who->map->path
18 && abs ($other->ob->x - $who->x) <= 1
19 && abs ($other->ob->y - $who->y) <= 1) {
17 $who->message ("following player '$args', to stop, type: 'follow"); 20 $who->message ("Following player '$args', to stop, type: 'follow");
21 $other->ob->message ("$name is now following your every step...");
18 $follow{$name} = $args; 22 $follow{$name} = [
23 $args,
24 [$other->ob->map->path, $other->ob->x, $other->ob->y],
25 [$who->map->path, $who->x, $who->y],
26 ];
27 } else {
28 $who->message ("You must stand directly beside '$args' to follow her/him");
29 delete $follow{$name};
30 }
19 } else { 31 } else {
20 $who->message ("cannot follow '$args': no such player"); 32 $who->message ("Cannot follow '$args': no such player");
33 delete $follow{$name};
21 } 34 }
22 } else { 35 } else {
23 $who->message ("follow mode off"); 36 $who->message ("follow mode off");
24 delete $follow{$name}; 37 delete $follow{$name};
25 } 38 }
26}; 39};
27 40
28sub teleport { 41sub teleport {
29 my ($pl, $map, $x, $y) = @_; 42 my ($pl, $map, $x, $y) = @_;
30 43
44 return if $pl->ob->map->path eq $map
45 && abs ($pl->ob->x - $x) <= 1
46 && abs ($pl->ob->y - $y) <= 1;
47
31 my $portal = cf::object::new ("exit"); 48 my $portal = cf::object::new ("exit");
32 49
33 $portal->set_slaying ($map->path); 50 $portal->set_slaying ($map);
34 $portal->set_hp ($x); 51 $portal->set_hp ($x);
35 $portal->set_sp ($y); 52 $portal->set_sp ($y);
36 53
37 $portal->apply ($pl->ob, 0); 54 $portal->apply ($pl->ob, 0);
38 55
42sub on_clock { 59sub on_clock {
43 my ($event) = @_; 60 my ($event) = @_;
44 61
45 return unless %follow; 62 return unless %follow;
46 63
47 while (my ($name, $target) = each %follow) { 64 while (my ($name, $v) = each %follow) {
65 my ($target, $his, $mine) = @$v;
48 my ($who, $other) = (cf::player::find $name, cf::player::find $target); 66 my ($who, $other) = (cf::player::find $name, cf::player::find $target);
49 if ($who && $other) { 67
68 if ($who && $other && $other->ob->map) {
50 teleport $who, $other->ob->map, $other->ob->x, $other->ob->y 69 my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y);
51 if $who->ob->map->path ne $other->ob->map->path; 70
71 if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) {
72 @$mine = @$his;
73 @$his = ($map, $x, $y);
74 }
75
76 my $map;
77
78 if ($map = cf::map::map $mine->[0]
79 and !grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR),
80 $map->at ($mine->[1], $mine->[2])) {
81 teleport $who, @$mine;
82 } else {
83 delete $follow{$name};
84 $who->ob->message ("You can't follow $target anymore!");
85 }
52 } else { 86 } else {
53 warn "follow: $name or $target is gone, removing from follow list\n";
54 delete $follow{$name}; 87 delete $follow{$name};
88 $who->ob->message ("$target is gone...");
55 } 89 }
56 } 90 }
57} 91}
58 92
59 93

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines