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.6 by root, Tue Feb 7 00:56:16 2006 UTC vs.
Revision 1.14 by elmex, Fri Mar 24 23:29:18 2006 UTC

2 2
3# TODO: skip arena 3# TODO: skip arena
4# TODO: check for player leaving 4# TODO: check for player leaving
5 5
6# implement a 'follow' command 6# implement a 'follow' command
7# don't follow on damned ground
7 8
8my %follow; 9my %follow;
9 10
10cf::register_command follow => 0, sub { 11cf::register_command follow => 0, sub {
11 my ($who, $args) = @_; 12 my ($who, $args) = @_;
16 if (my $other = cf::player::find $args) { 17 if (my $other = cf::player::find $args) {
17 if ($other->ob->map->path eq $who->map->path 18 if ($other->ob->map->path eq $who->map->path
18 && abs ($other->ob->x - $who->x) <= 1 19 && abs ($other->ob->x - $who->x) <= 1
19 && abs ($other->ob->y - $who->y) <= 1) { 20 && abs ($other->ob->y - $who->y) <= 1) {
20 $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...");
21 $follow{$name} = [ 23 $follow{$name} = [
22 $args, 24 $args,
23 [$other->ob->map->path, $other->ob->x, $other->ob->y], 25 [$other->ob->map->path, $other->ob->x, $other->ob->y],
24 [$who->map->path, $who->x, $who->y], 26 [$who->map->path, $who->x, $who->y],
25 ]; 27 ];
33 } 35 }
34 } else { 36 } else {
35 $who->message ("follow mode off"); 37 $who->message ("follow mode off");
36 delete $follow{$name}; 38 delete $follow{$name};
37 } 39 }
40 1
38}; 41};
39 42
40sub teleport { 43sub teleport {
41 my ($pl, $map, $x, $y) = @_; 44 my ($pl, $map, $x, $y) = @_;
42 45
43 return if $pl->ob->map->path eq $map 46 return if $pl->ob->map->path eq $map
44 && abs ($pl->ob->x - $x) <= 1 47 && abs ($pl->ob->x - $x) <= 1
45 && abs ($pl->ob->y - $y) <= 1; 48 && abs ($pl->ob->y - $y) <= 1;
46 49
47 my $portal = cf::object::new ("exit"); 50 my $portal = cf::object::new "exit";
48 51
49 $portal->set_slaying ($map); 52 $portal->set_slaying ($map);
50 $portal->set_hp ($x); 53 $portal->set_hp ($x);
51 $portal->set_sp ($y); 54 $portal->set_sp ($y);
52 55
53 $portal->apply ($pl->ob, 0); 56 $portal->apply ($pl->ob);
54 57
55 $portal->free; 58 $portal->free;
59}
60
61sub 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
56} 76}
57 77
58sub on_clock { 78sub on_clock {
59 my ($event) = @_; 79 my ($event) = @_;
60 80
61 return unless %follow; 81 return 0 unless %follow;
62 82
63 while (my ($name, $v) = each %follow) { 83 while (my ($name, $v) = each %follow) {
64 my ($target, $his, $mine) = @$v; 84 my ($target, $his, $mine) = @$v;
65 my ($who, $other) = (cf::player::find $name, cf::player::find $target); 85 my ($who, $other) = (cf::player::find $name, cf::player::find $target);
66 86
67 if ($who && $other) { 87 if ($who && $other && $other->ob->map) {
68 my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y); 88 my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y);
69 89
70 if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) { 90 if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) {
71 @$mine = @$his; 91 @$mine = @$his;
72 @$his = ($map, $x, $y); 92 @$his = ($map, $x, $y);
73 } 93 }
74 94
75 my $map; 95 my $map;
76 96
77 if ($map = cf::map::map $mine->[0] 97 if ($map = cf::map::map $mine->[0]
78 and !grep $_->flag (cf::FLAG_UNIQUE), $map->at ($mine->[1], $mine->[2])) { 98 and !grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR),
99 $map->at ($mine->[1], $mine->[2])) {
79 teleport $who, @$mine; 100 teleport $who, @$mine;
80 } else { 101 } else {
81 delete $follow{$name}; 102 delete $follow{$name};
82 $who->ob->message ("$target is gone where you can't follow..."); 103 $who->ob->message ("You can't follow $target anymore!");
83 } 104 }
84 } else { 105 } else {
85 delete $follow{$name}; 106 delete $follow{$name};
86 $who->ob->message ("$name or $target is gone..."); 107 $who->ob->message ("$target is gone...");
87 } 108 }
88 } 109 }
110
111 0
89} 112}
90 113
91 114
92 115
93 116

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines