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

Comparing cf.schmorp.de/maps/perl/follow.ext (file contents):
Revision 1.4 by root, Sat Feb 4 05:28:41 2006 UTC vs.
Revision 1.5 by root, Sat Feb 4 20:38:29 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");
18 $follow{$name} = $args; 21 $follow{$name} = [
22 $args,
23 [$other->ob->map->path, $other->ob->x, $other->ob->y],
24 [$who->map->path, $who->x, $who->y],
25 ];
26 } else {
27 $who->message ("You must stand directly beside '$args' to follow her/him");
28 delete $follow{$name};
29 }
19 } else { 30 } else {
20 $who->message ("cannot follow '$args': no such player"); 31 $who->message ("Cannot follow '$args': no such player");
32 delete $follow{$name};
21 } 33 }
22 } else { 34 } else {
23 $who->message ("follow mode off"); 35 $who->message ("follow mode off");
24 delete $follow{$name}; 36 delete $follow{$name};
25 } 37 }
26}; 38};
27 39
28sub teleport { 40sub teleport {
29 my ($pl, $map, $x, $y) = @_; 41 my ($pl, $map, $x, $y) = @_;
30 42
43 return if $pl->ob->map->path eq $map
44 && abs ($pl->ob->x - $x) <= 1
45 && abs ($pl->ob->y - $y) <= 1;
46
31 my $portal = cf::object::new ("exit"); 47 my $portal = cf::object::new ("exit");
32 48
33 $portal->set_slaying ($map->path); 49 $portal->set_slaying ($map);
34 $portal->set_hp ($x); 50 $portal->set_hp ($x);
35 $portal->set_sp ($y); 51 $portal->set_sp ($y);
36 52
37 $portal->apply ($pl->ob, 0); 53 $portal->apply ($pl->ob, 0);
38 54
42sub on_clock { 58sub on_clock {
43 my ($event) = @_; 59 my ($event) = @_;
44 60
45 return unless %follow; 61 return unless %follow;
46 62
47 while (my ($name, $target) = each %follow) { 63 while (my ($name, $v) = each %follow) {
64 my ($target, $his, $mine) = @$v;
48 my ($who, $other) = (cf::player::find $name, cf::player::find $target); 65 my ($who, $other) = (cf::player::find $name, cf::player::find $target);
66
49 if ($who && $other) { 67 if ($who && $other) {
50 teleport $who, $other->ob->map, $other->ob->x, $other->ob->y 68 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; 69
70 if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) {
71 @$mine = @$his;
72 @$his = ($map, $x, $y);
73 }
74
75 teleport $who, @$mine;
52 } else { 76 } else {
53 warn "follow: $name or $target is gone, removing from follow list\n"; 77 warn "follow: $name or $v->[0] is gone, removing from follow list\n";
54 delete $follow{$name}; 78 delete $follow{$name};
55 } 79 }
56 } 80 }
57} 81}
58 82

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines