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.25 by root, Tue Dec 12 16:59:34 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
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->free;
25}
7 26
8my %follow; 27my %follow;
9 28
29my $timer = Event->timer (interval => 0.2, parked => 1, cb => sub {
30 while (my ($name, $v) = each %follow) {
31 my ($target, $his, $mine) = @$v;
32 my ($who, $other) = (cf::player::find $name, cf::player::find $target);
33
34 if ($who && $other && $other->ob->map) {
35 my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y);
36
37 if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) {
38 @$mine = @$his;
39 @$his = ($map, $x, $y);
40 }
41
42 my $map;
43
44 if ($map = cf::map::find $mine->[0]
45 and !grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR),
46 $map->at ($mine->[1], $mine->[2])) {
47 teleport $who, @$mine;
48 } else {
49 delete $follow{$name};
50 $who->ob->message ("You can't follow $target anymore!");
51 }
52 } else {
53 delete $follow{$name};
54 $who->ob->message ("$target is gone...");
55 }
56 }
57
58 $_[0]->w->stop unless keys %follow;
59});
60
10cf::register_command follow => 0, sub { 61cf::register_command follow => sub {
11 my ($who, $args) = @_; 62 my ($who, $args) = @_;
12 63
13 my $name = $who->name; 64 my $name = $who->name;
14 65
15 if ($args ne "" && $name ne $args) { 66 if ($args ne "" && $name ne $args) {
16 if (my $other = cf::player::find $args) { 67 if (my $other = cf::player::find $args) {
17 if ($other->ob->map->path eq $who->map->path 68 if ($other->ob->map->path eq $who->map->path
18 && abs ($other->ob->x - $who->x) <= 1 69 && abs ($other->ob->x - $who->x) <= 1
19 && abs ($other->ob->y - $who->y) <= 1) { 70 && abs ($other->ob->y - $who->y) <= 1) {
20 $who->message ("Following player '$args', to stop, type: 'follow"); 71 $who->message ("Following player '$args', to stop, type: 'follow");
72 $other->ob->message ("$name is now following your every step...");
21 $follow{$name} = [ 73 $follow{$name} = [
22 $args, 74 $args,
23 [$other->ob->map->path, $other->ob->x, $other->ob->y], 75 [$other->ob->map->path, $other->ob->x, $other->ob->y],
24 [$who->map->path, $who->x, $who->y], 76 [$who->map->path, $who->x, $who->y],
25 ]; 77 ];
78 $timer->start;
26 } else { 79 } else {
27 $who->message ("You must stand directly beside '$args' to follow her/him"); 80 $who->message ("You must stand directly beside '$args' to follow her/him");
28 delete $follow{$name}; 81 delete $follow{$name};
29 } 82 }
30 } else { 83 } else {
35 $who->message ("follow mode off"); 88 $who->message ("follow mode off");
36 delete $follow{$name}; 89 delete $follow{$name};
37 } 90 }
38}; 91};
39 92
40sub teleport { 93cf::attach_to_players
41 my ($pl, $map, $x, $y) = @_; 94 on_death => sub {
95 my ($pl) = @_;
42 96
43 return if $pl->ob->map->path eq $map 97 my $name = $pl->ob->name;
44 && abs ($pl->ob->x - $x) <= 1
45 && abs ($pl->ob->y - $y) <= 1;
46 98
47 my $portal = cf::object::new ("exit"); 99 delete $follow{$name};
48 100
49 $portal->set_slaying ($map);
50 $portal->set_hp ($x);
51 $portal->set_sp ($y);
52
53 $portal->apply ($pl->ob, 0);
54
55 $portal->free;
56}
57
58sub on_clock {
59 my ($event) = @_;
60
61 return unless %follow;
62
63 while (my ($name, $v) = each %follow) { 101 while (my ($k, $v) = each %follow) {
64 my ($target, $his, $mine) = @$v; 102 if ($v->[0] eq $name) {
65 my ($who, $other) = (cf::player::find $name, cf::player::find $target); 103 delete $follow{$k};
66
67 if ($who && $other) {
68 my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y);
69
70 if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) {
71 @$mine = @$his;
72 @$his = ($map, $x, $y);
73 } 104 }
74
75 teleport $who, @$mine;
76 } else {
77 warn "follow: $name or $v->[0] is gone, removing from follow list\n";
78 delete $follow{$name};
79 } 105 }
80 } 106 },
81} 107;
82 108
83 109
84 110
85 111

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines