ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/follow.ext
Revision: 1.10
Committed: Thu Feb 9 01:15:25 2006 UTC (18 years, 3 months ago) by root
Branch: MAIN
Changes since 1.9: +1 -0 lines
Log Message:
*** empty log message ***

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 };
41
42 sub teleport {
43 my ($pl, $map, $x, $y) = @_;
44
45 return if $pl->ob->map->path eq $map
46 && abs ($pl->ob->x - $x) <= 1
47 && abs ($pl->ob->y - $y) <= 1;
48
49 my $portal = cf::object::new ("exit");
50
51 $portal->set_slaying ($map);
52 $portal->set_hp ($x);
53 $portal->set_sp ($y);
54
55 $portal->apply ($pl->ob);
56
57 $portal->free;
58 }
59
60 sub on_clock {
61 my ($event) = @_;
62
63 return unless %follow;
64
65 while (my ($name, $v) = each %follow) {
66 my ($target, $his, $mine) = @$v;
67 my ($who, $other) = (cf::player::find $name, cf::player::find $target);
68
69 if ($who && $other && $other->ob->map) {
70 my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y);
71
72 if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) {
73 @$mine = @$his;
74 @$his = ($map, $x, $y);
75 }
76
77 my $map;
78
79 if ($map = cf::map::map $mine->[0]
80 and !grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR),
81 $map->at ($mine->[1], $mine->[2])) {
82 teleport $who, @$mine;
83 } else {
84 delete $follow{$name};
85 $who->ob->message ("You can't follow $target anymore!");
86 }
87 } else {
88 delete $follow{$name};
89 $who->ob->message ("$target is gone...");
90 }
91 }
92 }
93
94
95
96