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.8 by root, Tue Feb 7 02:08:22 2006 UTC vs.
Revision 1.20 by root, Fri Aug 25 15:07:43 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 $other->ob->message ("$name is now following your every step...");
22 $follow{$name} = [
23 $args,
24 [$other->ob->map->path, $other->ob->x, $other->ob->y],
25 [$who->map->path, $who->x, $who->y],
26 ];
27 } else {
28 $who->message ("You must stand directly beside '$args' to follow her/him");
29 delete $follow{$name};
30 }
31 } else {
32 $who->message ("Cannot follow '$args': no such player");
33 delete $follow{$name};
34 }
35 } else {
36 $who->message ("follow mode off");
37 delete $follow{$name};
38 }
39};
40 8
41sub teleport { 9sub teleport {
42 my ($pl, $map, $x, $y) = @_; 10 my ($pl, $map, $x, $y) = @_;
43 11
44 return if $pl->ob->map->path eq $map 12 return if $pl->ob->map->path eq $map
45 && abs ($pl->ob->x - $x) <= 1 13 && abs ($pl->ob->x - $x) <= 1
46 && abs ($pl->ob->y - $y) <= 1; 14 && abs ($pl->ob->y - $y) <= 1;
47 15
48 my $portal = cf::object::new ("exit"); 16 my $portal = cf::object::new "exit";
49 17
50 $portal->set_slaying ($map); 18 $portal->set_slaying ($map);
51 $portal->set_hp ($x); 19 $portal->set_hp ($x);
52 $portal->set_sp ($y); 20 $portal->set_sp ($y);
53 21
54 $portal->apply ($pl->ob, 0); 22 $portal->apply ($pl->ob);
55 23
56 $portal->free; 24 $portal->free;
57} 25}
58 26
59sub on_clock { 27my %follow;
60 my ($event) = @_;
61 28
62 return unless %follow; 29my $timer = Event->timer (interval => 0.2, parked => 1, cb => sub {
63
64 while (my ($name, $v) = each %follow) { 30 while (my ($name, $v) = each %follow) {
65 my ($target, $his, $mine) = @$v; 31 my ($target, $his, $mine) = @$v;
66 my ($who, $other) = (cf::player::find $name, cf::player::find $target); 32 my ($who, $other) = (cf::player::find $name, cf::player::find $target);
67 33
68 if ($who && $other && $other->ob->map) { 34 if ($who && $other && $other->ob->map) {
86 } else { 52 } else {
87 delete $follow{$name}; 53 delete $follow{$name};
88 $who->ob->message ("$target is gone..."); 54 $who->ob->message ("$target is gone...");
89 } 55 }
90 } 56 }
91} 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_player
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;
92 108
93 109
94 110
95 111

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines