ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/follow.ext
Revision: 1.17
Committed: Mon Jun 12 14:13:39 2006 UTC (17 years, 11 months ago) by root
Branch: MAIN
Changes since 1.16: +2 -0 lines
Log Message:
send out_of_range when player strays away too much, clear dialog when palyer logs out

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