… | |
… | |
4 | # implement a replacement for the built-in say/chat/shout/tell/reply commands |
4 | # implement a replacement for the built-in say/chat/shout/tell/reply commands |
5 | # adds ignore/unignore functionality |
5 | # adds ignore/unignore functionality |
6 | |
6 | |
7 | use NPC_Dialogue; |
7 | use NPC_Dialogue; |
8 | use POSIX (); # for strftime only |
8 | use POSIX (); # for strftime only |
|
|
9 | |
|
|
10 | our $SAY_CHANNEL = { |
|
|
11 | id => "say", |
|
|
12 | title => "Map", |
|
|
13 | reply => "say ", |
|
|
14 | tooltip => "Things said to and replied from npcs near you and other players on the same map only.", |
|
|
15 | }; |
|
|
16 | |
|
|
17 | our $CHAT_CHANNEL = { |
|
|
18 | id => "chat", |
|
|
19 | title => "Chat", |
|
|
20 | reply => "chat ", |
|
|
21 | tooltip => "Player chat and shouts, global to the server.", |
|
|
22 | }; |
9 | |
23 | |
10 | sub clean_timeouts($) { |
24 | sub clean_timeouts($) { |
11 | my ($player) = @_; |
25 | my ($player) = @_; |
12 | my $NOW = time; |
26 | my $NOW = time; |
13 | |
27 | |
… | |
… | |
38 | prio => -1000, |
52 | prio => -1000, |
39 | on_login => sub { |
53 | on_login => sub { |
40 | my ($pl) = @_; |
54 | my ($pl) = @_; |
41 | |
55 | |
42 | clean_timeouts $pl->ob; |
56 | clean_timeouts $pl->ob; |
|
|
57 | $pl->ns->send_msg ($SAY_CHANNEL); |
|
|
58 | $pl->ns->send_msg ($CHAT_CHANNEL); |
43 | }, |
59 | }, |
44 | ); |
60 | ); |
45 | |
61 | |
46 | cf::register_command listen => sub { |
62 | cf::register_command listen => sub { |
47 | my ($pl, $msg) = @_; |
63 | my ($pl, $msg) = @_; |
… | |
… | |
746 | } |
762 | } |
747 | }; |
763 | }; |
748 | }; |
764 | }; |
749 | } |
765 | } |
750 | |
766 | |
751 | our $SAY_CHANNEL = { |
|
|
752 | id => "say", |
|
|
753 | title => "Map", |
|
|
754 | reply => "say ", |
|
|
755 | tooltip => "Things said to and replied from npcs near you and other players on the same map only.", |
|
|
756 | }; |
|
|
757 | |
|
|
758 | cf::register_command me => sub { |
767 | cf::register_command me => sub { |
759 | my ($pl, $msg) = @_; |
768 | my ($pl, $msg) = @_; |
760 | |
769 | |
761 | my $name = $pl->name; |
770 | my $name = $pl->name; |
762 | |
771 | |
763 | $_->ns->send_msg ($SAY_CHANNEL => "* $name $msg", cf::NDI_GREY, $_ == $pl ? (reply => 1) : ()) |
772 | $_->ns->send_msg ($SAY_CHANNEL => "* $name $msg", cf::NDI_GREY, $_ == $pl ? (reply => 1) : ()) |
764 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
773 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
765 | }; |
774 | }; |
766 | |
775 | |
767 | cf::register_command say => sub { |
776 | cf::register_command say => sub { |
768 | my ($pl, $msg) = @_; |
777 | my ($ob, $msg) = @_; |
769 | |
778 | |
770 | utf8::decode $msg; |
779 | utf8::decode $msg; |
771 | |
780 | |
772 | return if $pl->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); |
781 | return if $ob->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); |
773 | |
782 | |
774 | if ($msg) { |
783 | if ($msg) { |
775 | my $name = $pl->name; |
784 | my $name = $ob->name; |
776 | my @plonmap = grep $pl->on_same_map_as ($_->ob), cf::player::list; |
785 | my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list; |
777 | |
786 | |
778 | $_->ns->send_msg ($SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, $_ == $pl ? (reply => 1) : ()) |
787 | $_->ns->send_msg ($SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, $_ == $ob ? (reply => 1) : ()) |
779 | for @plonmap; |
788 | for @plonmap; |
780 | |
789 | |
781 | # npcs, magic_ears etc. |
790 | # npcs, magic_ears etc. |
782 | # first find all objects and their first-level inventories |
791 | # first find all objects and their first-level inventories |
783 | # within a 5x5 square that have something resembling |
792 | # within a 5x5 square that have something resembling |
784 | # dialogue or support on_say. |
793 | # dialogue or support on_say. |
785 | my ($map, $x, $y) = ($pl->map, $pl->x - 2, $pl->y - 2); |
794 | my ($map, $x, $y) = ($ob->map, $ob->x - 2, $ob->y - 2); |
786 | |
795 | |
787 | for my $npc ( |
796 | for my $npc ( |
788 | grep +($_->invoke (cf::EVENT_OBJECT_SAY, $pl->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_, |
797 | grep +($_->invoke (cf::EVENT_OBJECT_SAY, $ob->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_, |
789 | map +($_, $_->inv), |
798 | map +($_, $_->inv), |
790 | grep $_, |
799 | grep $_, |
791 | map $map->at ($x + $_ % 5, $y + (int $_ / 5)), |
800 | map $map->at ($x + $_ % 5, $y + (int $_ / 5)), |
792 | 0..24 |
801 | 0..24 |
793 | ) { |
802 | ) { |
794 | # if some listener teleported us somewhere else, stop right here |
803 | # if some listener teleported us somewhere else, stop right here |
795 | last unless $map->path == $pl->map->path; |
804 | last unless $map->path == $ob->map->path; |
796 | |
805 | |
797 | my $dialog = new NPC_Dialogue pl => $pl->contr, npc => $npc; |
806 | my $dialog = new NPC_Dialogue pl => $ob->contr, npc => $npc; |
798 | my ($reply, @kw) = $dialog->tell ($msg); |
807 | my ($reply, @kw) = $dialog->tell ($msg); |
799 | |
808 | |
800 | if (defined $reply) { |
809 | if (defined $reply) { |
801 | if ($npc->type == cf::MAGIC_EAR) { |
810 | if ($npc->type == cf::MAGIC_EAR) { |
802 | if (length $reply) { |
811 | if (length $reply) { |
803 | $_->contr->send_msg ($SAY_CHANNEL => $reply, cf::NDI_BROWN) |
812 | $_->ns->send_msg ($SAY_CHANNEL => $reply, cf::NDI_BROWN) |
804 | for @plonmap; |
813 | for @plonmap; |
805 | } |
814 | } |
806 | $npc->use_trigger; |
815 | $npc->use_trigger; |
807 | } else { |
816 | } else { |
808 | if (length $reply) { |
817 | if (length $reply) { |
809 | $_->contr->send_msg ($SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN) |
818 | $_->ns->send_msg ($SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN) |
810 | for @plonmap; |
819 | for @plonmap; |
811 | } |
820 | } |
812 | } |
821 | } |
813 | } |
822 | } |
814 | |
823 | |
815 | if (@kw) { |
824 | if (@kw) { |
816 | $_->contr->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) |
825 | $_->ns->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) |
817 | for @plonmap; |
826 | for @plonmap; |
818 | } |
827 | } |
819 | } |
828 | } |
820 | |
829 | |
821 | } else { |
830 | } else { |
822 | $pl->contr->send_msg ($SAY_CHANNEL => "What do you want to say?", 0, reply => 1); |
831 | $ob->contr->send_msg ($SAY_CHANNEL => "What do you want to say?", 0, reply => 1); |
823 | } |
832 | } |
824 | }; |
|
|
825 | |
|
|
826 | our $CHAT_CHANNEL = { |
|
|
827 | id => "chat", |
|
|
828 | title => "Chat", |
|
|
829 | reply => "chat ", |
|
|
830 | tooltip => "Player chat and shouts, global to the server.", |
|
|
831 | }; |
833 | }; |
832 | |
834 | |
833 | cf::register_command chat => sub { |
835 | cf::register_command chat => sub { |
834 | my ($pl, $msg) = @_; |
836 | my ($pl, $msg) = @_; |
835 | |
837 | |
… | |
… | |
864 | my $name = $pl->name; |
866 | my $name = $pl->name; |
865 | |
867 | |
866 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
868 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
867 | send_irc ("\007\0034{%s} %s\n", $name, $msg); |
869 | send_irc ("\007\0034{%s} %s\n", $name, $msg); |
868 | |
870 | |
869 | $_->ns->send_msg ($CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_BLUE, $_ == $pl ? (reply => 1) : ()) |
871 | $_->ns->send_msg ($CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_RED, $_ == $pl ? (reply => 1) : ()) |
870 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
872 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
871 | |
873 | |
872 | } else { |
874 | } else { |
873 | $pl->ns->send_msg ($CHAT_CHANNEL => "Shout what?"); |
875 | $pl->ns->send_msg ($CHAT_CHANNEL => "Shout what?"); |
874 | } |
876 | } |
… | |
… | |
910 | if ($target eq $name) { |
912 | if ($target eq $name) { |
911 | $ns->send_msg ($pl_channel => "You are talking to yourself, you freak!", reply => 1); |
913 | $ns->send_msg ($pl_channel => "You are talking to yourself, you freak!", reply => 1); |
912 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
914 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
913 | $ns->send_msg ($pl_channel => "$target ignores what you say. Give up on it.", reply => 1); |
915 | $ns->send_msg ($pl_channel => "$target ignores what you say. Give up on it.", reply => 1); |
914 | } else { |
916 | } else { |
915 | return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl->contr, $msg); |
917 | return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl, $msg); |
916 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; |
918 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; |
917 | |
919 | |
918 | $ns->send_msg ($pl_channel => "You tell $target: $msg", reply => 1); |
920 | $ns->send_msg ($pl_channel => "You tell $target: $msg", reply => 1); |
919 | $other->ns->send_msg ($other_channel => "$name tells you: $msg"); |
921 | $other->ns->send_msg ($other_channel => "$name tells you: $msg"); |
920 | } |
922 | } |