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 | |
8 | |
… | |
… | |
27 | id => "tell-$target", |
27 | id => "tell-$target", |
28 | title => "$target", |
28 | title => "$target", |
29 | reply => "tell $target ", |
29 | reply => "tell $target ", |
30 | tooltip => "Private messages from/to $target", |
30 | tooltip => "Private messages from/to $target", |
31 | } |
31 | } |
|
|
32 | } |
|
|
33 | |
|
|
34 | sub send_msg($$$$$) { |
|
|
35 | my ($pl, $channel, $msg, $flags, $sound) = @_; |
|
|
36 | $pl->play_sound (cf::sound::find $sound) if defined $sound; |
|
|
37 | $pl->send_msg ($channel, $msg, $flags); |
|
|
38 | () |
32 | } |
39 | } |
33 | |
40 | |
34 | sub clean_timeouts($) { |
41 | sub clean_timeouts($) { |
35 | my ($player) = @_; |
42 | my ($player) = @_; |
36 | my $NOW = time; |
43 | my $NOW = time; |
… | |
… | |
62 | prio => -1000, |
69 | prio => -1000, |
63 | on_login => sub { |
70 | on_login => sub { |
64 | my ($pl) = @_; |
71 | my ($pl) = @_; |
65 | |
72 | |
66 | clean_timeouts $pl->ob; |
73 | clean_timeouts $pl->ob; |
|
|
74 | |
67 | $pl->send_msg ($SAY_CHANNEL); |
75 | $pl->send_msg ($SAY_CHANNEL); |
68 | $pl->send_msg ($CHAT_CHANNEL); |
76 | $pl->send_msg ($CHAT_CHANNEL); |
69 | }, |
77 | }, |
70 | ); |
78 | ); |
71 | |
79 | |
… | |
… | |
94 | my $pl = $ob->contr; |
102 | my $pl = $ob->contr; |
95 | my $name = $ob->name; |
103 | my $name = $ob->name; |
96 | |
104 | |
97 | my $coin = int rand 2 ? "Heads" : "Tails"; |
105 | my $coin = int rand 2 ? "Heads" : "Tails"; |
98 | |
106 | |
99 | $_->send_msg ($SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY) |
107 | send_msg $_, $SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY, "msg_say" |
100 | for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; |
108 | for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; |
101 | |
109 | |
102 | $pl->send_msg ($SAY_CHANNEL => "You flip a coin.... $coin!", cf::NDI_GREY | cf::NDI_REPLY); |
110 | $pl->send_msg ($SAY_CHANNEL => "You flip a coin.... $coin!", cf::NDI_GREY | cf::NDI_REPLY); |
103 | }; |
111 | }; |
104 | |
112 | |
… | |
… | |
110 | |
118 | |
111 | my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc"); |
119 | my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc"); |
112 | my ($i, $j, $k, $l) = (rand 5, rand 5, rand 5, rand 6); |
120 | my ($i, $j, $k, $l) = (rand 5, rand 5, rand 5, rand 6); |
113 | my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]"; |
121 | my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]"; |
114 | |
122 | |
115 | $_->send_msg ($SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY) |
123 | send_msg $_, $SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY, "msg_say" |
116 | for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; |
124 | for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; |
117 | |
125 | |
118 | $pl->send_msg ($SAY_CHANNEL => "You roll $result!", cf::NDI_GREY | cf::NDI_REPLY); |
126 | $pl->send_msg ($SAY_CHANNEL => "You roll $result!", cf::NDI_GREY | cf::NDI_REPLY); |
119 | }; |
127 | }; |
120 | |
128 | |
… | |
… | |
243 | }, |
251 | }, |
244 | params => { |
252 | params => { |
245 | target => "<self> kisses you.", |
253 | target => "<self> kisses you.", |
246 | other => "<self> kisses <other>.", |
254 | other => "<self> kisses <other>.", |
247 | self => "You kiss <other>.", |
255 | self => "You kiss <other>.", |
|
|
256 | }, |
|
|
257 | self => { |
|
|
258 | }, |
|
|
259 | }, |
|
|
260 | smother => { |
|
|
261 | noparams => { |
|
|
262 | other => "<self> makes weird facial contortions", |
|
|
263 | self => "All the lonely people..", |
|
|
264 | }, |
|
|
265 | params => { |
|
|
266 | target => "<self> smothers you with kisses.", |
|
|
267 | other => "<self> smothers <other> with kisses.", |
|
|
268 | self => "You smother <other> with kisses.", |
248 | }, |
269 | }, |
249 | self => { |
270 | self => { |
250 | }, |
271 | }, |
251 | }, |
272 | }, |
252 | wink => { |
273 | wink => { |
… | |
… | |
706 | |
727 | |
707 | my $pl = $ob->contr; |
728 | my $pl = $ob->contr; |
708 | |
729 | |
709 | cf::async { |
730 | cf::async { |
710 | my $name = $ob->name; |
731 | my $name = $ob->name; |
|
|
732 | $Coro::current->{desc} = "emote handler for $name"; |
711 | |
733 | |
712 | if ($tname eq $name) { |
734 | if ($tname eq $name) { |
713 | my %emote = %{ $emotes->{$emotion}->{self} || {} }; |
735 | my %emote = %{ $emotes->{$emotion}->{self} || {} }; |
714 | |
736 | |
715 | $emote{other} ||= "You look away from <self>."; |
737 | $emote{other} ||= "You look away from <self>."; |
716 | $emote{self} ||= "My god! Is that LEGAL?"; |
738 | $emote{self} ||= "My god! Is that LEGAL?"; |
717 | |
739 | |
718 | $emote{other} =~ s/<self>/$name/; |
740 | $emote{other} =~ s/<self>/$name/; |
719 | |
741 | |
720 | $_->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) |
742 | send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" |
721 | for grep { $ob->on_same_map_as ($_->ob) && $_ != $ob} cf::player::list; |
743 | for grep { $ob->on_same_map_as ($_->ob) && $_ != $ob} cf::player::list; |
722 | |
744 | |
723 | $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY); |
745 | $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY); |
724 | } elsif ($tname) { |
746 | } elsif ($tname) { |
725 | my $target = cf::player::find $tname |
747 | my $target = cf::player::find $tname |
726 | or return $pl->send_msg (tell_channel $tname, "$tname is not around.", cf::NDI_DK_ORANGE | cf::NDI_REPLY); |
748 | or return send_msg $pl, tell_channel $tname, "$tname is not around.", cf::NDI_DK_ORANGE | cf::NDI_REPLY, "msg_chat"; |
727 | |
749 | |
728 | my %emote = %{ $emotes->{$emotion}->{params} || {} }; |
750 | my %emote = %{ $emotes->{$emotion}->{params} || {} }; |
729 | |
751 | |
730 | $emote{other} ||= "<self> is eyeing <other> quizzically."; |
752 | $emote{other} ||= "<self> is eyeing <other> quizzically."; |
731 | $emote{self} ||= "You are still nuts."; |
753 | $emote{self} ||= "You are still nuts."; |
732 | $emote{target} ||= "You get the distinct feeling that <other> is nuts."; |
754 | $emote{target} ||= "You get the distinct feeling that <self> is nuts."; |
733 | |
755 | |
734 | $emote{self} =~ s/<other>/$tname/; |
756 | $emote{self} =~ s/<other>/$tname/; |
735 | $emote{target} =~ s/<self>/$name/; |
757 | $emote{target} =~ s/<self>/$name/; |
736 | $emote{other} =~ s/<other>/$tname/; |
758 | $emote{other} =~ s/<other>/$tname/; |
737 | $emote{other} =~ s/<self>/$name/; |
759 | $emote{other} =~ s/<self>/$name/; |
738 | |
760 | |
739 | $_->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) |
761 | send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" |
740 | for grep { $_ != $pl && $_ != $target && $ob->on_same_map_as ($_->ob) } cf::player::list; |
762 | for grep { $_ != $pl && $_ != $target && $ob->on_same_map_as ($_->ob) } cf::player::list; |
741 | |
763 | |
742 | $target->send_msg (tell_channel $name, $emote{target}, cf::NDI_GREY); |
764 | send_msg $target, tell_channel $name, $emote{target}, cf::NDI_GREY, "msg_shout"; |
743 | $pl->send_msg (tell_channel $tname, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY); |
765 | $pl->send_msg (tell_channel $tname, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY); |
744 | } else { |
766 | } else { |
745 | my %emote = %{ $emotes->{$emotion}->{noparams} || {} }; |
767 | my %emote = %{ $emotes->{$emotion}->{noparams} || {} }; |
746 | |
768 | |
747 | $emote{other} ||= "<self> dances with glee."; |
769 | $emote{other} ||= "<self> dances with glee."; |
748 | $emote{self} ||= "You are a nut."; |
770 | $emote{self} ||= "You are a nut."; |
749 | |
771 | |
750 | $emote{other} =~ s/<self>/$name/; |
772 | $emote{other} =~ s/<self>/$name/; |
751 | |
773 | |
752 | $_->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) |
774 | send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" |
753 | for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl } cf::player::list; |
775 | for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl } cf::player::list; |
754 | |
776 | |
755 | $pl->send_msg ($CHAT_CHANNEL, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY); |
777 | $pl->send_msg ($CHAT_CHANNEL, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY); |
756 | } |
778 | } |
757 | }; |
779 | }; |
… | |
… | |
761 | cf::register_command me => sub { |
783 | cf::register_command me => sub { |
762 | my ($pl, $msg) = @_; |
784 | my ($pl, $msg) = @_; |
763 | |
785 | |
764 | my $name = $pl->name; |
786 | my $name = $pl->name; |
765 | |
787 | |
766 | $_->send_msg ($SAY_CHANNEL => "* $name $msg", cf::NDI_GREY | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0)) |
788 | send_msg $_, $SAY_CHANNEL => "* $name $msg", cf::NDI_GREY | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_say" |
767 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
789 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
768 | }; |
790 | }; |
769 | |
791 | |
770 | cf::register_command say => sub { |
792 | cf::register_command say => sub { |
771 | my ($ob, $msg) = @_; |
793 | my ($ob, $msg) = @_; |
… | |
… | |
776 | |
798 | |
777 | if ($msg) { |
799 | if ($msg) { |
778 | my $name = $ob->name; |
800 | my $name = $ob->name; |
779 | my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list; |
801 | my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list; |
780 | |
802 | |
|
|
803 | send_msg $_, $SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say" |
|
|
804 | for grep $_ != $ob->contr, @plonmap; |
781 | $_->send_msg ($SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | ($_ == $ob ? cf::NDI_REPLY : 0)) |
805 | $ob->contr->send_msg ($SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY); |
782 | for @plonmap; |
|
|
783 | |
806 | |
784 | # npcs, magic_ears etc. |
807 | # npcs, magic_ears etc. |
785 | # first find all objects and their first-level inventories |
808 | # first find all objects and their first-level inventories |
786 | # within a 5x5 square that have something resembling |
809 | # within a 5x5 square that have something resembling |
787 | # dialogue or support on_say. |
810 | # dialogue or support on_say. |
… | |
… | |
801 | my ($reply, @kw) = $dialog->tell ($msg); |
824 | my ($reply, @kw) = $dialog->tell ($msg); |
802 | |
825 | |
803 | if (defined $reply) { |
826 | if (defined $reply) { |
804 | if ($npc->type == cf::MAGIC_EAR) { |
827 | if ($npc->type == cf::MAGIC_EAR) { |
805 | if (length $reply) { |
828 | if (length $reply) { |
806 | $_->send_msg ($SAY_CHANNEL => $reply, cf::NDI_BROWN) |
829 | send_msg $_, $SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say" |
807 | for @plonmap; |
830 | for @plonmap; |
808 | } |
831 | } |
809 | $npc->use_trigger; |
832 | $npc->use_trigger; |
810 | } else { |
833 | } else { |
811 | if (length $reply) { |
834 | if (length $reply) { |
812 | $_->send_msg ($SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN) |
835 | send_msg $_, $SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say" |
813 | for @plonmap; |
836 | for @plonmap; |
814 | } |
837 | } |
815 | } |
838 | } |
816 | } |
839 | } |
817 | |
840 | |
… | |
… | |
840 | my $NOW = time; |
863 | my $NOW = time; |
841 | |
864 | |
842 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
865 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
843 | send_irc ("[%s] %s", $name, $msg); |
866 | send_irc ("[%s] %s", $name, $msg); |
844 | |
867 | |
845 | $_->send_msg ($CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0)) |
868 | send_msg $_, $CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat" |
846 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
869 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
847 | |
870 | |
848 | } else { |
871 | } else { |
849 | $pl->send_msg ($CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY); |
872 | $pl->send_msg ($CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY); |
850 | } |
873 | } |
… | |
… | |
864 | my $name = $ob->name; |
887 | my $name = $ob->name; |
865 | |
888 | |
866 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
889 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
867 | send_irc ("\007\0034{%s} %s\n", $name, $msg); |
890 | send_irc ("\007\0034{%s} %s\n", $name, $msg); |
868 | |
891 | |
869 | $_->send_msg ($CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_RED | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0)) |
892 | send_msg $_, $CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_RED | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_shout" |
870 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
893 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
871 | |
894 | |
872 | } else { |
895 | } else { |
873 | $pl->send_msg ($CHAT_CHANNEL => "Shout what?", cf::NDI_RED | cf::NDI_DEF | cf::NDI_REPLY); |
896 | $pl->send_msg ($CHAT_CHANNEL => "Shout what?", cf::NDI_RED | cf::NDI_DEF | cf::NDI_REPLY); |
874 | } |
897 | } |
… | |
… | |
905 | } else { |
928 | } else { |
906 | return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl, $msg); |
929 | return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl, $msg); |
907 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; |
930 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; |
908 | |
931 | |
909 | $ns->send_msg ($pl_channel => "You tell $target: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); |
932 | $ns->send_msg ($pl_channel => "You tell $target: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); |
910 | $other->send_msg ($other_channel => "$name tells you: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF); |
933 | send_msg $other, $other_channel => "$name tells you: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF, "msg_tell"; |
911 | } |
934 | } |
912 | } else { |
935 | } else { |
913 | $ns->send_msg ($pl_channel => "What do you want to tell $target?", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); |
936 | $ns->send_msg ($pl_channel => "What do you want to tell $target?", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); |
914 | } |
937 | } |
915 | |
938 | |