ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/follow.ext
Revision: 1.18
Committed: Tue Jul 11 15:37:31 2006 UTC (17 years, 10 months ago) by root
Branch: MAIN
Changes since 1.17: +52 -50 lines
Log Message:
improve prefetch to include players and savebed paths
remove unsupported on_clock handlers and replace them by timers

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 root 1.10 # don't follow on damned ground
8 root 1.1
9 root 1.3 sub teleport {
10     my ($pl, $map, $x, $y) = @_;
11    
12 root 1.5 return if $pl->ob->map->path eq $map
13     && abs ($pl->ob->x - $x) <= 1
14     && abs ($pl->ob->y - $y) <= 1;
15    
16 root 1.11 my $portal = cf::object::new "exit";
17 root 1.3
18 root 1.5 $portal->set_slaying ($map);
19 root 1.3 $portal->set_hp ($x);
20     $portal->set_sp ($y);
21    
22 root 1.9 $portal->apply ($pl->ob);
23 root 1.3
24     $portal->free;
25     }
26    
27 root 1.18 my %follow;
28 root 1.12
29 root 1.18 my $timer = Event->timer (interval => 0.2, parked => 1, cb => sub {
30     warn "follow\n";#d#
31 root 1.1
32 root 1.5 while (my ($name, $v) = each %follow) {
33     my ($target, $his, $mine) = @$v;
34 root 1.1 my ($who, $other) = (cf::player::find $name, cf::player::find $target);
35 root 1.5
36 root 1.8 if ($who && $other && $other->ob->map) {
37 root 1.5 my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y);
38    
39     if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) {
40     @$mine = @$his;
41     @$his = ($map, $x, $y);
42     }
43    
44 root 1.6 my $map;
45    
46     if ($map = cf::map::map $mine->[0]
47 root 1.7 and !grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR),
48     $map->at ($mine->[1], $mine->[2])) {
49 root 1.6 teleport $who, @$mine;
50     } else {
51     delete $follow{$name};
52 root 1.8 $who->ob->message ("You can't follow $target anymore!");
53 root 1.6 }
54 root 1.1 } else {
55     delete $follow{$name};
56 root 1.8 $who->ob->message ("$target is gone...");
57 root 1.1 }
58     }
59 root 1.17
60 root 1.18 $_[0]->w->stop unless keys %follow;
61     });
62    
63     cf::register_command follow => 0, sub {
64     my ($who, $args) = @_;
65    
66     my $name = $who->name;
67    
68     if ($args ne "" && $name ne $args) {
69     if (my $other = cf::player::find $args) {
70     if ($other->ob->map->path eq $who->map->path
71     && abs ($other->ob->x - $who->x) <= 1
72     && abs ($other->ob->y - $who->y) <= 1) {
73     $who->message ("Following player '$args', to stop, type: 'follow");
74     $other->ob->message ("$name is now following your every step...");
75     $follow{$name} = [
76     $args,
77     [$other->ob->map->path, $other->ob->x, $other->ob->y],
78     [$who->map->path, $who->x, $who->y],
79     ];
80     $timer->start;
81     } else {
82     $who->message ("You must stand directly beside '$args' to follow her/him");
83     delete $follow{$name};
84     }
85     } else {
86     $who->message ("Cannot follow '$args': no such player");
87     delete $follow{$name};
88     }
89     } else {
90     $who->message ("follow mode off");
91     delete $follow{$name};
92     }
93     };
94    
95     sub on_player_death {
96     my ($ob) = @_;
97    
98     my $name = $ob->name;
99    
100     delete $follow{$name};
101    
102     while (my ($k, $v) = each %follow) {
103     if ($v->[0] eq $name) {
104     delete $follow{$k};
105     }
106     }
107    
108 root 1.17 0
109 root 1.1 }
110    
111    
112    
113    
114 root 1.18