… | |
… | |
3 | # implement a replacement for the built-in say/chat/shout/tell 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 => { |
… | |
… | |
737 | $emote{other} ||= "You look away from <self>."; |
708 | $emote{other} ||= "You look away from <self>."; |
738 | $emote{self} ||= "My god! Is that LEGAL?"; |
709 | $emote{self} ||= "My god! Is that LEGAL?"; |
739 | |
710 | |
740 | $emote{other} =~ s/<self>/$name/; |
711 | $emote{other} =~ s/<self>/$name/; |
741 | |
712 | |
742 | send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" |
713 | send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" |
743 | 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; |
744 | |
715 | |
745 | $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY); |
716 | $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY); |
746 | } elsif ($tname) { |
717 | } elsif ($tname) { |
747 | my $target = cf::player::find $tname |
718 | my $target = cf::player::find $tname |
… | |
… | |
756 | $emote{self} =~ s/<other>/$tname/; |
727 | $emote{self} =~ s/<other>/$tname/; |
757 | $emote{target} =~ s/<self>/$name/; |
728 | $emote{target} =~ s/<self>/$name/; |
758 | $emote{other} =~ s/<other>/$tname/; |
729 | $emote{other} =~ s/<other>/$tname/; |
759 | $emote{other} =~ s/<self>/$name/; |
730 | $emote{other} =~ s/<self>/$name/; |
760 | |
731 | |
761 | send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" |
732 | send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" |
762 | 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; |
763 | |
734 | |
764 | 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"; |
765 | $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); |
766 | } else { |
737 | } else { |
… | |
… | |
769 | $emote{other} ||= "<self> dances with glee."; |
740 | $emote{other} ||= "<self> dances with glee."; |
770 | $emote{self} ||= "You are a nut."; |
741 | $emote{self} ||= "You are a nut."; |
771 | |
742 | |
772 | $emote{other} =~ s/<self>/$name/; |
743 | $emote{other} =~ s/<self>/$name/; |
773 | |
744 | |
774 | send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" |
745 | send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" |
775 | 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; |
776 | |
747 | |
777 | $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); |
778 | } |
749 | } |
779 | }; |
750 | }; |
780 | }; |
751 | }; |
781 | } |
752 | } |
782 | |
753 | |
783 | cf::register_command me => sub { |
754 | cf::register_command me => sub { |
784 | my ($pl, $msg) = @_; |
755 | my ($pl, $msg) = @_; |
785 | |
756 | |
786 | my $name = $pl->name; |
757 | my $name = $pl->name; |
787 | |
758 | |
788 | send_msg $_, $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" |
789 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
760 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
790 | }; |
761 | }; |
791 | |
762 | |
792 | cf::register_command say => sub { |
763 | cf::register_command say => sub { |
793 | my ($ob, $msg) = @_; |
764 | my ($ob, $msg) = @_; |
… | |
… | |
798 | |
769 | |
799 | if ($msg) { |
770 | if ($msg) { |
800 | my $name = $ob->name; |
771 | my $name = $ob->name; |
801 | 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; |
802 | |
773 | |
803 | send_msg $_, $SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say" |
774 | send_msg $_, $cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say" |
804 | for grep $_ != $ob->contr, @plonmap; |
775 | for grep $_ != $ob->contr, @plonmap; |
805 | $ob->contr->send_msg ($SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY); |
776 | $ob->contr->send_msg ($cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY); |
806 | |
777 | |
807 | # npcs, magic_ears etc. |
778 | # npcs, magic_ears etc. |
808 | # first find all objects and their first-level inventories |
779 | # first find all objects and their first-level inventories |
809 | # within a 5x5 square that have something resembling |
780 | # within a 5x5 square that have something resembling |
810 | # dialogue or support on_say. |
781 | # dialogue or support on_say. |
811 | 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); |
812 | |
783 | |
813 | for my $npc ( |
784 | for my $npc ( |
814 | 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, |
815 | map +($_, $_->inv), |
786 | map +($_, $_->inv), |
816 | grep $_, |
787 | grep $_, |
817 | map $map->at ($x + $_ % 5, $y + (int $_ / 5)), |
788 | map $map->at ($x + $_ % 5, $y + (int $_ / 5)), |
818 | 0..24 |
789 | 0..24 |
819 | ) { |
790 | ) { |
… | |
… | |
824 | my ($reply, @kw) = $dialog->tell ($msg); |
795 | my ($reply, @kw) = $dialog->tell ($msg); |
825 | |
796 | |
826 | if (defined $reply) { |
797 | if (defined $reply) { |
827 | if ($npc->type == cf::MAGIC_EAR) { |
798 | if ($npc->type == cf::MAGIC_EAR) { |
828 | if (length $reply) { |
799 | if (length $reply) { |
829 | send_msg $_, $SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say" |
800 | send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say" |
830 | for @plonmap; |
801 | for @plonmap; |
831 | } |
802 | } |
832 | $npc->use_trigger; |
803 | $npc->use_trigger; |
833 | } else { |
804 | } else { |
834 | if (length $reply) { |
805 | if (length $reply) { |
835 | 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" |
836 | for @plonmap; |
807 | for @plonmap; |
837 | } |
808 | } |
838 | } |
809 | } |
839 | } |
810 | } |
840 | |
811 | |
841 | if (@kw) { |
812 | if (@kw) { |
842 | $_->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) |
813 | $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) |
843 | for @plonmap; |
814 | for @plonmap; |
844 | } |
815 | } |
845 | } |
816 | } |
846 | |
817 | |
847 | } else { |
818 | } else { |
848 | $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); |
849 | } |
820 | } |
850 | }; |
821 | }; |
851 | |
822 | |
852 | cf::register_command chat => sub { |
823 | cf::register_command chat => sub { |
853 | my ($ob, $msg) = @_; |
824 | my ($ob, $msg) = @_; |
… | |
… | |
863 | my $NOW = time; |
834 | my $NOW = time; |
864 | |
835 | |
865 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
836 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
866 | send_irc ("[%s] %s", $name, $msg); |
837 | send_irc ("[%s] %s", $name, $msg); |
867 | |
838 | |
868 | 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" |
869 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
840 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW } cf::player::list; |
870 | |
841 | |
871 | } else { |
842 | } else { |
872 | $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); |
873 | } |
844 | } |
874 | }; |
845 | }; |
875 | |
846 | |
876 | cf::register_command shout => sub { |
847 | cf::register_command shout => sub { |
877 | my ($ob, $msg) = @_; |
848 | my ($ob, $msg) = @_; |
… | |
… | |
887 | my $name = $ob->name; |
858 | my $name = $ob->name; |
888 | |
859 | |
889 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
860 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
890 | send_irc ("\007\0034{%s} %s\n", $name, $msg); |
861 | send_irc ("\007\0034{%s} %s\n", $name, $msg); |
891 | |
862 | |
892 | 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" |
893 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
864 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW } cf::player::list; |
894 | |
865 | |
895 | } else { |
866 | } else { |
896 | $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); |
897 | } |
868 | } |
898 | }; |
869 | }; |
899 | |
870 | |
900 | cf::register_command tell => sub { |
871 | cf::register_command tell => sub { |
901 | my ($ob, $args) = @_; |
872 | my ($ob, $args) = @_; |