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.6 by root, Tue Feb 7 00:56:16 2006 UTC vs.
Revision 1.11 by root, Fri Feb 17 19:36:36 2006 UTC

2 2
3# TODO: skip arena 3# TODO: skip arena
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 8
8my %follow; 9my %follow;
9 10
10cf::register_command follow => 0, sub { 11cf::register_command follow => 0, sub {
11 my ($who, $args) = @_; 12 my ($who, $args) = @_;
16 if (my $other = cf::player::find $args) { 17 if (my $other = cf::player::find $args) {
17 if ($other->ob->map->path eq $who->map->path 18 if ($other->ob->map->path eq $who->map->path
18 && abs ($other->ob->x - $who->x) <= 1 19 && abs ($other->ob->x - $who->x) <= 1
19 && abs ($other->ob->y - $who->y) <= 1) { 20 && abs ($other->ob->y - $who->y) <= 1) {
20 $who->message ("Following player '$args', to stop, type: 'follow"); 21 $who->message ("Following player '$args', to stop, type: 'follow");
22 $other->ob->message ("$name is now following your every step...");
21 $follow{$name} = [ 23 $follow{$name} = [
22 $args, 24 $args,
23 [$other->ob->map->path, $other->ob->x, $other->ob->y], 25 [$other->ob->map->path, $other->ob->x, $other->ob->y],
24 [$who->map->path, $who->x, $who->y], 26 [$who->map->path, $who->x, $who->y],
25 ]; 27 ];
42 44
43 return if $pl->ob->map->path eq $map 45 return if $pl->ob->map->path eq $map
44 && abs ($pl->ob->x - $x) <= 1 46 && abs ($pl->ob->x - $x) <= 1
45 && abs ($pl->ob->y - $y) <= 1; 47 && abs ($pl->ob->y - $y) <= 1;
46 48
47 my $portal = cf::object::new ("exit"); 49 my $portal = cf::object::new "exit";
48 50
49 $portal->set_slaying ($map); 51 $portal->set_slaying ($map);
50 $portal->set_hp ($x); 52 $portal->set_hp ($x);
51 $portal->set_sp ($y); 53 $portal->set_sp ($y);
52 54
53 $portal->apply ($pl->ob, 0); 55 $portal->apply ($pl->ob);
54 56
55 $portal->free; 57 $portal->free;
56} 58}
57 59
58sub on_clock { 60sub on_clock {
62 64
63 while (my ($name, $v) = each %follow) { 65 while (my ($name, $v) = each %follow) {
64 my ($target, $his, $mine) = @$v; 66 my ($target, $his, $mine) = @$v;
65 my ($who, $other) = (cf::player::find $name, cf::player::find $target); 67 my ($who, $other) = (cf::player::find $name, cf::player::find $target);
66 68
67 if ($who && $other) { 69 if ($who && $other && $other->ob->map) {
68 my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y); 70 my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y);
69 71
70 if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) { 72 if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) {
71 @$mine = @$his; 73 @$mine = @$his;
72 @$his = ($map, $x, $y); 74 @$his = ($map, $x, $y);
73 } 75 }
74 76
75 my $map; 77 my $map;
76 78
77 if ($map = cf::map::map $mine->[0] 79 if ($map = cf::map::map $mine->[0]
78 and !grep $_->flag (cf::FLAG_UNIQUE), $map->at ($mine->[1], $mine->[2])) { 80 and !grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR),
81 $map->at ($mine->[1], $mine->[2])) {
79 teleport $who, @$mine; 82 teleport $who, @$mine;
80 } else { 83 } else {
81 delete $follow{$name}; 84 delete $follow{$name};
82 $who->ob->message ("$target is gone where you can't follow..."); 85 $who->ob->message ("You can't follow $target anymore!");
83 } 86 }
84 } else { 87 } else {
85 delete $follow{$name}; 88 delete $follow{$name};
86 $who->ob->message ("$name or $target is gone..."); 89 $who->ob->message ("$target is gone...");
87 } 90 }
88 } 91 }
89} 92}
90 93
91 94

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines