1 | #! perl # depends=irc mandatory |
1 | #! perl # depends=irc mandatory |
2 | |
2 | |
3 | # implement a replacement for the built-in say/chat/shout/tell/reply commands |
3 | # implement a replacement for the built-in say/chat/shout/tell commands |
4 | # adds ignore/unignore functionality |
4 | # adds ignore/unignore functionality |
5 | |
5 | |
6 | use NPC_Dialogue; |
6 | use NPC_Dialogue; |
7 | use POSIX (); # for strftime only |
7 | use POSIX (); # for strftime only |
8 | |
|
|
9 | our $SAY_CHANNEL = { |
|
|
10 | id => "say", |
|
|
11 | title => "Map", |
|
|
12 | reply => "say ", |
|
|
13 | tooltip => "Things said to and replied from npcs near you and other players on the same map only.", |
|
|
14 | }; |
|
|
15 | |
|
|
16 | our $CHAT_CHANNEL = { |
|
|
17 | id => "chat", |
|
|
18 | title => "Chat", |
|
|
19 | reply => "chat ", |
|
|
20 | tooltip => "Player chat and shouts, global to the server.", |
|
|
21 | }; |
|
|
22 | |
8 | |
23 | sub tell_channel($) { |
9 | sub tell_channel($) { |
24 | my ($target) = @_; |
10 | my ($target) = @_; |
25 | |
11 | |
26 | { |
12 | { |
… | |
… | |
70 | on_login => sub { |
56 | on_login => sub { |
71 | my ($pl) = @_; |
57 | my ($pl) = @_; |
72 | |
58 | |
73 | clean_timeouts $pl->ob; |
59 | clean_timeouts $pl->ob; |
74 | |
60 | |
75 | $pl->send_msg ($SAY_CHANNEL); |
61 | $pl->send_msg ($cf::SAY_CHANNEL); |
76 | $pl->send_msg ($CHAT_CHANNEL); |
62 | $pl->send_msg ($cf::CHAT_CHANNEL); |
77 | }, |
63 | }, |
78 | ); |
64 | ); |
79 | |
65 | |
|
|
66 | # TODO: remove once safe |
80 | cf::register_command listen => sub { |
67 | cf::register_command listen => sub { |
81 | my ($pl, $msg) = @_; |
|
|
82 | my $player = cf::player::find_active $pl->name; |
|
|
83 | |
|
|
84 | if ($msg ne "") { |
|
|
85 | $msg = 10 if $msg > 10; |
|
|
86 | |
|
|
87 | my $prev_listen = $player->listening; |
|
|
88 | $player->listening ($msg); |
|
|
89 | if ($prev_listen == $player->listening) { |
|
|
90 | $pl->message ("Your verbose level stays at $prev_listen.", cf::NDI_REPLY); |
|
|
91 | } else { |
|
|
92 | $pl->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_REPLY); |
|
|
93 | } |
|
|
94 | } else { |
|
|
95 | $pl->message ("Your verbose level is " . $player->listening . ".", cf::NDI_REPLY); |
|
|
96 | } |
|
|
97 | }; |
68 | }; |
98 | |
69 | |
99 | cf::register_command cointoss => sub { |
70 | cf::register_command cointoss => sub { |
100 | my ($ob, $msg) = @_; |
71 | my ($ob, $msg) = @_; |
101 | |
72 | |
102 | my $pl = $ob->contr; |
73 | my $pl = $ob->contr; |
103 | my $name = $ob->name; |
74 | my $name = $ob->name; |
104 | |
75 | |
105 | my $coin = int rand 2 ? "Heads" : "Tails"; |
76 | my $coin = int rand 2 ? "Heads" : "Tails"; |
106 | |
77 | |
107 | send_msg $_, $SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY, "msg_say" |
78 | send_msg $_, $cf::SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY, "msg_say" |
108 | for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; |
79 | for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; |
109 | |
80 | |
110 | $pl->send_msg ($SAY_CHANNEL => "You flip a coin.... $coin!", cf::NDI_GREY | cf::NDI_REPLY); |
81 | $pl->send_msg ($cf::SAY_CHANNEL => "You flip a coin.... $coin!", cf::NDI_GREY | cf::NDI_REPLY); |
111 | }; |
82 | }; |
112 | |
83 | |
113 | cf::register_command orcknuckle => sub { |
84 | cf::register_command orcknuckle => sub { |
114 | my ($ob, $msg) = @_; |
85 | my ($ob, $msg) = @_; |
115 | |
86 | |
… | |
… | |
118 | |
89 | |
119 | my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc"); |
90 | my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc"); |
120 | my ($i, $j, $k, $l) = (rand 5, rand 5, rand 5, rand 6); |
91 | my ($i, $j, $k, $l) = (rand 5, rand 5, rand 5, rand 6); |
121 | my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]"; |
92 | my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]"; |
122 | |
93 | |
123 | send_msg $_, $SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY, "msg_say" |
94 | send_msg $_, $cf::SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY, "msg_say" |
124 | for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; |
95 | for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; |
125 | |
96 | |
126 | $pl->send_msg ($SAY_CHANNEL => "You roll $result!", cf::NDI_GREY | cf::NDI_REPLY); |
97 | $pl->send_msg ($cf::SAY_CHANNEL => "You roll $result!", cf::NDI_GREY | cf::NDI_REPLY); |
127 | }; |
98 | }; |
128 | |
99 | |
129 | my $emotes = { |
100 | my $emotes = { |
130 | growl => { |
101 | growl => { |
131 | noparams => { |
102 | noparams => { |
… | |
… | |
251 | }, |
222 | }, |
252 | params => { |
223 | params => { |
253 | target => "<self> kisses you.", |
224 | target => "<self> kisses you.", |
254 | other => "<self> kisses <other>.", |
225 | other => "<self> kisses <other>.", |
255 | self => "You kiss <other>.", |
226 | self => "You kiss <other>.", |
|
|
227 | }, |
|
|
228 | self => { |
|
|
229 | }, |
|
|
230 | }, |
|
|
231 | smother => { |
|
|
232 | noparams => { |
|
|
233 | other => "<self> makes weird facial contortions", |
|
|
234 | self => "All the lonely people..", |
|
|
235 | }, |
|
|
236 | params => { |
|
|
237 | target => "<self> smothers you with kisses.", |
|
|
238 | other => "<self> smothers <other> with kisses.", |
|
|
239 | self => "You smother <other> with kisses.", |
256 | }, |
240 | }, |
257 | self => { |
241 | self => { |
258 | }, |
242 | }, |
259 | }, |
243 | }, |
260 | wink => { |
244 | wink => { |
… | |
… | |
724 | $emote{other} ||= "You look away from <self>."; |
708 | $emote{other} ||= "You look away from <self>."; |
725 | $emote{self} ||= "My god! Is that LEGAL?"; |
709 | $emote{self} ||= "My god! Is that LEGAL?"; |
726 | |
710 | |
727 | $emote{other} =~ s/<self>/$name/; |
711 | $emote{other} =~ s/<self>/$name/; |
728 | |
712 | |
729 | send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" |
713 | send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" |
730 | for grep { $ob->on_same_map_as ($_->ob) && $_ != $ob} cf::player::list; |
714 | for grep { $ob->on_same_map_as ($_->ob) && $_ != $ob} cf::player::list; |
731 | |
715 | |
732 | $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY); |
716 | $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY); |
733 | } elsif ($tname) { |
717 | } elsif ($tname) { |
734 | my $target = cf::player::find $tname |
718 | my $target = cf::player::find $tname |
… | |
… | |
736 | |
720 | |
737 | my %emote = %{ $emotes->{$emotion}->{params} || {} }; |
721 | my %emote = %{ $emotes->{$emotion}->{params} || {} }; |
738 | |
722 | |
739 | $emote{other} ||= "<self> is eyeing <other> quizzically."; |
723 | $emote{other} ||= "<self> is eyeing <other> quizzically."; |
740 | $emote{self} ||= "You are still nuts."; |
724 | $emote{self} ||= "You are still nuts."; |
741 | $emote{target} ||= "You get the distinct feeling that <other> is nuts."; |
725 | $emote{target} ||= "You get the distinct feeling that <self> is nuts."; |
742 | |
726 | |
743 | $emote{self} =~ s/<other>/$tname/; |
727 | $emote{self} =~ s/<other>/$tname/; |
744 | $emote{target} =~ s/<self>/$name/; |
728 | $emote{target} =~ s/<self>/$name/; |
745 | $emote{other} =~ s/<other>/$tname/; |
729 | $emote{other} =~ s/<other>/$tname/; |
746 | $emote{other} =~ s/<self>/$name/; |
730 | $emote{other} =~ s/<self>/$name/; |
747 | |
731 | |
748 | send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" |
732 | send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" |
749 | for grep { $_ != $pl && $_ != $target && $ob->on_same_map_as ($_->ob) } cf::player::list; |
733 | for grep { $_ != $pl && $_ != $target && $ob->on_same_map_as ($_->ob) } cf::player::list; |
750 | |
734 | |
751 | send_msg $target, tell_channel $name, $emote{target}, cf::NDI_GREY, "msg_shout"; |
735 | send_msg $target, tell_channel $name, $emote{target}, cf::NDI_GREY, "msg_shout"; |
752 | $pl->send_msg (tell_channel $tname, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY); |
736 | $pl->send_msg (tell_channel $tname, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY); |
753 | } else { |
737 | } else { |
… | |
… | |
756 | $emote{other} ||= "<self> dances with glee."; |
740 | $emote{other} ||= "<self> dances with glee."; |
757 | $emote{self} ||= "You are a nut."; |
741 | $emote{self} ||= "You are a nut."; |
758 | |
742 | |
759 | $emote{other} =~ s/<self>/$name/; |
743 | $emote{other} =~ s/<self>/$name/; |
760 | |
744 | |
761 | send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" |
745 | send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" |
762 | for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl } cf::player::list; |
746 | for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl } cf::player::list; |
763 | |
747 | |
764 | $pl->send_msg ($CHAT_CHANNEL, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY); |
748 | $pl->send_msg ($cf::CHAT_CHANNEL, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY); |
765 | } |
749 | } |
766 | }; |
750 | }; |
767 | }; |
751 | }; |
768 | } |
752 | } |
769 | |
753 | |
770 | cf::register_command me => sub { |
754 | cf::register_command me => sub { |
771 | my ($pl, $msg) = @_; |
755 | my ($pl, $msg) = @_; |
772 | |
756 | |
773 | my $name = $pl->name; |
757 | my $name = $pl->name; |
774 | |
758 | |
775 | send_msg $pl, $SAY_CHANNEL => "* $name $msg", cf::NDI_GREY | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_say" |
759 | send_msg $_, $cf::SAY_CHANNEL => "* $name $msg", cf::NDI_GREY | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_say" |
776 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
760 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
777 | }; |
761 | }; |
778 | |
762 | |
779 | cf::register_command say => sub { |
763 | cf::register_command say => sub { |
780 | my ($ob, $msg) = @_; |
764 | my ($ob, $msg) = @_; |
… | |
… | |
785 | |
769 | |
786 | if ($msg) { |
770 | if ($msg) { |
787 | my $name = $ob->name; |
771 | my $name = $ob->name; |
788 | my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list; |
772 | my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list; |
789 | |
773 | |
790 | send_msg $_, $SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | ($_ == $ob->contr ? cf::NDI_REPLY : 0), "msg_say" |
774 | send_msg $_, $cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say" |
791 | for @plonmap; |
775 | for grep $_ != $ob->contr, @plonmap; |
|
|
776 | $ob->contr->send_msg ($cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY); |
792 | |
777 | |
793 | # npcs, magic_ears etc. |
778 | # npcs, magic_ears etc. |
794 | # first find all objects and their first-level inventories |
779 | # first find all objects and their first-level inventories |
795 | # within a 5x5 square that have something resembling |
780 | # within a 5x5 square that have something resembling |
796 | # dialogue or support on_say. |
781 | # dialogue or support on_say. |
797 | my ($map, $x, $y) = ($ob->map, $ob->x - 2, $ob->y - 2); |
782 | my ($map, $x, $y) = ($ob->map, $ob->x - 2, $ob->y - 2); |
798 | |
783 | |
799 | for my $npc ( |
784 | for my $npc ( |
800 | grep +($_->invoke (cf::EVENT_OBJECT_SAY, $ob->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_, |
785 | grep +($_->invoke (cf::EVENT_OBJECT_SAY, $ob->contr, $msg) && return) || $_->has_dialogue, |
801 | map +($_, $_->inv), |
786 | map +($_, $_->inv), |
802 | grep $_, |
787 | grep $_, |
803 | map $map->at ($x + $_ % 5, $y + (int $_ / 5)), |
788 | map $map->at ($x + $_ % 5, $y + (int $_ / 5)), |
804 | 0..24 |
789 | 0..24 |
805 | ) { |
790 | ) { |
… | |
… | |
810 | my ($reply, @kw) = $dialog->tell ($msg); |
795 | my ($reply, @kw) = $dialog->tell ($msg); |
811 | |
796 | |
812 | if (defined $reply) { |
797 | if (defined $reply) { |
813 | if ($npc->type == cf::MAGIC_EAR) { |
798 | if ($npc->type == cf::MAGIC_EAR) { |
814 | if (length $reply) { |
799 | if (length $reply) { |
815 | send_msg $_, $SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say" |
800 | send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say" |
816 | for @plonmap; |
801 | for @plonmap; |
817 | } |
802 | } |
818 | $npc->use_trigger; |
803 | $npc->use_trigger; |
819 | } else { |
804 | } else { |
820 | if (length $reply) { |
805 | if (length $reply) { |
821 | send_msg $_, $SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say" |
806 | send_msg $_, $cf::SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say" |
822 | for @plonmap; |
807 | for @plonmap; |
823 | } |
808 | } |
824 | } |
809 | } |
825 | } |
810 | } |
826 | |
811 | |
827 | if (@kw) { |
812 | if (@kw) { |
828 | $_->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) |
813 | $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) |
829 | for @plonmap; |
814 | for @plonmap; |
830 | } |
815 | } |
831 | } |
816 | } |
832 | |
817 | |
833 | } else { |
818 | } else { |
834 | $ob->send_msg ($SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY); |
819 | $ob->send_msg ($cf::SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY); |
835 | } |
820 | } |
836 | }; |
821 | }; |
837 | |
822 | |
838 | cf::register_command chat => sub { |
823 | cf::register_command chat => sub { |
839 | my ($ob, $msg) = @_; |
824 | my ($ob, $msg) = @_; |
… | |
… | |
849 | my $NOW = time; |
834 | my $NOW = time; |
850 | |
835 | |
851 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
836 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
852 | send_irc ("[%s] %s", $name, $msg); |
837 | send_irc ("[%s] %s", $name, $msg); |
853 | |
838 | |
854 | send_msg $_, $CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat" |
839 | send_msg $_, $cf::CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat" |
855 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
840 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
856 | |
841 | |
857 | } else { |
842 | } else { |
858 | $pl->send_msg ($CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY); |
843 | $pl->send_msg ($cf::CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY); |
859 | } |
844 | } |
860 | }; |
845 | }; |
861 | |
846 | |
862 | cf::register_command shout => sub { |
847 | cf::register_command shout => sub { |
863 | my ($ob, $msg) = @_; |
848 | my ($ob, $msg) = @_; |
… | |
… | |
873 | my $name = $ob->name; |
858 | my $name = $ob->name; |
874 | |
859 | |
875 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
860 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
876 | send_irc ("\007\0034{%s} %s\n", $name, $msg); |
861 | send_irc ("\007\0034{%s} %s\n", $name, $msg); |
877 | |
862 | |
878 | send_msg $_, $CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_RED | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_shout" |
863 | send_msg $_, $cf::CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_RED | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_shout" |
879 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
864 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
880 | |
865 | |
881 | } else { |
866 | } else { |
882 | $pl->send_msg ($CHAT_CHANNEL => "Shout what?", cf::NDI_RED | cf::NDI_DEF | cf::NDI_REPLY); |
867 | $pl->send_msg ($cf::CHAT_CHANNEL => "Shout what?", cf::NDI_RED | cf::NDI_DEF | cf::NDI_REPLY); |
883 | } |
868 | } |
884 | }; |
869 | }; |
885 | |
870 | |
886 | cf::register_command tell => sub { |
871 | cf::register_command tell => sub { |
887 | my ($ob, $args) = @_; |
872 | my ($ob, $args) = @_; |