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

# Content
1 #! perl
2
3 # TODO: skip arena
4 # TODO: check for player leaving
5
6 # implement a 'follow' command
7 # don't follow on damned ground
8
9 sub teleport {
10 my ($pl, $map, $x, $y) = @_;
11
12 return if $pl->ob->map->path eq $map
13 && abs ($pl->ob->x - $x) <= 1
14 && abs ($pl->ob->y - $y) <= 1;
15
16 my $portal = cf::object::new "exit";
17
18 $portal->set_slaying ($map);
19 $portal->set_hp ($x);
20 $portal->set_sp ($y);
21
22 $portal->apply ($pl->ob);
23
24 $portal->free;
25 }
26
27 my %follow;
28
29 my $timer = Event->timer (interval => 0.2, parked => 1, cb => sub {
30 warn "follow\n";#d#
31
32 while (my ($name, $v) = each %follow) {
33 my ($target, $his, $mine) = @$v;
34 my ($who, $other) = (cf::player::find $name, cf::player::find $target);
35
36 if ($who && $other && $other->ob->map) {
37 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 my $map;
45
46 if ($map = cf::map::map $mine->[0]
47 and !grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR),
48 $map->at ($mine->[1], $mine->[2])) {
49 teleport $who, @$mine;
50 } else {
51 delete $follow{$name};
52 $who->ob->message ("You can't follow $target anymore!");
53 }
54 } else {
55 delete $follow{$name};
56 $who->ob->message ("$target is gone...");
57 }
58 }
59
60 $_[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 0
109 }
110
111
112
113
114