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.2 by root, Fri Feb 3 22:52:51 2006 UTC vs.
Revision 1.6 by root, Tue Feb 7 00:56:16 2006 UTC

1#! perl 1#! perl
2
3# TODO: skip arena
4# TODO: check for player leaving
2 5
3# implement a 'follow' command 6# implement a 'follow' command
4 7
5my %follow; 8my %follow;
6 9
8 my ($who, $args) = @_; 11 my ($who, $args) = @_;
9 12
10 my $name = $who->name; 13 my $name = $who->name;
11 14
12 if ($args ne "" && $name ne $args) { 15 if ($args ne "" && $name ne $args) {
13 if (cf::player::find $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) {
14 $who->message ("following player '$args', to stop, type: 'follow"); 20 $who->message ("Following player '$args', to stop, type: 'follow");
15 $follow{$name} = $args; 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 }
16 } else { 30 } else {
17 $who->message ("cannot follow '$args': no such player"); 31 $who->message ("Cannot follow '$args': no such player");
32 delete $follow{$name};
18 } 33 }
19 } else { 34 } else {
20 $who->message ("follow mode off"); 35 $who->message ("follow mode off");
21 delete $follow{$name}; 36 delete $follow{$name};
22 } 37 }
23}; 38};
24 39
40sub teleport {
41 my ($pl, $map, $x, $y) = @_;
42
43 return if $pl->ob->map->path eq $map
44 && abs ($pl->ob->x - $x) <= 1
45 && abs ($pl->ob->y - $y) <= 1;
46
47 my $portal = cf::object::new ("exit");
48
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
25sub on_clock { 58sub on_clock {
26 my ($event) = @_; 59 my ($event) = @_;
27 60
28 return unless %follow; 61 return unless %follow;
29 62
30 while (my ($name, $target) = each %follow) { 63 while (my ($name, $v) = each %follow) {
64 my ($target, $his, $mine) = @$v;
31 my ($who, $other) = (cf::player::find $name, cf::player::find $target); 65 my ($who, $other) = (cf::player::find $name, cf::player::find $target);
66
32 if ($who && $other) { 67 if ($who && $other) {
33 $who->ob->teleport ($other->ob->map, $other->ob->x, $other->ob->y) 68 my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y);
34 if $who->ob->map->path ne $other->ob->map->path; 69
70 if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) {
71 @$mine = @$his;
72 @$his = ($map, $x, $y);
73 }
74
75 my $map;
76
77 if ($map = cf::map::map $mine->[0]
78 and !grep $_->flag (cf::FLAG_UNIQUE), $map->at ($mine->[1], $mine->[2])) {
79 teleport $who, @$mine;
80 } else {
81 delete $follow{$name};
82 $who->ob->message ("$target is gone where you can't follow...");
83 }
35 } else { 84 } else {
36 warn "follow: $name or $target is gone, removing from follow list\n";
37 delete $follow{$name}; 85 delete $follow{$name};
86 $who->ob->message ("$name or $target is gone...");
38 } 87 }
39 } 88 }
40} 89}
41 90
42 91

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines