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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines