ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/follow.ext
(Generate patch)

Comparing deliantra/maps/perl/follow.ext (file contents):
Revision 1.1 by root, Fri Feb 3 21:22:53 2006 UTC vs.
Revision 1.17 by root, Mon Jun 12 14:13:39 2006 UTC

1#! perl 1#! perl
2 2
3# TODO: skip arena
4# TODO: check for player leaving
5
3# implement a 'follow' command 6# implement a 'follow' command
7# don't follow on damned ground
4 8
5my %follow; 9my %follow;
6 10
7cf::register_command follow => 0, sub { 11cf::register_command follow => 0, sub {
8 my ($who, $args) = @_; 12 my ($who, $args) = @_;
9 13
10 my $name = $who->name; 14 my $name = $who->name;
11 15
12 if ($args ne "" && $name ne $args) { 16 if ($args ne "" && $name ne $args) {
13 if (cf::player::find $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) {
14 $who->message ("following player '$args', to stop, type: 'follow"); 21 $who->message ("Following player '$args', to stop, type: 'follow");
22 $other->ob->message ("$name is now following your every step...");
15 $follow{$name} = $args; 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 }
16 } else { 32 } else {
17 $who->message ("cannot follow '$args': no such player"); 33 $who->message ("Cannot follow '$args': no such player");
34 delete $follow{$name};
18 } 35 }
19 } else { 36 } else {
20 $who->message ("follow mode off"); 37 $who->message ("follow mode off");
21 delete $follow{$name}; 38 delete $follow{$name};
22 } 39 }
23}; 40};
24 41
25sub on_clock { 42sub teleport {
26 my ($event) = @_; 43 my ($pl, $map, $x, $y) = @_;
27 44
28 return unless %follow; 45 return if $pl->ob->map->path eq $map
46 && abs ($pl->ob->x - $x) <= 1
47 && abs ($pl->ob->y - $y) <= 1;
29 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
60sub on_player_death {
61 my ($ob) = @_;
62
63 my $name = $ob->name;
64
65 delete $follow{$name};
66
30 while (my ($name, $target) = each %follow) { 67 while (my ($k, $v) = each %follow) {
31 my ($who, $other) = (cf::player::find $name, cf::player::find $target); 68 if ($v->[0] eq $name) {
32 if ($who && $other) {
33 $who->ob->teleport ($other->ob->map, $other->ob->x, $other->ob->y);
34 } else {
35 warn "follow: $name or $target is gone, removing from follow list\n";
36 delete $follow{$name}; 69 delete $follow{$k};
37 } 70 }
38 } 71 }
72
73 0
74}
75
76sub on_clock {
77 return 0 unless %follow;
78
79 while (my ($name, $v) = each %follow) {
80 my ($target, $his, $mine) = @$v;
81 my ($who, $other) = (cf::player::find $name, cf::player::find $target);
82
83 if ($who && $other && $other->ob->map) {
84 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 my $map;
92
93 if ($map = cf::map::map $mine->[0]
94 and !grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR),
95 $map->at ($mine->[1], $mine->[2])) {
96 teleport $who, @$mine;
97 } else {
98 delete $follow{$name};
99 $who->ob->message ("You can't follow $target anymore!");
100 }
101 } else {
102 delete $follow{$name};
103 $who->ob->message ("$target is gone...");
104 }
105 }
106
107 0
39} 108}
40 109
41 110
42 111
43 112

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines