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.5 by root, Sat Feb 4 20:38:29 2006 UTC vs.
Revision 1.13 by elmex, Mon Mar 20 23:27:50 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;
58}
59
60sub on_player_death {
61 my ($event) = @_;
62
63 my $ob = $event->{who};
64 my $name = $ob->name;
65
66 delete $follow{$name};
67
68 while (my ($k, $v) = each %follow) {
69 if ($v->[0] eq $name) {
70 delete $follow{$k};
71 }
72 }
73
74 0
56} 75}
57 76
58sub on_clock { 77sub on_clock {
59 my ($event) = @_; 78 my ($event) = @_;
60 79
62 81
63 while (my ($name, $v) = each %follow) { 82 while (my ($name, $v) = each %follow) {
64 my ($target, $his, $mine) = @$v; 83 my ($target, $his, $mine) = @$v;
65 my ($who, $other) = (cf::player::find $name, cf::player::find $target); 84 my ($who, $other) = (cf::player::find $name, cf::player::find $target);
66 85
67 if ($who && $other) { 86 if ($who && $other && $other->ob->map) {
68 my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y); 87 my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y);
69 88
70 if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) { 89 if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) {
71 @$mine = @$his; 90 @$mine = @$his;
72 @$his = ($map, $x, $y); 91 @$his = ($map, $x, $y);
73 } 92 }
74 93
94 my $map;
95
96 if ($map = cf::map::map $mine->[0]
97 and !grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR),
98 $map->at ($mine->[1], $mine->[2])) {
75 teleport $who, @$mine; 99 teleport $who, @$mine;
100 } else {
101 delete $follow{$name};
102 $who->ob->message ("You can't follow $target anymore!");
103 }
76 } else { 104 } else {
77 warn "follow: $name or $v->[0] is gone, removing from follow list\n";
78 delete $follow{$name}; 105 delete $follow{$name};
106 $who->ob->message ("$target is gone...");
79 } 107 }
80 } 108 }
81} 109}
82 110
83 111

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines