ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/chat.ext
(Generate patch)

Comparing deliantra/server/ext/chat.ext (file contents):
Revision 1.46 by root, Thu Dec 18 02:49:22 2008 UTC vs.
Revision 1.56 by root, Sun Sep 5 05:01:39 2010 UTC

73 my ($ob, $msg) = @_; 73 my ($ob, $msg) = @_;
74 74
75 my $pl = $ob->contr; 75 my $pl = $ob->contr;
76 my $name = $ob->name; 76 my $name = $ob->name;
77 77
78 my $coin = int rand 2 ? "Heads" : "Tails"; 78 my $coin = (cf::rndm 2) ? "Heads" : "Tails";
79 79
80 send_msg $_, $cf::SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY, "msg_say" 80 send_msg $_, $cf::SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY, "msg_say"
81 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; 81 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list;
82 82
83 $pl->send_msg ($cf::SAY_CHANNEL => "You flip a coin.... $coin!", cf::NDI_GREY | cf::NDI_REPLY); 83 $pl->send_msg ($cf::SAY_CHANNEL => "You flip a coin.... $coin!", cf::NDI_GREY | cf::NDI_REPLY);
88 88
89 my $pl = $ob->contr; 89 my $pl = $ob->contr;
90 my $name = $ob->name; 90 my $name = $ob->name;
91 91
92 my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc"); 92 my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc");
93 my ($i, $j, $k, $l) = (rand 5, rand 5, rand 5, rand 6); 93 my ($i, $j, $k, $l) = map +(cf::rndm $_), 5, 5, 5, 6;
94 my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]"; 94 my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]";
95 95
96 send_msg $_, $cf::SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY, "msg_say" 96 send_msg $_, $cf::SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY, "msg_say"
97 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; 97 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list;
98 98
218 }, 218 },
219 }, 219 },
220 kiss => { 220 kiss => {
221 noparams => { 221 noparams => {
222 other => "<self> makes a weird facial contortion", 222 other => "<self> makes a weird facial contortion",
223 self => "All the lonely people..", 223 self => "All the lonely people...",
224 }, 224 },
225 params => { 225 params => {
226 target => "<self> kisses you.", 226 target => "<self> kisses you.",
227 other => "<self> kisses <other>.", 227 other => "<self> kisses <other>.",
228 self => "You kiss <other>.", 228 self => "You kiss <other>.",
229 }, 229 },
230 self => { 230 self => {
231 }, 231 },
232 }, 232 },
233 hug => {
234 noparams => {
235 other => "<self> makes weird body movements.",
236 self => "All the lonely people...",
237 },
238 params => {
239 target => "<self> suddenly grabs you and gives you a bear hug.",
240 other => "<self> hugs <other>.",
241 self => "You hug <other>.",
242 },
243 self => {
244 other => "<self> tries to hug G<himself|herself>, but stumbles and now feels stupid.",
245 self => "You try and fail to hug yourself.",
246 },
247 },
233 smother => { 248 smother => {
234 noparams => { 249 noparams => {
235 other => "<self> makes weird facial contortions", 250 other => "<self> makes weird facial contortions",
236 self => "All the lonely people..", 251 self => "All the lonely people...",
237 }, 252 },
238 params => { 253 params => {
239 target => "<self> smothers you with kisses.", 254 target => "<self> smothers you with kisses.",
240 other => "<self> smothers <other> with kisses.", 255 other => "<self> smothers <other> with kisses.",
241 self => "You smother <other> with kisses.", 256 self => "You smother <other> with kisses.",
719 for grep { $ob->on_same_map_as ($_->ob) && $_ != $ob} cf::player::list; 734 for grep { $ob->on_same_map_as ($_->ob) && $_ != $ob} cf::player::list;
720 735
721 $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY | cf::NDI_VERBATIM); 736 $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY | cf::NDI_VERBATIM);
722 } elsif ($tname) { 737 } elsif ($tname) {
723 my $target = cf::player::find $tname 738 my $target = cf::player::find $tname
724 or return send_msg $pl, tell_channel $tname, "$tname is not around.", cf::NDI_DK_ORANGE | cf::NDI_REPLY, "msg_chat"; 739 or return send_msg $pl, tell_channel $tname, "The player called $tname is not known to this poor server.",
740 cf::NDI_DK_ORANGE | cf::NDI_REPLY, "msg_chat";
741
742 $target->ob->active
743 or return send_msg $pl, tell_channel $tname, "$tname is not around. H<$tname must be logged in.>",
744 cf::NDI_DK_ORANGE | cf::NDI_REPLY, "msg_chat";
725 745
726 my %emote = %{ $emotes->{$emotion}->{params} || {} }; 746 my %emote = %{ $emotes->{$emotion}->{params} || {} };
727 747
728 $emote{other} ||= "<self> is eyeing <other> quizzically."; 748 $emote{other} ||= "<self> is eyeing <other> quizzically.";
729 $emote{self} ||= "You are still nuts."; 749 $emote{self} ||= "You are still nuts.";
760 } 780 }
761 }; 781 };
762 }; 782 };
763} 783}
764 784
765cf::register_command me => sub {
766 my ($pl, $msg) = @_;
767
768 my $name = $pl->name;
769
770 send_msg $_, $cf::SAY_CHANNEL => "* $name $msg", cf::NDI_GREY | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_say"
771 for grep $pl->on_same_map_as ($_->ob), cf::player::list;
772};
773
774cf::register_command say => sub { 785cf::register_command say => sub {
775 my ($ob, $msg) = @_; 786 my ($ob, $msg) = @_;
776 787
777 utf8::decode $msg; 788 utf8::decode $msg;
778 789
783 my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list; 794 my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list;
784 795
785 send_msg $_, $cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say" 796 send_msg $_, $cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say"
786 for grep $_ != $ob->contr, @plonmap; 797 for grep $_ != $ob->contr, @plonmap;
787 $ob->contr->send_msg ($cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY); 798 $ob->contr->send_msg ($cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY);
799
800 my @npc;
788 801
789 # npcs, magic_ears etc. 802 # npcs, magic_ears etc.
790 # first find all objects and their first-level inventories 803 # first find all objects and their first-level inventories
791 # within a 5x5 square that have something resembling 804 # within a 5x5 square that have something resembling
792 # dialogue or support on_say. 805 # dialogue or support on_say.
806 # we prefer the nearest items NOT in the player, otherwise in player.
793 my ($map, $x, $y) = ($ob->map, $ob->x - 2, $ob->y - 2); 807 my ($map, $x, $y) = ($ob->map, $ob->x, $ob->y);
794 808
795 for my $npc ( 809 for my $dir (
796 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $ob->contr, $msg) && return) || $_->has_dialogue, 810 0,
797 map +($_, $_->inv), 811 1, 3, 5, 7,
798 grep $_, 812 2, 4, 6, 8,
799 map $map->at ($x + $_ % 5, $y + (int $_ / 5)), 813 9 .. cf::SIZEOFFREE2
800 0..24
801 ) { 814 ) {
815 @npc = grep $_->should_invoke (cf::EVENT_OBJECT_SAY) || $_->has_dialogue,
816 map +($_, $_->inv),
817 grep $_ != $ob,
818 $map->at ($x, $y, $dir)
819 and last;
820 }
821
822 unless (@npc) {
823 # nothing found, try the player inventory
824 @npc = grep $_->should_invoke (cf::EVENT_OBJECT_SAY) || $_->has_dialogue,
825 $ob->inv;
826 }
827
828 for my $npc (@npc) {
829 return if $npc->invoke (cf::EVENT_OBJECT_SAY, $ob->contr, $msg);
830
802 # if some listener teleported us somewhere else, stop right here 831 # if some listener teleported us somewhere else, stop right here
803 last unless $map->path == $ob->map->path; 832 last unless $map->path == $ob->map->path;
804 833
834 if ($npc->has_dialogue) {
805 my $dialog = new NPC_Dialogue pl => $ob->contr, npc => $npc; 835 my $dialog = new NPC_Dialogue pl => $ob->contr, npc => $npc;
806 my ($reply, @kw) = $dialog->tell ($msg); 836 my ($reply, @kw) = $dialog->tell ($msg);
807 837
808 if (defined $reply) { 838 if (defined $reply) {
809 if ($npc->type == cf::MAGIC_EAR) { 839 if ($npc->type == cf::MAGIC_EAR) {
810 send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say" 840 send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say"
811 for @plonmap; 841 for @plonmap;
812 } else { 842 } else {
813 send_msg $_, $cf::SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say" 843 send_msg $_, $cf::SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say"
844 for @plonmap;
845 }
846 }
847
848 if (@kw) {
849 $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN)
814 for @plonmap; 850 for @plonmap;
815 } 851 }
816 }
817
818 if (@kw) {
819 $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN)
820 for @plonmap;
821 } 852 }
822 } 853 }
823 854
824 } else { 855 } else {
825 $ob->send_msg ($cf::SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY); 856 $ob->send_msg ($cf::SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY);
826 } 857 }
827}; 858};
828 859
829cf::register_command chat => sub { 860
861sub _chat {
830 my ($ob, $msg) = @_; 862 my ($ob, $msg) = @_;
831
832 utf8::decode $msg;
833 863
834 my $pl = $ob->contr; 864 my $pl = $ob->contr;
835 865
836 return if $pl->invoke (cf::EVENT_PLAYER_CHAT, $msg); 866 return if $pl->invoke (cf::EVENT_PLAYER_CHAT, $msg);
837 867
838 if ($msg) { 868 if ($msg) {
839 my $name = $ob->name; 869 my $name = $ob->name;
840 my $NOW = time; 870 my $NOW = time;
841 871
842 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; 872 cf::LOG cf::llevDebug, sprintf "QBERT %s\n", $msg;
843 send_irc ("[%s] %s", $name, $msg); 873 send_irc ("%s", $msg);
844 874
845 send_msg $_, $cf::CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat" 875 send_msg $_, $cf::CHAT_CHANNEL => $msg, cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat"
846 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW } cf::player::list; 876 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW } cf::player::list;
847 877
848 } else { 878 } else {
849 $pl->send_msg ($cf::CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY); 879 $pl->send_msg ($cf::CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY);
850 } 880 }
881}
882
883cf::register_command chat => sub {
884 my ($ob, $msg) = @_;
885
886 utf8::decode $msg;
887 _chat $ob, $ob->name . " chats: $msg";
888};
889
890cf::register_command me => sub {
891 my ($ob, $msg) = @_;
892
893 utf8::decode $msg;
894 _chat $ob, "* " . $ob->name . " $msg";
851}; 895};
852 896
853cf::register_command shout => sub { 897cf::register_command shout => sub {
854 my ($ob, $msg) = @_; 898 my ($ob, $msg) = @_;
855 899

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines