--- deliantra/maps/perl/chat.ext 2006/06/09 04:18:02 1.19 +++ deliantra/maps/perl/chat.ext 2006/07/19 08:52:57 1.20 @@ -3,6 +3,8 @@ # implement a replacement for the built-in say/chat/shout/tell/reply commands # adds ignore/unignore functionality +use NPC_Dialogue; + sub valid_user($) { cf::player::find $_[0] or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2; @@ -15,10 +17,10 @@ for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { while (my ($k, $v) = each %$hash) { if ($v < $NOW) { - $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN); + $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN | cf::NDI_UNIQUE); delete $hash->{$k}; } elsif (!valid_user $k) { - $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN); + $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN | cf::NDI_UNIQUE); delete $hash->{$k}; } } @@ -39,26 +41,63 @@ my $prev_listen = $player->listening; $player->listening ($msg); if ($prev_listen == $player->listening) { - $who->message ("Your verbose level stayed ".$prev_listen.".", cf::NDI_UNIQUE); + $who->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE); } else { - $who->message ("Your verbose level is now ".$player->listening.". (previously: ".$prev_listen.")", cf::NDI_UNIQUE); + $who->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE); } } else { - $who->message ("Your verbose level is ".$player->listening.".", cf::NDI_UNIQUE); + $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE); } }; -#cf::register_command say => 0, sub { -# my ($who, $msg) = @_; -# -# if ($msg) { -# my $name = $who->name; -# $_->ob->message ("$name says: $msg", cf::NDI_WHITE) -# for grep $who->on_same_map_as ($_->ob), cf::player::list; -# } else { -# $who->message ("What do you want to say?", cf::NDI_UNIQUE); -# } -#}; +cf::register_command xsay => 0, sub { + my ($who, $msg) = @_; + + if ($msg) { + my $name = $who->name; + + my @messages = (["$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE]); + + # npcs, magic_ears etc. + # first find all objects and their inventories within a 5x5 square + # that have something resembling dialogue + my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2); + + for my $npc ( + grep NPC_Dialogue::has_dialogue $_, + map +($_, $_->inv), + grep $_, + map $map->at ($x + $_ % 5, $y + (int $_ / 5)), + 0..24 + ) { + # if some listener teleported us somewhere else, stop right here + last unless $map->path == $who->map->path; + + my $dialog = new NPC_Dialogue ob => $who, npc => $npc; + my $reply = $dialog->tell ($msg); + + if (defined $reply) { + if ($npc->type == cf::MAGIC_EAR) { + push @messages, [$reply, cf::NDI_BROWN | cf::NDI_UNIQUE] if length $reply; + $npc->use_trigger; + } else { + push @messages, [$npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE] if length $reply; + } + } + } + + # send replies to all players on this map + for (@messages) { + my ($msg, $flags) = @$_; + + $_->ob->message ($msg, $flags) + for grep $who->on_same_map_as ($_->ob), cf::player::list; + } + + } else { + $who->message ("What do you want to say?", cf::NDI_UNIQUE); + } +}; cf::register_command chat => 0, sub { my ($who, $msg) = @_;