ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/follow.ext
Revision: 1.5
Committed: Sat Feb 4 20:38:29 2006 UTC (18 years, 4 months ago) by root
Branch: MAIN
Changes since 1.4: +33 -9 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     teleport $who, @$mine;
76 root 1.1 } else {
77 root 1.5 warn "follow: $name or $v->[0] is gone, removing from follow list\n";
78 root 1.1 delete $follow{$name};
79     }
80     }
81     }
82    
83    
84    
85