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.51 by root, Sun Jul 19 18:15:07 2009 UTC vs.
Revision 1.55 by root, Fri Apr 23 17:56:45 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
790 790
791 send_msg $_, $cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say" 791 send_msg $_, $cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say"
792 for grep $_ != $ob->contr, @plonmap; 792 for grep $_ != $ob->contr, @plonmap;
793 $ob->contr->send_msg ($cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY); 793 $ob->contr->send_msg ($cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY);
794 794
795 my @npc;
796
795 # npcs, magic_ears etc. 797 # npcs, magic_ears etc.
796 # first find all objects and their first-level inventories 798 # first find all objects and their first-level inventories
797 # within a 5x5 square that have something resembling 799 # within a 5x5 square that have something resembling
798 # dialogue or support on_say. 800 # dialogue or support on_say.
801 # we prefer the nearest items NOT in the player, otherwise in player.
799 my ($map, $x, $y) = ($ob->map, $ob->x - 2, $ob->y - 2); 802 my ($map, $x, $y) = ($ob->map, $ob->x, $ob->y);
800 803
801 for my $npc ( 804 for my $dir (
802 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $ob->contr, $msg) && return) || $_->has_dialogue, 805 0,
803 map +($_, $_->inv), 806 1, 3, 5, 7,
804 grep $_, 807 2, 4, 6, 8,
805 map $map->at ($x + $_ % 5, $y + (int $_ / 5)), 808 9 .. cf::SIZEOFFREE2
806 0..24
807 ) { 809 ) {
810 @npc = grep $_->should_invoke (cf::EVENT_OBJECT_SAY) || $_->has_dialogue,
811 map +($_, $_->inv),
812 grep $_ != $ob,
813 $map->at ($x, $y, $dir)
814 and last;
815 }
816
817 unless (@npc) {
818 # nothing found, try the player inventory
819 @npc = grep $_->should_invoke (cf::EVENT_OBJECT_SAY) || $_->has_dialogue,
820 $ob->inv;
821 }
822
823 for my $npc (@npc) {
824 return if $npc->invoke (cf::EVENT_OBJECT_SAY, $ob->contr, $msg);
825
808 # if some listener teleported us somewhere else, stop right here 826 # if some listener teleported us somewhere else, stop right here
809 last unless $map->path == $ob->map->path; 827 last unless $map->path == $ob->map->path;
810 828
829 if ($npc->has_dialogue) {
811 my $dialog = new NPC_Dialogue pl => $ob->contr, npc => $npc; 830 my $dialog = new NPC_Dialogue pl => $ob->contr, npc => $npc;
812 my ($reply, @kw) = $dialog->tell ($msg); 831 my ($reply, @kw) = $dialog->tell ($msg);
813 832
814 if (defined $reply) { 833 if (defined $reply) {
815 if ($npc->type == cf::MAGIC_EAR) { 834 if ($npc->type == cf::MAGIC_EAR) {
816 send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say" 835 send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say"
817 for @plonmap; 836 for @plonmap;
818 } else { 837 } else {
819 send_msg $_, $cf::SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say" 838 send_msg $_, $cf::SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say"
839 for @plonmap;
840 }
841 }
842
843 if (@kw) {
844 $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN)
820 for @plonmap; 845 for @plonmap;
821 } 846 }
822 }
823
824 if (@kw) {
825 $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN)
826 for @plonmap;
827 } 847 }
828 } 848 }
829 849
830 } else { 850 } else {
831 $ob->send_msg ($cf::SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY); 851 $ob->send_msg ($cf::SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines