ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/follow.ext
Revision: 1.6
Committed: Tue Feb 7 00:56:16 2006 UTC (18 years, 3 months ago) by root
Branch: MAIN
Changes since 1.5: +10 -2 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #! perl
2
3 # TODO: skip arena
4 # TODO: check for player leaving
5
6 # implement a 'follow' command
7
8 my %follow;
9
10 cf::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
40 sub 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
58 sub on_clock {
59 my ($event) = @_;
60
61 return unless %follow;
62
63 while (my ($name, $v) = each %follow) {
64 my ($target, $his, $mine) = @$v;
65 my ($who, $other) = (cf::player::find $name, cf::player::find $target);
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 }
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 }
84 } else {
85 delete $follow{$name};
86 $who->ob->message ("$name or $target is gone...");
87 }
88 }
89 }
90
91
92
93