… | |
… | |
11 | |
11 | |
12 | $pl->send ("ext $token 1"); |
12 | $pl->send ("ext $token 1"); |
13 | }; |
13 | }; |
14 | |
14 | |
15 | my %dialog; # currently active dialogs |
15 | my %dialog; # currently active dialogs |
|
|
16 | |
|
|
17 | my $timer = Event->timer (interval => 0.2, parked => 1, cb => sub { |
|
|
18 | while (my ($token, $dialog) = each %dialog) { |
|
|
19 | my (undef, $dx, $dy) = $dialog->{ob}->rangevector ($dialog->{npc}); |
|
|
20 | next if (abs $dx) <= 2 && (abs $dy) <= 2; |
|
|
21 | |
|
|
22 | $dialog->{ob}->contr->send ("ext $token out_of_range"); |
|
|
23 | delete $dialog{$token}; |
|
|
24 | } |
|
|
25 | |
|
|
26 | $_[0]->w->stop unless keys %dialog; |
|
|
27 | }); |
16 | |
28 | |
17 | sub dialog_tell { |
29 | sub dialog_tell { |
18 | my ($token, $dialog, $msg) = @_; |
30 | my ($token, $dialog, $msg) = @_; |
19 | |
31 | |
20 | my $pl = $dialog->{ob}->contr; |
32 | my $pl = $dialog->{ob}->contr; |
… | |
… | |
53 | |
65 | |
54 | for my $npc ($pl->ob->map->at ($pl->ob->x + $dx, $pl->ob->y + $dy)) { |
66 | for my $npc ($pl->ob->map->at ($pl->ob->x + $dx, $pl->ob->y + $dy)) { |
55 | if (NPC_Dialogue::has_dialogue $npc) { |
67 | if (NPC_Dialogue::has_dialogue $npc) { |
56 | $dialog{$token} = new NPC_Dialogue ob => $pl->ob, npc => $npc; |
68 | $dialog{$token} = new NPC_Dialogue ob => $pl->ob, npc => $npc; |
57 | dialog_tell $token, $dialog{$token}, "hi"; |
69 | dialog_tell $token, $dialog{$token}, "hi"; |
|
|
70 | $timer->start; |
58 | return; |
71 | return; |
59 | } |
72 | } |
60 | } |
73 | } |
61 | |
74 | |
62 | $pl->send ("ext $token error"); |
75 | $pl->send ("ext $token error"); |
… | |
… | |
83 | delete $dialog{$_} for grep $pl->ob == $dialog{$_}{ob}, keys %dialog; |
96 | delete $dialog{$_} for grep $pl->ob == $dialog{$_}{ob}, keys %dialog; |
84 | |
97 | |
85 | 0 |
98 | 0 |
86 | } |
99 | } |
87 | |
100 | |
88 | sub on_clock { |
|
|
89 | return 0 unless %dialog; |
|
|
90 | |
101 | |
91 | while (my ($token, $dialog) = each %dialog) { |
|
|
92 | my (undef, $dx, $dy) = $dialog->{ob}->rangevector ($dialog->{npc}); |
|
|
93 | next if (abs $dx) <= 2 && (abs $dy) <= 2; |
|
|
94 | |
|
|
95 | $dialog->{ob}->contr->send ("ext $token out_of_range"); |
|
|
96 | delete $dialog{$token}; |
|
|
97 | } |
|
|
98 | |
|
|
99 | 0 |
|
|
100 | } |
|
|
101 | |
|
|