… | |
… | |
51 | $msg = 10 if $msg > 10; |
51 | $msg = 10 if $msg > 10; |
52 | |
52 | |
53 | my $prev_listen = $player->listening; |
53 | my $prev_listen = $player->listening; |
54 | $player->listening ($msg); |
54 | $player->listening ($msg); |
55 | if ($prev_listen == $player->listening) { |
55 | if ($prev_listen == $player->listening) { |
56 | $pl->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE); |
56 | $pl->message ("Your verbose level stays at $prev_listen.", cf::NDI_UNIQUE); |
57 | } else { |
57 | } else { |
58 | $pl->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE); |
58 | $pl->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE); |
59 | } |
59 | } |
60 | } else { |
60 | } else { |
61 | $pl->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE); |
61 | $pl->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE); |
… | |
… | |
64 | |
64 | |
65 | cf::register_command cointoss => sub { |
65 | cf::register_command cointoss => sub { |
66 | my ($pl, $msg) = @_; |
66 | my ($pl, $msg) = @_; |
67 | |
67 | |
68 | my $name = $pl->name; |
68 | my $name = $pl->name; |
|
|
69 | my $coin = int rand 2 ? "Heads" : "Tails"; |
69 | |
70 | |
70 | if (int rand 2) { |
|
|
71 | for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { |
71 | for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { |
72 | next |
72 | next |
73 | if $other->ob == $pl; |
73 | if $other->ob == $pl; |
74 | $other->ob->message ("$name flips a coin.... Heads!", cf::NDI_GREY | cf::NDI_UNIQUE); |
|
|
75 | } |
|
|
76 | |
|
|
77 | $pl->message ("You flip a coin.... Heads!", cf::NDI_GREY | cf::NDI_UNIQUE); |
|
|
78 | } else { |
|
|
79 | for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { |
|
|
80 | next |
|
|
81 | if $other->ob == $pl; |
|
|
82 | $other->ob->message ("$name flips a coin.... Tails!", cf::NDI_GREY | cf::NDI_UNIQUE); |
74 | $other->ob->message ("$name flips a coin.... $coin!", cf::NDI_GREY | cf::NDI_UNIQUE); |
83 | } |
|
|
84 | |
|
|
85 | $pl->message ("You flip a coin.... Tails!", cf::NDI_GREY | cf::NDI_UNIQUE); |
|
|
86 | } |
75 | } |
|
|
76 | |
|
|
77 | $pl->message ("You flip a coin.... $coin!", cf::NDI_GREY | cf::NDI_UNIQUE); |
87 | }; |
78 | }; |
88 | |
79 | |
89 | cf::register_command orcknuckle => sub { |
80 | cf::register_command orcknuckle => sub { |
90 | my ($pl, $msg) = @_; |
81 | my ($pl, $msg) = @_; |
91 | my @orcknuckle = ("none", "beholder", "ghost", "knight", "princess", "dragon", "orc"); |
82 | my @orcknuckle = ("none", "beholder", "ghost", "knight", "princess", "dragon", "orc"); |
… | |
… | |
755 | } |
746 | } |
756 | }; |
747 | }; |
757 | }; |
748 | }; |
758 | } |
749 | } |
759 | |
750 | |
|
|
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 | |
760 | cf::register_command me => sub { |
758 | cf::register_command me => sub { |
761 | my ($pl, $msg) = @_; |
759 | my ($pl, $msg) = @_; |
762 | |
760 | |
763 | my $name = $pl->name; |
761 | my $name = $pl->name; |
764 | |
762 | |
765 | $_->ob->message ("* $name $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
763 | $_->ns->send_msg ($SAY_CHANNEL => "* $name $msg", cf::NDI_GREY, $_ == $pl ? (reply => 1) : ()) |
766 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
764 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
767 | }; |
765 | }; |
768 | |
766 | |
769 | cf::register_command say => sub { |
767 | cf::register_command say => sub { |
770 | my ($pl, $msg) = @_; |
768 | my ($pl, $msg) = @_; |
… | |
… | |
773 | |
771 | |
774 | return if $pl->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); |
772 | return if $pl->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); |
775 | |
773 | |
776 | if ($msg) { |
774 | if ($msg) { |
777 | my $name = $pl->name; |
775 | my $name = $pl->name; |
778 | |
|
|
779 | $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
|
|
780 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
776 | my @plonmap = grep $pl->on_same_map_as ($_->ob), cf::player::list; |
|
|
777 | |
|
|
778 | $_->ns->send_msg ($SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, $_ == $pl ? (reply => 1) : ()) |
|
|
779 | for @plonmap; |
781 | |
780 | |
782 | # npcs, magic_ears etc. |
781 | # npcs, magic_ears etc. |
783 | # first find all objects and their first-level inventories |
782 | # first find all objects and their first-level inventories |
784 | # within a 5x5 square that have something resembling |
783 | # within a 5x5 square that have something resembling |
785 | # dialogue or support on_say. |
784 | # dialogue or support on_say. |
… | |
… | |
799 | my ($reply, @kw) = $dialog->tell ($msg); |
798 | my ($reply, @kw) = $dialog->tell ($msg); |
800 | |
799 | |
801 | if (defined $reply) { |
800 | if (defined $reply) { |
802 | if ($npc->type == cf::MAGIC_EAR) { |
801 | if ($npc->type == cf::MAGIC_EAR) { |
803 | if (length $reply) { |
802 | if (length $reply) { |
804 | $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE) |
803 | $_->contr->send_msg ($SAY_CHANNEL => $reply, cf::NDI_BROWN) |
805 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
804 | for @plonmap; |
806 | } |
805 | } |
807 | $npc->use_trigger; |
806 | $npc->use_trigger; |
808 | } else { |
807 | } else { |
809 | if (length $reply) { |
808 | if (length $reply) { |
810 | $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE) |
809 | $_->contr->send_msg ($SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN) |
811 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
810 | for @plonmap; |
812 | } |
811 | } |
813 | } |
812 | } |
814 | } |
813 | } |
815 | |
814 | |
816 | if (@kw) { |
815 | if (@kw) { |
817 | $_->ob->message ("[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN | cf::NDI_UNIQUE) |
816 | $_->contr->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) |
818 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
817 | for @plonmap; |
819 | } |
818 | } |
820 | } |
819 | } |
821 | |
820 | |
822 | } else { |
821 | } else { |
823 | $pl->message ("What do you want to say?", cf::NDI_UNIQUE); |
822 | $pl->contr->send_msg ($SAY_CHANNEL => "What do you want to say?", 0, reply => 1); |
824 | } |
823 | } |
|
|
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.", |
825 | }; |
831 | }; |
826 | |
832 | |
827 | cf::register_command chat => sub { |
833 | cf::register_command chat => sub { |
828 | my ($pl, $msg) = @_; |
834 | my ($pl, $msg) = @_; |
829 | |
835 | |
… | |
… | |
836 | my $NOW = time; |
842 | my $NOW = time; |
837 | |
843 | |
838 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
844 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
839 | send_irc ("[%s] %s", $name, $msg); |
845 | send_irc ("[%s] %s", $name, $msg); |
840 | |
846 | |
841 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
847 | $_->ns->send_msg ($CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE, $_ == $pl ? (reply => 1) : ()) |
842 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
848 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
843 | |
849 | |
844 | } else { |
850 | } else { |
845 | $pl->message ("Chat what?", cf::NDI_UNIQUE); |
851 | $pl->ns->send_msg ($CHAT_CHANNEL => "Chat what?"); |
846 | } |
852 | } |
847 | }; |
853 | }; |
848 | |
854 | |
849 | cf::register_command shout => sub { |
855 | cf::register_command shout => sub { |
850 | my ($pl, $msg) = @_; |
856 | my ($pl, $msg) = @_; |
… | |
… | |
858 | my $name = $pl->name; |
864 | my $name = $pl->name; |
859 | |
865 | |
860 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
866 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
861 | send_irc ("\007\0034{%s} %s\n", $name, $msg); |
867 | send_irc ("\007\0034{%s} %s\n", $name, $msg); |
862 | |
868 | |
863 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
869 | $_->ns->send_msg ($CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_BLUE, $_ == $pl ? (reply => 1) : ()) |
864 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
870 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
865 | |
871 | |
866 | } else { |
872 | } else { |
867 | $pl->message ("Shout what?", cf::NDI_UNIQUE); |
873 | $pl->ns->send_msg ($CHAT_CHANNEL => "Shout what?"); |
868 | } |
874 | } |
869 | }; |
875 | }; |
870 | |
876 | |
871 | cf::register_command tell => sub { |
877 | cf::register_command tell => sub { |
872 | my ($pl, $args) = @_; |
878 | my ($ob, $args) = @_; |
873 | my ($target, $msg) = split /\s+/, $args, 2; |
879 | my ($target, $msg) = split /\s+/, $args, 2; |
874 | |
880 | |
875 | utf8::decode $msg; |
881 | utf8::decode $msg; |
876 | |
882 | |
|
|
883 | my $pl = $ob->contr; |
|
|
884 | my $ns = $pl->ns |
|
|
885 | or return; |
|
|
886 | my $name = $ob->name; |
|
|
887 | |
877 | return if $pl->contr->invoke (cf::EVENT_PLAYER_TELL, $target, $msg); |
888 | return if $pl->invoke (cf::EVENT_PLAYER_TELL, $target, $msg); |
878 | |
889 | |
879 | my $name = $pl->name; |
890 | my $pl_channel = { |
|
|
891 | id => "tell-$target", |
|
|
892 | title => "$target", |
|
|
893 | reply => "tell $target ", |
|
|
894 | tooltip => "Private messages from/to $target", |
|
|
895 | }; |
880 | |
896 | |
881 | if ($target =~ /irc\//) { |
897 | if ($target =~ /irc\//) { |
882 | my (undef, $nick) = split /\//, $target, 2; |
898 | my (undef, $nick) = split /\//, $target, 2; |
883 | $pl->message ("You tell $target: $args"); |
899 | $ns->send_msg ($pl_channel => "You tell $target: $args", reply => 1); |
884 | send_irc ("(%s) %s: %s\n", $name, $nick, $msg); |
900 | send_irc ("(%s) %s: %s\n", $name, $nick, $msg); |
885 | } elsif (my $other = cf::player::find_active $target) { |
901 | } elsif (my $other = cf::player::find_active $target) { |
|
|
902 | my $other_channel = { |
|
|
903 | id => "tell-$name", |
|
|
904 | title => "$name", |
|
|
905 | reply => "tell $name ", |
|
|
906 | tooltip => "Private messages from/to $name", |
|
|
907 | }; |
886 | |
908 | |
887 | if ($msg) { |
909 | if ($msg) { |
888 | if ($target eq $name) { |
910 | if ($target eq $name) { |
889 | $pl->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
911 | $ns->send_msg ($pl_channel => "You are talking to yourself, you freak!", reply => 1); |
890 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
912 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
891 | $pl->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
913 | $ns->send_msg ($pl_channel => "$target ignores what you say. Give up on it.", reply => 1); |
892 | } else { |
914 | } else { |
893 | return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl->contr, $msg); |
915 | return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl->contr, $msg); |
894 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; |
916 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; |
895 | |
917 | |
896 | $pl->message ("You tell $target: $msg"); |
918 | $ns->send_msg ($pl_channel => "You tell $target: $msg", reply => 1); |
897 | $other->ob->message ("$name tells you: $msg"); |
919 | $other->ns->send_msg ($other_channel => "$name tells you: $msg"); |
898 | $other->ob->{ext_last_tell} = $name; |
|
|
899 | } |
920 | } |
900 | } else { |
921 | } else { |
901 | $pl->message ("What do you want to tell $target?", cf::NDI_UNIQUE); |
922 | $ns->send_msg ($pl_channel => "What do you want to tell $target?"); |
902 | } |
923 | } |
903 | |
924 | |
904 | } else { |
925 | } else { |
905 | $pl->message ("No such player. Your message: $msg", cf::NDI_UNIQUE); |
926 | $ns->send_msg ($pl_channel => "No such player. Your message: $msg"); |
906 | } |
|
|
907 | }; |
|
|
908 | |
|
|
909 | cf::register_command reply => sub { |
|
|
910 | my ($pl, $args) = @_; |
|
|
911 | my $name = $pl->name; |
|
|
912 | |
|
|
913 | utf8::decode $args; |
|
|
914 | |
|
|
915 | return if $pl->contr->invoke (cf::EVENT_PLAYER_TELL, $pl->{ext_last_tell}, $args); |
|
|
916 | |
|
|
917 | if ($pl->{ext_last_tell} =~ /irc\//) { |
|
|
918 | my (undef, $nick) = split /\//, $pl->{ext_last_tell}, 2; |
|
|
919 | $pl->message ("You tell " . $pl->{ext_last_tell} . ": $args"); |
|
|
920 | send_irc ("(%s) %s: %s\n", $name, $nick, $args); |
|
|
921 | } elsif (my $other = cf::player::find_active $pl->{ext_last_tell}) { |
|
|
922 | |
|
|
923 | if ($args) { |
|
|
924 | $other->ob->{ext_ignore_tell}{$name} >= time |
|
|
925 | or delete $other->ob->{ext_ignore_tell}{$name}; |
|
|
926 | |
|
|
927 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
|
|
928 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; |
|
|
929 | |
|
|
930 | $pl->message ("You tell " . $other->ob->name . ": $args"); |
|
|
931 | $other->ob->message ("$name tells you: $args"); |
|
|
932 | $pl->{ext_last_tell} = $other->ob->name; |
|
|
933 | } else { |
|
|
934 | $pl->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
|
|
935 | } |
|
|
936 | } else { |
|
|
937 | $pl->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE); |
|
|
938 | } |
|
|
939 | |
|
|
940 | } else { |
|
|
941 | $pl->message ("Can't reply, player left. Your message: $args".$pl->{ext_last_tell}, cf::NDI_UNIQUE); |
|
|
942 | } |
927 | } |
943 | }; |
928 | }; |
944 | |
929 | |
945 | cf::register_command ignore => sub { |
930 | cf::register_command ignore => sub { |
946 | my ($pl, $args) = @_; |
931 | my ($pl, $args) = @_; |