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

File Contents

# User Rev Content
1 root 1.1 #! perl
2    
3 root 1.4 # TODO: skip arena
4     # TODO: check for player leaving
5    
6 root 1.1 # 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 root 1.5 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 root 1.1 } else {
31 root 1.5 $who->message ("Cannot follow '$args': no such player");
32     delete $follow{$name};
33 root 1.1 }
34     } else {
35     $who->message ("follow mode off");
36     delete $follow{$name};
37     }
38     };
39    
40 root 1.3 sub teleport {
41     my ($pl, $map, $x, $y) = @_;
42    
43 root 1.5 return if $pl->ob->map->path eq $map
44     && abs ($pl->ob->x - $x) <= 1
45     && abs ($pl->ob->y - $y) <= 1;
46    
47 root 1.3 my $portal = cf::object::new ("exit");
48    
49 root 1.5 $portal->set_slaying ($map);
50 root 1.3 $portal->set_hp ($x);
51     $portal->set_sp ($y);
52    
53     $portal->apply ($pl->ob, 0);
54    
55     $portal->free;
56     }
57    
58 root 1.1 sub on_clock {
59     my ($event) = @_;
60    
61     return unless %follow;
62    
63 root 1.5 while (my ($name, $v) = each %follow) {
64     my ($target, $his, $mine) = @$v;
65 root 1.1 my ($who, $other) = (cf::player::find $name, cf::player::find $target);
66 root 1.5
67 root 1.1 if ($who && $other) {
68 root 1.5 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 root 1.6 my $map;
76    
77     if ($map = cf::map::map $mine->[0]
78 root 1.7 and !grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR),
79     $map->at ($mine->[1], $mine->[2])) {
80 root 1.6 teleport $who, @$mine;
81     } else {
82     delete $follow{$name};
83     $who->ob->message ("$target is gone where you can't follow...");
84     }
85 root 1.1 } else {
86     delete $follow{$name};
87 root 1.6 $who->ob->message ("$name or $target is gone...");
88 root 1.1 }
89     }
90     }
91    
92    
93    
94