ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/follow.ext
Revision: 1.14
Committed: Fri Mar 24 23:29:18 2006 UTC (18 years, 1 month ago) by elmex
Branch: MAIN
Changes since 1.13: +4 -1 lines
Log Message:
added some 0 and 1 to the callbacks

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 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 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 $other->ob->message ("$name is now following your every step...");
23 $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 } else {
33 $who->message ("Cannot follow '$args': no such player");
34 delete $follow{$name};
35 }
36 } else {
37 $who->message ("follow mode off");
38 delete $follow{$name};
39 }
40 1
41 };
42
43 sub teleport {
44 my ($pl, $map, $x, $y) = @_;
45
46 return if $pl->ob->map->path eq $map
47 && abs ($pl->ob->x - $x) <= 1
48 && abs ($pl->ob->y - $y) <= 1;
49
50 my $portal = cf::object::new "exit";
51
52 $portal->set_slaying ($map);
53 $portal->set_hp ($x);
54 $portal->set_sp ($y);
55
56 $portal->apply ($pl->ob);
57
58 $portal->free;
59 }
60
61 sub on_player_death {
62 my ($event) = @_;
63
64 my $ob = $event->{who};
65 my $name = $ob->name;
66
67 delete $follow{$name};
68
69 while (my ($k, $v) = each %follow) {
70 if ($v->[0] eq $name) {
71 delete $follow{$k};
72 }
73 }
74
75 0
76 }
77
78 sub on_clock {
79 my ($event) = @_;
80
81 return 0 unless %follow;
82
83 while (my ($name, $v) = each %follow) {
84 my ($target, $his, $mine) = @$v;
85 my ($who, $other) = (cf::player::find $name, cf::player::find $target);
86
87 if ($who && $other && $other->ob->map) {
88 my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y);
89
90 if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) {
91 @$mine = @$his;
92 @$his = ($map, $x, $y);
93 }
94
95 my $map;
96
97 if ($map = cf::map::map $mine->[0]
98 and !grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR),
99 $map->at ($mine->[1], $mine->[2])) {
100 teleport $who, @$mine;
101 } else {
102 delete $follow{$name};
103 $who->ob->message ("You can't follow $target anymore!");
104 }
105 } else {
106 delete $follow{$name};
107 $who->ob->message ("$target is gone...");
108 }
109 }
110
111 0
112 }
113
114
115
116