| 1 |
root |
1.1 |
#! perl |
| 2 |
|
|
|
| 3 |
|
|
# additional support for cfplus client |
| 4 |
|
|
|
| 5 |
root |
1.4 |
use NPC_Dialogue; |
| 6 |
|
|
|
| 7 |
root |
1.1 |
cf::register_extcmd cfplus_support => sub { |
| 8 |
root |
1.8 |
my ($pl, $msg) = @_; |
| 9 |
root |
1.1 |
|
| 10 |
root |
1.8 |
# $msg->{version} |
| 11 |
root |
1.1 |
|
| 12 |
root |
1.8 |
(version => 1) |
| 13 |
root |
1.1 |
}; |
| 14 |
|
|
|
| 15 |
root |
1.3 |
my %dialog; # currently active dialogs |
| 16 |
|
|
|
| 17 |
root |
1.5 |
my $timer = Event->timer (interval => 0.2, parked => 1, cb => sub { |
| 18 |
root |
1.8 |
while (my ($id, $dialog) = each %dialog) { |
| 19 |
root |
1.5 |
my (undef, $dx, $dy) = $dialog->{ob}->rangevector ($dialog->{npc}); |
| 20 |
|
|
next if (abs $dx) <= 2 && (abs $dy) <= 2; |
| 21 |
|
|
|
| 22 |
root |
1.8 |
$dialog->{ob}->contr->ext_reply ($id => msgtype => "error", msg => "out of range"); |
| 23 |
|
|
delete $dialog{$id}; |
| 24 |
root |
1.5 |
} |
| 25 |
|
|
|
| 26 |
|
|
$_[0]->w->stop unless keys %dialog; |
| 27 |
|
|
}); |
| 28 |
|
|
|
| 29 |
root |
1.3 |
sub dialog_tell { |
| 30 |
root |
1.8 |
my ($id, $dialog, $msg) = @_; |
| 31 |
root |
1.3 |
|
| 32 |
|
|
my $pl = $dialog->{ob}->contr; |
| 33 |
|
|
my ($reply, @kw) = $dialog->tell ($msg); |
| 34 |
|
|
$reply = "..." unless $reply; |
| 35 |
root |
1.8 |
|
| 36 |
|
|
$pl->ext_reply ($id => msgtype => "reply", msg => $reply, add_topics => \@kw); |
| 37 |
root |
1.1 |
} |
| 38 |
|
|
|
| 39 |
|
|
# return "interesting" information about the given tile |
| 40 |
|
|
# currently only returns the npc_dialog title when a dialog is possible |
| 41 |
|
|
cf::register_extcmd lookat => sub { |
| 42 |
root |
1.8 |
my ($pl, $msg) = @_; |
| 43 |
|
|
my ($dx, $dy) = @$msg{qw(dx dy)}; |
| 44 |
root |
1.1 |
|
| 45 |
root |
1.3 |
my $near = (abs $dx) <= 2 && (abs $dy) <= 2; |
| 46 |
root |
1.1 |
|
| 47 |
|
|
my %res; |
| 48 |
|
|
|
| 49 |
|
|
if ($pl->cell_visible ($dx, $dy)) { |
| 50 |
|
|
for my $ob ($pl->ob->map->at ($pl->ob->x + $dx, $pl->ob->y + $dy)) { |
| 51 |
|
|
$res{npc_dialog} = $ob->name |
| 52 |
root |
1.3 |
if $near && NPC_Dialogue::has_dialogue $ob; |
| 53 |
root |
1.1 |
} |
| 54 |
|
|
} |
| 55 |
|
|
|
| 56 |
root |
1.8 |
%res |
| 57 |
root |
1.1 |
}; |
| 58 |
|
|
|
| 59 |
|
|
cf::register_extcmd npc_dialog_begin => sub { |
| 60 |
root |
1.8 |
my ($pl, $msg) = @_; |
| 61 |
|
|
my ($id, $dx, $dy) = @$msg{qw(msgid dx dy)}; |
| 62 |
root |
1.1 |
|
| 63 |
root |
1.2 |
return unless (abs $dx) <= 2 && (abs $dy) <= 2; |
| 64 |
root |
1.1 |
return unless $pl->cell_visible ($dx, $dy); |
| 65 |
|
|
|
| 66 |
|
|
for my $npc ($pl->ob->map->at ($pl->ob->x + $dx, $pl->ob->y + $dy)) { |
| 67 |
root |
1.3 |
if (NPC_Dialogue::has_dialogue $npc) { |
| 68 |
root |
1.8 |
$dialog{$id} = new NPC_Dialogue ob => $pl->ob, npc => $npc; |
| 69 |
|
|
dialog_tell $id, $dialog{$id}, "hi"; |
| 70 |
root |
1.5 |
$timer->start; |
| 71 |
root |
1.1 |
return; |
| 72 |
|
|
} |
| 73 |
|
|
} |
| 74 |
|
|
|
| 75 |
root |
1.8 |
(msgtype => "error", msg => "nothing to talk to found") |
| 76 |
root |
1.1 |
}; |
| 77 |
|
|
|
| 78 |
|
|
cf::register_extcmd npc_dialog_tell => sub { |
| 79 |
root |
1.8 |
my ($pl, $msg) = @_; |
| 80 |
root |
1.1 |
|
| 81 |
root |
1.8 |
dialog_tell $msg->{msgid}, $dialog{$msg->{msgid}}, $msg->{msg} |
| 82 |
|
|
if $dialog{$msg->{msgid}}; |
| 83 |
root |
1.1 |
|
| 84 |
root |
1.8 |
() |
| 85 |
root |
1.1 |
}; |
| 86 |
|
|
|
| 87 |
|
|
cf::register_extcmd npc_dialog_end => sub { |
| 88 |
root |
1.8 |
my ($pl, $msg) = @_; |
| 89 |
|
|
|
| 90 |
|
|
delete $dialog{$msg->{msgid}}; |
| 91 |
root |
1.1 |
|
| 92 |
root |
1.8 |
() |
| 93 |
root |
1.1 |
}; |
| 94 |
|
|
|
| 95 |
root |
1.9 |
cf::attach_to_players |
| 96 |
|
|
on_logout => sub { |
| 97 |
|
|
my ($pl) = @_; |
| 98 |
|
|
|
| 99 |
|
|
delete $dialog{$_} for grep $pl->ob == $dialog{$_}{ob}, keys %dialog; |
| 100 |
|
|
}, |
| 101 |
|
|
; |
| 102 |
root |
1.3 |
|
| 103 |
root |
1.6 |
sub on_unload { |
| 104 |
root |
1.8 |
while (my ($id, $dialog) = each %dialog) { |
| 105 |
|
|
$dialog->{ob}->contr->ext_reply ($id => msgtype => "error", msg => "npc dialogue module was reloaded"); |
| 106 |
root |
1.6 |
} |
| 107 |
|
|
|
| 108 |
|
|
%dialog = (); |
| 109 |
|
|
} |
| 110 |
|
|
|
| 111 |
root |
1.2 |
|