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

Comparing deliantra/server/ext/follow.ext (file contents):
Revision 1.1 by root, Fri Dec 15 19:29:18 2006 UTC vs.
Revision 1.16 by root, Sun May 2 14:31:49 2010 UTC

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# don't follow on damned ground
8 8
9sub teleport { 9our %follow;
10 my ($pl, $map, $x, $y) = @_;
11 10
12 return if $pl->ob->map->path eq $map 11our $CORO = cf::async {
13 && abs ($pl->ob->x - $x) <= 1 12 $Coro::current->{desc} = "follow handler";
14 && abs ($pl->ob->y - $y) <= 1;
15 13
16 my $portal = cf::object::new "exit"; 14 while () {
15 cf::wait_for_tick;
17 16
18 $portal->slaying ($map); 17 while (my ($name, $v) = each %follow) {
19 $portal->stats->hp ($x); 18 my ($target, $his, $mine) = @$v;
20 $portal->stats->sp ($y); 19 my ($who, $other) = (cf::player::find_active $name, cf::player::find_active $target);
21 20
22 $portal->apply ($pl->ob); 21 if ($who && $other && $other->ob->map) {
22 my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y);
23 23
24 $portal->free; 24 if (
25} 25 ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2])
26 && $map !~ /^\{/
27 ) {
28 @$mine = @$his;
29 @$his = ($map, $x, $y);
30 }
26 31
27my %follow; 32 my $map;
28 33
29my $timer = Event->timer (interval => 0.2, parked => 1, data => cf::WF_AUTOCANCEL, cb => sub {
30 while (my ($name, $v) = each %follow) {
31 my ($target, $his, $mine) = @$v;
32 my ($who, $other) = (cf::player::find $name, cf::player::find $target);
33
34 if ($who && $other && $other->ob->map) {
35 my ($map, $x, $y) = ($other->ob->map->path, $other->ob->x, $other->ob->y);
36
37 if ($map ne $his->[0] || $x != $his->[1] || $y != $his->[2]) {
38 @$mine = @$his;
39 @$his = ($map, $x, $y);
40 }
41
42 my $map;
43
44 if ($map = cf::map::find $mine->[0] 34 if ($map = cf::map::find $mine->[0]
35 and $map =~ /^\// # short-gap fix
45 and !grep $_->flag (cf::FLAG_UNIQUE) && $_->flag (cf::FLAG_IS_FLOOR), 36 and !grep +($_->flag (cf::FLAG_UNIQUE) || $_->type == cf::SHOP_FLOOR) && $_->flag (cf::FLAG_IS_FLOOR),
46 $map->at ($mine->[1], $mine->[2])) { 37 $map->at ($mine->[1], $mine->[2])) {
47 teleport $who, @$mine; 38 $who->ob->goto (@$mine);
39 } else {
40 delete $follow{$name};
41 $who->ob->message ("You can't follow $target anymore!");
42 }
48 } else { 43 } else {
49 delete $follow{$name}; 44 delete $follow{$name};
50 $who->ob->message ("You can't follow $target anymore!"); 45 $who->ob->message ("$target is gone...")
46 if $who;
51 } 47 }
52 } else {
53 delete $follow{$name};
54 $who->ob->message ("$target is gone...");
55 } 48 }
49
50 Coro::schedule unless keys %follow;
56 } 51 }
57
58 $_[0]->w->stop unless keys %follow;
59}); 52};
60 53
61cf::register_command follow => sub { 54cf::register_command follow => sub {
62 my ($who, $args) = @_; 55 my ($who, $args) = @_;
63 56
64 my $name = $who->name; 57 my $name = $who->name;
65 58
66 if ($args ne "" && $name ne $args) { 59 if ($args ne "" && $name ne $args) {
67 if (my $other = cf::player::find $args) { 60 if (my $other = cf::player::find_active $args) {
68 if ($other->ob->map->path eq $who->map->path 61 if ($other->ob->map == $who->map
69 && abs ($other->ob->x - $who->x) <= 1 62 && abs ($other->ob->x - $who->x) <= 1
70 && abs ($other->ob->y - $who->y) <= 1) { 63 && abs ($other->ob->y - $who->y) <= 1) {
71 $who->message ("Following player '$args', to stop, type: 'follow"); 64 $who->message ("Following player '$args', to stop, type: 'follow");
72 $other->ob->message ("$name is now following your every step..."); 65 $other->ob->message ("$name is now following your every step...");
73 $follow{$name} = [ 66 $follow{$name} = [
74 $args, 67 $args,
75 [$other->ob->map->path, $other->ob->x, $other->ob->y], 68 [$other->ob->map->path, $other->ob->x, $other->ob->y],
76 [$who->map->path, $who->x, $who->y], 69 [$who->map->path, $who->x, $who->y],
77 ]; 70 ];
78 $timer->start; 71 $CORO->ready;
79 } else { 72 } else {
80 $who->message ("You must stand directly beside '$args' to follow her/him"); 73 $who->message ("You must stand directly beside '$args' to follow her/him");
81 delete $follow{$name}; 74 delete $follow{$name};
82 } 75 }
83 } else { 76 } else {
88 $who->message ("follow mode off"); 81 $who->message ("follow mode off");
89 delete $follow{$name}; 82 delete $follow{$name};
90 } 83 }
91}; 84};
92 85
93cf::attach_to_players 86cf::player->attach (
94 on_death => sub { 87 on_death => sub {
95 my ($pl) = @_; 88 my ($pl) = @_;
96 89
97 my $name = $pl->ob->name; 90 my $name = $pl->ob->name;
98 91
102 if ($v->[0] eq $name) { 95 if ($v->[0] eq $name) {
103 delete $follow{$k}; 96 delete $follow{$k};
104 } 97 }
105 } 98 }
106 }, 99 },
107; 100);
108 101
109 102
110 103
111 104

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines